author | HG Automerge |
Thu, 19 Jan 2017 12:00:14 +0000 | |
branch | jv |
changeset 3854 | 4afd107bc911 |
parent 3588 | b1560f509caa |
permissions | -rw-r--r-- |
0 | 1 |
" |
2 |
COPYRIGHT (c) 1993 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 |
" |
|
3588 | 12 |
"{ Package: 'stx:libview2' }" |
0 | 13 |
|
3588 | 14 |
"{ NameSpace: Smalltalk }" |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
15 |
|
0 | 16 |
ImageReader subclass:#SunRasterReader |
208 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
20 |
category:'Graphics-Images-Readers' |
0 | 21 |
! |
22 |
||
21 | 23 |
!SunRasterReader class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
28 | 28 |
All Rights Reserved |
0 | 29 |
|
21 | 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 |
! |
|
0 | 38 |
|
21 | 39 |
documentation |
40 |
" |
|
208 | 41 |
this class provides methods for loading Sun Raster and |
42 |
Sun Icon file images. |
|
43 |
||
32 | 44 |
No image writing is implemented. |
208 | 45 |
|
46 |
[See also:] |
|
234 | 47 |
Image Form Icon |
208 | 48 |
BlitImageReader FaceReader JPEGReader GIFReader PBMReader PCXReader |
210 | 49 |
ST80FormReader TargaReader TIFFReader WindowsIconReader |
209 | 50 |
XBMReader XPMReader XWDReader |
21 | 51 |
" |
52 |
! ! |
|
0 | 53 |
|
28 | 54 |
!SunRasterReader class methodsFor:'initialization'! |
55 |
||
56 |
initialize |
|
208 | 57 |
"install myself in the Image classes fileFormat table |
399 | 58 |
for the `.icon' and '.im8' extensions." |
208 | 59 |
|
647 | 60 |
MIMETypes defineImageType:nil suffix:'icon' reader:self. |
61 |
MIMETypes defineImageType:nil suffix:'im8' reader:self. |
|
398 | 62 |
|
399 | 63 |
"Modified: 1.2.1997 / 15:08:40 / cg" |
28 | 64 |
! ! |
65 |
||
3 | 66 |
!SunRasterReader class methodsFor:'testing'! |
67 |
||
68 |
isValidImageFile:aFileName |
|
69 |
"return true, if aFileName contains a sunraster image" |
|
70 |
||
21 | 71 |
|inStream nr| |
3 | 72 |
|
11 | 73 |
inStream := self streamReadingFile:aFileName. |
3 | 74 |
inStream isNil ifTrue:[^ false]. |
75 |
||
76 |
"try sun raster" |
|
77 |
inStream binary. |
|
3588 | 78 |
(((inStream nextUnsignedInt16MSB:true) == 16r59A6) |
79 |
and:[(inStream nextUnsignedInt16MSB:true) == 16r6A95]) ifTrue: [ |
|
80 |
inStream close. |
|
81 |
^ true |
|
3 | 82 |
]. |
83 |
||
83 | 84 |
inStream isPositionable ifFalse:[^ false]. |
85 |
||
3 | 86 |
"try sun bitmap image format" |
87 |
inStream text. |
|
16 | 88 |
inStream reset. |
35 | 89 |
|
90 |
"must start with a comment" |
|
91 |
inStream skipSeparators. |
|
92 |
inStream next ~~ $/ ifTrue:[^ false]. |
|
93 |
inStream next ~~ $* ifTrue:[^ false]. |
|
94 |
||
21 | 95 |
(inStream skipThroughAll: 'idth') isNil ifTrue: [ |
3588 | 96 |
inStream close. |
97 |
^ false |
|
3 | 98 |
]. |
21 | 99 |
inStream next; skipSeparators. |
100 |
nr := Integer readFrom: inStream. |
|
101 |
(nr isNil or:[nr <= 0]) ifTrue: [ |
|
3588 | 102 |
inStream close. |
103 |
^ false |
|
3 | 104 |
]. |
105 |
||
21 | 106 |
(inStream skipThroughAll: 'eight') isNil ifTrue: [ |
3588 | 107 |
inStream close. |
108 |
^ false |
|
3 | 109 |
]. |
21 | 110 |
inStream next; skipSeparators. |
111 |
nr := Integer readFrom: inStream. |
|
112 |
(nr isNil or:[nr <= 0]) ifTrue: [ |
|
3588 | 113 |
inStream close. |
114 |
^ false |
|
3 | 115 |
]. |
116 |
||
117 |
inStream close. |
|
118 |
^ true |
|
119 |
! ! |
|
120 |
||
1805 | 121 |
!SunRasterReader methodsFor:'reading'! |
0 | 122 |
|
43 | 123 |
fromStream: aStream |
208 | 124 |
"read an image in my format from aStream. |
125 |
Dtermine if its a raster or icon file." |
|
126 |
||
0 | 127 |
| rasterType mapType mapBytes imageWords form depth |
128 |
rMap gMap bMap mapLen |
|
918 | 129 |
a b c index pos| |
0 | 130 |
|
43 | 131 |
inStream := aStream. |
132 |
||
133 |
aStream binary. |
|
0 | 134 |
|
43 | 135 |
pos := aStream position. |
136 |
((aStream nextWord == 16r59A6) |
|
137 |
and:[aStream nextWord == 16r6A95]) ifFalse: [ |
|
44 | 138 |
"/ 'SUNReader: not a SunRaster file' errorPrintNL. |
208 | 139 |
aStream position:pos. |
140 |
^ self fromSunIconStream:aStream |
|
0 | 141 |
]. |
142 |
||
43 | 143 |
width := aStream nextLong. |
144 |
height := aStream nextLong. |
|
1846 | 145 |
self reportDimension. |
0 | 146 |
|
43 | 147 |
depth := aStream nextLong. |
148 |
aStream nextLong. "Ignore the image length since I can't rely on it anyway." |
|
149 |
rasterType := aStream nextLong. |
|
150 |
mapType := aStream nextLong. "Ignore the raster maptype." |
|
151 |
mapBytes := aStream nextLong. |
|
0 | 152 |
|
153 |
depth = 8 ifTrue: [ |
|
208 | 154 |
mapLen := (mapBytes // 3). |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
155 |
rMap := aStream nextBytes:mapLen. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
156 |
gMap := aStream nextBytes:mapLen. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
157 |
bMap := aStream nextBytes:mapLen. |
1759
f52382e5a9b8
slowly getting rid of the Colormap class
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
158 |
colorMap := MappedPalette redVector:rMap greenVector:gMap blueVector:bMap. |
0 | 159 |
|
208 | 160 |
data := ByteArray uninitializedNew:(width * height). |
161 |
aStream nextBytes:(width * height) into:data. |
|
0 | 162 |
|
208 | 163 |
photometric := #palette. |
164 |
samplesPerPixel := 1. |
|
165 |
bitsPerSample := #(8). |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
166 |
|
208 | 167 |
^ self |
0 | 168 |
]. |
169 |
depth ~~ 1 ifTrue: [ |
|
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
170 |
^ self fileFormatError:'only depth 1 and 8 supported'. |
0 | 171 |
]. |
172 |
||
173 |
form := nil. |
|
174 |
||
43 | 175 |
aStream skip: mapBytes. "Skip the color map." |
176 |
imageWords := (width / 16) ceiling * height. |
|
3 | 177 |
data := ByteArray uninitializedNew:(imageWords * 2). |
0 | 178 |
|
179 |
(rasterType between: 0 and: 2) ifFalse: [ |
|
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
180 |
^ self fileFormatError:'Unknown raster file rasterType'. |
0 | 181 |
]. |
182 |
||
183 |
(rasterType = 2) ifFalse: [ |
|
208 | 184 |
"no compression of bytes" |
185 |
aStream nextBytes:(imageWords * 2) into:data |
|
0 | 186 |
] ifTrue: [ |
208 | 187 |
"run length compression of bytes" |
0 | 188 |
|
208 | 189 |
index := 1. |
190 |
a := aStream next. |
|
191 |
[a notNil] whileTrue: [ |
|
192 |
(a = 128) ifFalse: [ |
|
193 |
data at:index put: a. |
|
194 |
index := index + 1 |
|
195 |
] ifTrue: [ |
|
196 |
b := aStream next. |
|
197 |
b = 0 ifTrue: [ |
|
198 |
data at:index put:128 . |
|
199 |
index := index + 1 |
|
200 |
] ifFalse: [ |
|
201 |
c := aStream next. |
|
202 |
1 to:(b+1) do:[:i | |
|
203 |
data at:index put:c. |
|
204 |
index := index + 1 |
|
205 |
] |
|
206 |
] |
|
207 |
]. |
|
208 |
a := aStream next |
|
209 |
]. |
|
0 | 210 |
]. |
211 |
photometric := #whiteIs0. |
|
212 |
samplesPerPixel := 1. |
|
213 |
bitsPerSample := #(1). |
|
214 |
||
43 | 215 |
" |
216 |
Image fromFile:'bitmaps/founders.im8' |
|
217 |
Image fromFile:'bitmaps/bf.im8' |
|
218 |
SunRasterReader fromStream:'bitmaps/founders.im8' asFilename readStream |
|
219 |
SunRasterReader fromStream:'bitmaps/bf.im8' asFilename readStream |
|
220 |
" |
|
208 | 221 |
|
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
222 |
"Modified: / 3.2.1998 / 18:00:35 / cg" |
3 | 223 |
! |
224 |
||
208 | 225 |
fromSunIconStream:aStream |
226 |
"helper: read an image in icon format from aStream" |
|
227 |
||
21 | 228 |
|index word |
229 |
w "{ Class: SmallInteger }" |
|
230 |
h "{ Class: SmallInteger }"| |
|
3 | 231 |
|
43 | 232 |
inStream := aStream. |
44 | 233 |
aStream text. |
3 | 234 |
|
43 | 235 |
(aStream skipThroughAll:'idth') isNil ifTrue: [ |
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
236 |
^ self fileFormatError:'Not a Sun Raster/Icon File'. |
3 | 237 |
]. |
43 | 238 |
aStream next; skipSeparators. "skip $=" |
239 |
width := Integer readFrom: aStream. |
|
21 | 240 |
(width isNil or:[width <= 0]) ifTrue: [ |
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
241 |
^ self fileFormatError:'format error (expected number)'. |
21 | 242 |
]. |
243 |
w := width. |
|
3 | 244 |
|
43 | 245 |
(aStream skipThroughAll:'eight') isNil ifTrue: [ |
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
246 |
^ self fileFormatError:'format error (expected height)'. |
208 | 247 |
^ nil |
21 | 248 |
]. |
43 | 249 |
aStream next; skipSeparators. "skip $=" |
250 |
height := Integer readFrom: aStream. |
|
21 | 251 |
(height isNil or:[height <= 0]) ifTrue: [ |
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
252 |
^ self fileFormatError:'format error (expected number)'. |
21 | 253 |
]. |
254 |
h := height. |
|
3 | 255 |
|
256 |
data := ByteArray uninitializedNew:((width + 7 // 8) * height). |
|
257 |
photometric := #whiteIs0. |
|
258 |
samplesPerPixel := 1. |
|
259 |
bitsPerSample := #(1). |
|
260 |
||
261 |
index := 0. |
|
21 | 262 |
1 to:h do: [:row | |
208 | 263 |
1 to: (w + 15 // 16) do: [:col | |
264 |
"rows are rounded up to next multiple of 16 bits" |
|
265 |
(aStream skipThroughAll:'0x') isNil ifTrue: [^ nil]. |
|
266 |
word := Integer readFrom:aStream radix:16. |
|
267 |
word isNil ifTrue:[ |
|
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
268 |
^ self fileFormatError:'format error'. |
208 | 269 |
]. |
270 |
data at: (index := index + 1) put: (word bitShift:-8). |
|
271 |
data at: (index := index + 1) put: (word bitAnd:16rFF). |
|
272 |
] |
|
3 | 273 |
]. |
208 | 274 |
|
813
4d473c1a3c05
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
275 |
"Modified: / 3.2.1998 / 18:01:15 / cg" |
0 | 276 |
! ! |
43 | 277 |
|
208 | 278 |
!SunRasterReader class methodsFor:'documentation'! |
279 |
||
280 |
version |
|
3588 | 281 |
^ '$Header$' |
208 | 282 |
! ! |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
918
diff
changeset
|
283 |
|
3588 | 284 |
|
43 | 285 |
SunRasterReader initialize! |