0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
28
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ImageReader subclass:#TIFFReader
|
28
|
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:''
|
32
|
23 |
category:'Graphics-Images support'
|
0
|
24 |
!
|
|
25 |
|
|
26 |
!TIFFReader class methodsFor:'documentation'!
|
|
27 |
|
21
|
28 |
copyright
|
|
29 |
"
|
|
30 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
28
|
31 |
All Rights Reserved
|
21
|
32 |
|
|
33 |
This software is furnished under a license and may be used
|
|
34 |
only in accordance with the terms of that license and with the
|
|
35 |
inclusion of the above copyright notice. This software may not
|
|
36 |
be provided or otherwise made available to, or used by, any
|
|
37 |
other person. No title to or ownership of the software is
|
|
38 |
hereby transferred.
|
|
39 |
"
|
|
40 |
!
|
|
41 |
|
|
42 |
version
|
|
43 |
"
|
99
|
44 |
$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.22 1995-08-30 17:54:23 claus Exp $
|
21
|
45 |
"
|
|
46 |
!
|
|
47 |
|
0
|
48 |
documentation
|
|
49 |
"
|
21
|
50 |
This class knows how to read TIFF files and how to
|
|
51 |
write uncompressed TIFF files.
|
14
|
52 |
|
21
|
53 |
Only single image files are supported.
|
38
|
54 |
Not all formats are implemented, and of those that are, not all are tested.
|
21
|
55 |
It should work with most rgb, mono and 2-plane greyscale
|
38
|
56 |
images, since this is what I have as test material on the NeXT.
|
21
|
57 |
It supports reading of uncompressed, LZW and G3 compressed
|
|
58 |
images; JPEG and packbits are currently not implemented.
|
14
|
59 |
|
21
|
60 |
Only writing of uncompressed images is currently implemented.
|
|
61 |
More formats will come ...
|
30
|
62 |
|
|
63 |
TODO: since I dont want to spend all of my life adding more formats here and
|
|
64 |
reinventing the wheel, this code should be changed to use the tiff library.
|
|
65 |
That would give us most formats and also writing capabilities for free.
|
0
|
66 |
"
|
|
67 |
! !
|
|
68 |
|
28
|
69 |
!TIFFReader class methodsFor:'initialization'!
|
|
70 |
|
|
71 |
initialize
|
30
|
72 |
Image fileFormats at:'.tiff' put:self.
|
28
|
73 |
Image fileFormats at:'.tif' put:self.
|
|
74 |
Image fileFormats at:'.TIF' put:self.
|
|
75 |
! !
|
|
76 |
|
3
|
77 |
!TIFFReader class methodsFor:'testing'!
|
|
78 |
|
|
79 |
isValidImageFile:aFileName
|
|
80 |
"return true, if aFileName contains a GIF image"
|
|
81 |
|
|
82 |
|inStream char1 char2 version|
|
|
83 |
|
11
|
84 |
inStream := self streamReadingFile:aFileName.
|
3
|
85 |
inStream isNil ifTrue:[^ false].
|
|
86 |
|
|
87 |
char1 := inStream next.
|
|
88 |
char2 := inStream next.
|
|
89 |
|
|
90 |
((char1 ~~ char2) or:[(char1 ~~ $I) and:[char1 ~~ $M]]) ifTrue:[
|
28
|
91 |
inStream close.
|
|
92 |
^ false
|
3
|
93 |
].
|
|
94 |
|
|
95 |
inStream binary.
|
|
96 |
version := inStream nextShortMSB:(char1 == $M).
|
|
97 |
inStream close.
|
|
98 |
|
|
99 |
(version ~~ 42) ifTrue:[^ false].
|
|
100 |
^ true
|
51
|
101 |
!
|
|
102 |
|
|
103 |
canRepresent:anImage
|
|
104 |
"return true, if anImage can be represented in my file format.
|
|
105 |
Any image is supported."
|
|
106 |
|
|
107 |
^ true
|
3
|
108 |
! !
|
|
109 |
|
0
|
110 |
!TIFFReader methodsFor:'reading from file'!
|
|
111 |
|
40
|
112 |
fromStream:aStream
|
|
113 |
"read an image from aStream"
|
3
|
114 |
|
0
|
115 |
|char1 char2 version
|
|
116 |
numberOfTags "{ Class: SmallInteger }"
|
|
117 |
tagType "{ Class: SmallInteger }"
|
|
118 |
numberType "{ Class: SmallInteger }"
|
|
119 |
length "{ Class: SmallInteger }"
|
35
|
120 |
result offset ok msb|
|
0
|
121 |
|
40
|
122 |
inStream := aStream.
|
0
|
123 |
|
40
|
124 |
char1 := aStream next.
|
|
125 |
char2 := aStream next.
|
0
|
126 |
(char1 ~~ char2) ifTrue:[
|
28
|
127 |
'TIFFReader: not a tiff file' errorPrintNL.
|
|
128 |
^ nil
|
0
|
129 |
].
|
|
130 |
(char1 == $I) ifTrue:[
|
35
|
131 |
byteOrder := #lsb.
|
|
132 |
msb := false.
|
0
|
133 |
] ifFalse:[
|
28
|
134 |
(char1 == $M) ifTrue:[
|
35
|
135 |
byteOrder := #msb.
|
|
136 |
msb := true.
|
28
|
137 |
] ifFalse:[
|
|
138 |
'TIFFReader: not a tiff file' errorPrintNL.
|
|
139 |
^ nil
|
|
140 |
]
|
0
|
141 |
].
|
|
142 |
|
40
|
143 |
aStream binary.
|
3
|
144 |
|
0
|
145 |
version := self readShort.
|
|
146 |
(version ~~ 42) ifTrue:[
|
28
|
147 |
'TIFFReader: version of tiff-file not supported' errorPrintNL.
|
|
148 |
^ nil
|
0
|
149 |
].
|
|
150 |
|
|
151 |
"setup default values"
|
|
152 |
|
|
153 |
compression := 1. "none"
|
|
154 |
fillOrder := #msb.
|
|
155 |
planarConfiguration := 1.
|
|
156 |
photometric := nil.
|
|
157 |
bitsPerSample := 1.
|
|
158 |
samplesPerPixel := 1.
|
|
159 |
width := nil.
|
|
160 |
height := nil.
|
|
161 |
stripOffsets := nil.
|
|
162 |
rowsPerStrip := nil.
|
|
163 |
"resolutionUnit := 2."
|
|
164 |
predictor := 1.
|
|
165 |
|
40
|
166 |
offset := aStream nextLongMSB:msb.
|
|
167 |
aStream position:offset + 1.
|
0
|
168 |
|
|
169 |
numberOfTags := self readShort.
|
3
|
170 |
1 to:numberOfTags do:[:index |
|
28
|
171 |
tagType := self readShort.
|
|
172 |
numberType := self readShort.
|
40
|
173 |
length := aStream nextLongMSB:msb.
|
28
|
174 |
self decodeTiffTag:tagType numberType:numberType length:length
|
0
|
175 |
].
|
|
176 |
|
40
|
177 |
offset := aStream nextLongMSB:msb.
|
0
|
178 |
(offset ~~ 0) ifTrue:[
|
28
|
179 |
'TIFFReader: more tags ignored' errorPrintNL
|
0
|
180 |
].
|
|
181 |
|
3
|
182 |
"check for required tags"
|
0
|
183 |
ok := true.
|
|
184 |
width isNil ifTrue:[
|
28
|
185 |
'TIFFReader: missing width tag' errorPrintNL.
|
|
186 |
ok := false
|
0
|
187 |
].
|
|
188 |
|
|
189 |
height isNil ifTrue:[
|
28
|
190 |
'TIFFReader: missing length tag' errorPrintNL.
|
|
191 |
ok := false
|
0
|
192 |
].
|
|
193 |
|
|
194 |
photometric isNil ifTrue:[
|
28
|
195 |
'TIFFReader: missing photometric tag' errorPrintNL.
|
|
196 |
ok := false
|
0
|
197 |
].
|
|
198 |
|
|
199 |
stripOffsets isNil ifTrue:[
|
28
|
200 |
'TIFFReader: missing stripOffsets tag' errorPrintNL.
|
|
201 |
ok := false
|
0
|
202 |
].
|
|
203 |
|
|
204 |
ok ifFalse:[
|
28
|
205 |
^ nil
|
0
|
206 |
].
|
|
207 |
|
|
208 |
"given all the information, read the bits"
|
|
209 |
|
|
210 |
rowsPerStrip isNil ifTrue:[
|
28
|
211 |
rowsPerStrip := height
|
0
|
212 |
].
|
|
213 |
|
30
|
214 |
ok := false.
|
0
|
215 |
(compression == 1) ifTrue:[
|
30
|
216 |
result := self readUncompressedTiffImageData.
|
|
217 |
ok := true
|
|
218 |
].
|
|
219 |
(compression == 2) ifTrue:[
|
|
220 |
result := self readCCITT3RLETiffImageData.
|
|
221 |
ok := true
|
|
222 |
].
|
|
223 |
(compression == 3) ifTrue:[
|
|
224 |
result := self readCCITTGroup3TiffImageData.
|
|
225 |
ok := true
|
|
226 |
].
|
|
227 |
(compression == 4) ifTrue:[
|
|
228 |
result := self readCCITTGroup4TiffImageData.
|
|
229 |
ok := true
|
|
230 |
].
|
|
231 |
(compression == 5) ifTrue:[
|
|
232 |
result := self readLZWTiffImageData.
|
|
233 |
ok := true
|
0
|
234 |
].
|
30
|
235 |
(compression == 6) ifTrue:[
|
|
236 |
result := self readJPEGTiffImageData.
|
|
237 |
ok := true
|
|
238 |
].
|
|
239 |
(compression == 32766) ifTrue:[
|
|
240 |
result := self readNeXTRLE2TiffImageData.
|
|
241 |
ok := true
|
|
242 |
].
|
|
243 |
(compression == 32771) ifTrue:[
|
|
244 |
result := self readCCITTRLEWTiffImageData.
|
|
245 |
ok := true
|
|
246 |
].
|
|
247 |
(compression == 32773) ifTrue:[
|
|
248 |
result := self readPackbitsTiffImageData.
|
|
249 |
ok := true
|
|
250 |
].
|
|
251 |
(compression == 32865) ifTrue:[
|
|
252 |
result := self readNeXTJPEGTiffImageData.
|
|
253 |
ok := true
|
|
254 |
].
|
|
255 |
ok ifFalse:[
|
80
|
256 |
'TIFFReader: compression type ' errorPrint. compression errorPrint.
|
30
|
257 |
' not known' errorPrintNL
|
|
258 |
].
|
0
|
259 |
^ result
|
|
260 |
! !
|
|
261 |
|
|
262 |
!TIFFReader methodsFor:'writing to file'!
|
|
263 |
|
|
264 |
save:image onFile:aFileName
|
3
|
265 |
"save image as (uncompressed) TIFF file on aFileName"
|
0
|
266 |
|
|
267 |
|pos1 pos|
|
|
268 |
|
|
269 |
outStream := FileStream newFileNamed:aFileName.
|
|
270 |
outStream isNil ifTrue:[
|
28
|
271 |
'TIFFReader: create error' errorPrintNL.
|
|
272 |
^ nil
|
0
|
273 |
].
|
|
274 |
|
3
|
275 |
"save as msb"
|
|
276 |
|
0
|
277 |
byteOrder := #msb.
|
3
|
278 |
"
|
|
279 |
byteOrder := #lsb.
|
|
280 |
"
|
0
|
281 |
fillOrder := #msb.
|
|
282 |
width := image width.
|
|
283 |
height := image height.
|
|
284 |
photometric := image photometric.
|
|
285 |
samplesPerPixel := image samplesPerPixel.
|
|
286 |
bitsPerSample := image bitsPerSample.
|
|
287 |
colorMap := image colorMap.
|
|
288 |
planarConfiguration := 1.
|
|
289 |
compression := 1. "none"
|
|
290 |
data := image bits.
|
|
291 |
|
|
292 |
currentOffset := 0.
|
|
293 |
|
3
|
294 |
(byteOrder == #msb) ifTrue:[
|
28
|
295 |
outStream nextPut:$M.
|
|
296 |
outStream nextPut:$M.
|
3
|
297 |
] ifFalse:[
|
28
|
298 |
outStream nextPut:$I.
|
|
299 |
outStream nextPut:$I.
|
3
|
300 |
].
|
0
|
301 |
currentOffset := currentOffset + 2.
|
|
302 |
|
|
303 |
outStream binary.
|
|
304 |
|
3
|
305 |
self writeShort:42.
|
0
|
306 |
currentOffset := currentOffset + 2.
|
|
307 |
|
|
308 |
pos1 := outStream position.
|
3
|
309 |
self writeLong:0. "start of tags - filled in later"
|
0
|
310 |
currentOffset := currentOffset + 4.
|
|
311 |
|
|
312 |
"output strips"
|
|
313 |
|
14
|
314 |
self writeUncompressedBits. "this outputs bits as strips, sets stripOffsets and stripByteCounts"
|
0
|
315 |
self writeStripOffsets. "this outputs strip offsets, sets stripOffsetsPos"
|
|
316 |
self writeStripByteCounts. "this outputs strip bytecounts, sets stripByteCountPos"
|
|
317 |
self writeBitsPerSample. "this outputs bitsPerSample, sets bitsPerSamplePos"
|
|
318 |
photometric == #palette ifTrue:[
|
28
|
319 |
self writeColorMap "this outputs colorMap, sets colorMapPos"
|
0
|
320 |
].
|
|
321 |
|
3
|
322 |
pos := outStream position. "backpatch tag offset"
|
0
|
323 |
outStream position:pos1.
|
3
|
324 |
self writeLong:(pos - 1). "fill in tag offset"
|
0
|
325 |
outStream position:pos.
|
3
|
326 |
"
|
0
|
327 |
('patch tag offset at: ', (pos1 printStringRadix:16) , ' to ',
|
28
|
328 |
(pos printStringRadix:16)) printNewline.
|
3
|
329 |
"
|
0
|
330 |
"output tag data"
|
|
331 |
|
|
332 |
photometric == #palette ifTrue:[
|
28
|
333 |
self writeShort:10. "10 tags"
|
0
|
334 |
] ifFalse:[
|
28
|
335 |
self writeShort:9. "9 tags"
|
0
|
336 |
].
|
|
337 |
self writeTag:256. "image width"
|
|
338 |
self writeTag:257. "image height"
|
|
339 |
self writeTag:258. "bits per sample"
|
|
340 |
self writeTag:259. "compression"
|
|
341 |
self writeTag:262. "photometric"
|
|
342 |
self writeTag:273. "strip offsets"
|
28
|
343 |
self writeTag:278. "rowsPerStrip"
|
0
|
344 |
self writeTag:279. "strip byte counts"
|
|
345 |
self writeTag:284. "planarconfig"
|
|
346 |
photometric == #palette ifTrue:[
|
28
|
347 |
self writeTag:320 "colorMap"
|
0
|
348 |
].
|
3
|
349 |
self writeLong:0. "end of tags mark"
|
14
|
350 |
outStream close
|
0
|
351 |
! !
|
|
352 |
|
|
353 |
!TIFFReader methodsFor:'private'!
|
|
354 |
|
66
|
355 |
readLongs:nLongs
|
|
356 |
"read nLongs long numbers (32bit) and return them in an array"
|
|
357 |
|
|
358 |
|oldPos offset values msb
|
|
359 |
n "{ Class: SmallInteger }" |
|
|
360 |
|
|
361 |
n := nLongs.
|
0
|
362 |
|
35
|
363 |
msb := byteOrder ~~ #lsb.
|
82
|
364 |
values := Array basicNew:n.
|
0
|
365 |
(n == 1) ifTrue:[
|
35
|
366 |
values at:1 put:(inStream nextLongMSB:msb).
|
0
|
367 |
] ifFalse:[
|
35
|
368 |
offset := inStream nextLongMSB:msb.
|
28
|
369 |
oldPos := inStream position.
|
|
370 |
inStream position:(offset + 1).
|
|
371 |
1 to:n do:[:index |
|
35
|
372 |
values at:index put:(inStream nextLongMSB:msb)
|
28
|
373 |
].
|
|
374 |
inStream position:oldPos
|
0
|
375 |
].
|
|
376 |
^ values
|
|
377 |
!
|
|
378 |
|
66
|
379 |
readShorts:nShorts
|
|
380 |
"read nShorts short numbers (16bit) and return them in an array"
|
0
|
381 |
|
66
|
382 |
|oldPos offset values msb val2
|
|
383 |
n "{ Class: SmallInteger }" |
|
|
384 |
|
|
385 |
n := nShorts.
|
0
|
386 |
|
35
|
387 |
msb := (byteOrder ~~ #lsb).
|
82
|
388 |
values := Array basicNew:n.
|
0
|
389 |
(n <= 2) ifTrue:[
|
35
|
390 |
values at:1 put:(inStream nextUnsignedShortMSB:msb).
|
66
|
391 |
val2 := inStream nextUnsignedShortMSB:msb.
|
|
392 |
|
28
|
393 |
(n == 2) ifTrue:[
|
66
|
394 |
values at:2 put:val2
|
28
|
395 |
]
|
0
|
396 |
] ifFalse:[
|
35
|
397 |
offset := inStream nextLongMSB:msb.
|
28
|
398 |
oldPos := inStream position.
|
|
399 |
inStream position:(offset + 1).
|
|
400 |
1 to:n do:[:index |
|
35
|
401 |
values at:index put:(inStream nextUnsignedShortMSB:msb)
|
28
|
402 |
].
|
|
403 |
inStream position:oldPos
|
0
|
404 |
].
|
|
405 |
^ values
|
|
406 |
!
|
|
407 |
|
|
408 |
readChars:n
|
66
|
409 |
"read n characters and return them in a string"
|
|
410 |
|
0
|
411 |
|oldPos offset string|
|
|
412 |
|
|
413 |
string := String new:(n - 1).
|
|
414 |
(n <= 4) ifTrue:[
|
28
|
415 |
inStream nextBytes:(n - 1) into:string
|
0
|
416 |
] ifFalse:[
|
35
|
417 |
offset := inStream nextLongMSB:(byteOrder ~~ #lsb).
|
28
|
418 |
oldPos := inStream position.
|
|
419 |
inStream position:(offset + 1).
|
|
420 |
inStream nextBytes:(n - 1) into:string.
|
|
421 |
inStream position:oldPos
|
0
|
422 |
].
|
|
423 |
^ string
|
|
424 |
!
|
|
425 |
|
66
|
426 |
readFracts:nFracts
|
|
427 |
"read nFracts fractions (2 32bit words) and return them in an array"
|
|
428 |
|
|
429 |
|oldPos offset values numerator denominator msb
|
|
430 |
n "{ Class: SmallInteger }" |
|
|
431 |
|
|
432 |
n := nFracts.
|
0
|
433 |
|
35
|
434 |
msb := byteOrder ~~ #lsb.
|
82
|
435 |
values := Array basicNew:n.
|
35
|
436 |
offset := inStream nextLongMSB:msb.
|
0
|
437 |
oldPos := inStream position.
|
|
438 |
inStream position:(offset + 1).
|
66
|
439 |
1 to:n do:[:index |
|
|
440 |
numerator := inStream nextLongMSB:msb.
|
|
441 |
denominator := inStream nextLongMSB:msb.
|
|
442 |
values at:index put:(Fraction numerator:numerator denominator:denominator)
|
0
|
443 |
].
|
|
444 |
inStream position:oldPos.
|
|
445 |
^ values
|
|
446 |
!
|
|
447 |
|
|
448 |
decodeTiffTag:tagType numberType:numberType length:length
|
|
449 |
|offset value valueArray
|
40
|
450 |
val scaleFactor rV gV bV
|
|
451 |
n "{ Class: SmallInteger }"
|
35
|
452 |
i2 "{ Class: SmallInteger }"
|
|
453 |
i3 "{ Class: SmallInteger }" |
|
0
|
454 |
|
|
455 |
(numberType == 3) ifTrue:[
|
28
|
456 |
"short"
|
|
457 |
valueArray := self readShorts:length.
|
|
458 |
value := valueArray at:1
|
0
|
459 |
] ifFalse:[
|
28
|
460 |
(numberType == 4) ifTrue:[
|
|
461 |
"integer"
|
|
462 |
valueArray := self readLongs:length.
|
|
463 |
value := valueArray at:1
|
|
464 |
] ifFalse:[
|
|
465 |
(numberType == 2) ifTrue:[
|
|
466 |
"character"
|
|
467 |
value := self readChars:length
|
|
468 |
] ifFalse:[
|
|
469 |
(numberType == 5) ifTrue:[
|
|
470 |
"fraction"
|
|
471 |
valueArray := self readFracts:length.
|
|
472 |
value := valueArray at:1
|
|
473 |
] ifFalse:[
|
35
|
474 |
offset := (inStream nextLongMSB:(byteOrder ~~ #lsb))
|
28
|
475 |
]
|
|
476 |
]
|
|
477 |
]
|
0
|
478 |
].
|
|
479 |
|
|
480 |
(tagType == 254) ifTrue:[
|
28
|
481 |
"NewSubfileType"
|
|
482 |
"newSubFileType := value."
|
14
|
483 |
"
|
28
|
484 |
'newSubfiletype ' print. value printNewline.
|
14
|
485 |
"
|
28
|
486 |
^ self
|
0
|
487 |
].
|
|
488 |
(tagType == 255) ifTrue:[
|
28
|
489 |
"SubfileType"
|
|
490 |
subFileType := value.
|
14
|
491 |
"
|
28
|
492 |
'subfiletype ' print. value printNewline.
|
14
|
493 |
"
|
28
|
494 |
^ self
|
0
|
495 |
].
|
|
496 |
(tagType == 256) ifTrue:[
|
28
|
497 |
"ImageWidth"
|
|
498 |
width := value.
|
21
|
499 |
"
|
28
|
500 |
'width ' print. width printNewline.
|
14
|
501 |
"
|
28
|
502 |
^ self
|
0
|
503 |
].
|
|
504 |
(tagType == 257) ifTrue:[
|
28
|
505 |
"ImageHeight"
|
|
506 |
height := value.
|
14
|
507 |
"
|
28
|
508 |
'height ' print. height printNewline.
|
14
|
509 |
"
|
28
|
510 |
^ self
|
0
|
511 |
].
|
|
512 |
(tagType == 258) ifTrue:[
|
28
|
513 |
"bitspersample"
|
|
514 |
bitsPerSample := valueArray.
|
14
|
515 |
"
|
28
|
516 |
'bitspersample ' print. bitsPerSample printNewline.
|
14
|
517 |
"
|
28
|
518 |
^ self
|
0
|
519 |
].
|
|
520 |
(tagType == 259) ifTrue:[
|
28
|
521 |
"compression"
|
|
522 |
compression := value.
|
14
|
523 |
"
|
28
|
524 |
'compression ' print. compression printNewline.
|
14
|
525 |
"
|
28
|
526 |
^ self
|
0
|
527 |
].
|
|
528 |
(tagType == 262) ifTrue:[
|
28
|
529 |
"photometric"
|
30
|
530 |
|
28
|
531 |
(value == 0) ifTrue:[
|
|
532 |
photometric := #whiteIs0
|
|
533 |
] ifFalse:[
|
|
534 |
(value == 1) ifTrue:[
|
|
535 |
photometric := #blackIs0
|
|
536 |
] ifFalse:[
|
|
537 |
(value == 2) ifTrue:[
|
|
538 |
photometric := #rgb
|
|
539 |
] ifFalse:[
|
|
540 |
(value == 3) ifTrue:[
|
|
541 |
photometric := #palette
|
|
542 |
] ifFalse:[
|
|
543 |
(value == 4) ifTrue:[
|
|
544 |
photometric := #transparency
|
|
545 |
] ifFalse:[
|
30
|
546 |
(value == 5) ifTrue:[
|
|
547 |
photometric := #separated "/ color separations
|
|
548 |
] ifFalse:[
|
|
549 |
(value == 6) ifTrue:[
|
|
550 |
photometric := #ycbr "/ CCIR 601
|
|
551 |
] ifFalse:[
|
|
552 |
(value == 8) ifTrue:[
|
|
553 |
photometric := #cielab "/ 1976 CIE L*a*b*
|
|
554 |
] ifFalse:[
|
|
555 |
photometric := nil
|
|
556 |
]
|
|
557 |
]
|
|
558 |
]
|
28
|
559 |
]
|
|
560 |
]
|
|
561 |
]
|
|
562 |
]
|
|
563 |
].
|
14
|
564 |
"
|
28
|
565 |
'photometric ' print. photometric printNewline.
|
14
|
566 |
"
|
28
|
567 |
^ self
|
0
|
568 |
].
|
|
569 |
(tagType == 263) ifTrue:[
|
28
|
570 |
"Treshholding"
|
|
571 |
"threshholding := value."
|
14
|
572 |
"
|
28
|
573 |
'treshholding ' print. value printNewline.
|
14
|
574 |
"
|
28
|
575 |
^ self
|
0
|
576 |
].
|
|
577 |
(tagType == 264) ifTrue:[
|
28
|
578 |
"CellWidth"
|
|
579 |
"cellWidth:= value."
|
14
|
580 |
"
|
28
|
581 |
'cellWidth ' print. value printNewline.
|
14
|
582 |
"
|
28
|
583 |
^ self
|
0
|
584 |
].
|
|
585 |
(tagType == 265) ifTrue:[
|
28
|
586 |
"CellLength"
|
|
587 |
"cellLength:= value."
|
14
|
588 |
"
|
28
|
589 |
'cellLength ' print. value printNewline.
|
14
|
590 |
"
|
28
|
591 |
^ self
|
0
|
592 |
].
|
|
593 |
(tagType == 266) ifTrue:[
|
28
|
594 |
"fillOrder"
|
|
595 |
(value == 1) ifTrue:[
|
|
596 |
fillOrder := #msb
|
|
597 |
] ifFalse:[
|
|
598 |
(value == 2) ifTrue:[
|
|
599 |
fillOrder := #lsb
|
|
600 |
] ifFalse:[
|
|
601 |
fillOrder := nil
|
|
602 |
]
|
|
603 |
].
|
14
|
604 |
"
|
28
|
605 |
'fillorder ' print. fillOrder printNewline.
|
14
|
606 |
"
|
28
|
607 |
^ self
|
0
|
608 |
].
|
|
609 |
(tagType == 269) ifTrue:[
|
30
|
610 |
"documentName - info only"
|
14
|
611 |
"
|
28
|
612 |
'documentName ' print. value printNewline.
|
14
|
613 |
"
|
28
|
614 |
^ self
|
0
|
615 |
].
|
|
616 |
(tagType == 270) ifTrue:[
|
30
|
617 |
"imageDescription - info only"
|
14
|
618 |
"
|
28
|
619 |
'imageDescription ' print. value printNewline.
|
14
|
620 |
"
|
28
|
621 |
^ self
|
0
|
622 |
].
|
|
623 |
(tagType == 271) ifTrue:[
|
30
|
624 |
"make - info only"
|
14
|
625 |
"
|
28
|
626 |
'make ' print. value printNewline.
|
14
|
627 |
"
|
28
|
628 |
^ self
|
0
|
629 |
].
|
|
630 |
(tagType == 272) ifTrue:[
|
30
|
631 |
"model - info only"
|
14
|
632 |
"
|
28
|
633 |
'model ' print. value printNewline.
|
14
|
634 |
"
|
28
|
635 |
^ self
|
0
|
636 |
].
|
|
637 |
(tagType == 273) ifTrue:[
|
28
|
638 |
"stripoffsets"
|
|
639 |
stripOffsets := valueArray.
|
14
|
640 |
"
|
28
|
641 |
'stripOffsets Array(' print. stripOffsets size print. ')' printNewline.
|
14
|
642 |
"
|
28
|
643 |
^ self
|
0
|
644 |
].
|
|
645 |
(tagType == 274) ifTrue:[
|
28
|
646 |
"Orientation"
|
|
647 |
"orientation:= value."
|
14
|
648 |
"
|
28
|
649 |
'orientation ' print. value printNewline.
|
14
|
650 |
"
|
28
|
651 |
^ self
|
0
|
652 |
].
|
|
653 |
(tagType == 277) ifTrue:[
|
28
|
654 |
"samplesPerPixel"
|
|
655 |
samplesPerPixel := value.
|
14
|
656 |
"
|
28
|
657 |
'samplesperpixel ' print. samplesPerPixel printNewline.
|
14
|
658 |
"
|
28
|
659 |
^ self
|
0
|
660 |
].
|
|
661 |
(tagType == 278) ifTrue:[
|
28
|
662 |
"rowsperstrip"
|
|
663 |
rowsPerStrip := value.
|
14
|
664 |
"
|
28
|
665 |
'rowsperstrip ' print. rowsPerStrip printNewline.
|
14
|
666 |
"
|
28
|
667 |
^ self
|
0
|
668 |
].
|
|
669 |
(tagType == 279) ifTrue:[
|
28
|
670 |
"stripbytecount"
|
|
671 |
stripByteCounts := valueArray.
|
14
|
672 |
"
|
28
|
673 |
'stripByteCounts Array(' print.
|
|
674 |
stripByteCounts size print.
|
|
675 |
')' printNewline.
|
14
|
676 |
"
|
28
|
677 |
^ self
|
0
|
678 |
].
|
|
679 |
(tagType == 280) ifTrue:[
|
28
|
680 |
"MinSampleValue"
|
|
681 |
"minSampleValue:= value."
|
14
|
682 |
"
|
28
|
683 |
'minSampleValue ' print. value printNewline.
|
14
|
684 |
"
|
28
|
685 |
^ self
|
0
|
686 |
].
|
|
687 |
(tagType == 281) ifTrue:[
|
28
|
688 |
"MaxSampleValue"
|
|
689 |
"maxSampleValue:= value."
|
14
|
690 |
"
|
28
|
691 |
'maxSampleValue ' print. value printNewline.
|
14
|
692 |
"
|
28
|
693 |
^ self
|
0
|
694 |
].
|
|
695 |
(tagType == 282) ifTrue:[
|
28
|
696 |
"xResolution"
|
14
|
697 |
"
|
28
|
698 |
'xres ' print. value printNewline.
|
14
|
699 |
"
|
28
|
700 |
^ self
|
0
|
701 |
].
|
|
702 |
(tagType == 283) ifTrue:[
|
28
|
703 |
"yResolution"
|
14
|
704 |
"
|
28
|
705 |
'yres ' print. value printNewline.
|
14
|
706 |
"
|
28
|
707 |
^ self
|
0
|
708 |
].
|
|
709 |
(tagType == 284) ifTrue:[
|
28
|
710 |
"planarconfig"
|
|
711 |
(value == 1) ifTrue:[
|
|
712 |
planarConfiguration := 1
|
|
713 |
] ifFalse:[
|
|
714 |
(value == 2) ifTrue:[
|
|
715 |
planarConfiguration := 2
|
|
716 |
] ifFalse:[
|
|
717 |
planarConfiguration := nil
|
|
718 |
]
|
|
719 |
].
|
14
|
720 |
"
|
28
|
721 |
'planarconfig ' print. planarConfiguration printNewline.
|
14
|
722 |
"
|
28
|
723 |
^ self
|
0
|
724 |
].
|
|
725 |
(tagType == 285) ifTrue:[
|
28
|
726 |
"pageName"
|
14
|
727 |
"
|
28
|
728 |
'pageName ' print. value printNewline.
|
14
|
729 |
"
|
28
|
730 |
^ self
|
0
|
731 |
].
|
|
732 |
(tagType == 286) ifTrue:[
|
28
|
733 |
"xPosition"
|
14
|
734 |
"
|
28
|
735 |
'xPos ' print. value printNewline.
|
14
|
736 |
"
|
28
|
737 |
^ self
|
0
|
738 |
].
|
|
739 |
(tagType == 287) ifTrue:[
|
28
|
740 |
"yPosition"
|
14
|
741 |
"
|
28
|
742 |
'yPos ' print. value printNewline.
|
14
|
743 |
"
|
28
|
744 |
^ self
|
0
|
745 |
].
|
|
746 |
(tagType == 288) ifTrue:[
|
28
|
747 |
"freeOffsets"
|
14
|
748 |
"
|
28
|
749 |
'freeOffsets ' print. value printNewline.
|
14
|
750 |
"
|
28
|
751 |
^ self
|
0
|
752 |
].
|
|
753 |
(tagType == 289) ifTrue:[
|
28
|
754 |
"freeByteCounts"
|
14
|
755 |
"
|
28
|
756 |
'freeByteCounts ' print. value printNewline.
|
14
|
757 |
"
|
28
|
758 |
^ self
|
0
|
759 |
].
|
|
760 |
(tagType == 290) ifTrue:[
|
28
|
761 |
"grayResponceUnit"
|
14
|
762 |
"
|
28
|
763 |
'grayResponceUnit' print. value printNewline.
|
14
|
764 |
"
|
28
|
765 |
^ self
|
0
|
766 |
].
|
|
767 |
(tagType == 291) ifTrue:[
|
28
|
768 |
"grayResponceCurve"
|
14
|
769 |
"
|
28
|
770 |
'grayResponceCurve' print. value printNewline.
|
14
|
771 |
"
|
28
|
772 |
^ self
|
0
|
773 |
].
|
|
774 |
(tagType == 292) ifTrue:[
|
28
|
775 |
"group3options"
|
|
776 |
group3options := value.
|
14
|
777 |
"
|
28
|
778 |
'group3options ' print. group3options printNewline.
|
14
|
779 |
"
|
28
|
780 |
^ self
|
0
|
781 |
].
|
|
782 |
(tagType == 293) ifTrue:[
|
28
|
783 |
"group4options"
|
|
784 |
"group4options := value."
|
14
|
785 |
"
|
28
|
786 |
'group4options ' print. value printNewline.
|
14
|
787 |
"
|
28
|
788 |
^ self
|
0
|
789 |
].
|
|
790 |
(tagType == 296) ifTrue:[
|
28
|
791 |
"resolutionunit"
|
14
|
792 |
"
|
28
|
793 |
(value == 1) ifTrue:[
|
|
794 |
'res-unit pixel' printNewline
|
|
795 |
] ifFalse:[
|
|
796 |
(value == 2) ifTrue:[
|
|
797 |
'res-unit inch' printNewline
|
|
798 |
] ifFalse:[
|
|
799 |
(value == 3) ifTrue:[
|
|
800 |
'res-unit mm' printNewline
|
|
801 |
] ifFalse:[
|
|
802 |
'res-unit invalid' printNewline
|
|
803 |
]
|
|
804 |
]
|
|
805 |
].
|
14
|
806 |
"
|
28
|
807 |
"resolutionUnit := value."
|
|
808 |
^ self
|
0
|
809 |
].
|
|
810 |
(tagType == 297) ifTrue:[
|
28
|
811 |
"pageNumber"
|
|
812 |
"pageNumber := value."
|
14
|
813 |
"
|
28
|
814 |
'pageNumber ' print. value printNewline.
|
14
|
815 |
"
|
28
|
816 |
^ self
|
0
|
817 |
].
|
|
818 |
(tagType == 300) ifTrue:[
|
28
|
819 |
"colorResponceUnit"
|
14
|
820 |
"
|
28
|
821 |
'colorResponceUnit' print. value printNewline.
|
14
|
822 |
"
|
28
|
823 |
^ self
|
0
|
824 |
].
|
|
825 |
(tagType == 301) ifTrue:[
|
28
|
826 |
"colorResponceCurve"
|
14
|
827 |
"
|
28
|
828 |
'colorResponceCurve' print. value printNewline.
|
14
|
829 |
"
|
28
|
830 |
^ self
|
0
|
831 |
].
|
30
|
832 |
(tagType == 305) ifTrue:[
|
|
833 |
"software - info only"
|
|
834 |
"
|
|
835 |
'software' print. value printNewline.
|
|
836 |
"
|
|
837 |
^ self
|
|
838 |
].
|
0
|
839 |
(tagType == 306) ifTrue:[
|
30
|
840 |
"dateTime - info only"
|
14
|
841 |
"
|
28
|
842 |
'dateTime ' print. value printNewline.
|
14
|
843 |
"
|
28
|
844 |
^ self
|
0
|
845 |
].
|
|
846 |
(tagType == 315) ifTrue:[
|
30
|
847 |
"artist - info only"
|
14
|
848 |
"
|
28
|
849 |
'artist ' print. value printNewline.
|
14
|
850 |
"
|
28
|
851 |
^ self
|
0
|
852 |
].
|
30
|
853 |
(tagType == 316) ifTrue:[
|
|
854 |
"host computer - info only"
|
|
855 |
"
|
|
856 |
'host ' print. value printNewline.
|
|
857 |
"
|
|
858 |
^ self
|
|
859 |
].
|
0
|
860 |
(tagType == 317) ifTrue:[
|
28
|
861 |
"predictor"
|
|
862 |
predictor := value.
|
14
|
863 |
"
|
28
|
864 |
'predictor ' print. predictor printNewline.
|
14
|
865 |
"
|
28
|
866 |
^ self
|
0
|
867 |
].
|
30
|
868 |
(tagType == 318) ifTrue:[
|
|
869 |
"whitePoint"
|
|
870 |
"
|
|
871 |
'whitePoint ' print. value printNewline.
|
|
872 |
"
|
|
873 |
^ self
|
|
874 |
].
|
|
875 |
(tagType == 319) ifTrue:[
|
|
876 |
"primaryChromatics"
|
|
877 |
"
|
|
878 |
'primaryChromatics ' print. value printNewline.
|
|
879 |
"
|
|
880 |
^ self
|
|
881 |
].
|
0
|
882 |
(tagType == 320) ifTrue:[
|
28
|
883 |
"colorMap"
|
14
|
884 |
"
|
28
|
885 |
'colorMap (size=' print. valueArray size print. ')' printNewline.
|
14
|
886 |
"
|
35
|
887 |
"
|
|
888 |
the tiff colormap contains 16bit values;
|
|
889 |
our colormap expects 8bit values
|
|
890 |
"
|
28
|
891 |
n := valueArray size // 3.
|
|
892 |
|
35
|
893 |
rV := ByteArray uninitializedNew:n.
|
|
894 |
gV := ByteArray uninitializedNew:n.
|
|
895 |
bV := ByteArray uninitializedNew:n.
|
28
|
896 |
scaleFactor := 255.0 / 16rFFFF.
|
35
|
897 |
i2 := n+1.
|
|
898 |
i3 := 2*n+1.
|
|
899 |
1 to:n do:[:vi |
|
|
900 |
val := ((valueArray at:vi) * scaleFactor) rounded.
|
|
901 |
rV at:vi put:val.
|
|
902 |
val := ((valueArray at:i2) * scaleFactor) rounded.
|
|
903 |
gV at:vi put:val.
|
|
904 |
val := ((valueArray at:i3) * scaleFactor) rounded.
|
|
905 |
bV at:vi put:val.
|
|
906 |
i2 := i2 + 1.
|
|
907 |
i3 := i3 + 1.
|
28
|
908 |
].
|
35
|
909 |
colorMap := Colormap redVector:rV greenVector:gV blueVector:bV.
|
28
|
910 |
^ self
|
0
|
911 |
].
|
30
|
912 |
(tagType == 332) ifTrue:[
|
|
913 |
"ink set"
|
|
914 |
"
|
|
915 |
'ink set' print. value printNewline.
|
|
916 |
"
|
|
917 |
^ self
|
|
918 |
].
|
|
919 |
(tagType == 333) ifTrue:[
|
|
920 |
"ink names"
|
|
921 |
"
|
|
922 |
'ink names' print. value printNewline.
|
|
923 |
"
|
|
924 |
^ self
|
|
925 |
].
|
|
926 |
(tagType == 336) ifTrue:[
|
|
927 |
"dot range"
|
|
928 |
"
|
|
929 |
'dot range' print. value printNewline.
|
|
930 |
"
|
|
931 |
^ self
|
|
932 |
].
|
|
933 |
(tagType == 337) ifTrue:[
|
|
934 |
"target printer"
|
|
935 |
"
|
|
936 |
'target printer' print. value printNewline.
|
|
937 |
"
|
|
938 |
^ self
|
|
939 |
].
|
|
940 |
(tagType == 339) ifTrue:[
|
|
941 |
"sample format"
|
|
942 |
"
|
|
943 |
'sample format' print. value printNewline.
|
|
944 |
"
|
|
945 |
^ self
|
|
946 |
].
|
|
947 |
(tagType == 340) ifTrue:[
|
|
948 |
"min sample value"
|
|
949 |
"
|
|
950 |
'min sample value' print. value printNewline.
|
|
951 |
"
|
|
952 |
^ self
|
|
953 |
].
|
|
954 |
(tagType == 341) ifTrue:[
|
|
955 |
"max sample value"
|
|
956 |
"
|
|
957 |
'max sample value' print. value printNewline.
|
|
958 |
"
|
|
959 |
^ self
|
|
960 |
].
|
|
961 |
(tagType == 512) ifTrue:[
|
|
962 |
"jpeg proc"
|
|
963 |
"
|
|
964 |
'jpeg proc' print. value printNewline.
|
|
965 |
"
|
|
966 |
^ self
|
|
967 |
].
|
|
968 |
(tagType == 513) ifTrue:[
|
|
969 |
"jpeg proc"
|
|
970 |
"
|
|
971 |
'jpeg proc' print. value printNewline.
|
|
972 |
"
|
|
973 |
^ self
|
|
974 |
].
|
|
975 |
(tagType == 32995) ifTrue:[
|
|
976 |
"matteing"
|
|
977 |
"
|
|
978 |
'matteing' print. value printNewline.
|
|
979 |
"
|
|
980 |
^ self
|
|
981 |
].
|
|
982 |
(tagType == 32996) ifTrue:[
|
|
983 |
"datatype"
|
|
984 |
"
|
|
985 |
'datatype' print. value printNewline.
|
|
986 |
"
|
|
987 |
^ self
|
|
988 |
].
|
|
989 |
(tagType == 32997) ifTrue:[
|
|
990 |
"imagedepth"
|
|
991 |
"
|
|
992 |
'imagedepth' print. value printNewline.
|
|
993 |
"
|
|
994 |
^ self
|
|
995 |
].
|
|
996 |
(tagType == 32998) ifTrue:[
|
|
997 |
"tiledepth"
|
|
998 |
"
|
|
999 |
'tiledepth' print. value printNewline.
|
|
1000 |
"
|
|
1001 |
^ self
|
|
1002 |
].
|
0
|
1003 |
|
21
|
1004 |
"
|
25
|
1005 |
'TIFFReader: tag:' print. tagType print. ' typ:' print. numberType print.
|
0
|
1006 |
' len:' print. length print. ' offs:' print. offset print.
|
|
1007 |
' val:' print. value print. ' valArr:' print. valueArray printNewline.
|
21
|
1008 |
"
|
25
|
1009 |
'TIFFReader: unknown tag type ' errorPrint. tagType errorPrintNL
|
0
|
1010 |
!
|
|
1011 |
|
14
|
1012 |
writeUncompressedBits
|
|
1013 |
"write bits as one or multiple strips"
|
0
|
1014 |
|
66
|
1015 |
|offs bytesPerRow nBytes
|
|
1016 |
h "{ Class: SmallInteger }"|
|
0
|
1017 |
|
14
|
1018 |
nBytes := data size.
|
|
1019 |
nBytes < 16rFFFF ifTrue:[
|
28
|
1020 |
stripOffsets := Array with:(outStream position - 1).
|
|
1021 |
stripByteCounts := Array with:nBytes.
|
|
1022 |
outStream nextPutBytes:nBytes from:data.
|
|
1023 |
rowsPerStrip := height
|
0
|
1024 |
] ifFalse:[
|
82
|
1025 |
stripOffsets := Array basicNew:height.
|
28
|
1026 |
bytesPerRow := nBytes // height.
|
82
|
1027 |
stripByteCounts := Array basicNew:height withAll:bytesPerRow.
|
0
|
1028 |
|
28
|
1029 |
offs := 1.
|
66
|
1030 |
h := height.
|
|
1031 |
1 to:h do:[:row |
|
28
|
1032 |
stripOffsets at:row put:(outStream position - 1).
|
|
1033 |
outStream nextPutBytes:bytesPerRow from:data startingAt:offs.
|
|
1034 |
offs := offs + bytesPerRow
|
|
1035 |
].
|
|
1036 |
rowsPerStrip := 1
|
0
|
1037 |
].
|
14
|
1038 |
"
|
0
|
1039 |
'stripOffsets: ' print. stripOffsets printNewline.
|
|
1040 |
'stripByteCounts: ' print. stripByteCounts printNewline.
|
14
|
1041 |
"
|
0
|
1042 |
!
|
|
1043 |
|
|
1044 |
writeColorMap
|
28
|
1045 |
|n|
|
|
1046 |
|
0
|
1047 |
colorMapPos := outStream position.
|
35
|
1048 |
#(red green blue) do:[:component |
|
28
|
1049 |
n := 0.
|
35
|
1050 |
colorMap do:[:clr |
|
|
1051 |
|entry|
|
|
1052 |
|
|
1053 |
clr isNil ifTrue:[
|
|
1054 |
entry := 0
|
28
|
1055 |
] ifFalse:[
|
35
|
1056 |
entry := clr perform:component.
|
|
1057 |
"
|
|
1058 |
tiff map is 16 bit - scale from percent to 0..16rFFFF
|
|
1059 |
"
|
|
1060 |
entry := (entry * 16rFFFF / 100) rounded.
|
28
|
1061 |
].
|
35
|
1062 |
self writeShort:entry.
|
28
|
1063 |
n := n + 1
|
|
1064 |
].
|
|
1065 |
"
|
|
1066 |
fill to 256 entries
|
|
1067 |
"
|
|
1068 |
[n < 256] whileTrue:[
|
|
1069 |
self writeShort:0.
|
|
1070 |
n := n + 1.
|
|
1071 |
]
|
0
|
1072 |
]
|
|
1073 |
!
|
|
1074 |
|
|
1075 |
writeStripOffsets
|
3
|
1076 |
"
|
0
|
1077 |
'stripOffsets: ' print. stripOffsets printNewline.
|
|
1078 |
'store stripoffsets at: ' print. outStream position printNewline.
|
3
|
1079 |
"
|
0
|
1080 |
stripOffsetsPos := outStream position.
|
|
1081 |
stripOffsets do:[:o |
|
28
|
1082 |
self writeLong:o
|
0
|
1083 |
]
|
|
1084 |
!
|
|
1085 |
|
|
1086 |
writeStripByteCounts
|
3
|
1087 |
"
|
0
|
1088 |
'stripByteCounts: ' print. stripByteCounts printNewline.
|
|
1089 |
'store stripbytecounts at: ' print. outStream position printNewline.
|
3
|
1090 |
"
|
0
|
1091 |
stripByteCountsPos := outStream position.
|
|
1092 |
stripByteCounts do:[:c |
|
28
|
1093 |
self writeShort:c
|
0
|
1094 |
]
|
|
1095 |
!
|
|
1096 |
|
|
1097 |
writeBitsPerSample
|
3
|
1098 |
"
|
0
|
1099 |
'bitsPerSample: ' print. bitsPerSample printNewline.
|
|
1100 |
'store bitspersample at: ' print. outStream position printNewline.
|
3
|
1101 |
"
|
0
|
1102 |
bitsPerSamplePos := outStream position.
|
|
1103 |
bitsPerSample do:[:n |
|
28
|
1104 |
self writeShort:n
|
0
|
1105 |
]
|
|
1106 |
!
|
|
1107 |
|
|
1108 |
writeTag:tagType
|
|
1109 |
self writeTiffTag:tagType.
|
|
1110 |
!
|
|
1111 |
|
|
1112 |
writeTiffTag:tagType
|
|
1113 |
|value valueArray numberType count address|
|
|
1114 |
|
|
1115 |
count := 1.
|
|
1116 |
address := nil.
|
|
1117 |
(tagType == 253) ifTrue:[
|
28
|
1118 |
"tiff class"
|
0
|
1119 |
].
|
|
1120 |
(tagType == 254) ifTrue:[
|
|
1121 |
].
|
|
1122 |
(tagType == 255) ifTrue:[
|
28
|
1123 |
"SubfileType"
|
|
1124 |
value := subFileType.
|
|
1125 |
numberType := #long.
|
0
|
1126 |
].
|
|
1127 |
(tagType == 256) ifTrue:[
|
28
|
1128 |
"ImageWidth"
|
|
1129 |
value := width.
|
|
1130 |
numberType := #short.
|
0
|
1131 |
].
|
|
1132 |
(tagType == 257) ifTrue:[
|
28
|
1133 |
"ImageHeight"
|
|
1134 |
value := height.
|
|
1135 |
numberType := #short.
|
0
|
1136 |
].
|
|
1137 |
(tagType == 258) ifTrue:[
|
28
|
1138 |
"bitspersample"
|
|
1139 |
address := bitsPerSamplePos - 1.
|
|
1140 |
numberType := #short.
|
|
1141 |
count := bitsPerSample size.
|
|
1142 |
valueArray := bitsPerSample
|
0
|
1143 |
].
|
|
1144 |
(tagType == 259) ifTrue:[
|
28
|
1145 |
"compression"
|
|
1146 |
value := compression.
|
|
1147 |
numberType := #short.
|
0
|
1148 |
].
|
|
1149 |
(tagType == 262) ifTrue:[
|
28
|
1150 |
"photometric"
|
|
1151 |
(photometric == #whiteIs0) ifTrue:[
|
|
1152 |
value := 0
|
|
1153 |
] ifFalse:[
|
|
1154 |
(photometric == #blackIs0) ifTrue:[
|
|
1155 |
value := 1
|
|
1156 |
] ifFalse:[
|
|
1157 |
(photometric == #rgb) ifTrue:[
|
|
1158 |
value := 2
|
|
1159 |
] ifFalse:[
|
|
1160 |
(photometric == #palette) ifTrue:[
|
|
1161 |
value := 3
|
|
1162 |
] ifFalse:[
|
|
1163 |
(photometric == #transparency) ifTrue:[
|
|
1164 |
value := 4
|
|
1165 |
] ifFalse:[
|
|
1166 |
self error:'bad photometric'
|
|
1167 |
]
|
|
1168 |
]
|
|
1169 |
]
|
|
1170 |
]
|
|
1171 |
].
|
|
1172 |
numberType := #short.
|
0
|
1173 |
].
|
|
1174 |
(tagType == 263) ifTrue:[
|
|
1175 |
].
|
|
1176 |
(tagType == 264) ifTrue:[
|
|
1177 |
].
|
|
1178 |
(tagType == 265) ifTrue:[
|
|
1179 |
].
|
|
1180 |
(tagType == 266) ifTrue:[
|
28
|
1181 |
"fillOrder"
|
|
1182 |
(fillOrder == #msb) ifTrue:[
|
|
1183 |
value := 1
|
|
1184 |
] ifFalse:[
|
|
1185 |
(fillOrder == #lsb) ifTrue:[
|
|
1186 |
value := 2
|
|
1187 |
] ifFalse:[
|
|
1188 |
self error:'bad fillOrder'
|
|
1189 |
]
|
|
1190 |
].
|
|
1191 |
numberType := #short.
|
0
|
1192 |
].
|
|
1193 |
(tagType == 269) ifTrue:[
|
|
1194 |
].
|
|
1195 |
(tagType == 270) ifTrue:[
|
|
1196 |
].
|
|
1197 |
(tagType == 271) ifTrue:[
|
|
1198 |
].
|
|
1199 |
(tagType == 272) ifTrue:[
|
|
1200 |
].
|
|
1201 |
(tagType == 273) ifTrue:[
|
28
|
1202 |
"stripoffsets"
|
|
1203 |
address := stripOffsetsPos - 1.
|
|
1204 |
numberType := #long.
|
|
1205 |
count := stripOffsets size.
|
|
1206 |
valueArray := stripOffsets
|
0
|
1207 |
].
|
|
1208 |
(tagType == 274) ifTrue:[
|
|
1209 |
].
|
|
1210 |
(tagType == 277) ifTrue:[
|
28
|
1211 |
"samplesPerPixel"
|
|
1212 |
value := samplesPerPixel.
|
|
1213 |
numberType := #short.
|
0
|
1214 |
].
|
|
1215 |
(tagType == 278) ifTrue:[
|
28
|
1216 |
"rowsperstrip"
|
|
1217 |
value := rowsPerStrip.
|
|
1218 |
numberType := #short.
|
0
|
1219 |
].
|
|
1220 |
(tagType == 279) ifTrue:[
|
28
|
1221 |
"stripbytecount"
|
|
1222 |
address := stripByteCountsPos - 1.
|
|
1223 |
numberType := #short.
|
|
1224 |
count := stripByteCounts size.
|
|
1225 |
valueArray := stripByteCounts
|
0
|
1226 |
].
|
|
1227 |
(tagType == 280) ifTrue:[
|
28
|
1228 |
"min sample value"
|
0
|
1229 |
].
|
|
1230 |
(tagType == 281) ifTrue:[
|
28
|
1231 |
"max sample value"
|
0
|
1232 |
].
|
|
1233 |
(tagType == 282) ifTrue:[
|
28
|
1234 |
"x resolution"
|
0
|
1235 |
].
|
|
1236 |
(tagType == 283) ifTrue:[
|
28
|
1237 |
"y resolution"
|
0
|
1238 |
].
|
|
1239 |
(tagType == 284) ifTrue:[
|
28
|
1240 |
"planarconfig"
|
|
1241 |
value := planarConfiguration.
|
|
1242 |
numberType := #short.
|
0
|
1243 |
].
|
|
1244 |
(tagType == 285) ifTrue:[
|
28
|
1245 |
"pageName"
|
0
|
1246 |
].
|
|
1247 |
(tagType == 286) ifTrue:[
|
28
|
1248 |
"xPosition"
|
0
|
1249 |
].
|
|
1250 |
(tagType == 287) ifTrue:[
|
28
|
1251 |
"yPosition"
|
0
|
1252 |
].
|
|
1253 |
(tagType == 288) ifTrue:[
|
28
|
1254 |
"freeOffsets"
|
0
|
1255 |
].
|
|
1256 |
(tagType == 289) ifTrue:[
|
28
|
1257 |
"freeByteCounts"
|
0
|
1258 |
].
|
|
1259 |
(tagType == 290) ifTrue:[
|
28
|
1260 |
"grayResponceUnit"
|
0
|
1261 |
].
|
|
1262 |
(tagType == 291) ifTrue:[
|
28
|
1263 |
"grayResponceCurve"
|
0
|
1264 |
].
|
|
1265 |
(tagType == 292) ifTrue:[
|
28
|
1266 |
"group3options"
|
|
1267 |
value := group3options.
|
|
1268 |
numberType := #long.
|
0
|
1269 |
].
|
|
1270 |
(tagType == 293) ifTrue:[
|
28
|
1271 |
"group4options"
|
0
|
1272 |
].
|
|
1273 |
(tagType == 296) ifTrue:[
|
28
|
1274 |
"resolutionunit"
|
|
1275 |
^ self
|
0
|
1276 |
].
|
|
1277 |
(tagType == 297) ifTrue:[
|
28
|
1278 |
"pageNumber"
|
0
|
1279 |
].
|
|
1280 |
(tagType == 300) ifTrue:[
|
28
|
1281 |
"colorResponceUnit"
|
0
|
1282 |
].
|
|
1283 |
(tagType == 301) ifTrue:[
|
28
|
1284 |
"colorResponceCurve"
|
0
|
1285 |
].
|
|
1286 |
(tagType == 306) ifTrue:[
|
28
|
1287 |
"dateTime"
|
0
|
1288 |
].
|
|
1289 |
(tagType == 315) ifTrue:[
|
28
|
1290 |
"artist"
|
0
|
1291 |
].
|
|
1292 |
(tagType == 317) ifTrue:[
|
28
|
1293 |
"predictor"
|
0
|
1294 |
].
|
|
1295 |
(tagType == 320) ifTrue:[
|
28
|
1296 |
"colormap"
|
|
1297 |
address := colorMapPos - 1.
|
|
1298 |
numberType := #short.
|
|
1299 |
count := 256 "(colorMap at:1) size" * 3.
|
0
|
1300 |
].
|
|
1301 |
|
|
1302 |
(value isNil and:[address isNil]) ifTrue:[
|
28
|
1303 |
self error:'unhandled tag'.
|
|
1304 |
^ self
|
0
|
1305 |
].
|
|
1306 |
|
14
|
1307 |
"
|
0
|
1308 |
'tag:' print. tagType print. ' typ:' print. numberType print.
|
|
1309 |
' len:' print. count print.
|
|
1310 |
' val:' print. value printNewline.
|
14
|
1311 |
"
|
0
|
1312 |
|
|
1313 |
self writeShort:tagType.
|
|
1314 |
numberType == #short ifTrue:[
|
28
|
1315 |
self writeShort:3.
|
|
1316 |
self writeLong:count.
|
0
|
1317 |
] ifFalse:[
|
28
|
1318 |
numberType == #long ifTrue:[
|
|
1319 |
self writeShort:4.
|
|
1320 |
self writeLong:count.
|
|
1321 |
] ifFalse:[
|
|
1322 |
numberType == #byte ifTrue:[
|
|
1323 |
self writeShort:1.
|
|
1324 |
self writeLong:count.
|
|
1325 |
] ifFalse:[
|
|
1326 |
self error:'bad numbertype'
|
|
1327 |
]
|
|
1328 |
]
|
0
|
1329 |
].
|
|
1330 |
address notNil ifTrue:[
|
28
|
1331 |
(numberType == #long and:[count == 1]) ifTrue:[
|
|
1332 |
self writeLong:(valueArray at:1).
|
|
1333 |
^ self
|
|
1334 |
].
|
|
1335 |
(numberType == #short and:[count <= 2]) ifTrue:[
|
|
1336 |
self writeShort:(valueArray at:1).
|
|
1337 |
count == 2 ifTrue:[
|
|
1338 |
self writeShort:(valueArray at:2).
|
|
1339 |
] ifFalse:[
|
|
1340 |
self writeShort:0
|
|
1341 |
].
|
|
1342 |
^ self
|
|
1343 |
].
|
|
1344 |
(numberType == #byte and:[count <= 4]) ifTrue:[
|
|
1345 |
outStream nextPut:(valueArray at:1).
|
|
1346 |
count > 1 ifTrue:[
|
|
1347 |
outStream nextPut:(valueArray at:2).
|
|
1348 |
count > 2 ifTrue:[
|
|
1349 |
outStream nextPut:(valueArray at:3).
|
|
1350 |
count > 3 ifTrue:[
|
|
1351 |
outStream nextPut:(valueArray at:4).
|
|
1352 |
] ifFalse:[
|
|
1353 |
outStream nextPut:0
|
|
1354 |
].
|
|
1355 |
] ifFalse:[
|
|
1356 |
outStream nextPut:0
|
|
1357 |
].
|
|
1358 |
] ifFalse:[
|
|
1359 |
outStream nextPut:0
|
|
1360 |
].
|
|
1361 |
^ self
|
|
1362 |
].
|
|
1363 |
self writeLong:address.
|
|
1364 |
^ self
|
0
|
1365 |
].
|
|
1366 |
numberType == #short ifTrue:[
|
28
|
1367 |
self writeShort:value.
|
|
1368 |
self writeShort:0
|
0
|
1369 |
] ifFalse:[
|
28
|
1370 |
numberType == #long ifTrue:[
|
|
1371 |
self writeLong:value
|
|
1372 |
] ifFalse:[
|
|
1373 |
numberType == #byte ifTrue:[
|
|
1374 |
outStream nextPut:value.
|
|
1375 |
outStream nextPut:0.
|
|
1376 |
outStream nextPut:0.
|
|
1377 |
outStream nextPut:0.
|
|
1378 |
] ifFalse:[
|
|
1379 |
self error:'bad numbertype'
|
|
1380 |
]
|
|
1381 |
]
|
0
|
1382 |
].
|
|
1383 |
!
|
|
1384 |
|
|
1385 |
readUncompressedTiffImageData
|
|
1386 |
|bytesPerRow bitsPerRow nPlanes
|
|
1387 |
stripNr "{ Class: SmallInteger }"
|
|
1388 |
offset "{ Class: SmallInteger }"
|
|
1389 |
row "{ Class: SmallInteger }"
|
11
|
1390 |
nBytes "{ Class: SmallInteger }"
|
|
1391 |
bitsPerPixel overAllBytes|
|
0
|
1392 |
|
|
1393 |
nPlanes := samplesPerPixel.
|
|
1394 |
|
|
1395 |
"only support 1-sample/pixel,
|
|
1396 |
with alpha - if separate planes,
|
|
1397 |
or rgb - if non separate planes and no alpha"
|
|
1398 |
|
|
1399 |
(nPlanes == 2) ifTrue:[
|
28
|
1400 |
(planarConfiguration ~~ 2) ifTrue:[
|
|
1401 |
self error:'with alpha, only separate planes supported'.
|
|
1402 |
^ nil
|
|
1403 |
].
|
|
1404 |
'TIFFReader: ignoring alpha plane' errorPrintNL.
|
|
1405 |
nPlanes := 1.
|
|
1406 |
bitsPerPixel := bitsPerSample at:1
|
0
|
1407 |
] ifFalse:[
|
28
|
1408 |
(nPlanes == 3) ifTrue:[
|
|
1409 |
(planarConfiguration ~~ 1) ifTrue:[
|
|
1410 |
self error:'only non separate planes supported'.
|
|
1411 |
^ nil
|
|
1412 |
].
|
|
1413 |
bitsPerSample ~= #(8 8 8) ifTrue:[
|
|
1414 |
self error:'only 8/8/8 rgb images supported'.
|
|
1415 |
^ nil
|
|
1416 |
].
|
|
1417 |
bitsPerPixel := 24
|
|
1418 |
] ifFalse:[
|
|
1419 |
(nPlanes ~~ 1) ifTrue:[
|
|
1420 |
self error:'format not supported'.
|
|
1421 |
^ nil
|
|
1422 |
].
|
|
1423 |
bitsPerPixel := bitsPerSample at:1
|
|
1424 |
]
|
0
|
1425 |
].
|
|
1426 |
|
|
1427 |
bitsPerRow := width * bitsPerPixel.
|
|
1428 |
bytesPerRow := bitsPerRow // 8.
|
|
1429 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[
|
28
|
1430 |
bytesPerRow := bytesPerRow + 1
|
0
|
1431 |
].
|
|
1432 |
|
11
|
1433 |
overAllBytes := bytesPerRow * height.
|
|
1434 |
data := ByteArray uninitializedNew:overAllBytes.
|
0
|
1435 |
|
|
1436 |
offset := 1.
|
|
1437 |
stripNr := 0.
|
|
1438 |
|
|
1439 |
row := 1.
|
|
1440 |
[row <= height] whileTrue:[
|
28
|
1441 |
stripNr := stripNr + 1.
|
|
1442 |
nBytes := stripByteCounts at:stripNr.
|
|
1443 |
inStream position:((stripOffsets at:stripNr) + 1).
|
0
|
1444 |
|
28
|
1445 |
inStream nextBytes:nBytes into:data startingAt:offset.
|
|
1446 |
offset := offset + nBytes.
|
|
1447 |
row := row + rowsPerStrip
|
0
|
1448 |
]
|
|
1449 |
!
|
|
1450 |
|
|
1451 |
readLZWTiffImageData
|
|
1452 |
"read LZW compressed tiff data; this method only
|
|
1453 |
handles 3x8 rgb and 1x2 or 2x2 greyscale images.
|
|
1454 |
For 2x2 greyscale images, the alpha plane is ignored.
|
|
1455 |
(maybe other formats work also - its simply not
|
|
1456 |
tested)"
|
|
1457 |
|
|
1458 |
|bytesPerRow compressedStrip nPlanes
|
|
1459 |
bytesPerStrip "{ Class: SmallInteger }"
|
|
1460 |
nBytes "{ Class: SmallInteger }"
|
|
1461 |
prevSize "{ Class: SmallInteger }"
|
|
1462 |
stripNr "{ Class: SmallInteger }"
|
|
1463 |
offset "{ Class: SmallInteger }"
|
|
1464 |
row "{ Class: SmallInteger }" |
|
|
1465 |
|
|
1466 |
nPlanes := samplesPerPixel.
|
|
1467 |
|
|
1468 |
(nPlanes == 3) ifTrue:[
|
28
|
1469 |
((bitsPerSample at:1) ~~ 8) ifTrue:[
|
|
1470 |
self error:'only 8 bit/sample supported'.
|
|
1471 |
^ nil
|
|
1472 |
].
|
|
1473 |
((bitsPerSample at:2) ~~ 8) ifTrue:[
|
|
1474 |
self error:'only 8 bit/sample supported'.
|
|
1475 |
^ nil
|
|
1476 |
].
|
|
1477 |
((bitsPerSample at:3) ~~ 8) ifTrue:[
|
|
1478 |
self error:'only 8 bit/sample supported'.
|
|
1479 |
^ nil
|
|
1480 |
].
|
|
1481 |
bytesPerRow := width * samplesPerPixel.
|
0
|
1482 |
] ifFalse:[
|
28
|
1483 |
(nPlanes == 2) ifTrue:[
|
|
1484 |
(planarConfiguration ~~ 2) ifTrue:[
|
|
1485 |
self error:'only separate planes supported'.
|
|
1486 |
^ nil
|
|
1487 |
].
|
|
1488 |
'TIFFReader: ignoring alpha plane' errorPrintNL.
|
|
1489 |
nPlanes := 1
|
|
1490 |
].
|
|
1491 |
(nPlanes == 1) ifFalse:[
|
|
1492 |
self error:'only 3-sample rgb / monochrome supported'.
|
|
1493 |
^ nil
|
|
1494 |
].
|
|
1495 |
bytesPerRow := (width * (bitsPerSample at:1) + 7) // 8.
|
0
|
1496 |
].
|
|
1497 |
|
|
1498 |
stripByteCounts isNil ifTrue:[
|
28
|
1499 |
self error:'currently require stripByteCounts'.
|
|
1500 |
^ nil
|
0
|
1501 |
].
|
|
1502 |
|
80
|
1503 |
'TIFFReader: decompressing LZW ...' infoPrintNL.
|
25
|
1504 |
|
0
|
1505 |
data := ByteArray uninitializedNew:(bytesPerRow * height).
|
|
1506 |
|
|
1507 |
offset := 1.
|
|
1508 |
stripNr := 0.
|
|
1509 |
|
|
1510 |
row := 1.
|
|
1511 |
bytesPerStrip := bytesPerRow * rowsPerStrip.
|
|
1512 |
prevSize := 0.
|
|
1513 |
[row <= height] whileTrue:[
|
28
|
1514 |
stripNr := stripNr + 1.
|
|
1515 |
inStream position:((stripOffsets at:stripNr) + 1).
|
|
1516 |
nBytes := stripByteCounts at:stripNr.
|
|
1517 |
(nBytes > prevSize) ifTrue:[
|
|
1518 |
compressedStrip := ByteArray uninitializedNew:nBytes.
|
|
1519 |
prevSize := nBytes
|
|
1520 |
].
|
|
1521 |
inStream nextBytes:nBytes
|
|
1522 |
into:compressedStrip.
|
|
1523 |
self class decompressLZWFrom:compressedStrip
|
|
1524 |
count:nBytes
|
|
1525 |
into:data
|
|
1526 |
startingAt:offset.
|
|
1527 |
offset := offset + bytesPerStrip.
|
|
1528 |
row := row + rowsPerStrip
|
0
|
1529 |
].
|
|
1530 |
|
|
1531 |
(predictor == 2) ifTrue:[
|
28
|
1532 |
self class decodeDelta:3 in:data width:width height:height
|
0
|
1533 |
]
|
|
1534 |
!
|
|
1535 |
|
|
1536 |
readCCITTGroup3TiffImageData
|
|
1537 |
"not really tested - all I got is a single
|
|
1538 |
fax from NeXT step"
|
|
1539 |
|
|
1540 |
|bytesPerRow bitsPerRow compressedStrip nPlanes
|
|
1541 |
stripNr "{ Class: SmallInteger }"
|
|
1542 |
offset "{ Class: SmallInteger }"
|
|
1543 |
row "{ Class: SmallInteger }"
|
|
1544 |
bytesPerStrip "{ Class: SmallInteger }" |
|
|
1545 |
|
|
1546 |
nPlanes := samplesPerPixel.
|
|
1547 |
(nPlanes == 2) ifTrue:[
|
28
|
1548 |
'TIFFReader: ignoring alpha plane' errorPrintNL.
|
|
1549 |
nPlanes := 1
|
0
|
1550 |
].
|
|
1551 |
|
|
1552 |
(nPlanes ~~ 1) ifTrue:[
|
28
|
1553 |
self error:'only monochrome/greyscale supported'.
|
|
1554 |
^ nil
|
0
|
1555 |
].
|
|
1556 |
|
|
1557 |
stripByteCounts isNil ifTrue:[
|
28
|
1558 |
self error:'currently require stripByteCounts'.
|
|
1559 |
^ nil
|
0
|
1560 |
].
|
|
1561 |
(rowsPerStrip ~~ 1) isNil ifTrue:[
|
28
|
1562 |
self error:'currently require rowsPerStrip to be 1'.
|
|
1563 |
^ nil
|
0
|
1564 |
].
|
|
1565 |
|
80
|
1566 |
'TIFFReader: decompressing CCITT-3 ...' infoPrintNL.
|
0
|
1567 |
|
|
1568 |
bitsPerRow := width * (bitsPerSample at:1).
|
|
1569 |
bytesPerRow := bitsPerRow // 8.
|
|
1570 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[
|
28
|
1571 |
bytesPerRow := bytesPerRow + 1
|
0
|
1572 |
].
|
|
1573 |
|
3
|
1574 |
data := ByteArray new:(bytesPerRow * height).
|
0
|
1575 |
compressedStrip := ByteArray uninitializedNew:bytesPerRow.
|
|
1576 |
|
|
1577 |
offset := 1.
|
|
1578 |
stripNr := 0.
|
|
1579 |
|
|
1580 |
row := 1.
|
|
1581 |
bytesPerStrip := bytesPerRow * rowsPerStrip.
|
|
1582 |
[row <= height] whileTrue:[
|
28
|
1583 |
stripNr := stripNr + 1.
|
|
1584 |
inStream position:((stripOffsets at:stripNr) + 1).
|
|
1585 |
inStream nextBytes:(stripByteCounts at:stripNr) into:compressedStrip.
|
|
1586 |
self class decompressCCITT3From:compressedStrip
|
|
1587 |
into:data
|
|
1588 |
startingAt:offset
|
|
1589 |
count:width.
|
|
1590 |
offset := offset + bytesPerStrip.
|
|
1591 |
row := row + rowsPerStrip
|
0
|
1592 |
]
|
|
1593 |
!
|
|
1594 |
|
|
1595 |
readJPEGTiffImageData
|
25
|
1596 |
'TIFFReader: jpeg compression not implemented' errorPrintNL
|
0
|
1597 |
!
|
|
1598 |
|
30
|
1599 |
readNeXTJPEGTiffImageData
|
|
1600 |
'TIFFReader: jpeg compression not implemented' errorPrintNL
|
|
1601 |
!
|
|
1602 |
|
|
1603 |
readCCITT3RLETiffImageData
|
|
1604 |
'TIFFReader: ccitt mod Huffman (rle) compression not implemented' errorPrintNL.
|
|
1605 |
!
|
|
1606 |
|
|
1607 |
readCCITT3RLEWTiffImageData
|
|
1608 |
'TIFFReader: ccitt mod Huffman (rlew) compression not implemented' errorPrintNL.
|
|
1609 |
!
|
|
1610 |
|
|
1611 |
readCCITTGroup4TiffImageData
|
|
1612 |
'TIFFReader: ccitt group4 fax compression not implemented' errorPrintNL.
|
|
1613 |
!
|
|
1614 |
|
|
1615 |
readNeXTRLE2TiffImageData
|
|
1616 |
'TIFFReader: next 2bit rle compression not implemented' errorPrintNL.
|
|
1617 |
!
|
|
1618 |
|
0
|
1619 |
readPackbitsTiffImageData
|
|
1620 |
"had no samples yet - however, packbits decompression
|
|
1621 |
is rather trivial to add ..."
|
|
1622 |
|
25
|
1623 |
'TIFFReader: packbits compression not implemented' errorPrintNL
|
0
|
1624 |
! !
|