Test If PNGwriter Will Open Your PNGs Satisfactorily




As of version 0.5.4, PNGwriter now opens a wider variety of PNG bit depths (See the readfromfile() entry in the Manual for details). There are still some variants that it will not warn you about, but that will not be read correctly, either presenting a very notorious deviation from the original image, or a slight tonality difference.

This example shows you all files included in the PngSuite collection of test PNG images, before and after reading by PNGwriter, the color type and bit depth as read by PNGwriter, and any warnings written to the console.

To see precisely what kind of image caused PNGwriter to fail or behave unexpectedly, please see the PngSuite reference document.

After the long list of images you'll find the source code for the program that generated these images.


Images that render OK

Before
After
Filename, color type and bit depth
as reported by PNGwriter
Reported errors
basi0g01.png, Color Type: 2, Bit Depth: 8  
basi0g04.png, Color Type: 2, Bit Depth: 8  
basi0g08.png, Color Type: 2, Bit Depth: 8  
basi0g16.png, Color Type: 2, Bit Depth: 16  
basi2c08.png, Color Type: 2, Bit Depth: 8  
basi2c16.png, Color Type: 2, Bit Depth: 16  
basi3p01.png, Color Type: 2, Bit Depth: 8  
basi3p02.png, Color Type: 2, Bit Depth: 8  
basi3p04.png, Color Type: 2, Bit Depth: 8  
basi3p08.png, Color Type: 2, Bit Depth: 8  
basn0g01.png, Color Type: 2, Bit Depth: 8  
basn0g04.png, Color Type: 2, Bit Depth: 8  
basn0g08.png, Color Type: 2, Bit Depth: 8  
basn0g16.png, Color Type: 2, Bit Depth: 16  
basn2c08.png, Color Type: 2, Bit Depth: 8  
basn2c16.png, Color Type: 2, Bit Depth: 16  
basn3p01.png, Color Type: 2, Bit Depth: 8  
basn3p02.png, Color Type: 2, Bit Depth: 8  
basn3p04.png, Color Type: 2, Bit Depth: 8  
basn3p08.png, Color Type: 2, Bit Depth: 8  
cdfn2c08.png, Color Type: 2, Bit Depth: 8  
cdhn2c08.png, Color Type: 2, Bit Depth: 8  
cdsn2c08.png, Color Type: 2, Bit Depth: 8  
cdun2c08.png, Color Type: 2, Bit Depth: 8  
ch1n3p04.png, Color Type: 2, Bit Depth: 8  
ch2n3p08.png, Color Type: 2, Bit Depth: 8  
cm0n0g04.png, Color Type: 2, Bit Depth: 8  
cm7n0g04.png, Color Type: 2, Bit Depth: 8  
cm9n0g04.png, Color Type: 2, Bit Depth: 8  
cs3n2c16.png, Color Type: 2, Bit Depth: 16  
cs3n3p08.png, Color Type: 2, Bit Depth: 8  
cs5n2c08.png, Color Type: 2, Bit Depth: 8  
cs5n3p08.png, Color Type: 2, Bit Depth: 8  
cs8n2c08.png, Color Type: 2, Bit Depth: 8  
cs8n3p08.png, Color Type: 2, Bit Depth: 8  
ct0n0g04.png, Color Type: 2, Bit Depth: 8  
ct1n0g04.png, Color Type: 2, Bit Depth: 8  
ctzn0g04.png, Color Type: 2, Bit Depth: 8  
g03n0g16.png, Color Type: 2, Bit Depth: 16  
g03n2c08.png, Color Type: 2, Bit Depth: 8  
g03n3p04.png, Color Type: 2, Bit Depth: 8  
g04n0g16.png, Color Type: 2, Bit Depth: 16  
g04n2c08.png, Color Type: 2, Bit Depth: 8  
g04n3p04.png, Color Type: 2, Bit Depth: 8  
g05n0g16.png, Color Type: 2, Bit Depth: 16  
g05n2c08.png, Color Type: 2, Bit Depth: 8  
g05n3p04.png, Color Type: 2, Bit Depth: 8  
g07n0g16.png, Color Type: 2, Bit Depth: 16  
g07n2c08.png, Color Type: 2, Bit Depth: 8  
g07n3p04.png, Color Type: 2, Bit Depth: 8  
g10n0g16.png, Color Type: 2, Bit Depth: 16  
g10n2c08.png, Color Type: 2, Bit Depth: 8  
g10n3p04.png, Color Type: 2, Bit Depth: 8  
g25n0g16.png, Color Type: 2, Bit Depth: 16  
g25n2c08.png, Color Type: 2, Bit Depth: 8  
g25n3p04.png, Color Type: 2, Bit Depth: 8  
oi1n0g16.png, Color Type: 2, Bit Depth: 16  
oi1n2c16.png, Color Type: 2, Bit Depth: 16  
oi2n0g16.png, Color Type: 2, Bit Depth: 16  
oi2n2c16.png, Color Type: 2, Bit Depth: 16  
oi4n0g16.png, Color Type: 2, Bit Depth: 16  
oi4n2c16.png, Color Type: 2, Bit Depth: 16  
oi9n0g16.png, Color Type: 2, Bit Depth: 16  
oi9n2c16.png, Color Type: 2, Bit Depth: 16  
pp0n2c16.png, Color Type: 2, Bit Depth: 16  
ps1n0g08.png, Color Type: 2, Bit Depth: 8  
ps1n2c16.png, Color Type: 2, Bit Depth: 16  
ps2n0g08.png, Color Type: 2, Bit Depth: 8  
ps2n2c16.png, Color Type: 2, Bit Depth: 16  
s01i3p01.png, Color Type: 2, Bit Depth: 8  
s01n3p01.png, Color Type: 2, Bit Depth: 8  
s02i3p01.png, Color Type: 2, Bit Depth: 8  
s02n3p01.png, Color Type: 2, Bit Depth: 8  
s03i3p01.png, Color Type: 2, Bit Depth: 8  
s03n3p01.png, Color Type: 2, Bit Depth: 8  
s04i3p01.png, Color Type: 2, Bit Depth: 8  
s04n3p01.png, Color Type: 2, Bit Depth: 8  
s05i3p02.png, Color Type: 2, Bit Depth: 8  
s05n3p02.png, Color Type: 2, Bit Depth: 8  
s06i3p02.png, Color Type: 2, Bit Depth: 8  
s06n3p02.png, Color Type: 2, Bit Depth: 8  
s07i3p02.png, Color Type: 2, Bit Depth: 8  
s07n3p02.png, Color Type: 2, Bit Depth: 8  
s08i3p02.png, Color Type: 2, Bit Depth: 8  
s08n3p02.png, Color Type: 2, Bit Depth: 8  
s09i3p02.png, Color Type: 2, Bit Depth: 8  
s09n3p02.png, Color Type: 2, Bit Depth: 8  
s32i3p04.png, Color Type: 2, Bit Depth: 8  
s32n3p04.png, Color Type: 2, Bit Depth: 8  
s33i3p04.png, Color Type: 2, Bit Depth: 8  
s33n3p04.png, Color Type: 2, Bit Depth: 8  
s34i3p04.png, Color Type: 2, Bit Depth: 8  
s34n3p04.png, Color Type: 2, Bit Depth: 8  
s35i3p04.png, Color Type: 2, Bit Depth: 8  
s35n3p04.png, Color Type: 2, Bit Depth: 8  
s36i3p04.png, Color Type: 2, Bit Depth: 8  
s36n3p04.png, Color Type: 2, Bit Depth: 8  
s37i3p04.png, Color Type: 2, Bit Depth: 8  
s37n3p04.png, Color Type: 2, Bit Depth: 8  
s38i3p04.png, Color Type: 2, Bit Depth: 8  
s38n3p04.png, Color Type: 2, Bit Depth: 8  
s39i3p04.png, Color Type: 2, Bit Depth: 8  
s39n3p04.png, Color Type: 2, Bit Depth: 8  
s40i3p04.png, Color Type: 2, Bit Depth: 8  
s40n3p04.png, Color Type: 2, Bit Depth: 8  
tp0n1g08.png, Color Type: 2, Bit Depth: 8  
tp0n2c08.png, Color Type: 2, Bit Depth: 8  
tp0n3p08.png, Color Type: 2, Bit Depth: 8  




