Permalink
Browse files

ZopfliPNG

  • Loading branch information...
lvandeve committed May 7, 2013
1 parent 79e6e0c commit 337d27f25ef15a6cf34fef2acd0613fddc411cb1
View
3 README
@@ -25,5 +25,8 @@ zopfli_bin.c is separate from the library and contains an example program to
create very well compressed gzip files. Currently the makefile builds this
program with the library statically linked in.
To build the binary, use "make". To build the library as a shared Linux library,
use "make libzopfli". The source code of Zopfli is under src/zopfli.
Zopfli Compression Algorithm was created by Lode Vandevenne and Jyrki
Alakuijala, based on an algorithm by Jyrki Alakuijala.
View
@@ -0,0 +1,35 @@
ZopfliPNG is a command line program to optimize the Portable Network Graphics
(PNG) images. This version has the following features:
- uses Zopfli compression for the Deflate compression,
- compares several strategies for choosing scanline filter codes,
- chooses a suitable color type to losslessly encode the image,
- removes all chunks that are unimportant for the typical web use (metadata,
text, etc...),
- optionally alters the hidden colors of fully transparent pixels for more
compression, and,
- optionally converts 16-bit color channels to 8-bit.
This is an alpha-release for testing while improvements, particularly to add
palette selection, are still being made. Feedback and bug reports are welcome.
To build ZopfliPNG, use "make zopflipng", or compile all the sources except
zopfli_bin.c.
The main compression algorithm in ZopfliPNG is ported from WebP lossless, but
naturally cannot give as much compression gain for PNGs as it does for a more
modern compression codec like WebP
https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification.
Compared to libpng -- an often used PNG encoder implementation -- ZopfliPNG uses
2-3 orders of magnitude more CPU time for compression. Initial testing using a
corpus of 1000 PNGs with translucency, randomly selected from the internet,
gives a compression improvement of 12% compared to convert -q 95, but only 0.5%
compared to pngout (from better of /f0 and /f5 runs).
By releasing this software we hope to make images on the web load faster without
a new image format, but the opportunities for optimization within PNG are
limited. When targeting Android, Chrome, Opera, and Yandex browsers, or by using
suitable plugins for other browsers, it is good to note that WebP lossless
images are still 26 % smaller than images recompressed with ZopfliPNG.
2013-05-07, Lode Vandevenne and Jyrki Alakuijala
View
@@ -1,5 +1,37 @@
make:
gcc src/zopfli/*.c -O2 -W -Wall -Wextra -ansi -pedantic -lm -o zopfli
CC = gcc
CXX = g++
debug:
gcc src/zopfli/*.c -g3 -lm -o zopfli
CFLAGS = -W -Wall -Wextra -ansi -pedantic -lm -O2
CXXFLAGS = -W -Wall -Wextra -ansi -pedantic -O2
ZOPFLILIB_SRC = src/zopfli/blocksplitter.c src/zopfli/cache.c\
src/zopfli/deflate.c src/zopfli/gzip_container.c\
src/zopfli/hash.c src/zopfli/katajainen.c\
src/zopfli/lz77.c src/zopfli/squeeze.c\
src/zopfli/tree.c src/zopfli/util.c\
src/zopfli/zlib_container.c src/zopfli/zopfli_lib.c
ZOPFLILIB_OBJ := $(patsubst src/zopfli/%.c,%.o,$(ZOPFLILIB_SRC))
ZOPFLIBIN_SRC := src/zopfli/zopfli_bin.c
LODEPNG_SRC := src/zopflipng/lodepng/lodepng.cpp src/zopflipng/lodepng/lodepng_util.cpp
ZOPFLIPNGLIB_SRC := src/zopflipng/zopflipng_lib.cc
ZOPFLIPNGBIN_SRC := src/zopflipng/zopflipng_bin.cc
.PHONY: zopfli zopflipng
# Zopfli binary
zopfli:
$(CC) $(ZOPFLILIB_SRC) $(ZOPFLIBIN_SRC) $(CFLAGS) -o zopfli
# Zopfli shared library
libzopfli:
$(CC) $(ZOPFLILIB_SRC) $(CFLAGS) -fPIC -c
$(CC) $(ZOPFLILIB_OBJ) $(CFLAGS) -shared -Wl,-soname,libzopfli.so.1 -o libzopfli.so.1.0.1
# ZopfliPNG binary
zopflipng:
$(CC) $(ZOPFLILIB_SRC) $(CFLAGS) -c
$(CXX) $(ZOPFLILIB_OBJ) $(LODEPNG_SRC) $(ZOPFLIPNGLIB_SRC) $(ZOPFLIPNGBIN_SRC) $(CFLAGS) -o zopflipng
# Remove all libraries and binaries
clean:
rm -f zopflipng zopfli $(ZOPFLILIB_OBJ) libzopfli*
View
@@ -27,6 +27,10 @@ Functions to compress according to the DEFLATE specification, using the
#include "zopfli.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Compresses according to the deflate specification and append the compressed
result to the output.
@@ -74,4 +78,9 @@ lend: end of block (not inclusive)
double ZopfliCalculateBlockSize(const unsigned short* litlens,
const unsigned short* dists,
size_t lstart, size_t lend, int btype);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* ZOPFLI_DEFLATE_H_ */
@@ -26,6 +26,10 @@ Functions to compress according to the Gzip specification.
#include "zopfli.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Compresses according to the gzip specification and append the compressed
result to the output.
@@ -39,4 +43,8 @@ void ZopfliGzipCompress(const ZopfliOptions* options,
const unsigned char* in, size_t insize,
unsigned char** out, size_t* outsize);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* ZOPFLI_GZIP_H_ */
@@ -26,6 +26,10 @@ Functions to compress according to the Zlib specification.
#include "zopfli.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Compresses according to the zlib specification and append the compressed
result to the output.
@@ -39,4 +43,8 @@ void ZopfliZlibCompress(const ZopfliOptions* options,
const unsigned char* in, size_t insize,
unsigned char** out, size_t* outsize);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* ZOPFLI_ZLIB_H_ */
View
@@ -23,6 +23,10 @@ Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
#include <stddef.h>
#include <stdlib.h> /* for size_t */
#ifdef __cplusplus
extern "C" {
#endif
/*
Options used throughout the program.
*/
@@ -86,4 +90,8 @@ void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type,
const unsigned char* in, size_t insize,
unsigned char** out, size_t* outsize);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* ZOPFLI_ZOPFLI_H_ */
Oops, something went wrong.

0 comments on commit 337d27f

Please sign in to comment.