equal
deleted
inserted
replaced
25 |
25 |
26 TIFFReader comment:' |
26 TIFFReader comment:' |
27 COPYRIGHT (c) 1991 by Claus Gittinger |
27 COPYRIGHT (c) 1991 by Claus Gittinger |
28 All Rights Reserved |
28 All Rights Reserved |
29 |
29 |
30 $Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.15 1995-02-15 10:36:16 claus Exp $ |
30 $Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.16 1995-02-18 15:32:43 claus Exp $ |
31 '! |
31 '! |
32 |
32 |
33 !TIFFReader class methodsFor:'documentation'! |
33 !TIFFReader class methodsFor:'documentation'! |
34 |
34 |
35 copyright |
35 copyright |
46 " |
46 " |
47 ! |
47 ! |
48 |
48 |
49 version |
49 version |
50 " |
50 " |
51 $Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.15 1995-02-15 10:36:16 claus Exp $ |
51 $Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.16 1995-02-18 15:32:43 claus Exp $ |
52 " |
52 " |
53 ! |
53 ! |
54 |
54 |
55 documentation |
55 documentation |
56 " |
56 " |
107 ^ true |
107 ^ true |
108 ! ! |
108 ! ! |
109 |
109 |
110 !TIFFReader methodsFor:'reading from file'! |
110 !TIFFReader methodsFor:'reading from file'! |
111 |
111 |
112 fromFile:aFileName |
112 fromStream:aStream |
113 "read an image from aFileName" |
113 "read an image from aStream" |
114 |
114 |
115 |char1 char2 version |
115 |char1 char2 version |
116 numberOfTags "{ Class: SmallInteger }" |
116 numberOfTags "{ Class: SmallInteger }" |
117 tagType "{ Class: SmallInteger }" |
117 tagType "{ Class: SmallInteger }" |
118 numberType "{ Class: SmallInteger }" |
118 numberType "{ Class: SmallInteger }" |
119 length "{ Class: SmallInteger }" |
119 length "{ Class: SmallInteger }" |
120 result offset ok msb| |
120 result offset ok msb| |
121 |
121 |
122 inStream := self class streamReadingFile:aFileName. |
122 inStream := aStream. |
123 inStream isNil ifTrue:[^ nil]. |
123 |
124 |
124 char1 := aStream next. |
125 char1 := inStream next. |
125 char2 := aStream next. |
126 char2 := inStream next. |
|
127 (char1 ~~ char2) ifTrue:[ |
126 (char1 ~~ char2) ifTrue:[ |
128 'TIFFReader: not a tiff file' errorPrintNL. |
127 'TIFFReader: not a tiff file' errorPrintNL. |
129 inStream close. |
|
130 ^ nil |
128 ^ nil |
131 ]. |
129 ]. |
132 (char1 == $I) ifTrue:[ |
130 (char1 == $I) ifTrue:[ |
133 byteOrder := #lsb. |
131 byteOrder := #lsb. |
134 msb := false. |
132 msb := false. |
136 (char1 == $M) ifTrue:[ |
134 (char1 == $M) ifTrue:[ |
137 byteOrder := #msb. |
135 byteOrder := #msb. |
138 msb := true. |
136 msb := true. |
139 ] ifFalse:[ |
137 ] ifFalse:[ |
140 'TIFFReader: not a tiff file' errorPrintNL. |
138 'TIFFReader: not a tiff file' errorPrintNL. |
141 inStream close. |
|
142 ^ nil |
139 ^ nil |
143 ] |
140 ] |
144 ]. |
141 ]. |
145 |
142 |
146 inStream binary. |
143 aStream binary. |
147 |
144 |
148 version := self readShort. |
145 version := self readShort. |
149 (version ~~ 42) ifTrue:[ |
146 (version ~~ 42) ifTrue:[ |
150 'TIFFReader: version of tiff-file not supported' errorPrintNL. |
147 'TIFFReader: version of tiff-file not supported' errorPrintNL. |
151 inStream close. |
|
152 ^ nil |
148 ^ nil |
153 ]. |
149 ]. |
154 |
150 |
155 "setup default values" |
151 "setup default values" |
156 |
152 |
165 stripOffsets := nil. |
161 stripOffsets := nil. |
166 rowsPerStrip := nil. |
162 rowsPerStrip := nil. |
167 "resolutionUnit := 2." |
163 "resolutionUnit := 2." |
168 predictor := 1. |
164 predictor := 1. |
169 |
165 |
170 offset := inStream nextLongMSB:msb. |
166 offset := aStream nextLongMSB:msb. |
171 inStream position:offset + 1. |
167 aStream position:offset + 1. |
172 |
168 |
173 numberOfTags := self readShort. |
169 numberOfTags := self readShort. |
174 1 to:numberOfTags do:[:index | |
170 1 to:numberOfTags do:[:index | |
175 tagType := self readShort. |
171 tagType := self readShort. |
176 numberType := self readShort. |
172 numberType := self readShort. |
177 length := inStream nextLongMSB:msb. |
173 length := aStream nextLongMSB:msb. |
178 self decodeTiffTag:tagType numberType:numberType length:length |
174 self decodeTiffTag:tagType numberType:numberType length:length |
179 ]. |
175 ]. |
180 |
176 |
181 offset := inStream nextLongMSB:msb. |
177 offset := aStream nextLongMSB:msb. |
182 (offset ~~ 0) ifTrue:[ |
178 (offset ~~ 0) ifTrue:[ |
183 'TIFFReader: more tags ignored' errorPrintNL |
179 'TIFFReader: more tags ignored' errorPrintNL |
184 ]. |
180 ]. |
185 |
181 |
186 "check for required tags" |
182 "check for required tags" |
204 'TIFFReader: missing stripOffsets tag' errorPrintNL. |
200 'TIFFReader: missing stripOffsets tag' errorPrintNL. |
205 ok := false |
201 ok := false |
206 ]. |
202 ]. |
207 |
203 |
208 ok ifFalse:[ |
204 ok ifFalse:[ |
209 inStream close. |
|
210 ^ nil |
205 ^ nil |
211 ]. |
206 ]. |
212 |
207 |
213 "given all the information, read the bits" |
208 "given all the information, read the bits" |
214 |
209 |
260 ok ifFalse:[ |
255 ok ifFalse:[ |
261 'TIFFReader: compression type ' errorPrint. |
256 'TIFFReader: compression type ' errorPrint. |
262 compression errorPrint. |
257 compression errorPrint. |
263 ' not known' errorPrintNL |
258 ' not known' errorPrintNL |
264 ]. |
259 ]. |
265 inStream close. |
|
266 ^ result |
260 ^ result |
267 ! ! |
261 ! ! |
268 |
262 |
269 !TIFFReader methodsFor:'writing to file'! |
263 !TIFFReader methodsFor:'writing to file'! |
270 |
264 |
442 ^ values |
436 ^ values |
443 ! |
437 ! |
444 |
438 |
445 decodeTiffTag:tagType numberType:numberType length:length |
439 decodeTiffTag:tagType numberType:numberType length:length |
446 |offset value valueArray |
440 |offset value valueArray |
447 val map scaleFactor rV gV bV |
441 val scaleFactor rV gV bV |
448 n "{ Class: SmallInteger }" |
442 n "{ Class: SmallInteger }" |
449 i "{ Class: SmallInteger }" |
|
450 i1 "{ Class: SmallInteger }" |
|
451 i2 "{ Class: SmallInteger }" |
443 i2 "{ Class: SmallInteger }" |
452 i3 "{ Class: SmallInteger }" | |
444 i3 "{ Class: SmallInteger }" | |
453 |
445 |
454 (numberType == 3) ifTrue:[ |
446 (numberType == 3) ifTrue:[ |
455 "short" |
447 "short" |
886 " |
878 " |
887 the tiff colormap contains 16bit values; |
879 the tiff colormap contains 16bit values; |
888 our colormap expects 8bit values |
880 our colormap expects 8bit values |
889 " |
881 " |
890 n := valueArray size // 3. |
882 n := valueArray size // 3. |
891 "/ colorMap := Array new:3. |
|
892 "/ colorMap at:1 put:(valueArray copyFrom:1 to:n). |
|
893 "/ colorMap at:2 put:(valueArray copyFrom:n+1 to:2*n). |
|
894 "/ colorMap at:3 put:(valueArray copyFrom:2*n+1 to:3*n). |
|
895 "/ scaleFactor := 255.0 / 16rFFFF. |
|
896 "/ 1 to:3 do:[:c | |
|
897 "/ map := colorMap at:c. |
|
898 "/ 1 to:n do:[:e | |
|
899 "/ val := map at:e. |
|
900 "/ val := (val * scaleFactor) rounded. |
|
901 "/ map at:e put:val |
|
902 "/ ] |
|
903 "/ ]. |
|
904 |
883 |
905 rV := ByteArray uninitializedNew:n. |
884 rV := ByteArray uninitializedNew:n. |
906 gV := ByteArray uninitializedNew:n. |
885 gV := ByteArray uninitializedNew:n. |
907 bV := ByteArray uninitializedNew:n. |
886 bV := ByteArray uninitializedNew:n. |
908 scaleFactor := 255.0 / 16rFFFF. |
887 scaleFactor := 255.0 / 16rFFFF. |