Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

2-bit PNG file converts wrong

Help
2012-10-30
2013-03-27
  • Brian Buchanan
    Brian Buchanan
    2012-10-30

    I have several PNG files that GraphicsMagick can't seem to convert properly.  I ran into this while trying to convert them to PDF files and the PDF's came out weird.  Same problem when running convert to a PNG.  Any suggestions as to how to make the conversion work correctly?

    Here's an Example:

    Download that file and do a
    gm convert UCHXr.png 100.png and look at the output.  The filesize goes down from 75kb to 14kb.

    $ gm identify UCHXr.png
    UCHXr.png PNG 2544x3300+0+0 PseudoClass 2c 8-bit 74.4K 0.000u 0:01
    Brian@C4070 /cygdrive/c/Users/Brian/Downloads
    $ gm identify -verbose UCHXr.png
    Image: UCHXr.png
      Format: PNG (Portable Network Graphics)
      Geometry: 2544x3300
      Class: PseudoClass
      Type: bilevel
      Depth: 1 bits-per-pixel component
      Channel Depths:
        Gray:     1 bits
      Channel Statistics:
        Gray:
          Minimum:                     0.00 (0.0000)
          Maximum:                 65535.00 (1.0000)
          Mean:                     7813.11 (0.1192)
          Standard Deviation:      21236.46 (0.3240)
      Colors: 2
        0: (  0,  0,  0)      black
        1: (255,255,255)      white
      Resolution: 118.11x118.11 pixels/centimeter
      Filesize: 74.4K
      Interlace: No
      Orientation: Unknown
      Background Color: white
      Border Color: #DFDFDF
      Matte Color: #BDBDBD
      Compose: Over
      Dispose: Undefined
      Iterations: 0
      Compression: Zip
      Signature: bde758adec43c57a80df5b5e058f4de20b937bcc829700d6f9a49d6dcd11edbc
      Tainted: False
      User Time: 0.124u
      Elapsed Time: 0:01
      Pixels Per Second: 70.2M
    $ gm identify 100.png
    100.png PNG 2544x3300+0+0 PseudoClass 2c 8-bit 13.8K 0.000u 0:01
    Brian@C4070 /cygdrive/c/Users/Brian/Downloads
    $ gm identify -verbose 100.png
    Image: 100.png
      Format: PNG (Portable Network Graphics)
      Geometry: 2544x3300
      Class: PseudoClass
      Type: bilevel
      Depth: 1 bits-per-pixel component
      Channel Depths:
        Gray:     1 bits
      Channel Statistics:
        Gray:
          Minimum:                     0.00 (0.0000)
          Maximum:                 65535.00 (1.0000)
          Mean:                     7813.11 (0.1192)
          Standard Deviation:      21236.46 (0.3240)
      Colors: 2
        0: (  0,  0,  0)      black
        1: (255,255,255)      white
      Resolution: 118.11x118.11 pixels/centimeter
      Filesize: 13.8K
      Interlace: No
      Orientation: Unknown
      Background Color: white
      Border Color: #DFDFDF
      Matte Color: #BDBDBD
      Compose: Over
      Dispose: Undefined
      Iterations: 0
      Compression: Zip
      Signature: bde758adec43c57a80df5b5e058f4de20b937bcc829700d6f9a49d6dcd11edbc
      Tainted: False
      User Time: 0.077u
      Elapsed Time: 0:01
      Pixels Per Second: 114.4M
    
     
  • Brian Buchanan
    Brian Buchanan
    2012-10-30

    Well the example failed and I can't see how to edit my post.  I'll try again here.
    Example on Imgur: http://imgur.com/UCHXr

     
  • The result of the convert operation has the same signature
    so I don't see that anything is wrong.  The reported filesize
    does seem low, though.

    GraphicsMagick 1.3.12 2010-03-08 Q8 reports 79.4k
    and so does GraphicsMagick 1.4 snapshot-20120831 Q16

     
  • Brian Buchanan
    Brian Buchanan
    2012-10-30

    I don't know why I didn't think to upload the output: http://imgur.com/LatUD

     
  • I suppose now we need to know which version of GM you tested.  GM-1.3.12 and GM-1.4-snapshot both work OK for me.

     
  • Brian Buchanan
    Brian Buchanan
    2012-10-30

    It's a cygwin build.

    $ gm version
    GraphicsMagick 1.3.16 2012-06-23 Q16 http://www.GraphicsMagick.org/
    Copyright (C) 2002-2012 GraphicsMagick Group.
    Additional copyrights and licenses apply to this software.
    See http://www.GraphicsMagick.org/www/Copyright.html for details.
    Feature Support:
      Thread Safe              yes
      Large Files (> 32 bit)   yes
      Large Memory (> 32 bit)  no
      BZIP                     yes
      DPS                      no
      FlashPix                 no
      FreeType                 yes
      Ghostscript (Library)    no
      JBIG                     yes
      JPEG-2000                yes
      JPEG                     yes
      Little CMS               yes
      Loadable Modules         yes
      OpenMP                   no
      PNG                      yes
      TIFF                     yes
      TRIO                     no
      UMEM                     no
      WMF                      yes
      X11                      yes
      XML                      yes
      ZLIB                     yes
    Host type: i686-pc-cygwin
    Configured using the command:
      /pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/src/GraphicsMagick-1.3.16/configure  '--srcdir=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/src/GraphicsMagick-1.3.16' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--libexecdir=/usr/lib' '--datadir=/usr/share' '--localstatedir=/var' '--sysconfdir=/etc' '--datarootdir=/usr/share' '--docdir=/usr/share/doc/GraphicsMagick' '-C' '--disable-static' '--enable-shared' '--with-perl' '--with-quantum-depth=16' '--disable-openmp' 'CC=gcc' 'CFLAGS=-ggdb -O2 -pipe -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/build=/usr/src/debug/GraphicsMagick-1.3.16-1 -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/src/GraphicsMagick-1.3.16=/usr/src/debug/GraphicsMagick-1.3.16-1' 'LDFLAGS=' 'LIBS=' 'CPPFLAGS=' 'CXX=g++' 'CXXFLAGS=-ggdb -O2 -pipe -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/build=/usr/src/debug/GraphicsMagick-1.3.16-1 -fdebug-prefix-map=/pub/devel/graphicsmagick/Grap
    Final Build Parameters:
      CC       = gcc -std=gnu99
      CFLAGS   = -ggdb -O2 -pipe -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/build=/usr/src/debug/GraphicsMagick-1.3.16-1 -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/src/GraphicsMagick-1.3.16=/usr/src/debug/GraphicsMagick-1.3.16-1 -Wall
      CPPFLAGS = -I/usr/include/freetype2 -I/usr/include/libxml2
      CXX      = g++
      CXXFLAGS = -ggdb -O2 -pipe -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/build=/usr/src/debug/GraphicsMagick-1.3.16-1 -fdebug-prefix-map=/pub/devel/graphicsmagick/GraphicsMagick-1.3.16-1/src/GraphicsMagick-1.3.16=/usr/src/debug/GraphicsMagick-1.3.16-1
      LDFLAGS  = -L/usr/lib -L/usr/lib
      LIBS     = -ljbig -llcms2 -ltiff -lfreetype -ljasper -ljpeg -lpng14 -lwmflite -lXext -lSM -lICE -lX11 -llzma -lbz2 -lxml2 -lz -lgdi32 -lm -lpthread
    
     
  • It should also be considered that GM 1.3.17 is now the current release.  Many distributions froze at 1.3.12 (released on March 8, 2010) due to PNG reader bugs in later versions but 1.3.17 is only known to contain one PNG reading bug at the moment, and not similar to this reported bug.

     
  • Oh, and it is worth mentioning that 1.3.17 fixed PNG reading bugs which are present in 1.3.16.  It seems likely that Cygwin has updated GraphicsMagick by now.

     
  • Brian Buchanan
    Brian Buchanan
    2012-10-30

    I think I found what you are talking about in the changelog:
    http://www.graphicsmagick.org/Changelog.html
    2012-08-31 Glenn Randers-Pehrson <glennrp@simplesystems.org>
    coders/png.c: ReadOnePNGImage: sub-8-bit palette images were getting unpacked twice; once by libpng via png_set_packing() and again by coders/png.c in a switch() statement around line 2500, resulting in horizontally stretched pixels.

    I have sent an e-mail to the cygwin mailing list to try and reach the package maintainer to apply the 1.3.17 update.

    Thanks for your help.

     
  • From my notes, the Cygwin maintainer is Marco Atzeri, and he is usually very good at providing updates.