Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Commit 337d27f

Browse files
committed
ZopfliPNG
1 parent 79e6e0c commit 337d27f

14 files changed

Lines changed: 9731 additions & 4 deletions

‎README‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ zopfli_bin.c is separate from the library and contains an example program to
2525
create very well compressed gzip files. Currently the makefile builds this
2626
program with the library statically linked in.
2727

28+
To build the binary, use "make". To build the library as a shared Linux library,
29+
use "make libzopfli". The source code of Zopfli is under src/zopfli.
30+
2831
Zopfli Compression Algorithm was created by Lode Vandevenne and Jyrki
2932
Alakuijala, based on an algorithm by Jyrki Alakuijala.

‎README.zopflipng‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ZopfliPNG is a command line program to optimize the Portable Network Graphics
2+
(PNG) images. This version has the following features:
3+
- uses Zopfli compression for the Deflate compression,
4+
- compares several strategies for choosing scanline filter codes,
5+
- chooses a suitable color type to losslessly encode the image,
6+
- removes all chunks that are unimportant for the typical web use (metadata,
7+
text, etc...),
8+
- optionally alters the hidden colors of fully transparent pixels for more
9+
compression, and,
10+
- optionally converts 16-bit color channels to 8-bit.
11+
12+
This is an alpha-release for testing while improvements, particularly to add
13+
palette selection, are still being made. Feedback and bug reports are welcome.
14+
15+
To build ZopfliPNG, use "make zopflipng", or compile all the sources except
16+
zopfli_bin.c.
17+
18+
The main compression algorithm in ZopfliPNG is ported from WebP lossless, but
19+
naturally cannot give as much compression gain for PNGs as it does for a more
20+
modern compression codec like WebP
21+
https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification.
22+
23+
Compared to libpng -- an often used PNG encoder implementation -- ZopfliPNG uses
24+
2-3 orders of magnitude more CPU time for compression. Initial testing using a
25+
corpus of 1000 PNGs with translucency, randomly selected from the internet,
26+
gives a compression improvement of 12% compared to convert -q 95, but only 0.5%
27+
compared to pngout (from better of /f0 and /f5 runs).
28+
29+
By releasing this software we hope to make images on the web load faster without
30+
a new image format, but the opportunities for optimization within PNG are
31+
limited. When targeting Android, Chrome, Opera, and Yandex browsers, or by using
32+
suitable plugins for other browsers, it is good to note that WebP lossless
33+
images are still 26 % smaller than images recompressed with ZopfliPNG.
34+
35+
2013-05-07, Lode Vandevenne and Jyrki Alakuijala

