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