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