diff --git a/picksmaller b/picksmaller new file mode 100755 index 000000000..3c73a446b --- /dev/null +++ b/picksmaller @@ -0,0 +1,27 @@ +#!/bin/sh + +# For use in the pngzop project +# Copyright 2013 by Glenn Randers-Pehrson +# Released under the pngcrush license (equivalent to the libpng license) + +# Selects the smaller of file.zdat (extracted from a PNG) or +# file.idat.zlib (same but recompressed with zopfli) + +# picksmall file1 file2 + +for file in $* +do +file1=$1 +file2=`echo $file1 | sed -e "s/zdat/idat.zlib/"` +shift + +size1=`ls -l $file1 | sed -e "s/[^ ]* [^ ]* [^ ]* [^ ]* //" -e "s/ .*//"` +size2=`ls -l $file2 | sed -e "s/[^ ]* [^ ]* [^ ]* [^ ]* //" -e "s/ .*//"` + +if [ $size1 -le $size2 ] ; then +echo $file1 +else +echo $file2 +fi + +done diff --git a/pngidat b/pngidat index 327acd26b..a2b1f49de 100644 --- a/pngidat +++ b/pngidat @@ -1,5 +1,12 @@ #!/bin/sh +# For use in the pngzop project +# Copyright 2013 by Glenn Randers-Pehrson +# Released under the pngcrush license (equivalent to the libpng license) + +# Extracts and decompresses the data from the IDAT chunks in a set of +# PNG files. + for x in $* do root=`echo $1 | sed -e s/.png$//` diff --git a/pngidat.c b/pngidat.c index 0ca30ac09..6f4792cb1 100644 --- a/pngidat.c +++ b/pngidat.c @@ -1,18 +1,21 @@ #include -/* Copyright 2013 Glenn Randers-Pehrson */ +/* Copyright 2013 Glenn Randers-Pehrson + * Released under the pngcrush license (equivalent to the libpng license) + */ /* Usage: - * pngidat.exe < file.png | pigz -d > file.idat + * pngidat.exe < file.png > file.zdat + * + * file.idat is the zlib datastream from the PNG IDAT chunks. * - * file.idat is the image datastream, with the filter bytes. */ main() { - int i; - int buf[5]; - int c; + unsigned int i; + unsigned int buf[5]; + unsigned int c; buf[4]='\0'; @@ -23,7 +26,7 @@ main() for (;;) { /* read length */ - int length; + unsigned int length; buf[0]=getchar(); if (buf[0] == EOF) break; @@ -46,7 +49,9 @@ for (;;) break; putchar(c); } - /* skip crc byte */ + if (c == EOF) + break; + /* skip crc bytes */ for (i=4; i; i--) { c=getchar(); @@ -59,7 +64,13 @@ for (;;) else { for (i=length+4; i; i--) + { c=getchar(); + if (c == EOF) + break; + } + if (c == EOF) + break; } } } diff --git a/pngzdat b/pngzdat index 7631d48ab..a51cdba76 100755 --- a/pngzdat +++ b/pngzdat @@ -1,5 +1,11 @@ #!/bin/sh +# For use in the pngzop project +# Copyright 2013 by Glenn Randers-Pehrson +# Released under the pngcrush license (equivalent to the libpng license) + +# Extracts the data from the IDAT chunks in a set of # PNG files. + for x in $* do root=`echo $1 | sed -e s/.png$//`