New PNG CompressionLevel

Hello
PngOptions.CompressionLevel is going to get removed!
The new PngOptions.PngCompressionLevel which is replaced is quite different!

How to match the CompressionLevel to PngCompressionLevel?

For CompressionLevel we set an integer from 0 to 9
For PngCompressionLevel there’s a list of Enum items!
Thanks.

@australian.dev.nerds

Cause

The change from PngOptions.CompressionLevel to PngOptions.PngCompressionLevel introduces a different way to specify compression settings. The previous integer values (0-9) are replaced by an enumeration that defines specific compression levels.

Solution

To match the old CompressionLevel values to the new PngCompressionLevel enum, you can use the following mapping:

  • 0: PngCompressionLevel.ZipLevel0
  • 1: PngCompressionLevel.ZipLevel1
  • 2: PngCompressionLevel.ZipLevel2
  • 3: PngCompressionLevel.ZipLevel3
  • 4: PngCompressionLevel.ZipLevel4
  • 5: PngCompressionLevel.ZipLevel5
  • 6: PngCompressionLevel.ZipLevel6
  • 7: PngCompressionLevel.ZipLevel7
  • 8: PngCompressionLevel.ZipLevel8
  • 9: PngCompressionLevel.ZipLevel9

You can set the PngCompressionLevel in your code like this:

Code

PngOptions options = new PngOptions();
options.PngCompressionLevel = PngCompressionLevel.ZipLevel9; // For maximum compression

Next Steps

  1. Review your existing code to identify where CompressionLevel is used.
  2. Replace it with the corresponding PngCompressionLevel enum value based on the mapping provided.
  3. Test your implementation to ensure the desired compression behavior is achieved.

If you have any further questions or need additional assistance, please feel free to ask!

1 Like

Thanks for your help.
I tried to convert this Jpeg image to Png and test different levels.

The first issue is that the image is rendered with corrupted colors on all settings, this is a bug, try to convert this Jpeg to Png please:

canon.zip (818.1 KB)

Then, I assume that PngCompressionLevel.DeflateRecomended sits beside ZipLevel9 because when converting the above Jpeg sample to Png, both DeflateRecomended and ZipLevel9 will make the image with the same size! Am I correct?
Best.

@australian.dev.nerds
The problem is in the decoding of color spaces in a particular image.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-7747

Files that don’t use this particular color space should convert correctly.

Not exactly. ZipLevel and DeflateRecomended use different deflate algorithms.
According to the internal testing DeflateRecomended typically falls somewhere between ZipLevel 8 and 9.
This value mainly depends on the source image and how much it can be compressed.
However, due to the use of a different deflate algorithm, DeflateRecommended performs noticeably faster than ZipLevel.
Considering all of the above, this algorithm was chosen as the recommended option, despite the lack of compression level customization.
Best regards.

1 Like

Hello and thanks for the info, the photo was taken using Canon R5, so it is expected to see largely in photos taken with recent Canon cameras.