‎makefile‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
make:
2-
gcc src/zopfli/*.c -O2 -W -Wall -Wextra -ansi -pedantic -lm -o zopfli
1+
CC = gcc
2+
CXX = g++
33

4-
debug:
5-
gcc src/zopfli/*.c -g3 -lm -o zopfli
4+
CFLAGS = -W -Wall -Wextra -ansi -pedantic -lm -O2
5+
CXXFLAGS = -W -Wall -Wextra -ansi -pedantic -O2
6+
7+
ZOPFLILIB_SRC = src/zopfli/blocksplitter.c src/zopfli/cache.c\
8+
src/zopfli/deflate.c src/zopfli/gzip_container.c\
9+
src/zopfli/hash.c src/zopfli/katajainen.c\
10+
src/zopfli/lz77.c src/zopfli/squeeze.c\
11+
src/zopfli/tree.c src/zopfli/util.c\
12+
src/zopfli/zlib_container.c src/zopfli/zopfli_lib.c
13+
ZOPFLILIB_OBJ := $(patsubst src/zopfli/%.c,%.o,$(ZOPFLILIB_SRC))
14+
ZOPFLIBIN_SRC := src/zopfli/zopfli_bin.c
15+
LODEPNG_SRC := src/zopflipng/lodepng/lodepng.cpp src/zopflipng/lodepng/lodepng_util.cpp
16+
ZOPFLIPNGLIB_SRC := src/zopflipng/zopflipng_lib.cc
17+
ZOPFLIPNGBIN_SRC := src/zopflipng/zopflipng_bin.cc
18+
19+
.PHONY: zopfli zopflipng
20+
21+
# Zopfli binary
22+
zopfli:
23+
$(CC) $(ZOPFLILIB_SRC) $(ZOPFLIBIN_SRC) $(CFLAGS) -o zopfli
24+
25+
# Zopfli shared library
26+
libzopfli:
27+
$(CC) $(ZOPFLILIB_SRC) $(CFLAGS) -fPIC -c
28+
$(CC) $(ZOPFLILIB_OBJ) $(CFLAGS) -shared -Wl,-soname,libzopfli.so.1 -o libzopfli.so.1.0.1
29+
30+
# ZopfliPNG binary
31+
zopflipng:
32+
$(CC) $(ZOPFLILIB_SRC) $(CFLAGS) -c
33+
$(CXX) $(ZOPFLILIB_OBJ) $(LODEPNG_SRC) $(ZOPFLIPNGLIB_SRC) $(ZOPFLIPNGBIN_SRC) $(CFLAGS) -o zopflipng
34+
35+
# Remove all libraries and binaries
36+
clean:
37+
rm -f zopflipng zopfli $(ZOPFLILIB_OBJ) libzopfli*

‎src/zopfli/deflate.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Functions to compress according to the DEFLATE specification, using the
2727

2828
#include "zopfli.h"
2929

30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
3034
/*
3135
Compresses according to the deflate specification and append the compressed
3236
result to the output.
@@ -74,4 +78,9 @@ lend: end of block (not inclusive)
7478
double ZopfliCalculateBlockSize(const unsigned short* litlens,
7579
const unsigned short* dists,
7680
size_t lstart, size_t lend, int btype);
81+
82+
#ifdef __cplusplus
83+
} // extern "C"
84+
#endif
85+
7786
#endif /* ZOPFLI_DEFLATE_H_ */

‎src/zopfli/gzip_container.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Functions to compress according to the Gzip specification.
2626

2727
#include "zopfli.h"
2828

29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
2933
/*
3034
Compresses according to the gzip specification and append the compressed
3135
result to the output.
@@ -39,4 +43,8 @@ void ZopfliGzipCompress(const ZopfliOptions* options,
3943
const unsigned char* in, size_t insize,
4044
unsigned char** out, size_t* outsize);
4145

46+
#ifdef __cplusplus
47+
} // extern "C"
48+
#endif
49+
4250
#endif /* ZOPFLI_GZIP_H_ */

‎src/zopfli/zlib_container.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Functions to compress according to the Zlib specification.
2626

2727
#include "zopfli.h"
2828

29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
2933
/*
3034
Compresses according to the zlib specification and append the compressed
3135
result to the output.
@@ -39,4 +43,8 @@ void ZopfliZlibCompress(const ZopfliOptions* options,
3943
const unsigned char* in, size_t insize,
4044
unsigned char** out, size_t* outsize);
4145

46+
#ifdef __cplusplus
47+
} // extern "C"
48+
#endif
49+
4250
#endif /* ZOPFLI_ZLIB_H_ */

‎src/zopfli/zopfli.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
2323
#include <stddef.h>
2424
#include <stdlib.h> /* for size_t */
2525

26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
2630
/*
2731
Options used throughout the program.
2832
*/
@@ -86,4 +90,8 @@ void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type,
8690
const unsigned char* in, size_t insize,
8791
unsigned char** out, size_t* outsize);
8892

93+
#ifdef __cplusplus
94+
} // extern "C"
95+
#endif
96+
8997
#endif /* ZOPFLI_ZOPFLI_H_ */

0 commit comments

Comments
 (0)