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