Open davidLif opened 7 years ago
Presence of alpha may be setting a transparency on the image, which would cause darkening. Perhaps convert image to strip out alpha, and see if that fixes things?
Removing the alpha indeed seems to solve the problem - thanks boxerab.
Why would this happen? As far as I understand, jp2 should support a wide range of colorspaces, included the some of the basic rgbs with transparency. Does the "Truecolour with alpha" not included in the EnumCS enumeration, and openjpeg tries to "move" the image to another colorspace (on of those that can be specified with EnumCS) ?
This might help: https://www.youtube.com/watch?v=LPn0KFlbqX8
Honestly, I don't know what is happening here :)
@davidLif ,
for the first image I get:
Lenna.png: w(512) h(512) d(3) nr_passes(1) alpha(0)
Lenna.jp2: numcomps(3) color_space(1)
.i.e. no alpha.
For the second image I get:
tumblr_nxtlkbxyjX1qhttpto2_1280.png: w(1280) h(747) d(4) nr_passes(7) alpha(1)
tumblr_nxtlkbxyjX1qhttpto2_1280.jp2: numcomps(4) color_space(1)
This image has alpha. And the PNG image is interlaced seven times. Please look for 'interlace' in 'man libpng'.
winfried
@davidLif ,
opj_compress -i tumblr_nxtlkbxyjX1qhttpto2_1280.png -o tumbl.jp2
libpng warning: Interlace handling should be turned on when using png_read_image [INFO] tile number 1 / 1 [INFO] Generated outfile tumbl.jp2
I 'once upon a time' did send a 'pngtoimage' patch for interlaced PNG images. That patch was ignored. Therefore the libpng warning.
In 'libpng-1.6.29', I find in 'pngread.c', line 714 ff:
if (png_ptr->interlaced != 0 && (png_ptr->transformations & PNG_INTERLACE) == 0) { /* Caller called png_start_read_image or png_read_update_info without * first turning on the PNG_INTERLACE transform. We can fix this here, * but the caller should do it! */ png_warning(png_ptr, "Interlace handling should be turned on when " "using png_read_image"); /* Make sure this is set correctly */ png_ptr->num_rows = png_ptr->height; }
winfried
David,
I just tried compressing your images with Grok codec https://github.com/GrokImageCompression/grok and the compressed images correctly match the original PNGs - no darkening of colours.
Check it out - API is exactly the same.
Cheers, Aaron
Hello to everyone,
While converting some png images to jp2, I noticed that 2 of them have lost some brightness in the result jp2s (I run the compress exe with no parameters except the input and output paths).
The only difference that I found between these 2 images and the others (which converted fine) is that both of them were Truecolour with alpha while the others had other colourspaces.
The zip contaic both of the original files and the results https://drive.google.com/file/d/0B-fLEESmweZVbmFjUjRGclZBd0U/view?usp=sharing
On tumblr_nxtlkbxyjX1qhttpto2_1280.png, the compression proccess had given this warning : libpng warning: Interlace handling should be turned on when using png_read_image
Thanks for OpenJPEG! This is really a good tool for working with jpg2000 files