1804
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
"{ Package: 'stx:libview2' }"
|
|
14 |
|
|
15 |
ImageReader subclass:#PICTReader
|
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Graphics-Images-Readers'
|
|
20 |
!
|
|
21 |
|
|
22 |
!PICTReader class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
|
38 |
documentation
|
|
39 |
"
|
|
40 |
this class provides methods for loading Sun Raster and
|
|
41 |
Sun Icon file images.
|
|
42 |
|
|
43 |
No image writing is implemented.
|
|
44 |
|
|
45 |
[See also:]
|
|
46 |
Image Form Icon
|
|
47 |
BlitImageReader FaceReader JPEGReader GIFReader PBMReader PCXReader
|
|
48 |
ST80FormReader TargaReader TIFFReader WindowsIconReader
|
|
49 |
XBMReader XPMReader XWDReader
|
|
50 |
"
|
|
51 |
!
|
|
52 |
|
|
53 |
examples
|
|
54 |
"
|
|
55 |
example8
|
|
56 |
--- Version 1 PICTure ---
|
|
57 |
|
|
58 |
| array image |
|
|
59 |
array := #[
|
|
60 |
16r00 16r4F
|
|
61 |
16r00 16r02 16r00 16r02 16r00 16r6E 16r00 16rAA
|
|
62 |
16r11
|
|
63 |
16r01
|
|
64 |
16r01
|
|
65 |
16r00 16r0A
|
|
66 |
16r00 16r02 16r00 16r02 16r00 16r6E 16r00 16rAA
|
|
67 |
16r0A
|
|
68 |
16r77 16rDD 16r77 16rDD 16r77 16rDD 16r77 16rDD
|
|
69 |
16r34
|
|
70 |
16r00 16r02 16r00 16r02 16r00 16r6E 16r00 16rAA
|
|
71 |
16r0A
|
|
72 |
16r88 16r22 16r88 16r22 16r88 16r22 16r88 16r22
|
|
73 |
16r5C
|
|
74 |
16r71
|
|
75 |
16r00 16r1A
|
|
76 |
16r00 16r02 16r00 16r02 16r00 16r6E 16r00 16rAA
|
|
77 |
16r00 16r6E 16r00 16r02 16r00 16r02 16r00 16r54 16r00 16r6E 16r00 16rAA 16r00 16r6E 16r00 16r02
|
|
78 |
16rFF
|
|
79 |
].
|
|
80 |
image := PICTReader fromStream: (ReadStream on: array).
|
|
81 |
"
|
|
82 |
! !
|
|
83 |
|
|
84 |
!PICTReader class methodsFor:'initialization'!
|
|
85 |
|
|
86 |
initialize
|
|
87 |
"install myself in the Image classes fileFormat table
|
|
88 |
for the `.icon' and '.im8' extensions."
|
|
89 |
|
|
90 |
MIMETypes defineImageType:nil suffix:'icon' reader:self.
|
|
91 |
MIMETypes defineImageType:nil suffix:'im8' reader:self.
|
|
92 |
|
|
93 |
"Modified: 1.2.1997 / 15:08:40 / cg"
|
|
94 |
! !
|
|
95 |
|
|
96 |
!PICTReader class methodsFor:'testing'!
|
|
97 |
|
|
98 |
isValidImageFile:aFileName
|
|
99 |
"return true, if aFileName contains a sunraster image"
|
|
100 |
|
|
101 |
|inStream nr|
|
|
102 |
|
|
103 |
inStream := self streamReadingFile:aFileName.
|
|
104 |
inStream isNil ifTrue:[^ false].
|
|
105 |
|
|
106 |
"try sun raster"
|
|
107 |
inStream binary.
|
|
108 |
((inStream nextWord == 16r59A6)
|
|
109 |
and:[inStream nextWord == 16r6A95]) ifTrue: [
|
|
110 |
inStream close.
|
|
111 |
^ true
|
|
112 |
].
|
|
113 |
|
|
114 |
inStream isPositionable ifFalse:[^ false].
|
|
115 |
|
|
116 |
"try sun bitmap image format"
|
|
117 |
inStream text.
|
|
118 |
inStream reset.
|
|
119 |
|
|
120 |
"must start with a comment"
|
|
121 |
inStream skipSeparators.
|
|
122 |
inStream next ~~ $/ ifTrue:[^ false].
|
|
123 |
inStream next ~~ $* ifTrue:[^ false].
|
|
124 |
|
|
125 |
(inStream skipThroughAll: 'idth') isNil ifTrue: [
|
|
126 |
inStream close.
|
|
127 |
^ false
|
|
128 |
].
|
|
129 |
inStream next; skipSeparators.
|
|
130 |
nr := Integer readFrom: inStream.
|
|
131 |
(nr isNil or:[nr <= 0]) ifTrue: [
|
|
132 |
inStream close.
|
|
133 |
^ false
|
|
134 |
].
|
|
135 |
|
|
136 |
(inStream skipThroughAll: 'eight') isNil ifTrue: [
|
|
137 |
inStream close.
|
|
138 |
^ false
|
|
139 |
].
|
|
140 |
inStream next; skipSeparators.
|
|
141 |
nr := Integer readFrom: inStream.
|
|
142 |
(nr isNil or:[nr <= 0]) ifTrue: [
|
|
143 |
inStream close.
|
|
144 |
^ false
|
|
145 |
].
|
|
146 |
|
|
147 |
inStream close.
|
|
148 |
^ true
|
|
149 |
! !
|
|
150 |
|
|
151 |
!PICTReader methodsFor:'reading from file'!
|
|
152 |
|
|
153 |
fromStream: aStream
|
|
154 |
"read an image in my format from aStream.
|
|
155 |
Dtermine if its a raster or icon file."
|
|
156 |
|
|
157 |
| rasterType mapType mapBytes imageWords form depth
|
|
158 |
rMap gMap bMap mapLen
|
|
159 |
a b c index pos|
|
|
160 |
|
|
161 |
inStream := aStream.
|
|
162 |
|
|
163 |
aStream binary.
|
|
164 |
|
|
165 |
pos := aStream position.
|
|
166 |
((aStream nextWord == 16r59A6)
|
|
167 |
and:[aStream nextWord == 16r6A95]) ifFalse: [
|
|
168 |
"/ 'SUNReader: not a SunRaster file' errorPrintNL.
|
|
169 |
aStream position:pos.
|
|
170 |
^ self fromSunIconStream:aStream
|
|
171 |
].
|
|
172 |
|
|
173 |
width := aStream nextLong.
|
|
174 |
height := aStream nextLong.
|
|
175 |
|
|
176 |
depth := aStream nextLong.
|
|
177 |
aStream nextLong. "Ignore the image length since I can't rely on it anyway."
|
|
178 |
rasterType := aStream nextLong.
|
|
179 |
mapType := aStream nextLong. "Ignore the raster maptype."
|
|
180 |
mapBytes := aStream nextLong.
|
|
181 |
|
|
182 |
depth = 8 ifTrue: [
|
|
183 |
mapLen := (mapBytes // 3).
|
|
184 |
rMap := aStream nextBytes:mapLen.
|
|
185 |
gMap := aStream nextBytes:mapLen.
|
|
186 |
bMap := aStream nextBytes:mapLen.
|
|
187 |
colorMap := MappedPalette redVector:rMap greenVector:gMap blueVector:bMap.
|
|
188 |
|
|
189 |
data := ByteArray uninitializedNew:(width * height).
|
|
190 |
aStream nextBytes:(width * height) into:data.
|
|
191 |
|
|
192 |
photometric := #palette.
|
|
193 |
samplesPerPixel := 1.
|
|
194 |
bitsPerSample := #(8).
|
|
195 |
|
|
196 |
^ self
|
|
197 |
].
|
|
198 |
depth ~~ 1 ifTrue: [
|
|
199 |
^ self fileFormatError:'only depth 1 and 8 supported'.
|
|
200 |
].
|
|
201 |
|
|
202 |
form := nil.
|
|
203 |
|
|
204 |
aStream skip: mapBytes. "Skip the color map."
|
|
205 |
imageWords := (width / 16) ceiling * height.
|
|
206 |
data := ByteArray uninitializedNew:(imageWords * 2).
|
|
207 |
|
|
208 |
(rasterType between: 0 and: 2) ifFalse: [
|
|
209 |
^ self fileFormatError:'Unknown raster file rasterType'.
|
|
210 |
].
|
|
211 |
|
|
212 |
(rasterType = 2) ifFalse: [
|
|
213 |
"no compression of bytes"
|
|
214 |
aStream nextBytes:(imageWords * 2) into:data
|
|
215 |
] ifTrue: [
|
|
216 |
"run length compression of bytes"
|
|
217 |
|
|
218 |
index := 1.
|
|
219 |
a := aStream next.
|
|
220 |
[a notNil] whileTrue: [
|
|
221 |
(a = 128) ifFalse: [
|
|
222 |
data at:index put: a.
|
|
223 |
index := index + 1
|
|
224 |
] ifTrue: [
|
|
225 |
b := aStream next.
|
|
226 |
b = 0 ifTrue: [
|
|
227 |
data at:index put:128 .
|
|
228 |
index := index + 1
|
|
229 |
] ifFalse: [
|
|
230 |
c := aStream next.
|
|
231 |
1 to:(b+1) do:[:i |
|
|
232 |
data at:index put:c.
|
|
233 |
index := index + 1
|
|
234 |
]
|
|
235 |
]
|
|
236 |
].
|
|
237 |
a := aStream next
|
|
238 |
].
|
|
239 |
].
|
|
240 |
photometric := #whiteIs0.
|
|
241 |
samplesPerPixel := 1.
|
|
242 |
bitsPerSample := #(1).
|
|
243 |
|
|
244 |
"
|
|
245 |
Image fromFile:'bitmaps/founders.im8'
|
|
246 |
Image fromFile:'bitmaps/bf.im8'
|
|
247 |
SunRasterReader fromStream:'bitmaps/founders.im8' asFilename readStream
|
|
248 |
SunRasterReader fromStream:'bitmaps/bf.im8' asFilename readStream
|
|
249 |
"
|
|
250 |
|
|
251 |
"Modified: / 3.2.1998 / 18:00:35 / cg"
|
|
252 |
! !
|
|
253 |
|
|
254 |
!PICTReader class methodsFor:'documentation'!
|
|
255 |
|
|
256 |
version
|
|
257 |
^ '$Header: /cvs/stx/stx/libview2/PICTReader.st,v 1.1 2003-09-01 09:52:06 cg Exp $'
|
|
258 |
! !
|
|
259 |
|
|
260 |
PICTReader initialize!
|