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