62 ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
62 ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
63 XBMReader XWDReader |
63 XBMReader XWDReader |
64 " |
64 " |
65 ! ! |
65 ! ! |
66 |
66 |
67 !XPMReader class methodsFor:'initialization'! |
67 !XPMReader class methodsFor:'initialization'! |
68 |
68 |
69 initialize |
69 initialize |
70 "tell Image-class, that a new fileReader is present |
70 "tell Image-class, that a new fileReader is present |
71 for the '.xpm' extension." |
71 for the '.xpm' extension." |
72 |
72 |
73 Image fileFormats at:'.xpm' put:self. |
73 Image fileFormats at:'.xpm' put:self. |
74 ! ! |
74 ! ! |
75 |
75 |
76 !XPMReader class methodsFor:'testing'! |
76 !XPMReader class methodsFor:'testing'! |
77 |
77 |
78 isValidImageFile:aFileName |
78 isValidImageFile:aFileName |
79 "return true, if aFileName contains an x-bitmap-file image" |
79 "return true, if aFileName contains an x-bitmap-file image" |
80 |
80 |
81 |line inStream | |
81 |line inStream | |
122 or nil on error" |
122 or nil on error" |
123 |
123 |
124 |line |
124 |line |
125 srcIndex "{ Class: SmallInteger }" |
125 srcIndex "{ Class: SmallInteger }" |
126 dstIndex "{ Class: SmallInteger }" |
126 dstIndex "{ Class: SmallInteger }" |
127 colorName colorMapSize redMap greenMap blueMap |
127 colorName monoName greyName symbolicName colorMapSize redMap greenMap blueMap |
128 charsPerPixel xlation s bitsPerPixel char lineDone maskPixelValue| |
128 charsPerPixel xlation s bitsPerPixel char lineDone maskPixelValue |
|
129 state| |
129 |
130 |
130 inStream := aStream. |
131 inStream := aStream. |
131 |
132 |
132 line := aStream nextLine. |
133 line := aStream nextLine. |
133 (line notNil and:[line startsWith:'/* XPM']) ifFalse:[ |
134 (line notNil and:[line startsWith:'/* XPM']) ifFalse:[ |
170 greenMap := ByteArray new:colorMapSize. |
171 greenMap := ByteArray new:colorMapSize. |
171 blueMap := ByteArray new:colorMapSize. |
172 blueMap := ByteArray new:colorMapSize. |
172 colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap. |
173 colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap. |
173 |
174 |
174 1 to:colorMapSize do:[:colorIndex | |
175 1 to:colorMapSize do:[:colorIndex | |
175 |index line color t| |
176 |index line color t word| |
176 |
177 |
177 line := aStream nextLine. |
178 line := aStream nextLine. |
178 [line notNil and:[line startsWith:'/*']] whileTrue:[ |
179 [line notNil and:[line startsWith:'/*']] whileTrue:[ |
179 line := aStream nextLine. |
180 line := aStream nextLine. |
180 ]. |
181 ]. |
187 s next. "skip quote" |
188 s next. "skip quote" |
188 index := s next asciiValue. |
189 index := s next asciiValue. |
189 xlation at:index put:colorIndex - 1. |
190 xlation at:index put:colorIndex - 1. |
190 |
191 |
191 lineDone := false. |
192 lineDone := false. |
|
193 state := nil. |
|
194 |
192 [lineDone] whileFalse:[ |
195 [lineDone] whileFalse:[ |
193 s skipSeparators. |
196 s skipSeparators. |
194 char := s peek. |
197 s peek == $# ifTrue:[ |
195 char == $" ifTrue:[ |
198 word := self colorNameFrom:s |
|
199 ] ifFalse:[ |
|
200 word := s nextAlphaNumericWord. |
|
201 ]. |
|
202 word isNil ifTrue:[ |
196 lineDone := true |
203 lineDone := true |
197 ] ifFalse:[ |
204 ] ifFalse:[ |
198 char == $s ifTrue:[ |
205 word = 's' ifTrue:[ |
199 " |
206 "/ symbolic name ... |
200 symbolic name |
207 state := $s. symbolicName := ''. |
201 " |
|
202 s next. |
|
203 s skipSeparators. |
|
204 self colorNameFrom:s. |
|
205 s skipSeparators. |
|
206 ] ifFalse:[ |
208 ] ifFalse:[ |
207 char == $m ifTrue:[ |
209 word = 'm' ifTrue:[ |
208 " |
210 "/ monochrome data |
209 monochrome data |
211 state := $m. monoName := ''. |
210 " |
|
211 s next. |
|
212 s skipSeparators. |
|
213 self colorNameFrom:s. |
|
214 s skipSeparators. |
|
215 ] ifFalse:[ |
212 ] ifFalse:[ |
216 (char == $g) ifTrue:[ |
213 word = 'g' ifTrue:[ |
217 " |
214 "/ grey data |
218 greyscale data |
215 state := $g. greyName := ''. |
219 " |
|
220 s next. |
|
221 s peek == 4 ifTrue:[s next]. |
|
222 s skipSeparators. |
|
223 self colorNameFrom:s. |
|
224 s skipSeparators. |
|
225 ] ifFalse:[ |
216 ] ifFalse:[ |
226 (char == $c) ifTrue:[ |
217 word = 'c' ifTrue:[ |
227 " |
218 "/ color data |
228 color data |
219 state := $c. colorName := ''. |
229 " |
|
230 s next. |
|
231 s skipSeparators. |
|
232 colorName := self colorNameFrom:s. |
|
233 s skipSeparators. |
|
234 ] ifFalse:[ |
220 ] ifFalse:[ |
235 'XPM: format error got: ' errorPrint. |
221 "/ append to name |
236 "/ char errorPrint. '(' errorPrint. char asciiValue printString errorPrint. |
222 state isNil ifTrue:[ |
237 "/ '); ' errorPrint. |
223 'XPM: format error got: ' errorPrint. |
238 '(expected ''c'',''m'',''g'' or ''s'')' errorPrintNL. |
224 word errorPrint. |
239 ^ nil |
225 ' (expected ''c'',''m'',''g'' or ''s'')' errorPrintNL. |
240 ]. |
226 ^ nil |
|
227 ]. |
|
228 |
|
229 state == $m ifTrue:[ |
|
230 monoName := monoName , ' ' , word. |
|
231 ]. |
|
232 state == $g ifTrue:[ |
|
233 greyName := greyName , ' ' , word. |
|
234 ]. |
|
235 state == $c ifTrue:[ |
|
236 colorName := colorName , ' ' , word. |
|
237 ]. |
|
238 state == $s ifTrue:[ |
|
239 symbolicName := symbolicName , ' ' , word. |
|
240 ]. |
|
241 (word startsWith:'#') ifTrue:[ |
|
242 state := nil. |
|
243 ] |
|
244 ] |
241 ] |
245 ] |
242 ] |
246 ] |
243 ] |
247 ] |
244 ]. |
248 ]. |
245 ]. |
249 ]. |
|
250 |
|
251 colorName notNil ifTrue:[ |
|
252 colorName := colorName withoutSeparators |
|
253 ]. |
|
254 monoName notNil ifTrue:[ |
|
255 monoName := monoName withoutSeparators |
|
256 ]. |
|
257 greyName notNil ifTrue:[ |
|
258 greyName := greyName withoutSeparators |
|
259 ]. |
|
260 symbolicName notNil ifTrue:[ |
|
261 symbolicName := symbolicName withoutSeparators |
|
262 ]. |
|
263 |
|
264 "/ |
|
265 "/ for now - ignore everything, except |
|
266 "/ colorName (if there is one) |
|
267 "/ |
|
268 colorName isNil ifTrue:[ |
|
269 colorName := greyName. |
|
270 colorName isNil ifTrue:[ |
|
271 colorName := monoName. |
|
272 ] |
|
273 ]. |
|
274 |
246 ((colorName = 'none') or:[colorName = 'None']) ifTrue:[ |
275 ((colorName = 'none') or:[colorName = 'None']) ifTrue:[ |
247 color := Color noColor. "/ white |
276 color := Color noColor. "/ white |
248 redMap at:colorIndex put:0. |
277 redMap at:colorIndex put:0. |
249 greenMap at:colorIndex put:0. |
278 greenMap at:colorIndex put:0. |
250 blueMap at:colorIndex put:0. |
279 blueMap at:colorIndex put:0. |
302 " |
331 " |
303 |
332 |
304 "Created: 24.9.1995 / 06:20:06 / claus" |
333 "Created: 24.9.1995 / 06:20:06 / claus" |
305 "Modified: 24.9.1995 / 07:07:33 / claus" |
334 "Modified: 24.9.1995 / 07:07:33 / claus" |
306 "Modified: 5.7.1996 / 17:27:59 / stefan" |
335 "Modified: 5.7.1996 / 17:27:59 / stefan" |
307 ! ! |
336 "Modified: 24.1.1997 / 14:45:02 / cg" |
308 |
337 ! ! |
309 !XPMReader class methodsFor:'documentation'! |
338 |
|
339 !XPMReader class methodsFor:'documentation'! |
310 |
340 |
311 version |
341 version |
312 ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.18 1996-07-05 21:09:05 stefan Exp $' |
342 ^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.19 1997-01-24 14:46:06 cg Exp $' |
313 ! ! |
343 ! ! |
314 XPMReader initialize! |
344 XPMReader initialize! |