Problems with PNG
Posted: 2010-06-22T19:17:55-07:00
I'm trying to list some problems that can occur when writing PNGs in the last IM versions. Some problems were also addressed in other threads lately, e.g.:
viewtopic.php?f=1&t=16267
viewtopic.php?f=3&t=16309
viewtopic.php?f=3&t=16338
viewtopic.php?f=3&t=16238
I'm currently using IM v6.6.2-5 Q16 on Windows XP. Errors that I get in the last versions:
- "invalid background palette index"
- "invalid colormap index"
- "tRNS chunk has out-of-range samples for bit_depth"
- "cannot write image with defined PNG:bit-depth or PNG:color-type" - solved with version 6.6.2-9
- unwanted images, false colors etc. (with or without accompanying error messages)
- sometimes even crashes - solved with version 6.6.2-8
In some cases it's only warnings and sometimes it could be my own bad commands, but still...
I don't know if/how some cases are related, so I'll just list it all in one thread here. (Be warned: This could get long. ) Maybe the.. PNG developers can pick up some issues if they have some time. I hope, my test cases help a bit.
And don't wonder if some strange combinations are listed - I just tried a lot of things as I couldn't achieve the output files that were once possible with an older IM version...
1) 8bit palette PNG with invalid background palette index warning
Magick: Invalid background palette index `logop8.png' @ warning/png.c/PNGWarningHandler/1457.
It's only a warning and the logo image is fine here, but perhaps it hints to another problem..
When I run that command on an older IM version (6.5.8-5), there's no warning. The only difference between these files seems to be the size of the palette. The 6.5.8-5 output contains a 256 colors palette, while the 6.6.2-5 output contains a 232 colors palette - the image itself has these 232 colors. So maybe the index of the bKGD chunk had a too high number. By the way, on v6.6.2-5, the output of "convert logo: PNG:logo.png" doesn't seem to try to write a bKGD chunk, and there's also no warning. Don't know why it changes with the PNG8 ouput.
2) 8bit palette PNG with invalid colormap index error (and invalid background palette index)
First - as comparison - the writing of a 'normal' PNG file...# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: (255,255,255) #FFFFFF white
1,1: (255,255,255) #FFFFFF whiteMagick: Invalid background palette index `-' @ warning/png.c/PNGWarningHandler/1457.
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: (255,255,255) #FFFFFF white
1,1: (255,255,255) #FFFFFF white
Magick: invalid colormap index `R:/Temp/magick-juCCUOwR' @ error/image.c/SyncImage/3906.
So the PNG8 output shows error messages, but IM still gives the correct pixel values at this point. (By the way: In older IM versions, I get a "memory allocation failed" in such cases.) Other programs already get some random pixel values when reading such an output file. If ones pipes the output through some formats, it even gets visible in IM:Magick: Invalid background palette index `-' @ warning/png.c/PNGWarningHandler/1457.
Magick: invalid colormap index `R:/Temp/magick-IXoV_gK5' @ error/image.c/SyncImage/3906.
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: ( 0, 0, 0) #000000 black
0,1: ( 0, 0, 0) #000000 black
1,1: ( 0, 0, 0) #000000 black
Output image with size 16x16 ("convert -size 16x16 xc:white PNG8:- | convert - BMP:- | convert - white16.png"):
(The upper left pixel is white.)
The output is fine (and without "invalid colormap index") only when the size is bigger than that - so when there are more than 256 pixels.
3) 8bit palette PNG with invalid colormap index error
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: ( 0, 0, 0) #000000 black
1,1: ( 0, 0, 0) #000000 black# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: ( 0, 0, 0) #000000 black
0,1: ( 0, 0, 0) #000000 black
1,1: (255,255,255) #FFFFFF white
Magick: invalid colormap index `R:/Temp/magick-yL6goPHE' @ error/image.c/SyncIma
ge/3906.
(By the way: In older versions, I got a "invalid number of colors in palette" error - a corrupt image with only a PNG header was written.)
Edit:
Updated status for versions 6.6.2-9 or newer.
viewtopic.php?f=1&t=16267
viewtopic.php?f=3&t=16309
viewtopic.php?f=3&t=16338
viewtopic.php?f=3&t=16238
I'm currently using IM v6.6.2-5 Q16 on Windows XP. Errors that I get in the last versions:
- "invalid background palette index"
- "invalid colormap index"
- "tRNS chunk has out-of-range samples for bit_depth"
- "cannot write image with defined PNG:bit-depth or PNG:color-type" - solved with version 6.6.2-9
- unwanted images, false colors etc. (with or without accompanying error messages)
- sometimes even crashes - solved with version 6.6.2-8
In some cases it's only warnings and sometimes it could be my own bad commands, but still...
I don't know if/how some cases are related, so I'll just list it all in one thread here. (Be warned: This could get long. ) Maybe the.. PNG developers can pick up some issues if they have some time. I hope, my test cases help a bit.
And don't wonder if some strange combinations are listed - I just tried a lot of things as I couldn't achieve the output files that were once possible with an older IM version...
1) 8bit palette PNG with invalid background palette index warning
Code: Select all
convert logo: PNG8:logop8.png
It's only a warning and the logo image is fine here, but perhaps it hints to another problem..
When I run that command on an older IM version (6.5.8-5), there's no warning. The only difference between these files seems to be the size of the palette. The 6.5.8-5 output contains a 256 colors palette, while the 6.6.2-5 output contains a 232 colors palette - the image itself has these 232 colors. So maybe the index of the bKGD chunk had a too high number. By the way, on v6.6.2-5, the output of "convert logo: PNG:logo.png" doesn't seem to try to write a bKGD chunk, and there's also no warning. Don't know why it changes with the PNG8 ouput.
2) 8bit palette PNG with invalid colormap index error (and invalid background palette index)
First - as comparison - the writing of a 'normal' PNG file...
Code: Select all
convert -size 2x2 xc:white PNG:- | convert - txt:-
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: (255,255,255) #FFFFFF white
1,1: (255,255,255) #FFFFFF white
Code: Select all
convert -size 2x2 xc:white PNG8:- | convert - txt:-
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: (255,255,255) #FFFFFF white
1,1: (255,255,255) #FFFFFF white
Magick: invalid colormap index `R:/Temp/magick-juCCUOwR' @ error/image.c/SyncImage/3906.
So the PNG8 output shows error messages, but IM still gives the correct pixel values at this point. (By the way: In older IM versions, I get a "memory allocation failed" in such cases.) Other programs already get some random pixel values when reading such an output file. If ones pipes the output through some formats, it even gets visible in IM:
Code: Select all
convert -size 2x2 xc:white PNG8:- | convert - BMP:- | convert - txt:-
Magick: invalid colormap index `R:/Temp/magick-IXoV_gK5' @ error/image.c/SyncImage/3906.
# ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255) #FFFFFF white
1,0: ( 0, 0, 0) #000000 black
0,1: ( 0, 0, 0) #000000 black
1,1: ( 0, 0, 0) #000000 black
Output image with size 16x16 ("convert -size 16x16 xc:white PNG8:- | convert - BMP:- | convert - white16.png"):
(The upper left pixel is white.)
The output is fine (and without "invalid colormap index") only when the size is bigger than that - so when there are more than 256 pixels.
3) 8bit palette PNG with invalid colormap index error
Code: Select all
convert -size 2x1 xc:white xc:black -append PNG:- | convert - txt:-
0,0: (255,255,255) #FFFFFF white
1,0: (255,255,255) #FFFFFF white
0,1: ( 0, 0, 0) #000000 black
1,1: ( 0, 0, 0) #000000 black
Code: Select all
convert -size 2x1 xc:white xc:black -append PNG8:- | convert - txt:-
0,0: (255,255,255) #FFFFFF white
1,0: ( 0, 0, 0) #000000 black
0,1: ( 0, 0, 0) #000000 black
1,1: (255,255,255) #FFFFFF white
Magick: invalid colormap index `R:/Temp/magick-yL6goPHE' @ error/image.c/SyncIma
ge/3906.
(By the way: In older versions, I got a "invalid number of colors in palette" error - a corrupt image with only a PNG header was written.)
Edit:
Updated status for versions 6.6.2-9 or newer.