Images with fatal issues: Other than corrupted images (the x series in PngSuite) all images that cause PNGwriter to fail are ones for which the transparency chunk was set (tp0n1g08.png, tp0n2c08.png and tp0n3p08.png, which render perfectly, are reference images with no transparency). From the PngSuite reference:

3.5     Transparency (and background) test files
------------------------------------------------

        tp0n1g08    -   not transparent for reference (logo on gray)
        tbbn1g04    -   transparent, black background chunk
        tbwn1g16    -   transparent, white background chunk
        tp0n2c08    -   not transparent for reference (logo on gray)
        tbrn2c08    -   transparent, red background chunk
        tbgn2c16    -   transparent, green background chunk
        tbbn2c16    -   transparent, blue background chunk
        tp0n3p08    -   not transparent for reference (logo on gray)
        tp1n3p08    -   transparent, but no background chunk
        tbbn3p08    -   transparent, black background chunk
        tbgn3p08    -   transparent, light-gray background chunk
        tbwn3p08    -   transparent, white background chunk
        tbyn3p08    -   transparent, yellow background chunk

3.12     Corrupted files
-----------------------

        x00n0g01    -   empty 0x0 grayscale file
        xcrn0g04    -   added cr bytes
        xlfn0g04    -   added lf bytes
        


