mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[pngzop] Renamed scripts to reflect what they do.
This commit is contained in:
18
move_best
18
move_best
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# For use in the pngzop project
|
|
||||||
# Copyright 2013 by Glenn Randers-Pehrson
|
|
||||||
# Released under the pngcrush license (equivalent to the libpng license)
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# move_best *.zdat
|
|
||||||
# assumes that for each *.zdat, *.idat.zlib exists
|
|
||||||
#
|
|
||||||
# moves the smaller of root.zdat or root.idat.zlib
|
|
||||||
# to root.best
|
|
||||||
|
|
||||||
for file in $*
|
|
||||||
do
|
|
||||||
root=`echo $file | sed -e "s/.zdat$//"`
|
|
||||||
cp `picksmaller $root.zdat` $root.best
|
|
||||||
done
|
|
||||||
23
pngidat
23
pngidat
@@ -1,23 +0,0 @@
|
|||||||
#!/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
|
|
||||||
case $1 in
|
|
||||||
*.png)
|
|
||||||
root=`echo $1 | sed -e "s/.png$//"`
|
|
||||||
pngidat.exe < $1 | zpipe -d > $root.idat
|
|
||||||
;;
|
|
||||||
*.zdat)
|
|
||||||
root=`echo $1 | sed -e "s/.zdat$//"`
|
|
||||||
zpipe -d < $1 > $root.idat
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
14
pngzdat
14
pngzdat
@@ -1,14 +0,0 @@
|
|||||||
#!/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$//`
|
|
||||||
pngidat.exe < $1 > $root.zdat
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
13
pngzop
13
pngzop
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# pngzop file.png > file_pz.png
|
|
||||||
|
|
||||||
for f in 0 1 2 3 4 5
|
|
||||||
do
|
|
||||||
rm -f pngzop-f$f-$$.png
|
|
||||||
pngcrush -q -m 1 -f $f -force $1 pngzop-f$f-$$.png
|
|
||||||
pngidat pngzop-f$f-$$.png
|
|
||||||
zopfli --i25 --zlib pngzop-f$f-$$.idat
|
|
||||||
done
|
|
||||||
cat `ls -S pngzop-f?-$$.idat.zlib | tail -1`
|
|
||||||
rm pngzop-f?-$$.png pngzop-f?-$$.idat pngzop-f?-$$.idat.zlib
|
|
||||||
28
pngzop-try
28
pngzop-try
@@ -1,28 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# pngzop-try
|
|
||||||
|
|
||||||
# usage: pngzop-try dir ...
|
|
||||||
|
|
||||||
# runs pngzop on each PNG file in a set of directories
|
|
||||||
|
|
||||||
# For use in the pngzop project
|
|
||||||
# Copyright 2013 by Glenn Randers-Pehrson
|
|
||||||
# Released under the pngcrush license (equivalent to the libpng license)
|
|
||||||
|
|
||||||
# From a PNG file, finds the smallest resulting compressed IDAT
|
|
||||||
# data from zopfli compression of filter types 0 through 4 and
|
|
||||||
# "adaptive" (f5) filtering.
|
|
||||||
|
|
||||||
for dir in $*
|
|
||||||
do
|
|
||||||
(
|
|
||||||
cd $dir
|
|
||||||
for n in *.png
|
|
||||||
do
|
|
||||||
pngzop $n > $n.zop
|
|
||||||
pngcrush -brute -force $n $n.bf.png
|
|
||||||
pngzdat $n.bf.png
|
|
||||||
done
|
|
||||||
)
|
|
||||||
done
|
|
||||||
@@ -3,4 +3,7 @@
|
|||||||
This is the pngzop branch of the "pmt" tree.
|
This is the pngzop branch of the "pmt" tree.
|
||||||
Code for supporting the "zopfli" compression method
|
Code for supporting the "zopfli" compression method
|
||||||
in PNG files will appear here.
|
in PNG files will appear here.
|
||||||
|
|
||||||
|
Eventually this collection of scripts will be incorporated
|
||||||
|
into pngcrush.
|
||||||
*/
|
*/
|
||||||
27
pngzop_brute.sh
Executable file
27
pngzop_brute.sh
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# pngzop_brute.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 concatenated data from the IDAT chunks in a set of PNG files,
|
||||||
|
# leaving it compressed as found.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# pngzop_brute *.png
|
||||||
|
|
||||||
|
# Standard Input: *.png
|
||||||
|
# Output: *_zop.png
|
||||||
|
|
||||||
|
for x in $*
|
||||||
|
do
|
||||||
|
root=`echo $1 | sed -e s/.png$//`
|
||||||
|
pngzop_get_ihdr.exe < $1 > ${root}_pngzop_brute.png
|
||||||
|
pngzop_brute_zopfli.sh $1
|
||||||
|
pngzop_zlib_to_idat.exe < ${root}.zlib >> ${root}_pngzop_brute.png
|
||||||
|
rm ${root}.zlib
|
||||||
|
pngzop_get_iend.exe < $1 >> ${root}_pngzop_brute.png
|
||||||
|
shift
|
||||||
|
done
|
||||||
47
pngzop_brute_zopfli.sh
Executable file
47
pngzop_brute_zopfli.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# png_brute_zopfli.sh
|
||||||
|
|
||||||
|
# For use in the pngzop project
|
||||||
|
# Copyright 2013 by Glenn Randers-Pehrson
|
||||||
|
# Released under the pngcrush license (equivalent to the libpng license)
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# png_brute_zopfli.sh file.png [...]
|
||||||
|
|
||||||
|
# Input: *.png, a set of PNG files
|
||||||
|
# Output: *.zlib, zopfli-compressed IDAT data
|
||||||
|
|
||||||
|
for x in $*
|
||||||
|
do
|
||||||
|
root=`echo $1 | sed -e "s/.png$//"`
|
||||||
|
|
||||||
|
# Generate trial PNGs with filter none, 4 PNG filters, and adaptive filter
|
||||||
|
for f in 0 1 2 3 4 5
|
||||||
|
do
|
||||||
|
pngcrush -q -m 1 -f $f -force $1 ${root}_f$f.png &
|
||||||
|
done
|
||||||
|
wait
|
||||||
|
|
||||||
|
# Extract and decompress the zlib datastream from the concatenated IDAT chunks.
|
||||||
|
for f in 0 1 2 3 4 5
|
||||||
|
do
|
||||||
|
pngzop_get_idat.exe < ${root}_f$f.png | zpipe -d > ${root}_f$f.idat &
|
||||||
|
done
|
||||||
|
wait
|
||||||
|
rm -f ${root}_f?.png
|
||||||
|
|
||||||
|
# Recompress the IDAT data using zopfli
|
||||||
|
for f in 0 1 2 3 4 5
|
||||||
|
do
|
||||||
|
zopfli --i25 --zlib ${root}_f$f.idat &
|
||||||
|
done
|
||||||
|
wait
|
||||||
|
rm -f ${root}_f?.idat
|
||||||
|
|
||||||
|
# Copy the smallest result to file.zlib
|
||||||
|
cat `ls -S ${root}_f?.idat.zlib | tail -1` > ${root}.zlib
|
||||||
|
rm -f ${root}_f?.idat.zlib
|
||||||
|
|
||||||
|
shift
|
||||||
|
done
|
||||||
22
pngzop_get_idat.sh
Normal file
22
pngzop_get_idat.sh
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# png_get_idat.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.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# png_get_idat.sh file.png
|
||||||
|
|
||||||
|
# Output: file.idat
|
||||||
|
|
||||||
|
for x in $*
|
||||||
|
do
|
||||||
|
root=`echo $1 | sed -e "s/.png$//"`
|
||||||
|
pngzop_get_idat.exe < $1 | zpipe -d > $root.idat
|
||||||
|
shift
|
||||||
|
done
|
||||||
22
pngzop_get_zdat.sh
Executable file
22
pngzop_get_zdat.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# pngzop_get_zdat.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 concatenated data from the IDAT chunks in a set of PNG files,
|
||||||
|
# leaving it compressed as found.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# pngzop_get_zdat.sh file.png
|
||||||
|
|
||||||
|
# Output: file.zdat
|
||||||
|
|
||||||
|
for x in $*
|
||||||
|
do
|
||||||
|
root=`echo $1 | sed -e s/.png$//`
|
||||||
|
pngzop_get_idat.exe < $1 > $root.zdat
|
||||||
|
shift
|
||||||
|
done
|
||||||
25
pngzop_pngcrush.sh
Executable file
25
pngzop_pngcrush.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# pngzop_pngcrush.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 concatenated data from the IDAT chunks in a set of PNG files,
|
||||||
|
# leaving it compressed as found.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# pngzop_pngcrush.sh *.png
|
||||||
|
|
||||||
|
# Standard Input: *.png
|
||||||
|
# Output: *_zop.png
|
||||||
|
|
||||||
|
for x in $*
|
||||||
|
do
|
||||||
|
root=`echo $1 | sed -e s/.png$//`
|
||||||
|
pngzop_get_ihdr.exe < $1 > ${root}_pngzop.png
|
||||||
|
pngzop_pngcrush_zopfli.sh $1 | pngzop_zlib_to_idat.exe >> ${root}_pngzop.png
|
||||||
|
pngzop_get_iend.exe < $1 >> ${root}_pngzop.png
|
||||||
|
shift
|
||||||
|
done
|
||||||
29
pngzop_pngcrush_zopfli.sh
Executable file
29
pngzop_pngcrush_zopfli.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# For use in the pngzop project
|
||||||
|
# Copyright 2013 by Glenn Randers-Pehrson
|
||||||
|
# Released under the pngcrush license (equivalent to the libpng license)
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# pngzop_pngcrush_zopfli.sh file.png > file.zlib
|
||||||
|
|
||||||
|
# file.png is a PNG file.
|
||||||
|
# Standard output is the uncompressed IDAT chunk data, recompressed as a zlib
|
||||||
|
# datastream.
|
||||||
|
|
||||||
|
root=`echo $1 | sed -e "s/.png$//"`
|
||||||
|
rm -f ${root}_L9.png
|
||||||
|
|
||||||
|
# Do pngcrush level 9 with none, 4 filters, and adaptive filtering, and
|
||||||
|
# select the smallest.
|
||||||
|
pngcrush -q -m 113 -m 114 -m 115 -m 116 -m 117 -m 118 \
|
||||||
|
-force $1 ${root}_L9.png
|
||||||
|
|
||||||
|
# Extract and decompress the zlib datastream from the concatenated IDAT chunks.
|
||||||
|
pngzop_get_idat.exe < ${root}_L9.png | zpipe -d > ${root}_L9.idat
|
||||||
|
rm ${root}_L9.png
|
||||||
|
|
||||||
|
# Recompress with zopfli and write it on standard output.
|
||||||
|
zopfli --i25 --zlib -c ${root}_L9.idat
|
||||||
|
|
||||||
|
rm ${root}_L9.idat
|
||||||
95
pngzop_zlib_to_idat.c
Normal file
95
pngzop_zlib_to_idat.c
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/* pngzopz2i */
|
||||||
|
|
||||||
|
/* Copyright 2013 Glenn Randers-Pehrson
|
||||||
|
* Released under the pngcrush license (equivalent to the libpng license)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Usage:
|
||||||
|
* pngzop_zlib_to_idat < file.zlib > file_out.idat
|
||||||
|
*
|
||||||
|
* file.zlib is the zlib datastream from zopli --zlib file_in.idat
|
||||||
|
* file_out.idat is the zlib datastream enclosed in PNG IDAT chunks.
|
||||||
|
* This is a single file that may contain multiple IDAT chunks.
|
||||||
|
*
|
||||||
|
* To do: make the maximum IDAT chunk data length an option (currently fixed
|
||||||
|
* at 250000 bytes).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <zlib.h> /* for crc32 */
|
||||||
|
|
||||||
|
void
|
||||||
|
put_uLong(uLong val)
|
||||||
|
{
|
||||||
|
putchar(val >> 24);
|
||||||
|
putchar(val >> 16);
|
||||||
|
putchar(val >> 8);
|
||||||
|
putchar(val >> 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
put_chunk(const unsigned char *chunk, uInt length)
|
||||||
|
{
|
||||||
|
uLong crc;
|
||||||
|
|
||||||
|
put_uLong(length-4); /* Exclude the tag */
|
||||||
|
fwrite(chunk, 1, length, stdout);
|
||||||
|
|
||||||
|
crc = crc32(0, Z_NULL, 0);
|
||||||
|
put_uLong(crc32(crc, chunk, length));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
unsigned char buf[250000];
|
||||||
|
int c;
|
||||||
|
const unsigned char idat[] = { 73, 68, 65, 84 /* "IDAT" */ };
|
||||||
|
int n=6;
|
||||||
|
|
||||||
|
/* IDAT */
|
||||||
|
buf[0]=idat[0];
|
||||||
|
buf[1]=idat[1];
|
||||||
|
buf[2]=idat[2];
|
||||||
|
buf[3]=idat[3];
|
||||||
|
|
||||||
|
/* CMF */
|
||||||
|
c=getchar();
|
||||||
|
if (c != EOF)
|
||||||
|
buf[4]=(unsigned char) c;
|
||||||
|
|
||||||
|
/* FLAGS */
|
||||||
|
if (c != EOF)
|
||||||
|
{
|
||||||
|
c=getchar();
|
||||||
|
if (c != EOF)
|
||||||
|
buf[5]=(unsigned char) c;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c != EOF)
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
/* read up to n=250000 bytes */
|
||||||
|
|
||||||
|
c=getchar();
|
||||||
|
|
||||||
|
if (c != EOF)
|
||||||
|
{
|
||||||
|
buf[n]=(unsigned char) c;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c != EOF && n < 250000)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
put_chunk(buf, n);
|
||||||
|
|
||||||
|
if (c == EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
n=4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user