author | Stefan Vogel <sv@exept.de> |
Fri, 05 Jul 1996 23:09:05 +0200 | |
changeset 316 | d39f3f8f7627 |
parent 259 | 62b1bbafd9ba |
child 384 | f139a7fc423b |
permissions | -rw-r--r-- |
22 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
28 | 3 |
All Rights Reserved |
22 | 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:#XPMReader |
|
203 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
259 | 17 |
category:'Graphics-Images-Support' |
22 | 18 |
! |
19 |
||
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
20 |
!XPMReader class methodsFor:'documentation'! |
22 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
28 | 25 |
All Rights Reserved |
22 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
this class provides methods for loading x-pixmap-file (xpm) images. |
|
203 | 39 |
|
24 | 40 |
These images are used (in X) for palette images (see ctwm or hp-vue for a lot |
203 | 41 |
of them). |
42 |
The code here is a hack - it may not work for all images |
|
43 |
(it works for the testfiles I got here). |
|
24 | 44 |
|
203 | 45 |
Limitations: |
46 |
only reads the full-color specification, ignoring monochrome |
|
47 |
and greyscale info. |
|
24 | 48 |
|
203 | 49 |
Can only handle single-character index. |
24 | 50 |
|
203 | 51 |
Only understands single-word color names (i.e. names with spaces |
52 |
are not supported) |
|
53 |
||
54 |
Image writing is not (yet) supported |
|
22 | 55 |
|
56 |
Suggestions: adapt & use the XPM library here. |
|
203 | 57 |
|
58 |
||
59 |
[See also:] |
|
234 | 60 |
Image Form Icon |
203 | 61 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader |
210 | 62 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
203 | 63 |
XBMReader XWDReader |
22 | 64 |
" |
65 |
! ! |
|
66 |
||
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
67 |
!XPMReader class methodsFor:'initialization'! |
28 | 68 |
|
69 |
initialize |
|
203 | 70 |
"tell Image-class, that a new fileReader is present |
71 |
for the '.xpm' extension." |
|
72 |
||
28 | 73 |
Image fileFormats at:'.xpm' put:self. |
74 |
! ! |
|
75 |
||
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
76 |
!XPMReader class methodsFor:'testing'! |
22 | 77 |
|
78 |
isValidImageFile:aFileName |
|
79 |
"return true, if aFileName contains an x-bitmap-file image" |
|
80 |
||
81 |
|line inStream | |
|
82 |
||
83 |
inStream := self streamReadingFile:aFileName. |
|
84 |
inStream isNil ifTrue:[^ false]. |
|
85 |
||
86 |
line := inStream nextLine. |
|
87 |
inStream close. |
|
88 |
line isNil ifTrue:[^ false]. |
|
89 |
(line startsWith:'/* XPM') ifFalse:[^ false]. |
|
90 |
^ true |
|
91 |
||
92 |
" |
|
93 |
XPMReader isValidImageFile:'bitmaps/magtape.xpm' |
|
94 |
XPMReader isValidImageFile:'bitmaps/ljet.xpm' |
|
95 |
XPMReader isValidImageFile:'bitmaps/garfield.gif' |
|
96 |
" |
|
97 |
! ! |
|
98 |
||
99 |
!XPMReader methodsFor:'reading from file'! |
|
100 |
||
101 |
colorNameFrom:aStream |
|
102 |
"read either a color-name or value specified in X-notation |
|
103 |
(#rrggbb where rr, gg and bb are 2-digit hex numbers)" |
|
104 |
||
105 |
|s| |
|
106 |
||
107 |
aStream peek == $# ifTrue:[ |
|
28 | 108 |
aStream next. |
109 |
s := '#'. |
|
24 | 110 |
] ifFalse:[ |
28 | 111 |
s := ''. |
22 | 112 |
]. |
28 | 113 |
[aStream peek isLetterOrDigit] whileTrue:[ |
114 |
s := s copyWith:aStream next |
|
24 | 115 |
]. |
116 |
^ s |
|
22 | 117 |
! |
118 |
||
41 | 119 |
fromStream:aStream |
120 |
"read an XPM-image from aStream. Return the receiver |
|
121 |
(with all relevant instance variables set for the image) |
|
122 |
or nil on error" |
|
22 | 123 |
|
124 |
|line |
|
125 |
srcIndex "{ Class: SmallInteger }" |
|
126 |
dstIndex "{ Class: SmallInteger }" |
|
127 |
colorName colorMapSize redMap greenMap blueMap |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
128 |
charsPerPixel xlation s bitsPerPixel char lineDone maskPixelValue| |
22 | 129 |
|
41 | 130 |
inStream := aStream. |
22 | 131 |
|
41 | 132 |
line := aStream nextLine. |
22 | 133 |
(line notNil and:[line startsWith:'/* XPM']) ifFalse:[ |
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
134 |
'XPM: format error (expected XPM)' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
135 |
^ nil |
22 | 136 |
]. |
137 |
||
41 | 138 |
line := aStream nextLine. |
107 | 139 |
[line notNil and:[(line startsWith:'/*') or:[line isBlank]]] whileTrue:[ |
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
140 |
line := aStream nextLine. |
22 | 141 |
]. |
142 |
(line notNil and:[line startsWith:'static char']) ifFalse:[ |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
143 |
'XPM: format error (expected static char)' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
144 |
^ nil |
22 | 145 |
]. |
41 | 146 |
line := aStream nextLine. |
107 | 147 |
(line notNil and:[line startsWith:'/*']) ifTrue:[ |
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
148 |
[line notNil |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
149 |
and:[(line startsWith:'/*') or:[line startsWith:' *']]] whileTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
150 |
line := aStream nextLine. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
151 |
]. |
22 | 152 |
]. |
153 |
(line notNil and:[line startsWith:'"']) ifFalse:[ |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
154 |
'XPM: format error (expected "ww hh nn mm)' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
155 |
^ nil |
22 | 156 |
]. |
157 |
s := ReadStream on:line. |
|
158 |
s next. "skip quote" |
|
159 |
width := Integer readFrom:s. |
|
160 |
height := Integer readFrom:s. |
|
161 |
colorMapSize := Integer readFrom:s. |
|
162 |
charsPerPixel := Integer readFrom:s. |
|
163 |
charsPerPixel ~~ 1 ifTrue:[ |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
164 |
'XPM: can only handle single-character xpm-files' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
165 |
^ nil |
22 | 166 |
]. |
167 |
xlation := Array new:256. |
|
168 |
||
107 | 169 |
redMap := ByteArray new:colorMapSize. |
170 |
greenMap := ByteArray new:colorMapSize. |
|
171 |
blueMap := ByteArray new:colorMapSize. |
|
36 | 172 |
colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap. |
22 | 173 |
|
174 |
1 to:colorMapSize do:[:colorIndex | |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
175 |
|index line color t| |
22 | 176 |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
177 |
line := aStream nextLine. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
178 |
[line notNil and:[line startsWith:'/*']] whileTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
179 |
line := aStream nextLine. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
180 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
181 |
(line notNil and:[line startsWith:'"']) ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
182 |
'XPM: format error (expected color spec)' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
183 |
^ nil |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
184 |
]. |
24 | 185 |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
186 |
s := ReadStream on:line. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
187 |
s next. "skip quote" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
188 |
index := s next asciiValue. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
189 |
xlation at:index put:colorIndex - 1. |
22 | 190 |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
191 |
lineDone := false. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
192 |
[lineDone] whileFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
193 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
194 |
char := s peek. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
195 |
char == $" ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
196 |
lineDone := true |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
197 |
] ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
198 |
char == $s ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
199 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
200 |
symbolic name |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
201 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
202 |
s next. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
203 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
204 |
self colorNameFrom:s. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
205 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
206 |
] ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
207 |
char == $m ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
208 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
209 |
monochrome data |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
210 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
211 |
s next. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
212 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
213 |
self colorNameFrom:s. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
214 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
215 |
] ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
216 |
(char == $g) ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
217 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
218 |
greyscale data |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
219 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
220 |
s next. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
221 |
s peek == 4 ifTrue:[s next]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
222 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
223 |
self colorNameFrom:s. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
224 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
225 |
] ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
226 |
(char == $c) ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
227 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
228 |
color data |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
229 |
" |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
230 |
s next. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
231 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
232 |
colorName := self colorNameFrom:s. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
233 |
s skipSeparators. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
234 |
] ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
235 |
'XPM: format error got: ' errorPrint. |
46 | 236 |
"/ char errorPrint. '(' errorPrint. char asciiValue printString errorPrint. |
237 |
"/ '); ' errorPrint. |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
238 |
'(expected ''c'',''m'',''g'' or ''s'')' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
239 |
^ nil |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
240 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
241 |
] |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
242 |
] |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
243 |
] |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
244 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
245 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
246 |
((colorName = 'none') or:[colorName = 'None']) ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
247 |
color := Color noColor. "/ white |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
248 |
redMap at:colorIndex put:0. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
249 |
greenMap at:colorIndex put:0. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
250 |
blueMap at:colorIndex put:0. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
251 |
maskPixelValue := colorIndex-1. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
252 |
] ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
253 |
color := Color name:colorName. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
254 |
redMap at:colorIndex put:(color red asFloat * 255.0 // 100). |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
255 |
greenMap at:colorIndex put:(color green asFloat * 255.0 // 100). |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
256 |
blueMap at:colorIndex put:(color blue asFloat * 255.0 // 100). |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
257 |
]. |
22 | 258 |
]. |
259 |
||
260 |
"actually, could make it an image with less depth most of the time ..." |
|
261 |
||
262 |
" |
|
263 |
bitsPerPixel := ((colorMapSize - 1) log:2) truncated + 1. |
|
264 |
" |
|
265 |
bitsPerPixel := 8. |
|
266 |
data := ByteArray new:(width * height). |
|
267 |
||
268 |
dstIndex := 1. |
|
269 |
1 to:height do:[:row | |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
270 |
line := aStream nextLine withoutSpaces. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
271 |
[line notNil and:[line startsWith:'/*']] whileTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
272 |
line := aStream nextLine withoutSpaces. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
273 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
274 |
(line notNil and:[line startsWith:'"']) ifFalse:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
275 |
'XPM: format error (expected pixels)' errorPrintNL. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
276 |
^ nil |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
277 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
278 |
srcIndex := 2. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
279 |
1 to: width do:[:col | |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
280 |
|char| |
22 | 281 |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
282 |
char := line at:srcIndex. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
283 |
data at:dstIndex put:(xlation at:char asciiValue). |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
284 |
srcIndex := srcIndex + 1. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
285 |
dstIndex := dstIndex + 1 |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
286 |
] |
22 | 287 |
]. |
288 |
||
289 |
photometric := #palette. |
|
290 |
samplesPerPixel := 1. |
|
291 |
bitsPerSample := Array with:bitsPerPixel. |
|
292 |
||
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
293 |
maskPixelValue notNil ifTrue:[ |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
294 |
self buildMaskFromColor:maskPixelValue |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
295 |
]. |
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
296 |
|
24 | 297 |
" |
41 | 298 |
XPMReader fromStream:('bitmaps/ljet.xpm' asFilename readStream) |
299 |
XPMReader fromStream:('bitmaps/magtape.xpm' asFilename readStream) |
|
300 |
XPMReader fromStream:('bitmaps/pixmap.xpm' asFilename readStream) |
|
301 |
XPMReader fromStream:('bitmaps/SBrowser.xbm' asFilename readStream) |
|
107 | 302 |
" |
303 |
||
304 |
"Created: 24.9.1995 / 06:20:06 / claus" |
|
305 |
"Modified: 24.9.1995 / 07:07:33 / claus" |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
306 |
"Modified: 5.7.1996 / 17:27:59 / stefan" |
22 | 307 |
! ! |
41 | 308 |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
309 |
!XPMReader class methodsFor:'documentation'! |
203 | 310 |
|
311 |
version |
|
316
d39f3f8f7627
Support color 'none' (transparency masks).
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
312 |
^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.18 1996-07-05 21:09:05 stefan Exp $' |
203 | 313 |
! ! |
41 | 314 |
XPMReader initialize! |