author | Claus Gittinger <cg@exept.de> |
Mon, 04 Apr 2011 14:17:34 +0200 | |
changeset 5737 | f39cc6dc9848 |
parent 5567 | 7a7a10a2e29c |
child 5927 | eebe3a485637 |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
77 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
3260 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
0 | 14 |
Object subclass:#ImageReader |
518 | 15 |
instanceVariableNames:'width height data byteOrder inStream outStream photometric |
1648
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
16 |
samplesPerPixel bitsPerSample colorMap mask maskPixel |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
17 |
dimensionCallBack dimensionHolder progressHolder imageSequence' |
518 | 18 |
classVariableNames:'ReverseBits' |
19 |
poolDictionaries:'' |
|
3843
57d7f752c63b
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
3839
diff
changeset
|
20 |
category:'Graphics-Images-Readers' |
0 | 21 |
! |
22 |
||
189 | 23 |
!ImageReader primitiveDefinitions! |
24 |
%{ |
|
1891 | 25 |
|
189 | 26 |
#ifndef _STDIO_H_INCLUDED_ |
27 |
# include <stdio.h> |
|
28 |
# define _STDIO_H_INCLUDED_ |
|
29 |
#endif |
|
4401 | 30 |
#ifndef _MALLOC_H_INCLUDED_ |
5527 | 31 |
# ifndef FREEBSD |
32 |
# include <malloc.h> |
|
33 |
# endif |
|
4401 | 34 |
# define _MALLOC_H_INCLUDED_ |
35 |
#endif |
|
2423
416882dbf8cf
changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
36 |
|
416882dbf8cf
changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
37 |
|
189 | 38 |
%} |
39 |
! ! |
|
40 |
||
89 | 41 |
!ImageReader primitiveFunctions! |
0 | 42 |
%{ |
43 |
||
44 |
/* |
|
45 |
* ccitt decompression |
|
46 |
*/ |
|
47 |
static short *whiteCountTable; |
|
48 |
static char *whiteShiftTable; |
|
49 |
static short *blackCountTable; |
|
50 |
static char *blackShiftTable; |
|
51 |
||
52 |
struct ccitt_def { |
|
53 |
unsigned short bits; |
|
54 |
short nBits; |
|
55 |
}; |
|
56 |
||
4714 | 57 |
static struct ccitt_def |
0 | 58 |
whiteDef[] = { |
59 |
{ 0x3500, 8 }, /* 0 */ |
|
60 |
{ 0x1c00, 6 }, |
|
61 |
{ 0x7000, 4 }, |
|
62 |
{ 0x8000, 4 }, |
|
63 |
{ 0xb000, 4 }, |
|
64 |
{ 0xc000, 4 }, |
|
65 |
{ 0xe000, 4 }, |
|
66 |
{ 0xf000, 4 }, |
|
67 |
{ 0x9800, 5 }, |
|
68 |
{ 0xA000, 5 }, |
|
69 |
{ 0x3800, 5 }, /* 10 */ |
|
70 |
{ 0x4000, 5 }, |
|
71 |
{ 0x2000, 6 }, |
|
72 |
{ 0x0c00, 6 }, |
|
73 |
{ 0xd000, 6 }, |
|
74 |
{ 0xd400, 6 }, |
|
75 |
{ 0xa800, 6 }, |
|
76 |
{ 0xac00, 6 }, |
|
77 |
{ 0x4e00, 7 }, |
|
78 |
{ 0x1800, 7 }, |
|
79 |
{ 0x1000, 7 }, /* 20 */ |
|
80 |
{ 0x2e00, 7 }, |
|
81 |
{ 0x0600, 7 }, |
|
82 |
{ 0x0800, 7 }, |
|
83 |
{ 0x5000, 7 }, |
|
84 |
{ 0x5600, 7 }, |
|
85 |
{ 0x2600, 7 }, |
|
86 |
{ 0x4800, 7 }, |
|
87 |
{ 0x3000, 7 }, |
|
88 |
{ 0x0200, 8 }, |
|
4714 | 89 |
{ 0x0300, 8 }, /* 30 */ |
90 |
{ 0x1a00, 8 }, |
|
91 |
{ 0x1b00, 8 }, |
|
92 |
{ 0x1200, 8 }, |
|
93 |
{ 0x1300, 8 }, |
|
94 |
{ 0x1400, 8 }, |
|
95 |
{ 0x1500, 8 }, |
|
96 |
{ 0x1600, 8 }, |
|
97 |
{ 0x1700, 8 }, |
|
98 |
{ 0x2800, 8 }, |
|
0 | 99 |
{ 0x2900, 8 }, /* 40 */ |
4714 | 100 |
{ 0x2a00, 8 }, |
101 |
{ 0x2b00, 8 }, |
|
102 |
{ 0x2c00, 8 }, |
|
103 |
{ 0x2d00, 8 }, |
|
104 |
{ 0x0400, 8 }, |
|
105 |
{ 0x0500, 8 }, |
|
106 |
{ 0x0a00, 8 }, |
|
107 |
{ 0x0b00, 8 }, |
|
108 |
{ 0x5200, 8 }, |
|
0 | 109 |
{ 0x5300, 8 }, /* 50 */ |
4714 | 110 |
{ 0x5400, 8 }, |
111 |
{ 0x5500, 8 }, |
|
112 |
{ 0x2400, 8 }, |
|
113 |
{ 0x2500, 8 }, |
|
114 |
{ 0x5800, 8 }, |
|
115 |
{ 0x5900, 8 }, |
|
116 |
{ 0x5a00, 8 }, |
|
117 |
{ 0x5b00, 8 }, |
|
118 |
{ 0x4a00, 8 }, |
|
0 | 119 |
{ 0x4b00, 8 }, /* 60 */ |
4714 | 120 |
{ 0x3200, 8 }, |
121 |
{ 0x3300, 8 }, |
|
122 |
{ 0x3400, 8 }, |
|
0 | 123 |
/* ---------------- */ |
124 |
{ 0xd800, 5 }, /* 64 */ |
|
125 |
{ 0x9000, 5 }, /* 128 */ |
|
126 |
{ 0x5c00, 6 }, /* 192 */ |
|
127 |
{ 0x6e00, 7 }, /* 256 */ |
|
128 |
{ 0x3600, 8 }, /* 320 */ |
|
129 |
{ 0x3700, 8 }, |
|
130 |
{ 0x6400, 8 }, |
|
131 |
{ 0x6500, 8 }, |
|
132 |
{ 0x6800, 8 }, |
|
133 |
{ 0x6700, 8 }, /* 640 */ |
|
134 |
{ 0x6600, 9 }, /* 704 */ |
|
135 |
{ 0x6680, 9 }, |
|
136 |
{ 0x6900, 9 }, |
|
137 |
{ 0x6980, 9 }, |
|
138 |
{ 0x6a00, 9 }, |
|
139 |
{ 0x6a80, 9 }, |
|
140 |
{ 0x6b00, 9 }, |
|
141 |
{ 0x6b80, 9 }, |
|
142 |
{ 0x6c00, 9 }, |
|
143 |
{ 0x6c80, 9 }, |
|
144 |
{ 0x6d00, 9 }, |
|
145 |
{ 0x6d80, 9 }, |
|
146 |
{ 0x4c00, 9 }, |
|
147 |
{ 0x4c80, 9 }, |
|
148 |
{ 0x4d00, 9 }, /* 1600 */ |
|
149 |
{ 0x6000, 6 }, /* 1664 */ |
|
150 |
{ 0x4d80, 9 }, /* 1728 */ |
|
151 |
/* -------------------------------- */ |
|
152 |
{ 0x0100, 11 }, /* 1792 */ |
|
153 |
{ 0x0180, 11 }, |
|
154 |
{ 0x01a0, 11 }, /* 1920 */ |
|
155 |
{ 0x0120, 12 }, /* 1984 */ |
|
156 |
{ 0x0130, 12 }, |
|
157 |
{ 0x0140, 12 }, |
|
158 |
{ 0x0150, 12 }, |
|
159 |
{ 0x0160, 12 }, |
|
160 |
{ 0x0170, 12 }, |
|
161 |
{ 0x01c0, 12 }, |
|
162 |
{ 0x01d0, 12 }, |
|
163 |
{ 0x01e0, 12 }, |
|
164 |
{ 0x01f0, 12 }, /* 2560 */ |
|
165 |
/* -------------------------------- */ |
|
166 |
{ 0x0010, 12 }, /* EOL */ |
|
167 |
}; |
|
168 |
||
4714 | 169 |
static struct ccitt_def |
0 | 170 |
blackDef[] = { |
171 |
{ 0x0dc0, 10 }, /* 0 */ |
|
172 |
{ 0x4000, 3 }, |
|
173 |
{ 0xc000, 2 }, |
|
174 |
{ 0x8000, 2 }, |
|
175 |
{ 0x6000, 3 }, |
|
176 |
{ 0x3000, 4 }, |
|
177 |
{ 0x2000, 4 }, |
|
178 |
{ 0x1800, 5 }, |
|
179 |
{ 0x1400, 6 }, |
|
180 |
{ 0x1000, 6 }, |
|
181 |
{ 0x0800, 7 }, /* 10 */ |
|
182 |
{ 0x0a00, 7 }, |
|
183 |
{ 0x0e00, 7 }, |
|
184 |
{ 0x0400, 8 }, |
|
185 |
{ 0x0700, 8 }, |
|
186 |
{ 0x0c00, 9 }, |
|
187 |
{ 0x05c0, 10 }, |
|
188 |
{ 0x0600, 10 }, |
|
189 |
{ 0x0200, 10 }, |
|
190 |
{ 0x0ce0, 11 }, |
|
191 |
{ 0x0d00, 11 }, /* 20 */ |
|
192 |
{ 0x0d80, 11 }, |
|
193 |
{ 0x06e0, 11 }, |
|
194 |
{ 0x0500, 11 }, |
|
195 |
{ 0x02e0, 11 }, |
|
196 |
{ 0x0300, 11 }, |
|
197 |
{ 0x0ca0, 12 }, |
|
198 |
{ 0x0cb0, 12 }, |
|
199 |
{ 0x0cc0, 12 }, |
|
4714 | 200 |
{ 0x0cd0, 12 }, |
0 | 201 |
{ 0x0680, 12 }, /* 30 */ |
4714 | 202 |
{ 0x0690, 12 }, |
203 |
{ 0x06a0, 12 }, |
|
204 |
{ 0x06b0, 12 }, |
|
205 |
{ 0x0d20, 12 }, |
|
206 |
{ 0x0d30, 12 }, |
|
207 |
{ 0x0d40, 12 }, |
|
208 |
{ 0x0d50, 12 }, |
|
209 |
{ 0x0d60, 12 }, |
|
0 | 210 |
{ 0x0d70, 12 }, |
4714 | 211 |
{ 0x06c0, 12 }, /* 40 */ |
212 |
{ 0x06d0, 12 }, |
|
213 |
{ 0x0da0, 12 }, |
|
214 |
{ 0x0db0, 12 }, |
|
215 |
{ 0x0540, 12 }, |
|
216 |
{ 0x0550, 12 }, |
|
217 |
{ 0x0560, 12 }, |
|
218 |
{ 0x0570, 12 }, |
|
219 |
{ 0x0640, 12 }, |
|
0 | 220 |
{ 0x0650, 12 }, |
4714 | 221 |
{ 0x0520, 12 }, /* 50 */ |
222 |
{ 0x0530, 12 }, |
|
223 |
{ 0x0240, 12 }, |
|
224 |
{ 0x0370, 12 }, |
|
225 |
{ 0x0380, 12 }, |
|
226 |
{ 0x0270, 12 }, |
|
227 |
{ 0x0280, 12 }, |
|
228 |
{ 0x0580, 12 }, |
|
229 |
{ 0x0590, 12 }, |
|
0 | 230 |
{ 0x02b0, 12 }, |
4714 | 231 |
{ 0x02c0, 12 }, /* 60 */ |
232 |
{ 0x05a0, 12 }, |
|
233 |
{ 0x0660, 12 }, |
|
234 |
{ 0x0670, 12 }, |
|
0 | 235 |
/* ---------------- */ |
236 |
{ 0x03c0, 10 }, /* 64 */ |
|
237 |
{ 0x0c80, 12 }, /* 128 */ |
|
238 |
{ 0x0c90, 12 }, /* 192 */ |
|
239 |
{ 0x05b0, 12 }, /* 256 */ |
|
240 |
{ 0x0330, 12 }, /* 320 */ |
|
241 |
{ 0x0340, 12 }, |
|
242 |
{ 0x0350, 12 }, /* 448 */ |
|
243 |
{ 0x0360, 13 }, /* 512 */ |
|
244 |
{ 0x0368, 13 }, |
|
245 |
{ 0x0250, 13 }, /* 640 */ |
|
246 |
{ 0x0258, 13 }, /* 704 */ |
|
247 |
{ 0x0260, 13 }, |
|
248 |
{ 0x0268, 13 }, |
|
249 |
{ 0x0390, 13 }, |
|
250 |
{ 0x0398, 13 }, |
|
251 |
{ 0x03a0, 13 }, |
|
252 |
{ 0x03a8, 13 }, |
|
253 |
{ 0x03b0, 13 }, |
|
254 |
{ 0x03b8, 13 }, |
|
255 |
{ 0x0290, 13 }, |
|
256 |
{ 0x0298, 13 }, |
|
257 |
{ 0x02a0, 13 }, |
|
258 |
{ 0x02a8, 13 }, |
|
259 |
{ 0x02d0, 13 }, |
|
260 |
{ 0x02d8, 13 }, /* 1600 */ |
|
261 |
{ 0x0320, 13 }, /* 1664 */ |
|
262 |
{ 0x0328, 13 }, /* 1728 */ |
|
263 |
/* -------------------------------- */ |
|
264 |
}; |
|
265 |
||
266 |
static |
|
267 |
initCCITTTables() { |
|
268 |
register cnt, bits, value; |
|
269 |
int nBits, index; |
|
270 |
||
271 |
if (whiteCountTable != (short *)0) return; |
|
272 |
||
273 |
whiteCountTable = (short *) malloc(sizeof(short) * 8192); |
|
12 | 274 |
if (! whiteCountTable) return; |
0 | 275 |
whiteShiftTable = (char *) malloc(sizeof(char) * 8192); |
12 | 276 |
if (! whiteShiftTable) { |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
277 |
goto fail1; |
12 | 278 |
} |
0 | 279 |
blackCountTable = (short *) malloc(sizeof(short) * 8192); |
12 | 280 |
if (! blackCountTable) { |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
281 |
goto fail2; |
12 | 282 |
} |
0 | 283 |
blackShiftTable = (char *) malloc(sizeof(char) * 8192); |
12 | 284 |
if (! blackShiftTable) { |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
285 |
free(blackCountTable); blackCountTable = (short *)0; |
95 | 286 |
fail2: |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
287 |
free(whiteShiftTable); whiteShiftTable = (char *)0; |
95 | 288 |
fail1: |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
289 |
free(whiteCountTable); whiteCountTable = (short *)0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
290 |
return; |
12 | 291 |
} |
0 | 292 |
|
293 |
for (index = 0; index < 8192; index++) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
294 |
whiteCountTable[index] = -1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
295 |
blackCountTable[index] = -1; |
0 | 296 |
} |
297 |
||
298 |
for (value = 0; value <= 63; value++) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
299 |
nBits = whiteDef[value].nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
300 |
bits = whiteDef[value].bits >> 3; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
301 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
302 |
whiteCountTable[bits] = value; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
303 |
whiteShiftTable[bits] = nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
304 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
305 |
nBits = blackDef[value].nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
306 |
bits = blackDef[value].bits >> 3; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
307 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
308 |
blackCountTable[bits] = value; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
309 |
blackShiftTable[bits] = nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
310 |
} |
0 | 311 |
} |
312 |
index = value; |
|
313 |
||
314 |
for (; value <= 1728; value += 64) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
315 |
nBits = whiteDef[index].nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
316 |
bits = whiteDef[index].bits >> 3; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
317 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
318 |
whiteCountTable[bits] = value; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
319 |
whiteShiftTable[bits] = nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
320 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
321 |
nBits = blackDef[index].nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
322 |
bits = blackDef[index].bits >> 3; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
323 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
324 |
blackCountTable[bits] = value; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
325 |
blackShiftTable[bits] = nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
326 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
327 |
index++; |
0 | 328 |
} |
329 |
||
330 |
for (; value <= 2560; value += 64) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
331 |
nBits = whiteDef[index].nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
332 |
bits = whiteDef[index].bits >> 3; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
333 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
334 |
whiteCountTable[bits] = value; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
335 |
whiteShiftTable[bits] = nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
336 |
blackCountTable[bits] = value; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
337 |
blackShiftTable[bits] = nBits; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
338 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
339 |
index++; |
0 | 340 |
} |
341 |
} |
|
342 |
||
4714 | 343 |
static short |
0 | 344 |
leftBits[] = { |
345 |
0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF |
|
346 |
}; |
|
347 |
||
189 | 348 |
static int |
77 | 349 |
__decodeCCITTgroup3__(from, to, len) |
0 | 350 |
unsigned char *from; |
351 |
register unsigned char *to; |
|
352 |
{ |
|
353 |
register cnt; |
|
354 |
register short *countPtr; |
|
355 |
register char *shiftPtr; |
|
356 |
unsigned bits, bits13; |
|
357 |
int shift, outCount, nBitsLess13; |
|
358 |
int outBitOffset; |
|
359 |
int nLeft, t; |
|
360 |
||
361 |
if (! whiteCountTable) initCCITTTables(); |
|
46 | 362 |
if (! whiteCountTable) return 0; /* malloc failed */ |
0 | 363 |
|
364 |
countPtr = whiteCountTable; |
|
365 |
shiftPtr = whiteShiftTable; |
|
366 |
outCount = 0; |
|
367 |
outBitOffset = 0; |
|
368 |
bits = *from++; |
|
369 |
bits = (bits << 8) | *from++; |
|
370 |
nBitsLess13 = 3; |
|
371 |
for (;;) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
372 |
bits13 = (bits >> nBitsLess13) & 0x1FFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
373 |
cnt = countPtr[bits13]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
374 |
if (cnt < 0) return 1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
375 |
shift = shiftPtr[bits13]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
376 |
outCount += cnt; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
377 |
if (countPtr == blackCountTable) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
378 |
/* toggle if it was a terminating code */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
379 |
if (cnt < 64) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
380 |
countPtr = whiteCountTable; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
381 |
shiftPtr = whiteShiftTable; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
382 |
} |
0 | 383 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
384 |
/* draw cnt black bits */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
385 |
if (cnt) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
386 |
if (outBitOffset) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
387 |
nLeft = 8 - outBitOffset; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
388 |
if (cnt < nLeft) nLeft = cnt; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
389 |
t = leftBits[nLeft] >> outBitOffset; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
390 |
*to |= t; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
391 |
cnt -= nLeft; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
392 |
outBitOffset += nLeft; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
393 |
if (outBitOffset >= 8) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
394 |
to++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
395 |
outBitOffset -= 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
396 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
397 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
398 |
if (cnt > 256) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
399 |
while ((INT)to & 3) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
400 |
*to++ = 0xFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
401 |
cnt -= 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
402 |
} |
4401 | 403 |
#if __POINTER_SIZE__ == 8 |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
404 |
while ((INT)to & 7) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
405 |
*to++ = 0xFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
406 |
cnt -= 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
407 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
408 |
while (cnt >= 64) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
409 |
(*(INT *)to) = 0xFFFFFFFFFFFFFFFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
410 |
to += 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
411 |
cnt -= 64; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
412 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
413 |
if (cnt >= 32) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
414 |
(*(long *)to) = 0xFFFFFFFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
415 |
to += 4; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
416 |
cnt -= 32; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
417 |
} |
4401 | 418 |
#else |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
419 |
while ((INT)to & 3) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
420 |
*to++ = 0xFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
421 |
cnt -= 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
422 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
423 |
while (cnt >= 32) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
424 |
(*(long *)to) = 0xFFFFFFFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
425 |
to += 4; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
426 |
cnt -= 32; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
427 |
} |
4401 | 428 |
#endif |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
429 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
430 |
while (cnt >= 8) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
431 |
*to++ = 0xFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
432 |
cnt -= 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
433 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
434 |
*to |= leftBits[cnt]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
435 |
outBitOffset += cnt; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
436 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
437 |
} else { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
438 |
/* toggle if it was a terminating code */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
439 |
if (cnt < 64) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
440 |
countPtr = blackCountTable; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
441 |
shiftPtr = blackShiftTable; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
442 |
} |
0 | 443 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
444 |
/* skip cnt bits */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
445 |
to += cnt >> 3; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
446 |
outBitOffset += cnt & 7; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
447 |
if (outBitOffset >= 8) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
448 |
to++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
449 |
outBitOffset -= 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
450 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
451 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
452 |
if (outCount >= len) return 1; |
0 | 453 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
454 |
nBitsLess13 -= shift; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
455 |
while (nBitsLess13 < 0) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
456 |
bits = (bits << 8) | *from++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
457 |
nBitsLess13 += 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
458 |
} |
0 | 459 |
} |
460 |
} |
|
461 |
||
462 |
/* |
|
463 |
* LZW decompression |
|
464 |
*/ |
|
465 |
struct buffer { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
466 |
struct buffer *prev; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
467 |
unsigned char chars[8192 - 4]; |
0 | 468 |
}; |
189 | 469 |
|
4714 | 470 |
static int |
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
471 |
__decodeLZW__(from, to, inCount, fromSize, toSize) |
0 | 472 |
unsigned char *from; |
473 |
unsigned char *to; |
|
474 |
{ |
|
475 |
register unsigned code; |
|
12 | 476 |
unsigned char **strings; |
477 |
short *stringLen; |
|
0 | 478 |
struct buffer *scratchBuffer; |
479 |
struct buffer *newBuffer; |
|
480 |
unsigned char *scratchPtr; |
|
481 |
int nScratch; |
|
1262 | 482 |
unsigned nextCode; |
483 |
int oldCode = -1; |
|
0 | 484 |
register unsigned bits; |
485 |
int nBits, mask, shift; |
|
486 |
int i; |
|
487 |
int len; |
|
488 |
int codeLen = 9; |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
489 |
unsigned char *fromEnd, *toEnd; |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
490 |
int ret = 1; /* return success */ |
0 | 491 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
492 |
fromEnd = from + fromSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
493 |
toEnd = to + toSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
494 |
|
0 | 495 |
scratchBuffer = (struct buffer *)malloc(sizeof(struct buffer)); |
12 | 496 |
if (! scratchBuffer) return 0; |
46 | 497 |
|
12 | 498 |
strings = (unsigned char **)malloc(sizeof(unsigned char *) * 4096); |
499 |
if (! strings) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
500 |
free(scratchBuffer); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
501 |
return 0; |
12 | 502 |
} |
503 |
stringLen = (short *)malloc(sizeof(short) * 4096); |
|
504 |
if (! stringLen) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
505 |
free(strings); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
506 |
free(scratchBuffer); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
507 |
return 0; |
12 | 508 |
} |
509 |
||
0 | 510 |
scratchBuffer->prev = (struct buffer *)0; |
511 |
scratchPtr = scratchBuffer->chars; |
|
512 |
nScratch = sizeof(scratchBuffer->chars); |
|
513 |
||
514 |
for (i = 0; i < 256; i++) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
515 |
*scratchPtr = i; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
516 |
strings[i] = scratchPtr++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
517 |
stringLen[i] = 1; |
0 | 518 |
} |
519 |
||
520 |
nextCode = 258; |
|
521 |
nScratch -= 256; |
|
522 |
mask = 0x1FF; |
|
523 |
nBits = 0; |
|
524 |
bits = 0; |
|
525 |
while (inCount) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
526 |
/* fetch code */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
527 |
while (nBits < codeLen) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
528 |
bits = (bits<<8) | *from++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
529 |
inCount--; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
530 |
nBits += 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
531 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
532 |
shift = nBits - codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
533 |
code = (bits >> shift) & mask; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
534 |
bits &= ~(mask << shift); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
535 |
nBits -= codeLen; |
4714 | 536 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
537 |
if (code == 257) break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
538 |
if (code == 256) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
539 |
if (! inCount) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
540 |
break; |
0 | 541 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
542 |
/* free stuff */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
543 |
while (scratchBuffer->prev) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
544 |
newBuffer = scratchBuffer; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
545 |
scratchBuffer = scratchBuffer->prev; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
546 |
free(newBuffer); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
547 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
548 |
/* reset everything */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
549 |
scratchPtr = scratchBuffer->chars + 256; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
550 |
nScratch = sizeof(scratchBuffer->chars) - 256; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
551 |
codeLen = 9; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
552 |
nextCode = 258; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
553 |
mask = 0x1FF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
554 |
/* fetch code */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
555 |
while (nBits < codeLen) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
556 |
bits = (bits<<8) | *from++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
557 |
inCount--; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
558 |
nBits += 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
559 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
560 |
shift = nBits - codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
561 |
code = (bits >> shift) & mask; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
562 |
bits &= ~(mask << shift); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
563 |
nBits -= codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
564 |
if (code == 257) break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
565 |
/* add to output */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
566 |
if (to >= toEnd) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
567 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
568 |
console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
569 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
570 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
571 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
572 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
573 |
*to++ = code; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
574 |
oldCode = code; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
575 |
} else { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
576 |
if (code < nextCode) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
577 |
/* writeString(string[code]) */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
578 |
len = stringLen[code]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
579 |
bcopy(strings[code], to, len); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
580 |
to += len; |
0 | 581 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
582 |
if (oldCode != -1) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
583 |
/* add( string[oldcode] + first(string[code]) ) */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
584 |
len = stringLen[oldCode] + 1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
585 |
if (nScratch < len) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
586 |
newBuffer = (struct buffer *)malloc(sizeof(struct buffer)); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
587 |
if (! newBuffer) goto out; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
588 |
newBuffer->prev = scratchBuffer; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
589 |
scratchBuffer = newBuffer; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
590 |
scratchPtr = scratchBuffer->chars; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
591 |
nScratch = sizeof(scratchBuffer->chars); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
592 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
593 |
stringLen[nextCode] = len; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
594 |
strings[nextCode] = scratchPtr; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
595 |
bcopy(strings[oldCode], scratchPtr, len-1); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
596 |
scratchPtr += len-1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
597 |
*scratchPtr++ = strings[code][0]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
598 |
nScratch -= len; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
599 |
nextCode++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
600 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
601 |
} else { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
602 |
if (oldCode == -1) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
603 |
/* bad input */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
604 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
605 |
goto out; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
606 |
} |
4714 | 607 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
608 |
/* writeString(string[oldCode] + first(string[oldCode]) ) */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
609 |
len = stringLen[oldCode]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
610 |
if ((to+len) >= toEnd) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
611 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
612 |
console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
613 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
614 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
615 |
goto out; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
616 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
617 |
bcopy(strings[oldCode], to, len); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
618 |
to += len; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
619 |
*to++ = strings[oldCode][0]; |
0 | 620 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
621 |
/* add( string[oldcode] + first(string[oldCode]) ) */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
622 |
len++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
623 |
if (nScratch < len) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
624 |
newBuffer = (struct buffer *)malloc(sizeof(struct buffer)); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
625 |
if (! newBuffer) goto out; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
626 |
newBuffer->prev = scratchBuffer; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
627 |
scratchBuffer = newBuffer; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
628 |
scratchPtr = scratchBuffer->chars; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
629 |
nScratch = sizeof(scratchBuffer->chars); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
630 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
631 |
stringLen[nextCode] = len; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
632 |
strings[nextCode] = scratchPtr; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
633 |
bcopy(strings[oldCode], scratchPtr, len-1); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
634 |
scratchPtr += len-1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
635 |
*scratchPtr++ = strings[oldCode][0]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
636 |
nScratch -= len; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
637 |
nextCode++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
638 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
639 |
oldCode = code; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
640 |
if (nextCode >= 511) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
641 |
if (nextCode == 511) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
642 |
codeLen = 10; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
643 |
mask = 0x3FF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
644 |
} else if (nextCode >= 1023) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
645 |
if (nextCode == 1023) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
646 |
codeLen = 11; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
647 |
mask = 0x7FF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
648 |
} else |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
649 |
if (nextCode == 2047) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
650 |
codeLen = 12; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
651 |
mask = 0xFFF; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
652 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
653 |
} |
0 | 654 |
} |
12 | 655 |
out: ; |
0 | 656 |
/* free stuff */ |
657 |
while (scratchBuffer) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
658 |
newBuffer = scratchBuffer; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
659 |
scratchBuffer = scratchBuffer->prev; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
660 |
free(newBuffer); |
0 | 661 |
} |
46 | 662 |
|
12 | 663 |
free(strings); |
664 |
free(stringLen); |
|
46 | 665 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
666 |
if (from > fromEnd) { |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
667 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
668 |
console_fprintf(stderr, "ImageReader [warning]: LZW inBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
669 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
670 |
ret = 0; |
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
671 |
} |
1262 | 672 |
return ret; |
0 | 673 |
} |
674 |
||
675 |
/* |
|
676 |
* delta decoding (TIFF predictor = 2) |
|
677 |
*/ |
|
189 | 678 |
static |
77 | 679 |
__decodeDelta__(bytes, width, height) |
0 | 680 |
register unsigned char *bytes; |
681 |
{ |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
682 |
register w; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
683 |
unsigned char r, g, b; |
0 | 684 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
685 |
while (height--) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
686 |
r = g = b = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
687 |
for (w = width; w; w--) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
688 |
r += *bytes; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
689 |
*bytes++ = r; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
690 |
g += *bytes; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
691 |
*bytes++ = g; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
692 |
b += *bytes; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
693 |
*bytes++ = b; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
694 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
695 |
} |
0 | 696 |
} |
697 |
||
46 | 698 |
/* |
699 |
* GIF decompression |
|
700 |
*/ |
|
189 | 701 |
static int |
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
702 |
__decodeGIF__(from, to, inCount, initialCodeLen, fromSize, toSize) |
0 | 703 |
unsigned char *from; |
704 |
unsigned char *to; |
|
705 |
{ |
|
706 |
register unsigned code; |
|
12 | 707 |
unsigned short *prefix; |
708 |
unsigned short *suffix; |
|
709 |
unsigned short *outCode; |
|
0 | 710 |
int outCount; |
711 |
unsigned maxCode, oldCode, fin, inCode, curCode; |
|
712 |
register unsigned bits; |
|
713 |
register int nBits, mask, shift; |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
714 |
int ret = 1; |
0 | 715 |
int i; |
716 |
int len; |
|
717 |
int endCode, clearCode, freeCode; |
|
718 |
int codeLen = initialCodeLen; |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
719 |
unsigned char *fromEnd, *toEnd; |
12 | 720 |
static int ranges[] = {0, 1, 2, 4, 8, 16, 32, 64, |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
721 |
128, 256, 512, 1024, 2048 }; |
0 | 722 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
723 |
fromEnd = from + fromSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
724 |
toEnd = to + toSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
725 |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
726 |
if ((unsigned)codeLen > 12) { |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
727 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
728 |
console_fprintf(stderr, "ImageReader [warning]: GIF bad codelen (>12)\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
729 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
730 |
return 0; |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
731 |
} |
12 | 732 |
prefix = (unsigned short *)malloc(sizeof(short) * 4096); |
733 |
if (! prefix) return 0; |
|
734 |
suffix = (unsigned short *)malloc(sizeof(short) * 4096); |
|
735 |
if (! suffix) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
736 |
free(prefix); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
737 |
return 0; |
12 | 738 |
} |
739 |
outCode = (unsigned short *)malloc(sizeof(short) * 4096); |
|
740 |
if (! outCode) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
741 |
free(prefix); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
742 |
free(suffix); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
743 |
return 0; |
12 | 744 |
} |
0 | 745 |
clearCode = ranges[codeLen]; /* 256 */ |
746 |
endCode = clearCode + 1; /* 257 */ |
|
747 |
freeCode = clearCode + 2; /* 258 */ |
|
748 |
maxCode = clearCode << 1; /* 512 */ |
|
749 |
outCount = 0; |
|
750 |
||
751 |
mask = maxCode - 1; /* 1FF */ |
|
752 |
nBits = 0; |
|
753 |
bits = 0; |
|
754 |
while (inCount) { |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
755 |
/* fetch code */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
756 |
while (nBits < codeLen) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
757 |
bits = bits | (*from++ << nBits); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
758 |
inCount--; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
759 |
nBits += 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
760 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
761 |
if (inCount <= 0) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
762 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
763 |
code = bits & mask; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
764 |
bits >>= codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
765 |
nBits -= codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
766 |
if (code == endCode) break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
767 |
if (code == clearCode) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
768 |
if (inCount <= 0) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
769 |
break; |
0 | 770 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
771 |
codeLen = initialCodeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
772 |
maxCode = clearCode<<1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
773 |
mask = maxCode - 1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
774 |
freeCode = clearCode + 2; |
0 | 775 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
776 |
/* fetch code */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
777 |
while (nBits < codeLen) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
778 |
bits = bits | (*from++ << nBits); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
779 |
inCount--; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
780 |
nBits += 8; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
781 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
782 |
if (inCount <= 0) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
783 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
784 |
code = bits & mask; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
785 |
bits >>= codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
786 |
nBits -= codeLen; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
787 |
if (code == endCode) break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
788 |
/* add to output */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
789 |
if (to >= toEnd) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
790 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
791 |
console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
792 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
793 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
794 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
795 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
796 |
*to++ = code; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
797 |
oldCode = fin = curCode = code; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
798 |
} else { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
799 |
curCode = inCode = code; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
800 |
if (curCode >= freeCode) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
801 |
curCode = oldCode; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
802 |
outCode[outCount++] = fin; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
803 |
} |
0 | 804 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
805 |
while (curCode >= clearCode) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
806 |
if (outCount > 1024) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
807 |
goto out; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
808 |
} |
2261 | 809 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
810 |
/* debugging and protecting myself from overwrites */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
811 |
if (curCode >= 4096) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
812 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
813 |
console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > 4095)\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
814 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
815 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
816 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
817 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
818 |
outCode[outCount++] = suffix[curCode]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
819 |
curCode = prefix[curCode]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
820 |
} |
0 | 821 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
822 |
fin = curCode; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
823 |
outCode[outCount++] = fin; |
0 | 824 |
|
2014
bcae1c2c32e4
fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
825 |
#if 0 |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
826 |
if ((to+outCount) >= toEnd) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
827 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
828 |
console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
829 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
830 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
831 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
832 |
} |
2014
bcae1c2c32e4
fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
833 |
#endif |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
834 |
for (i = outCount - 1; i >= 0; i--) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
835 |
if (to >= toEnd) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
836 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
837 |
console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
838 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
839 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
840 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
841 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
842 |
*to++ = outCode[i]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
843 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
844 |
outCount = 0; |
0 | 845 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
846 |
/* debugging and protecting myself from overwrites */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
847 |
if (freeCode >= 4096) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
848 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
849 |
console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > 4095)\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
850 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
851 |
ret = 0; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
852 |
break; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
853 |
} |
2261 | 854 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
855 |
prefix[freeCode] = oldCode; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
856 |
suffix[freeCode] = fin; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
857 |
oldCode = inCode; |
0 | 858 |
|
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
859 |
freeCode++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
860 |
if (freeCode >= maxCode) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
861 |
if (codeLen < 12) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
862 |
codeLen++; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
863 |
maxCode *= 2; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
864 |
mask = (1 << codeLen) - 1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
865 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
866 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
867 |
} |
0 | 868 |
} |
12 | 869 |
out: ; |
870 |
free(prefix); |
|
871 |
free(suffix); |
|
872 |
free(outCode); |
|
46 | 873 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
874 |
if (from > fromEnd) { |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
875 |
if (@global(InfoPrinting) == true) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
876 |
console_fprintf(stderr, "ImageReader [warning]: GIF inBuffer overrun\n"); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
877 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
878 |
ret = 0; |
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
879 |
} |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
880 |
return ret; |
0 | 881 |
} |
882 |
||
883 |
%} |
|
77 | 884 |
! ! |
105 | 885 |
|
1167 | 886 |
!ImageReader class methodsFor:'documentation'! |
105 | 887 |
|
888 |
copyright |
|
889 |
" |
|
890 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
891 |
All Rights Reserved |
|
892 |
||
893 |
This software is furnished under a license and may be used |
|
894 |
only in accordance with the terms of that license and with the |
|
895 |
inclusion of the above copyright notice. This software may not |
|
896 |
be provided or otherwise made available to, or used by, any |
|
897 |
other person. No title to or ownership of the software is |
|
898 |
hereby transferred. |
|
899 |
" |
|
900 |
! |
|
901 |
||
902 |
documentation |
|
903 |
" |
|
4714 | 904 |
Abstract class to provide common functions for image-readers |
105 | 905 |
(i.e. TIFFReader, GIFReader etc.) |
906 |
||
907 |
ImageReaders are created temporary to read an image from a stream. |
|
618 | 908 |
Normally, they are not directly used - instead, the image class is |
909 |
asked to read some file, and return an instance for it: |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
910 |
Image fromFile:<someFileName> |
618 | 911 |
The Image class will guess the images format and forward the task to |
912 |
some concrete ImageReaderClass. |
|
913 |
If that class finds, that the files format is incorrect, other readers |
|
914 |
are tried until some finds the files format acceptable. |
|
915 |
||
916 |
Image readers read the stream and collect all relevant information internally. |
|
118 | 917 |
Once done with reading, the actual image object is created and |
918 |
data filled in from the imageReaders collected info. |
|
105 | 919 |
|
618 | 920 |
See the implementation of #fromStream: in concrete subclasses. |
105 | 921 |
The public interfaces are: |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
922 |
<ConcreteReaderClass> fromFile:aFilename |
105 | 923 |
or: |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
924 |
<ConcreteReaderClass> fromStream:aStream |
105 | 925 |
|
121 | 926 |
If you add a new reader, dont forget to add the method #isValidImageFile: |
618 | 927 |
which should return true, if this reader supports reading a given file. |
4714 | 928 |
If your new reader class supports writing files, dont forget to add |
618 | 929 |
#canRepresent:anImage and return true from this method. |
593 | 930 |
|
931 |
[See also:] |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
932 |
Image Icon Form |
611 | 933 |
|
934 |
[author:] |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
935 |
Claus Gittinger |
105 | 936 |
" |
937 |
! ! |
|
938 |
||
1358 | 939 |
!ImageReader class methodsFor:'instance creation'! |
940 |
||
941 |
new |
|
942 |
^ self basicNew initialize |
|
943 |
||
944 |
"Created: 18.2.1997 / 17:08:45 / cg" |
|
945 |
! ! |
|
946 |
||
1167 | 947 |
!ImageReader class methodsFor:'cleanup'! |
105 | 948 |
|
285 | 949 |
lowSpaceCleanup |
950 |
"cleanup things we do not need" |
|
118 | 951 |
|
285 | 952 |
ReverseBits := nil |
105 | 953 |
! ! |
954 |
||
1167 | 955 |
!ImageReader class methodsFor:'constants'! |
105 | 956 |
|
957 |
reverseBits |
|
958 |
"return a table filled with bit reverse information. |
|
959 |
To convert from msbit-first to lsbit-first bytes, use |
|
960 |
the value as index into the table, retrieving the reverse |
|
961 |
value. Since indexing must start at 1, use (value + 1) as |
|
962 |
index." |
|
963 |
||
964 |
|val "{ Class: SmallInteger }" | |
|
965 |
||
966 |
ReverseBits isNil ifTrue:[ |
|
153 | 967 |
ReverseBits := ByteArray uninitializedNew:256. |
105 | 968 |
0 to:255 do:[:i | |
969 |
val := 0. |
|
970 |
(i bitTest:16r01) ifTrue:[val := val bitOr:16r80]. |
|
971 |
(i bitTest:16r02) ifTrue:[val := val bitOr:16r40]. |
|
972 |
(i bitTest:16r04) ifTrue:[val := val bitOr:16r20]. |
|
973 |
(i bitTest:16r08) ifTrue:[val := val bitOr:16r10]. |
|
974 |
(i bitTest:16r10) ifTrue:[val := val bitOr:16r08]. |
|
975 |
(i bitTest:16r20) ifTrue:[val := val bitOr:16r04]. |
|
976 |
(i bitTest:16r40) ifTrue:[val := val bitOr:16r02]. |
|
977 |
(i bitTest:16r80) ifTrue:[val := val bitOr:16r01]. |
|
978 |
ReverseBits at:(i + 1) put:val |
|
979 |
] |
|
980 |
]. |
|
981 |
^ ReverseBits |
|
982 |
! ! |
|
983 |
||
1167 | 984 |
!ImageReader class methodsFor:'decompression support'! |
105 | 985 |
|
285 | 986 |
decodeDelta:step in:data width:width height:height |
987 |
"perform NeXT special predictor delta decoding inplace in data. |
|
988 |
Calls primitive c function for speed" |
|
989 |
||
990 |
(step ~~ 3) ifTrue:[ |
|
991 |
^ self error:'only rgb pictures supported' |
|
992 |
]. |
|
105 | 993 |
|
285 | 994 |
%{ |
995 |
if (__isByteArray(data) |
|
996 |
&& __bothSmallInteger(width, height)) { |
|
2043
7b8d741538a0
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
997 |
__decodeDelta__(__ByteArrayInstPtr(data)->ba_element, |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2043
diff
changeset
|
998 |
__intVal(width), __intVal(height)); |
285 | 999 |
RETURN ( self ); |
1000 |
} |
|
1001 |
%} |
|
1002 |
. |
|
1003 |
self primitiveFailed |
|
1004 |
! |
|
105 | 1005 |
|
4714 | 1006 |
decompressCCITT3From:srcBytes into:dstBytes startingAt:offset count:count |
105 | 1007 |
"decompress CCITT Group 3 compressed image data. |
1008 |
count bytes from srcBytes are decompressed into dstBytes. |
|
1009 |
Calls primitive c function for speed" |
|
1010 |
%{ |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1011 |
if (__isByteArrayLike(srcBytes) |
105 | 1012 |
&& __isByteArray(dstBytes) |
1013 |
&& __bothSmallInteger(offset, count)) { |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1014 |
if (__decodeCCITTgroup3__(__ByteArrayInstPtr(srcBytes)->ba_element, |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1015 |
__ByteArrayInstPtr(dstBytes)->ba_element |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1016 |
+ __intVal(offset) - 1, |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1017 |
__intVal(count))) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1018 |
RETURN ( self ); |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1019 |
} |
105 | 1020 |
} |
1021 |
%} |
|
1022 |
. |
|
1023 |
self primitiveFailed |
|
1024 |
! |
|
1025 |
||
1026 |
decompressGIFFrom:srcBytes count:count into:dstBytes startingAt:offset codeLen:codeLen |
|
1027 |
"decompress GIF compressed image data. |
|
1028 |
count bytes from srcBytes are decompressed into dstBytes. |
|
1029 |
Calls primitive c function for speed" |
|
1030 |
%{ |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1031 |
if (__isByteArrayLike(srcBytes) |
105 | 1032 |
&& __isByteArray(dstBytes) |
1033 |
&& __bothSmallInteger(codeLen, offset) |
|
1034 |
&& __isSmallInteger(count)) { |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1035 |
if (__decodeGIF__(__ByteArrayInstPtr(srcBytes)->ba_element, |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1036 |
__ByteArrayInstPtr(dstBytes)->ba_element |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1037 |
+__intVal(offset) - 1, |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1038 |
__intVal(count), |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1039 |
__intVal(codeLen), |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1040 |
__byteArraySize(srcBytes), |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1041 |
__byteArraySize(dstBytes) |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1042 |
)) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1043 |
RETURN ( self ); |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1044 |
} |
105 | 1045 |
} |
1046 |
%} |
|
1047 |
. |
|
1048 |
self primitiveFailed |
|
1049 |
! |
|
1050 |
||
285 | 1051 |
decompressLZWFrom:srcBytes count:count into:dstBytes startingAt:offset |
1052 |
"decompress LZW (tiff) compressed image data. |
|
1053 |
count bytes from srcBytes are decompressed into dstBytes. |
|
105 | 1054 |
Calls primitive c function for speed" |
1055 |
%{ |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1056 |
if (__isByteArrayLike(srcBytes) |
285 | 1057 |
&& __isByteArray(dstBytes) |
1058 |
&& __bothSmallInteger(offset, count)) { |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1059 |
if (__decodeLZW__(__ByteArrayInstPtr(srcBytes)->ba_element, |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1060 |
__ByteArrayInstPtr(dstBytes)->ba_element |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1061 |
+ __intVal(offset) - 1, |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1062 |
__intVal(count), |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1063 |
__byteArraySize(srcBytes), |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1064 |
__byteArraySize(dstBytes) |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1065 |
)) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1066 |
RETURN ( self ); |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1067 |
} |
105 | 1068 |
} |
1069 |
%} |
|
1070 |
. |
|
1071 |
self primitiveFailed |
|
189 | 1072 |
! |
1073 |
||
1648
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1074 |
decompressRLEFrom:srcBytes at:srcStartIndex into:dstBytes at:dstStartIndex increment:dstIncrement |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1075 |
"common helper to expand RLE encoded data" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1076 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1077 |
"/ the code below expands common RLE formats, where the high bit |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1078 |
"/ controls how the count in the low 7 bits is to be interpreted: |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1079 |
"/ 1 means: count verbatim bytes follow; |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1080 |
"/ 0 means: repeat the next byte count times. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1081 |
"/ Decoding stops when a 0-count is encountered. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1082 |
"/ srcBytes and dstBytes should not overlap. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1083 |
"/ dstIncrement controls the stepping in the destination (usually: 1) |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1084 |
"/ |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1085 |
"/ this may be recoded in C in the future |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1086 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1087 |
|srcIdx "{Class: SmallInteger }" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1088 |
dstIdx "{Class: SmallInteger }" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1089 |
pixel "{Class: SmallInteger }" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1090 |
count "{Class: SmallInteger }"| |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1091 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1092 |
srcIdx := srcStartIndex. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1093 |
dstIdx := dstStartIndex. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1094 |
[true] whileTrue:[ |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1095 |
pixel := srcBytes at:srcIdx. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1096 |
count := pixel bitAnd:16r7F. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1097 |
count == 0 ifTrue:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1098 |
^ self |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1099 |
]. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1100 |
srcIdx := srcIdx + 1. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1101 |
(pixel bitAnd:16r80) == 0 ifTrue:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1102 |
"/ run bytes |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1103 |
pixel := srcBytes at:srcIdx. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1104 |
srcIdx := srcIdx + 1. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1105 |
dstIncrement == 1 ifTrue:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1106 |
dstBytes from:dstIdx to:(dstIdx+count-1) put:pixel. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1107 |
dstIdx := dstIdx + count. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1108 |
] ifFalse:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1109 |
1 to:count do:[:c | |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1110 |
dstBytes at:dstIdx put:pixel. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1111 |
dstIdx := dstIdx + dstIncrement. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1112 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1113 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1114 |
] ifFalse:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1115 |
"/ verbatim bytes |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1116 |
dstIncrement == 1 ifTrue:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1117 |
dstBytes replaceFrom:dstIdx to:(dstIdx+count-1) with:srcBytes startingAt:srcIdx. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1118 |
srcIdx := srcIdx + count. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1119 |
dstIdx := dstIdx + count. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1120 |
] ifFalse:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1121 |
1 to:count do:[:c | |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1122 |
dstBytes at:dstIdx put:(srcBytes at:srcIdx). |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1123 |
srcIdx := srcIdx + 1. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1124 |
dstIdx := dstIdx + dstIncrement. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1125 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1126 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1127 |
] |
1648
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1128 |
]. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1129 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1130 |
"Modified: 23.4.1997 / 18:54:05 / cg" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1131 |
! |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1132 |
|
3835 | 1133 |
swap:nBytes bytesFromRGB_to_BGR_in:data |
1134 |
"swap bytes from RGB into BGR order. |
|
1135 |
The argument is a pixel data buffer (byteArray)" |
|
1136 |
||
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1137 |
self swap:nBytes bytesFromRGB_to_BGR_in:data startingAt:1 |
3835 | 1138 |
|
1139 |
" |
|
1140 |
|bytes| |
|
1141 |
||
1142 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
|
1143 |
self swap:6 bytesFromRGB_to_BGR_in:bytes. |
|
4714 | 1144 |
bytes. |
3835 | 1145 |
" |
1146 |
" |
|
1147 |
|bytes| |
|
1148 |
||
1149 |
bytes := ByteArray new:1000000. |
|
4714 | 1150 |
bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12]. |
3835 | 1151 |
Time millisecondsToRun:[ |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1152 |
self swap:1000000 bytesFromRGB_to_BGR_in:bytes. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1153 |
]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1154 |
bytes copyTo:10. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1155 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1156 |
! |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1157 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1158 |
swap:nBytes bytesFromRGB_to_BGR_in:data startingAt:startIndex |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1159 |
"swap bytes from RGB into BGR order. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1160 |
The argument is a pixel data buffer (byteArray)" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1161 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1162 |
|t| |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1163 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1164 |
%{ /* OPTIONAL */ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1165 |
if (__isByteArray(data) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1166 |
&& __isSmallInteger(nBytes) |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1167 |
&& __isSmallInteger(startIndex)) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1168 |
int __nBytes = __intVal(nBytes); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1169 |
int __startOffset = __intVal(startIndex) - 1; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1170 |
int __dataSize = __byteArraySize(data); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1171 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1172 |
if ((__startOffset + __nBytes) <= __dataSize) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1173 |
int __lastIndex = __startOffset + __nBytes - 2; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1174 |
unsigned char *__cp = __ByteArrayInstPtr(data)->ba_element + __startOffset; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1175 |
int __i; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1176 |
unsigned char __t; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1177 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1178 |
for (__i=__startOffset; __i<__lastIndex; __i+=3, __cp+=3) { |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1179 |
__t = __cp[0]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1180 |
__cp[0] = __cp[2]; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1181 |
__cp[2] = __t; |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1182 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1183 |
RETURN (true); |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1184 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1185 |
} |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1186 |
%}. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1187 |
1 to:(nBytes - 2) by:3 do:[:i | |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1188 |
|ii| |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1189 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1190 |
ii := i + startIndex - 1. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1191 |
t := data at:ii. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1192 |
data at:i put:(data at:ii+2). |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1193 |
data at:ii+2 put:t |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1194 |
]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1195 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1196 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1197 |
|bytes| |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1198 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1199 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1200 |
self swap:6 bytesFromRGB_to_BGR_in:bytes startingAt:1. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1201 |
bytes. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1202 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1203 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1204 |
|bytes| |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1205 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1206 |
bytes := ByteArray new:1000000. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1207 |
bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1208 |
Time millisecondsToRun:[ |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1209 |
self swap:1000000 bytesFromRGB_to_BGR_in:bytes. |
4714 | 1210 |
]. |
1211 |
bytes copyTo:10. |
|
3835 | 1212 |
" |
285 | 1213 |
! ! |
1214 |
||
1167 | 1215 |
!ImageReader class methodsFor:'i/o support'! |
285 | 1216 |
|
1217 |
streamReadingFile:aFilename |
|
1218 |
"return a stream to read aFilename. |
|
1219 |
If the filename ends with '.Z' or '.gz', return a stream |
|
1220 |
to a pipe for the uncompressor. Otherwise, return a stream to read |
|
1221 |
the file directly." |
|
1222 |
||
1300 | 1223 |
|inStream name fn| |
285 | 1224 |
|
1225 |
name := aFilename asString. |
|
1226 |
((name endsWith:'.Z') or:[name endsWith:'.gz']) ifTrue:[ |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1227 |
fn := Smalltalk getSystemFileName:name. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1228 |
inStream := PipeStream readingFrom:'gunzip < ' , fn. |
285 | 1229 |
] ifFalse:[ |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1230 |
inStream := Smalltalk systemFileStreamFor:aFilename. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1231 |
inStream isNil ifTrue:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1232 |
inStream := Smalltalk bitmapFileStreamFor:aFilename |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1233 |
] |
285 | 1234 |
]. |
1235 |
inStream isNil ifTrue:[ |
|
4714 | 1236 |
'ImageReader [warning]: open error on: ' infoPrint. aFilename infoPrintCR. |
285 | 1237 |
]. |
1238 |
^ inStream |
|
518 | 1239 |
|
1300 | 1240 |
"Modified: 31.1.1997 / 10:37:24 / cg" |
285 | 1241 |
! ! |
1242 |
||
1167 | 1243 |
!ImageReader class methodsFor:'image reading'! |
285 | 1244 |
|
1245 |
fromFile:aFileName |
|
4714 | 1246 |
"read an image (in my format) from aFileName. |
285 | 1247 |
Return the image or nil on error." |
1248 |
||
1551 | 1249 |
|reader| |
285 | 1250 |
|
1551 | 1251 |
reader := self readFile:aFileName. |
1252 |
reader notNil ifTrue:[ |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1253 |
^ reader image |
285 | 1254 |
]. |
1551 | 1255 |
^ nil |
285 | 1256 |
|
1257 |
" |
|
1258 |
XBMReader fromFile:'bitmaps/SBrowser.xbm' |
|
4033 | 1259 |
XPMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
1260 |
XBMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
518 | 1261 |
" |
1262 |
||
1551 | 1263 |
"Modified: 4.4.1997 / 22:09:49 / cg" |
285 | 1264 |
! |
1265 |
||
1266 |
fromStream:aStream |
|
583 | 1267 |
"read an image (in my format) from aStream. |
1551 | 1268 |
Return the image or nil (if unrecognized format or error). |
1269 |
The stream remains open." |
|
285 | 1270 |
|
1271 |
|reader| |
|
1272 |
||
3839 | 1273 |
reader := self readStream:aStream. |
1274 |
^ reader image |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1275 |
! |
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1276 |
|
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1277 |
imagesFromFile:aFileName |
4714 | 1278 |
"read all images (in my format) from aFileName. |
1551 | 1279 |
Return a collection of images or nil on error. |
1280 |
Not all reader may support multiple images." |
|
1281 |
||
1282 |
|reader| |
|
1283 |
||
1284 |
reader := self readFile:aFileName. |
|
1285 |
reader notNil ifTrue:[ |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1286 |
^ reader images |
1551 | 1287 |
]. |
1288 |
^ nil |
|
1289 |
||
1290 |
"Modified: 4.4.1997 / 22:11:01 / cg" |
|
1291 |
! |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1292 |
|
1551 | 1293 |
imagesFromStream:aStream |
1294 |
"read all images (in my format) from aStream. |
|
1295 |
Return a collection of images or nil (if unrecognized format or error). |
|
1296 |
The stream remains open. |
|
1297 |
Not all reader may support multiple images." |
|
1298 |
||
1299 |
|reader| |
|
1300 |
||
3839 | 1301 |
reader := self new. |
1302 |
reader inStream:aStream. |
|
1303 |
reader fromStream:aStream. |
|
1304 |
^ reader images |
|
1551 | 1305 |
|
1306 |
"Modified: 4.4.1997 / 22:11:40 / cg" |
|
1307 |
! |
|
1308 |
||
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1309 |
readFile:aFilename |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1310 |
"create a reader and let it read an image (in my format) from aFilename. |
1551 | 1311 |
Return the reader." |
1312 |
||
1313 |
|reader inStream| |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1314 |
|
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1315 |
self == ImageReader ifTrue:[ |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1316 |
"select a reader supporting this file format" |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1317 |
|mime| |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1318 |
|
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1319 |
mime := aFilename asFilename mimeTypeFromName. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1320 |
mime isNil ifTrue:[ |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1321 |
mime := aFilename asFilename mimeTypeOfContents. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1322 |
]. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1323 |
|
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1324 |
mime notNil ifTrue:[ |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1325 |
reader := MIMETypes imageReaderForType:mime. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1326 |
reader isNil ifTrue:[ |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1327 |
"answer the reader when proceeding form this error" |
5737
f39cc6dc9848
raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents:
5567
diff
changeset
|
1328 |
reader := ConversionError raiseRequestErrorString:' - unsupported image type: ', mime. |
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1329 |
]. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1330 |
^ reader readFile:aFilename. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1331 |
]. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1332 |
]. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1333 |
|
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1334 |
|
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1335 |
inStream := self streamReadingFile:aFilename. |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1336 |
inStream isNil ifTrue:[ |
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1337 |
'ImageReader [warning]: file open error' errorPrintCR. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1338 |
^ nil |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1339 |
]. |
3839 | 1340 |
reader := self new. |
1341 |
reader inStream:inStream. |
|
3489 | 1342 |
[ |
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1343 |
reader fromStream:inStream. |
3605
b5c70808fc8c
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
3489
diff
changeset
|
1344 |
] ensure:[ |
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
1345 |
inStream close. |
3489 | 1346 |
]. |
1551 | 1347 |
^ reader |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1348 |
|
1551 | 1349 |
" |
4033 | 1350 |
XPMReader readFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
1551 | 1351 |
" |
1352 |
||
5737
f39cc6dc9848
raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents:
5567
diff
changeset
|
1353 |
"Modified: / 04-04-2011 / 14:16:56 / cg" |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1354 |
! |
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1355 |
|
3839 | 1356 |
readStream:aStream |
4714 | 1357 |
"create a reader and let it read a stream (in my format). |
1551 | 1358 |
Return the reader. The stream remains open." |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1359 |
|
3839 | 1360 |
|reader| |
1361 |
||
1362 |
reader := self new. |
|
1363 |
reader fromStream:aStream. |
|
1364 |
^ reader |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1365 |
|
1551 | 1366 |
"Created: 4.4.1997 / 22:08:13 / cg" |
285 | 1367 |
! ! |
1368 |
||
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1369 |
!ImageReader class methodsFor:'image support'! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1370 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1371 |
buildMaskFromColor:maskPixelValue for:pixels width:width height:height |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1372 |
"helper for image formats, where an individual pixel value |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1373 |
has been defined as a mask-pixel (i.e. GIF). |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1374 |
Creates a maskImage, with zeros at positions where the image |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1375 |
has the given pixelValue; all other mask pixels are set to 1." |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1376 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1377 |
|maskArray bytesPerMaskRow mask| |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1378 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1379 |
bytesPerMaskRow := (width+7) // 8. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1380 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1381 |
maskArray := ByteArray uninitializedNew:bytesPerMaskRow * height. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1382 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1383 |
%{ |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1384 |
int __w = __intVal(width); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1385 |
int __h = __intVal(height); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1386 |
int __x, __y; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1387 |
int __outBits, __nOut; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1388 |
unsigned char *__inP, *__outP, *__nextOutRow; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1389 |
int __bpr = __intVal(bytesPerMaskRow); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1390 |
int __maskPixel = __intVal(maskPixelValue); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1391 |
#ifdef DEBUG |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1392 |
unsigned char *outEnd; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1393 |
#endif |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1394 |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1395 |
if (! __isByteArrayLike(pixels)) goto fail; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1396 |
if (! __isByteArray(maskArray)) goto fail; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1397 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1398 |
__inP = __ByteArrayInstPtr(pixels)->ba_element; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1399 |
__outP = __ByteArrayInstPtr(maskArray)->ba_element; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1400 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1401 |
#ifdef DEBUG |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1402 |
outEnd = __outP + (__byteArraySize(maskArray)); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1403 |
#endif |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1404 |
/* |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1405 |
printf("outP: %x outEnd: %x sz: %d\n", __outP, outEnd, __byteArraySize(maskArray)); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1406 |
*/ |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1407 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1408 |
for (__y=__h; __y>0; __y--) { |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1409 |
__outBits = 0; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1410 |
__nOut = 8; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1411 |
__nextOutRow = __outP + __bpr; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1412 |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1413 |
for (__x=__w; __x>=8; __x-=8) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1414 |
if (__inP[0] != __maskPixel) { __outBits |= 0x80; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1415 |
if (__inP[1] != __maskPixel) { __outBits |= 0x40; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1416 |
if (__inP[2] != __maskPixel) { __outBits |= 0x20; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1417 |
if (__inP[3] != __maskPixel) { __outBits |= 0x10; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1418 |
if (__inP[4] != __maskPixel) { __outBits |= 0x08; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1419 |
if (__inP[5] != __maskPixel) { __outBits |= 0x04; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1420 |
if (__inP[6] != __maskPixel) { __outBits |= 0x02; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1421 |
if (__inP[7] != __maskPixel) { __outBits |= 0x01; }; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1422 |
__inP += 8; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1423 |
*__outP++ = __outBits; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1424 |
__outBits = 0; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1425 |
} |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1426 |
for (; __x>0; __x--) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1427 |
__outBits <<= 1; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1428 |
if (*__inP != __maskPixel) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1429 |
__outBits |= 1; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1430 |
} |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1431 |
__inP++; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1432 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1433 |
/* |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1434 |
printf("x: %d bits: %x\n", __x, __outBits); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1435 |
*/ |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1436 |
if (--__nOut == 0) { |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1437 |
#ifdef DEBUG |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1438 |
if (__outP >= outEnd) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1439 |
if (@global(InfoPrinting) == true) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1440 |
console_fprintf(stderr, "oops %d\n", __LINE__); |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1441 |
} |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1442 |
goto fail; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1443 |
} |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1444 |
#endif |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1445 |
*__outP = __outBits; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1446 |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1447 |
__outP++; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1448 |
__nOut = 8; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1449 |
__outBits = 0; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1450 |
} |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1451 |
} |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1452 |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1453 |
if (__nOut != 8) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1454 |
__outBits <<= __nOut; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1455 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1456 |
#ifdef DEBUG |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1457 |
if (__outP >= outEnd) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1458 |
if (@global(InfoPrinting) == true) { |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1459 |
console_fprintf(stderr, "oops2 %d\n", __LINE__); |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1460 |
} |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1461 |
goto fail; |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1462 |
} |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1463 |
#endif |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1464 |
*__outP = __outBits; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1465 |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1466 |
} |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1467 |
__outP = __nextOutRow; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1468 |
} |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1469 |
fail: ; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1470 |
%}. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1471 |
mask := ImageMask width:width height:height fromArray:maskArray. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1472 |
^ mask |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1473 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1474 |
"Created: 21.6.1996 / 11:43:47 / cg" |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1475 |
! ! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1476 |
|
1167 | 1477 |
!ImageReader class methodsFor:'image writing'! |
285 | 1478 |
|
1479 |
save:anImage onFile:aFileName |
|
1480 |
"save the image in my format on aFileName" |
|
1481 |
||
1482 |
^ (self basicNew) save:anImage onFile:aFileName |
|
1574 | 1483 |
|
1484 |
"Modified: 10.4.1997 / 17:42:57 / cg" |
|
3932 | 1485 |
! |
1486 |
||
1487 |
save:anImage onStream:aStream |
|
1488 |
"save the image in my format on a Stream" |
|
1489 |
||
1490 |
^ (self basicNew) save:anImage onStream:aStream |
|
1491 |
||
1492 |
"Modified: 10.4.1997 / 17:42:57 / cg" |
|
285 | 1493 |
! ! |
1494 |
||
1167 | 1495 |
!ImageReader class methodsFor:'testing'! |
285 | 1496 |
|
1497 |
canRepresent:anImage |
|
1498 |
"return true, if anImage can be represented in my file format. |
|
1499 |
must be redefined in concrete subclasses which support saving." |
|
1500 |
||
1501 |
^ false |
|
1502 |
! |
|
1503 |
||
1504 |
isValidImageFile:aFileName |
|
1505 |
"return true, if aFileName contains an image this |
|
1506 |
reader understands - must be redefined in concrete subclasses |
|
1507 |
which support reading." |
|
1508 |
||
1509 |
^ false |
|
105 | 1510 |
! ! |
1511 |
||
1512 |
!ImageReader methodsFor:'accessing'! |
|
1513 |
||
285 | 1514 |
bitsPerPixel |
1515 |
"return the number of bits per pixel" |
|
1516 |
||
3386
b9294699dbcf
care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1517 |
bitsPerSample isNil ifTrue:[^ nil]. |
285 | 1518 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
1519 |
! |
|
1520 |
||
1300 | 1521 |
bitsPerRow |
1522 |
"return the number of bits in one scanline of the image" |
|
1523 |
||
3868 | 1524 |
^ width * (self bitsPerPixel). |
1300 | 1525 |
|
1526 |
"Created: 31.1.1997 / 10:38:42 / cg" |
|
1527 |
! |
|
1528 |
||
285 | 1529 |
bitsPerSample |
583 | 1530 |
"return the number of bits per sample" |
1531 |
||
285 | 1532 |
^ bitsPerSample |
583 | 1533 |
|
1534 |
"Modified: 22.4.1996 / 19:15:18 / cg" |
|
285 | 1535 |
! |
1536 |
||
1300 | 1537 |
bytesPerRow |
1538 |
"return the number of bytes in one scanline of the image" |
|
1539 |
||
1540 |
|bitsPerRow bytesPerRow| |
|
1541 |
||
1542 |
bitsPerRow := width * (self bitsPerPixel). |
|
1543 |
bytesPerRow := bitsPerRow // 8. |
|
1544 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1545 |
bytesPerRow := bytesPerRow + 1 |
1300 | 1546 |
]. |
1547 |
^ bytesPerRow |
|
1548 |
||
1549 |
"Created: 31.1.1997 / 10:39:06 / cg" |
|
1550 |
! |
|
1551 |
||
285 | 1552 |
colorMap |
583 | 1553 |
"return the colormap" |
1554 |
||
285 | 1555 |
^ colorMap |
583 | 1556 |
|
1557 |
"Modified: 22.4.1996 / 19:15:24 / cg" |
|
285 | 1558 |
! |
1559 |
||
4714 | 1560 |
data |
583 | 1561 |
"return the raw image data" |
1562 |
||
285 | 1563 |
^ data |
583 | 1564 |
|
1565 |
"Modified: 22.4.1996 / 19:15:31 / cg" |
|
285 | 1566 |
! |
1567 |
||
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1568 |
hasMultipleImages |
1773 | 1569 |
^ imageSequence size > 1 |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1570 |
|
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1571 |
"Created: 4.4.1997 / 21:37:06 / cg" |
1773 | 1572 |
"Modified: 24.6.1997 / 15:33:43 / cg" |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1573 |
! |
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
1574 |
|
4714 | 1575 |
height |
583 | 1576 |
"return the height of the image" |
1577 |
||
285 | 1578 |
^ height |
583 | 1579 |
|
1580 |
"Modified: 22.4.1996 / 19:15:39 / cg" |
|
285 | 1581 |
! |
1582 |
||
105 | 1583 |
image |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1584 |
"return the image as represented by myself; |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1585 |
If my file contained multiple images, return the first one." |
105 | 1586 |
|
1773 | 1587 |
imageSequence size > 0 ifTrue:[ |
2152
b071479dac57
check byteArray bounds in bmp-decompressors;
Claus Gittinger <cg@exept.de>
parents:
2082
diff
changeset
|
1588 |
^ self images first. |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1589 |
]. |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1590 |
|
2080 | 1591 |
^ self makeImage. |
583 | 1592 |
|
1980
5f99cc1ac111
be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents:
1949
diff
changeset
|
1593 |
"Modified: / 15.1.1998 / 15:46:24 / stefan" |
2082 | 1594 |
"Modified: / 1.4.1998 / 14:31:35 / cg" |
1595 |
! |
|
1596 |
||
1597 |
imageFrames |
|
1598 |
"return a collection of all imageFrames as represented by myself. |
|
1599 |
ImageFrames are wrappers for individual images, which hold |
|
1600 |
additional information (such as image delay time). |
|
1601 |
Nil is return for single image formats/files." |
|
1602 |
||
1603 |
^ imageSequence |
|
1604 |
||
1605 |
"Created: / 1.4.1998 / 14:37:42 / cg" |
|
893
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1606 |
! |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1607 |
|
1551 | 1608 |
images |
1609 |
"return a collection of all images as represented by myself. |
|
1610 |
For compatibility with single-image formats, return a collection |
|
1773 | 1611 |
containing my single image here if the reader does not support |
1612 |
multiple images. |
|
1613 |
Readers for formats with multiple images should leave the images |
|
1614 |
in the imageSequence instVar as a side effect of reading." |
|
1551 | 1615 |
|
1616 |
|img| |
|
1617 |
||
1773 | 1618 |
imageSequence notNil ifTrue:[ |
2152
b071479dac57
check byteArray bounds in bmp-decompressors;
Claus Gittinger <cg@exept.de>
parents:
2082
diff
changeset
|
1619 |
^ (imageSequence collect:[:aFrame | aFrame image]) |
1773 | 1620 |
]. |
1621 |
||
2082 | 1622 |
img := self makeImage. |
1551 | 1623 |
img isNil ifTrue:[ |
2152
b071479dac57
check byteArray bounds in bmp-decompressors;
Claus Gittinger <cg@exept.de>
parents:
2082
diff
changeset
|
1624 |
^ img |
1551 | 1625 |
]. |
1626 |
^ Array with:img |
|
1627 |
||
2082 | 1628 |
"Modified: / 1.4.1998 / 14:36:23 / cg" |
1551 | 1629 |
! |
1630 |
||
2080 | 1631 |
makeImage |
2082 | 1632 |
"return the image as represented by the values found in my |
1633 |
instvars; these have been typically set as a side effect of |
|
1634 |
the fromStream:-method, which reads images." |
|
2080 | 1635 |
|
1636 |
|image depth| |
|
1637 |
||
1638 |
depth := self bitsPerPixel. |
|
3839 | 1639 |
(depth notNil and:[data notNil]) ifTrue:[ |
4033 | 1640 |
image := Image newForDepth:depth. |
1641 |
image depth:depth. |
|
1642 |
inStream isFileStream ifTrue:[ |
|
1643 |
image fileName:inStream pathName. |
|
1644 |
]. |
|
4714 | 1645 |
image |
1646 |
width:width |
|
4033 | 1647 |
height:height |
1648 |
photometric:photometric |
|
1649 |
samplesPerPixel:samplesPerPixel |
|
1650 |
bitsPerSample:bitsPerSample |
|
1651 |
colorMap:colorMap |
|
1652 |
bits:data |
|
1653 |
mask:mask. |
|
3386
b9294699dbcf
care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1654 |
|
4033 | 1655 |
imageSequence notNil ifTrue:[ |
1656 |
image imageSequence:imageSequence. |
|
1657 |
]. |
|
2080 | 1658 |
]. |
1659 |
^ image |
|
1660 |
||
1661 |
"Modified: / 15.1.1998 / 15:46:24 / stefan" |
|
1662 |
"Created: / 1.4.1998 / 14:09:45 / cg" |
|
2082 | 1663 |
"Modified: / 1.4.1998 / 14:41:35 / cg" |
2080 | 1664 |
! |
1665 |
||
893
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1666 |
mask |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1667 |
"return the image mask (or nil)" |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1668 |
|
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1669 |
^ mask |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1670 |
|
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1671 |
"Modified: 22.4.1996 / 19:15:31 / cg" |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1672 |
"Created: 20.6.1996 / 17:08:29 / cg" |
105 | 1673 |
! |
1674 |
||
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1675 |
numberOfImages |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1676 |
"return the number of images as read. |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1677 |
By default (here), I hold a single image; |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1678 |
however, some fileFormats allow for multiple images" |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1679 |
|
1773 | 1680 |
|n| |
1681 |
||
1682 |
(n := imageSequence size) > 0 ifTrue:[ |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1683 |
^ n |
1773 | 1684 |
]. |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1685 |
^ 1 |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1686 |
|
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1687 |
"Created: 21.6.1997 / 18:33:45 / cg" |
1773 | 1688 |
"Modified: 24.6.1997 / 15:33:26 / cg" |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1689 |
! |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
1690 |
|
105 | 1691 |
photometric |
583 | 1692 |
"return the photometric interpretation of the image data" |
1693 |
||
105 | 1694 |
^ photometric |
583 | 1695 |
|
1696 |
"Modified: 22.4.1996 / 19:15:57 / cg" |
|
105 | 1697 |
! |
1698 |
||
1699 |
samplesPerPixel |
|
583 | 1700 |
"return the number of samples per pixel" |
1701 |
||
105 | 1702 |
^ samplesPerPixel |
583 | 1703 |
|
1704 |
"Modified: 22.4.1996 / 19:16:03 / cg" |
|
105 | 1705 |
! |
1706 |
||
285 | 1707 |
width |
583 | 1708 |
"return the width of the image" |
1709 |
||
285 | 1710 |
^ width |
583 | 1711 |
|
1712 |
"Modified: 22.4.1996 / 19:16:10 / cg" |
|
105 | 1713 |
! ! |
1714 |
||
3263 | 1715 |
!ImageReader methodsFor:'accessing-private'! |
1355 | 1716 |
|
1717 |
byteOrder:aSymbol |
|
1718 |
"set the byte order - either #lsb or #msb" |
|
1719 |
||
1720 |
byteOrder := aSymbol |
|
1721 |
||
1722 |
"Created: 15.2.1997 / 13:58:50 / cg" |
|
1723 |
! |
|
1724 |
||
1725 |
inStream |
|
1726 |
^ inStream |
|
1727 |
||
1728 |
"Created: 15.2.1997 / 13:57:40 / cg" |
|
1729 |
! |
|
1730 |
||
1731 |
inStream:aStream |
|
1732 |
inStream := aStream |
|
1733 |
||
1734 |
"Created: 15.2.1997 / 13:57:35 / cg" |
|
1735 |
! ! |
|
1736 |
||
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1737 |
!ImageReader methodsFor:'error reporting'! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1738 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1739 |
fileFormatError:aMessage |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1740 |
"report a format error - no image could be read" |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1741 |
|
4055 | 1742 |
|errorString| |
1743 |
||
1744 |
errorString := self class name , ' [info]: ' , aMessage. |
|
1745 |
inStream isFileStream ifTrue:[ |
|
4714 | 1746 |
errorString := errorString , ' [in ' , inStream pathName , ']' |
4055 | 1747 |
]. |
1748 |
||
1749 |
Image badImageFormatQuerySignal raiseErrorString:errorString. |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1750 |
^ nil |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1751 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1752 |
"Created: / 3.2.1998 / 17:50:06 / cg" |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1753 |
! ! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1754 |
|
105 | 1755 |
!ImageReader methodsFor:'i/o support'! |
1756 |
||
1757 |
readLong |
|
1758 |
"return the next 4-byte long, honoring the byte-order" |
|
1759 |
||
1760 |
^ inStream nextLongMSB:(byteOrder ~~ #lsb) |
|
1761 |
! |
|
1762 |
||
1763 |
readShort |
|
1764 |
"return the next 2-byte short, honoring the byte-order" |
|
1765 |
||
1766 |
^ inStream nextUnsignedShortMSB:(byteOrder ~~ #lsb) |
|
1767 |
! |
|
1768 |
||
1769 |
readShortLong |
|
1770 |
"return the next 2-byte short, honoring the byte-order. |
|
1771 |
There are actually 4 bytes read, but only 2 looked at." |
|
1772 |
||
1773 |
|bytes val| |
|
1774 |
||
153 | 1775 |
bytes := ByteArray uninitializedNew:4. |
105 | 1776 |
inStream nextBytes:4 into:bytes. |
1777 |
(byteOrder == #lsb) ifTrue:[ |
|
1778 |
val := bytes at:2. |
|
1779 |
val := val * 256 + (bytes at:1) |
|
1780 |
] ifFalse:[ |
|
1781 |
val := bytes at:3. |
|
1782 |
val := val * 256 + (bytes at:4) |
|
1783 |
]. |
|
1784 |
^ val |
|
1785 |
! |
|
1786 |
||
5318 | 1787 |
readUnsignedLong |
1788 |
"return the next 4-byte long, honoring the byte-order" |
|
1789 |
||
1790 |
^ inStream nextUnsignedLongMSB:(byteOrder ~~ #lsb) |
|
1791 |
! |
|
1792 |
||
105 | 1793 |
writeLong:anInteger |
1794 |
"write a 4-byte long, honoring the byte-order." |
|
1795 |
||
1796 |
outStream nextPutLong:anInteger MSB:(byteOrder ~~ #lsb) |
|
1797 |
! |
|
1798 |
||
1799 |
writeShort:anInteger |
|
1800 |
"write a 2-byte short, honoring the byte-order." |
|
1801 |
||
1802 |
outStream nextPutShort:anInteger MSB:(byteOrder ~~ #lsb) |
|
1803 |
! ! |
|
285 | 1804 |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1805 |
!ImageReader methodsFor:'image reading'! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1806 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1807 |
fromStream:aStream |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1808 |
"read an image in my format from aStream. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1809 |
Leave image description in instance variables." |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1810 |
|
3839 | 1811 |
self inStream:aStream. |
1812 |
self readImage. |
|
1813 |
! |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1814 |
|
3839 | 1815 |
readImage |
1816 |
"read an image in my format from my inStream. |
|
1817 |
Leave image description in instance variables." |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1818 |
|
3839 | 1819 |
self subclassResponsibility. |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1820 |
! ! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1821 |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1822 |
!ImageReader methodsFor:'image reading support'! |
285 | 1823 |
|
929
f792d9689def
Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
893
diff
changeset
|
1824 |
buildMaskFromColor:maskPixelValue |
1631
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
1825 |
"helper for image formats, where an individual pixel value |
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
1826 |
has been defined as a mask-pixel (i.e. GIF). |
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
1827 |
Creates a maskImage, with zeros at positions where the image |
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
1828 |
has the given pixelValue; all other mask pixels are set to 1." |
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
1829 |
|
4714 | 1830 |
mask := self class |
1831 |
buildMaskFromColor:maskPixelValue |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1832 |
for:data |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1833 |
width:width |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1834 |
height:height |
929
f792d9689def
Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
893
diff
changeset
|
1835 |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1836 |
"Modified: / 14.1.1998 / 14:48:33 / cg" |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1837 |
! ! |
929
f792d9689def
Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
893
diff
changeset
|
1838 |
|
285 | 1839 |
!ImageReader methodsFor:'image writing'! |
1840 |
||
1841 |
save:image onFile:aFileName |
|
1842 |
"save image in my format on aFile" |
|
1843 |
||
3933
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1844 |
|stream| |
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1845 |
|
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1846 |
[ |
5567 | 1847 |
stream := aFileName asFilename newReadWriteStream. |
3933
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1848 |
] on:FileStream openErrorSignal do:[:ex| |
5567 | 1849 |
^ Image fileCreationErrorSignal |
1850 |
raiseWith:image |
|
1851 |
errorString:('file creation error: ' , aFileName asString). |
|
3933
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1852 |
]. |
1574 | 1853 |
|
3933
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1854 |
[ |
5567 | 1855 |
[ |
1856 |
self save:image onStream:stream. |
|
1857 |
] ifCurtailed:[ |
|
1858 |
OperatingSystem accessDeniedErrorSignal |
|
1859 |
handle:[:ex | |
|
1860 |
] do:[ |
|
1861 |
aFileName asFilename delete. |
|
1862 |
] |
|
1863 |
]. |
|
1864 |
] ensure:[ |
|
1865 |
stream close. |
|
1866 |
]. |
|
3933
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
1867 |
|
5567 | 1868 |
"Modified: / 01-06-2010 / 19:02:17 / cg" |
3932 | 1869 |
! |
1870 |
||
1871 |
save:image onStream:aStream |
|
1872 |
"save image in my format on a Stream" |
|
1873 |
||
4714 | 1874 |
^ Image cannotRepresentImageSignal |
4033 | 1875 |
raiseWith:image |
1876 |
errorString:('image save not implemented for this format'). |
|
285 | 1877 |
! ! |
1878 |
||
1358 | 1879 |
!ImageReader methodsFor:'initialization'! |
1880 |
||
1881 |
initialize |
|
1882 |
||
1883 |
"Created: 18.2.1997 / 17:08:31 / cg" |
|
1884 |
! ! |
|
1885 |
||
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1886 |
!ImageReader methodsFor:'progress reporting'! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1887 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1888 |
dimensionCallBack:aBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1889 |
"set the block, which is evaluated during the readProcess, as soon as |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1890 |
the images dimension is known. This is useful for background image reading, |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1891 |
if the size is need to be known (for example: for formatting purposes). |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1892 |
Obsoleted by dimensionHolder." |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1893 |
|
4177 | 1894 |
<resource:#obsolete> |
3965 | 1895 |
self obsoleteMethodWarning:'use #dimensionHolder'. |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1896 |
dimensionCallBack := aBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1897 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1898 |
"Created: 14.9.1996 / 17:10:58 / cg" |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1899 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1900 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1901 |
dimensionHolder:aValueHolderOrBlock |
4714 | 1902 |
"set the valueHolder or block, which is evaluated during the readProcess, |
1903 |
as soon as the images dimension is known. |
|
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1904 |
Useful for background image reading, if the size is need to be known (for example: for formatting purposes)." |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1905 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1906 |
dimensionHolder := aValueHolderOrBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1907 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1908 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1909 |
progressHolder:aValueHolderOrBlock |
4714 | 1910 |
"set the valueHolder or block, which is evaluated during the readProcess, |
1911 |
and set with progress information (0..100 percent). |
|
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1912 |
Useful for user feedback" |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1913 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1914 |
progressHolder := aValueHolderOrBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1915 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1916 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1917 |
reportDimension |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1918 |
dimensionCallBack notNil ifTrue:[ |
4033 | 1919 |
dimensionCallBack value:self |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1920 |
]. |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1921 |
dimensionHolder notNil ifTrue:[ |
4033 | 1922 |
dimensionHolder value:(width @ height) |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1923 |
]. |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1924 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1925 |
|
3957 | 1926 |
reportProgress:fraction |
1927 |
"can be used by a GUI application to indicate loading progress (0..1)" |
|
1928 |
||
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1929 |
progressHolder notNil ifTrue:[ |
4033 | 1930 |
progressHolder value:fraction |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1931 |
]. |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1932 |
! ! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
1933 |
|
1167 | 1934 |
!ImageReader class methodsFor:'documentation'! |
285 | 1935 |
|
1936 |
version |
|
5737
f39cc6dc9848
raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents:
5567
diff
changeset
|
1937 |
^ '$Header: /cvs/stx/stx/libview/ImageReader.st,v 1.99 2011-04-04 12:17:34 cg Exp $' |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1938 |
! |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1939 |
|
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1940 |
version_CVS |
5737
f39cc6dc9848
raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents:
5567
diff
changeset
|
1941 |
^ '$Header: /cvs/stx/stx/libview/ImageReader.st,v 1.99 2011-04-04 12:17:34 cg Exp $' |
285 | 1942 |
! ! |