author | Claus Gittinger <cg@exept.de> |
Wed, 22 Jan 2020 16:46:53 +0100 | |
changeset 8974 | f00c923a5748 |
parent 8958 | 809f4e8a2ce7 |
permissions | -rw-r--r-- |
8958 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
6 | 4 |
COPYRIGHT (c) 1991 by Claus Gittinger |
77 | 5 |
All Rights Reserved |
0 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3260 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
7142 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
Object subclass:#ImageReader |
8145 | 19 |
instanceVariableNames:'width height data byteOrder inStream outStream photometric depth |
1648
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
20 |
samplesPerPixel bitsPerSample colorMap mask maskPixel |
7375 | 21 |
dimensionCallBack dimensionHolder progressHolder imageSequence |
22 |
metaData' |
|
8129 | 23 |
classVariableNames:'BlackCountTable BlackShiftTable LeftBits ReverseBits |
24 |
WhiteCountTable WhiteShiftTable' |
|
518 | 25 |
poolDictionaries:'' |
3843
57d7f752c63b
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
3839
diff
changeset
|
26 |
category:'Graphics-Images-Readers' |
0 | 27 |
! |
28 |
||
8246 | 29 |
Query subclass:#EnforcedImageTypeQuery |
30 |
instanceVariableNames:'' |
|
31 |
classVariableNames:'' |
|
32 |
poolDictionaries:'' |
|
33 |
privateIn:ImageReader |
|
34 |
! |
|
35 |
||
189 | 36 |
!ImageReader primitiveDefinitions! |
37 |
%{ |
|
1891 | 38 |
|
6062 | 39 |
# define STDC_HEADERS |
189 | 40 |
#ifndef _STDIO_H_INCLUDED_ |
41 |
# include <stdio.h> |
|
42 |
# define _STDIO_H_INCLUDED_ |
|
43 |
#endif |
|
5973 | 44 |
|
6061 | 45 |
#if defined(__osx__) |
6062 | 46 |
# include <stdlib.h> |
6061 | 47 |
# define _MALLOC_H_INCLUDED_ |
48 |
#endif |
|
49 |
||
4401 | 50 |
#ifndef _MALLOC_H_INCLUDED_ |
5973 | 51 |
# if !defined(FREEBSD) |
6061 | 52 |
# include <malloc.h> |
53 |
# define _MALLOC_H_INCLUDED_ |
|
5527 | 54 |
# endif |
4401 | 55 |
#endif |
2423
416882dbf8cf
changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
56 |
|
416882dbf8cf
changes for egcs (__new in stdio.h)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
57 |
|
189 | 58 |
%} |
59 |
! ! |
|
60 |
||
89 | 61 |
!ImageReader primitiveFunctions! |
0 | 62 |
%{ |
63 |
||
64 |
/* |
|
65 |
* ccitt decompression |
|
66 |
*/ |
|
67 |
static short *whiteCountTable; |
|
68 |
static char *whiteShiftTable; |
|
69 |
static short *blackCountTable; |
|
70 |
static char *blackShiftTable; |
|
71 |
||
72 |
struct ccitt_def { |
|
73 |
unsigned short bits; |
|
74 |
short nBits; |
|
75 |
}; |
|
76 |
||
4714 | 77 |
static struct ccitt_def |
0 | 78 |
whiteDef[] = { |
79 |
{ 0x3500, 8 }, /* 0 */ |
|
80 |
{ 0x1c00, 6 }, |
|
81 |
{ 0x7000, 4 }, |
|
82 |
{ 0x8000, 4 }, |
|
83 |
{ 0xb000, 4 }, |
|
84 |
{ 0xc000, 4 }, |
|
85 |
{ 0xe000, 4 }, |
|
86 |
{ 0xf000, 4 }, |
|
87 |
{ 0x9800, 5 }, |
|
88 |
{ 0xA000, 5 }, |
|
89 |
{ 0x3800, 5 }, /* 10 */ |
|
90 |
{ 0x4000, 5 }, |
|
91 |
{ 0x2000, 6 }, |
|
92 |
{ 0x0c00, 6 }, |
|
93 |
{ 0xd000, 6 }, |
|
94 |
{ 0xd400, 6 }, |
|
95 |
{ 0xa800, 6 }, |
|
96 |
{ 0xac00, 6 }, |
|
97 |
{ 0x4e00, 7 }, |
|
98 |
{ 0x1800, 7 }, |
|
99 |
{ 0x1000, 7 }, /* 20 */ |
|
100 |
{ 0x2e00, 7 }, |
|
101 |
{ 0x0600, 7 }, |
|
102 |
{ 0x0800, 7 }, |
|
103 |
{ 0x5000, 7 }, |
|
104 |
{ 0x5600, 7 }, |
|
105 |
{ 0x2600, 7 }, |
|
106 |
{ 0x4800, 7 }, |
|
107 |
{ 0x3000, 7 }, |
|
108 |
{ 0x0200, 8 }, |
|
4714 | 109 |
{ 0x0300, 8 }, /* 30 */ |
110 |
{ 0x1a00, 8 }, |
|
111 |
{ 0x1b00, 8 }, |
|
112 |
{ 0x1200, 8 }, |
|
113 |
{ 0x1300, 8 }, |
|
114 |
{ 0x1400, 8 }, |
|
115 |
{ 0x1500, 8 }, |
|
116 |
{ 0x1600, 8 }, |
|
117 |
{ 0x1700, 8 }, |
|
118 |
{ 0x2800, 8 }, |
|
0 | 119 |
{ 0x2900, 8 }, /* 40 */ |
4714 | 120 |
{ 0x2a00, 8 }, |
121 |
{ 0x2b00, 8 }, |
|
122 |
{ 0x2c00, 8 }, |
|
123 |
{ 0x2d00, 8 }, |
|
124 |
{ 0x0400, 8 }, |
|
125 |
{ 0x0500, 8 }, |
|
126 |
{ 0x0a00, 8 }, |
|
127 |
{ 0x0b00, 8 }, |
|
128 |
{ 0x5200, 8 }, |
|
0 | 129 |
{ 0x5300, 8 }, /* 50 */ |
4714 | 130 |
{ 0x5400, 8 }, |
131 |
{ 0x5500, 8 }, |
|
132 |
{ 0x2400, 8 }, |
|
133 |
{ 0x2500, 8 }, |
|
134 |
{ 0x5800, 8 }, |
|
135 |
{ 0x5900, 8 }, |
|
136 |
{ 0x5a00, 8 }, |
|
137 |
{ 0x5b00, 8 }, |
|
138 |
{ 0x4a00, 8 }, |
|
0 | 139 |
{ 0x4b00, 8 }, /* 60 */ |
4714 | 140 |
{ 0x3200, 8 }, |
141 |
{ 0x3300, 8 }, |
|
142 |
{ 0x3400, 8 }, |
|
0 | 143 |
/* ---------------- */ |
144 |
{ 0xd800, 5 }, /* 64 */ |
|
145 |
{ 0x9000, 5 }, /* 128 */ |
|
146 |
{ 0x5c00, 6 }, /* 192 */ |
|
147 |
{ 0x6e00, 7 }, /* 256 */ |
|
148 |
{ 0x3600, 8 }, /* 320 */ |
|
149 |
{ 0x3700, 8 }, |
|
150 |
{ 0x6400, 8 }, |
|
151 |
{ 0x6500, 8 }, |
|
152 |
{ 0x6800, 8 }, |
|
153 |
{ 0x6700, 8 }, /* 640 */ |
|
154 |
{ 0x6600, 9 }, /* 704 */ |
|
155 |
{ 0x6680, 9 }, |
|
156 |
{ 0x6900, 9 }, |
|
157 |
{ 0x6980, 9 }, |
|
158 |
{ 0x6a00, 9 }, |
|
159 |
{ 0x6a80, 9 }, |
|
160 |
{ 0x6b00, 9 }, |
|
161 |
{ 0x6b80, 9 }, |
|
162 |
{ 0x6c00, 9 }, |
|
163 |
{ 0x6c80, 9 }, |
|
164 |
{ 0x6d00, 9 }, |
|
165 |
{ 0x6d80, 9 }, |
|
166 |
{ 0x4c00, 9 }, |
|
167 |
{ 0x4c80, 9 }, |
|
168 |
{ 0x4d00, 9 }, /* 1600 */ |
|
169 |
{ 0x6000, 6 }, /* 1664 */ |
|
170 |
{ 0x4d80, 9 }, /* 1728 */ |
|
171 |
/* -------------------------------- */ |
|
172 |
{ 0x0100, 11 }, /* 1792 */ |
|
173 |
{ 0x0180, 11 }, |
|
174 |
{ 0x01a0, 11 }, /* 1920 */ |
|
175 |
{ 0x0120, 12 }, /* 1984 */ |
|
176 |
{ 0x0130, 12 }, |
|
177 |
{ 0x0140, 12 }, |
|
178 |
{ 0x0150, 12 }, |
|
179 |
{ 0x0160, 12 }, |
|
180 |
{ 0x0170, 12 }, |
|
181 |
{ 0x01c0, 12 }, |
|
182 |
{ 0x01d0, 12 }, |
|
183 |
{ 0x01e0, 12 }, |
|
184 |
{ 0x01f0, 12 }, /* 2560 */ |
|
185 |
/* -------------------------------- */ |
|
186 |
{ 0x0010, 12 }, /* EOL */ |
|
187 |
}; |
|
188 |
||
4714 | 189 |
static struct ccitt_def |
0 | 190 |
blackDef[] = { |
191 |
{ 0x0dc0, 10 }, /* 0 */ |
|
192 |
{ 0x4000, 3 }, |
|
193 |
{ 0xc000, 2 }, |
|
194 |
{ 0x8000, 2 }, |
|
195 |
{ 0x6000, 3 }, |
|
196 |
{ 0x3000, 4 }, |
|
197 |
{ 0x2000, 4 }, |
|
198 |
{ 0x1800, 5 }, |
|
199 |
{ 0x1400, 6 }, |
|
200 |
{ 0x1000, 6 }, |
|
201 |
{ 0x0800, 7 }, /* 10 */ |
|
202 |
{ 0x0a00, 7 }, |
|
203 |
{ 0x0e00, 7 }, |
|
204 |
{ 0x0400, 8 }, |
|
205 |
{ 0x0700, 8 }, |
|
206 |
{ 0x0c00, 9 }, |
|
207 |
{ 0x05c0, 10 }, |
|
208 |
{ 0x0600, 10 }, |
|
209 |
{ 0x0200, 10 }, |
|
210 |
{ 0x0ce0, 11 }, |
|
211 |
{ 0x0d00, 11 }, /* 20 */ |
|
212 |
{ 0x0d80, 11 }, |
|
213 |
{ 0x06e0, 11 }, |
|
214 |
{ 0x0500, 11 }, |
|
215 |
{ 0x02e0, 11 }, |
|
216 |
{ 0x0300, 11 }, |
|
217 |
{ 0x0ca0, 12 }, |
|
218 |
{ 0x0cb0, 12 }, |
|
219 |
{ 0x0cc0, 12 }, |
|
4714 | 220 |
{ 0x0cd0, 12 }, |
0 | 221 |
{ 0x0680, 12 }, /* 30 */ |
4714 | 222 |
{ 0x0690, 12 }, |
223 |
{ 0x06a0, 12 }, |
|
224 |
{ 0x06b0, 12 }, |
|
225 |
{ 0x0d20, 12 }, |
|
226 |
{ 0x0d30, 12 }, |
|
227 |
{ 0x0d40, 12 }, |
|
228 |
{ 0x0d50, 12 }, |
|
229 |
{ 0x0d60, 12 }, |
|
0 | 230 |
{ 0x0d70, 12 }, |
4714 | 231 |
{ 0x06c0, 12 }, /* 40 */ |
232 |
{ 0x06d0, 12 }, |
|
233 |
{ 0x0da0, 12 }, |
|
234 |
{ 0x0db0, 12 }, |
|
235 |
{ 0x0540, 12 }, |
|
236 |
{ 0x0550, 12 }, |
|
237 |
{ 0x0560, 12 }, |
|
238 |
{ 0x0570, 12 }, |
|
239 |
{ 0x0640, 12 }, |
|
0 | 240 |
{ 0x0650, 12 }, |
4714 | 241 |
{ 0x0520, 12 }, /* 50 */ |
242 |
{ 0x0530, 12 }, |
|
243 |
{ 0x0240, 12 }, |
|
244 |
{ 0x0370, 12 }, |
|
245 |
{ 0x0380, 12 }, |
|
246 |
{ 0x0270, 12 }, |
|
247 |
{ 0x0280, 12 }, |
|
248 |
{ 0x0580, 12 }, |
|
249 |
{ 0x0590, 12 }, |
|
0 | 250 |
{ 0x02b0, 12 }, |
4714 | 251 |
{ 0x02c0, 12 }, /* 60 */ |
252 |
{ 0x05a0, 12 }, |
|
253 |
{ 0x0660, 12 }, |
|
254 |
{ 0x0670, 12 }, |
|
0 | 255 |
/* ---------------- */ |
256 |
{ 0x03c0, 10 }, /* 64 */ |
|
257 |
{ 0x0c80, 12 }, /* 128 */ |
|
258 |
{ 0x0c90, 12 }, /* 192 */ |
|
259 |
{ 0x05b0, 12 }, /* 256 */ |
|
260 |
{ 0x0330, 12 }, /* 320 */ |
|
261 |
{ 0x0340, 12 }, |
|
262 |
{ 0x0350, 12 }, /* 448 */ |
|
263 |
{ 0x0360, 13 }, /* 512 */ |
|
264 |
{ 0x0368, 13 }, |
|
265 |
{ 0x0250, 13 }, /* 640 */ |
|
266 |
{ 0x0258, 13 }, /* 704 */ |
|
267 |
{ 0x0260, 13 }, |
|
268 |
{ 0x0268, 13 }, |
|
269 |
{ 0x0390, 13 }, |
|
270 |
{ 0x0398, 13 }, |
|
271 |
{ 0x03a0, 13 }, |
|
272 |
{ 0x03a8, 13 }, |
|
273 |
{ 0x03b0, 13 }, |
|
274 |
{ 0x03b8, 13 }, |
|
275 |
{ 0x0290, 13 }, |
|
276 |
{ 0x0298, 13 }, |
|
277 |
{ 0x02a0, 13 }, |
|
278 |
{ 0x02a8, 13 }, |
|
279 |
{ 0x02d0, 13 }, |
|
280 |
{ 0x02d8, 13 }, /* 1600 */ |
|
281 |
{ 0x0320, 13 }, /* 1664 */ |
|
282 |
{ 0x0328, 13 }, /* 1728 */ |
|
283 |
/* -------------------------------- */ |
|
284 |
}; |
|
285 |
||
6761 | 286 |
static void |
0 | 287 |
initCCITTTables() { |
7539 | 288 |
register int cnt, bits, value; |
0 | 289 |
int nBits, index; |
290 |
||
291 |
if (whiteCountTable != (short *)0) return; |
|
292 |
||
293 |
whiteCountTable = (short *) malloc(sizeof(short) * 8192); |
|
12 | 294 |
if (! whiteCountTable) return; |
0 | 295 |
whiteShiftTable = (char *) malloc(sizeof(char) * 8192); |
12 | 296 |
if (! whiteShiftTable) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
297 |
goto fail1; |
12 | 298 |
} |
0 | 299 |
blackCountTable = (short *) malloc(sizeof(short) * 8192); |
12 | 300 |
if (! blackCountTable) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
301 |
goto fail2; |
12 | 302 |
} |
0 | 303 |
blackShiftTable = (char *) malloc(sizeof(char) * 8192); |
12 | 304 |
if (! blackShiftTable) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
305 |
free(blackCountTable); blackCountTable = (short *)0; |
95 | 306 |
fail2: |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
307 |
free(whiteShiftTable); whiteShiftTable = (char *)0; |
95 | 308 |
fail1: |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
309 |
free(whiteCountTable); whiteCountTable = (short *)0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
310 |
return; |
12 | 311 |
} |
0 | 312 |
|
313 |
for (index = 0; index < 8192; index++) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
314 |
whiteCountTable[index] = -1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
315 |
blackCountTable[index] = -1; |
0 | 316 |
} |
317 |
||
318 |
for (value = 0; value <= 63; value++) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
319 |
nBits = whiteDef[value].nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
320 |
bits = whiteDef[value].bits >> 3; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
321 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
322 |
whiteCountTable[bits] = value; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
323 |
whiteShiftTable[bits] = nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
324 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
325 |
nBits = blackDef[value].nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
326 |
bits = blackDef[value].bits >> 3; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
327 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
328 |
blackCountTable[bits] = value; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
329 |
blackShiftTable[bits] = nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
330 |
} |
0 | 331 |
} |
332 |
index = value; |
|
333 |
||
334 |
for (; value <= 1728; value += 64) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
335 |
nBits = whiteDef[index].nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
336 |
bits = whiteDef[index].bits >> 3; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
337 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
338 |
whiteCountTable[bits] = value; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
339 |
whiteShiftTable[bits] = nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
340 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
341 |
nBits = blackDef[index].nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
342 |
bits = blackDef[index].bits >> 3; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
343 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
344 |
blackCountTable[bits] = value; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
345 |
blackShiftTable[bits] = nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
346 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
347 |
index++; |
0 | 348 |
} |
349 |
||
350 |
for (; value <= 2560; value += 64) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
351 |
nBits = whiteDef[index].nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
352 |
bits = whiteDef[index].bits >> 3; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
353 |
for (cnt = 1 << (13 - nBits); cnt; cnt--, bits++) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
354 |
whiteCountTable[bits] = value; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
355 |
whiteShiftTable[bits] = nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
356 |
blackCountTable[bits] = value; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
357 |
blackShiftTable[bits] = nBits; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
358 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
359 |
index++; |
0 | 360 |
} |
361 |
} |
|
362 |
||
4714 | 363 |
static short |
0 | 364 |
leftBits[] = { |
365 |
0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF |
|
366 |
}; |
|
367 |
||
189 | 368 |
static int |
7539 | 369 |
__decodeCCITTgroup3__(unsigned char *from, unsigned char *to, int len) |
0 | 370 |
{ |
7539 | 371 |
register int cnt; |
0 | 372 |
register short *countPtr; |
373 |
register char *shiftPtr; |
|
7539 | 374 |
unsigned int bits, bits13; |
0 | 375 |
int shift, outCount, nBitsLess13; |
376 |
int outBitOffset; |
|
377 |
int nLeft, t; |
|
378 |
||
8107 | 379 |
if (! whiteCountTable) { |
380 |
initCCITTTables(); |
|
381 |
if (! whiteCountTable) return 0; /* malloc failed */ |
|
382 |
} |
|
0 | 383 |
|
384 |
countPtr = whiteCountTable; |
|
385 |
shiftPtr = whiteShiftTable; |
|
386 |
outCount = 0; |
|
387 |
outBitOffset = 0; |
|
388 |
bits = *from++; |
|
389 |
bits = (bits << 8) | *from++; |
|
390 |
nBitsLess13 = 3; |
|
8107 | 391 |
|
0 | 392 |
for (;;) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
393 |
bits13 = (bits >> nBitsLess13) & 0x1FFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
394 |
cnt = countPtr[bits13]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
395 |
if (cnt < 0) return 1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
396 |
shift = shiftPtr[bits13]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
397 |
outCount += cnt; |
8107 | 398 |
if (outCount > len) { |
399 |
fprintf(stderr, "CCITT buffer overrun\n"); |
|
400 |
return 0; |
|
401 |
} |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
402 |
if (countPtr == blackCountTable) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
403 |
/* toggle if it was a terminating code */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
404 |
if (cnt < 64) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
405 |
countPtr = whiteCountTable; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
406 |
shiftPtr = whiteShiftTable; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
407 |
} |
0 | 408 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
409 |
/* draw cnt black bits */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
410 |
if (cnt) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
411 |
if (outBitOffset) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
412 |
nLeft = 8 - outBitOffset; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
413 |
if (cnt < nLeft) nLeft = cnt; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
414 |
t = leftBits[nLeft] >> outBitOffset; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
415 |
*to |= t; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
416 |
cnt -= nLeft; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
417 |
outBitOffset += nLeft; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
418 |
if (outBitOffset >= 8) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
419 |
to++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
420 |
outBitOffset -= 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
421 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
422 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
423 |
if (cnt > 256) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
424 |
while ((INT)to & 3) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
425 |
*to++ = 0xFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
426 |
cnt -= 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
427 |
} |
4401 | 428 |
#if __POINTER_SIZE__ == 8 |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
429 |
while ((INT)to & 7) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
430 |
*to++ = 0xFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
431 |
cnt -= 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
432 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
433 |
while (cnt >= 64) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
434 |
(*(INT *)to) = 0xFFFFFFFFFFFFFFFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
435 |
to += 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
436 |
cnt -= 64; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
437 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
438 |
if (cnt >= 32) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
439 |
(*(long *)to) = 0xFFFFFFFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
440 |
to += 4; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
441 |
cnt -= 32; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
442 |
} |
4401 | 443 |
#else |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
444 |
while ((INT)to & 3) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
445 |
*to++ = 0xFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
446 |
cnt -= 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
447 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
448 |
while (cnt >= 32) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
449 |
(*(long *)to) = 0xFFFFFFFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
450 |
to += 4; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
451 |
cnt -= 32; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
452 |
} |
4401 | 453 |
#endif |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
454 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
455 |
while (cnt >= 8) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
456 |
*to++ = 0xFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
457 |
cnt -= 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
458 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
459 |
*to |= leftBits[cnt]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
460 |
outBitOffset += cnt; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
461 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
462 |
} else { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
463 |
/* toggle if it was a terminating code */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
464 |
if (cnt < 64) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
465 |
countPtr = blackCountTable; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
466 |
shiftPtr = blackShiftTable; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
467 |
} |
0 | 468 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
469 |
/* skip cnt bits */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
470 |
to += cnt >> 3; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
471 |
outBitOffset += cnt & 7; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
472 |
if (outBitOffset >= 8) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
473 |
to++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
474 |
outBitOffset -= 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
475 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
476 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
477 |
if (outCount >= len) return 1; |
0 | 478 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
479 |
nBitsLess13 -= shift; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
480 |
while (nBitsLess13 < 0) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
481 |
bits = (bits << 8) | *from++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
482 |
nBitsLess13 += 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
483 |
} |
0 | 484 |
} |
485 |
} |
|
486 |
||
487 |
/* |
|
488 |
* LZW decompression |
|
489 |
*/ |
|
490 |
struct buffer { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
491 |
struct buffer *prev; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
492 |
unsigned char chars[8192 - 4]; |
0 | 493 |
}; |
189 | 494 |
|
4714 | 495 |
static int |
7539 | 496 |
__decodeLZW__(unsigned char *from, unsigned char *to, int inCount, int fromSize, int toSize) |
0 | 497 |
{ |
498 |
register unsigned code; |
|
12 | 499 |
unsigned char **strings; |
500 |
short *stringLen; |
|
0 | 501 |
struct buffer *scratchBuffer; |
502 |
struct buffer *newBuffer; |
|
503 |
unsigned char *scratchPtr; |
|
504 |
int nScratch; |
|
1262 | 505 |
unsigned nextCode; |
506 |
int oldCode = -1; |
|
0 | 507 |
register unsigned bits; |
508 |
int nBits, mask, shift; |
|
509 |
int i; |
|
510 |
int len; |
|
511 |
int codeLen = 9; |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
512 |
unsigned char *fromEnd, *toEnd; |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
513 |
int ret = 1; /* return success */ |
0 | 514 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
515 |
fromEnd = from + fromSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
516 |
toEnd = to + toSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
517 |
|
0 | 518 |
scratchBuffer = (struct buffer *)malloc(sizeof(struct buffer)); |
12 | 519 |
if (! scratchBuffer) return 0; |
46 | 520 |
|
12 | 521 |
strings = (unsigned char **)malloc(sizeof(unsigned char *) * 4096); |
522 |
if (! strings) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
523 |
free(scratchBuffer); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
524 |
return 0; |
12 | 525 |
} |
526 |
stringLen = (short *)malloc(sizeof(short) * 4096); |
|
527 |
if (! stringLen) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
528 |
free(strings); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
529 |
free(scratchBuffer); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
530 |
return 0; |
12 | 531 |
} |
532 |
||
0 | 533 |
scratchBuffer->prev = (struct buffer *)0; |
534 |
scratchPtr = scratchBuffer->chars; |
|
535 |
nScratch = sizeof(scratchBuffer->chars); |
|
536 |
||
537 |
for (i = 0; i < 256; i++) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
538 |
*scratchPtr = i; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
539 |
strings[i] = scratchPtr++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
540 |
stringLen[i] = 1; |
0 | 541 |
} |
542 |
||
543 |
nextCode = 258; |
|
544 |
nScratch -= 256; |
|
545 |
mask = 0x1FF; |
|
546 |
nBits = 0; |
|
547 |
bits = 0; |
|
548 |
while (inCount) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
549 |
/* fetch code */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
550 |
while (nBits < codeLen) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
551 |
bits = (bits<<8) | *from++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
552 |
inCount--; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
553 |
nBits += 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
554 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
555 |
shift = nBits - codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
556 |
code = (bits >> shift) & mask; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
557 |
bits &= ~(mask << shift); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
558 |
nBits -= codeLen; |
4714 | 559 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
560 |
if (code == 257) break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
561 |
if (code == 256) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
562 |
if (! inCount) |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
563 |
break; |
0 | 564 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
565 |
/* free stuff */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
566 |
while (scratchBuffer->prev) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
567 |
newBuffer = scratchBuffer; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
568 |
scratchBuffer = scratchBuffer->prev; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
569 |
free(newBuffer); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
570 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
571 |
/* reset everything */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
572 |
scratchPtr = scratchBuffer->chars + 256; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
573 |
nScratch = sizeof(scratchBuffer->chars) - 256; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
574 |
codeLen = 9; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
575 |
nextCode = 258; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
576 |
mask = 0x1FF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
577 |
/* fetch code */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
578 |
while (nBits < codeLen) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
579 |
bits = (bits<<8) | *from++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
580 |
inCount--; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
581 |
nBits += 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
582 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
583 |
shift = nBits - codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
584 |
code = (bits >> shift) & mask; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
585 |
bits &= ~(mask << shift); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
586 |
nBits -= codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
587 |
if (code == 257) break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
588 |
/* add to output */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
589 |
if (to >= toEnd) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
590 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
591 |
console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
592 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
593 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
594 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
595 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
596 |
*to++ = code; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
597 |
oldCode = code; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
598 |
} else { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
599 |
if (code < nextCode) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
600 |
/* writeString(string[code]) */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
601 |
len = stringLen[code]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
602 |
bcopy(strings[code], to, len); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
603 |
to += len; |
0 | 604 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
605 |
if (oldCode != -1) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
606 |
/* add( string[oldcode] + first(string[code]) ) */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
607 |
len = stringLen[oldCode] + 1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
608 |
if (nScratch < len) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
609 |
newBuffer = (struct buffer *)malloc(sizeof(struct buffer)); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
610 |
if (! newBuffer) goto out; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
611 |
newBuffer->prev = scratchBuffer; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
612 |
scratchBuffer = newBuffer; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
613 |
scratchPtr = scratchBuffer->chars; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
614 |
nScratch = sizeof(scratchBuffer->chars); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
615 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
616 |
stringLen[nextCode] = len; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
617 |
strings[nextCode] = scratchPtr; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
618 |
bcopy(strings[oldCode], scratchPtr, len-1); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
619 |
scratchPtr += len-1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
620 |
*scratchPtr++ = strings[code][0]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
621 |
nScratch -= len; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
622 |
nextCode++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
623 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
624 |
} else { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
625 |
if (oldCode == -1) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
626 |
/* bad input */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
627 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
628 |
goto out; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
629 |
} |
4714 | 630 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
631 |
/* writeString(string[oldCode] + first(string[oldCode]) ) */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
632 |
len = stringLen[oldCode]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
633 |
if ((to+len) >= toEnd) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
634 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
635 |
console_fprintf(stderr, "ImageReader [warning]: LZW outBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
636 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
637 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
638 |
goto out; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
639 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
640 |
bcopy(strings[oldCode], to, len); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
641 |
to += len; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
642 |
*to++ = strings[oldCode][0]; |
0 | 643 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
644 |
/* add( string[oldcode] + first(string[oldCode]) ) */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
645 |
len++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
646 |
if (nScratch < len) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
647 |
newBuffer = (struct buffer *)malloc(sizeof(struct buffer)); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
648 |
if (! newBuffer) goto out; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
649 |
newBuffer->prev = scratchBuffer; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
650 |
scratchBuffer = newBuffer; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
651 |
scratchPtr = scratchBuffer->chars; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
652 |
nScratch = sizeof(scratchBuffer->chars); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
653 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
654 |
stringLen[nextCode] = len; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
655 |
strings[nextCode] = scratchPtr; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
656 |
bcopy(strings[oldCode], scratchPtr, len-1); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
657 |
scratchPtr += len-1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
658 |
*scratchPtr++ = strings[oldCode][0]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
659 |
nScratch -= len; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
660 |
nextCode++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
661 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
662 |
oldCode = code; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
663 |
if (nextCode >= 511) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
664 |
if (nextCode == 511) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
665 |
codeLen = 10; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
666 |
mask = 0x3FF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
667 |
} else if (nextCode >= 1023) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
668 |
if (nextCode == 1023) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
669 |
codeLen = 11; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
670 |
mask = 0x7FF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
671 |
} else { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
672 |
if (nextCode == 2047) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
673 |
codeLen = 12; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
674 |
mask = 0xFFF; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
675 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
676 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
677 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
678 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
679 |
} |
0 | 680 |
} |
12 | 681 |
out: ; |
0 | 682 |
/* free stuff */ |
683 |
while (scratchBuffer) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
684 |
newBuffer = scratchBuffer; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
685 |
scratchBuffer = scratchBuffer->prev; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
686 |
free(newBuffer); |
0 | 687 |
} |
46 | 688 |
|
12 | 689 |
free(strings); |
690 |
free(stringLen); |
|
46 | 691 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
692 |
if (from > fromEnd) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
693 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
694 |
console_fprintf(stderr, "ImageReader [warning]: LZW inBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
695 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
696 |
ret = 0; |
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
697 |
} |
1262 | 698 |
return ret; |
0 | 699 |
} |
700 |
||
701 |
/* |
|
702 |
* delta decoding (TIFF predictor = 2) |
|
703 |
*/ |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
704 |
static void |
8101 | 705 |
__decodeDelta3__(register unsigned char *bytes, int width, int height) |
0 | 706 |
{ |
7539 | 707 |
register int w; |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
708 |
unsigned char r, g, b; |
0 | 709 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
710 |
while (height--) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
711 |
r = g = b = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
712 |
for (w = width; w; w--) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
713 |
r += *bytes; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
714 |
*bytes++ = r; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
715 |
g += *bytes; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
716 |
*bytes++ = g; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
717 |
b += *bytes; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
718 |
*bytes++ = b; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
719 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
720 |
} |
0 | 721 |
} |
722 |
||
46 | 723 |
/* |
8101 | 724 |
* delta decoding (TIFF predictor = 2) |
725 |
*/ |
|
726 |
static void |
|
727 |
__decodeDelta4__(register unsigned char *bytes, int width, int height) |
|
728 |
{ |
|
729 |
register int w; |
|
730 |
unsigned char r, g, b, a; |
|
731 |
||
732 |
while (height--) { |
|
733 |
r = g = b = a = 0; |
|
734 |
for (w = width; w; w--) { |
|
735 |
r += *bytes; |
|
736 |
*bytes++ = r; |
|
737 |
g += *bytes; |
|
738 |
*bytes++ = g; |
|
739 |
b += *bytes; |
|
740 |
*bytes++ = b; |
|
741 |
a += *bytes; |
|
742 |
*bytes++ = a; |
|
743 |
} |
|
744 |
} |
|
745 |
} |
|
746 |
||
747 |
/* |
|
46 | 748 |
* GIF decompression |
749 |
*/ |
|
189 | 750 |
static int |
7539 | 751 |
__decodeGIF__(unsigned char *from, unsigned char *to, int inCount, int initialCodeLen, int fromSize, int toSize) |
0 | 752 |
{ |
753 |
register unsigned code; |
|
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
754 |
// #define GIF_PREFIX_SUFFIX_SIZE 4096 |
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
755 |
#define GIF_PREFIX_SUFFIX_SIZE (4096*2) |
12 | 756 |
unsigned short *prefix; |
757 |
unsigned short *suffix; |
|
758 |
unsigned short *outCode; |
|
0 | 759 |
int outCount; |
760 |
unsigned maxCode, oldCode, fin, inCode, curCode; |
|
761 |
register unsigned bits; |
|
762 |
register int nBits, mask, shift; |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
763 |
int ret = 1; |
0 | 764 |
int i; |
765 |
int len; |
|
766 |
int endCode, clearCode, freeCode; |
|
767 |
int codeLen = initialCodeLen; |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
768 |
unsigned char *fromEnd, *toEnd; |
12 | 769 |
static int ranges[] = {0, 1, 2, 4, 8, 16, 32, 64, |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
770 |
128, 256, 512, 1024, 2048 }; |
0 | 771 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
772 |
fromEnd = from + fromSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
773 |
toEnd = to + toSize; |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
774 |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
775 |
if ((unsigned)codeLen > 12) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
776 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
777 |
console_fprintf(stderr, "ImageReader [warning]: GIF bad codelen (>12)\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
778 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
779 |
return 0; |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
780 |
} |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
781 |
prefix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE); |
12 | 782 |
if (! prefix) return 0; |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
783 |
suffix = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE); |
12 | 784 |
if (! suffix) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
785 |
free(prefix); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
786 |
return 0; |
12 | 787 |
} |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
788 |
outCode = (unsigned short *)malloc(sizeof(short) * GIF_PREFIX_SUFFIX_SIZE); |
12 | 789 |
if (! outCode) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
790 |
free(prefix); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
791 |
free(suffix); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
792 |
return 0; |
12 | 793 |
} |
0 | 794 |
clearCode = ranges[codeLen]; /* 256 */ |
795 |
endCode = clearCode + 1; /* 257 */ |
|
796 |
freeCode = clearCode + 2; /* 258 */ |
|
797 |
maxCode = clearCode << 1; /* 512 */ |
|
798 |
outCount = 0; |
|
799 |
||
800 |
mask = maxCode - 1; /* 1FF */ |
|
801 |
nBits = 0; |
|
802 |
bits = 0; |
|
803 |
while (inCount) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
804 |
/* fetch code */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
805 |
while (nBits < codeLen) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
806 |
bits = bits | (*from++ << nBits); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
807 |
inCount--; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
808 |
nBits += 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
809 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
810 |
if (inCount <= 0) |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
811 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
812 |
code = bits & mask; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
813 |
bits >>= codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
814 |
nBits -= codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
815 |
if (code == endCode) break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
816 |
if (code == clearCode) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
817 |
if (inCount <= 0) |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
818 |
break; |
0 | 819 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
820 |
codeLen = initialCodeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
821 |
maxCode = clearCode<<1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
822 |
mask = maxCode - 1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
823 |
freeCode = clearCode + 2; |
0 | 824 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
825 |
/* fetch code */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
826 |
while (nBits < codeLen) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
827 |
bits = bits | (*from++ << nBits); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
828 |
inCount--; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
829 |
nBits += 8; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
830 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
831 |
if (inCount <= 0) |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
832 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
833 |
code = bits & mask; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
834 |
bits >>= codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
835 |
nBits -= codeLen; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
836 |
if (code == endCode) break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
837 |
/* add to output */ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
838 |
if (to >= toEnd) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
839 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
840 |
console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
841 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
842 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
843 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
844 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
845 |
*to++ = code; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
846 |
oldCode = fin = curCode = code; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
847 |
} else { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
848 |
curCode = inCode = code; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
849 |
if (curCode >= freeCode) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
850 |
curCode = oldCode; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
851 |
outCode[outCount++] = fin; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
852 |
} |
0 | 853 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
854 |
while (curCode >= clearCode) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
855 |
if (outCount > 1024) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
856 |
goto out; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
857 |
} |
2261 | 858 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
859 |
/* debugging and protecting myself from overwrites */ |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
860 |
if (curCode > (GIF_PREFIX_SUFFIX_SIZE-1)) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
861 |
if (@global(InfoPrinting) == true) { |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
862 |
console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (code > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1)); |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
863 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
864 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
865 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
866 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
867 |
outCode[outCount++] = suffix[curCode]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
868 |
curCode = prefix[curCode]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
869 |
} |
0 | 870 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
871 |
fin = curCode; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
872 |
outCode[outCount++] = fin; |
0 | 873 |
|
2014
bcae1c2c32e4
fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
874 |
#if 0 |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
875 |
if ((to+outCount) >= toEnd) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
876 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
877 |
console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
878 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
879 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
880 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
881 |
} |
2014
bcae1c2c32e4
fixed destination-array boundary check (in GIF-decode)
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
882 |
#endif |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
883 |
for (i = outCount - 1; i >= 0; i--) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
884 |
if (to >= toEnd) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
885 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
886 |
console_fprintf(stderr, "ImageReader [warning]: GIF outBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
887 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
888 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
889 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
890 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
891 |
*to++ = outCode[i]; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
892 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
893 |
outCount = 0; |
0 | 894 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
895 |
/* debugging and protecting myself from overwrites */ |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
896 |
if (freeCode > (GIF_PREFIX_SUFFIX_SIZE-1)) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
897 |
if (@global(InfoPrinting) == true) { |
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
898 |
console_fprintf(stderr, "ImageReader [warning]: GIF corrupted input (freeCode > %d)\n", (GIF_PREFIX_SUFFIX_SIZE-1)); |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
899 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
900 |
ret = 0; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
901 |
break; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
902 |
} |
2261 | 903 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
904 |
prefix[freeCode] = oldCode; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
905 |
suffix[freeCode] = fin; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
906 |
oldCode = inCode; |
0 | 907 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
908 |
freeCode++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
909 |
if (freeCode >= maxCode) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
910 |
if (codeLen < 12) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
911 |
codeLen++; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
912 |
maxCode *= 2; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
913 |
mask = (1 << codeLen) - 1; |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
914 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
915 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
916 |
} |
0 | 917 |
} |
12 | 918 |
out: ; |
919 |
free(prefix); |
|
920 |
free(suffix); |
|
921 |
free(outCode); |
|
46 | 922 |
|
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
923 |
if (from > fromEnd) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
924 |
if (@global(InfoPrinting) == true) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
925 |
console_fprintf(stderr, "ImageReader [warning]: GIF inBuffer overrun\n"); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
926 |
} |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
927 |
ret = 0; |
1988
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
928 |
} |
528dbff6ca26
do not overwrite provided output buffer when decompressing
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
929 |
return ret; |
0 | 930 |
} |
931 |
||
932 |
%} |
|
77 | 933 |
! ! |
105 | 934 |
|
1167 | 935 |
!ImageReader class methodsFor:'documentation'! |
105 | 936 |
|
937 |
copyright |
|
938 |
" |
|
939 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
940 |
All Rights Reserved |
|
941 |
||
942 |
This software is furnished under a license and may be used |
|
943 |
only in accordance with the terms of that license and with the |
|
944 |
inclusion of the above copyright notice. This software may not |
|
945 |
be provided or otherwise made available to, or used by, any |
|
946 |
other person. No title to or ownership of the software is |
|
947 |
hereby transferred. |
|
948 |
" |
|
949 |
! |
|
950 |
||
951 |
documentation |
|
952 |
" |
|
7172 | 953 |
Abstract class to provide common functions for image-readers/writers. |
954 |
(i.e. TIFFReader, GIFReader etc.). |
|
7182 | 955 |
|
956 |
In contrast to what the name suggests, ImageReaders are supposed to support |
|
7172 | 957 |
both reading and writing of images |
6058 | 958 |
(i.e. the name is somewhat outdated, but kept for historic and backward |
7182 | 959 |
compatibility reasons). |
7172 | 960 |
They provide functionality similar to Squeak's ImageReaderWriter classes. |
105 | 961 |
|
962 |
ImageReaders are created temporary to read an image from a stream. |
|
618 | 963 |
Normally, they are not directly used - instead, the image class is |
964 |
asked to read some file, and return an instance for it: |
|
7182 | 965 |
Image fromFile:<someFileName> |
7172 | 966 |
The Image class will guess the image's format and forward the task to |
618 | 967 |
some concrete ImageReaderClass. |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
968 |
If that class thinks, that the file's format is incorrect, |
6508 | 969 |
other readers are tried until some reader class finds the file's format acceptable. |
618 | 970 |
|
971 |
Image readers read the stream and collect all relevant information internally. |
|
118 | 972 |
Once done with reading, the actual image object is created and |
973 |
data filled in from the imageReaders collected info. |
|
105 | 974 |
|
618 | 975 |
See the implementation of #fromStream: in concrete subclasses. |
105 | 976 |
The public interfaces are: |
7182 | 977 |
<ConcreteReaderClass> fromFile:aFilename |
105 | 978 |
or: |
7182 | 979 |
<ConcreteReaderClass> fromStream:aStream |
105 | 980 |
|
6058 | 981 |
If you add a new reader, don't forget to add the method #isValidImageFile: |
618 | 982 |
which should return true, if this reader supports reading a given file. |
6058 | 983 |
|
984 |
If your new reader class supports writing files, don't forget to add |
|
618 | 985 |
#canRepresent:anImage and return true from this method. |
593 | 986 |
|
7172 | 987 |
writing: |
7182 | 988 |
tell the image, to save itself, via <image> saveOn:fileName |
989 |
or <image> saveOn:fileName using:<readerClass> |
|
990 |
||
593 | 991 |
[See also:] |
7182 | 992 |
Image Icon Form |
611 | 993 |
|
994 |
[author:] |
|
7182 | 995 |
Claus Gittinger |
105 | 996 |
" |
997 |
! ! |
|
998 |
||
1358 | 999 |
!ImageReader class methodsFor:'instance creation'! |
1000 |
||
1001 |
new |
|
1002 |
^ self basicNew initialize |
|
1003 |
||
1004 |
"Created: 18.2.1997 / 17:08:45 / cg" |
|
1005 |
! ! |
|
1006 |
||
1167 | 1007 |
!ImageReader class methodsFor:'cleanup'! |
105 | 1008 |
|
285 | 1009 |
lowSpaceCleanup |
1010 |
"cleanup things we do not need" |
|
118 | 1011 |
|
285 | 1012 |
ReverseBits := nil |
105 | 1013 |
! ! |
1014 |
||
1167 | 1015 |
!ImageReader class methodsFor:'constants'! |
105 | 1016 |
|
1017 |
reverseBits |
|
1018 |
"return a table filled with bit reverse information. |
|
1019 |
To convert from msbit-first to lsbit-first bytes, use |
|
1020 |
the value as index into the table, retrieving the reverse |
|
1021 |
value. Since indexing must start at 1, use (value + 1) as |
|
1022 |
index." |
|
1023 |
||
1024 |
|val "{ Class: SmallInteger }" | |
|
1025 |
||
1026 |
ReverseBits isNil ifTrue:[ |
|
153 | 1027 |
ReverseBits := ByteArray uninitializedNew:256. |
105 | 1028 |
0 to:255 do:[:i | |
1029 |
val := 0. |
|
1030 |
(i bitTest:16r01) ifTrue:[val := val bitOr:16r80]. |
|
1031 |
(i bitTest:16r02) ifTrue:[val := val bitOr:16r40]. |
|
1032 |
(i bitTest:16r04) ifTrue:[val := val bitOr:16r20]. |
|
1033 |
(i bitTest:16r08) ifTrue:[val := val bitOr:16r10]. |
|
1034 |
(i bitTest:16r10) ifTrue:[val := val bitOr:16r08]. |
|
1035 |
(i bitTest:16r20) ifTrue:[val := val bitOr:16r04]. |
|
1036 |
(i bitTest:16r40) ifTrue:[val := val bitOr:16r02]. |
|
1037 |
(i bitTest:16r80) ifTrue:[val := val bitOr:16r01]. |
|
1038 |
ReverseBits at:(i + 1) put:val |
|
1039 |
] |
|
1040 |
]. |
|
1041 |
^ ReverseBits |
|
1042 |
! ! |
|
1043 |
||
1167 | 1044 |
!ImageReader class methodsFor:'decompression support'! |
105 | 1045 |
|
8110 | 1046 |
_decompressCCITT3From:src count:inCount into:dst startingAt:dstIndexIn |
1047 |
|srcIndex dstIndex countTable shiftTable |
|
1048 |
outCount outBitOffset bits nBitsLess13 bits13 cnt shift |
|
1049 |
nLeft t leftBits| |
|
1050 |
||
1051 |
WhiteCountTable isNil ifTrue:[ |
|
1052 |
self initCCITTTables. |
|
1053 |
]. |
|
1054 |
countTable := WhiteCountTable. |
|
1055 |
shiftTable := WhiteShiftTable. |
|
1056 |
leftBits := #[ 0 16r80 16rC0 16rE0 16rF0 16rF8 16rFC 16rFE 16rFF ]. |
|
1057 |
||
1058 |
srcIndex := 1. |
|
1059 |
dstIndex := dstIndexIn. |
|
1060 |
||
1061 |
outCount := 0. |
|
1062 |
outBitOffset := 0. |
|
1063 |
bits := ((src at:srcIndex) bitShift:8) bitOr:(src at:srcIndex+1). |
|
1064 |
srcIndex := srcIndex + 2. |
|
1065 |
nBitsLess13 := 3. |
|
1066 |
||
1067 |
[ |
|
1068 |
bits13 := (bits rightShift: nBitsLess13) bitAnd: 16r1FFF. |
|
1069 |
cnt := countTable at:(bits13+1). |
|
1070 |
cnt < 0 ifTrue:[ |
|
1071 |
^ dstIndex |
|
1072 |
]. |
|
1073 |
shift := shiftTable at:(bits13+1). |
|
1074 |
outCount := outCount + cnt. |
|
1075 |
||
1076 |
countTable == BlackCountTable ifTrue:[ |
|
1077 |
"/ toggle if it was a terminating code |
|
1078 |
cnt < 64 ifTrue:[ |
|
1079 |
countTable := WhiteCountTable. |
|
1080 |
shiftTable := WhiteShiftTable |
|
1081 |
]. |
|
1082 |
"/ draw cnt black bits |
|
1083 |
cnt ~~ 0 ifTrue:[ |
|
1084 |
outBitOffset > 0 ifTrue:[ |
|
1085 |
nLeft := 8 - outBitOffset. |
|
1086 |
(cnt < nLeft) ifTrue:[ nLeft := cnt ]. |
|
1087 |
t := (leftBits at:(nLeft+1)) rightShift: outBitOffset. |
|
1088 |
dst at:dstIndex put: ((dst at:dstIndex) bitOr:(t bitAnd:16rFF)). |
|
1089 |
cnt := cnt - nLeft. |
|
1090 |
outBitOffset := outBitOffset + nLeft. |
|
1091 |
(outBitOffset >= 8) ifTrue:[ |
|
1092 |
dstIndex := dstIndex + 1. |
|
1093 |
outBitOffset := outBitOffset - 8. |
|
1094 |
] |
|
1095 |
]. |
|
1096 |
[ cnt >= 8 ] whileTrue:[ |
|
1097 |
dst at:dstIndex put:16rFF. |
|
1098 |
dstIndex := dstIndex + 1. |
|
1099 |
cnt := cnt - 8. |
|
1100 |
]. |
|
1101 |
dst at:dstIndex put:((dst at:dstIndex) bitOr:(leftBits at:(cnt+1))). |
|
1102 |
outBitOffset := outBitOffset + cnt. |
|
1103 |
] |
|
1104 |
] ifFalse:[ |
|
1105 |
"/ toggle if it was a terminating code |
|
1106 |
cnt < 64 ifTrue:[ |
|
1107 |
countTable := BlackCountTable. |
|
1108 |
shiftTable := BlackShiftTable |
|
1109 |
]. |
|
1110 |
||
1111 |
"/ skip cnt bits |
|
1112 |
dstIndex := dstIndex + (cnt rightShift: 3). |
|
1113 |
outBitOffset := outBitOffset + (cnt bitAnd: 7). |
|
1114 |
(outBitOffset >= 8) ifTrue:[ |
|
1115 |
dstIndex := dstIndex + 1. |
|
1116 |
outBitOffset := outBitOffset - 8. |
|
1117 |
] |
|
1118 |
]. |
|
1119 |
||
1120 |
nBitsLess13 := nBitsLess13 - shift. |
|
1121 |
||
1122 |
"/ fill bits from the input |
|
1123 |
[ nBitsLess13 < 0 ] whileTrue:[ |
|
1124 |
srcIndex > inCount ifTrue:[^ 1]. |
|
1125 |
||
1126 |
bits := (bits bitShift:8) bitOr:( src at:srcIndex ). |
|
1127 |
srcIndex := srcIndex + 1. |
|
1128 |
nBitsLess13 := nBitsLess13 + 8. |
|
1129 |
]. |
|
1130 |
] loop. |
|
1131 |
||
1132 |
"Created: / 25-08-2017 / 13:34:29 / cg" |
|
1133 |
"Modified: / 26-08-2017 / 18:12:15 / cg" |
|
1134 |
! |
|
1135 |
||
1136 |
_decompressCCITT3From:src count:inCount into:dst startingAt:dstIndexIn count:len |
|
1137 |
|srcIndex dstIndex countTable shiftTable |
|
1138 |
outCount outBitOffset bits nBitsLess13 bits13 cnt shift |
|
1139 |
nLeft t leftBits| |
|
1140 |
||
1141 |
WhiteCountTable isNil ifTrue:[ |
|
1142 |
self initCCITTTables. |
|
1143 |
]. |
|
1144 |
countTable := WhiteCountTable. |
|
1145 |
shiftTable := WhiteShiftTable. |
|
1146 |
leftBits := #[ 0 16r80 16rC0 16rE0 16rF0 16rF8 16rFC 16rFE 16rFF ]. |
|
1147 |
||
1148 |
srcIndex := 1. |
|
1149 |
dstIndex := dstIndexIn. |
|
1150 |
||
1151 |
outCount := 0. |
|
1152 |
outBitOffset := 0. |
|
1153 |
bits := ((src at:srcIndex) bitShift:8) bitOr:(src at:srcIndex+1). |
|
1154 |
srcIndex := srcIndex + 2. |
|
1155 |
nBitsLess13 := 3. |
|
1156 |
||
1157 |
[ |
|
1158 |
bits13 := (bits rightShift: nBitsLess13) bitAnd: 16r1FFF. |
|
1159 |
cnt := countTable at:(bits13+1). |
|
1160 |
cnt < 0 ifTrue:[ |
|
1161 |
^ 1 |
|
1162 |
]. |
|
1163 |
shift := shiftTable at:(bits13+1). |
|
1164 |
outCount := outCount + cnt. |
|
1165 |
outCount > len ifTrue:[ |
|
1166 |
self error:'out buffer overflow'. |
|
1167 |
^ 0 |
|
1168 |
]. |
|
1169 |
||
1170 |
countTable == BlackCountTable ifTrue:[ |
|
1171 |
"/ toggle if it was a terminating code |
|
1172 |
cnt < 64 ifTrue:[ |
|
1173 |
countTable := WhiteCountTable. |
|
1174 |
shiftTable := WhiteShiftTable |
|
1175 |
]. |
|
1176 |
"/ draw cnt black bits |
|
1177 |
cnt > 0 ifTrue:[ |
|
1178 |
outBitOffset > 0 ifTrue:[ |
|
1179 |
nLeft := 8 - outBitOffset. |
|
1180 |
(cnt < nLeft) ifTrue:[ nLeft := cnt ]. |
|
1181 |
t := (leftBits at:(nLeft+1)) rightShift: outBitOffset. |
|
1182 |
dst at:dstIndex put: ((dst at:dstIndex) bitOr:(t bitAnd:16rFF)). |
|
1183 |
cnt := cnt - nLeft. |
|
1184 |
outBitOffset := outBitOffset + nLeft. |
|
1185 |
(outBitOffset >= 8) ifTrue:[ |
|
1186 |
dstIndex := dstIndex + 1. |
|
1187 |
outBitOffset := outBitOffset - 8. |
|
1188 |
] |
|
1189 |
]. |
|
1190 |
[ cnt >= 8 ] whileTrue:[ |
|
1191 |
dst at:dstIndex put:16rFF. |
|
1192 |
dstIndex := dstIndex + 1. |
|
1193 |
cnt := cnt - 8. |
|
1194 |
]. |
|
1195 |
dst at:dstIndex put:((dst at:dstIndex) bitOr:(leftBits at:(cnt+1))). |
|
1196 |
outBitOffset := outBitOffset + cnt. |
|
1197 |
] |
|
1198 |
] ifFalse:[ |
|
1199 |
"/ toggle if it was a terminating code |
|
1200 |
cnt < 64 ifTrue:[ |
|
1201 |
countTable := BlackCountTable. |
|
1202 |
shiftTable := BlackShiftTable |
|
1203 |
]. |
|
1204 |
||
1205 |
"/ skip cnt bits |
|
1206 |
dstIndex := dstIndex + (cnt rightShift: 3). |
|
1207 |
outBitOffset := outBitOffset + (cnt bitAnd: 7). |
|
1208 |
(outBitOffset >= 8) ifTrue:[ |
|
1209 |
dstIndex := dstIndex + 1. |
|
1210 |
outBitOffset := outBitOffset - 8. |
|
1211 |
] |
|
1212 |
]. |
|
1213 |
||
1214 |
outCount >= len ifTrue:[ |
|
1215 |
^ 1 |
|
1216 |
]. |
|
1217 |
nBitsLess13 := nBitsLess13 - shift. |
|
1218 |
||
1219 |
"/ fill bits from the input |
|
1220 |
[ nBitsLess13 < 0 ] whileTrue:[ |
|
1221 |
bits := (bits bitShift:8) bitOr:( src at:srcIndex ). |
|
1222 |
srcIndex := srcIndex + 1. |
|
1223 |
nBitsLess13 := nBitsLess13 + 8. |
|
1224 |
]. |
|
1225 |
] loop. |
|
1226 |
||
1227 |
" |
|
1228 |
|bytes outBytes| |
|
1229 |
||
1230 |
bytes := '/Users/cg/DownloadsUnsaved/images/software/libtiffpic/g3test.g3' |
|
1231 |
asFilename binaryContentsOfEntireFile. |
|
1232 |
outBytes := ByteArray new:100000. |
|
1233 |
ImageReader |
|
1234 |
_decompressCCITT3From:bytes |
|
1235 |
count:bytes size |
|
1236 |
into:outBytes |
|
1237 |
startingAt:1. |
|
1238 |
" |
|
1239 |
||
1240 |
"Created: / 26-08-2017 / 14:16:54 / cg" |
|
1241 |
! |
|
1242 |
||
285 | 1243 |
decodeDelta:step in:data width:width height:height |
8110 | 1244 |
"perform TIFF predictor = 2 delta decoding inplace on data. |
285 | 1245 |
Calls primitive c function for speed" |
1246 |
||
8110 | 1247 |
|idx values ov nv| |
1248 |
||
8101 | 1249 |
(step == 3) ifTrue:[ |
285 | 1250 |
%{ |
8110 | 1251 |
if (__isByteArray(data) |
1252 |
&& __bothSmallInteger(width, height)) { |
|
1253 |
__decodeDelta3__(__ByteArrayInstPtr(data)->ba_element, |
|
1254 |
__intVal(width), __intVal(height)); |
|
1255 |
RETURN ( self ); |
|
1256 |
} |
|
8101 | 1257 |
%}. |
1258 |
]. |
|
1259 |
(step == 4) ifTrue:[ |
|
1260 |
%{ |
|
8110 | 1261 |
if (__isByteArray(data) |
1262 |
&& __bothSmallInteger(width, height)) { |
|
1263 |
__decodeDelta4__(__ByteArrayInstPtr(data)->ba_element, |
|
1264 |
__intVal(width), __intVal(height)); |
|
1265 |
RETURN ( self ); |
|
1266 |
} |
|
8101 | 1267 |
%}. |
8102 | 1268 |
]. |
8101 | 1269 |
|
8110 | 1270 |
"/ slow fallback |
1271 |
idx := 1. |
|
1272 |
1 to:height do:[:y | |
|
1273 |
values := Array new:step withAll:0. |
|
1274 |
1 to:width do:[:x | |
|
1275 |
1 to:step do:[:chNr | |
|
1276 |
ov := (values at:chNr). |
|
1277 |
nv := (ov + (data at:idx)) bitAnd:16rFF. |
|
1278 |
values at:chNr put:nv. |
|
1279 |
data at:idx put:nv. |
|
1280 |
idx := idx + 1. |
|
1281 |
]. |
|
1282 |
]. |
|
1283 |
]. |
|
1284 |
||
1285 |
"Modified: / 27-08-2017 / 16:52:37 / cg" |
|
285 | 1286 |
! |
105 | 1287 |
|
4714 | 1288 |
decompressCCITT3From:srcBytes into:dstBytes startingAt:offset count:count |
105 | 1289 |
"decompress CCITT Group 3 compressed image data. |
1290 |
count bytes from srcBytes are decompressed into dstBytes. |
|
1291 |
Calls primitive c function for speed" |
|
1292 |
%{ |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1293 |
if (__isByteArrayLike(srcBytes) |
105 | 1294 |
&& __isByteArray(dstBytes) |
1295 |
&& __bothSmallInteger(offset, count)) { |
|
8107 | 1296 |
int _count = __intVal(count); |
1297 |
||
1298 |
if (_count > __byteArraySize(dstBytes)) { |
|
1299 |
_count = __byteArraySize(dstBytes); |
|
1300 |
} |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1301 |
if (__decodeCCITTgroup3__(__ByteArrayInstPtr(srcBytes)->ba_element, |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1302 |
__ByteArrayInstPtr(dstBytes)->ba_element |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1303 |
+ __intVal(offset) - 1, |
8107 | 1304 |
_count)) { |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1305 |
RETURN ( self ); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1306 |
} |
105 | 1307 |
} |
1308 |
%} |
|
1309 |
. |
|
1310 |
self primitiveFailed |
|
1311 |
! |
|
1312 |
||
1313 |
decompressGIFFrom:srcBytes count:count into:dstBytes startingAt:offset codeLen:codeLen |
|
1314 |
"decompress GIF compressed image data. |
|
1315 |
count bytes from srcBytes are decompressed into dstBytes. |
|
1316 |
Calls primitive c function for speed" |
|
1317 |
%{ |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1318 |
if (__isByteArrayLike(srcBytes) |
105 | 1319 |
&& __isByteArray(dstBytes) |
1320 |
&& __bothSmallInteger(codeLen, offset) |
|
1321 |
&& __isSmallInteger(count)) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1322 |
if (__decodeGIF__(__ByteArrayInstPtr(srcBytes)->ba_element, |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1323 |
__ByteArrayInstPtr(dstBytes)->ba_element |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1324 |
+__intVal(offset) - 1, |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1325 |
__intVal(count), |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1326 |
__intVal(codeLen), |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1327 |
__byteArraySize(srcBytes), |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1328 |
__byteArraySize(dstBytes) |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1329 |
)) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1330 |
RETURN ( self ); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1331 |
} |
105 | 1332 |
} |
1333 |
%} |
|
1334 |
. |
|
1335 |
self primitiveFailed |
|
1336 |
! |
|
1337 |
||
285 | 1338 |
decompressLZWFrom:srcBytes count:count into:dstBytes startingAt:offset |
1339 |
"decompress LZW (tiff) compressed image data. |
|
1340 |
count bytes from srcBytes are decompressed into dstBytes. |
|
105 | 1341 |
Calls primitive c function for speed" |
1342 |
%{ |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
1343 |
if (__isByteArrayLike(srcBytes) |
285 | 1344 |
&& __isByteArray(dstBytes) |
1345 |
&& __bothSmallInteger(offset, count)) { |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1346 |
if (__decodeLZW__(__ByteArrayInstPtr(srcBytes)->ba_element, |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1347 |
__ByteArrayInstPtr(dstBytes)->ba_element |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1348 |
+ __intVal(offset) - 1, |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1349 |
__intVal(count), |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1350 |
__byteArraySize(srcBytes), |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1351 |
__byteArraySize(dstBytes) |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1352 |
)) { |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1353 |
RETURN ( self ); |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1354 |
} |
105 | 1355 |
} |
1356 |
%} |
|
1357 |
. |
|
1358 |
self primitiveFailed |
|
189 | 1359 |
! |
1360 |
||
6585 | 1361 |
decompressPackBits:nIn from:srcBytes to:dstBytes startingAt:dstOffset |
1362 |
"decompress a number of input bytes. |
|
1363 |
Used by tiff and some mac image formats. |
|
1364 |
Return the number of decompressed output bytes." |
|
1365 |
||
1366 |
|i b n v dstOffs| |
|
1367 |
||
1368 |
dstOffs := dstOffset. |
|
1369 |
i := 1. |
|
1370 |
||
1371 |
[i <= nIn] whileTrue:[ |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1372 |
b := srcBytes at:i. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1373 |
i := i + 1. |
6585 | 1374 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1375 |
b ~~ 16rFF ifTrue:[ "/ not a NOP |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1376 |
b <= 127 ifTrue:[ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1377 |
"/ 0..127 literal bytes |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1378 |
n := b + 1. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1379 |
dstBytes replaceFrom:dstOffs to:dstOffs+n-1 with:srcBytes startingAt:i. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1380 |
i := i + n. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1381 |
] ifFalse:[ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1382 |
"/ 128..254 a run |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1383 |
n := b - 125. |
6585 | 1384 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1385 |
v := srcBytes at:i. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1386 |
i := i + 1. |
6585 | 1387 |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1388 |
dstBytes from:dstOffs to:dstOffs+n put:v. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1389 |
]. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1390 |
dstOffs := dstOffs + n. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
1391 |
] |
6585 | 1392 |
]. |
1393 |
^ dstOffs - dstOffset |
|
1394 |
||
1395 |
"Created: / 1.12.1997 / 18:39:23 / cg" |
|
1396 |
"Modified: / 1.12.1997 / 18:49:58 / cg" |
|
1397 |
! |
|
1398 |
||
7926 | 1399 |
decompressPackBitsV2From:srcBytes at:srcStart to:dstBytes at:dstStart count:outCount |
1400 |
"decompress until a number of output bytes has been decompressed. |
|
1401 |
Used by some mac image formats. |
|
1402 |
Return the number of processed input bytes. |
|
1403 |
This does NOT treat FF as a noop." |
|
1404 |
||
1405 |
|i b n v dstOffs nRemaining| |
|
1406 |
||
1407 |
dstOffs := dstStart. |
|
1408 |
i := srcStart. |
|
1409 |
nRemaining := outCount. |
|
1410 |
[nRemaining > 0] whileTrue:[ |
|
8101 | 1411 |
b := srcBytes at:i. |
1412 |
i := i + 1. |
|
7926 | 1413 |
|
8101 | 1414 |
"/ mhmh - other packbits decoders seem to treat FF as a noop |
1415 |
"/ here, we do not. |
|
1416 |
true "b ~~ 16rFF" ifTrue:[ "/ not a NOP |
|
1417 |
b <= 127 ifTrue:[ |
|
1418 |
"/ 0..127: 1..128 literal bytes |
|
1419 |
n := b + 1. |
|
1420 |
dstBytes replaceFrom:dstOffs to:dstOffs+b with:srcBytes startingAt:i. |
|
1421 |
nRemaining := nRemaining - n. |
|
1422 |
i := i + n. |
|
1423 |
] ifFalse:[ |
|
1424 |
"/ 128..255 a run of length 3..130 |
|
1425 |
n := b - 125. |
|
7926 | 1426 |
|
8101 | 1427 |
v := srcBytes at:i. |
1428 |
i := i + 1. |
|
7926 | 1429 |
|
8101 | 1430 |
dstBytes from:dstOffs to:dstOffs+n-1 put:v. |
1431 |
nRemaining := nRemaining - n. |
|
1432 |
]. |
|
1433 |
dstOffs := dstOffs + n. |
|
1434 |
] ifFalse:[ |
|
1435 |
self halt |
|
1436 |
]. |
|
7926 | 1437 |
]. |
1438 |
^ i-srcStart |
|
1439 |
||
1440 |
"Created: / 22-02-2017 / 12:05:26 / cg" |
|
6585 | 1441 |
! |
1442 |
||
1648
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1443 |
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
|
1444 |
"common helper to expand RLE encoded data" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1445 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1446 |
"/ 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
|
1447 |
"/ 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
|
1448 |
"/ 1 means: count verbatim bytes follow; |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1449 |
"/ 0 means: repeat the next byte count times. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1450 |
"/ Decoding stops when a 0-count is encountered. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1451 |
"/ srcBytes and dstBytes should not overlap. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1452 |
"/ 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
|
1453 |
"/ |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1454 |
"/ 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
|
1455 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1456 |
|srcIdx "{Class: SmallInteger }" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1457 |
dstIdx "{Class: SmallInteger }" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1458 |
pixel "{Class: SmallInteger }" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1459 |
count "{Class: SmallInteger }"| |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1460 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1461 |
srcIdx := srcStartIndex. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1462 |
dstIdx := dstStartIndex. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1463 |
[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
|
1464 |
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
|
1465 |
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
|
1466 |
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
|
1467 |
^ self |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1468 |
]. |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1469 |
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
|
1470 |
(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
|
1471 |
"/ run bytes |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1472 |
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
|
1473 |
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
|
1474 |
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
|
1475 |
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
|
1476 |
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
|
1477 |
] ifFalse:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1478 |
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
|
1479 |
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
|
1480 |
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
|
1481 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1482 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1483 |
] ifFalse:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1484 |
"/ verbatim bytes |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1485 |
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
|
1486 |
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
|
1487 |
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
|
1488 |
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
|
1489 |
] ifFalse:[ |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1490 |
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
|
1491 |
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
|
1492 |
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
|
1493 |
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
|
1494 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1495 |
] |
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1496 |
] |
1648
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1497 |
]. |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1498 |
|
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1499 |
"Modified: 23.4.1997 / 18:54:05 / cg" |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1500 |
! |
cbb3f0d60617
prepare for RLE decompression code reuse
Claus Gittinger <cg@exept.de>
parents:
1633
diff
changeset
|
1501 |
|
8110 | 1502 |
decompressTiffPackBitsFrom:srcBytes to:dstBytes at:dstStart count:maxOutCount |
1503 |
"decompress all of srcBytes to dstBytes starting at dstStart. |
|
1504 |
Used by TIFF image formats. |
|
1505 |
This DOES TREAT FF as a noop." |
|
1506 |
||
1507 |
|i b n v dstOffs dstLast end srcSize| |
|
1508 |
||
1509 |
dstOffs := dstStart. |
|
1510 |
dstLast := (dstStart + maxOutCount - 1) min:(dstBytes size). |
|
1511 |
||
1512 |
i := 1. |
|
1513 |
srcSize := srcBytes size. |
|
1514 |
||
1515 |
[i <= srcSize] whileTrue:[ |
|
1516 |
b := srcBytes at:i. |
|
1517 |
i := i + 1. |
|
1518 |
||
1519 |
"/ treat FF as a noop |
|
1520 |
b ~~ 128 ifTrue:[ "/ not a NOP |
|
1521 |
b <= 127 ifTrue:[ |
|
1522 |
"/ 0..127: 1..128 literal bytes |
|
1523 |
n := b + 1. |
|
1524 |
end := (dstOffs+n-1) min:dstLast. |
|
1525 |
dstBytes replaceFrom:dstOffs to:end with:srcBytes startingAt:i. |
|
1526 |
i := i + n. |
|
1527 |
] ifFalse:[ |
|
1528 |
n := 1 - (b - 256). |
|
1529 |
v := srcBytes at:i. |
|
1530 |
i := i + 1. |
|
1531 |
end := (dstOffs+n-1) min:dstLast. |
|
1532 |
dstBytes from:dstOffs to:end put:v. |
|
1533 |
]. |
|
1534 |
dstOffs := dstOffs + n. |
|
1535 |
dstOffs > dstLast ifTrue:[ |
|
1536 |
^ dstLast-1-dstStart. |
|
1537 |
]. |
|
1538 |
]. |
|
1539 |
]. |
|
1540 |
^ dstOffs-dstStart |
|
1541 |
||
1542 |
"Created: / 26-08-2017 / 17:50:13 / cg" |
|
1543 |
"Modified: / 27-08-2017 / 12:32:17 / cg" |
|
1544 |
! |
|
1545 |
||
1546 |
initCCITTTables |
|
1547 |
|whiteDef blackDef index value| |
|
1548 |
||
1549 |
whiteDef := #( |
|
1550 |
( 16r3500 8 ) "/ 0 |
|
1551 |
( 16r1c00 6 ) |
|
1552 |
( 16r7000 4 ) |
|
1553 |
( 16r8000 4 ) |
|
1554 |
( 16rb000 4 ) |
|
1555 |
( 16rc000 4 ) |
|
1556 |
( 16re000 4 ) |
|
1557 |
( 16rf000 4 ) |
|
1558 |
( 16r9800 5 ) |
|
1559 |
( 16rA000 5 ) |
|
1560 |
( 16r3800 5 ) "/ 10 |
|
1561 |
( 16r4000 5 ) |
|
1562 |
( 16r2000 6 ) |
|
1563 |
( 16r0c00 6 ) |
|
1564 |
( 16rd000 6 ) |
|
1565 |
( 16rd400 6 ) |
|
1566 |
( 16ra800 6 ) |
|
1567 |
( 16rac00 6 ) |
|
1568 |
( 16r4e00 7 ) |
|
1569 |
( 16r1800 7 ) |
|
1570 |
( 16r1000 7 ) "/ 20 |
|
1571 |
( 16r2e00 7 ) |
|
1572 |
( 16r0600 7 ) |
|
1573 |
( 16r0800 7 ) |
|
1574 |
( 16r5000 7 ) |
|
1575 |
( 16r5600 7 ) |
|
1576 |
( 16r2600 7 ) |
|
1577 |
( 16r4800 7 ) |
|
1578 |
( 16r3000 7 ) |
|
1579 |
( 16r0200 8 ) |
|
1580 |
( 16r0300 8 ) "/ 30 |
|
1581 |
( 16r1a00 8 ) |
|
1582 |
( 16r1b00 8 ) |
|
1583 |
( 16r1200 8 ) |
|
1584 |
( 16r1300 8 ) |
|
1585 |
( 16r1400 8 ) |
|
1586 |
( 16r1500 8 ) |
|
1587 |
( 16r1600 8 ) |
|
1588 |
( 16r1700 8 ) |
|
1589 |
( 16r2800 8 ) |
|
1590 |
( 16r2900 8 ) "/ 40 |
|
1591 |
( 16r2a00 8 ) |
|
1592 |
( 16r2b00 8 ) |
|
1593 |
( 16r2c00 8 ) |
|
1594 |
( 16r2d00 8 ) |
|
1595 |
( 16r0400 8 ) |
|
1596 |
( 16r0500 8 ) |
|
1597 |
( 16r0a00 8 ) |
|
1598 |
( 16r0b00 8 ) |
|
1599 |
( 16r5200 8 ) |
|
1600 |
( 16r5300 8 ) "/ 50 |
|
1601 |
( 16r5400 8 ) |
|
1602 |
( 16r5500 8 ) |
|
1603 |
( 16r2400 8 ) |
|
1604 |
( 16r2500 8 ) |
|
1605 |
( 16r5800 8 ) |
|
1606 |
( 16r5900 8 ) |
|
1607 |
( 16r5a00 8 ) |
|
1608 |
( 16r5b00 8 ) |
|
1609 |
( 16r4a00 8 ) |
|
1610 |
( 16r4b00 8 ) "/ 60 |
|
1611 |
( 16r3200 8 ) |
|
1612 |
( 16r3300 8 ) |
|
1613 |
( 16r3400 8 ) |
|
1614 |
"/ ---------------- |
|
1615 |
( 16rd800 5 ) "/ 64 |
|
1616 |
( 16r9000 5 ) "/ 128 |
|
1617 |
( 16r5c00 6 ) "/ 192 |
|
1618 |
( 16r6e00 7 ) "/ 256 |
|
1619 |
( 16r3600 8 ) "/ 320 |
|
1620 |
( 16r3700 8 ) |
|
1621 |
( 16r6400 8 ) |
|
1622 |
( 16r6500 8 ) |
|
1623 |
( 16r6800 8 ) |
|
1624 |
( 16r6700 8 ) "/ 640 |
|
1625 |
( 16r6600 9 ) "/ 704 |
|
1626 |
( 16r6680 9 ) |
|
1627 |
( 16r6900 9 ) |
|
1628 |
( 16r6980 9 ) |
|
1629 |
( 16r6a00 9 ) |
|
1630 |
( 16r6a80 9 ) |
|
1631 |
( 16r6b00 9 ) |
|
1632 |
( 16r6b80 9 ) |
|
1633 |
( 16r6c00 9 ) |
|
1634 |
( 16r6c80 9 ) |
|
1635 |
( 16r6d00 9 ) |
|
1636 |
( 16r6d80 9 ) |
|
1637 |
( 16r4c00 9 ) |
|
1638 |
( 16r4c80 9 ) |
|
1639 |
( 16r4d00 9 ) "/ 1600 |
|
1640 |
( 16r6000 6 ) "/ 1664 |
|
1641 |
( 16r4d80 9 ) "/ 1728 |
|
1642 |
"/ -------------------------------- |
|
1643 |
( 16r0100 11 ) "/ 1792 |
|
1644 |
( 16r0180 11 ) |
|
1645 |
( 16r01a0 11 ) "/ 1920 |
|
1646 |
( 16r0120 12 ) "/ 1984 |
|
1647 |
( 16r0130 12 ) |
|
1648 |
( 16r0140 12 ) |
|
1649 |
( 16r0150 12 ) |
|
1650 |
( 16r0160 12 ) |
|
1651 |
( 16r0170 12 ) |
|
1652 |
( 16r01c0 12 ) |
|
1653 |
( 16r01d0 12 ) |
|
1654 |
( 16r01e0 12 ) |
|
1655 |
( 16r01f0 12 ) "/ 2560 |
|
1656 |
"/ -------------------------------- |
|
1657 |
( 16r0010 12 ) "/ EOL |
|
1658 |
). |
|
1659 |
||
1660 |
blackDef := #( |
|
1661 |
( 16r0dc0 10 ) "/ 0 |
|
1662 |
( 16r4000 3 ) |
|
1663 |
( 16rc000 2 ) |
|
1664 |
( 16r8000 2 ) |
|
1665 |
( 16r6000 3 ) |
|
1666 |
( 16r3000 4 ) |
|
1667 |
( 16r2000 4 ) |
|
1668 |
( 16r1800 5 ) |
|
1669 |
( 16r1400 6 ) |
|
1670 |
( 16r1000 6 ) |
|
1671 |
( 16r0800 7 ) "/ 10 |
|
1672 |
( 16r0a00 7 ) |
|
1673 |
( 16r0e00 7 ) |
|
1674 |
( 16r0400 8 ) |
|
1675 |
( 16r0700 8 ) |
|
1676 |
( 16r0c00 9 ) |
|
1677 |
( 16r05c0 10 ) |
|
1678 |
( 16r0600 10 ) |
|
1679 |
( 16r0200 10 ) |
|
1680 |
( 16r0ce0 11 ) |
|
1681 |
( 16r0d00 11 ) "/ 20 |
|
1682 |
( 16r0d80 11 ) |
|
1683 |
( 16r06e0 11 ) |
|
1684 |
( 16r0500 11 ) |
|
1685 |
( 16r02e0 11 ) |
|
1686 |
( 16r0300 11 ) |
|
1687 |
( 16r0ca0 12 ) |
|
1688 |
( 16r0cb0 12 ) |
|
1689 |
( 16r0cc0 12 ) |
|
1690 |
( 16r0cd0 12 ) |
|
1691 |
( 16r0680 12 ) "/ 30 |
|
1692 |
( 16r0690 12 ) |
|
1693 |
( 16r06a0 12 ) |
|
1694 |
( 16r06b0 12 ) |
|
1695 |
( 16r0d20 12 ) |
|
1696 |
( 16r0d30 12 ) |
|
1697 |
( 16r0d40 12 ) |
|
1698 |
( 16r0d50 12 ) |
|
1699 |
( 16r0d60 12 ) |
|
1700 |
( 16r0d70 12 ) |
|
1701 |
( 16r06c0 12 ) "/ 40 |
|
1702 |
( 16r06d0 12 ) |
|
1703 |
( 16r0da0 12 ) |
|
1704 |
( 16r0db0 12 ) |
|
1705 |
( 16r0540 12 ) |
|
1706 |
( 16r0550 12 ) |
|
1707 |
( 16r0560 12 ) |
|
1708 |
( 16r0570 12 ) |
|
1709 |
( 16r0640 12 ) |
|
1710 |
( 16r0650 12 ) |
|
1711 |
( 16r0520 12 ) "/ 50 |
|
1712 |
( 16r0530 12 ) |
|
1713 |
( 16r0240 12 ) |
|
1714 |
( 16r0370 12 ) |
|
1715 |
( 16r0380 12 ) |
|
1716 |
( 16r0270 12 ) |
|
1717 |
( 16r0280 12 ) |
|
1718 |
( 16r0580 12 ) |
|
1719 |
( 16r0590 12 ) |
|
1720 |
( 16r02b0 12 ) |
|
1721 |
( 16r02c0 12 ) "/ 60 |
|
1722 |
( 16r05a0 12 ) |
|
1723 |
( 16r0660 12 ) |
|
1724 |
( 16r0670 12 ) |
|
1725 |
"/ ---------------- |
|
1726 |
( 16r03c0 10 ) "/ 64 |
|
1727 |
( 16r0c80 12 ) "/ 128 |
|
1728 |
( 16r0c90 12 ) "/ 192 |
|
1729 |
( 16r05b0 12 ) "/ 256 |
|
1730 |
( 16r0330 12 ) "/ 320 |
|
1731 |
( 16r0340 12 ) |
|
1732 |
( 16r0350 12 ) "/ 448 |
|
1733 |
( 16r0360 13 ) "/ 512 |
|
1734 |
( 16r0368 13 ) |
|
1735 |
( 16r0250 13 ) "/ 640 |
|
1736 |
( 16r0258 13 ) "/ 704 |
|
1737 |
( 16r0260 13 ) |
|
1738 |
( 16r0268 13 ) |
|
1739 |
( 16r0390 13 ) |
|
1740 |
( 16r0398 13 ) |
|
1741 |
( 16r03a0 13 ) |
|
1742 |
( 16r03a8 13 ) |
|
1743 |
( 16r03b0 13 ) |
|
1744 |
( 16r03b8 13 ) |
|
1745 |
( 16r0290 13 ) |
|
1746 |
( 16r0298 13 ) |
|
1747 |
( 16r02a0 13 ) |
|
1748 |
( 16r02a8 13 ) |
|
1749 |
( 16r02d0 13 ) |
|
1750 |
( 16r02d8 13 ) "/ 1600 |
|
1751 |
( 16r0320 13 ) "/ 1664 |
|
1752 |
( 16r0328 13 ) "/ 1728 |
|
1753 |
"/ -------------------------------- |
|
1754 |
). |
|
1755 |
||
1756 |
WhiteCountTable := SignedWordArray new: 8192 withAll:-1. |
|
1757 |
BlackCountTable := SignedWordArray new: 8192 withAll:-1. |
|
1758 |
WhiteShiftTable := SignedWordArray new: 8192. |
|
1759 |
BlackShiftTable := SignedWordArray new: 8192. |
|
1760 |
||
1761 |
0 to:63 do:[:value | |
|
1762 |
|def nBits bits| |
|
1763 |
||
1764 |
def := whiteDef at:(value+1). |
|
1765 |
nBits := def second. |
|
1766 |
bits := def first >> 3. |
|
1767 |
(1 << (13 - nBits)) to:1 by:-1 do:[:cnt | |
|
1768 |
WhiteCountTable at:bits+1 put:value. |
|
1769 |
WhiteShiftTable at:bits+1 put:nBits. |
|
1770 |
bits := bits + 1. |
|
1771 |
]. |
|
1772 |
def := blackDef at:(value+1). |
|
1773 |
nBits := def second. |
|
1774 |
bits := def first >> 3. |
|
1775 |
(1 << (13 - nBits)) to:1 by:-1 do:[:cnt | |
|
1776 |
BlackCountTable at:bits+1 put:value. |
|
1777 |
BlackShiftTable at:bits+1 put:nBits. |
|
1778 |
bits := bits + 1. |
|
1779 |
]. |
|
1780 |
]. |
|
1781 |
||
1782 |
index := value := 64. |
|
1783 |
[ value <= 1728 ] whileTrue:[ |
|
1784 |
|nBits bits| |
|
1785 |
||
1786 |
nBits := (whiteDef at:(index+1)) second. |
|
1787 |
bits := (whiteDef at:(index+1)) first >> 3. |
|
1788 |
||
1789 |
(1 << (13 - nBits)) to:1 by:-1 do:[:cnt | |
|
1790 |
WhiteCountTable at:bits+1 put:value. |
|
1791 |
WhiteShiftTable at:bits+1 put:nBits. |
|
1792 |
bits := bits + 1. |
|
1793 |
]. |
|
1794 |
nBits := (blackDef at:(index+1)) second. |
|
1795 |
bits := (blackDef at:(index+1)) first >> 3. |
|
1796 |
(1 << (13 - nBits)) to:1 by:-1 do:[:cnt | |
|
1797 |
BlackCountTable at:bits+1 put:value. |
|
1798 |
BlackShiftTable at:bits+1 put:nBits. |
|
1799 |
bits := bits + 1. |
|
1800 |
]. |
|
1801 |
index := index + 1. |
|
1802 |
value := value + 64. |
|
1803 |
]. |
|
1804 |
||
1805 |
[ value <= 2560 ] whileTrue:[ |
|
1806 |
|nBits bits| |
|
1807 |
||
1808 |
nBits := (whiteDef at:(index+1)) second. |
|
1809 |
bits := (whiteDef at:(index+1)) first >> 3. |
|
1810 |
(1 << (13 - nBits)) to:1 by:-1 do:[:cnt | |
|
1811 |
WhiteCountTable at:bits+1 put:value. |
|
1812 |
WhiteShiftTable at:bits+1 put:nBits. |
|
1813 |
BlackCountTable at:bits+1 put:value. |
|
1814 |
BlackShiftTable at:bits+1 put:nBits. |
|
1815 |
bits := bits + 1. |
|
1816 |
]. |
|
1817 |
index := index + 1. |
|
1818 |
value := value + 64. |
|
1819 |
]. |
|
1820 |
||
1821 |
"Created: / 25-08-2017 / 13:25:46 / cg" |
|
1822 |
! |
|
1823 |
||
7501 | 1824 |
swap:nBytes bytesFromRGBA_to_BGRA_in:data startingAt:startIndex |
1825 |
"swap bytes from RGBA into BGRA order. |
|
1826 |
The argument is a pixel data buffer (byteArray)" |
|
1827 |
||
1828 |
self swap:(nBytes//4) pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:4 |
|
1829 |
||
1830 |
" |
|
1831 |
|bytes| |
|
1832 |
||
1833 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
|
1834 |
self swap:6 bytesFromRGB_to_BGR_in:bytes startingAt:1. |
|
1835 |
bytes. |
|
1836 |
" |
|
1837 |
" |
|
1838 |
|bytes| |
|
1839 |
||
1840 |
bytes := ByteArray new:1000000. |
|
1841 |
bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12]. |
|
1842 |
Time millisecondsToRun:[ |
|
7539 | 1843 |
self swap:1000000 bytesFromRGB_to_BGR_in:bytes. |
7501 | 1844 |
]. |
1845 |
bytes copyTo:10. |
|
1846 |
" |
|
1847 |
! |
|
1848 |
||
3835 | 1849 |
swap:nBytes bytesFromRGB_to_BGR_in:data |
1850 |
"swap bytes from RGB into BGR order. |
|
1851 |
The argument is a pixel data buffer (byteArray)" |
|
1852 |
||
7182 | 1853 |
self swap:(nBytes//3) pixelsFromRGB_to_BGR_in:data startingAt:1 bytesPerPixel:3 |
3835 | 1854 |
|
1855 |
" |
|
1856 |
|bytes| |
|
1857 |
||
1858 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
|
1859 |
self swap:6 bytesFromRGB_to_BGR_in:bytes. |
|
4714 | 1860 |
bytes. |
3835 | 1861 |
" |
1862 |
" |
|
1863 |
|bytes| |
|
1864 |
||
1865 |
bytes := ByteArray new:1000000. |
|
4714 | 1866 |
bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12]. |
3835 | 1867 |
Time millisecondsToRun:[ |
7539 | 1868 |
self swap:1000000 bytesFromRGB_to_BGR_in:bytes. |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1869 |
]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1870 |
bytes copyTo:10. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1871 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1872 |
! |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1873 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1874 |
swap:nBytes bytesFromRGB_to_BGR_in:data startingAt:startIndex |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1875 |
"swap bytes from RGB into BGR order. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1876 |
The argument is a pixel data buffer (byteArray)" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1877 |
|
7182 | 1878 |
self swap:(nBytes//3) pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:3 |
5129
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1879 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1880 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1881 |
|bytes| |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1882 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1883 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1884 |
self swap:6 bytesFromRGB_to_BGR_in:bytes startingAt:1. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1885 |
bytes. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1886 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1887 |
" |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1888 |
|bytes| |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1889 |
|
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1890 |
bytes := ByteArray new:1000000. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1891 |
bytes replaceFrom:1 with:#[ 0 1 2 3 4 5 6 7 8 9 10 11 12]. |
1f80ff25b6a5
BMP support removed (moved down to the WindopwsIconReader)
Claus Gittinger <cg@exept.de>
parents:
4912
diff
changeset
|
1892 |
Time millisecondsToRun:[ |
7539 | 1893 |
self swap:1000000 bytesFromRGB_to_BGR_in:bytes. |
4714 | 1894 |
]. |
1895 |
bytes copyTo:10. |
|
3835 | 1896 |
" |
7182 | 1897 |
! |
1898 |
||
1899 |
swap:count pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:bpp |
|
1900 |
"swap bytes from RGB into BGR order. |
|
1901 |
The argument is a pixel data buffer (byteArray). |
|
1902 |
Can be used for both 24bit rgb data (bpp=3) or rgba data (bpp=4)" |
|
1903 |
||
1904 |
|t idx| |
|
1905 |
||
1906 |
%{ /* OPTIONAL */ |
|
1907 |
if (__isByteArray(data) |
|
1908 |
&& __isSmallInteger(count) |
|
1909 |
&& __isSmallInteger(startIndex) |
|
1910 |
&& __isSmallInteger(bpp)) { |
|
1911 |
INT __count = __intVal(count); |
|
1912 |
INT __startOffset = __intVal(startIndex) - 1; |
|
1913 |
INT __dataSize = __byteArraySize(data); |
|
1914 |
int __bpp = __intVal(bpp); |
|
1915 |
INT __nBytes = __count * __bpp; |
|
1916 |
||
1917 |
if ((__startOffset + __nBytes) <= __dataSize) { |
|
1918 |
unsigned char *__cp = __ByteArrayInstPtr(data)->ba_element + __startOffset; |
|
1919 |
||
1920 |
while (__count-- > 0) { |
|
1921 |
unsigned char __t; |
|
1922 |
||
1923 |
__t = __cp[0]; |
|
1924 |
__cp[0] = __cp[2]; |
|
1925 |
__cp[2] = __t; |
|
1926 |
__cp += __bpp; |
|
1927 |
} |
|
1928 |
RETURN (true); |
|
1929 |
} |
|
1930 |
} |
|
1931 |
%}. |
|
1932 |
idx := startIndex. |
|
1933 |
1 to:count do:[:i | |
|
1934 |
t := data at:idx. |
|
1935 |
data at:idx put:(data at:idx+2). |
|
1936 |
data at:idx+2 put:t. |
|
1937 |
idx := idx + bpp. |
|
1938 |
]. |
|
1939 |
||
1940 |
" |
|
1941 |
|bytes| |
|
1942 |
||
1943 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
|
1944 |
self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:3. |
|
1945 |
bytes. |
|
1946 |
" |
|
1947 |
||
1948 |
" |
|
1949 |
|bytes| |
|
1950 |
||
1951 |
bytes := #[ 0 1 2 3 4 5 6 7 8 9 ]. |
|
1952 |
self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:4. |
|
1953 |
bytes. |
|
1954 |
" |
|
285 | 1955 |
! ! |
1956 |
||
1167 | 1957 |
!ImageReader class methodsFor:'i/o support'! |
285 | 1958 |
|
1959 |
streamReadingFile:aFilename |
|
1960 |
"return a stream to read aFilename. |
|
1961 |
If the filename ends with '.Z' or '.gz', return a stream |
|
1962 |
to a pipe for the uncompressor. Otherwise, return a stream to read |
|
1963 |
the file directly." |
|
1964 |
||
1300 | 1965 |
|inStream name fn| |
285 | 1966 |
|
1967 |
name := aFilename asString. |
|
1968 |
((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
|
1969 |
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
|
1970 |
inStream := PipeStream readingFrom:'gunzip < ' , fn. |
285 | 1971 |
] ifFalse:[ |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1972 |
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
|
1973 |
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
|
1974 |
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
|
1975 |
] |
285 | 1976 |
]. |
1977 |
inStream isNil ifTrue:[ |
|
4714 | 1978 |
'ImageReader [warning]: open error on: ' infoPrint. aFilename infoPrintCR. |
285 | 1979 |
]. |
1980 |
^ inStream |
|
518 | 1981 |
|
1300 | 1982 |
"Modified: 31.1.1997 / 10:37:24 / cg" |
285 | 1983 |
! ! |
1984 |
||
1167 | 1985 |
!ImageReader class methodsFor:'image reading'! |
285 | 1986 |
|
8846 | 1987 |
fromBase64Stream:aStream |
1988 |
"read an image in my format from aStream, which contains base64 encoded bytes. |
|
1989 |
Leave image description in instance variables." |
|
1990 |
||
1991 |
^ self fromStream:(Base64Coder on:aStream). |
|
1992 |
! |
|
1993 |
||
6060 | 1994 |
fromBytes:aByteArray |
1995 |
"read an image (in my format) from aByteArray. |
|
1996 |
Return the image or nil (if unrecognized format or error)" |
|
1997 |
||
1998 |
|reader| |
|
1999 |
||
2000 |
reader := self readStream:aByteArray readStream. |
|
2001 |
^ reader image |
|
2002 |
! |
|
2003 |
||
285 | 2004 |
fromFile:aFileName |
4714 | 2005 |
"read an image (in my format) from aFileName. |
285 | 2006 |
Return the image or nil on error." |
2007 |
||
1551 | 2008 |
|reader| |
285 | 2009 |
|
1551 | 2010 |
reader := self readFile:aFileName. |
2011 |
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
|
2012 |
^ reader image |
285 | 2013 |
]. |
1551 | 2014 |
^ nil |
285 | 2015 |
|
2016 |
" |
|
2017 |
XBMReader fromFile:'bitmaps/SBrowser.xbm' |
|
4033 | 2018 |
XPMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
2019 |
XBMReader fromFile:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
518 | 2020 |
" |
2021 |
||
1551 | 2022 |
"Modified: 4.4.1997 / 22:09:49 / cg" |
285 | 2023 |
! |
2024 |
||
2025 |
fromStream:aStream |
|
583 | 2026 |
"read an image (in my format) from aStream. |
1551 | 2027 |
Return the image or nil (if unrecognized format or error). |
2028 |
The stream remains open." |
|
285 | 2029 |
|
2030 |
|reader| |
|
2031 |
||
3839 | 2032 |
reader := self readStream:aStream. |
2033 |
^ reader image |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2034 |
! |
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2035 |
|
6060 | 2036 |
fromURL:url |
2037 |
"read an image (in my format) from url. |
|
2038 |
Return the image or nil (if unrecognized format or error)" |
|
2039 |
||
2040 |
|readerClass response| |
|
2041 |
||
2042 |
self == ImageReader ifTrue:[ |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2043 |
"select a reader supporting this file format" |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2044 |
readerClass := self readerClassForFilename:url asURL path. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2045 |
readerClass ~~ self ifTrue:[ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2046 |
^ readerClass fromURL:url. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2047 |
]. |
6060 | 2048 |
]. |
2049 |
||
2050 |
response := HTTPInterface get:url. |
|
2051 |
response isErrorResponse ifTrue:[ |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2052 |
self error:'failed to read url' mayProceed:true. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2053 |
^ nil |
6060 | 2054 |
]. |
2055 |
^ self fromBytes:(response data). |
|
2056 |
||
2057 |
" |
|
2058 |
self fromURL:'http://www.lutece.paris.fr/tech/images/helloworld.png' |
|
2059 |
" |
|
2060 |
! |
|
2061 |
||
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2062 |
imagesFromFile:aFileName |
4714 | 2063 |
"read all images (in my format) from aFileName. |
1551 | 2064 |
Return a collection of images or nil on error. |
2065 |
Not all reader may support multiple images." |
|
2066 |
||
2067 |
|reader| |
|
2068 |
||
2069 |
reader := self readFile:aFileName. |
|
2070 |
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
|
2071 |
^ reader images |
1551 | 2072 |
]. |
2073 |
^ nil |
|
2074 |
||
2075 |
"Modified: 4.4.1997 / 22:11:01 / cg" |
|
2076 |
! |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2077 |
|
1551 | 2078 |
imagesFromStream:aStream |
2079 |
"read all images (in my format) from aStream. |
|
2080 |
Return a collection of images or nil (if unrecognized format or error). |
|
2081 |
The stream remains open. |
|
2082 |
Not all reader may support multiple images." |
|
2083 |
||
2084 |
|reader| |
|
2085 |
||
3839 | 2086 |
reader := self new. |
2087 |
reader inStream:aStream. |
|
2088 |
reader fromStream:aStream. |
|
2089 |
^ reader images |
|
1551 | 2090 |
|
2091 |
"Modified: 4.4.1997 / 22:11:40 / cg" |
|
2092 |
! |
|
2093 |
||
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
2094 |
readFile:aFilename |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
2095 |
"create a reader and let it read an image (in my format) from aFilename. |
6060 | 2096 |
Return the reader, NOT the image (however, the reader has already read the image, |
2097 |
so it can be asked with 'reader image')." |
|
1551 | 2098 |
|
6060 | 2099 |
|readerClass reader inStream| |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2100 |
|
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
2101 |
self == ImageReader ifTrue:[ |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2102 |
"select a reader supporting this file format" |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2103 |
readerClass := self readerClassForFilename:aFilename. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2104 |
readerClass ~~ self ifTrue:[ |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2105 |
^ readerClass readFile:aFilename. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2106 |
]. |
4912
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
2107 |
]. |
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
2108 |
|
b2fd9c2d5e11
#fromFile: and #readFile: - choose a matching subclass
Stefan Vogel <sv@exept.de>
parents:
4776
diff
changeset
|
2109 |
inStream := self streamReadingFile:aFilename. |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2110 |
inStream isNil ifTrue:[ |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2111 |
'ImageReader [warning]: file open error' errorPrintCR. |
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2112 |
^ nil |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2113 |
]. |
3839 | 2114 |
reader := self new. |
2115 |
reader inStream:inStream. |
|
3489 | 2116 |
[ |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2117 |
reader fromStream:inStream. |
3605
b5c70808fc8c
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
3489
diff
changeset
|
2118 |
] ensure:[ |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2119 |
inStream close. |
3489 | 2120 |
]. |
1551 | 2121 |
^ reader |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2122 |
|
1551 | 2123 |
" |
6060 | 2124 |
XPMReader readFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
2125 |
(XPMReader readFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm') image |
|
1551 | 2126 |
" |
2127 |
||
5737
f39cc6dc9848
raise different error in #readFile: for unsupported filetypes
Claus Gittinger <cg@exept.de>
parents:
5567
diff
changeset
|
2128 |
"Modified: / 04-04-2011 / 14:16:56 / cg" |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2129 |
! |
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2130 |
|
3839 | 2131 |
readStream:aStream |
4714 | 2132 |
"create a reader and let it read a stream (in my format). |
6060 | 2133 |
Return the reader, NOT the image (however, the reader has already read the image, |
2134 |
so it can be asked with 'reader image'). |
|
2135 |
The stream remains open." |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2136 |
|
3839 | 2137 |
|reader| |
2138 |
||
2139 |
reader := self new. |
|
2140 |
reader fromStream:aStream. |
|
2141 |
^ reader |
|
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2142 |
|
1551 | 2143 |
"Created: 4.4.1997 / 22:08:13 / cg" |
6060 | 2144 |
! |
2145 |
||
2146 |
readerClassForFilename:aStringOrFilename |
|
2147 |
"return a reader class, determined by the file's name" |
|
2148 |
||
8505 | 2149 |
|fileName mime reader| |
2150 |
||
2151 |
fileName := aStringOrFilename asFilename. |
|
2152 |
mime := fileName mimeTypeFromName. |
|
6060 | 2153 |
mime isNil ifTrue:[ |
8505 | 2154 |
mime := fileName mimeTypeOfContents. |
6060 | 2155 |
]. |
2156 |
||
2157 |
mime notNil ifTrue:[ |
|
8505 | 2158 |
reader := MIMETypes imageReaderForType:mime. |
6060 | 2159 |
]. |
6167 | 2160 |
reader isNil ifTrue:[ |
8505 | 2161 |
"answer the reader when proceeding from this error" |
2162 |
reader := ConversionError raiseRequestErrorString:(' - unsupported image type: ''%1''' bindWith:(mime ? aStringOrFilename asFilename suffix)). |
|
6167 | 2163 |
]. |
2164 |
^ reader |
|
6060 | 2165 |
|
2166 |
" |
|
2167 |
self readerClassForFilename:('http://www.foo.bar/helloworld.png' asURL path) |
|
2168 |
self readerClassForFilename:('http://www.foo.bar/helloworld.gif' asURL path) |
|
2169 |
" |
|
285 | 2170 |
! ! |
2171 |
||
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2172 |
!ImageReader class methodsFor:'image support'! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2173 |
|
8095 | 2174 |
buildMaskFromColor:maskPixelValue for:pixels depth:depth width:width height:height |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2175 |
"helper for image formats, where an individual pixel value |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2176 |
has been defined as a mask-pixel (i.e. GIF). |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2177 |
Creates a maskImage, with zeros at positions where the image |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2178 |
has the given pixelValue; all other mask pixels are set to 1." |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2179 |
|
8095 | 2180 |
|maskArray bytesPerMaskRow mask ok| |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2181 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2182 |
bytesPerMaskRow := (width+7) // 8. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2183 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2184 |
maskArray := ByteArray uninitializedNew:bytesPerMaskRow * height. |
8095 | 2185 |
ok := false. |
8101 | 2186 |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2187 |
%{ |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2188 |
int __w = __intVal(width); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2189 |
int __h = __intVal(height); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2190 |
int __x, __y; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2191 |
int __outBits, __nOut; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2192 |
unsigned char *__inP, *__outP, *__nextOutRow; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2193 |
int __bpr = __intVal(bytesPerMaskRow); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2194 |
int __maskPixel = __intVal(maskPixelValue); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2195 |
#ifdef DEBUG |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2196 |
unsigned char *outEnd; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2197 |
#endif |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2198 |
|
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
2199 |
if (! __isByteArrayLike(pixels)) goto fail; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2200 |
if (! __isByteArray(maskArray)) goto fail; |
8095 | 2201 |
if (__intVal(depth) != 8) goto fail; |
8101 | 2202 |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2203 |
__inP = __ByteArrayInstPtr(pixels)->ba_element; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2204 |
__outP = __ByteArrayInstPtr(maskArray)->ba_element; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2205 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2206 |
#ifdef DEBUG |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2207 |
outEnd = __outP + (__byteArraySize(maskArray)); |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2208 |
#endif |
8095 | 2209 |
// |
2210 |
// printf("outP: %x outEnd: %x sz: %d\n", __outP, outEnd, __byteArraySize(maskArray)); |
|
2211 |
// |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2212 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2213 |
for (__y=__h; __y>0; __y--) { |
8101 | 2214 |
__outBits = 0; |
2215 |
__nOut = 8; |
|
2216 |
__nextOutRow = __outP + __bpr; |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2217 |
|
8101 | 2218 |
for (__x=__w; __x>=8; __x-=8) { |
2219 |
if (__inP[0] != __maskPixel) { __outBits |= 0x80; }; |
|
2220 |
if (__inP[1] != __maskPixel) { __outBits |= 0x40; }; |
|
2221 |
if (__inP[2] != __maskPixel) { __outBits |= 0x20; }; |
|
2222 |
if (__inP[3] != __maskPixel) { __outBits |= 0x10; }; |
|
2223 |
if (__inP[4] != __maskPixel) { __outBits |= 0x08; }; |
|
2224 |
if (__inP[5] != __maskPixel) { __outBits |= 0x04; }; |
|
2225 |
if (__inP[6] != __maskPixel) { __outBits |= 0x02; }; |
|
2226 |
if (__inP[7] != __maskPixel) { __outBits |= 0x01; }; |
|
2227 |
__inP += 8; |
|
2228 |
*__outP++ = __outBits; |
|
2229 |
__outBits = 0; |
|
2230 |
} |
|
2231 |
for (; __x>0; __x--) { |
|
2232 |
__outBits <<= 1; |
|
2233 |
if (*__inP != __maskPixel) { |
|
2234 |
__outBits |= 1; |
|
2235 |
} |
|
2236 |
__inP++; |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2237 |
|
8101 | 2238 |
// |
2239 |
// printf("x: %d bits: %x\n", __x, __outBits); |
|
2240 |
// |
|
2241 |
if (--__nOut == 0) { |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2242 |
#ifdef DEBUG |
8101 | 2243 |
if (__outP >= outEnd) { |
2244 |
if (@global(InfoPrinting) == true) { |
|
2245 |
console_fprintf(stderr, "oops %d\n", __LINE__); |
|
2246 |
} |
|
2247 |
goto fail; |
|
2248 |
} |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2249 |
#endif |
8101 | 2250 |
*__outP = __outBits; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2251 |
|
8101 | 2252 |
__outP++; |
2253 |
__nOut = 8; |
|
2254 |
__outBits = 0; |
|
2255 |
} |
|
2256 |
} |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2257 |
|
8101 | 2258 |
if (__nOut != 8) { |
2259 |
__outBits <<= __nOut; |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2260 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2261 |
#ifdef DEBUG |
8101 | 2262 |
if (__outP >= outEnd) { |
2263 |
if (@global(InfoPrinting) == true) { |
|
2264 |
console_fprintf(stderr, "oops2 %d\n", __LINE__); |
|
2265 |
} |
|
2266 |
goto fail; |
|
2267 |
} |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2268 |
#endif |
8101 | 2269 |
*__outP = __outBits; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2270 |
|
8101 | 2271 |
} |
2272 |
__outP = __nextOutRow; |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2273 |
} |
8095 | 2274 |
ok = true; |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2275 |
fail: ; |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2276 |
%}. |
8095 | 2277 |
ok ifFalse:[ |
8101 | 2278 |
"/ slow fallback... |
2279 |
self halt. |
|
2280 |
]. |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2281 |
mask := ImageMask width:width height:height fromArray:maskArray. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2282 |
^ mask |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2283 |
|
8095 | 2284 |
"Created: / 23-08-2017 / 17:10:03 / cg" |
2285 |
! |
|
2286 |
||
2287 |
buildMaskFromColor:maskPixelValue for:pixels width:width height:height |
|
2288 |
"helper for image formats, where an individual pixel value |
|
2289 |
has been defined as a mask-pixel (i.e. GIF). |
|
2290 |
Creates a maskImage, with zeros at positions where the image |
|
2291 |
has the given pixelValue; all other mask pixels are set to 1." |
|
2292 |
||
2293 |
^ self buildMaskFromColor:maskPixelValue for:pixels depth:8 width:width height:height |
|
2294 |
||
2295 |
"Created: / 21-06-1996 / 11:43:47 / cg" |
|
2296 |
"Modified: / 23-08-2017 / 17:13:23 / cg" |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2297 |
! ! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2298 |
|
1167 | 2299 |
!ImageReader class methodsFor:'image writing'! |
285 | 2300 |
|
2301 |
save:anImage onFile:aFileName |
|
7839 | 2302 |
"save the image in my format on aFileName. |
2303 |
Returns the imageReader instance (bad name; is a writer). |
|
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
2304 |
May raise Image cannotRepresentImageSignal, |
7839 | 2305 |
if the image cannot be represented in that format, |
2306 |
or it is not support" |
|
285 | 2307 |
|
2308 |
^ (self basicNew) save:anImage onFile:aFileName |
|
1574 | 2309 |
|
7839 | 2310 |
"Modified: / 10-04-1997 / 17:42:57 / cg" |
2311 |
"Modified (comment): / 05-02-2017 / 16:58:30 / cg" |
|
3932 | 2312 |
! |
2313 |
||
7172 | 2314 |
save:anImage onFile:aFileName quality:qualityPercent |
2315 |
"save the image in my format on aFileName. |
|
7839 | 2316 |
The qualityPercent argument is ignored by all lossless formats. |
2317 |
(however, JPG does care for it.) |
|
2318 |
Returns the imageReader instance (bad name; is a writer). |
|
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
2319 |
May raise Image cannotRepresentImageSignal, |
7839 | 2320 |
if the image cannot be represented in that format, |
2321 |
or it is not support" |
|
7172 | 2322 |
|
2323 |
^ (self basicNew) save:anImage onFile:aFileName quality:qualityPercent |
|
2324 |
||
7839 | 2325 |
"Modified: / 10-04-1997 / 17:42:57 / cg" |
2326 |
"Modified (comment): / 05-02-2017 / 16:58:45 / cg" |
|
7172 | 2327 |
! |
2328 |
||
3932 | 2329 |
save:anImage onStream:aStream |
7839 | 2330 |
"save the image in my format on aStream. |
2331 |
Returns the imageReader instance (bad name; is a writer). |
|
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
2332 |
May raise Image cannotRepresentImageSignal, |
7839 | 2333 |
if the image cannot be represented in that format, |
2334 |
or it is not support" |
|
3932 | 2335 |
|
2336 |
^ (self basicNew) save:anImage onStream:aStream |
|
2337 |
||
7839 | 2338 |
"Modified: / 10-04-1997 / 17:42:57 / cg" |
2339 |
"Modified (comment): / 05-02-2017 / 16:58:18 / cg" |
|
7172 | 2340 |
! |
2341 |
||
2342 |
save:anImage onStream:aStream quality:qualityPercent |
|
2343 |
"save the image in my format on a Stream. |
|
7839 | 2344 |
The qualityPercent argument is ignored by all lossless formats. |
2345 |
(however, JPG does care for it.) |
|
2346 |
Returns the imageReader instance (bad name; is a writer). |
|
7894
16136333fe33
increased the suffix/prefix size to 8192
Claus Gittinger <cg@exept.de>
parents:
7859
diff
changeset
|
2347 |
May raise Image cannotRepresentImageSignal, |
7839 | 2348 |
if the image cannot be represented in that format, |
2349 |
or it is not support" |
|
7172 | 2350 |
|
2351 |
^ (self basicNew) save:anImage onStream:aStream quality:qualityPercent |
|
2352 |
||
7174 | 2353 |
" |
7182 | 2354 |
(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield.gif' |
2355 |
(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield.jpg' |
|
7174 | 2356 |
(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield50.jpg' quality:50 |
2357 |
(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') saveOn:'garfield100.jpg' quality:100 |
|
2358 |
" |
|
7839 | 2359 |
|
2360 |
"Modified (comment): / 05-02-2017 / 16:58:11 / cg" |
|
7924 | 2361 |
! |
2362 |
||
2363 |
saveAll:aCollectionOfImages onFile:aFilename |
|
2364 |
"save an image collection in my format on a file. |
|
8101 | 2365 |
Not all file formats support multiple images, |
7924 | 2366 |
so be prepared for an exception to be raised." |
2367 |
||
2368 |
^ (self basicNew) saveAll:aCollectionOfImages onFile:aFilename |
|
2369 |
||
2370 |
"Created: / 22-02-2017 / 01:01:17 / cg" |
|
2371 |
! |
|
2372 |
||
2373 |
saveAll:aCollectionOfImages onStream:aStream |
|
2374 |
"save an image collection in my format on a Stream. |
|
8101 | 2375 |
Not all file formats support multiple images, |
7924 | 2376 |
so be prepared for an exception to be raised." |
2377 |
||
2378 |
^ (self basicNew) saveAll:aCollectionOfImages onStream:aStream |
|
2379 |
||
2380 |
"Created: / 22-02-2017 / 01:00:44 / cg" |
|
285 | 2381 |
! ! |
2382 |
||
8505 | 2383 |
!ImageReader class methodsFor:'private utilities'! |
2384 |
||
2385 |
writingFile:aFileName for:something do:aBlock |
|
2386 |
"helper for save image" |
|
2387 |
||
2388 |
|stream done| |
|
2389 |
||
2390 |
done := false. |
|
2391 |
||
2392 |
[ |
|
2393 |
stream := aFileName asFilename newReadWriteStream. |
|
2394 |
aBlock value:stream. |
|
2395 |
done := true. |
|
8958 | 2396 |
] on:OpenError do:[:ex| |
8505 | 2397 |
Image fileCreationErrorSignal |
2398 |
raiseWith:something |
|
2399 |
errorString:('file creation error: ' , ex description). |
|
2400 |
] ensure:[ |
|
2401 |
stream notNil ifTrue:[ |
|
2402 |
stream close. |
|
2403 |
done ifFalse:[ |
|
2404 |
OsError catch:[ |
|
2405 |
aFileName asFilename remove. |
|
2406 |
] |
|
2407 |
]. |
|
2408 |
]. |
|
2409 |
]. |
|
2410 |
||
2411 |
" |
|
2412 |
self writingFile:'/etc' for:nil do:[:arg| self halt]. |
|
2413 |
self writingFile:'/tmp/ttttt' for:nil do:[:arg| arg nextPutLine:'Hello']. |
|
2414 |
||
2415 |
self writingFile:'/tmp/ttttt' for:nil do:[:arg| ^ self]. |
|
2416 |
self assert:'/tmp/ttttt' asFilename exists not |
|
2417 |
" |
|
2418 |
||
2419 |
"Modified: / 04-08-2017 / 11:28:41 / stefan" |
|
2420 |
! ! |
|
2421 |
||
7859 | 2422 |
!ImageReader class methodsFor:'queries'! |
2423 |
||
2424 |
isAbstract |
|
2425 |
"Return if this class is an abstract class. |
|
2426 |
True is returned here for myself only; false for subclasses. |
|
2427 |
Abstract subclasses must redefine this again." |
|
2428 |
||
2429 |
^ self == ImageReader. |
|
2430 |
! ! |
|
2431 |
||
8246 | 2432 |
!ImageReader class methodsFor:'signal constants'! |
2433 |
||
2434 |
enforcedImageTypeQuery |
|
2435 |
"the query signal which can be used to override the default type |
|
2436 |
of image as returned by a reader. |
|
2437 |
Currently, only PNGReader supports. |
|
2438 |
Usage: |
|
2439 |
ImageReader enforcedImageTypeQuery answer:#rgb |
|
2440 |
do:[ |
|
2441 |
Image fromFile:anRGBAFile |
|
2442 |
] |
|
2443 |
" |
|
2444 |
||
2445 |
^ EnforcedImageTypeQuery |
|
2446 |
! ! |
|
2447 |
||
1167 | 2448 |
!ImageReader class methodsFor:'testing'! |
285 | 2449 |
|
2450 |
canRepresent:anImage |
|
2451 |
"return true, if anImage can be represented in my file format. |
|
2452 |
must be redefined in concrete subclasses which support saving." |
|
2453 |
||
2454 |
^ false |
|
2455 |
! |
|
2456 |
||
2457 |
isValidImageFile:aFileName |
|
2458 |
"return true, if aFileName contains an image this |
|
2459 |
reader understands - must be redefined in concrete subclasses |
|
2460 |
which support reading." |
|
2461 |
||
2462 |
^ false |
|
105 | 2463 |
! ! |
2464 |
||
2465 |
!ImageReader methodsFor:'accessing'! |
|
2466 |
||
285 | 2467 |
bitsPerPixel |
2468 |
"return the number of bits per pixel" |
|
2469 |
||
8146 | 2470 |
"/ if depth was given, that is what we use; |
2471 |
"/ otherwise, compute from bitsPerSample. |
|
2472 |
"/ notice, that depth is >= sum(bitsPerSample), |
|
2473 |
"/ for example, in a 16bit image, we mght have |
|
2474 |
"/ depth == 16 and bitsPerSample = 5+5+5, |
|
2475 |
||
2476 |
depth notNil ifTrue:[^ depth]. |
|
2477 |
||
3386
b9294699dbcf
care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2478 |
bitsPerSample isNil ifTrue:[^ nil]. |
5927 | 2479 |
^ bitsPerSample sum |
8146 | 2480 |
|
2481 |
"Modified (format): / 31-08-2017 / 18:09:59 / cg" |
|
285 | 2482 |
! |
2483 |
||
1300 | 2484 |
bitsPerRow |
2485 |
"return the number of bits in one scanline of the image" |
|
2486 |
||
3868 | 2487 |
^ width * (self bitsPerPixel). |
1300 | 2488 |
|
2489 |
"Created: 31.1.1997 / 10:38:42 / cg" |
|
2490 |
! |
|
2491 |
||
285 | 2492 |
bitsPerSample |
583 | 2493 |
"return the number of bits per sample" |
2494 |
||
285 | 2495 |
^ bitsPerSample |
583 | 2496 |
|
2497 |
"Modified: 22.4.1996 / 19:15:18 / cg" |
|
285 | 2498 |
! |
2499 |
||
1300 | 2500 |
bytesPerRow |
2501 |
"return the number of bytes in one scanline of the image" |
|
2502 |
||
7897 | 2503 |
^ Image bytesPerRowForWidth:width bitsPerPixel:(self bitsPerPixel) |
1300 | 2504 |
|
7897 | 2505 |
"Created: / 31-01-1997 / 10:39:06 / cg" |
2506 |
"Modified: / 16-02-2017 / 16:18:13 / cg" |
|
1300 | 2507 |
! |
2508 |
||
285 | 2509 |
colorMap |
583 | 2510 |
"return the colormap" |
2511 |
||
285 | 2512 |
^ colorMap |
583 | 2513 |
|
2514 |
"Modified: 22.4.1996 / 19:15:24 / cg" |
|
285 | 2515 |
! |
2516 |
||
7172 | 2517 |
compressQuality:qualityPercentIgnoredHere |
2518 |
"/ intentionally ignored here (redefined in JPEGReader) |
|
2519 |
! |
|
2520 |
||
4714 | 2521 |
data |
583 | 2522 |
"return the raw image data" |
2523 |
||
285 | 2524 |
^ data |
583 | 2525 |
|
2526 |
"Modified: 22.4.1996 / 19:15:31 / cg" |
|
285 | 2527 |
! |
2528 |
||
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2529 |
hasMultipleImages |
1773 | 2530 |
^ imageSequence size > 1 |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2531 |
|
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2532 |
"Created: 4.4.1997 / 21:37:06 / cg" |
1773 | 2533 |
"Modified: 24.6.1997 / 15:33:43 / cg" |
1550
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2534 |
! |
afee7c032a57
rudimentary support for multiple images.
Claus Gittinger <cg@exept.de>
parents:
1358
diff
changeset
|
2535 |
|
4714 | 2536 |
height |
583 | 2537 |
"return the height of the image" |
2538 |
||
285 | 2539 |
^ height |
583 | 2540 |
|
2541 |
"Modified: 22.4.1996 / 19:15:39 / cg" |
|
285 | 2542 |
! |
2543 |
||
105 | 2544 |
image |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2545 |
"return the image as represented by myself; |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2546 |
If my file contained multiple images, return the first one." |
105 | 2547 |
|
7908 | 2548 |
imageSequence notEmptyOrNil ifTrue:[ |
8110 | 2549 |
^ imageSequence first image |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2550 |
]. |
2080 | 2551 |
^ self makeImage. |
583 | 2552 |
|
7908 | 2553 |
"Modified: / 15-01-1998 / 15:46:24 / stefan" |
8110 | 2554 |
"Modified: / 26-08-2017 / 14:38:18 / cg" |
2082 | 2555 |
! |
2556 |
||
2557 |
imageFrames |
|
2558 |
"return a collection of all imageFrames as represented by myself. |
|
2559 |
ImageFrames are wrappers for individual images, which hold |
|
2560 |
additional information (such as image delay time). |
|
2561 |
Nil is return for single image formats/files." |
|
2562 |
||
2563 |
^ imageSequence |
|
2564 |
||
2565 |
"Created: / 1.4.1998 / 14:37:42 / cg" |
|
893
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2566 |
! |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2567 |
|
1551 | 2568 |
images |
2569 |
"return a collection of all images as represented by myself. |
|
2570 |
For compatibility with single-image formats, return a collection |
|
8110 | 2571 |
containing my single image here if the file format does not support |
1773 | 2572 |
multiple images. |
2573 |
Readers for formats with multiple images should leave the images |
|
2574 |
in the imageSequence instVar as a side effect of reading." |
|
1551 | 2575 |
|
2576 |
|img| |
|
2577 |
||
1773 | 2578 |
imageSequence notNil ifTrue:[ |
8110 | 2579 |
^ (imageSequence collect:[:aFrame | aFrame image]) |
1773 | 2580 |
]. |
2581 |
||
2082 | 2582 |
img := self makeImage. |
1551 | 2583 |
img isNil ifTrue:[ |
8110 | 2584 |
^ img |
1551 | 2585 |
]. |
2586 |
^ Array with:img |
|
2587 |
||
8110 | 2588 |
"Modified: / 01-04-1998 / 14:36:23 / cg" |
2589 |
"Modified (comment): / 26-08-2017 / 14:38:48 / cg" |
|
1551 | 2590 |
! |
2591 |
||
2080 | 2592 |
makeImage |
2082 | 2593 |
"return the image as represented by the values found in my |
2594 |
instvars; these have been typically set as a side effect of |
|
2595 |
the fromStream:-method, which reads images." |
|
2080 | 2596 |
|
2597 |
|image depth| |
|
2598 |
||
2599 |
depth := self bitsPerPixel. |
|
3839 | 2600 |
(depth notNil and:[data notNil]) ifTrue:[ |
8101 | 2601 |
image := Image newForDepth:depth. |
2602 |
image depth:depth. |
|
2603 |
inStream isFileStream ifTrue:[ |
|
2604 |
image fileName:inStream pathName. |
|
2605 |
]. |
|
2606 |
image |
|
2607 |
width:width |
|
2608 |
height:height |
|
2609 |
photometric:photometric |
|
2610 |
samplesPerPixel:samplesPerPixel |
|
2611 |
bitsPerSample:bitsPerSample |
|
2612 |
colorMap:colorMap |
|
2613 |
bits:data |
|
2614 |
mask:mask. |
|
3386
b9294699dbcf
care for nil-data when converting to an image
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2615 |
|
8101 | 2616 |
imageSequence notNil ifTrue:[ |
2617 |
image imageSequence:imageSequence. |
|
2618 |
]. |
|
2619 |
metaData notEmptyOrNil ifTrue:[ |
|
2620 |
image metaData:metaData |
|
2621 |
]. |
|
2080 | 2622 |
]. |
2623 |
^ image |
|
2624 |
||
8026 | 2625 |
"Modified: / 15-01-1998 / 15:46:24 / stefan" |
2626 |
"Created: / 01-04-1998 / 14:09:45 / cg" |
|
2627 |
"Modified: / 17-05-2017 / 14:37:16 / mawalch" |
|
2080 | 2628 |
! |
2629 |
||
893
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2630 |
mask |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2631 |
"return the image mask (or nil)" |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2632 |
|
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2633 |
^ mask |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2634 |
|
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2635 |
"Modified: 22.4.1996 / 19:15:31 / cg" |
24dc4b26a486
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2636 |
"Created: 20.6.1996 / 17:08:29 / cg" |
105 | 2637 |
! |
2638 |
||
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2639 |
numberOfImages |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2640 |
"return the number of images as read. |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2641 |
By default (here), I hold a single image; |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2642 |
however, some fileFormats allow for multiple images" |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2643 |
|
1773 | 2644 |
|n| |
2645 |
||
2646 |
(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
|
2647 |
^ n |
1773 | 2648 |
]. |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2649 |
^ 1 |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2650 |
|
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2651 |
"Created: 21.6.1997 / 18:33:45 / cg" |
1773 | 2652 |
"Modified: 24.6.1997 / 15:33:26 / cg" |
1772
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2653 |
! |
56b3ae478bbb
changes to support multiple images
Claus Gittinger <cg@exept.de>
parents:
1661
diff
changeset
|
2654 |
|
105 | 2655 |
photometric |
6309 | 2656 |
"return the photometric interpretation of the image data. |
2657 |
This may be a somewhat old leftover from times, when tiff was the first image file type to be read. |
|
2658 |
Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one. |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2659 |
However, in the meantime, many other classes depend on that, so that it should be kept as an API |
6309 | 2660 |
- even when the internal representation will be replaced by something better in the future." |
583 | 2661 |
|
105 | 2662 |
^ photometric |
583 | 2663 |
|
2664 |
"Modified: 22.4.1996 / 19:15:57 / cg" |
|
105 | 2665 |
! |
2666 |
||
2667 |
samplesPerPixel |
|
583 | 2668 |
"return the number of samples per pixel" |
2669 |
||
105 | 2670 |
^ samplesPerPixel |
583 | 2671 |
|
2672 |
"Modified: 22.4.1996 / 19:16:03 / cg" |
|
105 | 2673 |
! |
2674 |
||
285 | 2675 |
width |
583 | 2676 |
"return the width of the image" |
2677 |
||
285 | 2678 |
^ width |
583 | 2679 |
|
2680 |
"Modified: 22.4.1996 / 19:16:10 / cg" |
|
105 | 2681 |
! ! |
2682 |
||
3263 | 2683 |
!ImageReader methodsFor:'accessing-private'! |
1355 | 2684 |
|
2685 |
byteOrder:aSymbol |
|
2686 |
"set the byte order - either #lsb or #msb" |
|
2687 |
||
2688 |
byteOrder := aSymbol |
|
2689 |
||
2690 |
"Created: 15.2.1997 / 13:58:50 / cg" |
|
2691 |
! |
|
2692 |
||
2693 |
inStream |
|
2694 |
^ inStream |
|
2695 |
||
2696 |
"Created: 15.2.1997 / 13:57:40 / cg" |
|
2697 |
! |
|
2698 |
||
2699 |
inStream:aStream |
|
2700 |
inStream := aStream |
|
2701 |
||
2702 |
"Created: 15.2.1997 / 13:57:35 / cg" |
|
2703 |
! ! |
|
2704 |
||
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2705 |
!ImageReader methodsFor:'error reporting'! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2706 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2707 |
fileFormatError:aMessage |
7925 | 2708 |
"report a format error - no image could be read. |
2709 |
The error may be proceeded, then a nil is returned (useful for image sequences as in ICNS)" |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2710 |
|
8129 | 2711 |
^ self fileFormatError:aMessage with:nil |
2712 |
||
2713 |
"Created: / 03-02-1998 / 17:50:06 / cg" |
|
2714 |
"Modified: / 29-08-2017 / 23:00:51 / cg" |
|
2715 |
! |
|
2716 |
||
2717 |
fileFormatError:aMessage with:argument |
|
2718 |
"report a format error - no image could be read. |
|
2719 |
The error may be proceeded, then a nil is returned (useful for image sequences as in ICNS)" |
|
2720 |
||
4055 | 2721 |
|errorString| |
2722 |
||
8709 | 2723 |
errorString := self className , ' [error]: ' , (aMessage bindWith:argument). |
4055 | 2724 |
inStream isFileStream ifTrue:[ |
8110 | 2725 |
errorString := errorString , Character cr, '[in "' , inStream pathName , '"]' |
4055 | 2726 |
]. |
2727 |
||
6618 | 2728 |
Image badImageFormatQuerySignal raiseRequestErrorString:errorString. |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2729 |
^ nil |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2730 |
|
8129 | 2731 |
"Created: / 29-08-2017 / 23:00:37 / cg" |
8709 | 2732 |
"Modified: / 28-06-2019 / 09:02:57 / Claus Gittinger" |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2733 |
! ! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2734 |
|
105 | 2735 |
!ImageReader methodsFor:'i/o support'! |
2736 |
||
2737 |
readLong |
|
2738 |
"return the next 4-byte long, honoring the byte-order" |
|
2739 |
||
7142 | 2740 |
^ inStream nextInt32MSB:(byteOrder ~~ #lsb) |
105 | 2741 |
! |
2742 |
||
2743 |
readShort |
|
2744 |
"return the next 2-byte short, honoring the byte-order" |
|
2745 |
||
7142 | 2746 |
^ inStream nextUnsignedInt16MSB:(byteOrder ~~ #lsb) |
105 | 2747 |
! |
2748 |
||
2749 |
readShortLong |
|
2750 |
"return the next 2-byte short, honoring the byte-order. |
|
2751 |
There are actually 4 bytes read, but only 2 looked at." |
|
2752 |
||
2753 |
|bytes val| |
|
2754 |
||
153 | 2755 |
bytes := ByteArray uninitializedNew:4. |
105 | 2756 |
inStream nextBytes:4 into:bytes. |
2757 |
(byteOrder == #lsb) ifTrue:[ |
|
2758 |
val := bytes at:2. |
|
2759 |
val := val * 256 + (bytes at:1) |
|
2760 |
] ifFalse:[ |
|
2761 |
val := bytes at:3. |
|
2762 |
val := val * 256 + (bytes at:4) |
|
2763 |
]. |
|
2764 |
^ val |
|
2765 |
! |
|
2766 |
||
5318 | 2767 |
readUnsignedLong |
2768 |
"return the next 4-byte long, honoring the byte-order" |
|
2769 |
||
7142 | 2770 |
^ inStream nextUnsignedInt32MSB:(byteOrder ~~ #lsb) |
5318 | 2771 |
! |
2772 |
||
105 | 2773 |
writeLong:anInteger |
2774 |
"write a 4-byte long, honoring the byte-order." |
|
2775 |
||
7142 | 2776 |
outStream nextPutInt32:anInteger MSB:(byteOrder ~~ #lsb) |
105 | 2777 |
! |
2778 |
||
2779 |
writeShort:anInteger |
|
2780 |
"write a 2-byte short, honoring the byte-order." |
|
2781 |
||
7142 | 2782 |
outStream nextPutInt16:anInteger MSB:(byteOrder ~~ #lsb) |
105 | 2783 |
! ! |
285 | 2784 |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2785 |
!ImageReader methodsFor:'image reading'! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2786 |
|
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2787 |
fromStream:aStream |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2788 |
"read an image in my format from aStream. |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2789 |
Leave image description in instance variables." |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2790 |
|
3839 | 2791 |
self inStream:aStream. |
2792 |
self readImage. |
|
2793 |
! |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2794 |
|
3839 | 2795 |
readImage |
2796 |
"read an image in my format from my inStream. |
|
2797 |
Leave image description in instance variables." |
|
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2798 |
|
3839 | 2799 |
self subclassResponsibility. |
2039
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2800 |
! ! |
00e10543cf57
added common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2801 |
|
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
2802 |
!ImageReader methodsFor:'image reading support'! |
285 | 2803 |
|
929
f792d9689def
Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
893
diff
changeset
|
2804 |
buildMaskFromColor:maskPixelValue |
1631
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
2805 |
"helper for image formats, where an individual pixel value |
fc944d181796
use ImageMask instead of Depth1Image
Claus Gittinger <cg@exept.de>
parents:
1574
diff
changeset
|
2806 |
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
|
2807 |
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
|
2808 |
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
|
2809 |
|
4714 | 2810 |
mask := self class |
8101 | 2811 |
buildMaskFromColor:maskPixelValue |
2812 |
for:data depth:(self bitsPerPixel) |
|
2813 |
width:width height:height |
|
929
f792d9689def
Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
893
diff
changeset
|
2814 |
|
8095 | 2815 |
"Modified: / 23-08-2017 / 17:11:51 / cg" |
1983
03a93138c52a
made buildMask public and a class method (functionality also needed by JavaVM)
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
2816 |
! ! |
929
f792d9689def
Moved #buildMask from GIFReader to #buildMaskFromColor:
Stefan Vogel <sv@exept.de>
parents:
893
diff
changeset
|
2817 |
|
285 | 2818 |
!ImageReader methodsFor:'image writing'! |
2819 |
||
2820 |
save:image onFile:aFileName |
|
2821 |
"save image in my format on aFile" |
|
2822 |
||
8505 | 2823 |
self class writingFile:aFileName for:image do:[:stream | |
2824 |
self save:image onStream:stream. |
|
5567 | 2825 |
]. |
7172 | 2826 |
! |
2827 |
||
2828 |
save:image onFile:aFileName quality:qualityPercentOrNil |
|
2829 |
"save image in my format on aFile" |
|
2830 |
||
2831 |
self compressQuality:qualityPercentOrNil. |
|
2832 |
self save:image onFile:aFileName |
|
3933
10147dc53aef
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
3932
diff
changeset
|
2833 |
|
5567 | 2834 |
"Modified: / 01-06-2010 / 19:02:17 / cg" |
3932 | 2835 |
! |
2836 |
||
2837 |
save:image onStream:aStream |
|
7172 | 2838 |
"save image in my file-format onto aStream" |
3932 | 2839 |
|
4714 | 2840 |
^ Image cannotRepresentImageSignal |
7182 | 2841 |
raiseWith:image |
2842 |
errorString:('image save not implemented/supported for this format'). |
|
7172 | 2843 |
! |
2844 |
||
2845 |
save:image onStream:aStream quality:qualityPercentOrNil |
|
2846 |
"save image in my format on a Stream. |
|
2847 |
QualityPercent is ignored by lossless formats (jpg uses it)" |
|
2848 |
||
2849 |
self compressQuality:qualityPercentOrNil. |
|
2850 |
self save:image onStream:aStream |
|
6057 | 2851 |
! |
2852 |
||
2853 |
saveAll:aCollectionOfImages onFile:aFileName |
|
2854 |
"save a collection of images in my format on aFile. |
|
8101 | 2855 |
Not all file formats support multiple images, |
7924 | 2856 |
so be prepared for an exception to be raised." |
6057 | 2857 |
|
8505 | 2858 |
self class writingFile:aFileName for:aCollectionOfImages do:[:stream | |
2859 |
self saveAll:aCollectionOfImages onStream:stream. |
|
6057 | 2860 |
]. |
2861 |
||
2862 |
"Modified: / 01-06-2010 / 19:02:17 / cg" |
|
7924 | 2863 |
"Modified (comment): / 22-02-2017 / 01:00:03 / cg" |
6057 | 2864 |
! |
2865 |
||
2866 |
saveAll:aCollectionOfImages onStream:aStream |
|
2867 |
"save an image collection in my format on a Stream. |
|
8101 | 2868 |
Not all file formats support multiple images, |
7924 | 2869 |
so be prepared for an exception to be raised." |
6057 | 2870 |
|
2871 |
^ Image cannotRepresentImageSignal |
|
8101 | 2872 |
raiseWith:aCollectionOfImages |
2873 |
errorString:('save of imageSequence not implemented/supported for this format'). |
|
7924 | 2874 |
|
2875 |
"Modified (comment): / 22-02-2017 / 01:00:11 / cg" |
|
285 | 2876 |
! ! |
2877 |
||
1358 | 2878 |
!ImageReader methodsFor:'initialization'! |
2879 |
||
2880 |
initialize |
|
2881 |
||
2882 |
"Created: 18.2.1997 / 17:08:31 / cg" |
|
2883 |
! ! |
|
2884 |
||
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2885 |
!ImageReader methodsFor:'progress reporting'! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2886 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2887 |
dimensionCallBack:aBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2888 |
"set the block, which is evaluated during the readProcess, as soon as |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2889 |
the images dimension is known. This is useful for background image reading, |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2890 |
if the size is need to be known (for example: for formatting purposes). |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2891 |
Obsoleted by dimensionHolder." |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2892 |
|
4177 | 2893 |
<resource:#obsolete> |
3965 | 2894 |
self obsoleteMethodWarning:'use #dimensionHolder'. |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2895 |
dimensionCallBack := aBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2896 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2897 |
"Created: 14.9.1996 / 17:10:58 / cg" |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2898 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2899 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2900 |
dimensionHolder:aValueHolderOrBlock |
4714 | 2901 |
"set the valueHolder or block, which is evaluated during the readProcess, |
2902 |
as soon as the images dimension is known. |
|
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2903 |
Useful for background image reading, if the size is need to be known (for example: for formatting purposes)." |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2904 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2905 |
dimensionHolder := aValueHolderOrBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2906 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2907 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2908 |
progressHolder:aValueHolderOrBlock |
4714 | 2909 |
"set the valueHolder or block, which is evaluated during the readProcess, |
2910 |
and set with progress information (0..100 percent). |
|
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2911 |
Useful for user feedback" |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2912 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2913 |
progressHolder := aValueHolderOrBlock |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2914 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2915 |
|
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2916 |
reportDimension |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2917 |
dimensionCallBack notNil ifTrue:[ |
4033 | 2918 |
dimensionCallBack value:self |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2919 |
]. |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2920 |
dimensionHolder notNil ifTrue:[ |
4033 | 2921 |
dimensionHolder value:(width @ height) |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2922 |
]. |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2923 |
! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2924 |
|
3957 | 2925 |
reportProgress:fraction |
2926 |
"can be used by a GUI application to indicate loading progress (0..1)" |
|
2927 |
||
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2928 |
progressHolder notNil ifTrue:[ |
4033 | 2929 |
progressHolder value:fraction |
3955
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2930 |
]. |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2931 |
! ! |
6f48b9693fe5
dimensionReport and progressReport hooks
Claus Gittinger <cg@exept.de>
parents:
3933
diff
changeset
|
2932 |
|
8246 | 2933 |
!ImageReader::EnforcedImageTypeQuery class methodsFor:'documentation'! |
2934 |
||
2935 |
documentation |
|
2936 |
" |
|
2937 |
consider this a hack (but a not too bad one): |
|
2938 |
||
2939 |
with pngReader (and maybe others), we may want to read an image file, |
|
2940 |
but ignore the alpha channel. |
|
2941 |
I.e. read it as an rgb image although the image file is actually rgba formatted. |
|
2942 |
This is useful, if the image contains invalid alpha information anyway, |
|
2943 |
as when asking appium for a screen shot |
|
2944 |
(there are no transparent pixels on the screen - at least not until we get glass-plate displays...) |
|
2945 |
||
2946 |
Instead of passing this information down through all the possible image and image reader interfaces, |
|
2947 |
this query is asked by some readers (currently only pngReader) and |
|
2948 |
can be answered high above by a caller to answer #rgb. |
|
2949 |
||
2950 |
The default answer (nil) leads to the old behavior in that the file itself determines the format. |
|
2951 |
Please take a look at the concrete image reader documentation for which answers are valid and useful. |
|
2952 |
||
2953 |
[author:] |
|
2954 |
cg |
|
2955 |
||
2956 |
[instance variables:] |
|
2957 |
||
2958 |
[class variables:] |
|
2959 |
||
2960 |
[see also:] |
|
2961 |
||
2962 |
" |
|
2963 |
! ! |
|
2964 |
||
1167 | 2965 |
!ImageReader class methodsFor:'documentation'! |
285 | 2966 |
|
2967 |
version |
|
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2968 |
^ '$Header$' |
5481
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
2969 |
! |
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
2970 |
|
93de6ee2ed5a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5318
diff
changeset
|
2971 |
version_CVS |
6902
6357c181c178
eliminated a compiler warning
Claus Gittinger <cg@exept.de>
parents:
6761
diff
changeset
|
2972 |
^ '$Header$' |
285 | 2973 |
! ! |
8110 | 2974 |