0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1991-93 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ImageReader subclass:#TIFFReader
|
|
14 |
instanceVariableNames:'planarConfiguration
|
|
15 |
subFileType stripOffsets rowsPerStrip
|
|
16 |
fillOrder compression group3options predictor
|
|
17 |
stripByteCounts
|
|
18 |
currentOffset
|
|
19 |
stripOffsetsPos stripByteCountsPos bitsPerSamplePos
|
|
20 |
colorMapPos'
|
|
21 |
classVariableNames:''
|
|
22 |
poolDictionaries:''
|
|
23 |
category:'Graphics-Support'
|
|
24 |
!
|
|
25 |
|
|
26 |
TIFFReader comment:'
|
|
27 |
|
|
28 |
COPYRIGHT (c) 1991-93 by Claus Gittinger
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
%W% %E%
|
|
32 |
written Summer 91 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!TIFFReader class methodsFor:'documentation'!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
This class knows how to read TIFF files (and will
|
|
40 |
learn sometime in the future how to write them).
|
|
41 |
Currently, not all formats are implemented and of
|
|
42 |
those that are, not all are tested.
|
|
43 |
It should work with most rgb, mono and 2-plane greyscale
|
|
44 |
images, since this is what I have as test material on
|
|
45 |
the NeXT.
|
|
46 |
It supports uncompressed, LZW and G3 compressed images;
|
|
47 |
JPEG is currently not implemented.
|
|
48 |
More formats and compressions will come ...
|
|
49 |
"
|
|
50 |
! !
|
|
51 |
|
|
52 |
!TIFFReader methodsFor:'reading from file'!
|
|
53 |
|
|
54 |
fromFile:aFileName
|
|
55 |
|char1 char2 version
|
|
56 |
numberOfTags "{ Class: SmallInteger }"
|
|
57 |
tagType "{ Class: SmallInteger }"
|
|
58 |
numberType "{ Class: SmallInteger }"
|
|
59 |
length "{ Class: SmallInteger }"
|
|
60 |
result offset ok|
|
|
61 |
|
|
62 |
inStream := FileStream readonlyFileNamed:aFileName.
|
|
63 |
inStream isNil ifTrue:[
|
|
64 |
'open error' printNewline.
|
|
65 |
^ nil
|
|
66 |
].
|
|
67 |
|
|
68 |
char1 := inStream next.
|
|
69 |
char2 := inStream next.
|
|
70 |
(char1 ~~ char2) ifTrue:[
|
|
71 |
'not a tiff file' printNewline.
|
|
72 |
inStream close.
|
|
73 |
^ nil
|
|
74 |
].
|
|
75 |
(char1 == $I) ifTrue:[
|
|
76 |
byteOrder := #lsb
|
|
77 |
] ifFalse:[
|
|
78 |
(char1 == $M) ifTrue:[
|
|
79 |
byteOrder := #msb
|
|
80 |
] ifFalse:[
|
|
81 |
'not a tiff file' printNewline.
|
|
82 |
inStream close.
|
|
83 |
^ nil
|
|
84 |
]
|
|
85 |
].
|
|
86 |
|
|
87 |
version := self readShort.
|
|
88 |
(version ~~ 42) ifTrue:[
|
|
89 |
'version of tiff-file not supported' printNewline.
|
|
90 |
inStream close.
|
|
91 |
^ nil
|
|
92 |
].
|
|
93 |
|
|
94 |
"setup default values"
|
|
95 |
|
|
96 |
compression := 1. "none"
|
|
97 |
fillOrder := #msb.
|
|
98 |
planarConfiguration := 1.
|
|
99 |
photometric := nil.
|
|
100 |
bitsPerSample := 1.
|
|
101 |
samplesPerPixel := 1.
|
|
102 |
width := nil.
|
|
103 |
height := nil.
|
|
104 |
stripOffsets := nil.
|
|
105 |
rowsPerStrip := nil.
|
|
106 |
"resolutionUnit := 2."
|
|
107 |
predictor := 1.
|
|
108 |
|
|
109 |
offset := self readLong + 1.
|
|
110 |
inStream position:offset.
|
|
111 |
|
|
112 |
numberOfTags := self readShort.
|
|
113 |
1 to:(numberOfTags) do:[:index |
|
|
114 |
tagType := self readShort.
|
|
115 |
numberType := self readShort.
|
|
116 |
length := self readLong.
|
|
117 |
self decodeTiffTag:tagType numberType:numberType
|
|
118 |
length:length
|
|
119 |
].
|
|
120 |
|
|
121 |
offset := self readLong.
|
|
122 |
(offset ~~ 0) ifTrue:[
|
|
123 |
'more tags ignored' printNewline
|
|
124 |
].
|
|
125 |
|
|
126 |
ok := true.
|
|
127 |
width isNil ifTrue:[
|
|
128 |
'missing width tag' printNewline.
|
|
129 |
ok := false
|
|
130 |
].
|
|
131 |
|
|
132 |
height isNil ifTrue:[
|
|
133 |
'missing length tag' printNewline.
|
|
134 |
ok := false
|
|
135 |
].
|
|
136 |
|
|
137 |
photometric isNil ifTrue:[
|
|
138 |
'missing photometric tag' printNewline.
|
|
139 |
ok := false
|
|
140 |
].
|
|
141 |
|
|
142 |
stripOffsets isNil ifTrue:[
|
|
143 |
'missing stripOffsets tag' printNewline.
|
|
144 |
ok := false
|
|
145 |
].
|
|
146 |
|
|
147 |
ok ifFalse:[
|
|
148 |
inStream close.
|
|
149 |
^ nil
|
|
150 |
].
|
|
151 |
|
|
152 |
"given all the information, read the bits"
|
|
153 |
|
|
154 |
rowsPerStrip isNil ifTrue:[
|
|
155 |
rowsPerStrip := height
|
|
156 |
].
|
|
157 |
|
|
158 |
(compression == 1) ifTrue:[
|
|
159 |
result := self readUncompressedTiffImageData
|
|
160 |
] ifFalse:[
|
|
161 |
(compression == 5) ifTrue:[
|
|
162 |
result := self readLZWTiffImageData
|
|
163 |
] ifFalse:[
|
|
164 |
(compression == 2) ifTrue:[
|
|
165 |
"result := self readCCITT3ModHuffmanTiffImageData"
|
|
166 |
'ccitt mod Huffman compression not implemented' printNewline
|
|
167 |
] ifFalse:[
|
|
168 |
(compression == 3) ifTrue:[
|
|
169 |
result := self readCCITTGroup3TiffImageData
|
|
170 |
] ifFalse:[
|
|
171 |
(compression == 4) ifTrue:[
|
|
172 |
"result := self readCCITTGroup4TiffImageData"
|
|
173 |
'ccitt group4 fax compression not implemented' printNewline
|
|
174 |
] ifFalse:[
|
|
175 |
(compression == 32773) ifTrue:[
|
|
176 |
result := self readPackbitsTiffImageData
|
|
177 |
] ifFalse:[
|
|
178 |
(compression == 32865) ifTrue:[
|
|
179 |
result := self readJPEGTiffImageData
|
|
180 |
] ifFalse:[
|
|
181 |
'compression type not known' printNewline
|
|
182 |
]
|
|
183 |
]
|
|
184 |
]
|
|
185 |
]
|
|
186 |
]
|
|
187 |
]
|
|
188 |
].
|
|
189 |
|
|
190 |
inStream close.
|
|
191 |
^ result
|
|
192 |
! !
|
|
193 |
|
|
194 |
!TIFFReader methodsFor:'writing to file'!
|
|
195 |
|
|
196 |
save:image onFile:aFileName
|
|
197 |
"save image as TIFF file on aFileName"
|
|
198 |
|
|
199 |
|pos1 pos|
|
|
200 |
|
|
201 |
outStream := FileStream newFileNamed:aFileName.
|
|
202 |
outStream isNil ifTrue:[
|
|
203 |
'create error' printNewline.
|
|
204 |
^ nil
|
|
205 |
].
|
|
206 |
|
|
207 |
byteOrder := #msb.
|
|
208 |
fillOrder := #msb.
|
|
209 |
width := image width.
|
|
210 |
height := image height.
|
|
211 |
photometric := image photometric.
|
|
212 |
samplesPerPixel := image samplesPerPixel.
|
|
213 |
bitsPerSample := image bitsPerSample.
|
|
214 |
colorMap := image colorMap.
|
|
215 |
planarConfiguration := 1.
|
|
216 |
compression := 1. "none"
|
|
217 |
data := image bits.
|
|
218 |
|
|
219 |
"save as msb"
|
|
220 |
|
|
221 |
currentOffset := 0.
|
|
222 |
|
|
223 |
outStream nextPut:$M.
|
|
224 |
outStream nextPut:$M.
|
|
225 |
currentOffset := currentOffset + 2.
|
|
226 |
|
|
227 |
outStream binary.
|
|
228 |
|
|
229 |
self writeShort:42. "version"
|
|
230 |
currentOffset := currentOffset + 2.
|
|
231 |
|
|
232 |
pos1 := outStream position.
|
|
233 |
self writeLong:0. "start of commands - filled in later"
|
|
234 |
currentOffset := currentOffset + 4.
|
|
235 |
|
|
236 |
"output strips"
|
|
237 |
|
|
238 |
self writeBits. "this outputs bits as strips, sets stripOffsets and stripByteCounts"
|
|
239 |
self writeStripOffsets. "this outputs strip offsets, sets stripOffsetsPos"
|
|
240 |
self writeStripByteCounts. "this outputs strip bytecounts, sets stripByteCountPos"
|
|
241 |
self writeBitsPerSample. "this outputs bitsPerSample, sets bitsPerSamplePos"
|
|
242 |
photometric == #palette ifTrue:[
|
|
243 |
self writeColorMap "this outputs colorMap, sets colorMapPos"
|
|
244 |
].
|
|
245 |
|
|
246 |
pos := outStream position. "backpatch tag offset"
|
|
247 |
outStream position:pos1.
|
|
248 |
self writeLong:(pos - 1).
|
|
249 |
outStream position:pos.
|
|
250 |
('patch tag offset at: ', (pos1 printStringRadix:16) , ' to ',
|
|
251 |
(pos printStringRadix:16)) printNewline.
|
|
252 |
|
|
253 |
"output tag data"
|
|
254 |
|
|
255 |
photometric == #palette ifTrue:[
|
|
256 |
self writeShort:9
|
|
257 |
] ifFalse:[
|
|
258 |
self writeShort:8. "8 tags"
|
|
259 |
].
|
|
260 |
self writeTag:256. "image width"
|
|
261 |
self writeTag:257. "image height"
|
|
262 |
self writeTag:258. "bits per sample"
|
|
263 |
self writeTag:259. "compression"
|
|
264 |
self writeTag:262. "photometric"
|
|
265 |
self writeTag:273. "strip offsets"
|
|
266 |
self writeTag:279. "strip byte counts"
|
|
267 |
self writeTag:284. "planarconfig"
|
|
268 |
photometric == #palette ifTrue:[
|
|
269 |
self writeTag:320 "colorMap"
|
|
270 |
].
|
|
271 |
self writeLong:0.
|
|
272 |
|
|
273 |
outStream close
|
|
274 |
! !
|
|
275 |
|
|
276 |
!TIFFReader methodsFor:'private'!
|
|
277 |
|
|
278 |
readLongs:n
|
|
279 |
|oldPos offset values|
|
|
280 |
|
|
281 |
values := Array new:n.
|
|
282 |
(n == 1) ifTrue:[
|
|
283 |
values at:1 put:(self readLong)
|
|
284 |
] ifFalse:[
|
|
285 |
offset := self readLong.
|
|
286 |
oldPos := inStream position.
|
|
287 |
inStream position:(offset + 1).
|
|
288 |
1 to:n do:[:index |
|
|
289 |
values at:index put:(self readLong)
|
|
290 |
].
|
|
291 |
inStream position:oldPos
|
|
292 |
].
|
|
293 |
^ values
|
|
294 |
!
|
|
295 |
|
|
296 |
writeLongs:longs
|
|
297 |
1 to:longs size do:[:l |
|
|
298 |
self writeLong:l
|
|
299 |
]
|
|
300 |
!
|
|
301 |
|
|
302 |
readShorts:n
|
|
303 |
|oldPos offset values|
|
|
304 |
|
|
305 |
values := Array new:n.
|
|
306 |
(n <= 2) ifTrue:[
|
|
307 |
values at:1 put:(self readShort).
|
|
308 |
(n == 2) ifTrue:[
|
|
309 |
values at:2 put:(self readShort)
|
|
310 |
] ifFalse:[
|
|
311 |
self readShort
|
|
312 |
]
|
|
313 |
] ifFalse:[
|
|
314 |
offset := self readLong.
|
|
315 |
oldPos := inStream position.
|
|
316 |
inStream position:(offset + 1).
|
|
317 |
1 to:n do:[:index |
|
|
318 |
values at:index put:(self readShort)
|
|
319 |
].
|
|
320 |
inStream position:oldPos
|
|
321 |
].
|
|
322 |
^ values
|
|
323 |
!
|
|
324 |
|
|
325 |
readChars:n
|
|
326 |
|oldPos offset string|
|
|
327 |
|
|
328 |
string := String new:(n - 1).
|
|
329 |
(n <= 4) ifTrue:[
|
|
330 |
inStream nextBytes:(n - 1) into:string
|
|
331 |
] ifFalse:[
|
|
332 |
offset := self readLong.
|
|
333 |
oldPos := inStream position.
|
|
334 |
inStream position:(offset + 1).
|
|
335 |
inStream nextBytes:(n - 1) into:string.
|
|
336 |
inStream position:oldPos
|
|
337 |
].
|
|
338 |
^ string
|
|
339 |
!
|
|
340 |
|
|
341 |
readFracts:cnt
|
|
342 |
|oldPos offset values n d|
|
|
343 |
|
|
344 |
values := Array new:cnt.
|
|
345 |
offset := self readLong.
|
|
346 |
oldPos := inStream position.
|
|
347 |
inStream position:(offset + 1).
|
|
348 |
1 to:cnt do:[:index |
|
|
349 |
n := self readLong.
|
|
350 |
d := self readLong.
|
|
351 |
values at:index put:(Fraction numerator:n denominator:d)
|
|
352 |
].
|
|
353 |
inStream position:oldPos.
|
|
354 |
^ values
|
|
355 |
!
|
|
356 |
|
|
357 |
decodeTiffTag:tagType numberType:numberType length:length
|
|
358 |
|offset value valueArray
|
|
359 |
val
|
|
360 |
n "{ Class: SmallInteger }" |
|
|
361 |
|
|
362 |
(numberType == 3) ifTrue:[
|
|
363 |
"short"
|
|
364 |
valueArray := self readShorts:length.
|
|
365 |
value := valueArray at:1
|
|
366 |
] ifFalse:[
|
|
367 |
(numberType == 4) ifTrue:[
|
|
368 |
"integer"
|
|
369 |
valueArray := self readLongs:length.
|
|
370 |
value := valueArray at:1
|
|
371 |
] ifFalse:[
|
|
372 |
(numberType == 2) ifTrue:[
|
|
373 |
"character"
|
|
374 |
value := self readChars:length
|
|
375 |
] ifFalse:[
|
|
376 |
(numberType == 5) ifTrue:[
|
|
377 |
"fraction"
|
|
378 |
valueArray := self readFracts:length.
|
|
379 |
value := valueArray at:1
|
|
380 |
] ifFalse:[
|
|
381 |
offset := self readLong
|
|
382 |
]
|
|
383 |
]
|
|
384 |
]
|
|
385 |
].
|
|
386 |
|
|
387 |
(tagType == 254) ifTrue:[
|
|
388 |
"NewSubfileType"
|
|
389 |
"newSubFileType := value."
|
|
390 |
'newSubfiletype ' print. value printNewline.
|
|
391 |
^ self
|
|
392 |
].
|
|
393 |
(tagType == 255) ifTrue:[
|
|
394 |
"SubfileType"
|
|
395 |
subFileType := value.
|
|
396 |
'subfiletype ' print. value printNewline.
|
|
397 |
^ self
|
|
398 |
].
|
|
399 |
(tagType == 256) ifTrue:[
|
|
400 |
"ImageWidth"
|
|
401 |
width := value.
|
|
402 |
'width ' print. width printNewline.
|
|
403 |
^ self
|
|
404 |
].
|
|
405 |
(tagType == 257) ifTrue:[
|
|
406 |
"ImageHeight"
|
|
407 |
height := value.
|
|
408 |
'height ' print. height printNewline.
|
|
409 |
^ self
|
|
410 |
].
|
|
411 |
(tagType == 258) ifTrue:[
|
|
412 |
"bitspersample"
|
|
413 |
bitsPerSample := valueArray.
|
|
414 |
'bitspersample ' print. bitsPerSample printNewline.
|
|
415 |
^ self
|
|
416 |
].
|
|
417 |
(tagType == 259) ifTrue:[
|
|
418 |
"compression"
|
|
419 |
compression := value.
|
|
420 |
'compression ' print. compression printNewline.
|
|
421 |
^ self
|
|
422 |
].
|
|
423 |
(tagType == 262) ifTrue:[
|
|
424 |
"photometric"
|
|
425 |
(value == 0) ifTrue:[
|
|
426 |
photometric := #whiteIs0
|
|
427 |
] ifFalse:[
|
|
428 |
(value == 1) ifTrue:[
|
|
429 |
photometric := #blackIs0
|
|
430 |
] ifFalse:[
|
|
431 |
(value == 2) ifTrue:[
|
|
432 |
photometric := #rgb
|
|
433 |
] ifFalse:[
|
|
434 |
(value == 3) ifTrue:[
|
|
435 |
photometric := #palette
|
|
436 |
] ifFalse:[
|
|
437 |
(value == 4) ifTrue:[
|
|
438 |
photometric := #transparency
|
|
439 |
] ifFalse:[
|
|
440 |
photometric := nil
|
|
441 |
]
|
|
442 |
]
|
|
443 |
]
|
|
444 |
]
|
|
445 |
].
|
|
446 |
'photometric ' print. photometric printNewline.
|
|
447 |
^ self
|
|
448 |
].
|
|
449 |
(tagType == 263) ifTrue:[
|
|
450 |
"Treshholding"
|
|
451 |
"threshholding := value."
|
|
452 |
'treshholding ' print. value printNewline.
|
|
453 |
^ self
|
|
454 |
].
|
|
455 |
(tagType == 264) ifTrue:[
|
|
456 |
"CellWidth"
|
|
457 |
"cellWidth:= value."
|
|
458 |
'cellWidth ' print. value printNewline.
|
|
459 |
^ self
|
|
460 |
].
|
|
461 |
(tagType == 265) ifTrue:[
|
|
462 |
"CellLength"
|
|
463 |
"cellLength:= value."
|
|
464 |
'cellLength ' print. value printNewline.
|
|
465 |
^ self
|
|
466 |
].
|
|
467 |
(tagType == 266) ifTrue:[
|
|
468 |
"fillOrder"
|
|
469 |
(value == 1) ifTrue:[
|
|
470 |
fillOrder := #msb
|
|
471 |
] ifFalse:[
|
|
472 |
(value == 2) ifTrue:[
|
|
473 |
fillOrder := #lsb
|
|
474 |
] ifFalse:[
|
|
475 |
fillOrder := nil
|
|
476 |
]
|
|
477 |
].
|
|
478 |
'fillorder ' print. fillOrder printNewline.
|
|
479 |
^ self
|
|
480 |
].
|
|
481 |
(tagType == 269) ifTrue:[
|
|
482 |
"documentName"
|
|
483 |
'documentName ' print. value printNewline.
|
|
484 |
^ self
|
|
485 |
].
|
|
486 |
(tagType == 270) ifTrue:[
|
|
487 |
"imageDescription"
|
|
488 |
'imageDescription ' print. value printNewline.
|
|
489 |
^ self
|
|
490 |
].
|
|
491 |
(tagType == 271) ifTrue:[
|
|
492 |
"make"
|
|
493 |
'make ' print. value printNewline.
|
|
494 |
^ self
|
|
495 |
].
|
|
496 |
(tagType == 272) ifTrue:[
|
|
497 |
"model"
|
|
498 |
'model ' print. value printNewline.
|
|
499 |
^ self
|
|
500 |
].
|
|
501 |
(tagType == 273) ifTrue:[
|
|
502 |
"stripoffsets"
|
|
503 |
stripOffsets := valueArray.
|
|
504 |
'stripOffsets Array(' print. stripOffsets size print. ')' printNewline.
|
|
505 |
^ self
|
|
506 |
].
|
|
507 |
(tagType == 274) ifTrue:[
|
|
508 |
"Orientation"
|
|
509 |
"orientation:= value."
|
|
510 |
'orientation ' print. value printNewline.
|
|
511 |
^ self
|
|
512 |
].
|
|
513 |
(tagType == 277) ifTrue:[
|
|
514 |
"samplesPerPixel"
|
|
515 |
samplesPerPixel := value.
|
|
516 |
'samplesperpixel ' print. samplesPerPixel printNewline.
|
|
517 |
^ self
|
|
518 |
].
|
|
519 |
(tagType == 278) ifTrue:[
|
|
520 |
"rowsperstrip"
|
|
521 |
rowsPerStrip := value.
|
|
522 |
'rowsperstrip ' print. rowsPerStrip printNewline.
|
|
523 |
^ self
|
|
524 |
].
|
|
525 |
(tagType == 279) ifTrue:[
|
|
526 |
"stripbytecount"
|
|
527 |
stripByteCounts := valueArray.
|
|
528 |
'stripByteCounts Array(' print.
|
|
529 |
stripByteCounts size print.
|
|
530 |
')' printNewline.
|
|
531 |
^ self
|
|
532 |
].
|
|
533 |
(tagType == 280) ifTrue:[
|
|
534 |
"MinSampleValue"
|
|
535 |
"minSampleValue:= value."
|
|
536 |
'minSampleValue ' print. value printNewline.
|
|
537 |
^ self
|
|
538 |
].
|
|
539 |
(tagType == 281) ifTrue:[
|
|
540 |
"MaxSampleValue"
|
|
541 |
"maxSampleValue:= value."
|
|
542 |
'maxSampleValue ' print. value printNewline.
|
|
543 |
^ self
|
|
544 |
].
|
|
545 |
(tagType == 282) ifTrue:[
|
|
546 |
"xResolution"
|
|
547 |
'xres ' print. value printNewline.
|
|
548 |
^ self
|
|
549 |
].
|
|
550 |
(tagType == 283) ifTrue:[
|
|
551 |
"yResolution"
|
|
552 |
'yres ' print. value printNewline.
|
|
553 |
^ self
|
|
554 |
].
|
|
555 |
(tagType == 284) ifTrue:[
|
|
556 |
"planarconfig"
|
|
557 |
(value == 1) ifTrue:[
|
|
558 |
planarConfiguration := 1
|
|
559 |
] ifFalse:[
|
|
560 |
(value == 2) ifTrue:[
|
|
561 |
planarConfiguration := 2
|
|
562 |
] ifFalse:[
|
|
563 |
planarConfiguration := nil
|
|
564 |
]
|
|
565 |
].
|
|
566 |
'planarconfig ' print. planarConfiguration printNewline.
|
|
567 |
^ self
|
|
568 |
].
|
|
569 |
(tagType == 285) ifTrue:[
|
|
570 |
"pageName"
|
|
571 |
'pageName ' print. value printNewline.
|
|
572 |
^ self
|
|
573 |
].
|
|
574 |
(tagType == 286) ifTrue:[
|
|
575 |
"xPosition"
|
|
576 |
'xPos ' print. value printNewline.
|
|
577 |
^ self
|
|
578 |
].
|
|
579 |
(tagType == 287) ifTrue:[
|
|
580 |
"yPosition"
|
|
581 |
'yPos ' print. value printNewline.
|
|
582 |
^ self
|
|
583 |
].
|
|
584 |
(tagType == 288) ifTrue:[
|
|
585 |
"freeOffsets"
|
|
586 |
'freeOffsets ' print. value printNewline.
|
|
587 |
^ self
|
|
588 |
].
|
|
589 |
(tagType == 289) ifTrue:[
|
|
590 |
"freeByteCounts"
|
|
591 |
'freeByteCounts ' print. value printNewline.
|
|
592 |
^ self
|
|
593 |
].
|
|
594 |
(tagType == 290) ifTrue:[
|
|
595 |
"grayResponceUnit"
|
|
596 |
'grayResponceUnit' print. value printNewline.
|
|
597 |
^ self
|
|
598 |
].
|
|
599 |
(tagType == 291) ifTrue:[
|
|
600 |
"grayResponceCurve"
|
|
601 |
'grayResponceCurve' print. value printNewline.
|
|
602 |
^ self
|
|
603 |
].
|
|
604 |
(tagType == 292) ifTrue:[
|
|
605 |
"group3options"
|
|
606 |
group3options := value.
|
|
607 |
'group3options ' print. group3options printNewline.
|
|
608 |
^ self
|
|
609 |
].
|
|
610 |
(tagType == 293) ifTrue:[
|
|
611 |
"group4options"
|
|
612 |
"group4options := value."
|
|
613 |
'group4options ' print. value printNewline.
|
|
614 |
^ self
|
|
615 |
].
|
|
616 |
(tagType == 296) ifTrue:[
|
|
617 |
"resolutionunit"
|
|
618 |
(value == 1) ifTrue:[
|
|
619 |
'res-unit pixel' printNewline
|
|
620 |
] ifFalse:[
|
|
621 |
(value == 2) ifTrue:[
|
|
622 |
'res-unit inch' printNewline
|
|
623 |
] ifFalse:[
|
|
624 |
(value == 3) ifTrue:[
|
|
625 |
'res-unit mm' printNewline
|
|
626 |
] ifFalse:[
|
|
627 |
'res-unit invalid' printNewline
|
|
628 |
]
|
|
629 |
]
|
|
630 |
].
|
|
631 |
"resolutionUnit := value."
|
|
632 |
^ self
|
|
633 |
].
|
|
634 |
(tagType == 297) ifTrue:[
|
|
635 |
"pageNumber"
|
|
636 |
"pageNumber := value."
|
|
637 |
'pageNumber ' print. value printNewline.
|
|
638 |
^ self
|
|
639 |
].
|
|
640 |
(tagType == 300) ifTrue:[
|
|
641 |
"colorResponceUnit"
|
|
642 |
'colorResponceUnit' print. value printNewline.
|
|
643 |
^ self
|
|
644 |
].
|
|
645 |
(tagType == 301) ifTrue:[
|
|
646 |
"colorResponceCurve"
|
|
647 |
'colorResponceCurve' print. value printNewline.
|
|
648 |
^ self
|
|
649 |
].
|
|
650 |
(tagType == 306) ifTrue:[
|
|
651 |
"dateTime"
|
|
652 |
'dateTime ' print. value printNewline.
|
|
653 |
^ self
|
|
654 |
].
|
|
655 |
(tagType == 315) ifTrue:[
|
|
656 |
"artist"
|
|
657 |
'artist ' print. value printNewline.
|
|
658 |
^ self
|
|
659 |
].
|
|
660 |
(tagType == 317) ifTrue:[
|
|
661 |
"predictor"
|
|
662 |
predictor := value.
|
|
663 |
'predictor ' print. predictor printNewline.
|
|
664 |
^ self
|
|
665 |
].
|
|
666 |
(tagType == 320) ifTrue:[
|
|
667 |
"colorMap"
|
|
668 |
'colorMap (size=' print. valueArray size print. ')' printNewline.
|
|
669 |
n := valueArray size // 3.
|
|
670 |
colorMap := Array new:3.
|
|
671 |
colorMap at:1 put:(valueArray copyFrom:1 to:n).
|
|
672 |
colorMap at:2 put:(valueArray copyFrom:n+1 to:2*n).
|
|
673 |
colorMap at:3 put:(valueArray copyFrom:2*n+1 to:3*n).
|
|
674 |
1 to:3 do:[:c |
|
|
675 |
1 to:n do:[:e |
|
|
676 |
val := (colorMap at:c) at:e.
|
|
677 |
val := (val * 255.0 / 16rFFFF) rounded.
|
|
678 |
(colorMap at:c) at:e put:val
|
|
679 |
]
|
|
680 |
].
|
|
681 |
^ self
|
|
682 |
].
|
|
683 |
|
|
684 |
'tag:' print. tagType print. ' typ:' print. numberType print.
|
|
685 |
' len:' print. length print. ' offs:' print. offset print.
|
|
686 |
' val:' print. value print. ' valArr:' print. valueArray printNewline.
|
|
687 |
|
|
688 |
'unknown type ' print. tagType printNewline
|
|
689 |
!
|
|
690 |
|
|
691 |
writeBits
|
|
692 |
"write bits as one strip"
|
|
693 |
|
|
694 |
|offs bytesPerRow|
|
|
695 |
|
|
696 |
data size < 16rFFFF ifTrue:[
|
|
697 |
stripOffsets := Array with:(outStream position - 1).
|
|
698 |
stripByteCounts := Array with:(data size).
|
|
699 |
outStream nextPutBytes:data size from:data.
|
|
700 |
rowsPerStrip := height
|
|
701 |
] ifFalse:[
|
|
702 |
stripOffsets := Array new:height.
|
|
703 |
bytesPerRow := data size // height.
|
|
704 |
stripByteCounts := (Array new:height) atAllPut:bytesPerRow.
|
|
705 |
|
|
706 |
offs := 1.
|
|
707 |
1 to:height do:[:row |
|
|
708 |
stripOffsets at:row put:(outStream position - 1).
|
|
709 |
outStream nextPutBytes:data size from:data startingAt:offs.
|
|
710 |
offs := offs + bytesPerRow
|
|
711 |
].
|
|
712 |
rowsPerStrip := 1
|
|
713 |
].
|
|
714 |
'stripOffsets: ' print. stripOffsets printNewline.
|
|
715 |
'stripByteCounts: ' print. stripByteCounts printNewline.
|
|
716 |
!
|
|
717 |
|
|
718 |
writeColorMap
|
|
719 |
colorMapPos := outStream position.
|
|
720 |
colorMap do:[:subMap |
|
|
721 |
subMap do:[:entry |
|
|
722 |
"my maps are 8 bit - tiff map is 16 bit"
|
|
723 |
|
|
724 |
self writeShort:(entry / 255 * 16rFFFF) rounded
|
|
725 |
]
|
|
726 |
]
|
|
727 |
!
|
|
728 |
|
|
729 |
writeStripOffsets
|
|
730 |
'stripOffsets: ' print. stripOffsets printNewline.
|
|
731 |
'store stripoffsets at: ' print. outStream position printNewline.
|
|
732 |
stripOffsetsPos := outStream position.
|
|
733 |
stripOffsets do:[:o |
|
|
734 |
self writeLong:o
|
|
735 |
]
|
|
736 |
!
|
|
737 |
|
|
738 |
writeStripByteCounts
|
|
739 |
'stripByteCounts: ' print. stripByteCounts printNewline.
|
|
740 |
'store stripbytecounts at: ' print. outStream position printNewline.
|
|
741 |
stripByteCountsPos := outStream position.
|
|
742 |
stripByteCounts do:[:c |
|
|
743 |
self writeShort:c
|
|
744 |
]
|
|
745 |
!
|
|
746 |
|
|
747 |
writeBitsPerSample
|
|
748 |
'bitsPerSample: ' print. bitsPerSample printNewline.
|
|
749 |
'store bitspersample at: ' print. outStream position printNewline.
|
|
750 |
bitsPerSamplePos := outStream position.
|
|
751 |
bitsPerSample do:[:n |
|
|
752 |
self writeShort:n
|
|
753 |
]
|
|
754 |
!
|
|
755 |
|
|
756 |
writeTag:tagType
|
|
757 |
self writeTiffTag:tagType.
|
|
758 |
!
|
|
759 |
|
|
760 |
writeTiffTag:tagType
|
|
761 |
|value valueArray numberType count address|
|
|
762 |
|
|
763 |
count := 1.
|
|
764 |
address := nil.
|
|
765 |
(tagType == 253) ifTrue:[
|
|
766 |
"tiff class"
|
|
767 |
].
|
|
768 |
(tagType == 254) ifTrue:[
|
|
769 |
].
|
|
770 |
(tagType == 255) ifTrue:[
|
|
771 |
"SubfileType"
|
|
772 |
value := subFileType.
|
|
773 |
numberType := #long.
|
|
774 |
].
|
|
775 |
(tagType == 256) ifTrue:[
|
|
776 |
"ImageWidth"
|
|
777 |
value := width.
|
|
778 |
numberType := #short.
|
|
779 |
].
|
|
780 |
(tagType == 257) ifTrue:[
|
|
781 |
"ImageHeight"
|
|
782 |
value := height.
|
|
783 |
numberType := #short.
|
|
784 |
].
|
|
785 |
(tagType == 258) ifTrue:[
|
|
786 |
"bitspersample"
|
|
787 |
address := bitsPerSamplePos - 1.
|
|
788 |
numberType := #short.
|
|
789 |
count := bitsPerSample size.
|
|
790 |
valueArray := bitsPerSample
|
|
791 |
].
|
|
792 |
(tagType == 259) ifTrue:[
|
|
793 |
"compression"
|
|
794 |
value := compression.
|
|
795 |
numberType := #short.
|
|
796 |
].
|
|
797 |
(tagType == 262) ifTrue:[
|
|
798 |
"photometric"
|
|
799 |
(photometric == #whiteIs0) ifTrue:[
|
|
800 |
value := 0
|
|
801 |
] ifFalse:[
|
|
802 |
(photometric == #blackIs0) ifTrue:[
|
|
803 |
value := 1
|
|
804 |
] ifFalse:[
|
|
805 |
(photometric == #rgb) ifTrue:[
|
|
806 |
value := 2
|
|
807 |
] ifFalse:[
|
|
808 |
(photometric == #palette) ifTrue:[
|
|
809 |
value := 3
|
|
810 |
] ifFalse:[
|
|
811 |
(photometric == #transparency) ifTrue:[
|
|
812 |
value := 4
|
|
813 |
] ifFalse:[
|
|
814 |
self error:'bad photometric'
|
|
815 |
]
|
|
816 |
]
|
|
817 |
]
|
|
818 |
]
|
|
819 |
].
|
|
820 |
numberType := #short.
|
|
821 |
].
|
|
822 |
(tagType == 263) ifTrue:[
|
|
823 |
].
|
|
824 |
(tagType == 264) ifTrue:[
|
|
825 |
].
|
|
826 |
(tagType == 265) ifTrue:[
|
|
827 |
].
|
|
828 |
(tagType == 266) ifTrue:[
|
|
829 |
"fillOrder"
|
|
830 |
(fillOrder == #msb) ifTrue:[
|
|
831 |
value := 1
|
|
832 |
] ifFalse:[
|
|
833 |
(fillOrder == #lsb) ifTrue:[
|
|
834 |
value := 2
|
|
835 |
] ifFalse:[
|
|
836 |
self error:'bad fillOrder'
|
|
837 |
]
|
|
838 |
].
|
|
839 |
numberType := #short.
|
|
840 |
].
|
|
841 |
(tagType == 269) ifTrue:[
|
|
842 |
].
|
|
843 |
(tagType == 270) ifTrue:[
|
|
844 |
].
|
|
845 |
(tagType == 271) ifTrue:[
|
|
846 |
].
|
|
847 |
(tagType == 272) ifTrue:[
|
|
848 |
].
|
|
849 |
(tagType == 273) ifTrue:[
|
|
850 |
"stripoffsets"
|
|
851 |
address := stripOffsetsPos - 1.
|
|
852 |
numberType := #long.
|
|
853 |
count := stripOffsets size.
|
|
854 |
valueArray := stripOffsets
|
|
855 |
].
|
|
856 |
(tagType == 274) ifTrue:[
|
|
857 |
].
|
|
858 |
(tagType == 277) ifTrue:[
|
|
859 |
"samplesPerPixel"
|
|
860 |
value := samplesPerPixel.
|
|
861 |
numberType := #short.
|
|
862 |
].
|
|
863 |
(tagType == 278) ifTrue:[
|
|
864 |
"rowsperstrip"
|
|
865 |
value := rowsPerStrip.
|
|
866 |
numberType := #short.
|
|
867 |
].
|
|
868 |
(tagType == 279) ifTrue:[
|
|
869 |
"stripbytecount"
|
|
870 |
address := stripByteCountsPos - 1.
|
|
871 |
numberType := #short.
|
|
872 |
count := stripByteCounts size.
|
|
873 |
valueArray := stripByteCounts
|
|
874 |
].
|
|
875 |
(tagType == 280) ifTrue:[
|
|
876 |
"min sample value"
|
|
877 |
].
|
|
878 |
(tagType == 281) ifTrue:[
|
|
879 |
"max sample value"
|
|
880 |
].
|
|
881 |
(tagType == 282) ifTrue:[
|
|
882 |
"x resolution"
|
|
883 |
].
|
|
884 |
(tagType == 283) ifTrue:[
|
|
885 |
"y resolution"
|
|
886 |
].
|
|
887 |
(tagType == 284) ifTrue:[
|
|
888 |
"planarconfig"
|
|
889 |
value := planarConfiguration.
|
|
890 |
numberType := #short.
|
|
891 |
].
|
|
892 |
(tagType == 285) ifTrue:[
|
|
893 |
"pageName"
|
|
894 |
].
|
|
895 |
(tagType == 286) ifTrue:[
|
|
896 |
"xPosition"
|
|
897 |
].
|
|
898 |
(tagType == 287) ifTrue:[
|
|
899 |
"yPosition"
|
|
900 |
].
|
|
901 |
(tagType == 288) ifTrue:[
|
|
902 |
"freeOffsets"
|
|
903 |
].
|
|
904 |
(tagType == 289) ifTrue:[
|
|
905 |
"freeByteCounts"
|
|
906 |
].
|
|
907 |
(tagType == 290) ifTrue:[
|
|
908 |
"grayResponceUnit"
|
|
909 |
].
|
|
910 |
(tagType == 291) ifTrue:[
|
|
911 |
"grayResponceCurve"
|
|
912 |
].
|
|
913 |
(tagType == 292) ifTrue:[
|
|
914 |
"group3options"
|
|
915 |
value := group3options.
|
|
916 |
numberType := #long.
|
|
917 |
].
|
|
918 |
(tagType == 293) ifTrue:[
|
|
919 |
"group4options"
|
|
920 |
].
|
|
921 |
(tagType == 296) ifTrue:[
|
|
922 |
"resolutionunit"
|
|
923 |
^ self
|
|
924 |
].
|
|
925 |
(tagType == 297) ifTrue:[
|
|
926 |
"pageNumber"
|
|
927 |
].
|
|
928 |
(tagType == 300) ifTrue:[
|
|
929 |
"colorResponceUnit"
|
|
930 |
].
|
|
931 |
(tagType == 301) ifTrue:[
|
|
932 |
"colorResponceCurve"
|
|
933 |
].
|
|
934 |
(tagType == 306) ifTrue:[
|
|
935 |
"dateTime"
|
|
936 |
].
|
|
937 |
(tagType == 315) ifTrue:[
|
|
938 |
"artist"
|
|
939 |
].
|
|
940 |
(tagType == 317) ifTrue:[
|
|
941 |
"predictor"
|
|
942 |
].
|
|
943 |
(tagType == 320) ifTrue:[
|
|
944 |
"colormap"
|
|
945 |
address := colorMapPos - 1.
|
|
946 |
numberType := #short.
|
|
947 |
count := (colorMap at:1) size * 3.
|
|
948 |
].
|
|
949 |
|
|
950 |
(value isNil and:[address isNil]) ifTrue:[
|
|
951 |
self error:'unhandled tag'.
|
|
952 |
^ self
|
|
953 |
].
|
|
954 |
|
|
955 |
'tag:' print. tagType print. ' typ:' print. numberType print.
|
|
956 |
' len:' print. count print.
|
|
957 |
' val:' print. value printNewline.
|
|
958 |
|
|
959 |
self writeShort:tagType.
|
|
960 |
numberType == #short ifTrue:[
|
|
961 |
self writeShort:3.
|
|
962 |
self writeLong:count.
|
|
963 |
] ifFalse:[
|
|
964 |
numberType == #long ifTrue:[
|
|
965 |
self writeShort:4.
|
|
966 |
self writeLong:count.
|
|
967 |
] ifFalse:[
|
|
968 |
numberType == #byte ifTrue:[
|
|
969 |
self writeShort:1.
|
|
970 |
self writeLong:count.
|
|
971 |
] ifFalse:[
|
|
972 |
self error:'bad numbertype'
|
|
973 |
]
|
|
974 |
]
|
|
975 |
].
|
|
976 |
address notNil ifTrue:[
|
|
977 |
(numberType == #long and:[count == 1]) ifTrue:[
|
|
978 |
self writeLong:(valueArray at:1).
|
|
979 |
^ self
|
|
980 |
].
|
|
981 |
(numberType == #short and:[count <= 2]) ifTrue:[
|
|
982 |
self writeShort:(valueArray at:1).
|
|
983 |
count == 2 ifTrue:[
|
|
984 |
self writeShort:(valueArray at:2).
|
|
985 |
] ifFalse:[
|
|
986 |
self writeShort:0
|
|
987 |
].
|
|
988 |
^ self
|
|
989 |
].
|
|
990 |
(numberType == #byte and:[count <= 4]) ifTrue:[
|
|
991 |
outStream nextPut:(valueArray at:1).
|
|
992 |
count > 1 ifTrue:[
|
|
993 |
outStream nextPut:(valueArray at:2).
|
|
994 |
count > 2 ifTrue:[
|
|
995 |
outStream nextPut:(valueArray at:3).
|
|
996 |
count > 3 ifTrue:[
|
|
997 |
outStream nextPut:(valueArray at:4).
|
|
998 |
] ifFalse:[
|
|
999 |
outStream nextPut:0
|
|
1000 |
].
|
|
1001 |
] ifFalse:[
|
|
1002 |
outStream nextPut:0
|
|
1003 |
].
|
|
1004 |
] ifFalse:[
|
|
1005 |
outStream nextPut:0
|
|
1006 |
].
|
|
1007 |
^ self
|
|
1008 |
].
|
|
1009 |
self writeLong:address.
|
|
1010 |
^ self
|
|
1011 |
].
|
|
1012 |
numberType == #short ifTrue:[
|
|
1013 |
self writeShort:value.
|
|
1014 |
self writeShort:0
|
|
1015 |
] ifFalse:[
|
|
1016 |
numberType == #long ifTrue:[
|
|
1017 |
self writeLong:value
|
|
1018 |
] ifFalse:[
|
|
1019 |
numberType == #byte ifTrue:[
|
|
1020 |
outStream nextPut:value.
|
|
1021 |
outStream nextPut:0.
|
|
1022 |
outStream nextPut:0.
|
|
1023 |
outStream nextPut:0.
|
|
1024 |
] ifFalse:[
|
|
1025 |
self error:'bad numbertype'
|
|
1026 |
]
|
|
1027 |
]
|
|
1028 |
].
|
|
1029 |
!
|
|
1030 |
|
|
1031 |
readUncompressedTiffImageData
|
|
1032 |
|bytesPerRow bitsPerRow nPlanes
|
|
1033 |
stripNr "{ Class: SmallInteger }"
|
|
1034 |
offset "{ Class: SmallInteger }"
|
|
1035 |
row "{ Class: SmallInteger }"
|
|
1036 |
bytesPerStrip "{ Class: SmallInteger }"
|
|
1037 |
bitsPerPixel |
|
|
1038 |
|
|
1039 |
nPlanes := samplesPerPixel.
|
|
1040 |
|
|
1041 |
"only support 1-sample/pixel,
|
|
1042 |
with alpha - if separate planes,
|
|
1043 |
or rgb - if non separate planes and no alpha"
|
|
1044 |
|
|
1045 |
(nPlanes == 2) ifTrue:[
|
|
1046 |
(planarConfiguration ~~ 2) ifTrue:[
|
|
1047 |
self error:'with alpha, only separate planes supported'.
|
|
1048 |
^ nil
|
|
1049 |
].
|
|
1050 |
'ignoring alpha plane' printNewline.
|
|
1051 |
nPlanes := 1.
|
|
1052 |
bitsPerPixel := bitsPerSample at:1
|
|
1053 |
] ifFalse:[
|
|
1054 |
(nPlanes == 3) ifTrue:[
|
|
1055 |
(planarConfiguration ~~ 1) ifTrue:[
|
|
1056 |
self error:'only non separate planes supported'.
|
|
1057 |
^ nil
|
|
1058 |
].
|
|
1059 |
bitsPerSample ~= #(8 8 8) ifTrue:[
|
|
1060 |
self error:'only 8/8/8 rgb images supported'.
|
|
1061 |
^ nil
|
|
1062 |
].
|
|
1063 |
bitsPerPixel := 24
|
|
1064 |
] ifFalse:[
|
|
1065 |
(nPlanes ~~ 1) ifTrue:[
|
|
1066 |
self error:'format not supported'.
|
|
1067 |
^ nil
|
|
1068 |
].
|
|
1069 |
bitsPerPixel := bitsPerSample at:1
|
|
1070 |
]
|
|
1071 |
].
|
|
1072 |
|
|
1073 |
bitsPerRow := width * bitsPerPixel.
|
|
1074 |
bytesPerRow := bitsPerRow // 8.
|
|
1075 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[
|
|
1076 |
bytesPerRow := bytesPerRow + 1
|
|
1077 |
].
|
|
1078 |
|
|
1079 |
data := ByteArray uninitializedNew:(bytesPerRow * height).
|
|
1080 |
|
|
1081 |
offset := 1.
|
|
1082 |
stripNr := 0.
|
|
1083 |
|
|
1084 |
row := 1.
|
|
1085 |
bytesPerStrip := bytesPerRow * rowsPerStrip.
|
|
1086 |
[row <= height] whileTrue:[
|
|
1087 |
stripNr := stripNr + 1.
|
|
1088 |
inStream position:((stripOffsets at:stripNr) + 1).
|
|
1089 |
|
|
1090 |
inStream nextBytes:(bytesPerRow * rowsPerStrip)
|
|
1091 |
into:data
|
|
1092 |
startingAt:offset.
|
|
1093 |
|
|
1094 |
offset := offset + bytesPerStrip.
|
|
1095 |
row := row + rowsPerStrip
|
|
1096 |
]
|
|
1097 |
!
|
|
1098 |
|
|
1099 |
readLZWTiffImageData
|
|
1100 |
"read LZW compressed tiff data; this method only
|
|
1101 |
handles 3x8 rgb and 1x2 or 2x2 greyscale images.
|
|
1102 |
For 2x2 greyscale images, the alpha plane is ignored.
|
|
1103 |
(maybe other formats work also - its simply not
|
|
1104 |
tested)"
|
|
1105 |
|
|
1106 |
|bytesPerRow compressedStrip nPlanes
|
|
1107 |
bytesPerStrip "{ Class: SmallInteger }"
|
|
1108 |
nBytes "{ Class: SmallInteger }"
|
|
1109 |
prevSize "{ Class: SmallInteger }"
|
|
1110 |
stripNr "{ Class: SmallInteger }"
|
|
1111 |
offset "{ Class: SmallInteger }"
|
|
1112 |
row "{ Class: SmallInteger }" |
|
|
1113 |
|
|
1114 |
nPlanes := samplesPerPixel.
|
|
1115 |
|
|
1116 |
(nPlanes == 3) ifTrue:[
|
|
1117 |
((bitsPerSample at:1) ~~ 8) ifTrue:[
|
|
1118 |
self error:'only 8 bit/sample supported'.
|
|
1119 |
^ nil
|
|
1120 |
].
|
|
1121 |
((bitsPerSample at:2) ~~ 8) ifTrue:[
|
|
1122 |
self error:'only 8 bit/sample supported'.
|
|
1123 |
^ nil
|
|
1124 |
].
|
|
1125 |
((bitsPerSample at:3) ~~ 8) ifTrue:[
|
|
1126 |
self error:'only 8 bit/sample supported'.
|
|
1127 |
^ nil
|
|
1128 |
].
|
|
1129 |
bytesPerRow := width * samplesPerPixel.
|
|
1130 |
] ifFalse:[
|
|
1131 |
(nPlanes == 2) ifTrue:[
|
|
1132 |
(planarConfiguration ~~ 2) ifTrue:[
|
|
1133 |
self error:'only separate planes supported'.
|
|
1134 |
^ nil
|
|
1135 |
].
|
|
1136 |
'ignoring alpha plane' printNewline.
|
|
1137 |
nPlanes := 1
|
|
1138 |
].
|
|
1139 |
(nPlanes == 1) ifFalse:[
|
|
1140 |
self error:'only 3-sample rgb / monochrome supported'.
|
|
1141 |
^ nil
|
|
1142 |
].
|
|
1143 |
bytesPerRow := (width * (bitsPerSample at:1) + 7) // 8.
|
|
1144 |
].
|
|
1145 |
|
|
1146 |
stripByteCounts isNil ifTrue:[
|
|
1147 |
self error:'currently require stripByteCounts'.
|
|
1148 |
^ nil
|
|
1149 |
].
|
|
1150 |
|
|
1151 |
data := ByteArray uninitializedNew:(bytesPerRow * height).
|
|
1152 |
|
|
1153 |
offset := 1.
|
|
1154 |
stripNr := 0.
|
|
1155 |
|
|
1156 |
row := 1.
|
|
1157 |
bytesPerStrip := bytesPerRow * rowsPerStrip.
|
|
1158 |
prevSize := 0.
|
|
1159 |
[row <= height] whileTrue:[
|
|
1160 |
stripNr := stripNr + 1.
|
|
1161 |
inStream position:((stripOffsets at:stripNr) + 1).
|
|
1162 |
nBytes := stripByteCounts at:stripNr.
|
|
1163 |
(nBytes > prevSize) ifTrue:[
|
|
1164 |
compressedStrip := ByteArray uninitializedNew:nBytes.
|
|
1165 |
prevSize := nBytes
|
|
1166 |
].
|
|
1167 |
inStream nextBytes:nBytes
|
|
1168 |
into:compressedStrip.
|
|
1169 |
self class decompressLZWFrom:compressedStrip
|
|
1170 |
count:nBytes
|
|
1171 |
into:data
|
|
1172 |
startingAt:offset.
|
|
1173 |
offset := offset + bytesPerStrip.
|
|
1174 |
row := row + rowsPerStrip
|
|
1175 |
].
|
|
1176 |
|
|
1177 |
(predictor == 2) ifTrue:[
|
|
1178 |
self class decodeDelta:3 in:data width:width height:height
|
|
1179 |
]
|
|
1180 |
!
|
|
1181 |
|
|
1182 |
readCCITTGroup3TiffImageData
|
|
1183 |
"not really tested - all I got is a single
|
|
1184 |
fax from NeXT step"
|
|
1185 |
|
|
1186 |
|bytesPerRow bitsPerRow compressedStrip nPlanes
|
|
1187 |
stripNr "{ Class: SmallInteger }"
|
|
1188 |
offset "{ Class: SmallInteger }"
|
|
1189 |
row "{ Class: SmallInteger }"
|
|
1190 |
bytesPerStrip "{ Class: SmallInteger }" |
|
|
1191 |
|
|
1192 |
nPlanes := samplesPerPixel.
|
|
1193 |
(nPlanes == 2) ifTrue:[
|
|
1194 |
'ignoring alpha plane' printNewline.
|
|
1195 |
nPlanes := 1
|
|
1196 |
].
|
|
1197 |
|
|
1198 |
(nPlanes ~~ 1) ifTrue:[
|
|
1199 |
self error:'only monochrome/greyscale supported'.
|
|
1200 |
^ nil
|
|
1201 |
].
|
|
1202 |
|
|
1203 |
stripByteCounts isNil ifTrue:[
|
|
1204 |
self error:'currently require stripByteCounts'.
|
|
1205 |
^ nil
|
|
1206 |
].
|
|
1207 |
(rowsPerStrip ~~ 1) isNil ifTrue:[
|
|
1208 |
self error:'currently require rowsPerStrip to be 1'.
|
|
1209 |
^ nil
|
|
1210 |
].
|
|
1211 |
|
|
1212 |
|
|
1213 |
bitsPerRow := width * (bitsPerSample at:1).
|
|
1214 |
bytesPerRow := bitsPerRow // 8.
|
|
1215 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[
|
|
1216 |
bytesPerRow := bytesPerRow + 1
|
|
1217 |
].
|
|
1218 |
|
|
1219 |
data := ByteArray uninitializedNew:(bytesPerRow * height).
|
|
1220 |
compressedStrip := ByteArray uninitializedNew:bytesPerRow.
|
|
1221 |
|
|
1222 |
offset := 1.
|
|
1223 |
stripNr := 0.
|
|
1224 |
|
|
1225 |
row := 1.
|
|
1226 |
bytesPerStrip := bytesPerRow * rowsPerStrip.
|
|
1227 |
[row <= height] whileTrue:[
|
|
1228 |
stripNr := stripNr + 1.
|
|
1229 |
inStream position:((stripOffsets at:stripNr) + 1).
|
|
1230 |
inStream nextBytes:(stripByteCounts at:stripNr)
|
|
1231 |
into:compressedStrip.
|
|
1232 |
self class decompressCCITT3From:compressedStrip
|
|
1233 |
into:data
|
|
1234 |
startingAt:offset
|
|
1235 |
count:width.
|
|
1236 |
offset := offset + bytesPerStrip.
|
|
1237 |
row := row + rowsPerStrip
|
|
1238 |
]
|
|
1239 |
!
|
|
1240 |
|
|
1241 |
readJPEGTiffImageData
|
|
1242 |
'jpeg compression not implemented' printNewline
|
|
1243 |
!
|
|
1244 |
|
|
1245 |
readPackbitsTiffImageData
|
|
1246 |
"had no samples yet - however, packbits decompression
|
|
1247 |
is rather trivial to add ..."
|
|
1248 |
|
|
1249 |
'packbits compression not implemented' printNewline
|
|
1250 |
! !
|