ImageMagick icon indicating copy to clipboard operation
ImageMagick copied to clipboard

Add compression and chunk data length to Attributes options

Open emanuelb opened this issue 4 years ago • 2 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am using the latest version of ImageMagick
  • [x] I have searched open and closed issues to ensure it has not already been reported

Description

you can read the original bug report at diffoscope for more details: https://salsa.debian.org/reproducible-builds/diffoscope/-/issues/142

diffoscope tool call identify -format on images to show differences between them, comparing the result of: identify -verbose or identify -format '%b\n%c\n%d\n%e\n%f\n%g\n%h\n%i\n%k\n%l\n%m\n%n\n%o\n%p\n%q\n%r\n%s\n%t\n%u\n%w\n%x\n%y\n%z\n%A\n%B\n%C\n%D\n%G\n%H\n%M\n%O\n%P\n%Q\n%S\n%T\n%U\n%W\n%X\n%Y\n%Z\n%@\n%#\n' (calling identify tool with all options declared in https://www.imagemagick.org/script/escape.php) on below files:

https://salsa.debian.org/reproducible-builds/diffoscope/uploads/29505f2274a6d0a0792e0f77518709f9/ic_launcher1.png https://salsa.debian.org/reproducible-builds/diffoscope/uploads/45d8f83436b4072a99276b36ca4b774d/ic_launcher2.png

will not result in meaningful diff which means that there is some image metadata that the tool doesn't support yet, running tools pngchunks and pngcheck show differences: 97.8% compression vs 97.2% compression and Chunk: Data Length 3220 vs Chunk: Data Length 4082 so the issue is about adding support for the above fields Chunk Data Length and compression to identify tool.

emanuelb avatar Jun 04 '20 15:06 emanuelb

The images are exactly the same per the ImageMagick compare command, there is a distortion of zero. Difference in metadata can surmised with a difference in checksum such as sha256sum. Compression appears to be a calculated value. If its a true PNG metadata value, let us know what it is. If not, we need the exact algorithm used to compute the compression ratio. The chunk data length is problematic in that there can be multiple IDAT chunks. We could sum them for a final value but we need a compelling reason to undertake the effort to produce the value. Alternatively, you can code the solution yourself and present it as a pull request.

urban-warrior avatar Jun 04 '20 22:06 urban-warrior

The diffoscope tool try to avoid returning only binary diff if meaningful diff is possible, it's using identify tool for image compare, on above files it find no differences, but pngchunks and pngcheck tools return meaningful information which adding it to identify may help other use-cases as well (not just diffing), while I can't offer a pull-request with code addition, I can point to the source-code of the above commands in Debian distro where it's output the useful information:

The pngchunks code for output of (on above file): Chunk: Data Length 3220 (max 2147483647), Type 1413563465 [IDAT] is in: https://sources.debian.org/src/pngtools/0.4-1.3/pngchunks.c/?hl=104#L85-L91

The code of pngcheck tool which output:

chunk IDAT at offset 0x00025, length 3220
No errors detected in ic_launcher1.png (3 chunks, 97.8% compression).

is in one of those locations: https://sources.debian.org/src/pngcheck/2.3.0-10/pngcheck.c/?hl=4678#L4677-L4680 https://sources.debian.org/src/pngcheck/2.3.0-10/pngcheck.c/?hl=4711#L4710-L4713

emanuelb avatar Jun 04 '20 22:06 emanuelb