Before
After
Filename, color type and bit depth
as reported by PNGwriter
Reported errors
tbbn1g04.png, Color Type: 6, Bit Depth: 8 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
tbbn2c16.png, Color Type: 2, Bit Depth: 16  
tbbn3p08.png, Color Type: 6, Bit Depth: 8 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
tbgn2c16.png, Color Type: 2, Bit Depth: 16  
tbgn3p08.png, Color Type: 6, Bit Depth: 8 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
tbrn2c08.png, Color Type: 2, Bit Depth: 8  
tbwn1g16.png, Color Type: 6, Bit Depth: 16 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
tbwn3p08.png, Color Type: 6, Bit Depth: 8 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
tbyn3p08.png, Color Type: 6, Bit Depth: 8 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
tp1n3p08.png, Color Type: 6, Bit Depth: 8 PNGwriter::readfromfile() - WARNING **: Input file is of unsupported type (bad color_type). Output will be unpredictable.
x00n0g01.png, Color Type: 2, Bit Depth: 16 PNGwriter::read_png_info - ERROR **: This file may be a corrupted PNG file. (setjmp(*png_ptr)->jmpbf) failed).
PNGwriter::readfromfile - ERROR **: Error opening file x00n0g01.png. read_png_info() failed.
libpng error: Image width or height is zero in IHDR
xcrn0g04.png, Color Type: 2, Bit Depth: 16 PNGwriter::readfromfile - ERROR **: Error opening file xcrn0g04.png. read_png_info() failed.
PNGwriter::read_png_info - ERROR **: This file may be a corrupted PNG file. (setjmp(*png_ptr)->jmpbf) failed).
libpng error: PNG file corrupted by ASCII conversion
xlfn0g04.png, Color Type: 2, Bit Depth: 16 PNGwriter::read_png_info - ERROR **: This file may be a corrupted PNG file. (setjmp(*png_ptr)->jmpbf) failed). libpng error: PNG file corrupted by ASCII conversion.
PNGwriter::readfromfile - ERROR **: Error opening file xlfn0g04.png. read_png_info() failed.




