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