[pngzop] Added picksmaller script, added license info.

This commit is contained in:
Glenn Randers-Pehrson
2013-03-06 12:39:12 -06:00
parent 3aeca85c4c
commit 56f554022e
4 changed files with 59 additions and 8 deletions

27
picksmaller Executable file
View File

@@ -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

View File

@@ -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$//`

View File

@@ -1,18 +1,21 @@
#include <stdio.h>
/* 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;
}
}
}

View File

@@ -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$//`