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