possible bug converting gif to png IM 6.6.9.5

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug converting gif to png IM 6.6.9.5

Post by fmw42 »

IM 6.6.9.5 Q16 Mac OSX Tiger.

I created a gif image with a 64 color colormap. (colortable2.gif is the same as Anthony's colortable.gif at http://www.imagemagick.org/Usage/quantize/#map)

convert logo: +dither -map colortable2.gif logo_ct2.gif

Code: Select all

identify -verbose logo_ct2.gif
Image: logo_ct2.gif
  Format: GIF (CompuServe graphics interchange format)
  Class: PseudoClass
  Geometry: 640x480+0+0
  Resolution: 72x72
  Print size: 8.88889x6.66667
  Units: Undefined
  Type: Palette
  Endianess: Undefined
  Colorspace: RGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 228.156 (0.894729)
      standard deviation: 73.6803 (0.288943)
      kurtosis: 4.81152
      skewness: -2.56884
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 224.718 (0.881247)
      standard deviation: 76.5379 (0.300149)
      kurtosis: 3.78431
      skewness: -2.34107
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 227.607 (0.892575)
      standard deviation: 67.808 (0.265914)
      kurtosis: 4.42396
      skewness: -2.39206
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 226.827 (0.889517)
      standard deviation: 72.7662 (0.285358)
      kurtosis: 4.38664
      skewness: -2.44631
  Histogram:
      8902: (  0,  0,  0) #000000 black
     13762: (  0,  0,128) #000080 navy
      8321: ( 47, 79, 79) #2F4F4F DarkSlateGray
       902: (112,128,144) #708090 SlateGray
       468: (139,134, 78) #8B864E rgb(139,134,78)
       384: (160, 82, 45) #A0522D sienna
       446: (178, 34, 34) #B22222 firebrick
      2769: (190,190,190) #BEBEBE grey
      1438: (205,133, 63) #CD853F peru
      3204: (210,180,140) #D2B48C tan
      1813: (220,220,220) #DCDCDC gainsboro
       764: (230,230,250) #E6E6FA lavender
       372: (245,222,179) #F5DEB3 wheat
      3361: (255,  0,  0) #FF0000 red
       829: (255, 99, 71) #FF6347 tomato
        87: (255,165,  0) #FFA500 orange
       928: (255,215,  0) #FFD700 gold
       159: (255,250,205) #FFFACD LemonChiffon
      1468: (255,255,  0) #FFFF00 yellow
    256823: (255,255,255) #FFFFFF white
  Colormap: 64
         0: (  0,  0,  0) #000000 black
         1: ( 47, 79, 79) #2F4F4F DarkSlateGray
         2: (178, 34, 34) #B22222 firebrick
         3: (255,  0,  0) #FF0000 red
         4: (160, 82, 45) #A0522D sienna
         5: (255, 99, 71) #FF6347 tomato
         6: (  0,255,  0) #00FF00 lime
         7: ( 50,205, 50) #32CD32 LimeGreen
         8: ( 46,139, 87) #2E8B57 SeaGreen
         9: (255,165,  0) #FFA500 orange
        10: (205,133, 63) #CD853F peru
        11: (255,215,  0) #FFD700 gold
        12: (255,255,  0) #FFFF00 yellow
        13: (139,134, 78) #8B864E rgb(139,134,78)
        14: (  0,  0,128) #000080 navy
        15: (  0,  0,255) #0000FF blue
        16: (160, 32,240) #A020F0 rgb(160,32,240)
        17: (255,  0,255) #FF00FF magenta
        18: ( 32,178,170) #20B2AA LightSeaGreen
        19: (112,128,144) #708090 SlateGray
        20: ( 30,144,255) #1E90FF DodgerBlue
        21: (  0,255,255) #00FFFF cyan
        22: (190,190,190) #BEBEBE grey
        23: (210,180,140) #D2B48C tan
        24: (152,251,152) #98FB98 PaleGreen
        25: (245,222,179) #F5DEB3 wheat
        26: (238,130,238) #EE82EE violet
        27: (135,206,235) #87CEEB SkyBlue
        28: (220,220,220) #DCDCDC gainsboro
        29: (255,250,205) #FFFACD LemonChiffon
        30: (230,230,250) #E6E6FA lavender
        31: (255,255,255) #FFFFFF white
        32: (  0,  0,  0) #000000 black
        33: (  0,  0,  0) #000000 black
        34: (  0,  0,  0) #000000 black
        35: (  0,  0,  0) #000000 black
        36: (  0,  0,  0) #000000 black
        37: (  0,  0,  0) #000000 black
        38: (  0,  0,  0) #000000 black
        39: (  0,  0,  0) #000000 black
        40: (  0,  0,  0) #000000 black
        41: (  0,  0,  0) #000000 black
        42: (  0,  0,  0) #000000 black
        43: (  0,  0,  0) #000000 black
        44: (  0,  0,  0) #000000 black
        45: (  0,  0,  0) #000000 black
        46: (  0,  0,  0) #000000 black
        47: (  0,  0,  0) #000000 black
        48: (  0,  0,  0) #000000 black
        49: (  0,  0,  0) #000000 black
        50: (  0,  0,  0) #000000 black
        51: (  0,  0,  0) #000000 black
        52: (  0,  0,  0) #000000 black
        53: (  0,  0,  0) #000000 black
        54: (  0,  0,  0) #000000 black
        55: (  0,  0,  0) #000000 black
        56: (  0,  0,  0) #000000 black
        57: (  0,  0,  0) #000000 black
        58: (  0,  0,  0) #000000 black
        59: (  0,  0,  0) #000000 black
        60: (  0,  0,  0) #000000 black
        61: (  0,  0,  0) #000000 black
        62: (  0,  0,  0) #000000 black
        63: (  0,  0,  0) #000000 black
After converting the gif to png, the number of colors in the colormap in the png file is down to 20. Is this expected behavior? Is it possible to convert from GIF to PNG and preserve the same colors and order in the colormap?

convert logo_ct2.gif logo_ct2.png

Code: Select all

identify -verbose logo_ct2.png
Image: logo_ct2.png
 Format: PNG (Portable Network Graphics)
  Class: PseudoClass
  Geometry: 640x480+0+0
  Resolution: 72x72
  Print size: 8.88889x6.66667
  Units: Undefined
  Type: Palette
  Endianess: Undefined
  Colorspace: RGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 228.156 (0.894729)
      standard deviation: 73.6803 (0.288943)
      kurtosis: 4.81152
      skewness: -2.56884
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 224.718 (0.881247)
      standard deviation: 76.5379 (0.300149)
      kurtosis: 3.78431
      skewness: -2.34107
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 227.607 (0.892575)
      standard deviation: 67.808 (0.265914)
      kurtosis: 4.42396
      skewness: -2.39206
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 226.827 (0.889517)
      standard deviation: 72.7662 (0.285358)
      kurtosis: 4.38664
      skewness: -2.44631
  Histogram:
      8902: (  0,  0,  0) #000000 black
     13762: (  0,  0,128) #000080 navy
      8321: ( 47, 79, 79) #2F4F4F DarkSlateGray
       902: (112,128,144) #708090 SlateGray
       468: (139,134, 78) #8B864E rgb(139,134,78)
       384: (160, 82, 45) #A0522D sienna
       446: (178, 34, 34) #B22222 firebrick
      2769: (190,190,190) #BEBEBE grey
      1438: (205,133, 63) #CD853F peru
      3204: (210,180,140) #D2B48C tan
      1813: (220,220,220) #DCDCDC gainsboro
       764: (230,230,250) #E6E6FA lavender
       372: (245,222,179) #F5DEB3 wheat
      3361: (255,  0,  0) #FF0000 red
       829: (255, 99, 71) #FF6347 tomato
        87: (255,165,  0) #FFA500 orange
       928: (255,215,  0) #FFD700 gold
       159: (255,250,205) #FFFACD LemonChiffon
      1468: (255,255,  0) #FFFF00 yellow
    256823: (255,255,255) #FFFFFF white
  Colormap: 20
         0: (255,255,255) #FFFFFF white
         1: (245,222,179) #F5DEB3 wheat
         2: (255,215,  0) #FFD700 gold
         3: (255,250,205) #FFFACD LemonChiffon
         4: (210,180,140) #D2B48C tan
         5: (230,230,250) #E6E6FA lavender
         6: (190,190,190) #BEBEBE grey
         7: (  0,  0,  0) #000000 black
         8: (220,220,220) #DCDCDC gainsboro
         9: ( 47, 79, 79) #2F4F4F DarkSlateGray
        10: (112,128,144) #708090 SlateGray
        11: (160, 82, 45) #A0522D sienna
        12: (139,134, 78) #8B864E rgb(139,134,78)
        13: (255,255,  0) #FFFF00 yellow
        14: (205,133, 63) #CD853F peru
        15: (255, 99, 71) #FF6347 tomato
        16: (255,  0,  0) #FF0000 red
        17: (  0,  0,128) #000080 navy
        18: (255,165,  0) #FFA500 orange
        19: (178, 34, 34) #B22222 firebrick
Last edited by fmw42 on 2011-04-18T17:08:15-07:00, edited 1 time in total.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: possible bug converting gif to png IM 6.6.9.5

Post by glennrp »

33 of your colormap entries are (0,0,0) and the PNG encoder collapses them
into one entry. Also any of the other colors that aren't used are eliminated.
I don't think it is presently possible to preserve the original colormap.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug converting gif to png IM 6.6.9.5

Post by fmw42 »

glennrp wrote:33 of your colormap entries are (0,0,0) and the PNG encoder collapses them
into one entry. Also any of the other colors that aren't used are eliminated.
I don't think it is presently possible to preserve the original colormap.
Glenn,

Thanks.

OK. This came about in an attempt for me to (create test images to) help answer a question (about appending two png images with a common colormap) at http://studio.imagemagick.org/pipermail ... 23747.html. If you don't mind, could you look at that (and the other responses) and perhaps respond. Is it an issue of needing a current version of IM?

Fred
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: possible bug converting gif to png IM 6.6.9.5

Post by glennrp »

ImageMagick-6.6.9-6 (SVN revision 4245) has a new "-define" option:

Code: Select all

-define PNG:preserve-colormap
which should do what you wanted.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug converting gif to png IM 6.6.9.5

Post by fmw42 »

glennrp wrote:ImageMagick-6.6.9-6 (SVN revision 4245) has a new "-define" option:

Code: Select all

-define PNG:preserve-colormap
which should do what you wanted.

Thanks. I think that will be useful to others as well.

Thanks

Fred
Post Reply