annotate src/dmzlib.c @ 999:b3b8794c4915

Rename a function argument.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Mar 2015 03:02:19 +0200
parents 4a68f8d0adc5
children 5df750e47721
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- ZLib implementation
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Public domain zlib decode v0.2 by Sean Barrett 2006-11-18
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * Modified and reformatted for DMLib by Matti 'ccr' Hamalainen
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmzlib.h"
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #define DM_ZLIB_TMPBUF_SIZE (16 * 1024)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
11 #define DMSTBI_ASSERT(x) // dummy
951
1723ebe6771c Add kludge stbi__err() implementation temporarily until the error handling
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
12
1723ebe6771c Add kludge stbi__err() implementation temporarily until the error handling
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
13
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 // @TODO: should statically initialize these for optimal thread safety
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
15 static Uint8 dm_zdefault_length[288], dm_zdefault_distance[32];
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 void dmZLibInit()
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 int i;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 // use <= to match clearly with spec
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 for (i = 0; i <= 143; i++)
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
24 dm_zdefault_length[i] = 8;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 for (; i <= 255; i++)
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
27 dm_zdefault_length[i] = 9;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 for (; i <= 279; i++)
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
30 dm_zdefault_length[i] = 7;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 for (; i <= 287; i++)
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
33 dm_zdefault_length[i] = 8;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 for (i = 0; i <= 31; i++)
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
36 dm_zdefault_distance[i] = 5;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
998
4a68f8d0adc5 Rename bitreverse functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 997
diff changeset
40 static inline int dmBitReverse16(int n)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 return n;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
998
4a68f8d0adc5 Rename bitreverse functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 997
diff changeset
50 static inline int dmBitReverseN(int v, int bits)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
52 DMSTBI_ASSERT(bits <= 16);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 // to bit reverse n bits, reverse 16 and shift
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 // e.g. 11 bits, bit reverse and shift away 5
998
4a68f8d0adc5 Rename bitreverse functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 997
diff changeset
55 return dmBitReverse16(v) >> (16 - bits);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
59 static int dmZLibBuildHuffmanTables(DMZHuffmanContext * ctx, const Uint8 * sizelist, const int num)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 int i, k = 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 int code, next_code[16], sizes[17];
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 // DEFLATE spec for generating codes
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 memset(sizes, 0, sizeof(sizes));
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
66 memset(ctx->fast, 0, sizeof(ctx->fast));
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 for (i = 0; i < num; i++)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 sizes[sizelist[i]]++;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 sizes[0] = 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 for (i = 1; i < 16; i++)
954
88cbea0ee9b5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
73 {
88cbea0ee9b5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
74 if (sizes[i] > (1 << i))
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
75 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
76 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
77 "Sizes assert failed while building Huffman codes.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
78 }
954
88cbea0ee9b5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
79 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 code = 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 for (i = 1; i < 16; i++)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 next_code[i] = code;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
85 ctx->firstCode[i] = (Uint16) code;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
86 ctx->firstSymbol[i] = (Uint16) k;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 code = (code + sizes[i]);
954
88cbea0ee9b5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
88
88cbea0ee9b5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
89 if (sizes[i] && code - 1 >= (1 << i))
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
90 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
91 return dmError(DMERR_INVALID_DATA,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
92 "Bad Huffman code lengths.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
93 }
954
88cbea0ee9b5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
94
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
95 ctx->maxCode[i] = code << (16 - i); // preshift for inner loop
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 code <<= 1;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 k += sizes[i];
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
100 ctx->maxCode[16] = 0x10000; // sentinel
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 for (i = 0; i < num; i++)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 int s = sizelist[i];
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 if (s)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
106 int c = next_code[s] - ctx->firstCode[s] + ctx->firstSymbol[s];
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 Uint16 fastv = (Uint16) ((s << 9) | i);
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
108 ctx->size[c] = (Uint8) s;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
109 ctx->value[c] = (Uint16) i;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 if (s <= STBI__ZFAST_BITS)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 {
998
4a68f8d0adc5 Rename bitreverse functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 997
diff changeset
112 int k = dmBitReverseN(next_code[s], s);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 while (k < STBI__ZFAST_SIZE)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
115 ctx->fast[k] = fastv;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 k += (1 << s);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
997
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
119 next_code[s]++;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 }
964
76ac0d5c89b3 Oops, bugfix.
Matti Hamalainen <ccr@tnsp.org>
parents: 960
diff changeset
122
76ac0d5c89b3 Oops, bugfix.
Matti Hamalainen <ccr@tnsp.org>
parents: 960
diff changeset
123 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
127 static inline Uint8 dmZGet8(DMZLibContext * ctx)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
129 if (ctx->zbuffer >= ctx->zbufferEnd)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 return 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
132 return *ctx->zbuffer++;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
136 static void dmZFillBits(DMZLibContext * ctx)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 do
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
140 DMSTBI_ASSERT(ctx->codeBuffer < (1U << ctx->numBits));
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
141 ctx->codeBuffer |= dmZGet8(ctx) << ctx->numBits;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
142 ctx->numBits += 8;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
144 while (ctx->numBits <= 24);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
148 static inline unsigned int dmZReceive(DMZLibContext * ctx, int n)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
150 unsigned int val;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
151
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
152 if (ctx->numBits < n)
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
153 dmZFillBits(ctx);
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
154
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
155 val = ctx->codeBuffer & ((1 << n) - 1);
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
156 ctx->codeBuffer >>= n;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
157 ctx->numBits -= n;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
158
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
159 return val;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
163 static int dmZLibHuffmanDecodeSlow(DMZLibContext * ctx, DMZHuffmanContext * huff, int *val)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 int b, s, k;
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
166 *val = 0;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 // not resolved by fast table, so compute it the slow way
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 // use jpeg approach, which requires MSbits at top
998
4a68f8d0adc5 Rename bitreverse functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 997
diff changeset
170 k = dmBitReverse16(ctx->codeBuffer);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 for (s = STBI__ZFAST_BITS + 1; ; s++)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
173 if (k < huff->maxCode[s])
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
174 break;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 if (s == 16)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
178 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
179 return dmError(DMERR_DATA_ERROR,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
180 "Bad Huffman code.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
181 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 // code size is s, so:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
184 b = (k >> (16 - s)) - huff->firstCode[s] + huff->firstSymbol[s];
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
185 DMSTBI_ASSERT(huff->size[b] == s);
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
186
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
187 ctx->codeBuffer >>= s;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
188 ctx->numBits -= s;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
189 *val = huff->value[b];
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
190
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
191 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
195 static inline int dmZLibHuffmanDecode(DMZLibContext * ctx, DMZHuffmanContext * huff, int *val)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 int b;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
198 if (ctx->numBits < 16)
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
199 dmZFillBits(ctx);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
201 b = huff->fast[ctx->codeBuffer & STBI__ZFAST_MASK];
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 if (b)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 int s = b >> 9;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
205 ctx->codeBuffer >>= s;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
206 ctx->numBits -= s;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
207 *val = b & 511;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
208 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
210
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
211 return dmZLibHuffmanDecodeSlow(ctx, huff, val);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
215 static int dmZLibExpand(DMZLibContext * ctx, Uint8 *zout, size_t n)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
217 Uint8 *newBuf;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
218 size_t cur, limit;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
219
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
220 ctx->zout = zout;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
222 if (!ctx->expandable)
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
223 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
224 return dmError(DMERR_BOUNDS,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
225 "Output buffer limit hit, and is not expandable.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
226 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
228 cur = ctx->zout - ctx->zoutStart;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
229 limit = ctx->zoutEnd - ctx->zoutStart;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 while (cur + n > limit)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 limit *= 2;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
234 if ((newBuf = (Uint8 *) dmRealloc(ctx->zoutStart, limit)) == NULL)
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
235 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
236 return dmError(DMERR_MALLOC,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
237 "Could not reallocate buffer.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
238 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
240 ctx->zoutStart = newBuf;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
241 ctx->zout = newBuf + cur;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
242 ctx->zoutEnd = newBuf + limit;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
243
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
244 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 static const int stbi__zlength_base[31] =
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 };
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 static const int stbi__zlength_extra[31] =
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 5, 5, 5, 5, 0, 0, 0
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 };
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 static const int stbi__zdist_base[32] =
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 16385, 24577, 0, 0
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 };
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 static const int stbi__zdist_extra[32] =
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 10, 11, 11, 12, 12, 13, 13
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 };
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
275 static int dmZLibParseHuffmanBlock(DMZLibContext * a)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
277 Uint8 *zout = a->zout;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 for (;;)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
280 int z, ret;
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
281 if ((ret = dmZLibHuffmanDecode(a, &a->zlength, &z)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
282 return ret;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
283
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 if (z < 256)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
286 if (zout >= a->zoutEnd)
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
287 {
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
288 if ((ret = dmZLibExpand(a, zout, 1)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
289 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 zout = a->zout;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 }
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
293 *zout++ = (Uint8) z;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 Uint8 *p;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 int len, dist;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 if (z == 256)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 a->zout = zout;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
302 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 z -= 257;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 len = stbi__zlength_base[z];
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 if (stbi__zlength_extra[z])
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
308 len += dmZReceive(a, stbi__zlength_extra[z]);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
310 if ((ret = dmZLibHuffmanDecode(a, &a->zdistance, &z)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
311 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 dist = stbi__zdist_base[z];
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 if (stbi__zdist_extra[z])
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
315 dist += dmZReceive(a, stbi__zdist_extra[z]);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
317 if (zout - a->zoutStart < dist)
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
318 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
319 return dmError(DMERR_DATA_ERROR,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
320 "Bad Huffman block distance.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
321 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
323 if (zout + len > a->zoutEnd)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 {
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
325 if (!dmZLibExpand(a, zout, len))
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 return 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 zout = a->zout;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 p = (Uint8 *) (zout - dist);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 if (dist == 1)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 { // run of one byte; common in images.
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 Uint8 v = *p;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 do { *zout++ = v; } while (--len);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 do { *zout++ = *p++; } while (--len);
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 static const Uint8 length_dezigzag[19] =
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 16, 17, 18, 0, 8, 7, 9,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 6 , 10, 5 , 11, 4, 12, 3,
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 13, 2 , 14, 1 , 15
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 };
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
352 static int dmZLibComputeHuffmanCodes(DMZLibContext * ctx)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 DMZHuffmanContext z_codelength;
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
355 Uint8 codeLengths[286 + 32 + 137]; //padding for maximum single op
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
356 Uint8 codeLengthSizes[19];
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
357 int i, n, ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
359 int hlit = dmZReceive(ctx, 5) + 257;
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
360 int hdist = dmZReceive(ctx, 5) + 1;
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
361 int hclen = dmZReceive(ctx, 4) + 4;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
363 memset(codeLengthSizes, 0, sizeof(codeLengthSizes));
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 for (i = 0; i < hclen; i++)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 {
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
367 codeLengthSizes[length_dezigzag[i]] = (Uint8) s;
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
368 int s = dmZReceive(ctx, 3);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
371 if ((ret = dmZLibBuildHuffmanTables(&z_codelength, codeLengthSizes, 19)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
372 return ret;
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
373
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 n = 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 while (n < hlit + hdist)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
377 int c;
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
378 if ((ret = dmZLibHuffmanDecode(ctx, &z_codelength, &c)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
379 return ret;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
380
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
381 DMSTBI_ASSERT(c >= 0 && c < 19);
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
382
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 if (c < 16)
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
384 codeLengths[n++] = (Uint8) c;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 if (c == 16)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 {
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
388 c = dmZReceive(ctx, 2) + 3;
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
389 memset(codeLengths + n, codeLengths[n - 1], c);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 n += c;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 if (c == 17)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 {
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
395 c = dmZReceive(ctx, 3) + 3;
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
396 memset(codeLengths + n, 0, c);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 n += c;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 {
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
401 c = dmZReceive(ctx, 7) + 11;
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
402 memset(codeLengths + n, 0, c);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 n += c;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 if (n != hlit + hdist)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
408 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
409 return dmError(DMERR_DATA_ERROR,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
410 "Bad huffman codelengths.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
411 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
413 if ((ret = dmZLibBuildHuffmanTables(&ctx->zlength, codeLengths, hlit)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
414 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
999
b3b8794c4915 Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 998
diff changeset
416 if ((ret = dmZLibBuildHuffmanTables(&ctx->zdistance, codeLengths + hlit, hdist)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
417 return ret;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
418
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
419 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422
990
76f3961a044b Fix one function name.
Matti Hamalainen <ccr@tnsp.org>
parents: 969
diff changeset
423 static int dmZLibParseUncompressedBlock(DMZLibContext * ctx)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 Uint8 header[4];
968
b522067e2beb Fix error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
426 int len, nlen, k, ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
997
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
428 // "Any bits of input up to the next byte boundary are ignored."
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
429 if (ctx->numBits & 7)
997
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
430 dmZReceive(ctx, ctx->numBits & 7);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 // drain the bit-packed data into header
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 k = 0;
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
434 while (ctx->numBits > 0)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 {
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
436 header[k++] = (Uint8) (ctx->codeBuffer & 255); // suppress MSVC run-time check
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
437 ctx->codeBuffer >>= 8;
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
438 ctx->numBits -= 8;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 }
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
440 DMSTBI_ASSERT(ctx->numBits == 0);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 // now fill header the normal way
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 while (k < 4)
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
444 header[k++] = dmZGet8(ctx);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
446 len = (header[1] << 8) | header[0];
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
447 nlen = (header[3] << 8) | header[2];
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 if (nlen != (len ^ 0xffff))
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
450 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
451 return dmError(DMERR_DATA_ERROR,
992
929e43afbdb1 Improve error message slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
452 "Compressed data corrupt %04x :: %04x [%04x].\n",
929e43afbdb1 Improve error message slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
453 nlen, len, len ^ 0xffff);
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
454 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
456 if (ctx->zbuffer + len > ctx->zbufferEnd)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
457 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
458 return dmError(DMERR_BOUNDS,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
459 "Read past buffer, probably corrupt compressed data.\n");
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
460 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461
968
b522067e2beb Fix error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
462 if (ctx->zout + len > ctx->zoutEnd &&
969
14b82bd5a408 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
463 (ret = dmZLibExpand(ctx, ctx->zout, len)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
464 {
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
465 return dmError(DMERR_DATA_ERROR,
997
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
466 "Could not expand output buffer: %d, %s\n",
968
b522067e2beb Fix error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 965
diff changeset
467 ret, dmErrorStr(ret));
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
468 }
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
965
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
470 memcpy(ctx->zout, ctx->zbuffer, len);
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
471 ctx->zbuffer += len;
df8d2ad98f7d Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
472 ctx->zout += len;
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
473
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
474 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
478 int dmZLibDecode(DMZLibContext * ctx)
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
480 int final, type, ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
482 ctx->numBits = 0;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
483 ctx->codeBuffer = 0;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 do
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 {
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
486 final = dmZReceive(ctx, 1);
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
487 type = dmZReceive(ctx, 2);
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 if (type == 0)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 {
990
76f3961a044b Fix one function name.
Matti Hamalainen <ccr@tnsp.org>
parents: 969
diff changeset
490 if ((ret = dmZLibParseUncompressedBlock(ctx)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
491 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 if (type == 3)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 return 0;
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 else
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 if (type == 1)
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 {
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 // use fixed code lengths
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
501 if ((ret = dmZLibBuildHuffmanTables(&ctx->zlength, dm_zdefault_length, 288)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
502 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
504 if ((ret = dmZLibBuildHuffmanTables(&ctx->zdistance, dm_zdefault_distance, 32)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
505 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 else
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
508 if ((ret = dmZLibComputeHuffmanCodes(ctx)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
509 return ret;
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
510
960
1832ac20edb2 Clean up dmzlib and use it in stb_image.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
511 if ((ret = dmZLibParseHuffmanBlock(ctx)) != DMERR_OK)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
512 return ret;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 }
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 while (!final);
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
516
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
517 return DMERR_OK;
949
6ed9465f3913 Initial import of separated zlib decoding routines lifted from
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 }
997
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
519
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
520
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
521 int dmZLibParseHeader(DMZLibContext * ctx, BOOL checkPNG)
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
522 {
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
523 // See http://tools.ietf.org/html/rfc1950
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
524 int cmf = dmZGet8(ctx); // Compression method and flags
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
525 int flags = dmZGet8(ctx); // Flags
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
526 int cmethod = (cmf & 15);
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
527 int cinfo = (cmf >> 4) & 15;
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
528 ctx->window = 1 << (8 + cinfo); // Window size (not used at the moment)
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
529
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
530 // "The FCHECK value must be such that CMF and FLG, when viewed as
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
531 // a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
532 // is a multiple of 31."
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
533 if ((cmf * 256 + flags) % 31 != 0)
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
534 {
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
535 return dmError(DMERR_INVALID_DATA,
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
536 "Bad zlib header.");
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
537 }
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
538
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
539 // We only support compression method 8
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
540 if (cmethod != 8)
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
541 {
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
542 return dmError(DMERR_INVALID_DATA,
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
543 "Bad or unsupported zlib compression method %d.\n",
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
544 cmethod);
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
545 }
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
546
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
547 if (checkPNG && (flags & 32))
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
548 {
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
549 // preset dictionary not allowed in png
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
550 return dmError(DMERR_NOT_SUPPORTED,
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
551 "Preset dictionary not allowed in PNG.\n");
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
552 }
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
553 return DMERR_OK;
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
554 }
cd0e0270e1ce Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 992
diff changeset
555