summaryrefslogtreecommitdiff
path: root/apps/plugins/png
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/png')
-rw-r--r--apps/plugins/png/SOURCES6
-rw-r--r--apps/plugins/png/adler32.c149
-rw-r--r--apps/plugins/png/crc32_png.c423
-rw-r--r--apps/plugins/png/crc32_png.h441
-rw-r--r--apps/plugins/png/inffast.c379
-rw-r--r--apps/plugins/png/inffast.h11
-rw-r--r--apps/plugins/png/inffixed.h94
-rw-r--r--apps/plugins/png/inflate.c1334
-rw-r--r--apps/plugins/png/inflate.h116
-rw-r--r--apps/plugins/png/inftrees.c329
-rw-r--r--apps/plugins/png/inftrees.h55
-rw-r--r--apps/plugins/png/png.c2271
-rw-r--r--apps/plugins/png/png.h366
-rw-r--r--apps/plugins/png/png.make29
-rw-r--r--apps/plugins/png/zconf.h332
-rw-r--r--apps/plugins/png/zlib.h1357
-rw-r--r--apps/plugins/png/zutil.h269
17 files changed, 0 insertions, 7961 deletions
diff --git a/apps/plugins/png/SOURCES b/apps/plugins/png/SOURCES
deleted file mode 100644
index 94805a5623..0000000000
--- a/apps/plugins/png/SOURCES
+++ /dev/null
@@ -1,6 +0,0 @@
1adler32.c
2crc32_png.c
3inffast.c
4inflate.c
5inftrees.c
6png.c
diff --git a/apps/plugins/png/adler32.c b/apps/plugins/png/adler32.c
deleted file mode 100644
index 007ba26277..0000000000
--- a/apps/plugins/png/adler32.c
+++ /dev/null
@@ -1,149 +0,0 @@
1/* adler32.c -- compute the Adler-32 checksum of a data stream
2 * Copyright (C) 1995-2004 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#define ZLIB_INTERNAL
9#include "zlib.h"
10
11#define BASE 65521UL /* largest prime smaller than 65536 */
12#define NMAX 5552
13/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
14
15#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
16#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
17#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
18#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
19#define DO16(buf) DO8(buf,0); DO8(buf,8);
20
21/* use NO_DIVIDE if your processor does not do division in hardware */
22#ifdef NO_DIVIDE
23# define MOD(a) \
24 do { \
25 if (a >= (BASE << 16)) a -= (BASE << 16); \
26 if (a >= (BASE << 15)) a -= (BASE << 15); \
27 if (a >= (BASE << 14)) a -= (BASE << 14); \
28 if (a >= (BASE << 13)) a -= (BASE << 13); \
29 if (a >= (BASE << 12)) a -= (BASE << 12); \
30 if (a >= (BASE << 11)) a -= (BASE << 11); \
31 if (a >= (BASE << 10)) a -= (BASE << 10); \
32 if (a >= (BASE << 9)) a -= (BASE << 9); \
33 if (a >= (BASE << 8)) a -= (BASE << 8); \
34 if (a >= (BASE << 7)) a -= (BASE << 7); \
35 if (a >= (BASE << 6)) a -= (BASE << 6); \
36 if (a >= (BASE << 5)) a -= (BASE << 5); \
37 if (a >= (BASE << 4)) a -= (BASE << 4); \
38 if (a >= (BASE << 3)) a -= (BASE << 3); \
39 if (a >= (BASE << 2)) a -= (BASE << 2); \
40 if (a >= (BASE << 1)) a -= (BASE << 1); \
41 if (a >= BASE) a -= BASE; \
42 } while (0)
43# define MOD4(a) \
44 do { \
45 if (a >= (BASE << 4)) a -= (BASE << 4); \
46 if (a >= (BASE << 3)) a -= (BASE << 3); \
47 if (a >= (BASE << 2)) a -= (BASE << 2); \
48 if (a >= (BASE << 1)) a -= (BASE << 1); \
49 if (a >= BASE) a -= BASE; \
50 } while (0)
51#else
52# define MOD(a) a %= BASE
53# define MOD4(a) a %= BASE
54#endif
55
56/* ========================================================================= */
57uLong ZEXPORT adler32(adler, buf, len)
58 uLong adler;
59 const Bytef *buf;
60 uInt len;
61{
62 unsigned long sum2;
63 unsigned n;
64
65 /* split Adler-32 into component sums */
66 sum2 = (adler >> 16) & 0xffff;
67 adler &= 0xffff;
68
69 /* in case user likes doing a byte at a time, keep it fast */
70 if (len == 1) {
71 adler += buf[0];
72 if (adler >= BASE)
73 adler -= BASE;
74 sum2 += adler;
75 if (sum2 >= BASE)
76 sum2 -= BASE;
77 return adler | (sum2 << 16);
78 }
79
80 /* initial Adler-32 value (deferred check for len == 1 speed) */
81 if (buf == Z_NULL)
82 return 1L;
83
84 /* in case short lengths are provided, keep it somewhat fast */
85 if (len < 16) {
86 while (len--) {
87 adler += *buf++;
88 sum2 += adler;
89 }
90 if (adler >= BASE)
91 adler -= BASE;
92 MOD4(sum2); /* only added so many BASE's */
93 return adler | (sum2 << 16);
94 }
95
96 /* do length NMAX blocks -- requires just one modulo operation */
97 while (len >= NMAX) {
98 len -= NMAX;
99 n = NMAX / 16; /* NMAX is divisible by 16 */
100 do {
101 DO16(buf); /* 16 sums unrolled */
102 buf += 16;
103 } while (--n);
104 MOD(adler);
105 MOD(sum2);
106 }
107
108 /* do remaining bytes (less than NMAX, still just one modulo) */
109 if (len) { /* avoid modulos if none remaining */
110 while (len >= 16) {
111 len -= 16;
112 DO16(buf);
113 buf += 16;
114 }
115 while (len--) {
116 adler += *buf++;
117 sum2 += adler;
118 }
119 MOD(adler);
120 MOD(sum2);
121 }
122
123 /* return recombined sums */
124 return adler | (sum2 << 16);
125}
126
127/* ========================================================================= */
128uLong ZEXPORT adler32_combine(adler1, adler2, len2)
129 uLong adler1;
130 uLong adler2;
131 z_off_t len2;
132{
133 unsigned long sum1;
134 unsigned long sum2;
135 unsigned rem;
136
137 /* the derivation of this formula is left as an exercise for the reader */
138 rem = (unsigned)(len2 % BASE);
139 sum1 = adler1 & 0xffff;
140 sum2 = rem * sum1;
141 MOD(sum2);
142 sum1 += (adler2 & 0xffff) + BASE - 1;
143 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
144 if (sum1 > BASE) sum1 -= BASE;
145 if (sum1 > BASE) sum1 -= BASE;
146 if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
147 if (sum2 > BASE) sum2 -= BASE;
148 return sum1 | (sum2 << 16);
149}
diff --git a/apps/plugins/png/crc32_png.c b/apps/plugins/png/crc32_png.c
deleted file mode 100644
index a76f49d35c..0000000000
--- a/apps/plugins/png/crc32_png.c
+++ /dev/null
@@ -1,423 +0,0 @@
1/* crc32.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995-2005 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 *
5 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
6 * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
7 * tables for updating the shift register in one step with three exclusive-ors
8 * instead of four steps with four exclusive-ors. This results in about a
9 * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
10 */
11
12/* @(#) $Id$ */
13
14/*
15 Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
16 protection on the static variables used to control the first-use generation
17 of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
18 first call get_crc_table() to initialize the tables before allowing more than
19 one thread to use crc32().
20 */
21
22#ifdef MAKECRCH
23# include <stdio.h>
24# ifndef DYNAMIC_CRC_TABLE
25# define DYNAMIC_CRC_TABLE
26# endif /* !DYNAMIC_CRC_TABLE */
27#endif /* MAKECRCH */
28
29#include "zutil.h" /* for STDC and FAR definitions */
30
31#define local static
32
33/* Find a four-byte integer type for crc32_little() and crc32_big(). */
34#ifndef NOBYFOUR
35# ifdef STDC /* need ANSI C limits.h to determine sizes */
36# include <limits.h>
37# define BYFOUR
38# if (UINT_MAX == 0xffffffffUL)
39 typedef unsigned int u4;
40# else
41# if (ULONG_MAX == 0xffffffffUL)
42 typedef unsigned long u4;
43# else
44# if (USHRT_MAX == 0xffffffffUL)
45 typedef unsigned short u4;
46# else
47# undef BYFOUR /* can't find a four-byte integer type! */
48# endif
49# endif
50# endif
51# endif /* STDC */
52#endif /* !NOBYFOUR */
53
54/* Definitions for doing the crc four data bytes at a time. */
55#ifdef BYFOUR
56# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
57 (((w)&0xff00)<<8)+(((w)&0xff)<<24))
58 local unsigned long crc32_little OF((unsigned long,
59 const unsigned char FAR *, unsigned));
60 local unsigned long crc32_big OF((unsigned long,
61 const unsigned char FAR *, unsigned));
62# define TBLS 8
63#else
64# define TBLS 1
65#endif /* BYFOUR */
66
67/* Local functions for crc concatenation */
68local unsigned long gf2_matrix_times OF((unsigned long *mat,
69 unsigned long vec));
70local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
71
72#ifdef DYNAMIC_CRC_TABLE
73
74local volatile int crc_table_empty = 1;
75local unsigned long FAR crc_table[TBLS][256];
76local void make_crc_table OF((void));
77#ifdef MAKECRCH
78 local void write_table OF((FILE *, const unsigned long FAR *));
79#endif /* MAKECRCH */
80/*
81 Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
82 x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
83
84 Polynomials over GF(2) are represented in binary, one bit per coefficient,
85 with the lowest powers in the most significant bit. Then adding polynomials
86 is just exclusive-or, and multiplying a polynomial by x is a right shift by
87 one. If we call the above polynomial p, and represent a byte as the
88 polynomial q, also with the lowest power in the most significant bit (so the
89 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
90 where a mod b means the remainder after dividing a by b.
91
92 This calculation is done using the shift-register method of multiplying and
93 taking the remainder. The register is initialized to zero, and for each
94 incoming bit, x^32 is added mod p to the register if the bit is a one (where
95 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
96 x (which is shifting right by one and adding x^32 mod p if the bit shifted
97 out is a one). We start with the highest power (least significant bit) of
98 q and repeat for all eight bits of q.
99
100 The first table is simply the CRC of all possible eight bit values. This is
101 all the information needed to generate CRCs on data a byte at a time for all
102 combinations of CRC register values and incoming bytes. The remaining tables
103 allow for word-at-a-time CRC calculation for both big-endian and little-
104 endian machines, where a word is four bytes.
105*/
106local void make_crc_table()
107{
108 unsigned long c;
109 int n, k;
110 unsigned long poly; /* polynomial exclusive-or pattern */
111 /* terms of polynomial defining this crc (except x^32): */
112 static volatile int first = 1; /* flag to limit concurrent making */
113 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
114
115 /* See if another task is already doing this (not thread-safe, but better
116 than nothing -- significantly reduces duration of vulnerability in
117 case the advice about DYNAMIC_CRC_TABLE is ignored) */
118 if (first) {
119 first = 0;
120
121 /* make exclusive-or pattern from polynomial (0xedb88320UL) */
122 poly = 0UL;
123 for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
124 poly |= 1UL << (31 - p[n]);
125
126 /* generate a crc for every 8-bit value */
127 for (n = 0; n < 256; n++) {
128 c = (unsigned long)n;
129 for (k = 0; k < 8; k++)
130 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
131 crc_table[0][n] = c;
132 }
133
134#ifdef BYFOUR
135 /* generate crc for each value followed by one, two, and three zeros,
136 and then the byte reversal of those as well as the first table */
137 for (n = 0; n < 256; n++) {
138 c = crc_table[0][n];
139 crc_table[4][n] = REV(c);
140 for (k = 1; k < 4; k++) {
141 c = crc_table[0][c & 0xff] ^ (c >> 8);
142 crc_table[k][n] = c;
143 crc_table[k + 4][n] = REV(c);
144 }
145 }
146#endif /* BYFOUR */
147
148 crc_table_empty = 0;
149 }
150 else { /* not first */
151 /* wait for the other guy to finish (not efficient, but rare) */
152 while (crc_table_empty)
153 ;
154 }
155
156#ifdef MAKECRCH
157 /* write out CRC tables to crc32.h */
158 {
159 FILE *out;
160
161 out = fopen("crc32_png.h", "w");
162 if (out == NULL) return;
163 fprintf(out, "/* crc32_png.h -- tables for rapid CRC calculation\n");
164 fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
165 fprintf(out, "local const unsigned long FAR ");
166 fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
167 write_table(out, crc_table[0]);
168# ifdef BYFOUR
169 fprintf(out, "#ifdef BYFOUR\n");
170 for (k = 1; k < 8; k++) {
171 fprintf(out, " },\n {\n");
172 write_table(out, crc_table[k]);
173 }
174 fprintf(out, "#endif\n");
175# endif /* BYFOUR */
176 fprintf(out, " }\n};\n");
177 fclose(out);
178 }
179#endif /* MAKECRCH */
180}
181
182#ifdef MAKECRCH
183local void write_table(out, table)
184 FILE *out;
185 const unsigned long FAR *table;
186{
187 int n;
188
189 for (n = 0; n < 256; n++)
190 fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
191 n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
192}
193#endif /* MAKECRCH */
194
195#else /* !DYNAMIC_CRC_TABLE */
196/* ========================================================================
197 * Tables of CRC-32s of all single-byte values, made by make_crc_table().
198 */
199#include "crc32_png.h"
200#endif /* DYNAMIC_CRC_TABLE */
201
202/* =========================================================================
203 * This function can be used by asm versions of crc32()
204 */
205const unsigned long FAR * ZEXPORT get_crc_table()
206{
207#ifdef DYNAMIC_CRC_TABLE
208 if (crc_table_empty)
209 make_crc_table();
210#endif /* DYNAMIC_CRC_TABLE */
211 return (const unsigned long FAR *)crc_table;
212}
213
214/* ========================================================================= */
215#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
216#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
217
218/* ========================================================================= */
219unsigned long ZEXPORT crc32(crc, buf, len)
220 unsigned long crc;
221 const unsigned char FAR *buf;
222 unsigned len;
223{
224 if (buf == Z_NULL) return 0UL;
225
226#ifdef DYNAMIC_CRC_TABLE
227 if (crc_table_empty)
228 make_crc_table();
229#endif /* DYNAMIC_CRC_TABLE */
230
231#ifdef BYFOUR
232 if (sizeof(void *) == sizeof(ptrdiff_t)) {
233 u4 endian;
234
235 endian = 1;
236 if (*((unsigned char *)(&endian)))
237 return crc32_little(crc, buf, len);
238 else
239 return crc32_big(crc, buf, len);
240 }
241#endif /* BYFOUR */
242 crc = crc ^ 0xffffffffUL;
243 while (len >= 8) {
244 DO8;
245 len -= 8;
246 }
247 if (len) do {
248 DO1;
249 } while (--len);
250 return crc ^ 0xffffffffUL;
251}
252
253#ifdef BYFOUR
254
255/* ========================================================================= */
256#define DOLIT4 c ^= *buf4++; \
257 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
258 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
259#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
260
261/* ========================================================================= */
262local unsigned long crc32_little(crc, buf, len)
263 unsigned long crc;
264 const unsigned char FAR *buf;
265 unsigned len;
266{
267 register u4 c;
268 register const u4 FAR *buf4;
269
270 c = (u4)crc;
271 c = ~c;
272 while (len && ((ptrdiff_t)buf & 3)) {
273 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
274 len--;
275 }
276
277 buf4 = (const u4 FAR *)(const void FAR *)buf;
278 while (len >= 32) {
279 DOLIT32;
280 len -= 32;
281 }
282 while (len >= 4) {
283 DOLIT4;
284 len -= 4;
285 }
286 buf = (const unsigned char FAR *)buf4;
287
288 if (len) do {
289 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
290 } while (--len);
291 c = ~c;
292 return (unsigned long)c;
293}
294
295/* ========================================================================= */
296#define DOBIG4 c ^= *++buf4; \
297 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
298 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
299#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
300
301/* ========================================================================= */
302local unsigned long crc32_big(crc, buf, len)
303 unsigned long crc;
304 const unsigned char FAR *buf;
305 unsigned len;
306{
307 register u4 c;
308 register const u4 FAR *buf4;
309
310 c = REV((u4)crc);
311 c = ~c;
312 while (len && ((ptrdiff_t)buf & 3)) {
313 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
314 len--;
315 }
316
317 buf4 = (const u4 FAR *)(const void FAR *)buf;
318 buf4--;
319 while (len >= 32) {
320 DOBIG32;
321 len -= 32;
322 }
323 while (len >= 4) {
324 DOBIG4;
325 len -= 4;
326 }
327 buf4++;
328 buf = (const unsigned char FAR *)buf4;
329
330 if (len) do {
331 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
332 } while (--len);
333 c = ~c;
334 return (unsigned long)(REV(c));
335}
336
337#endif /* BYFOUR */
338
339#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
340
341/* ========================================================================= */
342local unsigned long gf2_matrix_times(mat, vec)
343 unsigned long *mat;
344 unsigned long vec;
345{
346 unsigned long sum;
347
348 sum = 0;
349 while (vec) {
350 if (vec & 1)
351 sum ^= *mat;
352 vec >>= 1;
353 mat++;
354 }
355 return sum;
356}
357
358/* ========================================================================= */
359local void gf2_matrix_square(square, mat)
360 unsigned long *square;
361 unsigned long *mat;
362{
363 int n;
364
365 for (n = 0; n < GF2_DIM; n++)
366 square[n] = gf2_matrix_times(mat, mat[n]);
367}
368
369/* ========================================================================= */
370uLong ZEXPORT crc32_combine(crc1, crc2, len2)
371 uLong crc1;
372 uLong crc2;
373 z_off_t len2;
374{
375 int n;
376 unsigned long row;
377 unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
378 unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
379
380 /* degenerate case */
381 if (len2 == 0)
382 return crc1;
383
384 /* put operator for one zero bit in odd */
385 odd[0] = 0xedb88320L; /* CRC-32 polynomial */
386 row = 1;
387 for (n = 1; n < GF2_DIM; n++) {
388 odd[n] = row;
389 row <<= 1;
390 }
391
392 /* put operator for two zero bits in even */
393 gf2_matrix_square(even, odd);
394
395 /* put operator for four zero bits in odd */
396 gf2_matrix_square(odd, even);
397
398 /* apply len2 zeros to crc1 (first square will put the operator for one
399 zero byte, eight zero bits, in even) */
400 do {
401 /* apply zeros operator for this bit of len2 */
402 gf2_matrix_square(even, odd);
403 if (len2 & 1)
404 crc1 = gf2_matrix_times(even, crc1);
405 len2 >>= 1;
406
407 /* if no more bits set, then done */
408 if (len2 == 0)
409 break;
410
411 /* another iteration of the loop with odd and even swapped */
412 gf2_matrix_square(odd, even);
413 if (len2 & 1)
414 crc1 = gf2_matrix_times(odd, crc1);
415 len2 >>= 1;
416
417 /* if no more bits set, then done */
418 } while (len2 != 0);
419
420 /* return combined crc */
421 crc1 ^= crc2;
422 return crc1;
423}
diff --git a/apps/plugins/png/crc32_png.h b/apps/plugins/png/crc32_png.h
deleted file mode 100644
index 8053b6117c..0000000000
--- a/apps/plugins/png/crc32_png.h
+++ /dev/null
@@ -1,441 +0,0 @@
1/* crc32.h -- tables for rapid CRC calculation
2 * Generated automatically by crc32.c
3 */
4
5local const unsigned long FAR crc_table[TBLS][256] =
6{
7 {
8 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
9 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
10 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
11 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
12 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
13 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
14 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
15 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
16 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
17 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
18 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
19 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
20 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
21 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
22 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
23 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
24 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
25 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
26 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
27 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
28 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
29 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
30 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
31 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
32 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
33 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
34 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
35 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
36 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
37 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
38 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
39 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
40 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
41 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
42 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
43 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
44 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
45 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
46 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
47 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
48 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
49 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
50 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
51 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
52 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
53 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
54 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
55 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
56 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
57 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
58 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
59 0x2d02ef8dUL
60#ifdef BYFOUR
61 },
62 {
63 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
64 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
65 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
66 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
67 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
68 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
69 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
70 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
71 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
72 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
73 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
74 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
75 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
76 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
77 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
78 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
79 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
80 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
81 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
82 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
83 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
84 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
85 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
86 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
87 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
88 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
89 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
90 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
91 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
92 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
93 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
94 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
95 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
96 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
97 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
98 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
99 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
100 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
101 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
102 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
103 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
104 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
105 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
106 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
107 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
108 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
109 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
110 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
111 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
112 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
113 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
114 0x9324fd72UL
115 },
116 {
117 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
118 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
119 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
120 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
121 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
122 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
123 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
124 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
125 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
126 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
127 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
128 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
129 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
130 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
131 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
132 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
133 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
134 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
135 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
136 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
137 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
138 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
139 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
140 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
141 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
142 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
143 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
144 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
145 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
146 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
147 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
148 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
149 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
150 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
151 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
152 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
153 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
154 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
155 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
156 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
157 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
158 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
159 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
160 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
161 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
162 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
163 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
164 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
165 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
166 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
167 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
168 0xbe9834edUL
169 },
170 {
171 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
172 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
173 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
174 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
175 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
176 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
177 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
178 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
179 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
180 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
181 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
182 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
183 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
184 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
185 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
186 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
187 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
188 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
189 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
190 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
191 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
192 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
193 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
194 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
195 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
196 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
197 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
198 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
199 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
200 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
201 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
202 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
203 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
204 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
205 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
206 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
207 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
208 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
209 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
210 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
211 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
212 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
213 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
214 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
215 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
216 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
217 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
218 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
219 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
220 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
221 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
222 0xde0506f1UL
223 },
224 {
225 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
226 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
227 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
228 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
229 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
230 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
231 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
232 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
233 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
234 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
235 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
236 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
237 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
238 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
239 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
240 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
241 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
242 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
243 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
244 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
245 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
246 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
247 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
248 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
249 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
250 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
251 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
252 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
253 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
254 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
255 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
256 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
257 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
258 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
259 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
260 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
261 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
262 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
263 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
264 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
265 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
266 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
267 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
268 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
269 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
270 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
271 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
272 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
273 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
274 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
275 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
276 0x8def022dUL
277 },
278 {
279 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
280 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
281 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
282 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
283 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
284 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
285 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
286 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
287 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
288 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
289 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
290 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
291 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
292 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
293 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
294 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
295 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
296 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
297 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
298 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
299 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
300 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
301 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
302 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
303 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
304 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
305 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
306 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
307 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
308 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
309 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
310 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
311 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
312 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
313 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
314 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
315 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
316 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
317 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
318 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
319 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
320 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
321 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
322 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
323 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
324 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
325 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
326 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
327 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
328 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
329 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
330 0x72fd2493UL
331 },
332 {
333 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
334 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
335 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
336 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
337 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
338 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
339 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
340 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
341 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
342 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
343 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
344 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
345 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
346 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
347 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
348 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
349 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
350 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
351 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
352 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
353 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
354 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
355 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
356 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
357 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
358 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
359 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
360 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
361 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
362 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
363 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
364 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
365 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
366 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
367 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
368 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
369 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
370 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
371 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
372 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
373 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
374 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
375 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
376 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
377 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
378 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
379 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
380 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
381 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
382 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
383 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
384 0xed3498beUL
385 },
386 {
387 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
388 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
389 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
390 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
391 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
392 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
393 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
394 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
395 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
396 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
397 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
398 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
399 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
400 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
401 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
402 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
403 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
404 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
405 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
406 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
407 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
408 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
409 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
410 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
411 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
412 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
413 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
414 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
415 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
416 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
417 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
418 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
419 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
420 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
421 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
422 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
423 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
424 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
425 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
426 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
427 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
428 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
429 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
430 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
431 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
432 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
433 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
434 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
435 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
436 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
437 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
438 0xf10605deUL
439#endif
440 }
441};
diff --git a/apps/plugins/png/inffast.c b/apps/plugins/png/inffast.c
deleted file mode 100644
index bf96323ab2..0000000000
--- a/apps/plugins/png/inffast.c
+++ /dev/null
@@ -1,379 +0,0 @@
1/* inffast.c -- fast decoding
2 * Copyright (C) 1995-2004 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8#include "inflate.h"
9#include "inffast.h"
10#include "plugin.h"
11
12#ifndef ASMINF
13
14extern struct inflate_state state;
15extern unsigned char *memory_max;
16
17/* Allow machine dependent optimization for post-increment or pre-increment.
18 Based on testing to date,
19 Pre-increment preferred for:
20 - PowerPC G3 (Adler)
21 - MIPS R5000 (Randers-Pehrson)
22 Post-increment preferred for:
23 - none
24 No measurable difference:
25 - Pentium III (Anderson)
26 - M68060 (Nikl)
27 */
28#ifdef POSTINC
29# define OFF 0
30# define PUP(a) *(a)++
31#else
32# define OFF 1
33# define PUP(a) *++(a)
34#endif
35
36/*
37 Decode literal, length, and distance codes and write out the resulting
38 literal and match bytes until either not enough input or output is
39 available, an end-of-block is encountered, or a data error is encountered.
40 When large enough input and output buffers are supplied to inflate(), for
41 example, a 16K input buffer and a 64K output buffer, more than 95% of the
42 inflate execution time is spent in this routine.
43
44 Entry assumptions:
45
46 state->mode == LEN
47 strm->avail_in >= 6
48 strm->avail_out >= 258
49 start >= strm->avail_out
50 state->bits < 8
51
52 On return, state->mode is one of:
53
54 LEN -- ran out of enough output space or enough available input
55 TYPE -- reached end of block code, inflate() to interpret next block
56 BAD -- error in block data
57
58 Notes:
59
60 - The maximum input bits used by a length/distance pair is 15 bits for the
61 length code, 5 bits for the length extra, 15 bits for the distance code,
62 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
63 Therefore if strm->avail_in >= 6, then there is enough input to avoid
64 checking for available input while decoding.
65
66 - The maximum bytes that a single length/distance pair can output is 258
67 bytes, which is the maximum length that can be coded. inflate_fast()
68 requires strm->avail_out >= 258 for each loop to avoid checking for
69 output space.
70 */
71void inflate_fast(strm, start)
72z_streamp strm;
73unsigned start; /* inflate()'s starting value for strm->avail_out */
74{
75 //struct inflate_state FAR *state;
76 unsigned char FAR *in; /* local strm->next_in */
77 unsigned char FAR *last; /* while in < last, enough input available */
78 unsigned char FAR *out; /* local strm->next_out */
79 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
80 unsigned char FAR *end; /* while out < end, enough space available */
81#ifdef INFLATE_STRICT
82 unsigned dmax; /* maximum distance from zlib header */
83#endif
84 unsigned wsize; /* window size or zero if not using window */
85 unsigned whave; /* valid bytes in the window */
86 unsigned write; /* window write index */
87 unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
88 unsigned long hold; /* local strm->hold */
89 unsigned bits; /* local strm->bits */
90 code const FAR *lcode; /* local strm->lencode */
91 code const FAR *dcode; /* local strm->distcode */
92 unsigned lmask; /* mask for first level of length codes */
93 unsigned dmask; /* mask for first level of distance codes */
94 code this; /* retrieved table entry */
95 unsigned op; /* code bits, operation, extra bits, or */
96 /* window position, window bytes to copy */
97 unsigned len; /* match length, unused bytes */
98 unsigned dist; /* match distance */
99 unsigned char FAR *from; /* where to copy match from */
100
101 /* copy state to local variables */
102 //state = (struct inflate_state FAR *)strm->state;
103 in = strm->next_in - OFF;
104 last = in + (strm->avail_in - 5);
105 out = strm->next_out - OFF;
106 beg = out - (start - strm->avail_out);
107 end = out + (strm->avail_out - 257);
108#ifdef INFLATE_STRICT
109 dmax = state->dmax;
110#endif
111 wsize = state.wsize;
112 whave = state.whave;
113 write = state.write;
114 window = state.window;
115 hold = state.hold;
116 bits = state.bits;
117 lcode = state.lencode;
118 dcode = state.distcode;
119 lmask = (1U << state.lenbits) - 1;
120 dmask = (1U << state.distbits) - 1;
121
122 /* decode literals and length/distances until end-of-block or not enough
123 input data or output space */
124 do {
125 if (bits < 15) {
126 hold += (unsigned long)(PUP(in)) << bits;
127 bits += 8;
128 hold += (unsigned long)(PUP(in)) << bits;
129 bits += 8;
130 }
131 this = lcode[hold & lmask];
132 dolen:
133 op = (unsigned)(this.bits);
134 hold >>= op;
135 bits -= op;
136 op = (unsigned)(this.op);
137 if (op == 0) { /* literal */
138 //DEBUGF(this.val >= 0x20 && this.val < 0x7f ?
139 // "inflate: literal '%c'\n" :
140 // "inflate: literal 0x%02x\n", this.val);
141 if (out >= memory_max) {
142 strm->msg = (char *)"Out of memory";
143 state.mode = ZMEM;
144 break;
145 }
146 PUP(out) = (unsigned char)(this.val);
147 }
148 else if (op & 16) { /* length base */
149 len = (unsigned)(this.val);
150 op &= 15; /* number of extra bits */
151 if (op) {
152 if (bits < op) {
153 hold += (unsigned long)(PUP(in)) << bits;
154 bits += 8;
155 }
156 len += (unsigned)hold & ((1U << op) - 1);
157 hold >>= op;
158 bits -= op;
159 }
160 //DEBUGF("inflate: length %u\n", len);
161 if (bits < 15) {
162 hold += (unsigned long)(PUP(in)) << bits;
163 bits += 8;
164 hold += (unsigned long)(PUP(in)) << bits;
165 bits += 8;
166 }
167 this = dcode[hold & dmask];
168 dodist:
169 op = (unsigned)(this.bits);
170 hold >>= op;
171 bits -= op;
172 op = (unsigned)(this.op);
173 if (op & 16) { /* distance base */
174 dist = (unsigned)(this.val);
175 op &= 15; /* number of extra bits */
176 if (bits < op) {
177 hold += (unsigned long)(PUP(in)) << bits;
178 bits += 8;
179 if (bits < op) {
180 hold += (unsigned long)(PUP(in)) << bits;
181 bits += 8;
182 }
183 }
184 dist += (unsigned)hold & ((1U << op) - 1);
185#ifdef INFLATE_STRICT
186 if (dist > dmax) {
187 strm->msg = (char *)"invalid distance too far back";
188 state->mode = BAD;
189 break;
190 }
191#endif
192 hold >>= op;
193 bits -= op;
194 //DEBUGF("inflate: distance %u\n", dist);
195 op = (unsigned)(out - beg); /* max distance in output */
196 if (dist > op) { /* see if copy from window */
197 op = dist - op; /* distance back in window */
198 if (op > whave) {
199 strm->msg = (char *)"invalid distance too far back";
200 state.mode = BAD;
201 break;
202 }
203 from = window - OFF;
204 if (write == 0) { /* very common case */
205 from += wsize - op;
206 if (op < len) { /* some from window */
207 len -= op;
208 do {
209 if (out >= memory_max) {
210 strm->msg = (char *)"Out of memory";
211 state.mode = ZMEM;
212 break;
213 }
214 PUP(out) = PUP(from);
215 } while (--op);
216 from = out - dist; /* rest from output */
217 }
218 }
219 else if (write < op) { /* wrap around window */
220 from += wsize + write - op;
221 op -= write;
222 if (op < len) { /* some from end of window */
223 len -= op;
224 do {
225 if (out >= memory_max) {
226 strm->msg = (char *)"Out of memory";
227 state.mode = ZMEM;
228 break;
229 }
230 PUP(out) = PUP(from);
231 } while (--op);
232 from = window - OFF;
233 if (write < len) { /* some from start of window */
234 op = write;
235 len -= op;
236 do {
237 if (out >= memory_max) {
238 strm->msg = (char *)"Out of memory";
239 state.mode = ZMEM;
240 break;
241 }
242 PUP(out) = PUP(from);
243 } while (--op);
244 from = out - dist; /* rest from output */
245 }
246 }
247 }
248 else { /* contiguous in window */
249 from += write - op;
250 if (op < len) { /* some from window */
251 len -= op;
252 do {
253 if (out >= memory_max) {
254 strm->msg = (char *)"Out of memory";
255 state.mode = ZMEM;
256 break;
257 }
258 PUP(out) = PUP(from);
259 } while (--op);
260 from = out - dist; /* rest from output */
261 }
262 }
263 while (len > 2) {
264 if (out >= memory_max-2) {
265 strm->msg = (char *)"Out of memory";
266 state.mode = ZMEM;
267 break;
268 }
269 PUP(out) = PUP(from);
270 PUP(out) = PUP(from);
271 PUP(out) = PUP(from);
272 len -= 3;
273 }
274 if (len) {
275 if (out >= memory_max) {
276 strm->msg = (char *)"Out of memory";
277 state.mode = ZMEM;
278 break;
279 }
280 PUP(out) = PUP(from);
281 if (len > 1) {
282 if (out >= memory_max) {
283 strm->msg = (char *)"Out of memory";
284 state.mode = ZMEM;
285 break;
286 }
287 PUP(out) = PUP(from);
288 }
289 }
290 }
291 else {
292 from = out - dist; /* copy direct from output */
293 do { /* minimum length is three */
294 if (out >= memory_max-2) {
295 strm->msg = (char *)"Out of memory";
296 state.mode = ZMEM;
297 break;
298 }
299 PUP(out) = PUP(from);
300 PUP(out) = PUP(from);
301 PUP(out) = PUP(from);
302 len -= 3;
303 } while (len > 2);
304 if (len) {
305 if (out >= memory_max) {
306 strm->msg = (char *)"Out of memory";
307 state.mode = ZMEM;
308 break;
309 }
310 PUP(out) = PUP(from);
311 if (len > 1) {
312 if (out >= memory_max) {
313 strm->msg = (char *)"Out of memory";
314 state.mode = ZMEM;
315 break;
316 }
317 PUP(out) = PUP(from);
318 }
319 }
320 }
321 }
322 else if ((op & 64) == 0) { /* 2nd level distance code */
323 this = dcode[this.val + (hold & ((1U << op) - 1))];
324 goto dodist;
325 }
326 else {
327 strm->msg = (char *)"invalid distance code";
328 state.mode = BAD;
329 break;
330 }
331 }
332 else if ((op & 64) == 0) { /* 2nd level length code */
333 this = lcode[this.val + (hold & ((1U << op) - 1))];
334 goto dolen;
335 }
336 else if (op & 32) { /* end-of-block */
337 //DEBUGF("inflate: end of block\n");
338 state.mode = TYPE;
339 break;
340 }
341 else {
342 strm->msg = (char *)"invalid literal/length code";
343 state.mode = BAD;
344 break;
345 }
346 } while (in < last && out < end);
347
348 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
349 len = bits >> 3;
350 in -= len;
351 bits -= len << 3;
352 hold &= (1U << bits) - 1;
353
354 /* update state and return */
355 strm->next_in = in + OFF;
356 strm->next_out = out + OFF;
357 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
358 strm->avail_out = (unsigned)(out < end ?
359 257 + (end - out) : 257 - (out - end));
360 state.hold = hold;
361 state.bits = bits;
362 return;
363}
364
365/*
366 inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
367 - Using bit fields for code structure
368 - Different op definition to avoid & for extra bits (do & for table bits)
369 - Three separate decoding do-loops for direct, window, and write == 0
370 - Special case for distance > 1 copies to do overlapped load and store copy
371 - Explicit branch predictions (based on measured branch probabilities)
372 - Deferring match copy and interspersed it with decoding subsequent codes
373 - Swapping literal/length else
374 - Swapping window/direct else
375 - Larger unrolled copy loops (three is about right)
376 - Moving len -= 3 statement into middle of loop
377 */
378
379#endif /* !ASMINF */
diff --git a/apps/plugins/png/inffast.h b/apps/plugins/png/inffast.h
deleted file mode 100644
index 1e88d2d97b..0000000000
--- a/apps/plugins/png/inffast.h
+++ /dev/null
@@ -1,11 +0,0 @@
1/* inffast.h -- header to use inffast.c
2 * Copyright (C) 1995-2003 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11void inflate_fast OF((z_streamp strm, unsigned start));
diff --git a/apps/plugins/png/inffixed.h b/apps/plugins/png/inffixed.h
deleted file mode 100644
index 75ed4b5978..0000000000
--- a/apps/plugins/png/inffixed.h
+++ /dev/null
@@ -1,94 +0,0 @@
1 /* inffixed.h -- table for decoding fixed codes
2 * Generated automatically by makefixed().
3 */
4
5 /* WARNING: this file should *not* be used by applications. It
6 is part of the implementation of the compression library and
7 is subject to change. Applications should only use zlib.h.
8 */
9
10 static const code lenfix[512] = {
11 {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
12 {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
13 {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
14 {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
15 {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
16 {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
17 {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
18 {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
19 {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
20 {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
21 {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
22 {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
23 {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
24 {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
25 {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
26 {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
27 {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
28 {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
29 {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
30 {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
31 {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
32 {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
33 {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
34 {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
35 {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
36 {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
37 {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
38 {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
39 {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
40 {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
41 {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
42 {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
43 {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
44 {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
45 {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
46 {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
47 {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
48 {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
49 {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
50 {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
51 {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
52 {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
53 {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
54 {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
55 {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
56 {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
57 {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
58 {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
59 {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
60 {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
61 {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
62 {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
63 {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
64 {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
65 {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
66 {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
67 {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
68 {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
69 {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
70 {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
71 {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
72 {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
73 {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
74 {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
75 {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
76 {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
77 {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
78 {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
79 {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
80 {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
81 {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
82 {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
83 {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
84 {0,9,255}
85 };
86
87 static const code distfix[32] = {
88 {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
89 {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
90 {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
91 {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
92 {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
93 {22,5,193},{64,5,0}
94 };
diff --git a/apps/plugins/png/inflate.c b/apps/plugins/png/inflate.c
deleted file mode 100644
index 2cf6f972a4..0000000000
--- a/apps/plugins/png/inflate.c
+++ /dev/null
@@ -1,1334 +0,0 @@
1/* inflate.c -- zlib decompression
2 * Copyright (C) 1995-2005 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * Change history:
8 *
9 * 1.2.beta0 24 Nov 2002
10 * - First version -- complete rewrite of inflate to simplify code, avoid
11 * creation of window when not needed, minimize use of window when it is
12 * needed, make inffast.c even faster, implement gzip decoding, and to
13 * improve code readability and style over the previous zlib inflate code
14 *
15 * 1.2.beta1 25 Nov 2002
16 * - Use pointers for available input and output checking in inffast.c
17 * - Remove input and output counters in inffast.c
18 * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
19 * - Remove unnecessary second byte pull from length extra in inffast.c
20 * - Unroll direct copy to three copies per loop in inffast.c
21 *
22 * 1.2.beta2 4 Dec 2002
23 * - Change external routine names to reduce potential conflicts
24 * - Correct filename to inffixed.h for fixed tables in inflate.c
25 * - Make hbuf[] unsigned char to match parameter type in inflate.c
26 * - Change strm->next_out[-state.offset] to *(strm->next_out - state.offset)
27 * to avoid negation problem on Alphas (64 bit) in inflate.c
28 *
29 * 1.2.beta3 22 Dec 2002
30 * - Add comments on state.bits assertion in inffast.c
31 * - Add comments on op field in inftrees.h
32 * - Fix bug in reuse of allocated window after inflateReset()
33 * - Remove bit fields--back to byte structure for speed
34 * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
35 * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
36 * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
37 * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
38 * - Use local copies of stream next and avail values, as well as local bit
39 * buffer and bit count in inflate()--for speed when inflate_fast() not used
40 *
41 * 1.2.beta4 1 Jan 2003
42 * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
43 * - Move a comment on output buffer sizes from inffast.c to inflate.c
44 * - Add comments in inffast.c to introduce the inflate_fast() routine
45 * - Rearrange window copies in inflate_fast() for speed and simplification
46 * - Unroll last copy for window match in inflate_fast()
47 * - Use local copies of window variables in inflate_fast() for speed
48 * - Pull out common write == 0 case for speed in inflate_fast()
49 * - Make op and len in inflate_fast() unsigned for consistency
50 * - Add FAR to lcode and dcode declarations in inflate_fast()
51 * - Simplified bad distance check in inflate_fast()
52 * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
53 * source file infback.c to provide a call-back interface to inflate for
54 * programs like gzip and unzip -- uses window as output buffer to avoid
55 * window copying
56 *
57 * 1.2.beta5 1 Jan 2003
58 * - Improved inflateBack() interface to allow the caller to provide initial
59 * input in strm.
60 * - Fixed stored blocks bug in inflateBack()
61 *
62 * 1.2.beta6 4 Jan 2003
63 * - Added comments in inffast.c on effectiveness of POSTINC
64 * - Typecasting all around to reduce compiler warnings
65 * - Changed loops from while (1) or do {} while (1) to for (;;), again to
66 * make compilers happy
67 * - Changed type of window in inflateBackInit() to unsigned char *
68 *
69 * 1.2.beta7 27 Jan 2003
70 * - Changed many types to unsigned or unsigned short to avoid warnings
71 * - Added inflateCopy() function
72 *
73 * 1.2.0 9 Mar 2003
74 * - Changed inflateBack() interface to provide separate opaque descriptors
75 * for the in() and out() functions
76 * - Changed inflateBack() argument and in_func typedef to swap the length
77 * and buffer address return values for the input function
78 * - Check next_in and next_out for Z_NULL on entry to inflate()
79 *
80 * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
81 */
82
83#include "zutil.h"
84#include "inftrees.h"
85#include "inflate.h"
86#include "inffast.h"
87#include "plugin.h"
88#include "png.h"
89
90#ifdef MAKEFIXED
91# ifndef BUILDFIXED
92# define BUILDFIXED
93# endif
94#endif
95
96struct inflate_state state;
97
98/* function prototypes */
99local void fixedtables OF((void));
100local int updatewindow OF((z_streamp strm, unsigned out));
101#ifdef BUILDFIXED
102 void makefixed OF((void));
103#endif
104local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
105 unsigned len));
106
107int ZEXPORT inflateReset(strm)
108z_streamp strm;
109{
110 //struct inflate_state FAR *state;
111
112 if (strm == Z_NULL) return Z_STREAM_ERROR;
113 //state = strm->state;
114 strm->total_in = strm->total_out = state.total = 0;
115 strm->msg = Z_NULL;
116 strm->adler = 1; /* to support ill-conceived Java test suite */
117 state.mode = HEAD;
118 state.last = 0;
119 state.havedict = 0;
120 state.dmax = 32768U;
121 state.head = Z_NULL;
122 state.wsize = 0;
123 state.whave = 0;
124 state.write = 0;
125 state.hold = 0;
126 state.bits = 0;
127 state.lencode = state.distcode = state.next = state.codes;
128 //DEBUGF("inflate: reset\n");
129 return Z_OK;
130}
131
132int ZEXPORT inflatePrime(strm, bits, value)
133z_streamp strm;
134int bits;
135int value;
136{
137 //struct inflate_state FAR *state;
138
139 if (strm == Z_NULL) return Z_STREAM_ERROR;
140 //state = (struct inflate_state FAR *)strm->state;
141 if (bits > 16 || state.bits + bits > 32) return Z_STREAM_ERROR;
142 value &= (1L << bits) - 1;
143 state.hold += value << state.bits;
144 state.bits += bits;
145 return Z_OK;
146}
147
148int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
149z_streamp strm;
150int windowBits;
151const char *version;
152int stream_size;
153{
154 //struct inflate_state FAR *state;
155
156 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
157 stream_size != (int)(sizeof(z_stream)))
158 return Z_VERSION_ERROR;
159 if (strm == Z_NULL) return Z_STREAM_ERROR;
160 strm->msg = Z_NULL; /* in case we return an error */
161 //if (strm->zalloc == (alloc_func)0) {
162 // strm->zalloc = zcalloc;
163 // strm->opaque = (voidpf)0;
164 //}
165 //if (strm->zfree == (free_func)0) strm->zfree = zcfree;
166 //state = (struct inflate_state FAR *)
167 // ZALLOC(strm, 1, sizeof(struct inflate_state));
168 //if (state == Z_NULL) return Z_MEM_ERROR;
169 //DEBUGF("inflate: allocated\n");
170 //strm->state = (struct internal_state FAR *)state;
171 if (windowBits < 0) {
172 state.wrap = 0;
173 windowBits = -windowBits;
174 }
175 else {
176 state.wrap = (windowBits >> 4) + 1;
177#ifdef GUNZIP
178 if (windowBits < 48) windowBits &= 15;
179#endif
180 }
181 if (windowBits < 8 || windowBits > 15) {
182 //ZFREE(strm, state);
183 //strm->state = Z_NULL;
184 return Z_STREAM_ERROR;
185 }
186 state.wbits = (unsigned)windowBits;
187 state.window = Z_NULL;
188 return inflateReset(strm);
189}
190
191int ZEXPORT inflateInit_(strm, version, stream_size)
192z_streamp strm;
193const char *version;
194int stream_size;
195{
196 return inflateInit2_(strm, DEF_WBITS, version, stream_size);
197}
198
199/*
200 Return state with length and distance decoding tables and index sizes set to
201 fixed code decoding. Normally this returns fixed tables from inffixed.h.
202 If BUILDFIXED is defined, then instead this routine builds the tables the
203 first time it's called, and returns those tables the first time and
204 thereafter. This reduces the size of the code by about 2K bytes, in
205 exchange for a little execution time. However, BUILDFIXED should not be
206 used for threaded applications, since the rewriting of the tables and virgin
207 may not be thread-safe.
208 */
209local void fixedtables(void)
210//struct inflate_state FAR *state;
211{
212#ifdef BUILDFIXED
213 static int virgin = 1;
214 static code *lenfix, *distfix;
215 static code fixed[544];
216
217 /* build fixed huffman tables if first call (may not be thread safe) */
218 if (virgin) {
219 unsigned sym, bits;
220 static code *next;
221
222 /* literal/length table */
223 sym = 0;
224 while (sym < 144) state.lens[sym++] = 8;
225 while (sym < 256) state.lens[sym++] = 9;
226 while (sym < 280) state.lens[sym++] = 7;
227 while (sym < 288) state.lens[sym++] = 8;
228 next = fixed;
229 lenfix = next;
230 bits = 9;
231 inflate_table(LENS, state.lens, 288, &(next), &(bits), state.work);
232
233 /* distance table */
234 sym = 0;
235 while (sym < 32) state.lens[sym++] = 5;
236 distfix = next;
237 bits = 5;
238 inflate_table(DISTS, state.lens, 32, &(next), &(bits), state.work);
239
240 /* do this just once */
241 virgin = 0;
242 }
243#else /* !BUILDFIXED */
244# include "inffixed.h"
245#endif /* BUILDFIXED */
246 state.lencode = lenfix;
247 state.lenbits = 9;
248 state.distcode = distfix;
249 state.distbits = 5;
250}
251
252#ifdef MAKEFIXED
253#include <stdio.h>
254
255/*
256 Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
257 defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
258 those tables to stdout, which would be piped to inffixed.h. A small program
259 can simply call makefixed to do this:
260
261 void makefixed(void);
262
263 int main(void)
264 {
265 makefixed();
266 return 0;
267 }
268
269 Then that can be linked with zlib built with MAKEFIXED defined and run:
270
271 a.out > inffixed.h
272 */
273void makefixed()
274{
275 unsigned low, size;
276 struct inflate_state state;
277
278 fixedtables(&state);
279 puts(" /* inffixed.h -- table for decoding fixed codes");
280 puts(" * Generated automatically by makefixed().");
281 puts(" */");
282 puts("");
283 puts(" /* WARNING: this file should *not* be used by applications.");
284 puts(" It is part of the implementation of this library and is");
285 puts(" subject to change. Applications should only use zlib.h.");
286 puts(" */");
287 puts("");
288 size = 1U << 9;
289 printf(" static const code lenfix[%u] = {", size);
290 low = 0;
291 for (;;) {
292 if ((low % 7) == 0) printf("\n ");
293 printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
294 state.lencode[low].val);
295 if (++low == size) break;
296 putchar(',');
297 }
298 puts("\n };");
299 size = 1U << 5;
300 printf("\n static const code distfix[%u] = {", size);
301 low = 0;
302 for (;;) {
303 if ((low % 6) == 0) printf("\n ");
304 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
305 state.distcode[low].val);
306 if (++low == size) break;
307 putchar(',');
308 }
309 puts("\n };");
310}
311#endif /* MAKEFIXED */
312
313/*
314 Update the window with the last wsize (normally 32K) bytes written before
315 returning. If window does not exist yet, create it. This is only called
316 when a window is already in use, or when output has been written during this
317 inflate call, but the end of the deflate stream has not been reached yet.
318 It is also called to create a window for dictionary data when a dictionary
319 is loaded.
320
321 Providing output buffers larger than 32K to inflate() should provide a speed
322 advantage, since only the last 32K of output is copied to the sliding window
323 upon return from inflate(), and since all distances after the first 32K of
324 output will fall in the output data, making match copies simpler and faster.
325 The advantage may be dependent on the size of the processor's data caches.
326 */
327local int updatewindow(strm, out)
328z_streamp strm;
329unsigned out;
330{
331 //struct inflate_state FAR *state;
332 unsigned copy, dist;
333
334 //state = (struct inflate_state FAR *)strm->state;
335
336 /* if it hasn't been done already, allocate space for the window */
337 if (state.window == Z_NULL) {
338 state.window = (unsigned char FAR *)
339 ZALLOC(strm, 1U << state.wbits,
340 sizeof(unsigned char));
341 if (state.window == Z_NULL) return 1;
342 }
343
344 /* if window not in use yet, initialize */
345 if (state.wsize == 0) {
346 state.wsize = 1U << state.wbits;
347 state.write = 0;
348 state.whave = 0;
349 }
350
351 /* copy state.wsize or less output bytes into the circular window */
352 copy = out - strm->avail_out;
353 if (copy >= state.wsize) {
354 zmemcpy(state.window, strm->next_out - state.wsize, state.wsize);
355 state.write = 0;
356 state.whave = state.wsize;
357 }
358 else {
359 dist = state.wsize - state.write;
360 if (dist > copy) dist = copy;
361 zmemcpy(state.window + state.write, strm->next_out - copy, dist);
362 copy -= dist;
363 if (copy) {
364 zmemcpy(state.window, strm->next_out - copy, copy);
365 state.write = copy;
366 state.whave = state.wsize;
367 }
368 else {
369 state.write += dist;
370 if (state.write == state.wsize) state.write = 0;
371 if (state.whave < state.wsize) state.whave += dist;
372 }
373 }
374 return 0;
375}
376
377/* Macros for inflate(): */
378
379/* check function to use adler32() for zlib or crc32() for gzip */
380#ifdef GUNZIP
381# define UPDATE(check, buf, len) \
382 (state.flags ? crc32(check, buf, len) : adler32(check, buf, len))
383#else
384# define UPDATE(check, buf, len) adler32(check, buf, len)
385#endif
386
387/* check macros for header crc */
388#ifdef GUNZIP
389# define CRC2(check, word) \
390 do { \
391 hbuf[0] = (unsigned char)(word); \
392 hbuf[1] = (unsigned char)((word) >> 8); \
393 check = crc32(check, hbuf, 2); \
394 } while (0)
395
396# define CRC4(check, word) \
397 do { \
398 hbuf[0] = (unsigned char)(word); \
399 hbuf[1] = (unsigned char)((word) >> 8); \
400 hbuf[2] = (unsigned char)((word) >> 16); \
401 hbuf[3] = (unsigned char)((word) >> 24); \
402 check = crc32(check, hbuf, 4); \
403 } while (0)
404#endif
405
406/* Load registers with state in inflate() for speed */
407#define LOAD() \
408 do { \
409 put = strm->next_out; \
410 left = strm->avail_out; \
411 next = strm->next_in; \
412 have = strm->avail_in; \
413 hold = state.hold; \
414 bits = state.bits; \
415 } while (0)
416
417/* Restore state from registers in inflate() */
418#define RESTORE() \
419 do { \
420 strm->next_out = put; \
421 strm->avail_out = left; \
422 strm->next_in = next; \
423 strm->avail_in = have; \
424 state.hold = hold; \
425 state.bits = bits; \
426 } while (0)
427
428/* Clear the input bit accumulator */
429#define INITBITS() \
430 do { \
431 hold = 0; \
432 bits = 0; \
433 } while (0)
434
435/* Get a byte of input into the bit accumulator, or return from inflate()
436 if there is no input available. */
437#define PULLBYTE() \
438 do { \
439 if (have == 0) goto inf_leave; \
440 have--; \
441 hold += (unsigned long)(*next++) << bits; \
442 bits += 8; \
443 } while (0)
444
445/* Assure that there are at least n bits in the bit accumulator. If there is
446 not enough available input to do that, then return from inflate(). */
447#define NEEDBITS(n) \
448 do { \
449 while (bits < (unsigned)(n)) \
450 PULLBYTE(); \
451 } while (0)
452
453/* Return the low n bits of the bit accumulator (n < 16) */
454#define BITS(n) \
455 ((unsigned)hold & ((1U << (n)) - 1))
456
457/* Remove n bits from the bit accumulator */
458#define DROPBITS(n) \
459 do { \
460 hold >>= (n); \
461 bits -= (unsigned)(n); \
462 } while (0)
463
464/* Remove zero to seven bits as needed to go to a byte boundary */
465#define BYTEBITS() \
466 do { \
467 hold >>= bits & 7; \
468 bits -= bits & 7; \
469 } while (0)
470
471/* Reverse the bytes in a 32-bit value */
472#define REVERSE(q) \
473 ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
474 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
475
476/*
477 inflate() uses a state machine to process as much input data and generate as
478 much output data as possible before returning. The state machine is
479 structured roughly as follows:
480
481 for (;;) switch (state) {
482 ...
483 case STATEn:
484 if (not enough input data or output space to make progress)
485 return;
486 ... make progress ...
487 state = STATEm;
488 break;
489 ...
490 }
491
492 so when inflate() is called again, the same case is attempted again, and
493 if the appropriate resources are provided, the machine proceeds to the
494 next state. The NEEDBITS() macro is usually the way the state evaluates
495 whether it can proceed or should return. NEEDBITS() does the return if
496 the requested bits are not available. The typical use of the BITS macros
497 is:
498
499 NEEDBITS(n);
500 ... do something with BITS(n) ...
501 DROPBITS(n);
502
503 where NEEDBITS(n) either returns from inflate() if there isn't enough
504 input left to load n bits into the accumulator, or it continues. BITS(n)
505 gives the low n bits in the accumulator. When done, DROPBITS(n) drops
506 the low n bits off the accumulator. INITBITS() clears the accumulator
507 and sets the number of available bits to zero. BYTEBITS() discards just
508 enough bits to put the accumulator on a byte boundary. After BYTEBITS()
509 and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
510
511 NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
512 if there is no input available. The decoding of variable length codes uses
513 PULLBYTE() directly in order to pull just enough bytes to decode the next
514 code, and no more.
515
516 Some states loop until they get enough input, making sure that enough
517 state information is maintained to continue the loop where it left off
518 if NEEDBITS() returns in the loop. For example, want, need, and keep
519 would all have to actually be part of the saved state in case NEEDBITS()
520 returns:
521
522 case STATEw:
523 while (want < need) {
524 NEEDBITS(n);
525 keep[want++] = BITS(n);
526 DROPBITS(n);
527 }
528 state = STATEx;
529 case STATEx:
530
531 As shown above, if the next state is also the next case, then the break
532 is omitted.
533
534 A state may also return if there is not enough output space available to
535 complete that state. Those states are copying stored data, writing a
536 literal byte, and copying a matching string.
537
538 When returning, a "goto inf_leave" is used to update the total counters,
539 update the check value, and determine whether any progress has been made
540 during that inflate() call in order to return the proper return code.
541 Progress is defined as a change in either strm->avail_in or strm->avail_out.
542 When there is a window, goto inf_leave will update the window with the last
543 output written. If a goto inf_leave occurs in the middle of decompression
544 and there is no window currently, goto inf_leave will create one and copy
545 output to the window for the next call of inflate().
546
547 In this implementation, the flush parameter of inflate() only affects the
548 return code (per zlib.h). inflate() always writes as much as possible to
549 strm->next_out, given the space available and the provided input--the effect
550 documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
551 the allocation of and copying into a sliding window until necessary, which
552 provides the effect documented in zlib.h for Z_FINISH when the entire input
553 stream available. So the only thing the flush parameter actually does is:
554 when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
555 will return Z_BUF_ERROR if it has not reached the end of the stream.
556 */
557
558extern void cb_progress(int current, int total);
559
560int ZEXPORT inflate(strm, flush)
561z_streamp strm;
562int flush;
563{
564 //struct inflate_state FAR *state;
565 unsigned char FAR *next; /* next input */
566 unsigned char FAR *put; /* next output */
567 unsigned have, left; /* available input and output */
568 unsigned long hold; /* bit buffer */
569 unsigned bits; /* bits in bit buffer */
570 unsigned in, out; /* save starting available input and output */
571 unsigned copy; /* number of stored or match bytes to copy */
572 unsigned char FAR *from; /* where to copy match bytes from */
573 code this; /* current decoding table entry */
574 code last; /* parent table entry */
575 unsigned len; /* length to copy for repeats, bits to drop */
576 int ret; /* return code */
577#ifdef GUNZIP
578 unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
579#endif
580 static const unsigned short order[19] = /* permutation of code lengths */
581 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
582
583 if (strm == Z_NULL || strm->next_out == Z_NULL ||
584 (strm->next_in == Z_NULL && strm->avail_in != 0))
585 return Z_STREAM_ERROR;
586
587 uInt insize = strm->avail_in;
588
589 //state = (struct inflate_state FAR *)strm->state;
590 if (state.mode == TYPE) state.mode = TYPEDO; /* skip check */
591 LOAD();
592 in = have;
593 out = left;
594 ret = Z_OK;
595 for (;;) {
596 switch (state.mode) {
597 case HEAD:
598 if (state.wrap == 0) {
599 state.mode = TYPEDO;
600 break;
601 }
602 NEEDBITS(16);
603#ifdef GUNZIP
604 if ((state.wrap & 2) && hold == 0x8b1f) { /* gzip header */
605 state.check = crc32(0L, Z_NULL, 0);
606 CRC2(state.check, hold);
607 INITBITS();
608 state.mode = FLAGS;
609 break;
610 }
611 state.flags = 0; /* expect zlib header */
612 if (state.head != Z_NULL)
613 state.head->done = -1;
614 if (!(state.wrap & 1) || /* check if zlib header allowed */
615#else
616 if (
617#endif
618 ((BITS(8) << 8) + (hold >> 8)) % 31) {
619 strm->msg = (char *)"incorrect header check";
620 state.mode = BAD;
621 break;
622 }
623 if (BITS(4) != Z_DEFLATED) {
624 strm->msg = (char *)"unknown compression method";
625 state.mode = BAD;
626 break;
627 }
628 DROPBITS(4);
629 len = BITS(4) + 8;
630 if (len > state.wbits) {
631 strm->msg = (char *)"invalid window size";
632 state.mode = BAD;
633 break;
634 }
635 state.dmax = 1U << len;
636 //DEBUGF("inflate: zlib header ok\n");
637 strm->adler = state.check = adler32(0L, Z_NULL, 0);
638 state.mode = hold & 0x200 ? DICTID : TYPE;
639 INITBITS();
640 break;
641#ifdef GUNZIP
642 case FLAGS:
643 NEEDBITS(16);
644 state.flags = (int)(hold);
645 if ((state.flags & 0xff) != Z_DEFLATED) {
646 strm->msg = (char *)"unknown compression method";
647 state.mode = BAD;
648 break;
649 }
650 if (state.flags & 0xe000) {
651 strm->msg = (char *)"unknown header flags set";
652 state.mode = BAD;
653 break;
654 }
655 if (state.head != Z_NULL)
656 state.head->text = (int)((hold >> 8) & 1);
657 if (state.flags & 0x0200) CRC2(state.check, hold);
658 INITBITS();
659 state.mode = TIME;
660 case TIME:
661 NEEDBITS(32);
662 if (state.head != Z_NULL)
663 state.head->time = hold;
664 if (state.flags & 0x0200) CRC4(state.check, hold);
665 INITBITS();
666 state.mode = OS;
667 case OS:
668 NEEDBITS(16);
669 if (state.head != Z_NULL) {
670 state.head->xflags = (int)(hold & 0xff);
671 state.head->os = (int)(hold >> 8);
672 }
673 if (state.flags & 0x0200) CRC2(state.check, hold);
674 INITBITS();
675 state.mode = EXLEN;
676 case EXLEN:
677 if (state.flags & 0x0400) {
678 NEEDBITS(16);
679 state.length = (unsigned)(hold);
680 if (state.head != Z_NULL)
681 state.head->extra_len = (unsigned)hold;
682 if (state.flags & 0x0200) CRC2(state.check, hold);
683 INITBITS();
684 }
685 else if (state.head != Z_NULL)
686 state.head->extra = Z_NULL;
687 state.mode = EXTRA;
688 case EXTRA:
689 if (state.flags & 0x0400) {
690 copy = state.length;
691 if (copy > have) copy = have;
692 if (copy) {
693 if (state.head != Z_NULL &&
694 state.head->extra != Z_NULL) {
695 len = state.head->extra_len - state.length;
696 zmemcpy(state.head->extra + len, next,
697 len + copy > state.head->extra_max ?
698 state.head->extra_max - len : copy);
699 }
700 if (state.flags & 0x0200)
701 state.check = crc32(state.check, next, copy);
702 have -= copy;
703 next += copy;
704 state.length -= copy;
705 }
706 if (state.length) goto inf_leave;
707 }
708 state.length = 0;
709 state.mode = NAME;
710 case NAME:
711 if (state.flags & 0x0800) {
712 if (have == 0) goto inf_leave;
713 copy = 0;
714 do {
715 len = (unsigned)(next[copy++]);
716 if (state.head != Z_NULL &&
717 state.head->name != Z_NULL &&
718 state.length < state.head->name_max)
719 state.head->name[state.length++] = len;
720 } while (len && copy < have);
721 if (state.flags & 0x0200)
722 state.check = crc32(state.check, next, copy);
723 have -= copy;
724 next += copy;
725 if (len) goto inf_leave;
726 }
727 else if (state.head != Z_NULL)
728 state.head->name = Z_NULL;
729 state.length = 0;
730 state.mode = COMMENT;
731 case COMMENT:
732 if (state.flags & 0x1000) {
733 if (have == 0) goto inf_leave;
734 copy = 0;
735 do {
736 len = (unsigned)(next[copy++]);
737 if (state.head != Z_NULL &&
738 state.head->comment != Z_NULL &&
739 state.length < state.head->comm_max)
740 state.head->comment[state.length++] = len;
741 } while (len && copy < have);
742 if (state.flags & 0x0200)
743 state.check = crc32(state.check, next, copy);
744 have -= copy;
745 next += copy;
746 if (len) goto inf_leave;
747 }
748 else if (state.head != Z_NULL)
749 state.head->comment = Z_NULL;
750 state.mode = HCRC;
751 case HCRC:
752 if (state.flags & 0x0200) {
753 NEEDBITS(16);
754 if (hold != (state.check & 0xffff)) {
755 strm->msg = (char *)"header crc mismatch";
756 state.mode = BAD;
757 break;
758 }
759 INITBITS();
760 }
761 if (state.head != Z_NULL) {
762 state.head->hcrc = (int)((state.flags >> 9) & 1);
763 state.head->done = 1;
764 }
765 strm->adler = state.check = crc32(0L, Z_NULL, 0);
766 state.mode = TYPE;
767 break;
768#endif
769 case DICTID:
770 NEEDBITS(32);
771 strm->adler = state.check = REVERSE(hold);
772 INITBITS();
773 state.mode = DICT;
774 case DICT:
775 if (state.havedict == 0) {
776 RESTORE();
777 return Z_NEED_DICT;
778 }
779 strm->adler = state.check = adler32(0L, Z_NULL, 0);
780 state.mode = TYPE;
781 case TYPE:
782 if (flush == Z_BLOCK) goto inf_leave;
783 case TYPEDO:
784 if (state.last) {
785 BYTEBITS();
786 state.mode = CHECK;
787 break;
788 }
789 NEEDBITS(3);
790 state.last = BITS(1);
791 DROPBITS(1);
792 switch (BITS(2)) {
793 case 0: /* stored block */
794 //DEBUGF("inflate: stored block%s\n",
795 //state.last ? " (last)" : "");
796 state.mode = STORED;
797 break;
798 case 1: /* fixed block */
799 fixedtables();
800 //DEBUGF("inflate: fixed codes block%s\n",
801 //state.last ? " (last)" : "");
802 state.mode = LEN; /* decode codes */
803 break;
804 case 2: /* dynamic block */
805 //DEBUGF("inflate: dynamic codes block%s\n",
806 //state.last ? " (last)" : "");
807 state.mode = TABLE;
808 break;
809 case 3:
810 strm->msg = (char *)"invalid block type";
811 state.mode = BAD;
812 }
813 DROPBITS(2);
814 break;
815 case STORED:
816 BYTEBITS(); /* go to byte boundary */
817 NEEDBITS(32);
818 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
819 strm->msg = (char *)"invalid stored block lengths";
820 state.mode = BAD;
821 break;
822 }
823 state.length = (unsigned)hold & 0xffff;
824 //DEBUGF("inflate: stored length %u\n",
825 //state.length);
826 INITBITS();
827 state.mode = COPY;
828 case COPY:
829 copy = state.length;
830 if (copy) {
831 if (copy > have) copy = have;
832 if (copy > left) copy = left;
833 if (copy == 0) goto inf_leave;
834 zmemcpy(put, next, copy);
835 have -= copy;
836 next += copy;
837 left -= copy;
838 put += copy;
839 state.length -= copy;
840 break;
841 }
842 //DEBUGF("inflate: stored end\n");
843 state.mode = TYPE;
844 break;
845 case TABLE:
846 NEEDBITS(14);
847 state.nlen = BITS(5) + 257;
848 DROPBITS(5);
849 state.ndist = BITS(5) + 1;
850 DROPBITS(5);
851 state.ncode = BITS(4) + 4;
852 DROPBITS(4);
853#ifndef PKZIP_BUG_WORKAROUND
854 if (state.nlen > 286 || state.ndist > 30) {
855 strm->msg = (char *)"too many length or distance symbols";
856 state.mode = BAD;
857 break;
858 }
859#endif
860 //DEBUGF("inflate: table sizes ok\n");
861 state.have = 0;
862 state.mode = LENLENS;
863 case LENLENS:
864 while (state.have < state.ncode) {
865 NEEDBITS(3);
866 state.lens[order[state.have++]] = (unsigned short)BITS(3);
867 DROPBITS(3);
868 }
869 while (state.have < 19)
870 state.lens[order[state.have++]] = 0;
871 state.next = state.codes;
872 state.lencode = (code const FAR *)(state.next);
873 state.lenbits = 7;
874 ret = inflate_table(CODES, state.lens, 19, &(state.next),
875 &(state.lenbits), state.work);
876 if (ret) {
877 strm->msg = (char *)"invalid code lengths set";
878 state.mode = BAD;
879 break;
880 }
881 //DEBUGF("inflate: code lengths ok\n");
882 state.have = 0;
883 state.mode = CODELENS;
884 case CODELENS:
885 while (state.have < state.nlen + state.ndist) {
886 for (;;) {
887 this = state.lencode[BITS(state.lenbits)];
888 if ((unsigned)(this.bits) <= bits) break;
889 PULLBYTE();
890 }
891 if (this.val < 16) {
892 NEEDBITS(this.bits);
893 DROPBITS(this.bits);
894 state.lens[state.have++] = this.val;
895 }
896 else {
897 if (this.val == 16) {
898 NEEDBITS(this.bits + 2);
899 DROPBITS(this.bits);
900 if (state.have == 0) {
901 strm->msg = (char *)"invalid bit length repeat";
902 state.mode = BAD;
903 break;
904 }
905 len = state.lens[state.have - 1];
906 copy = 3 + BITS(2);
907 DROPBITS(2);
908 }
909 else if (this.val == 17) {
910 NEEDBITS(this.bits + 3);
911 DROPBITS(this.bits);
912 len = 0;
913 copy = 3 + BITS(3);
914 DROPBITS(3);
915 }
916 else {
917 NEEDBITS(this.bits + 7);
918 DROPBITS(this.bits);
919 len = 0;
920 copy = 11 + BITS(7);
921 DROPBITS(7);
922 }
923 if (state.have + copy > state.nlen + state.ndist) {
924 strm->msg = (char *)"invalid bit length repeat";
925 state.mode = BAD;
926 break;
927 }
928 while (copy--)
929 state.lens[state.have++] = (unsigned short)len;
930 }
931 }
932
933 /* handle error breaks in while */
934 if (state.mode == BAD) break;
935
936 /* build code tables */
937 state.next = state.codes;
938 state.lencode = (code const FAR *)(state.next);
939 state.lenbits = 9;
940 ret = inflate_table(LENS, state.lens, state.nlen, &(state.next),
941 &(state.lenbits), state.work);
942 if (ret) {
943 strm->msg = (char *)"invalid literal/lengths set";
944 state.mode = BAD;
945 break;
946 }
947 state.distcode = (code const FAR *)(state.next);
948 state.distbits = 6;
949 ret = inflate_table(DISTS, state.lens + state.nlen, state.ndist,
950 &(state.next), &(state.distbits), state.work);
951 if (ret) {
952 strm->msg = (char *)"invalid distances set";
953 state.mode = BAD;
954 break;
955 }
956 //DEBUGF("inflate: codes ok\n");
957 state.mode = LEN;
958 case LEN:
959 if (have >= 6 && left >= 258) {
960 RESTORE();
961 inflate_fast(strm, out);
962 LOAD();
963 break;
964 }
965 for (;;) {
966 this = state.lencode[BITS(state.lenbits)];
967 if ((unsigned)(this.bits) <= bits) break;
968 PULLBYTE();
969 }
970 if (this.op && (this.op & 0xf0) == 0) {
971 last = this;
972 for (;;) {
973 this = state.lencode[last.val +
974 (BITS(last.bits + last.op) >> last.bits)];
975 if ((unsigned)(last.bits + this.bits) <= bits) break;
976 PULLBYTE();
977 }
978 DROPBITS(last.bits);
979 }
980 DROPBITS(this.bits);
981 state.length = (unsigned)this.val;
982 if ((int)(this.op) == 0) {
983 //DEBUGF(this.val >= 0x20 && this.val < 0x7f ?
984 //"inflate: literal '%c'\n" :
985 //"inflate: literal 0x%02x\n", this.val);
986 state.mode = LIT;
987 break;
988 }
989 if (this.op & 32) {
990 //DEBUGF("inflate: end of block\n");
991 state.mode = TYPE;
992 break;
993 }
994 if (this.op & 64) {
995 strm->msg = (char *)"invalid literal/length code";
996 state.mode = BAD;
997 break;
998 }
999 state.extra = (unsigned)(this.op) & 15;
1000 state.mode = LENEXT;
1001 case LENEXT:
1002 if (state.extra) {
1003 NEEDBITS(state.extra);
1004 state.length += BITS(state.extra);
1005 DROPBITS(state.extra);
1006 }
1007 //DEBUGF("inflate: length %u\n", state.length);
1008 state.mode = DIST;
1009 case DIST:
1010 for (;;) {
1011 this = state.distcode[BITS(state.distbits)];
1012 if ((unsigned)(this.bits) <= bits) break;
1013 PULLBYTE();
1014 }
1015 if ((this.op & 0xf0) == 0) {
1016 last = this;
1017 for (;;) {
1018 this = state.distcode[last.val +
1019 (BITS(last.bits + last.op) >> last.bits)];
1020 if ((unsigned)(last.bits + this.bits) <= bits) break;
1021 PULLBYTE();
1022 }
1023 DROPBITS(last.bits);
1024 }
1025 DROPBITS(this.bits);
1026 if (this.op & 64) {
1027 strm->msg = (char *)"invalid distance code";
1028 state.mode = BAD;
1029 break;
1030 }
1031 state.offset = (unsigned)this.val;
1032 state.extra = (unsigned)(this.op) & 15;
1033 state.mode = DISTEXT;
1034 case DISTEXT:
1035 if (state.extra) {
1036 NEEDBITS(state.extra);
1037 state.offset += BITS(state.extra);
1038 DROPBITS(state.extra);
1039 }
1040#ifdef INFLATE_STRICT
1041 if (state.offset > state.dmax) {
1042 strm->msg = (char *)"invalid distance too far back";
1043 state.mode = BAD;
1044 break;
1045 }
1046#endif
1047 if (state.offset > state.whave + out - left) {
1048 strm->msg = (char *)"invalid distance too far back";
1049 state.mode = BAD;
1050 break;
1051 }
1052 //DEBUGF("inflate: distance %u\n", state.offset);
1053 state.mode = MATCH;
1054 case MATCH:
1055 if (left == 0) goto inf_leave;
1056 copy = out - left;
1057 if (state.offset > copy) { /* copy from window */
1058 copy = state.offset - copy;
1059 if (copy > state.write) {
1060 copy -= state.write;
1061 from = state.window + (state.wsize - copy);
1062 }
1063 else
1064 from = state.window + (state.write - copy);
1065 if (copy > state.length) copy = state.length;
1066 }
1067 else { /* copy from output */
1068 from = put - state.offset;
1069 copy = state.length;
1070 }
1071 if (copy > left) copy = left;
1072 left -= copy;
1073 state.length -= copy;
1074 do {
1075 *put++ = *from++;
1076 } while (--copy);
1077 if (state.length == 0) state.mode = LEN;
1078 break;
1079 case LIT:
1080 if (left == 0) goto inf_leave;
1081 *put++ = (unsigned char)(state.length);
1082 left--;
1083 state.mode = LEN;
1084 break;
1085 case CHECK:
1086 if (state.wrap) {
1087 NEEDBITS(32);
1088 out -= left;
1089 strm->total_out += out;
1090 state.total += out;
1091 if (out)
1092 strm->adler = state.check =
1093 UPDATE(state.check, put - out, out);
1094 out = left;
1095 if ((
1096#ifdef GUNZIP
1097 state.flags ? hold :
1098#endif
1099 REVERSE(hold)) != state.check) {
1100 strm->msg = (char *)"incorrect data check";
1101 state.mode = BAD;
1102 break;
1103 }
1104 INITBITS();
1105 //DEBUGF("inflate: check matches trailer\n");
1106 }
1107#ifdef GUNZIP
1108 state.mode = LENGTH;
1109 case LENGTH:
1110 if (state.wrap && state.flags) {
1111 NEEDBITS(32);
1112 if (hold != (state.total & 0xffffffffUL)) {
1113 strm->msg = (char *)"incorrect length check";
1114 state.mode = BAD;
1115 break;
1116 }
1117 INITBITS();
1118 Tracev((stderr, "inflate: length matches trailer\n"));
1119 }
1120#endif
1121 state.mode = DONE;
1122 case DONE:
1123 ret = Z_STREAM_END;
1124 goto inf_leave;
1125 case BAD:
1126 ret = Z_DATA_ERROR;
1127 goto inf_leave;
1128 case ZMEM:
1129 return Z_MEM_ERROR;
1130 case SYNC:
1131 default:
1132 return Z_STREAM_ERROR;
1133 }
1134 //DEBUGF("%d / %d\n", strm->total_in, strm->avail_in);
1135 if (rb->button_get(false) == PNG_MENU)
1136 return PLUGIN_ABORT;
1137 else cb_progress(insize - strm->avail_in, insize);
1138 }
1139
1140 /*
1141 Return from inflate(), updating the total counts and the check value.
1142 If there was no progress during the inflate() call, return a buffer
1143 error. Call updatewindow() to create and/or update the window state.
1144 Note: a memory error from inflate() is non-recoverable.
1145 */
1146 inf_leave:
1147 RESTORE();
1148 if (state.wsize || (state.mode < CHECK && out != strm->avail_out))
1149 if (updatewindow(strm, out)) {
1150 state.mode = ZMEM;
1151 return Z_MEM_ERROR;
1152 }
1153 in -= strm->avail_in;
1154 out -= strm->avail_out;
1155 strm->total_in += in;
1156 strm->total_out += out;
1157 state.total += out;
1158 if (state.wrap && out)
1159 strm->adler = state.check =
1160 UPDATE(state.check, strm->next_out - out, out);
1161 strm->data_type = state.bits + (state.last ? 64 : 0) +
1162 (state.mode == TYPE ? 128 : 0);
1163 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1164 ret = Z_BUF_ERROR;
1165 return ret;
1166}
1167
1168int ZEXPORT inflateEnd(strm)
1169z_streamp strm;
1170{
1171 //struct inflate_state FAR *state;
1172 if (strm == Z_NULL /*|| strm->zfree == (free_func)0*/)
1173 return Z_STREAM_ERROR;
1174 //state = (struct inflate_state FAR *)strm->state;
1175 //if (state.window != Z_NULL) ZFREE(strm, state.window);
1176 //ZFREE(strm, strm->state);
1177 //strm->state = Z_NULL;
1178 //DEBUGF("inflate: end\n");
1179 return Z_OK;
1180}
1181
1182int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
1183z_streamp strm;
1184const Bytef *dictionary;
1185uInt dictLength;
1186{
1187 //struct inflate_state FAR *state;
1188 unsigned long id;
1189
1190 /* check state */
1191 if (strm == Z_NULL) return Z_STREAM_ERROR;
1192 //state = (struct inflate_state FAR *)strm->state;
1193 if (state.wrap != 0 && state.mode != DICT)
1194 return Z_STREAM_ERROR;
1195
1196 /* check for correct dictionary id */
1197 if (state.mode == DICT) {
1198 id = adler32(0L, Z_NULL, 0);
1199 id = adler32(id, dictionary, dictLength);
1200 if (id != state.check)
1201 return Z_DATA_ERROR;
1202 }
1203
1204 /* copy dictionary to window */
1205 if (updatewindow(strm, strm->avail_out)) {
1206 state.mode = ZMEM;
1207 return Z_MEM_ERROR;
1208 }
1209 if (dictLength > state.wsize) {
1210 zmemcpy(state.window, dictionary + dictLength - state.wsize,
1211 state.wsize);
1212 state.whave = state.wsize;
1213 }
1214 else {
1215 zmemcpy(state.window + state.wsize - dictLength, dictionary,
1216 dictLength);
1217 state.whave = dictLength;
1218 }
1219 state.havedict = 1;
1220 //DEBUGF("inflate: dictionary set\n");
1221 return Z_OK;
1222}
1223
1224int ZEXPORT inflateGetHeader(strm, head)
1225z_streamp strm;
1226gz_headerp head;
1227{
1228 //struct inflate_state FAR *state;
1229
1230 /* check state */
1231 if (strm == Z_NULL) return Z_STREAM_ERROR;
1232 //state = (struct inflate_state FAR *)strm->state;
1233 if ((state.wrap & 2) == 0) return Z_STREAM_ERROR;
1234
1235 /* save header structure */
1236 state.head = head;
1237 head->done = 0;
1238 return Z_OK;
1239}
1240
1241/*
1242 Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
1243 or when out of input. When called, *have is the number of pattern bytes
1244 found in order so far, in 0..3. On return *have is updated to the new
1245 state. If on return *have equals four, then the pattern was found and the
1246 return value is how many bytes were read including the last byte of the
1247 pattern. If *have is less than four, then the pattern has not been found
1248 yet and the return value is len. In the latter case, syncsearch() can be
1249 called again with more data and the *have state. *have is initialized to
1250 zero for the first call.
1251 */
1252local unsigned syncsearch(have, buf, len)
1253unsigned FAR *have;
1254unsigned char FAR *buf;
1255unsigned len;
1256{
1257 unsigned got;
1258 unsigned next;
1259
1260 got = *have;
1261 next = 0;
1262 while (next < len && got < 4) {
1263 if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
1264 got++;
1265 else if (buf[next])
1266 got = 0;
1267 else
1268 got = 4 - got;
1269 next++;
1270 }
1271 *have = got;
1272 return next;
1273}
1274
1275int ZEXPORT inflateSync(strm)
1276z_streamp strm;
1277{
1278 unsigned len; /* number of bytes to look at or looked at */
1279 unsigned long in, out; /* temporary to save total_in and total_out */
1280 unsigned char buf[4]; /* to restore bit buffer to byte string */
1281 //struct inflate_state FAR *state;
1282
1283 /* check parameters */
1284 if (strm == Z_NULL) return Z_STREAM_ERROR;
1285 //state = (struct inflate_state FAR *)strm->state;
1286 if (strm->avail_in == 0 && state.bits < 8) return Z_BUF_ERROR;
1287
1288 /* if first time, start search in bit buffer */
1289 if (state.mode != SYNC) {
1290 state.mode = SYNC;
1291 state.hold <<= state.bits & 7;
1292 state.bits -= state.bits & 7;
1293 len = 0;
1294 while (state.bits >= 8) {
1295 buf[len++] = (unsigned char)(state.hold);
1296 state.hold >>= 8;
1297 state.bits -= 8;
1298 }
1299 state.have = 0;
1300 syncsearch(&(state.have), buf, len);
1301 }
1302
1303 /* search available input */
1304 len = syncsearch(&(state.have), strm->next_in, strm->avail_in);
1305 strm->avail_in -= len;
1306 strm->next_in += len;
1307 strm->total_in += len;
1308
1309 /* return no joy or set up to restart inflate() on a new block */
1310 if (state.have != 4) return Z_DATA_ERROR;
1311 in = strm->total_in; out = strm->total_out;
1312 inflateReset(strm);
1313 strm->total_in = in; strm->total_out = out;
1314 state.mode = TYPE;
1315 return Z_OK;
1316}
1317
1318/*
1319 Returns true if inflate is currently at the end of a block generated by
1320 Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
1321 implementation to provide an additional safety check. PPP uses
1322 Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
1323 block. When decompressing, PPP checks that at the end of input packet,
1324 inflate is waiting for these length bytes.
1325 */
1326int ZEXPORT inflateSyncPoint(strm)
1327z_streamp strm;
1328{
1329 //struct inflate_state FAR *state;
1330
1331 if (strm == Z_NULL) return Z_STREAM_ERROR;
1332 //state = (struct inflate_state FAR *)strm->state;
1333 return state.mode == STORED && state.bits == 0;
1334}
diff --git a/apps/plugins/png/inflate.h b/apps/plugins/png/inflate.h
deleted file mode 100644
index d35c1bc041..0000000000
--- a/apps/plugins/png/inflate.h
+++ /dev/null
@@ -1,116 +0,0 @@
1/* inflate.h -- internal inflate state definition
2 * Copyright (C) 1995-2004 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* define NO_GZIP when compiling if you want to disable gzip header and
12 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
13 the crc code when it is not needed. For shared libraries, gzip decoding
14 should be left enabled. */
15
16#ifndef NO_GZIP
17# define GUNZIP
18#endif
19
20/* Possible inflate modes between inflate() calls */
21typedef enum {
22 HEAD, /* i: waiting for magic header */
23 FLAGS, /* i: waiting for method and flags (gzip) */
24 TIME, /* i: waiting for modification time (gzip) */
25 OS, /* i: waiting for extra flags and operating system (gzip) */
26 EXLEN, /* i: waiting for extra length (gzip) */
27 EXTRA, /* i: waiting for extra bytes (gzip) */
28 NAME, /* i: waiting for end of file name (gzip) */
29 COMMENT, /* i: waiting for end of comment (gzip) */
30 HCRC, /* i: waiting for header crc (gzip) */
31 DICTID, /* i: waiting for dictionary check value */
32 DICT, /* waiting for inflateSetDictionary() call */
33 TYPE, /* i: waiting for type bits, including last-flag bit */
34 TYPEDO, /* i: same, but skip check to exit inflate on new block */
35 STORED, /* i: waiting for stored size (length and complement) */
36 COPY, /* i/o: waiting for input or output to copy stored block */
37 TABLE, /* i: waiting for dynamic block table lengths */
38 LENLENS, /* i: waiting for code length code lengths */
39 CODELENS, /* i: waiting for length/lit and distance code lengths */
40 LEN, /* i: waiting for length/lit code */
41 LENEXT, /* i: waiting for length extra bits */
42 DIST, /* i: waiting for distance code */
43 DISTEXT, /* i: waiting for distance extra bits */
44 MATCH, /* o: waiting for output space to copy string */
45 LIT, /* o: waiting for output space to write literal */
46 CHECK, /* i: waiting for 32-bit check value */
47 LENGTH, /* i: waiting for 32-bit length (gzip) */
48 DONE, /* finished check, done -- remain here until reset */
49 BAD, /* got a data error -- remain here until reset */
50 ZMEM, /* got an inflate() memory error -- remain here until reset */
51 SYNC /* looking for synchronization bytes to restart inflate() */
52} inflate_mode;
53
54/*
55 State transitions between above modes -
56
57 (most modes can go to the BAD or MEM mode -- not shown for clarity)
58
59 Process header:
60 HEAD -> (gzip) or (zlib)
61 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
62 NAME -> COMMENT -> HCRC -> TYPE
63 (zlib) -> DICTID or TYPE
64 DICTID -> DICT -> TYPE
65 Read deflate blocks:
66 TYPE -> STORED or TABLE or LEN or CHECK
67 STORED -> COPY -> TYPE
68 TABLE -> LENLENS -> CODELENS -> LEN
69 Read deflate codes:
70 LEN -> LENEXT or LIT or TYPE
71 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
72 LIT -> LEN
73 Process trailer:
74 CHECK -> LENGTH -> DONE
75 */
76
77/* state maintained between inflate() calls. Approximately 7K bytes. */
78struct inflate_state {
79 inflate_mode mode; /* current inflate mode */
80 int last; /* true if processing last block */
81 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
82 int havedict; /* true if dictionary provided */
83 int flags; /* gzip header method and flags (0 if zlib) */
84 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
85 unsigned long check; /* protected copy of check value */
86 unsigned long total; /* protected copy of output count */
87 gz_headerp head; /* where to save gzip header information */
88 /* sliding window */
89 unsigned wbits; /* log base 2 of requested window size */
90 unsigned wsize; /* window size or zero if not using window */
91 unsigned whave; /* valid bytes in the window */
92 unsigned write; /* window write index */
93 unsigned char FAR *window; /* allocated sliding window, if needed */
94 /* bit accumulator */
95 unsigned long hold; /* input bit accumulator */
96 unsigned bits; /* number of bits in "in" */
97 /* for string and stored block copying */
98 unsigned length; /* literal or length of data to copy */
99 unsigned offset; /* distance back to copy string from */
100 /* for table and code decoding */
101 unsigned extra; /* extra bits needed */
102 /* fixed and dynamic code tables */
103 code const FAR *lencode; /* starting table for length/literal codes */
104 code const FAR *distcode; /* starting table for distance codes */
105 unsigned lenbits; /* index bits for lencode */
106 unsigned distbits; /* index bits for distcode */
107 /* dynamic table building */
108 unsigned ncode; /* number of code length code lengths */
109 unsigned nlen; /* number of length code lengths */
110 unsigned ndist; /* number of distance code lengths */
111 unsigned have; /* number of code lengths in lens[] */
112 code FAR *next; /* next available space in codes[] */
113 unsigned short lens[320]; /* temporary storage for code lengths */
114 unsigned short work[288]; /* work area for code table building */
115 code codes[ENOUGH]; /* space for code tables */
116};
diff --git a/apps/plugins/png/inftrees.c b/apps/plugins/png/inftrees.c
deleted file mode 100644
index 8a9c13ff03..0000000000
--- a/apps/plugins/png/inftrees.c
+++ /dev/null
@@ -1,329 +0,0 @@
1/* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2005 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8
9#define MAXBITS 15
10
11const char inflate_copyright[] =
12 " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
13/*
14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot
16 include such an acknowledgment, I would appreciate that you keep this
17 copyright string in the executable of your product.
18 */
19
20/*
21 Build a set of tables to decode the provided canonical Huffman code.
22 The code lengths are lens[0..codes-1]. The result starts at *table,
23 whose indices are 0..2^bits-1. work is a writable array of at least
24 lens shorts, which is used as a work area. type is the type of code
25 to be generated, CODES, LENS, or DISTS. On return, zero is success,
26 -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
27 on return points to the next available entry's address. bits is the
28 requested root table index bits, and on return it is the actual root
29 table index bits. It will differ if the request is greater than the
30 longest code or if it is less than the shortest code.
31 */
32int inflate_table(type, lens, codes, table, bits, work)
33codetype type;
34unsigned short FAR *lens;
35unsigned codes;
36code FAR * FAR *table;
37unsigned FAR *bits;
38unsigned short FAR *work;
39{
40 unsigned len; /* a code's length in bits */
41 unsigned sym; /* index of code symbols */
42 unsigned min, max; /* minimum and maximum code lengths */
43 unsigned root; /* number of index bits for root table */
44 unsigned curr; /* number of index bits for current table */
45 unsigned drop; /* code bits to drop for sub-table */
46 int left; /* number of prefix codes available */
47 unsigned used; /* code entries in table used */
48 unsigned huff; /* Huffman code */
49 unsigned incr; /* for incrementing code, index */
50 unsigned fill; /* index for replicating entries */
51 unsigned low; /* low bits for current root entry */
52 unsigned mask; /* mask for low root bits */
53 code this; /* table entry for duplication */
54 code FAR *next; /* next available space in table */
55 const unsigned short FAR *base; /* base value table to use */
56 const unsigned short FAR *extra; /* extra bits table to use */
57 int end; /* use base and extra for symbol > end */
58 unsigned short count[MAXBITS+1]; /* number of codes of each length */
59 unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
60 static const unsigned short lbase[31] = { /* Length codes 257..285 base */
61 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
69 8193, 12289, 16385, 24577, 0, 0};
70 static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
71 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
72 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
73 28, 28, 29, 29, 64, 64};
74
75 /*
76 Process a set of code lengths to create a canonical Huffman code. The
77 code lengths are lens[0..codes-1]. Each length corresponds to the
78 symbols 0..codes-1. The Huffman code is generated by first sorting the
79 symbols by length from short to long, and retaining the symbol order
80 for codes with equal lengths. Then the code starts with all zero bits
81 for the first code of the shortest length, and the codes are integer
82 increments for the same length, and zeros are appended as the length
83 increases. For the deflate format, these bits are stored backwards
84 from their more natural integer increment ordering, and so when the
85 decoding tables are built in the large loop below, the integer codes
86 are incremented backwards.
87
88 This routine assumes, but does not check, that all of the entries in
89 lens[] are in the range 0..MAXBITS. The caller must assure this.
90 1..MAXBITS is interpreted as that code length. zero means that that
91 symbol does not occur in this code.
92
93 The codes are sorted by computing a count of codes for each length,
94 creating from that a table of starting indices for each length in the
95 sorted table, and then entering the symbols in order in the sorted
96 table. The sorted table is work[], with that space being provided by
97 the caller.
98
99 The length counts are used for other purposes as well, i.e. finding
100 the minimum and maximum length codes, determining if there are any
101 codes at all, checking for a valid set of lengths, and looking ahead
102 at length counts to determine sub-table sizes when building the
103 decoding tables.
104 */
105
106 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
107 for (len = 0; len <= MAXBITS; len++)
108 count[len] = 0;
109 for (sym = 0; sym < codes; sym++)
110 count[lens[sym]]++;
111
112 /* bound code lengths, force root to be within code lengths */
113 root = *bits;
114 for (max = MAXBITS; max >= 1; max--)
115 if (count[max] != 0) break;
116 if (root > max) root = max;
117 if (max == 0) { /* no symbols to code at all */
118 this.op = (unsigned char)64; /* invalid code marker */
119 this.bits = (unsigned char)1;
120 this.val = (unsigned short)0;
121 *(*table)++ = this; /* make a table to force an error */
122 *(*table)++ = this;
123 *bits = 1;
124 return 0; /* no symbols, but wait for decoding to report error */
125 }
126 for (min = 1; min <= MAXBITS; min++)
127 if (count[min] != 0) break;
128 if (root < min) root = min;
129
130 /* check for an over-subscribed or incomplete set of lengths */
131 left = 1;
132 for (len = 1; len <= MAXBITS; len++) {
133 left <<= 1;
134 left -= count[len];
135 if (left < 0) return -1; /* over-subscribed */
136 }
137 if (left > 0 && (type == CODES || max != 1))
138 return -1; /* incomplete set */
139
140 /* generate offsets into symbol table for each length for sorting */
141 offs[1] = 0;
142 for (len = 1; len < MAXBITS; len++)
143 offs[len + 1] = offs[len] + count[len];
144
145 /* sort symbols by length, by symbol order within each length */
146 for (sym = 0; sym < codes; sym++)
147 if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
148
149 /*
150 Create and fill in decoding tables. In this loop, the table being
151 filled is at next and has curr index bits. The code being used is huff
152 with length len. That code is converted to an index by dropping drop
153 bits off of the bottom. For codes where len is less than drop + curr,
154 those top drop + curr - len bits are incremented through all values to
155 fill the table with replicated entries.
156
157 root is the number of index bits for the root table. When len exceeds
158 root, sub-tables are created pointed to by the root entry with an index
159 of the low root bits of huff. This is saved in low to check for when a
160 new sub-table should be started. drop is zero when the root table is
161 being filled, and drop is root when sub-tables are being filled.
162
163 When a new sub-table is needed, it is necessary to look ahead in the
164 code lengths to determine what size sub-table is needed. The length
165 counts are used for this, and so count[] is decremented as codes are
166 entered in the tables.
167
168 used keeps track of how many table entries have been allocated from the
169 provided *table space. It is checked when a LENS table is being made
170 against the space in *table, ENOUGH, minus the maximum space needed by
171 the worst case distance code, MAXD. This should never happen, but the
172 sufficiency of ENOUGH has not been proven exhaustively, hence the check.
173 This assumes that when type == LENS, bits == 9.
174
175 sym increments through all symbols, and the loop terminates when
176 all codes of length max, i.e. all codes, have been processed. This
177 routine permits incomplete codes, so another loop after this one fills
178 in the rest of the decoding tables with invalid code markers.
179 */
180
181 /* set up for code type */
182 switch (type) {
183 case CODES:
184 base = extra = work; /* dummy value--not used */
185 end = 19;
186 break;
187 case LENS:
188 base = lbase;
189 base -= 257;
190 extra = lext;
191 extra -= 257;
192 end = 256;
193 break;
194 default: /* DISTS */
195 base = dbase;
196 extra = dext;
197 end = -1;
198 }
199
200 /* initialize state for loop */
201 huff = 0; /* starting code */
202 sym = 0; /* starting code symbol */
203 len = min; /* starting code length */
204 next = *table; /* current table to fill in */
205 curr = root; /* current table index bits */
206 drop = 0; /* current bits to drop from code for index */
207 low = (unsigned)(-1); /* trigger new sub-table when len > root */
208 used = 1U << root; /* use root table entries */
209 mask = used - 1; /* mask for comparing low */
210
211 /* check available table space */
212 if (type == LENS && used >= ENOUGH - MAXD)
213 return 1;
214
215 /* process all codes and make table entries */
216 for (;;) {
217 /* create table entry */
218 this.bits = (unsigned char)(len - drop);
219 if ((int)(work[sym]) < end) {
220 this.op = (unsigned char)0;
221 this.val = work[sym];
222 }
223 else if ((int)(work[sym]) > end) {
224 this.op = (unsigned char)(extra[work[sym]]);
225 this.val = base[work[sym]];
226 }
227 else {
228 this.op = (unsigned char)(32 + 64); /* end of block */
229 this.val = 0;
230 }
231
232 /* replicate for those indices with low len bits equal to huff */
233 incr = 1U << (len - drop);
234 fill = 1U << curr;
235 min = fill; /* save offset to next table */
236 do {
237 fill -= incr;
238 next[(huff >> drop) + fill] = this;
239 } while (fill != 0);
240
241 /* backwards increment the len-bit code huff */
242 incr = 1U << (len - 1);
243 while (huff & incr)
244 incr >>= 1;
245 if (incr != 0) {
246 huff &= incr - 1;
247 huff += incr;
248 }
249 else
250 huff = 0;
251
252 /* go to next symbol, update count, len */
253 sym++;
254 if (--(count[len]) == 0) {
255 if (len == max) break;
256 len = lens[work[sym]];
257 }
258
259 /* create new sub-table if needed */
260 if (len > root && (huff & mask) != low) {
261 /* if first time, transition to sub-tables */
262 if (drop == 0)
263 drop = root;
264
265 /* increment past last table */
266 next += min; /* here min is 1 << curr */
267
268 /* determine length of next table */
269 curr = len - drop;
270 left = (int)(1 << curr);
271 while (curr + drop < max) {
272 left -= count[curr + drop];
273 if (left <= 0) break;
274 curr++;
275 left <<= 1;
276 }
277
278 /* check for enough space */
279 used += 1U << curr;
280 if (type == LENS && used >= ENOUGH - MAXD)
281 return 1;
282
283 /* point entry in root table to sub-table */
284 low = huff & mask;
285 (*table)[low].op = (unsigned char)curr;
286 (*table)[low].bits = (unsigned char)root;
287 (*table)[low].val = (unsigned short)(next - *table);
288 }
289 }
290
291 /*
292 Fill in rest of table for incomplete codes. This loop is similar to the
293 loop above in incrementing huff for table indices. It is assumed that
294 len is equal to curr + drop, so there is no loop needed to increment
295 through high index bits. When the current sub-table is filled, the loop
296 drops back to the root table to fill in any remaining entries there.
297 */
298 this.op = (unsigned char)64; /* invalid code marker */
299 this.bits = (unsigned char)(len - drop);
300 this.val = (unsigned short)0;
301 while (huff != 0) {
302 /* when done with sub-table, drop back to root table */
303 if (drop != 0 && (huff & mask) != low) {
304 drop = 0;
305 len = root;
306 next = *table;
307 this.bits = (unsigned char)len;
308 }
309
310 /* put invalid code marker in table */
311 next[huff >> drop] = this;
312
313 /* backwards increment the len-bit code huff */
314 incr = 1U << (len - 1);
315 while (huff & incr)
316 incr >>= 1;
317 if (incr != 0) {
318 huff &= incr - 1;
319 huff += incr;
320 }
321 else
322 huff = 0;
323 }
324
325 /* set return parameters */
326 *table += used;
327 *bits = root;
328 return 0;
329}
diff --git a/apps/plugins/png/inftrees.h b/apps/plugins/png/inftrees.h
deleted file mode 100644
index b1104c87e7..0000000000
--- a/apps/plugins/png/inftrees.h
+++ /dev/null
@@ -1,55 +0,0 @@
1/* inftrees.h -- header to use inftrees.c
2 * Copyright (C) 1995-2005 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* Structure for decoding tables. Each entry provides either the
12 information needed to do the operation requested by the code that
13 indexed that table entry, or it provides a pointer to another
14 table that indexes more bits of the code. op indicates whether
15 the entry is a pointer to another table, a literal, a length or
16 distance, an end-of-block, or an invalid code. For a table
17 pointer, the low four bits of op is the number of index bits of
18 that table. For a length or distance, the low four bits of op
19 is the number of extra bits to get after the code. bits is
20 the number of bits in this code or part of the code to drop off
21 of the bit buffer. val is the actual byte to output in the case
22 of a literal, the base length or distance, or the offset from
23 the current table to the next table. Each entry is four bytes. */
24typedef struct {
25 unsigned char op; /* operation, extra bits, table bits */
26 unsigned char bits; /* bits in this part of the code */
27 unsigned short val; /* offset in table or code value */
28} code;
29
30/* op values as set by inflate_table():
31 00000000 - literal
32 0000tttt - table link, tttt != 0 is the number of table index bits
33 0001eeee - length or distance, eeee is the number of extra bits
34 01100000 - end of block
35 01000000 - invalid code
36 */
37
38/* Maximum size of dynamic tree. The maximum found in a long but non-
39 exhaustive search was 1444 code structures (852 for length/literals
40 and 592 for distances, the latter actually the result of an
41 exhaustive search). The true maximum is not known, but the value
42 below is more than safe. */
43#define ENOUGH 2048
44#define MAXD 592
45
46/* Type of code to build for inftable() */
47typedef enum {
48 CODES,
49 LENS,
50 DISTS
51} codetype;
52
53extern int inflate_table OF((codetype type, unsigned short FAR *lens,
54 unsigned codes, code FAR * FAR *table,
55 unsigned FAR *bits, unsigned short FAR *work));
diff --git a/apps/plugins/png/png.c b/apps/plugins/png/png.c
deleted file mode 100644
index 3f826001c9..0000000000
--- a/apps/plugins/png/png.c
+++ /dev/null
@@ -1,2271 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$id $
9 *
10 * Copyright (C) 2009 by Christophe Gouiran <bechris13250 -at- gmail -dot- com>
11 *
12 * Based on lodepng, a lightweight png decoder/encoder
13 * (c) 2005-2008 Lode Vandevenne
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25/*
26LodePNG version 20080927
27
28Copyright (c) 2005-2008 Lode Vandevenne
29
30This software is provided 'as-is', without any express or implied
31warranty. In no event will the authors be held liable for any damages
32arising from the use of this software.
33
34Permission is granted to anyone to use this software for any purpose,
35including commercial applications, and to alter it and redistribute it
36freely, subject to the following restrictions:
37
38 1. The origin of this software must not be misrepresented; you must not
39 claim that you wrote the original software. If you use this software
40 in a product, an acknowledgment in the product documentation would be
41 appreciated but is not required.
42
43 2. Altered source versions must be plainly marked as such, and must not be
44 misrepresented as being the original software.
45
46 3. This notice may not be removed or altered from any source
47 distribution.
48*/
49
50/*
51The manual and changelog can be found in the header file "lodepng.h"
52You are free to name this file lodepng.cpp or lodepng.c depending on your usage.
53*/
54
55#include "plugin.h"
56#include "lcd.h"
57#include <lib/playback_control.h>
58#include <lib/helper.h>
59#include <lib/configfile.h>
60#include <lib/grey.h>
61#include <lib/pluginlib_bmp.h>
62#include "zlib.h"
63#include "png.h"
64
65PLUGIN_HEADER
66
67/* ////////////////////////////////////////////////////////////////////////// */
68/* LodeFlate & LodeZlib Setting structs */
69/* ////////////////////////////////////////////////////////////////////////// */
70
71typedef struct LodePNG_InfoColor /*info about the color type of an image*/
72{
73 /*header (IHDR)*/
74 unsigned colorType; /*color type*/
75 unsigned bitDepth; /*bits per sample*/
76
77 /*palette (PLTE)*/
78 unsigned char palette[256 * 4]; /*palette in RGBARGBA... order*/
79 size_t palettesize; /*palette size in number of colors (amount of bytes is 4 * palettesize)*/
80
81 /*transparent color key (tRNS)*/
82 unsigned key_defined; /*is a transparent color key given?*/
83 unsigned key_r; /*red component of color key*/
84 unsigned key_g; /*green component of color key*/
85 unsigned key_b; /*blue component of color key*/
86} LodePNG_InfoColor;
87
88typedef struct LodePNG_Time /*LodePNG's encoder does not generate the current time. To make it add a time chunk the correct time has to be provided*/
89{
90 unsigned year; /*2 bytes*/
91 unsigned char month; /*1-12*/
92 unsigned char day; /*1-31*/
93 unsigned char hour; /*0-23*/
94 unsigned char minute; /*0-59*/
95 unsigned char second; /*0-60 (to allow for leap seconds)*/
96} LodePNG_Time;
97
98typedef struct LodePNG_InfoPng /*information about the PNG image, except pixels and sometimes except width and height*/
99{
100 /*header (IHDR), palette (PLTE) and transparency (tRNS)*/
101 unsigned width; /*width of the image in pixels (ignored by encoder, but filled in by decoder)*/
102 unsigned height; /*height of the image in pixels (ignored by encoder, but filled in by decoder)*/
103 unsigned compressionMethod; /*compression method of the original file*/
104 unsigned filterMethod; /*filter method of the original file*/
105 unsigned interlaceMethod; /*interlace method of the original file*/
106 LodePNG_InfoColor color; /*color type and bits, palette, transparency*/
107
108 /*suggested background color (bKGD)*/
109 unsigned background_defined; /*is a suggested background color given?*/
110 unsigned background_r; /*red component of suggested background color*/
111 unsigned background_g; /*green component of suggested background color*/
112 unsigned background_b; /*blue component of suggested background color*/
113
114 /*time chunk (tIME)*/
115 unsigned char time_defined; /*if 0, no tIME chunk was or will be generated in the PNG image*/
116 LodePNG_Time time;
117
118 /*phys chunk (pHYs)*/
119 unsigned phys_defined; /*is pHYs chunk defined?*/
120 unsigned phys_x;
121 unsigned phys_y;
122 unsigned char phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/
123
124} LodePNG_InfoPng;
125
126typedef struct LodePNG_InfoRaw /*contains user-chosen information about the raw image data, which is independent of the PNG image*/
127{
128 LodePNG_InfoColor color;
129} LodePNG_InfoRaw;
130
131typedef struct LodePNG_DecodeSettings
132{
133 unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/
134} LodePNG_DecodeSettings;
135
136typedef struct LodePNG_Decoder
137{
138 LodePNG_DecodeSettings settings;
139 LodePNG_InfoRaw infoRaw;
140 LodePNG_InfoPng infoPng; /*info of the PNG image obtained after decoding*/
141 long error;
142 char error_msg[128];
143 int x,y;
144 int width,height;
145} LodePNG_Decoder;
146
147#define VERSION_STRING "20080927"
148
149/* Min memory allowing us to use the plugin buffer
150 * and thus not stopping the music
151 * *Very* rough estimation:
152 * Max 10 000 dir entries * 4bytes/entry (char **) = 40000 bytes
153 * + 30k code size = 70 000
154 * + 50k min for png = 130 000
155 */
156#define MIN_MEM 130000
157
158/* Headings */
159#define DIR_PREV 1
160#define DIR_NEXT -1
161#define DIR_NONE 0
162
163/* decompressed image in the possible sizes (1,2,4,8), wasting the other */
164static fb_data *disp[9];
165/* up to here currently used by image(s) */
166static fb_data *disp_buf;
167
168/* my memory pool (from the mp3 buffer) */
169static char print[128]; /* use a common snprintf() buffer */
170
171unsigned char *memory, *memory_max;
172static size_t memory_size;
173
174static unsigned char *image; /* where we put the content of the file */
175static size_t image_size;
176
177static fb_data *converted_image; /* the (color) converted image */
178static size_t converted_image_size;
179
180static unsigned char *decoded_image; /* the decoded image */
181static size_t decoded_image_size;
182
183static fb_data *resized_image; /* the decoded image */
184
185static struct tree_context *tree;
186
187/* the current full file name */
188static char np_file[MAX_PATH];
189static int curfile = 0, direction = DIR_NONE, entries = 0;
190
191static LodePNG_Decoder decoder;
192
193/* list of the png files */
194static char **file_pt;
195#if PLUGIN_BUFFER_SIZE >= MIN_MEM
196/* are we using the plugin buffer or the audio buffer? */
197static bool plug_buf = true;
198#endif
199
200/* Persistent configuration */
201#define PNG_CONFIGFILE "png.cfg"
202#define PNG_SETTINGS_MINVERSION 1
203#define PNG_SETTINGS_VERSION 1
204
205/* Slideshow times */
206#define SS_MIN_TIMEOUT 1
207#define SS_MAX_TIMEOUT 20
208#define SS_DEFAULT_TIMEOUT 5
209
210struct png_settings
211{
212 int ss_timeout;
213};
214
215static struct png_settings png_settings =
216 {
217 SS_DEFAULT_TIMEOUT
218 };
219static struct png_settings old_settings;
220
221static struct configdata png_config[] =
222 {
223 { TYPE_INT, SS_MIN_TIMEOUT, SS_MAX_TIMEOUT,
224 { .int_p = &png_settings.ss_timeout }, "Slideshow Time", NULL
225 },
226 };
227
228#if LCD_DEPTH > 1
229static fb_data* old_backdrop;
230#endif
231
232static int slideshow_enabled = false; /* run slideshow */
233static int running_slideshow = false; /* loading image because of slideshw */
234#ifndef SIMULATOR
235static int immediate_ata_off = false; /* power down disk after loading */
236#endif
237
238static unsigned ds, ds_min, ds_max; /* downscaling and limits */
239
240/*
241The two functions below (LodePNG_decompress and LodePNG_compress) directly call the
242LodeZlib_decompress and LodeZlib_compress functions. The only purpose of the functions
243below, is to provide the ability to let LodePNG use a different Zlib encoder by only
244changing the two functions below, instead of changing it inside the vareous places
245in the other LodePNG functions.
246
247*out must be NULL and *outsize must be 0 initially, and after the function is done,
248*out must point to the decompressed data, *outsize must be the size of it, and must
249be the size of the useful data in bytes, not the alloc size.
250*/
251
252static unsigned LodePNG_decompress(unsigned char* out, size_t* outsize, const unsigned char* in, size_t insize, char *error_msg)
253{
254 z_stream stream;
255 int err;
256
257 rb->strcpy(error_msg, "");
258
259 stream.next_in = (Bytef*)in;
260 stream.avail_in = (uInt)insize;
261
262 stream.next_out = out;
263 stream.avail_out = (uInt)*outsize;
264
265 stream.zalloc = (alloc_func)0;
266 stream.zfree = (free_func)0;
267
268 err = inflateInit(&stream);
269 if (err != Z_OK) return err;
270
271 err = inflate(&stream, Z_FINISH);
272 if (err != Z_STREAM_END) {
273 inflateEnd(&stream);
274 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
275 return Z_DATA_ERROR;
276 return err;
277 }
278 *outsize = stream.total_out;
279
280 err = inflateEnd(&stream);
281 if (stream.msg != Z_NULL)
282 rb->strcpy(error_msg, stream.msg);
283 return err;
284
285}
286
287/* ////////////////////////////////////////////////////////////////////////// */
288/* / Reading and writing single bits and bytes from/to stream for LodePNG / */
289/* ////////////////////////////////////////////////////////////////////////// */
290
291static unsigned char readBitFromReversedStream(size_t* bitpointer, const unsigned char* bitstream)
292{
293 unsigned char result = (unsigned char)((bitstream[(*bitpointer) >> 3] >> (7 - ((*bitpointer) & 0x7))) & 1);
294 (*bitpointer)++;
295 return result;
296}
297
298static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned char* bitstream, size_t nbits)
299{
300 unsigned result = 0;
301 size_t i;
302 for (i = nbits - 1; i < nbits; i--) result += (unsigned)readBitFromReversedStream(bitpointer, bitstream) << i;
303 return result;
304}
305
306static void setBitOfReversedStream0(size_t* bitpointer, unsigned char* bitstream, unsigned char bit)
307{
308 /*the current bit in bitstream must be 0 for this to work*/
309 if (bit) bitstream[(*bitpointer) >> 3] |= (bit << (7 - ((*bitpointer) & 0x7))); /*earlier bit of huffman code is in a lesser significant bit of an earlier byte*/
310 (*bitpointer)++;
311}
312
313static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, unsigned char bit)
314{
315 /*the current bit in bitstream may be 0 or 1 for this to work*/
316 if (bit == 0) bitstream[(*bitpointer) >> 3] &= (unsigned char)(~(1 << (7 - ((*bitpointer) & 0x7))));
317 else bitstream[(*bitpointer) >> 3] |= (1 << (7 - ((*bitpointer) & 0x7)));
318 (*bitpointer)++;
319}
320
321static unsigned LodePNG_read32bitInt(const unsigned char* buffer)
322{
323 return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
324}
325
326/* ////////////////////////////////////////////////////////////////////////// */
327/* / PNG chunks / */
328/* ////////////////////////////////////////////////////////////////////////// */
329
330unsigned LodePNG_chunk_length(const unsigned char* chunk) /*get the length of the data of the chunk. Total chunk length has 12 bytes more.*/
331{
332 return LodePNG_read32bitInt(&chunk[0]);
333}
334
335void LodePNG_chunk_type(char type[5], const unsigned char* chunk) /*puts the 4-byte type in null terminated string*/
336{
337 unsigned i;
338 for (i = 0; i < 4; i++) type[i] = chunk[4 + i];
339 type[4] = 0; /*null termination char*/
340}
341
342unsigned char LodePNG_chunk_type_equals(const unsigned char* chunk, const char* type) /*check if the type is the given type*/
343{
344 if (type[4] != 0) return 0;
345 return (chunk[4] == type[0] && chunk[5] == type[1] && chunk[6] == type[2] && chunk[7] == type[3]);
346}
347
348/*properties of PNG chunks gotten from capitalization of chunk type name, as defined by the standard*/
349unsigned char LodePNG_chunk_critical(const unsigned char* chunk) /*0: ancillary chunk, 1: it's one of the critical chunk types*/
350{
351 return((chunk[4] & 32) == 0);
352}
353
354unsigned char LodePNG_chunk_private(const unsigned char* chunk) /*0: public, 1: private*/
355{
356 return((chunk[6] & 32) != 0);
357}
358
359unsigned char LodePNG_chunk_safetocopy(const unsigned char* chunk) /*0: the chunk is unsafe to copy, 1: the chunk is safe to copy*/
360{
361 return((chunk[7] & 32) != 0);
362}
363
364unsigned char* LodePNG_chunk_data(unsigned char* chunk) /*get pointer to the data of the chunk*/
365{
366 return &chunk[8];
367}
368
369const unsigned char* LodePNG_chunk_data_const(const unsigned char* chunk) /*get pointer to the data of the chunk*/
370{
371 return &chunk[8];
372}
373
374unsigned LodePNG_chunk_check_crc(const unsigned char* chunk) /*returns 0 if the crc is correct, error code if it's incorrect*/
375{
376 unsigned length = LodePNG_chunk_length(chunk);
377 unsigned CRC = LodePNG_read32bitInt(&chunk[length + 8]);
378 unsigned checksum = crc32(0L, &chunk[4], length + 4); /*the CRC is taken of the data and the 4 chunk type letters, not the length*/
379 if (CRC != checksum) return 1;
380 else return 0;
381}
382
383unsigned char* LodePNG_chunk_next(unsigned char* chunk) /*don't use on IEND chunk, as there is no next chunk then*/
384{
385 unsigned total_chunk_length = LodePNG_chunk_length(chunk) + 12;
386 return &chunk[total_chunk_length];
387}
388
389const unsigned char* LodePNG_chunk_next_const(const unsigned char* chunk) /*don't use on IEND chunk, as there is no next chunk then*/
390{
391 unsigned total_chunk_length = LodePNG_chunk_length(chunk) + 12;
392 return &chunk[total_chunk_length];
393}
394
395/* ////////////////////////////////////////////////////////////////////////// */
396/* / Color types and such / */
397/* ////////////////////////////////////////////////////////////////////////// */
398
399/*return type is a LodePNG error code*/
400static unsigned checkColorValidity(unsigned colorType, unsigned bd) /*bd = bitDepth*/
401{
402 switch (colorType)
403 {
404 case 0:
405 if (!(bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16)) return 37; break; /*grey*/
406 case 2:
407 if (!( bd == 8 || bd == 16)) return 37; break; /*RGB*/
408 case 3:
409 if (!(bd == 1 || bd == 2 || bd == 4 || bd == 8 )) return 37; break; /*palette*/
410 case 4:
411 if (!( bd == 8 || bd == 16)) return 37; break; /*grey + alpha*/
412 case 6:
413 if (!( bd == 8 || bd == 16)) return 37; break; /*RGBA*/
414 default:
415 return 31;
416 }
417 return 0; /*allowed color type / bits combination*/
418}
419
420static unsigned getNumColorChannels(unsigned colorType)
421{
422 switch (colorType)
423 {
424 case 0:
425 return 1; /*grey*/
426 case 2:
427 return 3; /*RGB*/
428 case 3:
429 return 1; /*palette*/
430 case 4:
431 return 2; /*grey + alpha*/
432 case 6:
433 return 4; /*RGBA*/
434 }
435 return 0; /*unexisting color type*/
436}
437
438static unsigned getBpp(unsigned colorType, unsigned bitDepth)
439{
440 return getNumColorChannels(colorType) * bitDepth; /*bits per pixel is amount of channels * bits per channel*/
441}
442
443/* ////////////////////////////////////////////////////////////////////////// */
444
445void LodePNG_InfoColor_init(LodePNG_InfoColor* info)
446{
447 info->key_defined = 0;
448 info->key_r = info->key_g = info->key_b = 0;
449 info->colorType = 6;
450 info->bitDepth = 8;
451 memset(info->palette, 0, 256 * 4 * sizeof(unsigned char));
452 info->palettesize = 0;
453}
454
455void LodePNG_InfoColor_cleanup(LodePNG_InfoColor* info)
456{
457 info->palettesize = 0;
458}
459
460unsigned LodePNG_InfoColor_getBpp(const LodePNG_InfoColor* info) { return getBpp(info->colorType, info->bitDepth); } /*calculate bits per pixel out of colorType and bitDepth*/
461unsigned LodePNG_InfoColor_isGreyscaleType(const LodePNG_InfoColor* info) { return info->colorType == 0 || info->colorType == 4; }
462
463unsigned LodePNG_InfoColor_equal(const LodePNG_InfoColor* info1, const LodePNG_InfoColor* info2)
464{
465 return info1->colorType == info2->colorType
466 && info1->bitDepth == info2->bitDepth; /*palette and color key not compared*/
467}
468
469void LodePNG_InfoPng_init(LodePNG_InfoPng* info)
470{
471 info->width = info->height = 0;
472 LodePNG_InfoColor_init(&info->color);
473 info->interlaceMethod = 0;
474 info->compressionMethod = 0;
475 info->filterMethod = 0;
476 info->background_defined = 0;
477 info->background_r = info->background_g = info->background_b = 0;
478
479 info->time_defined = 0;
480 info->phys_defined = 0;
481}
482
483void LodePNG_InfoPng_cleanup(LodePNG_InfoPng* info)
484{
485 LodePNG_InfoColor_cleanup(&info->color);
486}
487
488unsigned LodePNG_InfoColor_copy(LodePNG_InfoColor* dest, const LodePNG_InfoColor* source)
489{
490 size_t i;
491 LodePNG_InfoColor_cleanup(dest);
492 *dest = *source;
493 for (i = 0; i < source->palettesize * 4; i++) dest->palette[i] = source->palette[i];
494 return 0;
495}
496
497unsigned LodePNG_InfoPng_copy(LodePNG_InfoPng* dest, const LodePNG_InfoPng* source)
498{
499 unsigned error = 0;
500 LodePNG_InfoPng_cleanup(dest);
501 *dest = *source;
502 LodePNG_InfoColor_init(&dest->color);
503 error = LodePNG_InfoColor_copy(&dest->color, &source->color); if (error) return error;
504 return error;
505}
506
507void LodePNG_InfoPng_swap(LodePNG_InfoPng* a, LodePNG_InfoPng* b)
508{
509 LodePNG_InfoPng temp = *a;
510 *a = *b;
511 *b = temp;
512}
513
514void LodePNG_InfoRaw_init(LodePNG_InfoRaw* info)
515{
516 LodePNG_InfoColor_init(&info->color);
517}
518
519void LodePNG_InfoRaw_cleanup(LodePNG_InfoRaw* info)
520{
521 LodePNG_InfoColor_cleanup(&info->color);
522}
523
524unsigned LodePNG_InfoRaw_copy(LodePNG_InfoRaw* dest, const LodePNG_InfoRaw* source)
525{
526 unsigned error = 0;
527 LodePNG_InfoRaw_cleanup(dest);
528 *dest = *source;
529 LodePNG_InfoColor_init(&dest->color);
530 error = LodePNG_InfoColor_copy(&dest->color, &source->color); if (error) return error;
531 return error;
532}
533
534/* ////////////////////////////////////////////////////////////////////////// */
535
536/*
537converts from any color type to 24-bit or 32-bit (later maybe more supported). return value = LodePNG error code
538the out buffer must have (w * h * bpp + 7) / 8 bytes, where bpp is the bits per pixel of the output color type (LodePNG_InfoColor_getBpp)
539for < 8 bpp images, there may _not_ be padding bits at the end of scanlines.
540*/
541unsigned LodePNG_convert(fb_data* out, const unsigned char* in, LodePNG_InfoColor* infoOut, LodePNG_InfoColor* infoIn, unsigned w, unsigned h)
542{
543 size_t i, j, bp = 0; /*bitpointer, used by less-than-8-bit color types*/
544 size_t x, y;
545 unsigned char c;
546
547 if (!running_slideshow)
548 {
549 rb->snprintf(print, sizeof(print), "color conversion in progress");
550 rb->lcd_puts(0, 3, print);
551 rb->lcd_update();
552 }
553
554 /*cases where in and out already have the same format*/
555 if (LodePNG_InfoColor_equal(infoIn, infoOut))
556 {
557
558 i = 0;
559 j = 0;
560 for (y = 0 ; y < h ; y++) {
561 for (x = 0 ; x < w ; x++) {
562 unsigned char r = in[i++];
563 unsigned char g = in[i++];
564 unsigned char b = in[i++];
565 out[j++] = LCD_RGBPACK(r,g,b);
566 }
567 }
568 return 0;
569 }
570
571 if ((infoOut->colorType == 2 || infoOut->colorType == 6) && infoOut->bitDepth == 8)
572 {
573 if (infoIn->bitDepth == 8)
574 {
575 switch (infoIn->colorType)
576 {
577 case 0: /*greyscale color*/
578 i = 0;
579 for (y = 0 ; y < h ; y++) {
580 for (x = 0 ; x < w ; x++) {
581 c=in[i];
582 //unsigned char r = in[i];
583 //unsigned char g = in[i];
584 //unsigned char b = in[i];
585 out[i++] = LCD_RGBPACK(c,c,c);
586 }
587 }
588 break;
589 case 2: /*RGB color*/
590 i = 0;
591 for (y = 0 ; y < h ; y++) {
592 for (x = 0 ; x < w ; x++) {
593 j = 3 * i;
594 unsigned char r = in[j];
595 unsigned char g = in[j + 1];
596 unsigned char b = in[j + 2];
597 out[i++] = LCD_RGBPACK(r,g,b);
598 }
599 }
600 break;
601 case 3: /*indexed color (palette)*/
602 i = 0;
603 for (y = 0 ; y < h ; y++) {
604 for (x = 0 ; x < w ; x++) {
605 if (in[i] >= infoIn->palettesize) return 46;
606 j = in[i] << 2;
607 unsigned char r = infoIn->palette[j];
608 unsigned char g = infoIn->palette[j + 1];
609 unsigned char b = infoIn->palette[j + 2];
610 out[i++] = LCD_RGBPACK(r,g,b);
611 }
612 }
613 break;
614 case 4: /*greyscale with alpha*/
615 i = 0;
616 for (y = 0 ; y < h ; y++) {
617 for (x = 0 ; x < w ; x++) {
618 c = in[i << 1];
619 //unsigned char r = in[i<<1];
620 //unsigned char g = in[i<<1];
621 //unsigned char b = in[i<<1];
622 out[i++] = LCD_RGBPACK(c,c,c);
623 }
624 }
625 break;
626 case 6: /*RGB with alpha*/
627 i = 0;
628 for (y = 0 ; y < h ; y++) {
629 for (x = 0 ; x < w ; x++) {
630 j = i << 2;
631 unsigned char r = in[j];
632 unsigned char g = in[j + 1];
633 unsigned char b = in[j + 2];
634 out[i++] = LCD_RGBPACK(r,g,b);
635 }
636 }
637 break;
638 default:
639 break;
640 }
641 }
642 else if (infoIn->bitDepth == 16)
643 {
644 switch (infoIn->colorType)
645 {
646 case 0: /*greyscale color*/
647 i = 0;
648 for (y = 0 ; y < h ; y++) {
649 for (x = 0 ; x < w ; x++) {
650 c = in[i << 1];
651 //unsigned char r = in[2 * i];
652 //unsigned char g = in[2 * i];
653 //unsigned char b = in[2 * i];
654 out[i++] = LCD_RGBPACK(c,c,c);
655 }
656 }
657 break;
658 case 2: /*RGB color*/
659 i = 0;
660 for (y = 0 ; y < h ; y++) {
661 for (x = 0 ; x < w ; x++) {
662 j = 6 * i;
663 unsigned char r = in[j];
664 unsigned char g = in[j + 2];
665 unsigned char b = in[j + 4];
666 out[i++] = LCD_RGBPACK(r,g,b);
667 }
668 }
669 break;
670 case 4: /*greyscale with alpha*/
671 i = 0;
672 for (y = 0 ; y < h ; y++) {
673 for (x = 0 ; x < w ; x++) {
674 c = in[i << 2];
675 //unsigned char r = in[4 * i];
676 //unsigned char g = in[4 * i];
677 //unsigned char b = in[4 * i];
678 out[i++] = LCD_RGBPACK(c,c,c);
679 }
680 }
681 break;
682 case 6: /*RGB with alpha*/
683 i = 0;
684 for (y = 0 ; y < h ; y++) {
685 for (x = 0 ; x < w ; x++) {
686 j = i << 3;
687 unsigned char r = in[j];
688 unsigned char g = in[j + 2];
689 unsigned char b = in[j + 4];
690 out[i++] = LCD_RGBPACK(r,g,b);
691 }
692 }
693 break;
694 default:
695 break;
696 }
697 }
698 else /*infoIn->bitDepth is less than 8 bit per channel*/
699 {
700 switch (infoIn->colorType)
701 {
702 case 0: /*greyscale color*/
703 i = 0;
704 for (y = 0 ; y < h ; y++) {
705 for (x = 0 ; x < w ; x++) {
706 unsigned value = readBitsFromReversedStream(&bp, in, infoIn->bitDepth);
707 value = (value * 255) / ((1 << infoIn->bitDepth) - 1); /*scale value from 0 to 255*/
708 unsigned char r = (unsigned char)value;
709 unsigned char g = (unsigned char)value;
710 unsigned char b = (unsigned char)value;
711 out[i++] = LCD_RGBPACK(r,g,b);
712 }
713 }
714 break;
715 case 3: /*indexed color (palette)*/
716 i = 0;
717 for (y = 0 ; y < h ; y++) {
718 for (x = 0 ; x < w ; x++) {
719 unsigned value = readBitsFromReversedStream(&bp, in, infoIn->bitDepth);
720 if (value >= infoIn->palettesize) return 47;
721 j = value << 2;
722 unsigned char r = infoIn->palette[j];
723 unsigned char g = infoIn->palette[j + 1];
724 unsigned char b = infoIn->palette[j + 2];
725 out[i++] = LCD_RGBPACK(r,g,b);
726 }
727 }
728 break;
729 default:
730 break;
731 }
732 }
733 }
734 else if (LodePNG_InfoColor_isGreyscaleType(infoOut) && infoOut->bitDepth == 8) /*conversion from greyscale to greyscale*/
735 {
736 if (!LodePNG_InfoColor_isGreyscaleType(infoIn)) return 62;
737 if (infoIn->bitDepth == 8)
738 {
739 switch (infoIn->colorType)
740 {
741 case 0: /*greyscale color*/
742 i = 0;
743 for (y = 0 ; y < h ; y++) {
744 for (x = 0 ; x < w ; x++) {
745 c = in[i];
746 //unsigned char r = in[i];
747 //unsigned char g = in[i];
748 //unsigned char b = in[i];
749 out[i++] = LCD_RGBPACK(c,c,c);
750 }
751 }
752 break;
753 case 4: /*greyscale with alpha*/
754 i = 0;
755 for (y = 0 ; y < h ; y++) {
756 for (x = 0 ; x < w ; x++) {
757 c = in[(i << 1) + 1];
758 //unsigned char r = in[2 * i + 1];
759 //unsigned char g = in[2 * i + 1];
760 //unsigned char b = in[2 * i + 1];
761 out[i++] = LCD_RGBPACK(c,c,c);
762 }
763 }
764 break;
765 default:
766 return 31;
767 }
768 }
769 else if (infoIn->bitDepth == 16)
770 {
771 switch (infoIn->colorType)
772 {
773 case 0: /*greyscale color*/
774 i = 0;
775 for (y = 0 ; y < h ; y++) {
776 for (x = 0 ; x < w ; x++) {
777 c = in[i << 1];
778 //unsigned char r = in[2 * i];
779 //unsigned char g = in[2 * i];
780 //unsigned char b = in[2 * i];
781 out[i++] = LCD_RGBPACK(c,c,c);
782 }
783 }
784 break;
785 case 4: /*greyscale with alpha*/
786 i = 0;
787 for (y = 0 ; y < h ; y++) {
788 for (x = 0 ; x < w ; x++) {
789 c = in[i << 2];
790 //unsigned char r = in[4 * i];
791 //unsigned char g = in[4 * i];
792 //unsigned char b = in[4 * i];
793 out[i++] = LCD_RGBPACK(c,c,c);
794 }
795 }
796 break;
797 default:
798 return 31;
799 }
800 }
801 else /*infoIn->bitDepth is less than 8 bit per channel*/
802 {
803 if (infoIn->colorType != 0) return 31; /*colorType 0 is the only greyscale type with < 8 bits per channel*/
804 i = 0;
805 for (y = 0 ; y < h ; y++) {
806 for (x = 0 ; x < w ; x++) {
807 unsigned value = readBitsFromReversedStream(&bp, in, infoIn->bitDepth);
808 value = (value * 255) / ((1 << infoIn->bitDepth) - 1); /*scale value from 0 to 255*/
809 unsigned char r = (unsigned char)value;
810 unsigned char g = (unsigned char)value;
811 unsigned char b = (unsigned char)value;
812 out[i++] = LCD_RGBPACK(r,g,b);
813 }
814 }
815 }
816 }
817 else return 59;
818
819 return 0;
820}
821
822/*Paeth predicter, used by PNG filter type 4*/
823static int paethPredictor(int a, int b, int c)
824{
825 int p = a + b - c;
826 int pa = p > a ? p - a : a - p;
827 int pb = p > b ? p - b : b - p;
828 int pc = p > c ? p - c : c - p;
829
830 if (pa <= pb && pa <= pc) return a;
831 else if (pb <= pc) return b;
832 else return c;
833}
834
835/*shared values used by multiple Adam7 related functions*/
836
837static const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }; /*x start values*/
838static const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }; /*y start values*/
839static const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }; /*x delta values*/
840static const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }; /*y delta values*/
841
842static void Adam7_getpassvalues(unsigned passw[7], unsigned passh[7], size_t filter_passstart[8], size_t padded_passstart[8], size_t passstart[8], unsigned w, unsigned h, unsigned bpp)
843{
844 /*the passstart values have 8 values: the 8th one actually indicates the byte after the end of the 7th (= last) pass*/
845 unsigned i;
846
847 /*calculate width and height in pixels of each pass*/
848 for (i = 0; i < 7; i++)
849 {
850 passw[i] = (w + ADAM7_DX[i] - ADAM7_IX[i] - 1) / ADAM7_DX[i];
851 passh[i] = (h + ADAM7_DY[i] - ADAM7_IY[i] - 1) / ADAM7_DY[i];
852 if (passw[i] == 0) passh[i] = 0;
853 if (passh[i] == 0) passw[i] = 0;
854 }
855
856 filter_passstart[0] = padded_passstart[0] = passstart[0] = 0;
857 for (i = 0; i < 7; i++)
858 {
859 filter_passstart[i + 1] = filter_passstart[i] + ((passw[i] && passh[i]) ? passh[i] * (1 + (passw[i] * bpp + 7) / 8) : 0); /*if passw[i] is 0, it's 0 bytes, not 1 (no filtertype-byte)*/
860 padded_passstart[i + 1] = padded_passstart[i] + passh[i] * ((passw[i] * bpp + 7) / 8); /*bits padded if needed to fill full byte at end of each scanline*/
861 passstart[i + 1] = passstart[i] + (passh[i] * passw[i] * bpp + 7) / 8; /*only padded at end of reduced image*/
862 }
863}
864
865/* ////////////////////////////////////////////////////////////////////////// */
866/* / PNG Decoder / */
867/* ////////////////////////////////////////////////////////////////////////// */
868
869/*read the information from the header and store it in the LodePNG_Info. return value is error*/
870void LodePNG_inspect(LodePNG_Decoder* decoder, const unsigned char* in, size_t inlength)
871{
872 if (inlength == 0 || in == 0) { decoder->error = 48; return; } /*the given data is empty*/
873 if (inlength < 29) { decoder->error = 27; return; } /*error: the data length is smaller than the length of the header*/
874
875 /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/
876 LodePNG_InfoPng_cleanup(&decoder->infoPng);
877 LodePNG_InfoPng_init(&decoder->infoPng);
878 decoder->error = 0;
879
880 if (in[0] != 137 || in[1] != 80 || in[2] != 78 || in[3] != 71 || in[4] != 13 || in[5] != 10 || in[6] != 26 || in[7] != 10) { decoder->error = 28; return; } /*error: the first 8 bytes are not the correct PNG signature*/
881 if (in[12] != 'I' || in[13] != 'H' || in[14] != 'D' || in[15] != 'R') { decoder->error = 29; return; } /*error: it doesn't start with a IHDR chunk!*/
882
883 /*read the values given in the header*/
884 decoder->infoPng.width = LodePNG_read32bitInt(&in[16]);
885 decoder->infoPng.height = LodePNG_read32bitInt(&in[20]);
886 decoder->infoPng.color.bitDepth = in[24];
887 decoder->infoPng.color.colorType = in[25];
888 decoder->infoPng.compressionMethod = in[26];
889 decoder->infoPng.filterMethod = in[27];
890 decoder->infoPng.interlaceMethod = in[28];
891
892 unsigned CRC = LodePNG_read32bitInt(&in[29]);
893 unsigned checksum = crc32(0L, &in[12], 17);
894 if (CRC != checksum) { decoder->error = 57; return; }
895
896 if (decoder->infoPng.compressionMethod != 0) { decoder->error = 32; return; } /*error: only compression method 0 is allowed in the specification*/
897 if (decoder->infoPng.filterMethod != 0) { decoder->error = 33; return; } /*error: only filter method 0 is allowed in the specification*/
898 if (decoder->infoPng.interlaceMethod > 1) { decoder->error = 34; return; } /*error: only interlace methods 0 and 1 exist in the specification*/
899
900 decoder->error = checkColorValidity(decoder->infoPng.color.colorType, decoder->infoPng.color.bitDepth);
901}
902
903static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, size_t bytewidth, unsigned char filterType, size_t length)
904{
905 /*
906 For PNG filter method 0
907 unfilter a PNG image scanline by scanline. when the pixels are smaller than 1 byte, the filter works byte per byte (bytewidth = 1)
908 precon is the previous unfiltered scanline, recon the result, scanline the current one
909 the incoming scanlines do NOT include the filtertype byte, that one is given in the parameter filterType instead
910 recon and scanline MAY be the same memory address! precon must be disjoint.
911 */
912
913 size_t i;
914 switch (filterType)
915 {
916 case 0:
917 //for(i = 0; i < length; i++) recon[i] = scanline[i];
918 memcpy(recon, scanline, length * sizeof(unsigned char));
919 break;
920 case 1:
921 //for(i = 0; i < bytewidth; i++) recon[i] = scanline[i];
922 memcpy(recon, scanline, bytewidth * sizeof(unsigned char));
923 for (i = bytewidth; i < length; i++) recon[i] = scanline[i] + recon[i - bytewidth];
924 break;
925 case 2:
926 if (precon) for (i = 0; i < length; i++) recon[i] = scanline[i] + precon[i];
927 else //for(i = 0; i < length; i++) recon[i] = scanline[i];
928 memcpy(recon, scanline, length * sizeof(unsigned char));
929 break;
930 case 3:
931 if (precon)
932 {
933 for (i = 0; i < bytewidth; i++) recon[i] = scanline[i] + precon[i] / 2;
934 for (i = bytewidth; i < length; i++) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) / 2);
935 }
936 else
937 {
938 //for(i = 0; i < bytewidth; i++) recon[i] = scanline[i];
939 memcpy(recon, scanline, bytewidth * sizeof(unsigned char));
940 for (i = bytewidth; i < length; i++) recon[i] = scanline[i] + recon[i - bytewidth] / 2;
941 }
942 break;
943 case 4:
944 if (precon)
945 {
946 for (i = 0; i < bytewidth; i++) recon[i] = (unsigned char)(scanline[i] + paethPredictor(0, precon[i], 0));
947 for (i = bytewidth; i < length; i++) recon[i] = (unsigned char)(scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
948 }
949 else
950 {
951 //for(i = 0; i < bytewidth; i++) recon[i] = scanline[i];
952 memcpy(recon, scanline, bytewidth * sizeof(unsigned char));
953 for (i = bytewidth; i < length; i++) recon[i] = (unsigned char)(scanline[i] + paethPredictor(recon[i - bytewidth], 0, 0));
954 }
955 break;
956 default:
957 return 36; /*error: unexisting filter type given*/
958 }
959 return 0;
960}
961
962static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp)
963{
964 /*
965 For PNG filter method 0
966 this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 it's called 7 times)
967 out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline
968 w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel
969 in and out are allowed to be the same memory address!
970 */
971
972 unsigned y;
973 unsigned char* prevline = 0;
974
975 size_t bytewidth = (bpp + 7) / 8; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/
976 size_t linebytes = (w * bpp + 7) / 8;
977
978 for (y = 0; y < h; y++)
979 {
980 size_t outindex = linebytes * y;
981 size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
982 unsigned char filterType = in[inindex];
983
984 unsigned error = unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes);
985 if (error) return error;
986
987 prevline = &out[outindex];
988 }
989
990 return 0;
991}
992
993static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp)
994{
995 /*Note: this function works on image buffers WITHOUT padding bits at end of scanlines with non-multiple-of-8 bit amounts, only between reduced images is padding
996 out must be big enough AND must be 0 everywhere if bpp < 8 in the current implementation (because that's likely a little bit faster)*/
997 unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8];
998 unsigned i;
999
1000 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
1001
1002 if (bpp >= 8)
1003 {
1004 for (i = 0; i < 7; i++)
1005 {
1006 unsigned x, y, b;
1007 size_t bytewidth = bpp / 8;
1008 for (y = 0; y < passh[i]; y++)
1009 for (x = 0; x < passw[i]; x++)
1010 {
1011 size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth;
1012 size_t pixeloutstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth;
1013 for (b = 0; b < bytewidth; b++)
1014 {
1015 out[pixeloutstart + b] = in[pixelinstart + b];
1016 }
1017 }
1018 }
1019 }
1020 else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/
1021 {
1022 for (i = 0; i < 7; i++)
1023 {
1024 unsigned x, y, b;
1025 unsigned ilinebits = bpp * passw[i];
1026 unsigned olinebits = bpp * w;
1027 size_t obp, ibp; /*bit pointers (for out and in buffer)*/
1028 for (y = 0; y < passh[i]; y++)
1029 for (x = 0; x < passw[i]; x++)
1030 {
1031 ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
1032 obp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp;
1033 for (b = 0; b < bpp; b++)
1034 {
1035 unsigned char bit = readBitFromReversedStream(&ibp, in);
1036 setBitOfReversedStream0(&obp, out, bit); /*note that this function assumes the out buffer is completely 0, use setBitOfReversedStream otherwise*/
1037 }
1038 }
1039 }
1040 }
1041}
1042
1043static void removePaddingBits(unsigned char* out, const unsigned char* in, size_t olinebits, size_t ilinebits, unsigned h)
1044{
1045 /*
1046 After filtering there are still padding bits if scanlines have non multiple of 8 bit amounts. They need to be removed (except at last scanline of (Adam7-reduced) image) before working with pure image buffers for the Adam7 code, the color convert code and the output to the user.
1047 in and out are allowed to be the same buffer, in may also be higher but still overlapping; in must have >= ilinebits*h bits, out must have >= olinebits*h bits, olinebits must be <= ilinebits
1048 also used to move bits after earlier such operations happened, e.g. in a sequence of reduced images from Adam7
1049 only useful if (ilinebits - olinebits) is a value in the range 1..7
1050 */
1051 unsigned y;
1052 size_t diff = ilinebits - olinebits;
1053 size_t obp = 0, ibp = 0; /*bit pointers*/
1054 for (y = 0; y < h; y++)
1055 {
1056 size_t x;
1057 for (x = 0; x < olinebits; x++)
1058 {
1059 unsigned char bit = readBitFromReversedStream(&ibp, in);
1060 setBitOfReversedStream(&obp, out, bit);
1061 }
1062 ibp += diff;
1063 }
1064}
1065
1066/*out must be buffer big enough to contain full image, and in must contain the full decompressed data from the IDAT chunks*/
1067static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, const LodePNG_Decoder* decoder) /*return value is error*/
1068{
1069 /*
1070 This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype. Steps:
1071 *) if no Adam7: 1) unfilter 2) remove padding bits (= posible extra bits per scanline if bpp < 8)
1072 *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace
1073 NOTE: the in buffer will be overwritten with intermediate data!
1074 */
1075 unsigned bpp = LodePNG_InfoColor_getBpp(&decoder->infoPng.color);
1076 unsigned w = decoder->infoPng.width;
1077 unsigned h = decoder->infoPng.height;
1078 unsigned error = 0;
1079 if (bpp == 0) return 31; /*error: invalid colortype*/
1080
1081 if (decoder->infoPng.interlaceMethod == 0)
1082 {
1083 if (bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
1084 {
1085 error = unfilter(in, in, w, h, bpp);
1086 if (error) return error;
1087 removePaddingBits(out, in, w * bpp, ((w * bpp + 7) / 8) * 8, h);
1088 }
1089 else error = unfilter(out, in, w, h, bpp); /*we can immediatly filter into the out buffer, no other steps needed*/
1090 }
1091 else /*interlaceMethod is 1 (Adam7)*/
1092 {
1093 unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8];
1094 unsigned i;
1095
1096 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
1097
1098 for (i = 0; i < 7; i++)
1099 {
1100 error = unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp);
1101 if (error) return error;
1102 if (bpp < 8) /*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline, move bytes instead of bits or move not at all*/
1103 {
1104 /*remove padding bits in scanlines; after this there still may be padding bits between the different reduced images: each reduced image still starts nicely at a byte*/
1105 removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp, ((passw[i] * bpp + 7) / 8) * 8, passh[i]);
1106 }
1107 }
1108
1109 Adam7_deinterlace(out, in, w, h, bpp);
1110 }
1111
1112 return error;
1113}
1114
1115/*read a PNG, the result will be in the same color type as the PNG (hence "generic")*/
1116static void decodeGeneric(LodePNG_Decoder* decoder, unsigned char* in, size_t size, void (*pf_progress)(int current, int total))
1117{
1118 if (pf_progress != NULL)
1119 pf_progress(0, 100);
1120 unsigned char IEND = 0;
1121 const unsigned char* chunk;
1122 size_t i;
1123 unsigned char *idat = memory;
1124 size_t idat_size = 0;
1125
1126 /*for unknown chunk order*/
1127 unsigned unknown = 0;
1128 unsigned critical_pos = 1; /*1 = after IHDR, 2 = after PLTE, 3 = after IDAT*/
1129
1130 /*provide some proper output values if error will happen*/
1131 decoded_image_size = 0;
1132
1133if (size == 0 || in == 0) { decoder->error = 48; return; } /*the given data is empty*/
1134
1135 LodePNG_inspect(decoder, in, size); /*reads header and resets other parameters in decoder->infoPng*/
1136 if (decoder->error) return;
1137
1138 chunk = &in[33]; /*first byte of the first chunk after the header*/
1139
1140 while (!IEND) /*loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is put at the start of the in buffer*/
1141 {
1142 unsigned chunkLength;
1143 const unsigned char* data; /*the data in the chunk*/
1144
1145 if ((size_t)((chunk - in) + 12) > size || chunk < in) { decoder->error = 30; break; } /*error: size of the in buffer too small to contain next chunk*/
1146 chunkLength = LodePNG_chunk_length(chunk); /*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
1147 if (chunkLength > 2147483647) { decoder->error = 63; break; }
1148 if ((size_t)((chunk - in) + chunkLength + 12) > size || (chunk + chunkLength + 12) < in) { decoder->error = 35; break; } /*error: size of the in buffer too small to contain next chunk*/
1149 data = LodePNG_chunk_data_const(chunk);
1150
1151 /*IDAT chunk, containing compressed image data*/
1152 if (LodePNG_chunk_type_equals(chunk, "IDAT"))
1153 {
1154 size_t oldsize = idat_size;
1155 idat_size += chunkLength;
1156 if (idat + idat_size >= image) { decoder->error = OUT_OF_MEMORY; break; }
1157 memcpy(idat+oldsize, data, chunkLength * sizeof(unsigned char));
1158 critical_pos = 3;
1159 }
1160 /*IEND chunk*/
1161 else if (LodePNG_chunk_type_equals(chunk, "IEND"))
1162 {
1163 IEND = 1;
1164 }
1165 /*palette chunk (PLTE)*/
1166 else if (LodePNG_chunk_type_equals(chunk, "PLTE"))
1167 {
1168 unsigned pos = 0;
1169 decoder->infoPng.color.palettesize = chunkLength / 3;
1170 if (decoder->infoPng.color.palettesize > 256) { decoder->error = 38; break; } /*error: palette too big*/
1171 for (i = 0; i < decoder->infoPng.color.palettesize; i++)
1172 {
1173 decoder->infoPng.color.palette[4 * i + 0] = data[pos++]; /*R*/
1174 decoder->infoPng.color.palette[4 * i + 1] = data[pos++]; /*G*/
1175 decoder->infoPng.color.palette[4 * i + 2] = data[pos++]; /*B*/
1176 decoder->infoPng.color.palette[4 * i + 3] = 255; /*alpha*/
1177 }
1178 critical_pos = 2;
1179 }
1180 /*palette transparency chunk (tRNS)*/
1181 else if (LodePNG_chunk_type_equals(chunk, "tRNS"))
1182 {
1183 if (decoder->infoPng.color.colorType == 3)
1184 {
1185 if (chunkLength > decoder->infoPng.color.palettesize) { decoder->error = 39; break; } /*error: more alpha values given than there are palette entries*/
1186 for (i = 0; i < chunkLength; i++) decoder->infoPng.color.palette[4 * i + 3] = data[i];
1187 }
1188 else if (decoder->infoPng.color.colorType == 0)
1189 {
1190 if (chunkLength != 2) { decoder->error = 40; break; } /*error: this chunk must be 2 bytes for greyscale image*/
1191 decoder->infoPng.color.key_defined = 1;
1192 decoder->infoPng.color.key_r = decoder->infoPng.color.key_g = decoder->infoPng.color.key_b = 256 * data[0] + data[1];
1193 }
1194 else if (decoder->infoPng.color.colorType == 2)
1195 {
1196 if (chunkLength != 6) { decoder->error = 41; break; } /*error: this chunk must be 6 bytes for RGB image*/
1197 decoder->infoPng.color.key_defined = 1;
1198 decoder->infoPng.color.key_r = 256 * data[0] + data[1];
1199 decoder->infoPng.color.key_g = 256 * data[2] + data[3];
1200 decoder->infoPng.color.key_b = 256 * data[4] + data[5];
1201 }
1202 else { decoder->error = 42; break; } /*error: tRNS chunk not allowed for other color models*/
1203 }
1204 /*background color chunk (bKGD)*/
1205 else if (LodePNG_chunk_type_equals(chunk, "bKGD"))
1206 {
1207 if (decoder->infoPng.color.colorType == 3)
1208 {
1209 if (chunkLength != 1) { decoder->error = 43; break; } /*error: this chunk must be 1 byte for indexed color image*/
1210 decoder->infoPng.background_defined = 1;
1211 decoder->infoPng.background_r = decoder->infoPng.background_g = decoder->infoPng.background_g = data[0];
1212 }
1213 else if (decoder->infoPng.color.colorType == 0 || decoder->infoPng.color.colorType == 4)
1214 {
1215 if (chunkLength != 2) { decoder->error = 44; break; } /*error: this chunk must be 2 bytes for greyscale image*/
1216 decoder->infoPng.background_defined = 1;
1217 decoder->infoPng.background_r = decoder->infoPng.background_g = decoder->infoPng.background_b = 256 * data[0] + data[1];
1218 }
1219 else if (decoder->infoPng.color.colorType == 2 || decoder->infoPng.color.colorType == 6)
1220 {
1221 if (chunkLength != 6) { decoder->error = 45; break; } /*error: this chunk must be 6 bytes for greyscale image*/
1222 decoder->infoPng.background_defined = 1;
1223 decoder->infoPng.background_r = 256 * data[0] + data[1];
1224 decoder->infoPng.background_g = 256 * data[2] + data[3];
1225 decoder->infoPng.background_b = 256 * data[4] + data[5];
1226 }
1227 }
1228 else if (LodePNG_chunk_type_equals(chunk, "tIME"))
1229 {
1230 if (chunkLength != 7) { decoder->error = 73; break; }
1231 decoder->infoPng.time_defined = 1;
1232 decoder->infoPng.time.year = 256 * data[0] + data[+ 1];
1233 decoder->infoPng.time.month = data[2];
1234 decoder->infoPng.time.day = data[3];
1235 decoder->infoPng.time.hour = data[4];
1236 decoder->infoPng.time.minute = data[5];
1237 decoder->infoPng.time.second = data[6];
1238 }
1239 else if (LodePNG_chunk_type_equals(chunk, "pHYs"))
1240 {
1241 if (chunkLength != 9) { decoder->error = 74; break; }
1242 decoder->infoPng.phys_defined = 1;
1243 decoder->infoPng.phys_x = 16777216 * data[0] + 65536 * data[1] + 256 * data[2] + data[3];
1244 decoder->infoPng.phys_y = 16777216 * data[4] + 65536 * data[5] + 256 * data[6] + data[7];
1245 decoder->infoPng.phys_unit = data[8];
1246 }
1247 else /*it's not an implemented chunk type, so ignore it: skip over the data*/
1248 {
1249 if (LodePNG_chunk_critical(chunk)) { decoder->error = 69; break; } /*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/
1250 unknown = 1;
1251 }
1252
1253 if (!unknown) /*check CRC if wanted, only on known chunk types*/
1254 {
1255 long time = *rb->current_tick;
1256 if (LodePNG_chunk_check_crc(chunk)) { decoder->error = 57; break; }
1257 time = *rb->current_tick-time;
1258 }
1259
1260 if (!IEND) chunk = LodePNG_chunk_next_const(chunk);
1261 }
1262
1263 if (!decoder->error)
1264 {
1265 unsigned char *scanlines = idat + idat_size;
1266 size_t scanlines_size = (size_t)memory_max - idat_size + 1;
1267 long time = *rb->current_tick;
1268 decoder->error = LodePNG_decompress(scanlines, &scanlines_size, idat, idat_size, decoder->error_msg); /*decompress with the Zlib decompressor*/
1269 if (pf_progress) pf_progress(100, 100);
1270 time = *rb->current_tick-time;
1271
1272 if (!decoder->error)
1273 {
1274 decoded_image_size = (decoder->infoPng.height * decoder->infoPng.width * LodePNG_InfoColor_getBpp(&decoder->infoPng.color) + 7) / 8;
1275 if (decoded_image_size > memory_size) { decoder->error = OUT_OF_MEMORY; return; }
1276 decoded_image = memory_max - decoded_image_size + 1;
1277 if (scanlines + scanlines_size >= decoded_image) { decoder->error = OUT_OF_MEMORY; return; }
1278 memset(decoded_image, 0, decoded_image_size * sizeof(unsigned char));
1279 if (!running_slideshow)
1280 {
1281 rb->snprintf(print, sizeof(print), "unfiltering scanlines");
1282 rb->lcd_puts(0, 3, print);
1283 rb->lcd_update();
1284 }
1285 decoder->error = postProcessScanlines(decoded_image, scanlines, decoder);
1286 }
1287 }
1288}
1289
1290void LodePNG_decode(LodePNG_Decoder* decoder, unsigned char* in, size_t insize, void (*pf_progress)(int current, int total))
1291{
1292 decodeGeneric(decoder, in, insize, pf_progress);
1293 if (decoder->error) return;
1294
1295 /*TODO: check if this works according to the statement in the documentation: "The converter can convert from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/
1296if (!(decoder->infoRaw.color.colorType == 2 || decoder->infoRaw.color.colorType == 6) && !(decoder->infoRaw.color.bitDepth == 8)) { decoder->error = 56; return; }
1297 converted_image = (fb_data *)((intptr_t)(memory + 3) & ~3);
1298 converted_image_size = decoder->infoPng.width*decoder->infoPng.height;
1299 if ((unsigned char *)(converted_image + converted_image_size) >= decoded_image) { decoder->error = OUT_OF_MEMORY; }
1300 if (!decoder->error) decoder->error = LodePNG_convert(converted_image, decoded_image, &decoder->infoRaw.color, &decoder->infoPng.color, decoder->infoPng.width, decoder->infoPng.height);
1301}
1302
1303void LodePNG_DecodeSettings_init(LodePNG_DecodeSettings* settings)
1304{
1305 settings->color_convert = 1;
1306}
1307
1308void LodePNG_Decoder_init(LodePNG_Decoder* decoder)
1309{
1310 LodePNG_DecodeSettings_init(&decoder->settings);
1311 LodePNG_InfoRaw_init(&decoder->infoRaw);
1312 LodePNG_InfoPng_init(&decoder->infoPng);
1313 decoder->error = 1;
1314}
1315
1316void LodePNG_Decoder_cleanup(LodePNG_Decoder* decoder)
1317{
1318 LodePNG_InfoRaw_cleanup(&decoder->infoRaw);
1319 LodePNG_InfoPng_cleanup(&decoder->infoPng);
1320}
1321
1322#define PNG_ERROR_MIN 27
1323#define PNG_ERROR_MAX 74
1324static const unsigned char *png_error_messages[PNG_ERROR_MAX-PNG_ERROR_MIN+1] =
1325{
1326 "png file smaller than a png header", /*27*/
1327 "incorrect png signature", /*28*/
1328 "first chunk is not IHDR", /*29*/
1329 "chunk length too large", /*30*/
1330 "illegal PNG color type or bpp", /*31*/
1331 "illegal PNG compression method", /*32*/
1332 "illegal PNG filter method", /*33*/
1333 "illegal PNG interlace method", /*34*/
1334 "chunk length of a chunk is too large or the chunk too small", /*35*/
1335 "illegal PNG filter type encountered", /*36*/
1336 "illegal bit depth for this color type given", /*37*/
1337 "the palette is too big (more than 256 colors)", /*38*/
1338 "more palette alpha values given in tRNS, than there are colors in the palette", /*39*/
1339 "tRNS chunk has wrong size for greyscale image", /*40*/
1340 "tRNS chunk has wrong size for RGB image", /*41*/
1341 "tRNS chunk appeared while it was not allowed for this color type", /*42*/
1342 "bKGD chunk has wrong size for palette image", /*43*/
1343 "bKGD chunk has wrong size for greyscale image", /*44*/
1344 "bKGD chunk has wrong size for RGB image", /*45*/
1345 "value encountered in indexed image is larger than the palette size", /*46*/
1346 "value encountered in indexed image is larger than the palette size", /*47*/
1347 "input file is empty", /*48*/
1348 NULL, /*49*/
1349 NULL, /*50*/
1350 NULL, /*51*/
1351 NULL, /*52*/
1352 NULL, /*53*/
1353 NULL, /*54*/
1354 NULL, /*55*/
1355 NULL, /*56*/
1356 "invalid CRC", /*57*/
1357 NULL, /*58*/
1358 "conversion to unexisting or unsupported color type or bit depth", /*59*/
1359 NULL, /*60*/
1360 NULL, /*61*/
1361 NULL, /*62*/
1362 "png chunk too long", /*63*/
1363 NULL, /*64*/
1364 NULL, /*65*/
1365 NULL, /*66*/
1366 NULL, /*67*/
1367 NULL, /*68*/
1368 "unknown critical chunk", /*69*/
1369 NULL, /*70*/
1370 NULL, /*71*/
1371 NULL, /*72*/
1372 "invalid tIME chunk size", /*73*/
1373 "invalid pHYs chunk size", /*74*/
1374};
1375
1376bool png_ext(const char ext[])
1377{
1378 if (!ext)
1379 return false;
1380 if (!rb->strcasecmp(ext,".png"))
1381 return true;
1382 else
1383 return false;
1384}
1385
1386/*Read directory contents for scrolling. */
1387void get_pic_list(void)
1388{
1389 int i;
1390 struct entry *dircache;
1391 char *pname;
1392 tree = rb->tree_get_context();
1393 dircache = tree->dircache;
1394
1395 file_pt = (char **) memory;
1396
1397 /* Remove path and leave only the name.*/
1398 pname = rb->strrchr(np_file,'/');
1399 pname++;
1400
1401 for (i = 0; i < tree->filesindir; i++)
1402 {
1403 if (!(dircache[i].attr & ATTR_DIRECTORY)
1404 && png_ext(rb->strrchr(dircache[i].name, '.')))
1405 {
1406 file_pt[entries] = dircache[i].name;
1407 /* Set Selected File. */
1408 if (!rb->strcmp(file_pt[entries], pname))
1409 curfile = entries;
1410 entries++;
1411 }
1412 }
1413
1414 memory += (entries * sizeof(char**));
1415 memory_size -= (entries * sizeof(char**));
1416}
1417
1418int change_filename(int direct)
1419{
1420 bool file_erased = (file_pt[curfile] == NULL);
1421 direction = direct;
1422
1423 curfile += (direct == DIR_PREV? entries - 1: 1);
1424 if (curfile >= entries)
1425 curfile -= entries;
1426
1427 if (file_erased)
1428 {
1429 /* remove 'erased' file names from list. */
1430 int count, i;
1431 for (count = i = 0; i < entries; i++)
1432 {
1433 if (curfile == i)
1434 curfile = count;
1435 if (file_pt[i] != NULL)
1436 file_pt[count++] = file_pt[i];
1437 }
1438 entries = count;
1439 }
1440
1441 if (entries == 0)
1442 {
1443 rb->splash(HZ, "No supported files");
1444 return PLUGIN_ERROR;
1445 }
1446
1447 if (rb->strlen(tree->currdir) > 1)
1448 {
1449 rb->strcpy(np_file, tree->currdir);
1450 rb->strcat(np_file, "/");
1451 }
1452 else
1453 rb->strcpy(np_file, tree->currdir);
1454
1455 rb->strcat(np_file, file_pt[curfile]);
1456
1457 return PLUGIN_OTHER;
1458}
1459
1460/* switch off overlay, for handling SYS_ events */
1461void cleanup(void *parameter)
1462{
1463 (void)parameter;
1464}
1465
1466#define VSCROLL (LCD_HEIGHT/8)
1467#define HSCROLL (LCD_WIDTH/10)
1468
1469#define ZOOM_IN 100 /* return codes for below function */
1470#define ZOOM_OUT 101
1471
1472int show_menu(void) /* return 1 to quit */
1473{
1474#if LCD_DEPTH > 1
1475 rb->lcd_set_backdrop(old_backdrop);
1476#ifdef HAVE_LCD_COLOR
1477 rb->lcd_set_foreground(rb->global_settings->fg_color);
1478 rb->lcd_set_background(rb->global_settings->bg_color);
1479#else
1480 rb->lcd_set_foreground(LCD_BLACK);
1481 rb->lcd_set_background(LCD_WHITE);
1482#endif
1483#endif
1484 int result;
1485
1486 enum menu_id
1487 {
1488 MIID_RETURN = 0,
1489 MIID_TOGGLE_SS_MODE,
1490 MIID_CHANGE_SS_MODE,
1491#if PLUGIN_BUFFER_SIZE >= MIN_MEM
1492 MIID_SHOW_PLAYBACK_MENU,
1493#endif
1494 MIID_QUIT,
1495 };
1496
1497 MENUITEM_STRINGLIST(menu, "Png Menu", NULL,
1498 "Return", "Toggle Slideshow Mode",
1499 "Change Slideshow Time",
1500#if PLUGIN_BUFFER_SIZE >= MIN_MEM
1501 "Show Playback Menu",
1502#endif
1503 "Quit");
1504
1505 static const struct opt_items slideshow[2] = {
1506 { "Disable", -1 },
1507 { "Enable", -1 },
1508 };
1509
1510 result=rb->do_menu(&menu, NULL, NULL, false);
1511
1512 switch (result)
1513 {
1514 case MIID_RETURN:
1515 break;
1516 case MIID_TOGGLE_SS_MODE:
1517 rb->set_option("Toggle Slideshow", &slideshow_enabled, INT,
1518 slideshow , 2, NULL);
1519 break;
1520 case MIID_CHANGE_SS_MODE:
1521 rb->set_int("Slideshow Time", "s", UNIT_SEC,
1522 &png_settings.ss_timeout, NULL, 1,
1523 SS_MIN_TIMEOUT, SS_MAX_TIMEOUT, NULL);
1524 break;
1525#if PLUGIN_BUFFER_SIZE >= MIN_MEM
1526 case MIID_SHOW_PLAYBACK_MENU:
1527 if (plug_buf)
1528 {
1529 playback_control(NULL);
1530 }
1531 else
1532 {
1533 rb->splash(HZ, "Cannot restart playback");
1534 }
1535 break;
1536#endif
1537 case MIID_QUIT:
1538 return 1;
1539 break;
1540 }
1541
1542#if !defined(SIMULATOR) && defined(HAVE_DISK_STORAGE)
1543 /* change ata spindown time based on slideshow time setting */
1544 immediate_ata_off = false;
1545 rb->storage_spindown(rb->global_settings->disk_spindown);
1546
1547 if (slideshow_enabled)
1548 {
1549 if (png_settings.ss_timeout < 10)
1550 {
1551 /* slideshow times < 10s keep disk spinning */
1552 rb->storage_spindown(0);
1553 }
1554 else if (!rb->mp3_is_playing())
1555 {
1556 /* slideshow times > 10s and not playing: ata_off after load */
1557 immediate_ata_off = true;
1558 }
1559 }
1560#endif
1561#if LCD_DEPTH > 1
1562 rb->lcd_set_backdrop(NULL);
1563 rb->lcd_set_foreground(LCD_WHITE);
1564 rb->lcd_set_background(LCD_BLACK);
1565#endif
1566 rb->lcd_clear_display();
1567 return 0;
1568}
1569
1570void draw_image(struct LodePNG_Decoder* decoder)
1571{
1572 rb->lcd_bitmap_part(resized_image, decoder->x, decoder->y, decoder->width,
1573 MAX(0, (LCD_WIDTH - decoder->width) / 2),
1574 MAX(0, (LCD_HEIGHT - decoder->height) / 2),
1575 decoder->width - decoder->x,
1576 decoder->height - decoder->y);
1577}
1578
1579/* Pan the viewing window right - move image to the left and fill in
1580 the right-hand side */
1581static void pan_view_right(struct LodePNG_Decoder* decoder)
1582{
1583 int move;
1584
1585 move = MIN(HSCROLL, decoder->width - decoder->x - LCD_WIDTH);
1586 if (move > 0)
1587 {
1588 decoder->x += move;
1589 draw_image(decoder);
1590 rb->lcd_update();
1591 }
1592}
1593
1594/* Pan the viewing window left - move image to the right and fill in
1595 the left-hand side */
1596static void pan_view_left(struct LodePNG_Decoder* decoder)
1597{
1598 int move;
1599
1600 move = MIN(HSCROLL, decoder->x);
1601 if (move > 0)
1602 {
1603 decoder->x -= move;
1604 draw_image(decoder);
1605 rb->lcd_update();
1606 }
1607}
1608
1609
1610/* Pan the viewing window up - move image down and fill in
1611 the top */
1612static void pan_view_up(struct LodePNG_Decoder* decoder)
1613{
1614 int move;
1615
1616 move = MIN(VSCROLL, decoder->y);
1617 if (move > 0)
1618 {
1619 decoder->y -= move;
1620 draw_image(decoder);
1621 rb->lcd_update();
1622 }
1623}
1624
1625/* Pan the viewing window down - move image up and fill in
1626 the bottom */
1627static void pan_view_down(struct LodePNG_Decoder* decoder)
1628{
1629 int move;
1630
1631 move = MIN(VSCROLL, decoder->height - decoder->y - LCD_HEIGHT);
1632 if (move > 0)
1633 {
1634 decoder->y += move;
1635 draw_image(decoder);
1636 rb->lcd_update();
1637 }
1638}
1639
1640/* interactively scroll around the image */
1641int scroll_bmp(struct LodePNG_Decoder* decoder)
1642{
1643 int button;
1644 int lastbutton = 0;
1645
1646 while (true)
1647 {
1648 if (slideshow_enabled)
1649 button = rb->button_get_w_tmo(png_settings.ss_timeout * HZ);
1650 else
1651 button = rb->button_get(true);
1652
1653 running_slideshow = false;
1654
1655 switch (button)
1656 {
1657 case PNG_LEFT:
1658 if (entries > 1 && decoder->width <= LCD_WIDTH
1659 && decoder->height <= LCD_HEIGHT)
1660 return change_filename(DIR_PREV);
1661 case PNG_LEFT | BUTTON_REPEAT:
1662 pan_view_left(decoder);
1663 break;
1664
1665 case PNG_RIGHT:
1666 if (entries > 1 && decoder->width <= LCD_WIDTH
1667 && decoder->height <= LCD_HEIGHT)
1668 return change_filename(DIR_NEXT);
1669 case PNG_RIGHT | BUTTON_REPEAT:
1670 pan_view_right(decoder);
1671 break;
1672
1673 case PNG_UP:
1674 case PNG_UP | BUTTON_REPEAT:
1675 pan_view_up(decoder);
1676 break;
1677
1678 case PNG_DOWN:
1679 case PNG_DOWN | BUTTON_REPEAT:
1680 pan_view_down(decoder);
1681 break;
1682
1683 case BUTTON_NONE:
1684 if (!slideshow_enabled)
1685 break;
1686 running_slideshow = true;
1687 if (entries > 1)
1688 return change_filename(DIR_NEXT);
1689 break;
1690
1691#ifdef PNG_SLIDE_SHOW
1692 case PNG_SLIDE_SHOW:
1693 slideshow_enabled = !slideshow_enabled;
1694 running_slideshow = slideshow_enabled;
1695 break;
1696#endif
1697
1698#ifdef PNG_NEXT_REPEAT
1699 case PNG_NEXT_REPEAT:
1700#endif
1701 case PNG_NEXT:
1702 if (entries > 1)
1703 return change_filename(DIR_NEXT);
1704 break;
1705
1706#ifdef PNG_PREVIOUS_REPEAT
1707 case PNG_PREVIOUS_REPEAT:
1708#endif
1709 case PNG_PREVIOUS:
1710 if (entries > 1)
1711 return change_filename(DIR_PREV);
1712 break;
1713
1714 case PNG_ZOOM_IN:
1715#ifdef PNG_ZOOM_PRE
1716 if (lastbutton != PNG_ZOOM_PRE)
1717 break;
1718#endif
1719 return ZOOM_IN;
1720 break;
1721
1722 case PNG_ZOOM_OUT:
1723#ifdef PNG_ZOOM_PRE
1724 if (lastbutton != PNG_ZOOM_PRE)
1725 break;
1726#endif
1727 return ZOOM_OUT;
1728 break;
1729
1730#ifdef PNG_RC_MENU
1731 case PNG_RC_MENU:
1732#endif
1733 case PNG_MENU:
1734
1735 if (show_menu() == 1)
1736 return PLUGIN_OK;
1737
1738 draw_image(decoder);
1739 rb->lcd_update();
1740
1741 break;
1742 default:
1743 if (rb->default_event_handler_ex(button, cleanup, NULL)
1744 == SYS_USB_CONNECTED)
1745 return PLUGIN_USB_CONNECTED;
1746 break;
1747
1748 } /* switch */
1749
1750 if (button != BUTTON_NONE)
1751 lastbutton = button;
1752 } /* while (true) */
1753}
1754
1755/* callback updating a progress meter while PNG decoding */
1756void cb_progress(int current, int total)
1757{
1758
1759 if (current & 1) rb->yield(); /* be nice to the other threads */
1760 if (!running_slideshow)
1761 {
1762 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
1763 0, LCD_HEIGHT-8, LCD_WIDTH, 8,
1764 total, 0, current, HORIZONTAL);
1765 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
1766 }
1767 else
1768 {
1769 /* in slideshow mode, keep gui interference to a minimum */
1770 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
1771 0, LCD_HEIGHT-4, LCD_WIDTH, 4,
1772 total, 0, current, HORIZONTAL);
1773 rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4);
1774 }
1775}
1776
1777int pngmem(struct LodePNG_Decoder* decoder, int ds)
1778{
1779 return (decoder->infoPng.width/ds) * (decoder->infoPng.height/ds) * FB_DATA_SZ;
1780}
1781
1782/* how far can we zoom in without running out of memory */
1783int min_downscale(struct LodePNG_Decoder* decoder, int bufsize)
1784{
1785 int downscale = 8;
1786
1787 if (pngmem(decoder, 8) > bufsize)
1788 return 0; /* error, too large, even 1:8 doesn't fit */
1789
1790 while (downscale > 1 && pngmem(decoder, downscale/2) <= bufsize)
1791 downscale /= 2;
1792
1793 return downscale;
1794}
1795
1796/* how far can we zoom out, to fit image into the LCD */
1797unsigned max_downscale(struct LodePNG_Decoder* decoder)
1798{
1799 unsigned downscale = 1;
1800
1801 while (downscale < 8 && (decoder->infoPng.width/downscale > LCD_WIDTH
1802 || decoder->infoPng.height/downscale > LCD_HEIGHT))
1803 {
1804 downscale *= 2;
1805 }
1806
1807 return downscale;
1808}
1809
1810/* load image from filename. */
1811int load_image(char* filename, struct LodePNG_Decoder* decoder)
1812{
1813 int fd;
1814 long time = 0; /* measured ticks */
1815 int w, h; /* used to center output */
1816
1817 fd = rb->open(filename, O_RDONLY);
1818 if (fd < 0)
1819 {
1820 rb->splashf(HZ, "err opening %s:%d", filename, fd);
1821 return PLUGIN_ERROR;
1822 }
1823 image_size = rb->filesize(fd);
1824
1825 DEBUGF("reading file '%s'\n", filename);
1826
1827 if (!running_slideshow) {
1828 rb->snprintf(print, sizeof(print), "%s:", rb->strrchr(filename,'/')+1);
1829 rb->lcd_puts(0, 0, print);
1830 rb->lcd_update();
1831 }
1832
1833 if (image_size > memory_size) {
1834 decoder->error = FILE_TOO_LARGE;
1835 rb->close(fd);
1836#ifndef SIMULATOR
1837 if (running_slideshow && immediate_ata_off) {
1838 /* running slideshow and time is long enough: power down disk */
1839 rb->storage_sleep();
1840 }
1841#endif
1842
1843 } else {
1844 if (!running_slideshow) {
1845 rb->snprintf(print, sizeof(print), "loading %lu bytes", image_size);
1846 rb->lcd_puts(0, 1, print);
1847 rb->lcd_update();
1848 }
1849
1850 image = memory_max - image_size + 1;
1851 rb->read(fd, image, image_size);
1852 rb->close(fd);
1853
1854 if (!running_slideshow) {
1855 rb->snprintf(print, sizeof(print), "decoding image");
1856 rb->lcd_puts(0, 2, print);
1857 rb->lcd_update();
1858 }
1859#ifndef SIMULATOR
1860 else if (immediate_ata_off) {
1861 /* running slideshow and time is long enough: power down disk */
1862 rb->storage_sleep();
1863 }
1864#endif
1865
1866 decoder->settings.color_convert = 1;
1867 decoder->infoRaw.color.colorType = 2;
1868 decoder->infoRaw.color.bitDepth = 8;
1869
1870 LodePNG_inspect(decoder, image, image_size);
1871
1872 if (!decoder->error) {
1873
1874 if (!running_slideshow) {
1875 rb->snprintf(print, sizeof(print), "image %dx%d",
1876 decoder->infoPng.width, decoder->infoPng.height);
1877 rb->lcd_puts(0, 2, print);
1878 rb->lcd_update();
1879
1880 rb->snprintf(print, sizeof(print), "decoding %d*%d",
1881 decoder->infoPng.width, decoder->infoPng.height);
1882 rb->lcd_puts(0, 3, print);
1883 rb->lcd_update();
1884 }
1885
1886 /* the actual decoding */
1887 time = *rb->current_tick;
1888#ifdef HAVE_ADJUSTABLE_CPU_FREQ
1889 rb->cpu_boost(true);
1890 LodePNG_decode(decoder, image, image_size, cb_progress);
1891 rb->cpu_boost(false);
1892#else
1893 LodePNG_decode(decoder, image, image_size, cb_progress);
1894#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
1895 }
1896 }
1897
1898 time = *rb->current_tick - time;
1899
1900 if (!running_slideshow && !decoder->error)
1901 {
1902 rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ);
1903 rb->lcd_getstringsize(print, &w, &h); /* centered in progress bar */
1904 rb->lcd_putsxy((LCD_WIDTH - w)/2, LCD_HEIGHT - h, print);
1905 rb->lcd_update();
1906 }
1907
1908 if (decoder->error) {
1909#if PLUGIN_BUFFER_SIZE >= MIN_MEM
1910 if (plug_buf && (decoder->error == FILE_TOO_LARGE
1911 || decoder->error == OUT_OF_MEMORY || decoder->error == Z_MEM_ERROR))
1912 return PLUGIN_OUTOFMEM;
1913#endif
1914
1915 if (decoder->error >= PNG_ERROR_MIN && decoder->error <= PNG_ERROR_MAX
1916 && png_error_messages[decoder->error-PNG_ERROR_MIN] != NULL)
1917 {
1918 rb->splash(HZ, png_error_messages[decoder->error-PNG_ERROR_MIN]);
1919 }
1920 else
1921 {
1922 switch (decoder->error) {
1923 case PLUGIN_ABORT:
1924 break;
1925 case OUT_OF_MEMORY:
1926 case Z_MEM_ERROR:
1927 rb->splash(HZ, "Out of Memory");break;
1928 case FILE_TOO_LARGE:
1929 rb->splash(HZ, "File too large");break;
1930 case Z_DATA_ERROR:
1931 rb->splash(HZ, decoder->error_msg);break;
1932 default:
1933 rb->splashf(HZ, "other error : %ld", decoder->error);break;
1934 }
1935 }
1936
1937 if (decoder->error == PLUGIN_ABORT)
1938 return PLUGIN_ABORT;
1939 else
1940 return PLUGIN_ERROR;
1941 }
1942 return PLUGIN_OK;
1943}
1944
1945/* return decoded or cached image */
1946fb_data *get_image(struct LodePNG_Decoder* decoder, int ds)
1947{
1948 fb_data * p_disp = disp[ds]; /* short cut */
1949
1950 decoder->width = decoder->infoPng.width / ds;
1951 decoder->height = decoder->infoPng.height / ds;
1952
1953 if (p_disp != NULL)
1954 {
1955 DEBUGF("Found an image in cache\n");
1956 return p_disp; /* we still have it */
1957 }
1958
1959 /* assign image buffer */
1960 if (ds > 1) {
1961 if (!running_slideshow)
1962 {
1963 rb->snprintf(print, sizeof(print), "resizing %d*%d",
1964 decoder->width, decoder->height);
1965 rb->lcd_puts(0, 3, print);
1966 rb->lcd_update();
1967 }
1968 struct bitmap bmp_src, bmp_dst;
1969
1970 int size = decoder->width * decoder->height;
1971
1972 if ((unsigned char *)(disp_buf + size) >= memory_max) {
1973 /* have to discard the current */
1974 int i;
1975 for (i=1; i<=8; i++)
1976 disp[i] = NULL; /* invalidate all bitmaps */
1977 /* start again from the beginning of the buffer */
1978 disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3);
1979 }
1980
1981 disp[ds] = disp_buf;
1982 disp_buf = (fb_data *)((intptr_t)(disp[ds] + size + 3) & ~3);
1983
1984 bmp_src.width = decoder->infoPng.width;
1985 bmp_src.height = decoder->infoPng.height;
1986 bmp_src.data = (unsigned char *)converted_image;
1987
1988 bmp_dst.width = decoder->width;
1989 bmp_dst.height = decoder->height;
1990 bmp_dst.data = (unsigned char *)disp[ds];
1991#ifdef HAVE_ADJUSTABLE_CPU_FREQ
1992 rb->cpu_boost(true);
1993 smooth_resize_bitmap(&bmp_src, &bmp_dst);
1994 rb->cpu_boost(false);
1995#else
1996 smooth_resize_bitmap(&bmp_src, &bmp_dst);
1997#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
1998 } else {
1999 disp[ds] = converted_image;
2000 return converted_image;
2001 }
2002
2003 return disp[ds];
2004}
2005
2006/* set the view to the given center point, limit if necessary */
2007void set_view (struct LodePNG_Decoder* decoder, int cx, int cy)
2008{
2009 int x, y;
2010
2011 /* plain center to available width/height */
2012 x = cx - MIN(LCD_WIDTH, decoder->width) / 2;
2013 y = cy - MIN(LCD_HEIGHT, decoder->height) / 2;
2014
2015 /* limit against upper image size */
2016 x = MIN(decoder->width - LCD_WIDTH, x);
2017 y = MIN(decoder->height - LCD_HEIGHT, y);
2018
2019 /* limit against negative side */
2020 x = MAX(0, x);
2021 y = MAX(0, y);
2022
2023 decoder->x = x; /* set the values */
2024 decoder->y = y;
2025}
2026
2027/* calculate the view center based on the bitmap position */
2028void get_view(struct LodePNG_Decoder* decoder, int* p_cx, int* p_cy)
2029{
2030 *p_cx = decoder->x + MIN(LCD_WIDTH, decoder->width) / 2;
2031 *p_cy = decoder->y + MIN(LCD_HEIGHT, decoder->height) / 2;
2032}
2033
2034/* load, decode, display the image */
2035int load_and_show(char* filename)
2036{
2037 int status;
2038 int cx=0, cy=0; /* view center */
2039
2040#if LCD_DEPTH > 1
2041 rb->lcd_set_foreground(LCD_WHITE);
2042 rb->lcd_set_background(LCD_BLACK);
2043 rb->lcd_set_backdrop(NULL);
2044#endif
2045 rb->lcd_clear_display();
2046
2047 memset(&disp, 0, sizeof(disp));
2048 LodePNG_Decoder_init(&decoder);
2049
2050 if (rb->button_get(false) == PNG_MENU)
2051 status = PLUGIN_ABORT;
2052 else
2053 status = load_image(filename, &decoder);
2054
2055 if (status == PLUGIN_OUTOFMEM)
2056 {
2057#if PLUGIN_BUFFER_SIZE >= MIN_MEM
2058 if (plug_buf)
2059 {
2060 rb->lcd_setfont(FONT_SYSFIXED);
2061 rb->lcd_clear_display();
2062 rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1);
2063 rb->lcd_puts(0,0,print);
2064 rb->lcd_puts(0,1,"Not enough plugin memory!");
2065 rb->lcd_puts(0,2,"Zoom In: Stop playback.");
2066 if (entries>1)
2067 rb->lcd_puts(0,3,"Left/Right: Skip File.");
2068 rb->lcd_puts(0,4,"Show Menu: Quit.");
2069 rb->lcd_update();
2070 rb->lcd_setfont(FONT_UI);
2071
2072 rb->button_clear_queue();
2073
2074 while (1)
2075 {
2076 int button = rb->button_get(true);
2077 switch (button)
2078 {
2079 case PNG_ZOOM_IN:
2080 plug_buf = false;
2081 memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
2082 memory_max = memory + memory_size - 1;
2083 /*try again this file, now using the audio buffer */
2084 return PLUGIN_OTHER;
2085#ifdef PNG_RC_MENU
2086 case PNG_RC_MENU:
2087#endif
2088 case PNG_MENU:
2089 return PLUGIN_OK;
2090
2091 case PNG_LEFT:
2092 if (entries>1)
2093 {
2094 rb->lcd_clear_display();
2095 return change_filename(DIR_PREV);
2096 }
2097 break;
2098
2099 case PNG_RIGHT:
2100 if (entries>1)
2101 {
2102 rb->lcd_clear_display();
2103 return change_filename(DIR_NEXT);
2104 }
2105 break;
2106 default:
2107 if (rb->default_event_handler_ex(button, cleanup, NULL)
2108 == SYS_USB_CONNECTED)
2109 return PLUGIN_USB_CONNECTED;
2110
2111 }
2112 }
2113 }
2114 else
2115#endif
2116 {
2117 rb->splash(HZ, "Out of Memory");
2118 file_pt[curfile] = NULL;
2119 return change_filename(direction);
2120 }
2121 }
2122 else if (status == PLUGIN_ERROR)
2123 {
2124 file_pt[curfile] = NULL;
2125 return change_filename(direction);
2126 }
2127 else if (status == PLUGIN_ABORT) {
2128 rb->splash(HZ, "aborted");
2129 return PLUGIN_OK;
2130 }
2131
2132 disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3);
2133 ds_max = max_downscale(&decoder); /* check display constraint */
2134 ds_min = min_downscale(&decoder, memory_max - (unsigned char*)disp_buf); /* check memory constraint */
2135 if (ds_min == 0) {
2136 /* Can not resize the image */
2137 ds_min = ds_max = 1;
2138 } else if (ds_max < ds_min) {
2139 ds_max = ds_min;
2140 }
2141
2142 ds = ds_max; /* initialize setting */
2143 cx = decoder.infoPng.width/ds/2; /* center the view */
2144 cy = decoder.infoPng.height/ds/2;
2145
2146 do {
2147 resized_image = get_image(&decoder, ds); /* decode or fetch from cache */
2148
2149 set_view(&decoder, cx, cy);
2150
2151 if (!running_slideshow)
2152 {
2153 rb->snprintf(print, sizeof(print), "showing %dx%d",
2154 decoder.width, decoder.height);
2155 rb->lcd_puts(0, 3, print);
2156 rb->lcd_update();
2157 }
2158
2159 rb->lcd_clear_display();
2160 draw_image(&decoder);
2161 rb->lcd_update();
2162
2163 /* drawing is now finished, play around with scrolling
2164 * until you press OFF or connect USB
2165 */
2166 while (1)
2167 {
2168 status = scroll_bmp(&decoder);
2169 if (status == ZOOM_IN)
2170 {
2171 if (ds > 1)
2172 {
2173 /* as 1/1 is always available, jump ds to 1 if ds is ds_min. */
2174 int zoom = (ds == ds_min)? ds_min: 2;
2175 ds /= zoom; /* reduce downscaling to zoom in */
2176 get_view(&decoder, &cx, &cy);
2177 cx *= zoom; /* prepare the position in the new image */
2178 cy *= zoom;
2179 }
2180 else
2181 continue;
2182 }
2183
2184 if (status == ZOOM_OUT)
2185 {
2186 if (ds < ds_max)
2187 {
2188 /* if ds is 1 and ds_min is greater than 1, jump ds to ds_min. */
2189 int zoom = (ds < ds_min)? ds_min: 2;
2190 ds *= zoom; /* increase downscaling to zoom out */
2191 get_view(&decoder, &cx, &cy);
2192 cx /= zoom; /* prepare the position in the new image */
2193 cy /= zoom;
2194 }
2195 else
2196 continue;
2197 }
2198 break;
2199 }
2200 rb->lcd_clear_display();
2201 }
2202 while (status != PLUGIN_OK && status != PLUGIN_USB_CONNECTED
2203 && status != PLUGIN_OTHER);
2204
2205 return status;
2206}
2207
2208/******************** Plugin entry point *********************/
2209
2210enum plugin_status plugin_start(const void* parameter)
2211{
2212 int condition;
2213#if LCD_DEPTH > 1
2214 old_backdrop = rb->lcd_get_backdrop();
2215#endif
2216
2217 if (!parameter) return PLUGIN_ERROR;
2218
2219#if PLUGIN_BUFFER_SIZE >= MIN_MEM
2220 memory = rb->plugin_get_buffer((size_t *)&memory_size);
2221#else
2222 memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
2223#endif
2224
2225 rb->strcpy(np_file, parameter);
2226 get_pic_list();
2227
2228 if (!entries) return PLUGIN_ERROR;
2229
2230#if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR)
2231 if (!rb->audio_status()) {
2232 plug_buf = false;
2233 memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
2234 }
2235#endif
2236
2237 memory_max = memory + memory_size - 1;
2238
2239 /* should be ok to just load settings since the plugin itself has
2240 just been loaded from disk and the drive should be spinning */
2241 configfile_load(PNG_CONFIGFILE, png_config,
2242 ARRAYLEN(png_config), PNG_SETTINGS_MINVERSION);
2243 old_settings = png_settings;
2244
2245 /* Turn off backlight timeout */
2246 backlight_force_on(); /* backlight control in lib/helper.c */
2247
2248 do
2249 {
2250 condition = load_and_show(np_file);
2251 } while (condition != PLUGIN_OK && condition != PLUGIN_USB_CONNECTED
2252 && condition != PLUGIN_ERROR);
2253
2254 if (rb->memcmp(&png_settings, &old_settings, sizeof (png_settings)))
2255 {
2256 /* Just in case drive has to spin, keep it from looking locked */
2257 rb->splash(0, "Saving Settings");
2258 configfile_save(PNG_CONFIGFILE, png_config,
2259 ARRAYLEN(png_config), PNG_SETTINGS_VERSION);
2260 }
2261
2262#if !defined(SIMULATOR) && defined(HAVE_DISK_STORAGE)
2263 /* set back ata spindown time in case we changed it */
2264 rb->storage_spindown(rb->global_settings->disk_spindown);
2265#endif
2266
2267 /* Turn on backlight timeout (revert to settings) */
2268 backlight_use_settings(); /* backlight control in lib/helper.c */
2269
2270 return condition;
2271}
diff --git a/apps/plugins/png/png.h b/apps/plugins/png/png.h
deleted file mode 100644
index 4699e24e70..0000000000
--- a/apps/plugins/png/png.h
+++ /dev/null
@@ -1,366 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$id $
9 *
10 * Copyright (C) 2009 by Christophe Gouiran <bechris13250 -at- gmail -dot- com>
11 *
12 * Based on lodepng, a lightweight png decoder/encoder
13 * (c) 2005-2008 Lode Vandevenne
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25/*
26LodePNG version 20080927
27
28Copyright (c) 2005-2008 Lode Vandevenne
29
30This software is provided 'as-is', without any express or implied
31warranty. In no event will the authors be held liable for any damages
32arising from the use of this software.
33
34Permission is granted to anyone to use this software for any purpose,
35including commercial applications, and to alter it and redistribute it
36freely, subject to the following restrictions:
37
38 1. The origin of this software must not be misrepresented; you must not
39 claim that you wrote the original software. If you use this software
40 in a product, an acknowledgment in the product documentation would be
41 appreciated but is not required.
42
43 2. Altered source versions must be plainly marked as such, and must not be
44 misrepresented as being the original software.
45
46 3. This notice may not be removed or altered from any source
47 distribution.
48*/
49
50/*
51The manual and changelog can be found in the header file "lodepng.h"
52You are free to name this file lodepng.cpp or lodepng.c depending on your usage.
53*/
54
55/* variable button definitions */
56#if CONFIG_KEYPAD == RECORDER_PAD
57#define PNG_ZOOM_IN BUTTON_PLAY
58#define PNG_ZOOM_OUT BUTTON_ON
59#define PNG_UP BUTTON_UP
60#define PNG_DOWN BUTTON_DOWN
61#define PNG_LEFT BUTTON_LEFT
62#define PNG_RIGHT BUTTON_RIGHT
63#define PNG_NEXT BUTTON_F3
64#define PNG_PREVIOUS BUTTON_F2
65#define PNG_MENU BUTTON_OFF
66
67#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
68#define PNG_ZOOM_IN BUTTON_SELECT
69#define PNG_ZOOM_OUT BUTTON_ON
70#define PNG_UP BUTTON_UP
71#define PNG_DOWN BUTTON_DOWN
72#define PNG_LEFT BUTTON_LEFT
73#define PNG_RIGHT BUTTON_RIGHT
74#define PNG_NEXT BUTTON_F3
75#define PNG_PREVIOUS BUTTON_F2
76#define PNG_MENU BUTTON_OFF
77
78#elif CONFIG_KEYPAD == ONDIO_PAD
79#define PNG_ZOOM_PRE BUTTON_MENU
80#define PNG_ZOOM_IN (BUTTON_MENU | BUTTON_REL)
81#define PNG_ZOOM_OUT (BUTTON_MENU | BUTTON_DOWN)
82#define PNG_UP BUTTON_UP
83#define PNG_DOWN BUTTON_DOWN
84#define PNG_LEFT BUTTON_LEFT
85#define PNG_RIGHT BUTTON_RIGHT
86#define PNG_NEXT (BUTTON_MENU | BUTTON_RIGHT)
87#define PNG_PREVIOUS (BUTTON_MENU | BUTTON_LEFT)
88#define PNG_MENU BUTTON_OFF
89
90#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
91 (CONFIG_KEYPAD == IRIVER_H300_PAD)
92#define PNG_ZOOM_IN BUTTON_SELECT
93#define PNG_ZOOM_OUT BUTTON_MODE
94#define PNG_UP BUTTON_UP
95#define PNG_DOWN BUTTON_DOWN
96#define PNG_LEFT BUTTON_LEFT
97#define PNG_RIGHT BUTTON_RIGHT
98#if (CONFIG_KEYPAD == IRIVER_H100_PAD)
99#define PNG_NEXT BUTTON_ON
100#define PNG_PREVIOUS BUTTON_REC
101#else
102#define PNG_NEXT BUTTON_REC
103#define PNG_PREVIOUS BUTTON_ON
104#endif
105#define PNG_MENU BUTTON_OFF
106#define PNG_RC_MENU BUTTON_RC_STOP
107
108#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
109 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
110#define PNG_ZOOM_IN BUTTON_SCROLL_FWD
111#define PNG_ZOOM_OUT BUTTON_SCROLL_BACK
112#define PNG_UP BUTTON_MENU
113#define PNG_DOWN BUTTON_PLAY
114#define PNG_LEFT BUTTON_LEFT
115#define PNG_RIGHT BUTTON_RIGHT
116#define PNG_MENU (BUTTON_SELECT | BUTTON_MENU)
117#define PNG_NEXT (BUTTON_SELECT | BUTTON_RIGHT)
118#define PNG_PREVIOUS (BUTTON_SELECT | BUTTON_LEFT)
119
120#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
121#define PNG_ZOOM_PRE BUTTON_SELECT
122#define PNG_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
123#define PNG_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
124#define PNG_UP BUTTON_UP
125#define PNG_DOWN BUTTON_DOWN
126#define PNG_LEFT BUTTON_LEFT
127#define PNG_RIGHT BUTTON_RIGHT
128#define PNG_MENU BUTTON_POWER
129#define PNG_NEXT BUTTON_PLAY
130#define PNG_PREVIOUS BUTTON_REC
131
132#elif CONFIG_KEYPAD == GIGABEAT_PAD
133#define PNG_ZOOM_IN BUTTON_VOL_UP
134#define PNG_ZOOM_OUT BUTTON_VOL_DOWN
135#define PNG_UP BUTTON_UP
136#define PNG_DOWN BUTTON_DOWN
137#define PNG_LEFT BUTTON_LEFT
138#define PNG_RIGHT BUTTON_RIGHT
139#define PNG_MENU BUTTON_MENU
140#define PNG_NEXT (BUTTON_A | BUTTON_RIGHT)
141#define PNG_PREVIOUS (BUTTON_A | BUTTON_LEFT)
142
143#elif CONFIG_KEYPAD == SANSA_E200_PAD
144#define PNG_ZOOM_PRE BUTTON_SELECT
145#define PNG_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
146#define PNG_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
147#define PNG_UP BUTTON_UP
148#define PNG_DOWN BUTTON_DOWN
149#define PNG_LEFT BUTTON_LEFT
150#define PNG_RIGHT BUTTON_RIGHT
151#define PNG_MENU BUTTON_POWER
152#define PNG_SLIDE_SHOW BUTTON_REC
153#define PNG_NEXT BUTTON_SCROLL_FWD
154#define PNG_NEXT_REPEAT (BUTTON_SCROLL_FWD|BUTTON_REPEAT)
155#define PNG_PREVIOUS BUTTON_SCROLL_BACK
156#define PNG_PREVIOUS_REPEAT (BUTTON_SCROLL_BACK|BUTTON_REPEAT)
157
158#elif CONFIG_KEYPAD == SANSA_FUZE_PAD
159#define PNG_ZOOM_PRE BUTTON_SELECT
160#define PNG_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
161#define PNG_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
162#define PNG_UP BUTTON_UP
163#define PNG_DOWN BUTTON_DOWN
164#define PNG_LEFT BUTTON_LEFT
165#define PNG_RIGHT BUTTON_RIGHT
166#define PNG_MENU (BUTTON_HOME|BUTTON_REPEAT)
167#define PNG_NEXT BUTTON_SCROLL_FWD
168#define PNG_NEXT_REPEAT (BUTTON_SCROLL_FWD|BUTTON_REPEAT)
169#define PNG_PREVIOUS BUTTON_SCROLL_BACK
170#define PNG_PREVIOUS_REPEAT (BUTTON_SCROLL_BACK|BUTTON_REPEAT)
171
172#elif CONFIG_KEYPAD == SANSA_C200_PAD
173#define PNG_ZOOM_PRE BUTTON_SELECT
174#define PNG_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
175#define PNG_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
176#define PNG_UP BUTTON_UP
177#define PNG_DOWN BUTTON_DOWN
178#define PNG_LEFT BUTTON_LEFT
179#define PNG_RIGHT BUTTON_RIGHT
180#define PNG_MENU BUTTON_POWER
181#define PNG_SLIDE_SHOW BUTTON_REC
182#define PNG_NEXT BUTTON_VOL_UP
183#define PNG_NEXT_REPEAT (BUTTON_VOL_UP|BUTTON_REPEAT)
184#define PNG_PREVIOUS BUTTON_VOL_DOWN
185#define PNG_PREVIOUS_REPEAT (BUTTON_VOL_DOWN|BUTTON_REPEAT)
186
187#elif CONFIG_KEYPAD == SANSA_CLIP_PAD
188#define PNG_ZOOM_PRE BUTTON_SELECT
189#define PNG_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
190#define PNG_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
191#define PNG_UP BUTTON_UP
192#define PNG_DOWN BUTTON_DOWN
193#define PNG_LEFT BUTTON_LEFT
194#define PNG_RIGHT BUTTON_RIGHT
195#define PNG_MENU BUTTON_POWER
196#define PNG_SLIDE_SHOW BUTTON_HOME
197#define PNG_NEXT BUTTON_VOL_UP
198#define PNG_NEXT_REPEAT (BUTTON_VOL_UP|BUTTON_REPEAT)
199#define PNG_PREVIOUS BUTTON_VOL_DOWN
200#define PNG_PREVIOUS_REPEAT (BUTTON_VOL_DOWN|BUTTON_REPEAT)
201
202#elif CONFIG_KEYPAD == SANSA_M200_PAD
203#define PNG_ZOOM_PRE BUTTON_SELECT
204#define PNG_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
205#define PNG_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
206#define PNG_UP BUTTON_UP
207#define PNG_DOWN BUTTON_DOWN
208#define PNG_LEFT BUTTON_LEFT
209#define PNG_RIGHT BUTTON_RIGHT
210#define PNG_MENU BUTTON_POWER
211#define PNG_SLIDE_SHOW (BUTTON_SELECT | BUTTON_UP)
212#define PNG_NEXT BUTTON_VOL_UP
213#define PNG_NEXT_REPEAT (BUTTON_VOL_UP|BUTTON_REPEAT)
214#define PNG_PREVIOUS BUTTON_VOL_DOWN
215#define PNG_PREVIOUS_REPEAT (BUTTON_VOL_DOWN|BUTTON_REPEAT)
216
217#elif CONFIG_KEYPAD == IRIVER_H10_PAD
218#define PNG_ZOOM_PRE BUTTON_PLAY
219#define PNG_ZOOM_IN (BUTTON_PLAY | BUTTON_REL)
220#define PNG_ZOOM_OUT (BUTTON_PLAY | BUTTON_REPEAT)
221#define PNG_UP BUTTON_SCROLL_UP
222#define PNG_DOWN BUTTON_SCROLL_DOWN
223#define PNG_LEFT BUTTON_LEFT
224#define PNG_RIGHT BUTTON_RIGHT
225#define PNG_MENU BUTTON_POWER
226#define PNG_NEXT BUTTON_FF
227#define PNG_PREVIOUS BUTTON_REW
228
229#elif CONFIG_KEYPAD == MROBE500_PAD
230
231#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
232#define PNG_ZOOM_IN BUTTON_VOL_UP
233#define PNG_ZOOM_OUT BUTTON_VOL_DOWN
234#define PNG_UP BUTTON_UP
235#define PNG_DOWN BUTTON_DOWN
236#define PNG_LEFT BUTTON_LEFT
237#define PNG_RIGHT BUTTON_RIGHT
238#define PNG_MENU BUTTON_MENU
239#define PNG_NEXT BUTTON_NEXT
240#define PNG_PREVIOUS BUTTON_PREV
241
242#elif CONFIG_KEYPAD == MROBE100_PAD
243#define PNG_ZOOM_IN BUTTON_SELECT
244#define PNG_ZOOM_OUT BUTTON_PLAY
245#define PNG_UP BUTTON_UP
246#define PNG_DOWN BUTTON_DOWN
247#define PNG_LEFT BUTTON_LEFT
248#define PNG_RIGHT BUTTON_RIGHT
249#define PNG_MENU BUTTON_MENU
250#define PNG_NEXT (BUTTON_DISPLAY | BUTTON_RIGHT)
251#define PNG_PREVIOUS (BUTTON_DISPLAY | BUTTON_LEFT)
252
253#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
254#define PNG_ZOOM_PRE BUTTON_RC_PLAY
255#define PNG_ZOOM_IN (BUTTON_RC_PLAY|BUTTON_REL)
256#define PNG_ZOOM_OUT (BUTTON_RC_PLAY|BUTTON_REPEAT)
257#define PNG_UP BUTTON_RC_VOL_UP
258#define PNG_DOWN BUTTON_RC_VOL_DOWN
259#define PNG_LEFT BUTTON_RC_REW
260#define PNG_RIGHT BUTTON_RC_FF
261#define PNG_MENU BUTTON_RC_REC
262#define PNG_NEXT BUTTON_RC_MODE
263#define PNG_PREVIOUS BUTTON_RC_MENU
264
265#elif CONFIG_KEYPAD == COWON_D2_PAD
266
267#elif CONFIG_KEYPAD == IAUDIO67_PAD
268#define PNG_ZOOM_IN BUTTON_VOLUP
269#define PNG_ZOOM_OUT BUTTON_VOLDOWN
270#define PNG_UP BUTTON_STOP
271#define PNG_DOWN BUTTON_PLAY
272#define PNG_LEFT BUTTON_LEFT
273#define PNG_RIGHT BUTTON_RIGHT
274#define PNG_MENU BUTTON_MENU
275#define PNG_NEXT (BUTTON_PLAY|BUTTON_VOLUP)
276#define PNG_PREVIOUS (BUTTON_PLAY|BUTTON_VOLDOWN)
277
278#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
279
280#define PNG_ZOOM_IN BUTTON_PLAY
281#define PNG_ZOOM_OUT BUTTON_CUSTOM
282#define PNG_UP BUTTON_UP
283#define PNG_DOWN BUTTON_DOWN
284#define PNG_LEFT BUTTON_LEFT
285#define PNG_RIGHT BUTTON_RIGHT
286#define PNG_MENU BUTTON_MENU
287#define PNG_NEXT BUTTON_SELECT
288#define PNG_PREVIOUS BUTTON_BACK
289
290#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
291#define PNG_ZOOM_IN BUTTON_VOL_UP
292#define PNG_ZOOM_OUT BUTTON_VOL_DOWN
293#define PNG_UP BUTTON_UP
294#define PNG_DOWN BUTTON_DOWN
295#define PNG_LEFT BUTTON_LEFT
296#define PNG_RIGHT BUTTON_RIGHT
297#define PNG_MENU BUTTON_MENU
298#define PNG_NEXT BUTTON_VIEW
299#define PNG_PREVIOUS BUTTON_PLAYLIST
300
301#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
302#define PNG_ZOOM_IN BUTTON_VOL_UP
303#define PNG_ZOOM_OUT BUTTON_VOL_DOWN
304#define PNG_UP BUTTON_UP
305#define PNG_DOWN BUTTON_DOWN
306#define PNG_LEFT BUTTON_PREV
307#define PNG_RIGHT BUTTON_NEXT
308#define PNG_MENU BUTTON_MENU
309#define PNG_NEXT BUTTON_RIGHT
310#define PNG_PREVIOUS BUTTON_LEFT
311
312#elif CONFIG_KEYPAD == ONDAVX747_PAD
313#define PNG_MENU BUTTON_POWER
314#elif CONFIG_KEYPAD == ONDAVX777_PAD
315#define PNG_MENU BUTTON_POWER
316
317#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
318#define PNG_ZOOM_IN (BUTTON_PLAY|BUTTON_UP)
319#define PNG_ZOOM_OUT (BUTTON_PLAY|BUTTON_DOWN)
320#define PNG_UP BUTTON_UP
321#define PNG_DOWN BUTTON_DOWN
322#define PNG_LEFT BUTTON_LEFT
323#define PNG_RIGHT BUTTON_RIGHT
324#define PNG_MENU BUTTON_PLAY
325#define PNG_NEXT BUTTON_FFWD
326#define PNG_PREVIOUS BUTTON_REW
327
328#else
329#error No keymap defined!
330#endif
331
332#ifdef HAVE_TOUCHSCREEN
333#ifndef PNG_UP
334#define PNG_UP BUTTON_TOPMIDDLE
335#endif
336#ifndef PNG_DOWN
337#define PNG_DOWN BUTTON_BOTTOMMIDDLE
338#endif
339#ifndef PNG_LEFT
340#define PNG_LEFT BUTTON_MIDLEFT
341#endif
342#ifndef PNG_RIGHT
343#define PNG_RIGHT BUTTON_MIDRIGHT
344#endif
345#ifndef PNG_ZOOM_IN
346#define PNG_ZOOM_IN BUTTON_TOPRIGHT
347#endif
348#ifndef PNG_ZOOM_OUT
349#define PNG_ZOOM_OUT BUTTON_TOPLEFT
350#endif
351#ifndef PNG_MENU
352#define PNG_MENU (BUTTON_CENTER|BUTTON_REL)
353#endif
354#ifndef PNG_NEXT
355#define PNG_NEXT BUTTON_BOTTOMRIGHT
356#endif
357#ifndef PNG_PREVIOUS
358#define PNG_PREVIOUS BUTTON_BOTTOMLEFT
359#endif
360#endif
361
362#define PLUGIN_OTHER 10 /* State code for output with return. */
363#define PLUGIN_ABORT 11
364#define PLUGIN_OUTOFMEM 12
365#define OUT_OF_MEMORY 9900
366#define FILE_TOO_LARGE 9910
diff --git a/apps/plugins/png/png.make b/apps/plugins/png/png.make
deleted file mode 100644
index 8f4ef39e72..0000000000
--- a/apps/plugins/png/png.make
+++ /dev/null
@@ -1,29 +0,0 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10PNGSRCDIR := $(APPSDIR)/plugins/png
11PNGBUILDDIR := $(BUILDDIR)/apps/plugins/png
12
13ROCKS += $(PNGBUILDDIR)/png.rock
14
15PNG_SRC := $(call preprocess, $(PNGSRCDIR)/SOURCES)
16PNG_OBJ := $(call c2obj, $(PNG_SRC))
17
18# add source files to OTHER_SRC to get automatic dependencies
19OTHER_SRC += $(PNG_SRC)
20
21# Use -O3 for png plugin : it gives a bigger file but very good performances
22PNGFLAGS = $(PLUGINFLAGS) -O3 -DNO_GZCOMPRESS -DNO_GZIP
23
24$(PNGBUILDDIR)/png.rock: $(PNG_OBJ)
25
26# Compile PNG plugin with extra flags (adapted from ZXBox)
27$(PNGBUILDDIR)/%.o: $(PNGSRCDIR)/%.c $(PNGSRCDIR)/png.make
28 $(SILENT)mkdir -p $(dir $@)
29 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) -I$(dir $<) $(PNGFLAGS) -c $< -o $@
diff --git a/apps/plugins/png/zconf.h b/apps/plugins/png/zconf.h
deleted file mode 100644
index 03a9431c8b..0000000000
--- a/apps/plugins/png/zconf.h
+++ /dev/null
@@ -1,332 +0,0 @@
1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#ifndef ZCONF_H
9#define ZCONF_H
10
11/*
12 * If you *really* need a unique prefix for all types and library functions,
13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14 */
15#ifdef Z_PREFIX
16# define deflateInit_ z_deflateInit_
17# define deflate z_deflate
18# define deflateEnd z_deflateEnd
19# define inflateInit_ z_inflateInit_
20# define inflate z_inflate
21# define inflateEnd z_inflateEnd
22# define deflateInit2_ z_deflateInit2_
23# define deflateSetDictionary z_deflateSetDictionary
24# define deflateCopy z_deflateCopy
25# define deflateReset z_deflateReset
26# define deflateParams z_deflateParams
27# define deflateBound z_deflateBound
28# define deflatePrime z_deflatePrime
29# define inflateInit2_ z_inflateInit2_
30# define inflateSetDictionary z_inflateSetDictionary
31# define inflateSync z_inflateSync
32# define inflateSyncPoint z_inflateSyncPoint
33# define inflateCopy z_inflateCopy
34# define inflateReset z_inflateReset
35# define inflateBack z_inflateBack
36# define inflateBackEnd z_inflateBackEnd
37# define compress z_compress
38# define compress2 z_compress2
39# define compressBound z_compressBound
40# define uncompress z_uncompress
41# define adler32 z_adler32
42# define crc32 z_crc32
43# define get_crc_table z_get_crc_table
44# define zError z_zError
45
46# define alloc_func z_alloc_func
47# define free_func z_free_func
48# define in_func z_in_func
49# define out_func z_out_func
50# define Byte z_Byte
51# define uInt z_uInt
52# define uLong z_uLong
53# define Bytef z_Bytef
54# define charf z_charf
55# define intf z_intf
56# define uIntf z_uIntf
57# define uLongf z_uLongf
58# define voidpf z_voidpf
59# define voidp z_voidp
60#endif
61
62#if defined(__MSDOS__) && !defined(MSDOS)
63# define MSDOS
64#endif
65#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
66# define OS2
67#endif
68#if defined(_WINDOWS) && !defined(WINDOWS)
69# define WINDOWS
70#endif
71#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
72# ifndef WIN32
73# define WIN32
74# endif
75#endif
76#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
77# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
78# ifndef SYS16BIT
79# define SYS16BIT
80# endif
81# endif
82#endif
83
84/*
85 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
86 * than 64k bytes at a time (needed on systems with 16-bit int).
87 */
88#ifdef SYS16BIT
89# define MAXSEG_64K
90#endif
91#ifdef MSDOS
92# define UNALIGNED_OK
93#endif
94
95#ifdef __STDC_VERSION__
96# ifndef STDC
97# define STDC
98# endif
99# if __STDC_VERSION__ >= 199901L
100# ifndef STDC99
101# define STDC99
102# endif
103# endif
104#endif
105#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
106# define STDC
107#endif
108#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
109# define STDC
110#endif
111#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
112# define STDC
113#endif
114#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
115# define STDC
116#endif
117
118#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
119# define STDC
120#endif
121
122#ifndef STDC
123# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
124# define const /* note: need a more gentle solution here */
125# endif
126#endif
127
128/* Some Mac compilers merge all .h files incorrectly: */
129#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
130# define NO_DUMMY_DECL
131#endif
132
133/* Maximum value for memLevel in deflateInit2 */
134#ifndef MAX_MEM_LEVEL
135# ifdef MAXSEG_64K
136# define MAX_MEM_LEVEL 8
137# else
138# define MAX_MEM_LEVEL 9
139# endif
140#endif
141
142/* Maximum value for windowBits in deflateInit2 and inflateInit2.
143 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
144 * created by gzip. (Files created by minigzip can still be extracted by
145 * gzip.)
146 */
147#ifndef MAX_WBITS
148# define MAX_WBITS 15 /* 32K LZ77 window */
149#endif
150
151/* The memory requirements for deflate are (in bytes):
152 (1 << (windowBits+2)) + (1 << (memLevel+9))
153 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
154 plus a few kilobytes for small objects. For example, if you want to reduce
155 the default memory requirements from 256K to 128K, compile with
156 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
157 Of course this will generally degrade compression (there's no free lunch).
158
159 The memory requirements for inflate are (in bytes) 1 << windowBits
160 that is, 32K for windowBits=15 (default value) plus a few kilobytes
161 for small objects.
162*/
163
164 /* Type declarations */
165
166#ifndef OF /* function prototypes */
167# ifdef STDC
168# define OF(args) args
169# else
170# define OF(args) ()
171# endif
172#endif
173
174/* The following definitions for FAR are needed only for MSDOS mixed
175 * model programming (small or medium model with some far allocations).
176 * This was tested only with MSC; for other MSDOS compilers you may have
177 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
178 * just define FAR to be empty.
179 */
180#ifdef SYS16BIT
181# if defined(M_I86SM) || defined(M_I86MM)
182 /* MSC small or medium model */
183# define SMALL_MEDIUM
184# ifdef _MSC_VER
185# define FAR _far
186# else
187# define FAR far
188# endif
189# endif
190# if (defined(__SMALL__) || defined(__MEDIUM__))
191 /* Turbo C small or medium model */
192# define SMALL_MEDIUM
193# ifdef __BORLANDC__
194# define FAR _far
195# else
196# define FAR far
197# endif
198# endif
199#endif
200
201#if defined(WINDOWS) || defined(WIN32)
202 /* If building or using zlib as a DLL, define ZLIB_DLL.
203 * This is not mandatory, but it offers a little performance increase.
204 */
205# ifdef ZLIB_DLL
206# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
207# ifdef ZLIB_INTERNAL
208# define ZEXTERN extern __declspec(dllexport)
209# else
210# define ZEXTERN extern __declspec(dllimport)
211# endif
212# endif
213# endif /* ZLIB_DLL */
214 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
215 * define ZLIB_WINAPI.
216 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
217 */
218# ifdef ZLIB_WINAPI
219# ifdef FAR
220# undef FAR
221# endif
222# include <windows.h>
223 /* No need for _export, use ZLIB.DEF instead. */
224 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
225# define ZEXPORT WINAPI
226# ifdef WIN32
227# define ZEXPORTVA WINAPIV
228# else
229# define ZEXPORTVA FAR CDECL
230# endif
231# endif
232#endif
233
234#if defined (__BEOS__)
235# ifdef ZLIB_DLL
236# ifdef ZLIB_INTERNAL
237# define ZEXPORT __declspec(dllexport)
238# define ZEXPORTVA __declspec(dllexport)
239# else
240# define ZEXPORT __declspec(dllimport)
241# define ZEXPORTVA __declspec(dllimport)
242# endif
243# endif
244#endif
245
246#ifndef ZEXTERN
247# define ZEXTERN extern
248#endif
249#ifndef ZEXPORT
250# define ZEXPORT
251#endif
252#ifndef ZEXPORTVA
253# define ZEXPORTVA
254#endif
255
256#ifndef FAR
257# define FAR
258#endif
259
260#if !defined(__MACTYPES__)
261typedef unsigned char Byte; /* 8 bits */
262#endif
263typedef unsigned int uInt; /* 16 bits or more */
264typedef unsigned long uLong; /* 32 bits or more */
265
266#ifdef SMALL_MEDIUM
267 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
268# define Bytef Byte FAR
269#else
270 typedef Byte FAR Bytef;
271#endif
272typedef char FAR charf;
273typedef int FAR intf;
274typedef uInt FAR uIntf;
275typedef uLong FAR uLongf;
276
277#ifdef STDC
278 typedef void const *voidpc;
279 typedef void FAR *voidpf;
280 typedef void *voidp;
281#else
282 typedef Byte const *voidpc;
283 typedef Byte FAR *voidpf;
284 typedef Byte *voidp;
285#endif
286
287#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
288# include <sys/types.h> /* for off_t */
289# include <unistd.h> /* for SEEK_* and off_t */
290# ifdef VMS
291# include <unixio.h> /* for off_t */
292# endif
293# define z_off_t off_t
294#endif
295#ifndef SEEK_SET
296# define SEEK_SET 0 /* Seek from beginning of file. */
297# define SEEK_CUR 1 /* Seek from current position. */
298# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
299#endif
300#ifndef z_off_t
301# define z_off_t long
302#endif
303
304#if defined(__OS400__)
305# define NO_vsnprintf
306#endif
307
308#if defined(__MVS__)
309# define NO_vsnprintf
310# ifdef FAR
311# undef FAR
312# endif
313#endif
314
315/* MVS linker does not support external names larger than 8 bytes */
316#if defined(__MVS__)
317# pragma map(deflateInit_,"DEIN")
318# pragma map(deflateInit2_,"DEIN2")
319# pragma map(deflateEnd,"DEEND")
320# pragma map(deflateBound,"DEBND")
321# pragma map(inflateInit_,"ININ")
322# pragma map(inflateInit2_,"ININ2")
323# pragma map(inflateEnd,"INEND")
324# pragma map(inflateSync,"INSY")
325# pragma map(inflateSetDictionary,"INSEDI")
326# pragma map(compressBound,"CMBND")
327# pragma map(inflate_table,"INTABL")
328# pragma map(inflate_fast,"INFA")
329# pragma map(inflate_copyright,"INCOPY")
330#endif
331
332#endif /* ZCONF_H */
diff --git a/apps/plugins/png/zlib.h b/apps/plugins/png/zlib.h
deleted file mode 100644
index 23e6dcd8f5..0000000000
--- a/apps/plugins/png/zlib.h
+++ /dev/null
@@ -1,1357 +0,0 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.3, July 18th, 2005
3
4 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
13
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
21
22 Jean-loup Gailly Mark Adler
23 jloup@gzip.org madler@alumni.caltech.edu
24
25
26 The data format used by the zlib library is described by RFCs (Request for
27 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
28 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29*/
30
31#ifndef ZLIB_H
32#define ZLIB_H
33
34#include "zconf.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define ZLIB_VERSION "1.2.3"
41#define ZLIB_VERNUM 0x1230
42
43/*
44 The 'zlib' compression library provides in-memory compression and
45 decompression functions, including integrity checks of the uncompressed
46 data. This version of the library supports only one compression method
47 (deflation) but other algorithms will be added later and will have the same
48 stream interface.
49
50 Compression can be done in a single step if the buffers are large
51 enough (for example if an input file is mmap'ed), or can be done by
52 repeated calls of the compression function. In the latter case, the
53 application must provide more input and/or consume the output
54 (providing more output space) before each call.
55
56 The compressed data format used by default by the in-memory functions is
57 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
58 around a deflate stream, which is itself documented in RFC 1951.
59
60 The library also supports reading and writing files in gzip (.gz) format
61 with an interface similar to that of stdio using the functions that start
62 with "gz". The gzip format is different from the zlib format. gzip is a
63 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
64
65 This library can optionally read and write gzip streams in memory as well.
66
67 The zlib format was designed to be compact and fast for use in memory
68 and on communications channels. The gzip format was designed for single-
69 file compression on file systems, has a larger header than zlib to maintain
70 directory information, and uses a different, slower check method than zlib.
71
72 The library does not install any signal handler. The decoder checks
73 the consistency of the compressed data, so the library should never
74 crash even in case of corrupted input.
75*/
76
77typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
78typedef void (*free_func) OF((voidpf opaque, voidpf address));
79
80struct internal_state;
81
82typedef struct z_stream_s {
83 Bytef *next_in; /* next input byte */
84 uInt avail_in; /* number of bytes available at next_in */
85 uLong total_in; /* total nb of input bytes read so far */
86
87 Bytef *next_out; /* next output byte should be put there */
88 uInt avail_out; /* remaining free space at next_out */
89 uLong total_out; /* total nb of bytes output so far */
90
91 char *msg; /* last error message, NULL if no error */
92 //struct internal_state state; /* not visible by applications */
93
94 alloc_func zalloc; /* used to allocate the internal state */
95 free_func zfree; /* used to free the internal state */
96 voidpf opaque; /* private data object passed to zalloc and zfree */
97
98 int data_type; /* best guess about the data type: binary or text */
99 uLong adler; /* adler32 value of the uncompressed data */
100 uLong reserved; /* reserved for future use */
101} z_stream;
102
103typedef z_stream FAR *z_streamp;
104
105/*
106 gzip header information passed to and from zlib routines. See RFC 1952
107 for more details on the meanings of these fields.
108*/
109typedef struct gz_header_s {
110 int text; /* true if compressed data believed to be text */
111 uLong time; /* modification time */
112 int xflags; /* extra flags (not used when writing a gzip file) */
113 int os; /* operating system */
114 Bytef *extra; /* pointer to extra field or Z_NULL if none */
115 uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
116 uInt extra_max; /* space at extra (only when reading header) */
117 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
118 uInt name_max; /* space at name (only when reading header) */
119 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
120 uInt comm_max; /* space at comment (only when reading header) */
121 int hcrc; /* true if there was or will be a header crc */
122 int done; /* true when done reading gzip header (not used
123 when writing a gzip file) */
124} gz_header;
125
126typedef gz_header FAR *gz_headerp;
127
128/*
129 The application must update next_in and avail_in when avail_in has
130 dropped to zero. It must update next_out and avail_out when avail_out
131 has dropped to zero. The application must initialize zalloc, zfree and
132 opaque before calling the init function. All other fields are set by the
133 compression library and must not be updated by the application.
134
135 The opaque value provided by the application will be passed as the first
136 parameter for calls of zalloc and zfree. This can be useful for custom
137 memory management. The compression library attaches no meaning to the
138 opaque value.
139
140 zalloc must return Z_NULL if there is not enough memory for the object.
141 If zlib is used in a multi-threaded application, zalloc and zfree must be
142 thread safe.
143
144 On 16-bit systems, the functions zalloc and zfree must be able to allocate
145 exactly 65536 bytes, but will not be required to allocate more than this
146 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
147 pointers returned by zalloc for objects of exactly 65536 bytes *must*
148 have their offset normalized to zero. The default allocation function
149 provided by this library ensures this (see zutil.c). To reduce memory
150 requirements and avoid any allocation of 64K objects, at the expense of
151 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
152
153 The fields total_in and total_out can be used for statistics or
154 progress reports. After compression, total_in holds the total size of
155 the uncompressed data and may be saved for use in the decompressor
156 (particularly if the decompressor wants to decompress everything in
157 a single step).
158*/
159
160 /* constants */
161
162#define Z_NO_FLUSH 0
163#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
164#define Z_SYNC_FLUSH 2
165#define Z_FULL_FLUSH 3
166#define Z_FINISH 4
167#define Z_BLOCK 5
168/* Allowed flush values; see deflate() and inflate() below for details */
169
170#define Z_OK 0
171#define Z_STREAM_END 1
172#define Z_NEED_DICT 2
173#define Z_ERRNO (-1)
174#define Z_STREAM_ERROR (-2)
175#define Z_DATA_ERROR (-3)
176#define Z_MEM_ERROR (-4)
177#define Z_BUF_ERROR (-5)
178#define Z_VERSION_ERROR (-6)
179/* Return codes for the compression/decompression functions. Negative
180 * values are errors, positive values are used for special but normal events.
181 */
182
183#define Z_NO_COMPRESSION 0
184#define Z_BEST_SPEED 1
185#define Z_BEST_COMPRESSION 9
186#define Z_DEFAULT_COMPRESSION (-1)
187/* compression levels */
188
189#define Z_FILTERED 1
190#define Z_HUFFMAN_ONLY 2
191#define Z_RLE 3
192#define Z_FIXED 4
193#define Z_DEFAULT_STRATEGY 0
194/* compression strategy; see deflateInit2() below for details */
195
196#define Z_BINARY 0
197#define Z_TEXT 1
198#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
199#define Z_UNKNOWN 2
200/* Possible values of the data_type field (though see inflate()) */
201
202#define Z_DEFLATED 8
203/* The deflate compression method (the only one supported in this version) */
204
205#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
206
207#define zlib_version zlibVersion()
208/* for compatibility with versions < 1.0.2 */
209
210 /* basic functions */
211
212ZEXTERN const char * ZEXPORT zlibVersion OF((void));
213/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
214 If the first character differs, the library code actually used is
215 not compatible with the zlib.h header file used by the application.
216 This check is automatically made by deflateInit and inflateInit.
217 */
218
219/*
220ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
221
222 Initializes the internal stream state for compression. The fields
223 zalloc, zfree and opaque must be initialized before by the caller.
224 If zalloc and zfree are set to Z_NULL, deflateInit updates them to
225 use default allocation functions.
226
227 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
228 1 gives best speed, 9 gives best compression, 0 gives no compression at
229 all (the input data is simply copied a block at a time).
230 Z_DEFAULT_COMPRESSION requests a default compromise between speed and
231 compression (currently equivalent to level 6).
232
233 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
234 enough memory, Z_STREAM_ERROR if level is not a valid compression level,
235 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
236 with the version assumed by the caller (ZLIB_VERSION).
237 msg is set to null if there is no error message. deflateInit does not
238 perform any compression: this will be done by deflate().
239*/
240
241
242ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
243/*
244 deflate compresses as much data as possible, and stops when the input
245 buffer becomes empty or the output buffer becomes full. It may introduce some
246 output latency (reading input without producing any output) except when
247 forced to flush.
248
249 The detailed semantics are as follows. deflate performs one or both of the
250 following actions:
251
252 - Compress more input starting at next_in and update next_in and avail_in
253 accordingly. If not all input can be processed (because there is not
254 enough room in the output buffer), next_in and avail_in are updated and
255 processing will resume at this point for the next call of deflate().
256
257 - Provide more output starting at next_out and update next_out and avail_out
258 accordingly. This action is forced if the parameter flush is non zero.
259 Forcing flush frequently degrades the compression ratio, so this parameter
260 should be set only when necessary (in interactive applications).
261 Some output may be provided even if flush is not set.
262
263 Before the call of deflate(), the application should ensure that at least
264 one of the actions is possible, by providing more input and/or consuming
265 more output, and updating avail_in or avail_out accordingly; avail_out
266 should never be zero before the call. The application can consume the
267 compressed output when it wants, for example when the output buffer is full
268 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
269 and with zero avail_out, it must be called again after making room in the
270 output buffer because there might be more output pending.
271
272 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
273 decide how much data to accumualte before producing output, in order to
274 maximize compression.
275
276 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
277 flushed to the output buffer and the output is aligned on a byte boundary, so
278 that the decompressor can get all input data available so far. (In particular
279 avail_in is zero after the call if enough output space has been provided
280 before the call.) Flushing may degrade compression for some compression
281 algorithms and so it should be used only when necessary.
282
283 If flush is set to Z_FULL_FLUSH, all output is flushed as with
284 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
285 restart from this point if previous compressed data has been damaged or if
286 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
287 compression.
288
289 If deflate returns with avail_out == 0, this function must be called again
290 with the same value of the flush parameter and more output space (updated
291 avail_out), until the flush is complete (deflate returns with non-zero
292 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
293 avail_out is greater than six to avoid repeated flush markers due to
294 avail_out == 0 on return.
295
296 If the parameter flush is set to Z_FINISH, pending input is processed,
297 pending output is flushed and deflate returns with Z_STREAM_END if there
298 was enough output space; if deflate returns with Z_OK, this function must be
299 called again with Z_FINISH and more output space (updated avail_out) but no
300 more input data, until it returns with Z_STREAM_END or an error. After
301 deflate has returned Z_STREAM_END, the only possible operations on the
302 stream are deflateReset or deflateEnd.
303
304 Z_FINISH can be used immediately after deflateInit if all the compression
305 is to be done in a single step. In this case, avail_out must be at least
306 the value returned by deflateBound (see below). If deflate does not return
307 Z_STREAM_END, then it must be called again as described above.
308
309 deflate() sets strm->adler to the adler32 checksum of all input read
310 so far (that is, total_in bytes).
311
312 deflate() may update strm->data_type if it can make a good guess about
313 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
314 binary. This field is only for information purposes and does not affect
315 the compression algorithm in any manner.
316
317 deflate() returns Z_OK if some progress has been made (more input
318 processed or more output produced), Z_STREAM_END if all input has been
319 consumed and all output has been produced (only when flush is set to
320 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
321 if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
322 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
323 fatal, and deflate() can be called again with more input and more output
324 space to continue compressing.
325*/
326
327
328ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
329/*
330 All dynamically allocated data structures for this stream are freed.
331 This function discards any unprocessed input and does not flush any
332 pending output.
333
334 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
335 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
336 prematurely (some input or output was discarded). In the error case,
337 msg may be set but then points to a static string (which must not be
338 deallocated).
339*/
340
341
342/*
343ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
344
345 Initializes the internal stream state for decompression. The fields
346 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
347 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
348 value depends on the compression method), inflateInit determines the
349 compression method from the zlib header and allocates all data structures
350 accordingly; otherwise the allocation will be deferred to the first call of
351 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
352 use default allocation functions.
353
354 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
355 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
356 version assumed by the caller. msg is set to null if there is no error
357 message. inflateInit does not perform any decompression apart from reading
358 the zlib header if present: this will be done by inflate(). (So next_in and
359 avail_in may be modified, but next_out and avail_out are unchanged.)
360*/
361
362
363ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
364/*
365 inflate decompresses as much data as possible, and stops when the input
366 buffer becomes empty or the output buffer becomes full. It may introduce
367 some output latency (reading input without producing any output) except when
368 forced to flush.
369
370 The detailed semantics are as follows. inflate performs one or both of the
371 following actions:
372
373 - Decompress more input starting at next_in and update next_in and avail_in
374 accordingly. If not all input can be processed (because there is not
375 enough room in the output buffer), next_in is updated and processing
376 will resume at this point for the next call of inflate().
377
378 - Provide more output starting at next_out and update next_out and avail_out
379 accordingly. inflate() provides as much output as possible, until there
380 is no more input data or no more space in the output buffer (see below
381 about the flush parameter).
382
383 Before the call of inflate(), the application should ensure that at least
384 one of the actions is possible, by providing more input and/or consuming
385 more output, and updating the next_* and avail_* values accordingly.
386 The application can consume the uncompressed output when it wants, for
387 example when the output buffer is full (avail_out == 0), or after each
388 call of inflate(). If inflate returns Z_OK and with zero avail_out, it
389 must be called again after making room in the output buffer because there
390 might be more output pending.
391
392 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
393 Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
394 output as possible to the output buffer. Z_BLOCK requests that inflate() stop
395 if and when it gets to the next deflate block boundary. When decoding the
396 zlib or gzip format, this will cause inflate() to return immediately after
397 the header and before the first block. When doing a raw inflate, inflate()
398 will go ahead and process the first block, and will return when it gets to
399 the end of that block, or when it runs out of data.
400
401 The Z_BLOCK option assists in appending to or combining deflate streams.
402 Also to assist in this, on return inflate() will set strm->data_type to the
403 number of unused bits in the last byte taken from strm->next_in, plus 64
404 if inflate() is currently decoding the last block in the deflate stream,
405 plus 128 if inflate() returned immediately after decoding an end-of-block
406 code or decoding the complete header up to just before the first byte of the
407 deflate stream. The end-of-block will not be indicated until all of the
408 uncompressed data from that block has been written to strm->next_out. The
409 number of unused bits may in general be greater than seven, except when
410 bit 7 of data_type is set, in which case the number of unused bits will be
411 less than eight.
412
413 inflate() should normally be called until it returns Z_STREAM_END or an
414 error. However if all decompression is to be performed in a single step
415 (a single call of inflate), the parameter flush should be set to
416 Z_FINISH. In this case all pending input is processed and all pending
417 output is flushed; avail_out must be large enough to hold all the
418 uncompressed data. (The size of the uncompressed data may have been saved
419 by the compressor for this purpose.) The next operation on this stream must
420 be inflateEnd to deallocate the decompression state. The use of Z_FINISH
421 is never required, but can be used to inform inflate that a faster approach
422 may be used for the single inflate() call.
423
424 In this implementation, inflate() always flushes as much output as
425 possible to the output buffer, and always uses the faster approach on the
426 first call. So the only effect of the flush parameter in this implementation
427 is on the return value of inflate(), as noted below, or when it returns early
428 because Z_BLOCK is used.
429
430 If a preset dictionary is needed after this call (see inflateSetDictionary
431 below), inflate sets strm->adler to the adler32 checksum of the dictionary
432 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
433 strm->adler to the adler32 checksum of all output produced so far (that is,
434 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
435 below. At the end of the stream, inflate() checks that its computed adler32
436 checksum is equal to that saved by the compressor and returns Z_STREAM_END
437 only if the checksum is correct.
438
439 inflate() will decompress and check either zlib-wrapped or gzip-wrapped
440 deflate data. The header type is detected automatically. Any information
441 contained in the gzip header is not retained, so applications that need that
442 information should instead use raw inflate, see inflateInit2() below, or
443 inflateBack() and perform their own processing of the gzip header and
444 trailer.
445
446 inflate() returns Z_OK if some progress has been made (more input processed
447 or more output produced), Z_STREAM_END if the end of the compressed data has
448 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
449 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
450 corrupted (input stream not conforming to the zlib format or incorrect check
451 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
452 if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
453 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
454 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
455 inflate() can be called again with more input and more output space to
456 continue decompressing. If Z_DATA_ERROR is returned, the application may then
457 call inflateSync() to look for a good compression block if a partial recovery
458 of the data is desired.
459*/
460
461
462ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
463/*
464 All dynamically allocated data structures for this stream are freed.
465 This function discards any unprocessed input and does not flush any
466 pending output.
467
468 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
469 was inconsistent. In the error case, msg may be set but then points to a
470 static string (which must not be deallocated).
471*/
472
473 /* Advanced functions */
474
475/*
476 The following functions are needed only in some special applications.
477*/
478
479/*
480ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
481 int level,
482 int method,
483 int windowBits,
484 int memLevel,
485 int strategy));
486
487 This is another version of deflateInit with more compression options. The
488 fields next_in, zalloc, zfree and opaque must be initialized before by
489 the caller.
490
491 The method parameter is the compression method. It must be Z_DEFLATED in
492 this version of the library.
493
494 The windowBits parameter is the base two logarithm of the window size
495 (the size of the history buffer). It should be in the range 8..15 for this
496 version of the library. Larger values of this parameter result in better
497 compression at the expense of memory usage. The default value is 15 if
498 deflateInit is used instead.
499
500 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
501 determines the window size. deflate() will then generate raw deflate data
502 with no zlib header or trailer, and will not compute an adler32 check value.
503
504 windowBits can also be greater than 15 for optional gzip encoding. Add
505 16 to windowBits to write a simple gzip header and trailer around the
506 compressed data instead of a zlib wrapper. The gzip header will have no
507 file name, no extra data, no comment, no modification time (set to zero),
508 no header crc, and the operating system will be set to 255 (unknown). If a
509 gzip stream is being written, strm->adler is a crc32 instead of an adler32.
510
511 The memLevel parameter specifies how much memory should be allocated
512 for the internal compression state. memLevel=1 uses minimum memory but
513 is slow and reduces compression ratio; memLevel=9 uses maximum memory
514 for optimal speed. The default value is 8. See zconf.h for total memory
515 usage as a function of windowBits and memLevel.
516
517 The strategy parameter is used to tune the compression algorithm. Use the
518 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
519 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
520 string match), or Z_RLE to limit match distances to one (run-length
521 encoding). Filtered data consists mostly of small values with a somewhat
522 random distribution. In this case, the compression algorithm is tuned to
523 compress them better. The effect of Z_FILTERED is to force more Huffman
524 coding and less string matching; it is somewhat intermediate between
525 Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
526 Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
527 parameter only affects the compression ratio but not the correctness of the
528 compressed output even if it is not set appropriately. Z_FIXED prevents the
529 use of dynamic Huffman codes, allowing for a simpler decoder for special
530 applications.
531
532 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
533 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
534 method). msg is set to null if there is no error message. deflateInit2 does
535 not perform any compression: this will be done by deflate().
536*/
537
538ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
539 const Bytef *dictionary,
540 uInt dictLength));
541/*
542 Initializes the compression dictionary from the given byte sequence
543 without producing any compressed output. This function must be called
544 immediately after deflateInit, deflateInit2 or deflateReset, before any
545 call of deflate. The compressor and decompressor must use exactly the same
546 dictionary (see inflateSetDictionary).
547
548 The dictionary should consist of strings (byte sequences) that are likely
549 to be encountered later in the data to be compressed, with the most commonly
550 used strings preferably put towards the end of the dictionary. Using a
551 dictionary is most useful when the data to be compressed is short and can be
552 predicted with good accuracy; the data can then be compressed better than
553 with the default empty dictionary.
554
555 Depending on the size of the compression data structures selected by
556 deflateInit or deflateInit2, a part of the dictionary may in effect be
557 discarded, for example if the dictionary is larger than the window size in
558 deflate or deflate2. Thus the strings most likely to be useful should be
559 put at the end of the dictionary, not at the front. In addition, the
560 current implementation of deflate will use at most the window size minus
561 262 bytes of the provided dictionary.
562
563 Upon return of this function, strm->adler is set to the adler32 value
564 of the dictionary; the decompressor may later use this value to determine
565 which dictionary has been used by the compressor. (The adler32 value
566 applies to the whole dictionary even if only a subset of the dictionary is
567 actually used by the compressor.) If a raw deflate was requested, then the
568 adler32 value is not computed and strm->adler is not set.
569
570 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
571 parameter is invalid (such as NULL dictionary) or the stream state is
572 inconsistent (for example if deflate has already been called for this stream
573 or if the compression method is bsort). deflateSetDictionary does not
574 perform any compression: this will be done by deflate().
575*/
576
577ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
578 z_streamp source));
579/*
580 Sets the destination stream as a complete copy of the source stream.
581
582 This function can be useful when several compression strategies will be
583 tried, for example when there are several ways of pre-processing the input
584 data with a filter. The streams that will be discarded should then be freed
585 by calling deflateEnd. Note that deflateCopy duplicates the internal
586 compression state which can be quite large, so this strategy is slow and
587 can consume lots of memory.
588
589 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
590 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
591 (such as zalloc being NULL). msg is left unchanged in both source and
592 destination.
593*/
594
595ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
596/*
597 This function is equivalent to deflateEnd followed by deflateInit,
598 but does not free and reallocate all the internal compression state.
599 The stream will keep the same compression level and any other attributes
600 that may have been set by deflateInit2.
601
602 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
603 stream state was inconsistent (such as zalloc or state being NULL).
604*/
605
606ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
607 int level,
608 int strategy));
609/*
610 Dynamically update the compression level and compression strategy. The
611 interpretation of level and strategy is as in deflateInit2. This can be
612 used to switch between compression and straight copy of the input data, or
613 to switch to a different kind of input data requiring a different
614 strategy. If the compression level is changed, the input available so far
615 is compressed with the old level (and may be flushed); the new level will
616 take effect only at the next call of deflate().
617
618 Before the call of deflateParams, the stream state must be set as for
619 a call of deflate(), since the currently available input may have to
620 be compressed and flushed. In particular, strm->avail_out must be non-zero.
621
622 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
623 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
624 if strm->avail_out was zero.
625*/
626
627ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
628 int good_length,
629 int max_lazy,
630 int nice_length,
631 int max_chain));
632/*
633 Fine tune deflate's internal compression parameters. This should only be
634 used by someone who understands the algorithm used by zlib's deflate for
635 searching for the best matching string, and even then only by the most
636 fanatic optimizer trying to squeeze out the last compressed bit for their
637 specific input data. Read the deflate.c source code for the meaning of the
638 max_lazy, good_length, nice_length, and max_chain parameters.
639
640 deflateTune() can be called after deflateInit() or deflateInit2(), and
641 returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
642 */
643
644ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
645 uLong sourceLen));
646/*
647 deflateBound() returns an upper bound on the compressed size after
648 deflation of sourceLen bytes. It must be called after deflateInit()
649 or deflateInit2(). This would be used to allocate an output buffer
650 for deflation in a single pass, and so would be called before deflate().
651*/
652
653ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
654 int bits,
655 int value));
656/*
657 deflatePrime() inserts bits in the deflate output stream. The intent
658 is that this function is used to start off the deflate output with the
659 bits leftover from a previous deflate stream when appending to it. As such,
660 this function can only be used for raw deflate, and must be used before the
661 first deflate() call after a deflateInit2() or deflateReset(). bits must be
662 less than or equal to 16, and that many of the least significant bits of
663 value will be inserted in the output.
664
665 deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
666 stream state was inconsistent.
667*/
668
669ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
670 gz_headerp head));
671/*
672 deflateSetHeader() provides gzip header information for when a gzip
673 stream is requested by deflateInit2(). deflateSetHeader() may be called
674 after deflateInit2() or deflateReset() and before the first call of
675 deflate(). The text, time, os, extra field, name, and comment information
676 in the provided gz_header structure are written to the gzip header (xflag is
677 ignored -- the extra flags are set according to the compression level). The
678 caller must assure that, if not Z_NULL, name and comment are terminated with
679 a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
680 available there. If hcrc is true, a gzip header crc is included. Note that
681 the current versions of the command-line version of gzip (up through version
682 1.3.x) do not support header crc's, and will report that it is a "multi-part
683 gzip file" and give up.
684
685 If deflateSetHeader is not used, the default gzip header has text false,
686 the time set to zero, and os set to 255, with no extra, name, or comment
687 fields. The gzip header is returned to the default state by deflateReset().
688
689 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
690 stream state was inconsistent.
691*/
692
693/*
694ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
695 int windowBits));
696
697 This is another version of inflateInit with an extra parameter. The
698 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
699 before by the caller.
700
701 The windowBits parameter is the base two logarithm of the maximum window
702 size (the size of the history buffer). It should be in the range 8..15 for
703 this version of the library. The default value is 15 if inflateInit is used
704 instead. windowBits must be greater than or equal to the windowBits value
705 provided to deflateInit2() while compressing, or it must be equal to 15 if
706 deflateInit2() was not used. If a compressed stream with a larger window
707 size is given as input, inflate() will return with the error code
708 Z_DATA_ERROR instead of trying to allocate a larger window.
709
710 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
711 determines the window size. inflate() will then process raw deflate data,
712 not looking for a zlib or gzip header, not generating a check value, and not
713 looking for any check values for comparison at the end of the stream. This
714 is for use with other formats that use the deflate compressed data format
715 such as zip. Those formats provide their own check values. If a custom
716 format is developed using the raw deflate format for compressed data, it is
717 recommended that a check value such as an adler32 or a crc32 be applied to
718 the uncompressed data as is done in the zlib, gzip, and zip formats. For
719 most applications, the zlib format should be used as is. Note that comments
720 above on the use in deflateInit2() applies to the magnitude of windowBits.
721
722 windowBits can also be greater than 15 for optional gzip decoding. Add
723 32 to windowBits to enable zlib and gzip decoding with automatic header
724 detection, or add 16 to decode only the gzip format (the zlib format will
725 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
726 a crc32 instead of an adler32.
727
728 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
729 memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
730 is set to null if there is no error message. inflateInit2 does not perform
731 any decompression apart from reading the zlib header if present: this will
732 be done by inflate(). (So next_in and avail_in may be modified, but next_out
733 and avail_out are unchanged.)
734*/
735
736ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
737 const Bytef *dictionary,
738 uInt dictLength));
739/*
740 Initializes the decompression dictionary from the given uncompressed byte
741 sequence. This function must be called immediately after a call of inflate,
742 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
743 can be determined from the adler32 value returned by that call of inflate.
744 The compressor and decompressor must use exactly the same dictionary (see
745 deflateSetDictionary). For raw inflate, this function can be called
746 immediately after inflateInit2() or inflateReset() and before any call of
747 inflate() to set the dictionary. The application must insure that the
748 dictionary that was used for compression is provided.
749
750 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
751 parameter is invalid (such as NULL dictionary) or the stream state is
752 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
753 expected one (incorrect adler32 value). inflateSetDictionary does not
754 perform any decompression: this will be done by subsequent calls of
755 inflate().
756*/
757
758ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
759/*
760 Skips invalid compressed data until a full flush point (see above the
761 description of deflate with Z_FULL_FLUSH) can be found, or until all
762 available input is skipped. No output is provided.
763
764 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
765 if no more input was provided, Z_DATA_ERROR if no flush point has been found,
766 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
767 case, the application may save the current current value of total_in which
768 indicates where valid compressed data was found. In the error case, the
769 application may repeatedly call inflateSync, providing more input each time,
770 until success or end of the input data.
771*/
772
773ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
774 z_streamp source));
775/*
776 Sets the destination stream as a complete copy of the source stream.
777
778 This function can be useful when randomly accessing a large stream. The
779 first pass through the stream can periodically record the inflate state,
780 allowing restarting inflate at those points when randomly accessing the
781 stream.
782
783 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
784 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
785 (such as zalloc being NULL). msg is left unchanged in both source and
786 destination.
787*/
788
789ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
790/*
791 This function is equivalent to inflateEnd followed by inflateInit,
792 but does not free and reallocate all the internal decompression state.
793 The stream will keep attributes that may have been set by inflateInit2.
794
795 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
796 stream state was inconsistent (such as zalloc or state being NULL).
797*/
798
799ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
800 int bits,
801 int value));
802/*
803 This function inserts bits in the inflate input stream. The intent is
804 that this function is used to start inflating at a bit position in the
805 middle of a byte. The provided bits will be used before any bytes are used
806 from next_in. This function should only be used with raw inflate, and
807 should be used before the first inflate() call after inflateInit2() or
808 inflateReset(). bits must be less than or equal to 16, and that many of the
809 least significant bits of value will be inserted in the input.
810
811 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
812 stream state was inconsistent.
813*/
814
815ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
816 gz_headerp head));
817/*
818 inflateGetHeader() requests that gzip header information be stored in the
819 provided gz_header structure. inflateGetHeader() may be called after
820 inflateInit2() or inflateReset(), and before the first call of inflate().
821 As inflate() processes the gzip stream, head->done is zero until the header
822 is completed, at which time head->done is set to one. If a zlib stream is
823 being decoded, then head->done is set to -1 to indicate that there will be
824 no gzip header information forthcoming. Note that Z_BLOCK can be used to
825 force inflate() to return immediately after header processing is complete
826 and before any actual data is decompressed.
827
828 The text, time, xflags, and os fields are filled in with the gzip header
829 contents. hcrc is set to true if there is a header CRC. (The header CRC
830 was valid if done is set to one.) If extra is not Z_NULL, then extra_max
831 contains the maximum number of bytes to write to extra. Once done is true,
832 extra_len contains the actual extra field length, and extra contains the
833 extra field, or that field truncated if extra_max is less than extra_len.
834 If name is not Z_NULL, then up to name_max characters are written there,
835 terminated with a zero unless the length is greater than name_max. If
836 comment is not Z_NULL, then up to comm_max characters are written there,
837 terminated with a zero unless the length is greater than comm_max. When
838 any of extra, name, or comment are not Z_NULL and the respective field is
839 not present in the header, then that field is set to Z_NULL to signal its
840 absence. This allows the use of deflateSetHeader() with the returned
841 structure to duplicate the header. However if those fields are set to
842 allocated memory, then the application will need to save those pointers
843 elsewhere so that they can be eventually freed.
844
845 If inflateGetHeader is not used, then the header information is simply
846 discarded. The header is always checked for validity, including the header
847 CRC if present. inflateReset() will reset the process to discard the header
848 information. The application would need to call inflateGetHeader() again to
849 retrieve the header from the next gzip stream.
850
851 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
852 stream state was inconsistent.
853*/
854
855/*
856ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
857 unsigned char FAR *window));
858
859 Initialize the internal stream state for decompression using inflateBack()
860 calls. The fields zalloc, zfree and opaque in strm must be initialized
861 before the call. If zalloc and zfree are Z_NULL, then the default library-
862 derived memory allocation routines are used. windowBits is the base two
863 logarithm of the window size, in the range 8..15. window is a caller
864 supplied buffer of that size. Except for special applications where it is
865 assured that deflate was used with small window sizes, windowBits must be 15
866 and a 32K byte window must be supplied to be able to decompress general
867 deflate streams.
868
869 See inflateBack() for the usage of these routines.
870
871 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
872 the paramaters are invalid, Z_MEM_ERROR if the internal state could not
873 be allocated, or Z_VERSION_ERROR if the version of the library does not
874 match the version of the header file.
875*/
876
877typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
878typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
879
880ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
881 in_func in, void FAR *in_desc,
882 out_func out, void FAR *out_desc));
883/*
884 inflateBack() does a raw inflate with a single call using a call-back
885 interface for input and output. This is more efficient than inflate() for
886 file i/o applications in that it avoids copying between the output and the
887 sliding window by simply making the window itself the output buffer. This
888 function trusts the application to not change the output buffer passed by
889 the output function, at least until inflateBack() returns.
890
891 inflateBackInit() must be called first to allocate the internal state
892 and to initialize the state with the user-provided window buffer.
893 inflateBack() may then be used multiple times to inflate a complete, raw
894 deflate stream with each call. inflateBackEnd() is then called to free
895 the allocated state.
896
897 A raw deflate stream is one with no zlib or gzip header or trailer.
898 This routine would normally be used in a utility that reads zip or gzip
899 files and writes out uncompressed files. The utility would decode the
900 header and process the trailer on its own, hence this routine expects
901 only the raw deflate stream to decompress. This is different from the
902 normal behavior of inflate(), which expects either a zlib or gzip header and
903 trailer around the deflate stream.
904
905 inflateBack() uses two subroutines supplied by the caller that are then
906 called by inflateBack() for input and output. inflateBack() calls those
907 routines until it reads a complete deflate stream and writes out all of the
908 uncompressed data, or until it encounters an error. The function's
909 parameters and return types are defined above in the in_func and out_func
910 typedefs. inflateBack() will call in(in_desc, &buf) which should return the
911 number of bytes of provided input, and a pointer to that input in buf. If
912 there is no input available, in() must return zero--buf is ignored in that
913 case--and inflateBack() will return a buffer error. inflateBack() will call
914 out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
915 should return zero on success, or non-zero on failure. If out() returns
916 non-zero, inflateBack() will return with an error. Neither in() nor out()
917 are permitted to change the contents of the window provided to
918 inflateBackInit(), which is also the buffer that out() uses to write from.
919 The length written by out() will be at most the window size. Any non-zero
920 amount of input may be provided by in().
921
922 For convenience, inflateBack() can be provided input on the first call by
923 setting strm->next_in and strm->avail_in. If that input is exhausted, then
924 in() will be called. Therefore strm->next_in must be initialized before
925 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
926 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
927 must also be initialized, and then if strm->avail_in is not zero, input will
928 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
929
930 The in_desc and out_desc parameters of inflateBack() is passed as the
931 first parameter of in() and out() respectively when they are called. These
932 descriptors can be optionally used to pass any information that the caller-
933 supplied in() and out() functions need to do their job.
934
935 On return, inflateBack() will set strm->next_in and strm->avail_in to
936 pass back any unused input that was provided by the last in() call. The
937 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
938 if in() or out() returned an error, Z_DATA_ERROR if there was a format
939 error in the deflate stream (in which case strm->msg is set to indicate the
940 nature of the error), or Z_STREAM_ERROR if the stream was not properly
941 initialized. In the case of Z_BUF_ERROR, an input or output error can be
942 distinguished using strm->next_in which will be Z_NULL only if in() returned
943 an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
944 out() returning non-zero. (in() will always be called before out(), so
945 strm->next_in is assured to be defined if out() returns non-zero.) Note
946 that inflateBack() cannot return Z_OK.
947*/
948
949ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
950/*
951 All memory allocated by inflateBackInit() is freed.
952
953 inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
954 state was inconsistent.
955*/
956
957ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
958/* Return flags indicating compile-time options.
959
960 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
961 1.0: size of uInt
962 3.2: size of uLong
963 5.4: size of voidpf (pointer)
964 7.6: size of z_off_t
965
966 Compiler, assembler, and debug options:
967 8: DEBUG
968 9: ASMV or ASMINF -- use ASM code
969 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
970 11: 0 (reserved)
971
972 One-time table building (smaller code, but not thread-safe if true):
973 12: BUILDFIXED -- build static block decoding tables when needed
974 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
975 14,15: 0 (reserved)
976
977 Library content (indicates missing functionality):
978 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
979 deflate code when not needed)
980 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
981 and decode gzip streams (to avoid linking crc code)
982 18-19: 0 (reserved)
983
984 Operation variations (changes in library functionality):
985 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
986 21: FASTEST -- deflate algorithm with only one, lowest compression level
987 22,23: 0 (reserved)
988
989 The sprintf variant used by gzprintf (zero is best):
990 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
991 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
992 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
993
994 Remainder:
995 27-31: 0 (reserved)
996 */
997
998
999 /* utility functions */
1000
1001/*
1002 The following utility functions are implemented on top of the
1003 basic stream-oriented functions. To simplify the interface, some
1004 default options are assumed (compression level and memory usage,
1005 standard memory allocation functions). The source code of these
1006 utility functions can easily be modified if you need special options.
1007*/
1008
1009ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1010 const Bytef *source, uLong sourceLen));
1011/*
1012 Compresses the source buffer into the destination buffer. sourceLen is
1013 the byte length of the source buffer. Upon entry, destLen is the total
1014 size of the destination buffer, which must be at least the value returned
1015 by compressBound(sourceLen). Upon exit, destLen is the actual size of the
1016 compressed buffer.
1017 This function can be used to compress a whole file at once if the
1018 input file is mmap'ed.
1019 compress returns Z_OK if success, Z_MEM_ERROR if there was not
1020 enough memory, Z_BUF_ERROR if there was not enough room in the output
1021 buffer.
1022*/
1023
1024ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1025 const Bytef *source, uLong sourceLen,
1026 int level));
1027/*
1028 Compresses the source buffer into the destination buffer. The level
1029 parameter has the same meaning as in deflateInit. sourceLen is the byte
1030 length of the source buffer. Upon entry, destLen is the total size of the
1031 destination buffer, which must be at least the value returned by
1032 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1033 compressed buffer.
1034
1035 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1036 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1037 Z_STREAM_ERROR if the level parameter is invalid.
1038*/
1039
1040ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1041/*
1042 compressBound() returns an upper bound on the compressed size after
1043 compress() or compress2() on sourceLen bytes. It would be used before
1044 a compress() or compress2() call to allocate the destination buffer.
1045*/
1046
1047ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1048 const Bytef *source, uLong sourceLen));
1049/*
1050 Decompresses the source buffer into the destination buffer. sourceLen is
1051 the byte length of the source buffer. Upon entry, destLen is the total
1052 size of the destination buffer, which must be large enough to hold the
1053 entire uncompressed data. (The size of the uncompressed data must have
1054 been saved previously by the compressor and transmitted to the decompressor
1055 by some mechanism outside the scope of this compression library.)
1056 Upon exit, destLen is the actual size of the compressed buffer.
1057 This function can be used to decompress a whole file at once if the
1058 input file is mmap'ed.
1059
1060 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1061 enough memory, Z_BUF_ERROR if there was not enough room in the output
1062 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
1063*/
1064
1065
1066typedef voidp gzFile;
1067
1068ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1069/*
1070 Opens a gzip (.gz) file for reading or writing. The mode parameter
1071 is as in fopen ("rb" or "wb") but can also include a compression level
1072 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
1073 Huffman only compression as in "wb1h", or 'R' for run-length encoding
1074 as in "wb1R". (See the description of deflateInit2 for more information
1075 about the strategy parameter.)
1076
1077 gzopen can be used to read a file which is not in gzip format; in this
1078 case gzread will directly read from the file without decompression.
1079
1080 gzopen returns NULL if the file could not be opened or if there was
1081 insufficient memory to allocate the (de)compression state; errno
1082 can be checked to distinguish the two cases (if errno is zero, the
1083 zlib error is Z_MEM_ERROR). */
1084
1085ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1086/*
1087 gzdopen() associates a gzFile with the file descriptor fd. File
1088 descriptors are obtained from calls like open, dup, creat, pipe or
1089 fileno (in the file has been previously opened with fopen).
1090 The mode parameter is as in gzopen.
1091 The next call of gzclose on the returned gzFile will also close the
1092 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
1093 descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
1094 gzdopen returns NULL if there was insufficient memory to allocate
1095 the (de)compression state.
1096*/
1097
1098ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1099/*
1100 Dynamically update the compression level or strategy. See the description
1101 of deflateInit2 for the meaning of these parameters.
1102 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1103 opened for writing.
1104*/
1105
1106ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1107/*
1108 Reads the given number of uncompressed bytes from the compressed file.
1109 If the input file was not in gzip format, gzread copies the given number
1110 of bytes into the buffer.
1111 gzread returns the number of uncompressed bytes actually read (0 for
1112 end of file, -1 for error). */
1113
1114ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1115 voidpc buf, unsigned len));
1116/*
1117 Writes the given number of uncompressed bytes into the compressed file.
1118 gzwrite returns the number of uncompressed bytes actually written
1119 (0 in case of error).
1120*/
1121
1122ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
1123/*
1124 Converts, formats, and writes the args to the compressed file under
1125 control of the format string, as in fprintf. gzprintf returns the number of
1126 uncompressed bytes actually written (0 in case of error). The number of
1127 uncompressed bytes written is limited to 4095. The caller should assure that
1128 this limit is not exceeded. If it is exceeded, then gzprintf() will return
1129 return an error (0) with nothing written. In this case, there may also be a
1130 buffer overflow with unpredictable consequences, which is possible only if
1131 zlib was compiled with the insecure functions sprintf() or vsprintf()
1132 because the secure snprintf() or vsnprintf() functions were not available.
1133*/
1134
1135ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1136/*
1137 Writes the given null-terminated string to the compressed file, excluding
1138 the terminating null character.
1139 gzputs returns the number of characters written, or -1 in case of error.
1140*/
1141
1142ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1143/*
1144 Reads bytes from the compressed file until len-1 characters are read, or
1145 a newline character is read and transferred to buf, or an end-of-file
1146 condition is encountered. The string is then terminated with a null
1147 character.
1148 gzgets returns buf, or Z_NULL in case of error.
1149*/
1150
1151ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1152/*
1153 Writes c, converted to an unsigned char, into the compressed file.
1154 gzputc returns the value that was written, or -1 in case of error.
1155*/
1156
1157ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1158/*
1159 Reads one byte from the compressed file. gzgetc returns this byte
1160 or -1 in case of end of file or error.
1161*/
1162
1163ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1164/*
1165 Push one character back onto the stream to be read again later.
1166 Only one character of push-back is allowed. gzungetc() returns the
1167 character pushed, or -1 on failure. gzungetc() will fail if a
1168 character has been pushed but not read yet, or if c is -1. The pushed
1169 character will be discarded if the stream is repositioned with gzseek()
1170 or gzrewind().
1171*/
1172
1173ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1174/*
1175 Flushes all pending output into the compressed file. The parameter
1176 flush is as in the deflate() function. The return value is the zlib
1177 error number (see function gzerror below). gzflush returns Z_OK if
1178 the flush parameter is Z_FINISH and all output could be flushed.
1179 gzflush should be called only when strictly necessary because it can
1180 degrade compression.
1181*/
1182
1183ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1184 z_off_t offset, int whence));
1185/*
1186 Sets the starting position for the next gzread or gzwrite on the
1187 given compressed file. The offset represents a number of bytes in the
1188 uncompressed data stream. The whence parameter is defined as in lseek(2);
1189 the value SEEK_END is not supported.
1190 If the file is opened for reading, this function is emulated but can be
1191 extremely slow. If the file is opened for writing, only forward seeks are
1192 supported; gzseek then compresses a sequence of zeroes up to the new
1193 starting position.
1194
1195 gzseek returns the resulting offset location as measured in bytes from
1196 the beginning of the uncompressed stream, or -1 in case of error, in
1197 particular if the file is opened for writing and the new starting position
1198 would be before the current position.
1199*/
1200
1201ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1202/*
1203 Rewinds the given file. This function is supported only for reading.
1204
1205 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1206*/
1207
1208ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1209/*
1210 Returns the starting position for the next gzread or gzwrite on the
1211 given compressed file. This position represents a number of bytes in the
1212 uncompressed data stream.
1213
1214 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1215*/
1216
1217ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1218/*
1219 Returns 1 when EOF has previously been detected reading the given
1220 input stream, otherwise zero.
1221*/
1222
1223ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1224/*
1225 Returns 1 if file is being read directly without decompression, otherwise
1226 zero.
1227*/
1228
1229ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1230/*
1231 Flushes all pending output if necessary, closes the compressed file
1232 and deallocates all the (de)compression state. The return value is the zlib
1233 error number (see function gzerror below).
1234*/
1235
1236ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1237/*
1238 Returns the error message for the last error which occurred on the
1239 given compressed file. errnum is set to zlib error number. If an
1240 error occurred in the file system and not in the compression library,
1241 errnum is set to Z_ERRNO and the application may consult errno
1242 to get the exact error code.
1243*/
1244
1245ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1246/*
1247 Clears the error and end-of-file flags for file. This is analogous to the
1248 clearerr() function in stdio. This is useful for continuing to read a gzip
1249 file that is being written concurrently.
1250*/
1251
1252 /* checksum functions */
1253
1254/*
1255 These functions are not related to compression but are exported
1256 anyway because they might be useful in applications using the
1257 compression library.
1258*/
1259
1260ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1261/*
1262 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1263 return the updated checksum. If buf is NULL, this function returns
1264 the required initial value for the checksum.
1265 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1266 much faster. Usage example:
1267
1268 uLong adler = adler32(0L, Z_NULL, 0);
1269
1270 while (read_buffer(buffer, length) != EOF) {
1271 adler = adler32(adler, buffer, length);
1272 }
1273 if (adler != original_adler) error();
1274*/
1275
1276ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1277 z_off_t len2));
1278/*
1279 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1280 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1281 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1282 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
1283*/
1284
1285ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1286/*
1287 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1288 updated CRC-32. If buf is NULL, this function returns the required initial
1289 value for the for the crc. Pre- and post-conditioning (one's complement) is
1290 performed within this function so it shouldn't be done by the application.
1291 Usage example:
1292
1293 uLong crc = crc32(0L, Z_NULL, 0);
1294
1295 while (read_buffer(buffer, length) != EOF) {
1296 crc = crc32(crc, buffer, length);
1297 }
1298 if (crc != original_crc) error();
1299*/
1300
1301ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1302
1303/*
1304 Combine two CRC-32 check values into one. For two sequences of bytes,
1305 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1306 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1307 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1308 len2.
1309*/
1310
1311
1312 /* various hacks, don't look :) */
1313
1314/* deflateInit and inflateInit are macros to allow checking the zlib version
1315 * and the compiler's view of z_stream:
1316 */
1317ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1318 const char *version, int stream_size));
1319ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1320 const char *version, int stream_size));
1321ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1322 int windowBits, int memLevel,
1323 int strategy, const char *version,
1324 int stream_size));
1325ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1326 const char *version, int stream_size));
1327ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1328 unsigned char FAR *window,
1329 const char *version,
1330 int stream_size));
1331#define deflateInit(strm, level) \
1332 deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
1333#define inflateInit(strm) \
1334 inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
1335#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1336 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1337 (strategy), ZLIB_VERSION, sizeof(z_stream))
1338#define inflateInit2(strm, windowBits) \
1339 inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1340#define inflateBackInit(strm, windowBits, window) \
1341 inflateBackInit_((strm), (windowBits), (window), \
1342 ZLIB_VERSION, sizeof(z_stream))
1343
1344
1345#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1346 struct internal_state {int dummy;}; /* hack for buggy compilers */
1347#endif
1348
1349ZEXTERN const char * ZEXPORT zError OF((int));
1350ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
1351ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
1352
1353#ifdef __cplusplus
1354}
1355#endif
1356
1357#endif /* ZLIB_H */
diff --git a/apps/plugins/png/zutil.h b/apps/plugins/png/zutil.h
deleted file mode 100644
index b7d5eff81b..0000000000
--- a/apps/plugins/png/zutil.h
+++ /dev/null
@@ -1,269 +0,0 @@
1/* zutil.h -- internal interface and configuration of the compression library
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* @(#) $Id$ */
12
13#ifndef ZUTIL_H
14#define ZUTIL_H
15
16#define ZLIB_INTERNAL
17#include "zlib.h"
18
19#ifdef STDC
20# ifndef _WIN32_WCE
21# include <stddef.h>
22# endif
23# include <string.h>
24# include <stdlib.h>
25#endif
26#ifdef NO_ERRNO_H
27# ifdef _WIN32_WCE
28 /* The Microsoft C Run-Time Library for Windows CE doesn't have
29 * errno. We define it as a global variable to simplify porting.
30 * Its value is always 0 and should not be used. We rename it to
31 * avoid conflict with other libraries that use the same workaround.
32 */
33# define errno z_errno
34# endif
35 extern int errno;
36#else
37# ifndef _WIN32_WCE
38# include <errno.h>
39# endif
40#endif
41
42#ifndef local
43# define local static
44#endif
45/* compile with -Dlocal if your debugger can't find static symbols */
46
47typedef unsigned char uch;
48typedef uch FAR uchf;
49typedef unsigned short ush;
50typedef ush FAR ushf;
51typedef unsigned long ulg;
52
53extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
54/* (size given to avoid silly warnings with Visual C++) */
55
56#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
57
58#define ERR_RETURN(strm,err) \
59 return (strm->msg = (char*)ERR_MSG(err), (err))
60/* To be used only when the state is known to be valid */
61
62 /* common constants */
63
64#ifndef DEF_WBITS
65# define DEF_WBITS MAX_WBITS
66#endif
67/* default windowBits for decompression. MAX_WBITS is for compression only */
68
69#if MAX_MEM_LEVEL >= 8
70# define DEF_MEM_LEVEL 8
71#else
72# define DEF_MEM_LEVEL MAX_MEM_LEVEL
73#endif
74/* default memLevel */
75
76#define STORED_BLOCK 0
77#define STATIC_TREES 1
78#define DYN_TREES 2
79/* The three kinds of block type */
80
81#define MIN_MATCH 3
82#define MAX_MATCH 258
83/* The minimum and maximum match lengths */
84
85#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
86
87 /* target dependencies */
88
89#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
90# define OS_CODE 0x00
91# if defined(__TURBOC__) || defined(__BORLANDC__)
92# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
93 /* Allow compilation with ANSI keywords only enabled */
94 void _Cdecl farfree( void *block );
95 void *_Cdecl farmalloc( unsigned long nbytes );
96# else
97# include <alloc.h>
98# endif
99# else /* MSC or DJGPP */
100# include <malloc.h>
101# endif
102#endif
103
104#ifdef AMIGA
105# define OS_CODE 0x01
106#endif
107
108#if defined(VAXC) || defined(VMS)
109# define OS_CODE 0x02
110# define F_OPEN(name, mode) \
111 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
112#endif
113
114#if defined(ATARI) || defined(atarist)
115# define OS_CODE 0x05
116#endif
117
118#ifdef OS2
119# define OS_CODE 0x06
120# ifdef M_I86
121 #include <malloc.h>
122# endif
123#endif
124
125#if defined(MACOS) || defined(TARGET_OS_MAC)
126# define OS_CODE 0x07
127# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
128# include <unix.h> /* for fdopen */
129# else
130# ifndef fdopen
131# define fdopen(fd,mode) NULL /* No fdopen() */
132# endif
133# endif
134#endif
135
136#ifdef TOPS20
137# define OS_CODE 0x0a
138#endif
139
140#ifdef WIN32
141# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
142# define OS_CODE 0x0b
143# endif
144#endif
145
146#ifdef __50SERIES /* Prime/PRIMOS */
147# define OS_CODE 0x0f
148#endif
149
150#if defined(_BEOS_) || defined(RISCOS)
151# define fdopen(fd,mode) NULL /* No fdopen() */
152#endif
153
154#if (defined(_MSC_VER) && (_MSC_VER > 600))
155# if defined(_WIN32_WCE)
156# define fdopen(fd,mode) NULL /* No fdopen() */
157# ifndef _PTRDIFF_T_DEFINED
158 typedef int ptrdiff_t;
159# define _PTRDIFF_T_DEFINED
160# endif
161# else
162# define fdopen(fd,type) _fdopen(fd,type)
163# endif
164#endif
165
166 /* common defaults */
167
168#ifndef OS_CODE
169# define OS_CODE 0x03 /* assume Unix */
170#endif
171
172#ifndef F_OPEN
173# define F_OPEN(name, mode) fopen((name), (mode))
174#endif
175
176 /* functions */
177
178#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
179# ifndef HAVE_VSNPRINTF
180# define HAVE_VSNPRINTF
181# endif
182#endif
183#if defined(__CYGWIN__)
184# ifndef HAVE_VSNPRINTF
185# define HAVE_VSNPRINTF
186# endif
187#endif
188#ifndef HAVE_VSNPRINTF
189# ifdef MSDOS
190 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
191 but for now we just assume it doesn't. */
192# define NO_vsnprintf
193# endif
194# ifdef __TURBOC__
195# define NO_vsnprintf
196# endif
197# ifdef WIN32
198 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
199# if !defined(vsnprintf) && !defined(NO_vsnprintf)
200# define vsnprintf _vsnprintf
201# endif
202# endif
203# ifdef __SASC
204# define NO_vsnprintf
205# endif
206#endif
207#ifdef VMS
208# define NO_vsnprintf
209#endif
210
211#if defined(pyr)
212# define NO_MEMCPY
213#endif
214#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
215 /* Use our own functions for small and medium model with MSC <= 5.0.
216 * You may have to use the same strategy for Borland C (untested).
217 * The __SC__ check is for Symantec.
218 */
219# define NO_MEMCPY
220#endif
221#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
222# define HAVE_MEMCPY
223#endif
224#ifdef HAVE_MEMCPY
225# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
226# define zmemcpy _fmemcpy
227# define zmemcmp _fmemcmp
228# define zmemzero(dest, len) _fmemset(dest, 0, len)
229# else
230# define zmemcpy memcpy
231# define zmemcmp memcmp
232# define zmemzero(dest, len) memset(dest, 0, len)
233# endif
234#else
235 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
236 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
237 extern void zmemzero OF((Bytef* dest, uInt len));
238#endif
239
240/* Diagnostic functions */
241#ifdef DEBUG
242# include <stdio.h>
243 extern int z_verbose;
244 extern void z_error OF((char *m));
245# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
246# define Trace(x) {if (z_verbose>=0) fprintf x ;}
247# define Tracev(x) {if (z_verbose>0) fprintf x ;}
248# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
249# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
250# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
251#else
252# define Assert(cond,msg)
253# define Trace(x)
254# define Tracev(x)
255# define Tracevv(x)
256# define Tracec(c,x)
257# define Tracecv(c,x)
258#endif
259
260
261voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
262void zcfree OF((voidpf opaque, voidpf ptr));
263
264#define ZALLOC(strm, items, size) \
265 (*((strm)->zalloc))((strm)->opaque, (items), (size))
266#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
267#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
268
269#endif /* ZUTIL_H */