Images that render with slight tone issues:

Before
After
Filename, color type and bit depth
as reported by PNGwriter
Reported errors
basi0g02.png, Color Type: 2, Bit Depth: 8  
basn0g02.png, Color Type: 2, Bit Depth: 8  
ccwn2c08.png, Color Type: 2, Bit Depth: 8  
ccwn3p08.png, Color Type: 2, Bit Depth: 8  
f00n0g08.png, Color Type: 2, Bit Depth: 8  
f00n2c08.png, Color Type: 2, Bit Depth: 8  
f01n0g08.png, Color Type: 2, Bit Depth: 8  
f01n2c08.png, Color Type: 2, Bit Depth: 8  
f02n0g08.png, Color Type: 2, Bit Depth: 8  
f02n2c08.png, Color Type: 2, Bit Depth: 8  
f03n0g08.png, Color Type: 2, Bit Depth: 8  
f03n2c08.png, Color Type: 2, Bit Depth: 8  
f04n0g08.png, Color Type: 2, Bit Depth: 8  
f04n2c08.png, Color Type: 2, Bit Depth: 8  
z00n2c08.png, Color Type: 2, Bit Depth: 8  
z03n2c08.png, Color Type: 2, Bit Depth: 8  
z06n2c08.png, Color Type: 2, Bit Depth: 8  
z09n2c08.png, Color Type: 2, Bit Depth: 8  




Images for which transparency information is discarded:

Before
After
Filename, color type and bit depth
as reported by PNGwriter
Reported errors
basi4a08.png, Color Type: 2, Bit Depth: 8  
basi4a16.png, Color Type: 2, Bit Depth: 16  
basi6a08.png, Color Type: 2, Bit Depth: 8  
basi6a16.png, Color Type: 2, Bit Depth: 16  
basn4a08.png, Color Type: 2, Bit Depth: 8  
basn4a16.png, Color Type: 2, Bit Depth: 16  
basn6a08.png, Color Type: 2, Bit Depth: 8  
basn6a16.png, Color Type: 2, Bit Depth: 16  
bgai4a08.png, Color Type: 2, Bit Depth: 8  
bgai4a16.png, Color Type: 2, Bit Depth: 16  
bgan6a08.png, Color Type: 2, Bit Depth: 8  
bgan6a16.png, Color Type: 2, Bit Depth: 16  
bgbn4a08.png, Color Type: 2, Bit Depth: 8  
bggn4a16.png, Color Type: 2, Bit Depth: 16  
bgwn6a08.png, Color Type: 2, Bit Depth: 8  
bgyn6a16.png, Color Type: 2, Bit Depth: 16  
pp0n6a08.png, Color Type: 2, Bit Depth: 8  



What follows is a small program that will open a file and then write it out to disk with a similar filename, making it easy to search for cases of unexpected behaviour. Also included is a shellscript, so you can automate the process on a directory of files.

Here's the code:
#include <pngwriter.h>
#include <stdlib.h>
#include <string>

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{

	   string filename(argv[1]);
	//filename = (*(argv+1));
	if(argc!=2)
	{

	return 0;
	}
	
	pngwriter image(1, 1, 0, "out.png");

    image.readfromfile(argv[1]);
   
   // Rename the file, add -mod to the basename.
   char * newfilename;

   char fl[1024];
   strcpy(fl, filename.c_str());

   newfilename = strtok (fl, "." );
   strcat(newfilename, "-mod.png" ); 
   image.pngwriter_rename(newfilename);



   std::cout << "File Name: " << argv[1] << ",  Color Type: " << image.getcolortype() << ", Bit Depth: " << image.getbitdepth() << std::endl;

   
   image.close();
	return 0;   
}


And here's the shellscript.

#!/bin/bash

for caca in *.png
  do
  base=`basename $caca .png`
  png=${base}.png
  ./readfromfile-test $png
#  echo "Finished " ${base}-mod.jpg
done