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