author | Claus Gittinger <cg@exept.de> |
Mon, 01 Sep 2003 16:47:57 +0200 | |
changeset 1805 | 93f557cbe600 |
parent 1759 | f52382e5a9b8 |
child 1812 | 5c902c4135f1 |
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 |
||
1400 | 13 |
"{ Package: 'stx:libview2' }" |
14 |
||
22 | 15 |
ImageReader subclass:#XPMReader |
1737 | 16 |
instanceVariableNames:'charsPerPixel maskPixelValue characterTranslation' |
203 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1743
diff
changeset
|
19 |
category:'Graphics-Images-Readers' |
22 | 20 |
! |
21 |
||
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
22 |
!XPMReader class methodsFor:'documentation'! |
22 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
28 | 27 |
All Rights Reserved |
22 | 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 x-pixmap-file (xpm) images. |
|
203 | 41 |
|
24 | 42 |
These images are used (in X) for palette images (see ctwm or hp-vue for a lot |
203 | 43 |
of them). |
44 |
The code here is a hack - it may not work for all images |
|
45 |
(it works for the testfiles I got here). |
|
24 | 46 |
|
203 | 47 |
Limitations: |
48 |
only reads the full-color specification, ignoring monochrome |
|
49 |
and greyscale info. |
|
24 | 50 |
|
203 | 51 |
Can only handle single-character index. |
24 | 52 |
|
203 | 53 |
Only understands single-word color names (i.e. names with spaces |
54 |
are not supported) |
|
55 |
||
459 | 56 |
Image writing is only supported for images with less than about 50 |
57 |
colors (single byte encoding). If present, the mask must be a |
|
58 |
single bit mask (i.e. no alpha channel). |
|
59 |
Due to the algorithm, writing may be slow for big images |
|
22 | 60 |
|
61 |
Suggestions: adapt & use the XPM library here. |
|
203 | 62 |
|
63 |
||
64 |
[See also:] |
|
234 | 65 |
Image Form Icon |
203 | 66 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader |
210 | 67 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
203 | 68 |
XBMReader XWDReader |
22 | 69 |
" |
70 |
! ! |
|
71 |
||
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
72 |
!XPMReader class methodsFor:'initialization'! |
28 | 73 |
|
74 |
initialize |
|
203 | 75 |
"tell Image-class, that a new fileReader is present |
400 | 76 |
for the '.xpm' and '.pm' extensions." |
203 | 77 |
|
647 | 78 |
MIMETypes defineImageType:'image/x-xpixmap' suffix:'xpm' reader:self. |
79 |
MIMETypes defineImageType:nil suffix:'pm' reader:self. |
|
398 | 80 |
|
400 | 81 |
"Modified: 1.2.1997 / 15:10:29 / cg" |
28 | 82 |
! ! |
83 |
||
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
84 |
!XPMReader class methodsFor:'testing'! |
22 | 85 |
|
460 | 86 |
canRepresent:anImage |
87 |
"return true, if anImage can be represented in my file format. |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
88 |
Currently only images with less than 80 colors are supported." |
460 | 89 |
|
90 |
anImage depth <= 6 ifTrue:[^ true]. |
|
91 |
anImage photometric == #palette ifTrue:[ |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
92 |
anImage colorMap size < 80 ifTrue:[^ true]. |
460 | 93 |
]. |
1495 | 94 |
anImage usedColors size < 80 ifTrue:[^ true]. |
1521 | 95 |
Transcript showCR:'XPMReader: too many colors in image.'. |
1495 | 96 |
^ false |
460 | 97 |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
98 |
"Modified: 27.2.1997 / 12:40:22 / cg" |
460 | 99 |
! |
100 |
||
22 | 101 |
isValidImageFile:aFileName |
102 |
"return true, if aFileName contains an x-bitmap-file image" |
|
103 |
||
104 |
|line inStream | |
|
105 |
||
106 |
inStream := self streamReadingFile:aFileName. |
|
107 |
inStream isNil ifTrue:[^ false]. |
|
108 |
||
550 | 109 |
Stream readErrorSignal handle:[:ex | |
110 |
line := nil |
|
111 |
] do:[ |
|
1510
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
112 |
Stream lineTooLongErrorSignal handle:[:ex | |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
113 |
line := nil. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
114 |
Transcript showCR:'long line'. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
115 |
ex return. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
116 |
] do:[ |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
117 |
line := inStream nextLine. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
118 |
] |
550 | 119 |
]. |
22 | 120 |
inStream close. |
121 |
line isNil ifTrue:[^ false]. |
|
122 |
(line startsWith:'/* XPM') ifFalse:[^ false]. |
|
123 |
^ true |
|
124 |
||
125 |
" |
|
562
921472d151d9
handle commented lines (in colorSpec)
Claus Gittinger <cg@exept.de>
parents:
560
diff
changeset
|
126 |
XPMReader isValidImageFile:'fooBar' |
1737 | 127 |
XPMReader isValidImageFile:'../../goodies/bitmaps/xpmBitmaps/device_images/ljet.xpm' |
562
921472d151d9
handle commented lines (in colorSpec)
Claus Gittinger <cg@exept.de>
parents:
560
diff
changeset
|
128 |
XPMReader isValidImageFile:'bitmaps/gifImages/garfield.gif' |
550 | 129 |
" |
130 |
||
562
921472d151d9
handle commented lines (in colorSpec)
Claus Gittinger <cg@exept.de>
parents:
560
diff
changeset
|
131 |
"Modified: 24.4.1997 / 20:29:40 / cg" |
22 | 132 |
! ! |
133 |
||
1805 | 134 |
!XPMReader methodsFor:'reading'! |
135 |
||
136 |
readImage |
|
137 |
"read an XPM-image from my inStream. Return the receiver |
|
138 |
(with all relevant instance variables set for the image) |
|
139 |
or nil on error" |
|
140 |
||
141 |
|line |
|
142 |
srcIndex "{ Class: SmallInteger }" |
|
143 |
dstIndex "{ Class: SmallInteger }" |
|
144 |
colorMapSize |
|
145 |
s bitsPerPixel key lastKey lastChar1 lastChar2 c1 c2 lastXLation| |
|
146 |
||
147 |
line := inStream nextLine. |
|
148 |
(line notNil and:[line startsWith:'/* XPM']) ifFalse:[ |
|
149 |
^ self fileFormatError:'format error (expected XPM)'. |
|
150 |
]. |
|
151 |
||
152 |
line := inStream nextLine. |
|
153 |
[line notNil and:[(line startsWith:'/*') or:[line isBlank or:[(line startsWith:' *')]]]] whileTrue:[ |
|
154 |
line := inStream nextLine. |
|
155 |
]. |
|
156 |
(line notNil and:[line startsWith:'static char']) ifFalse:[ |
|
157 |
^ self fileFormatError:'format error (expected static char)'. |
|
158 |
]. |
|
159 |
line := inStream nextLine. |
|
160 |
(line notNil and:[line startsWith:'/*']) ifTrue:[ |
|
161 |
[line notNil |
|
162 |
and:[(line startsWith:'/*') or:[line startsWith:' *']]] whileTrue:[ |
|
163 |
line := inStream nextLine. |
|
164 |
]. |
|
165 |
]. |
|
166 |
line notNil ifTrue:[ |
|
167 |
line := line withoutSeparators |
|
168 |
]. |
|
169 |
(line notNil and:[line startsWith:'"']) ifFalse:[ |
|
170 |
^ self fileFormatError:'format error (expected "ww hh nn mm)'. |
|
171 |
]. |
|
172 |
s := ReadStream on:line. |
|
173 |
s next. "skip quote" |
|
174 |
width := Integer readFrom:s. |
|
175 |
height := Integer readFrom:s. |
|
176 |
colorMapSize := Integer readFrom:s. |
|
177 |
charsPerPixel := Integer readFrom:s. |
|
178 |
||
179 |
charsPerPixel ~~ 1 ifTrue:[ |
|
180 |
characterTranslation := Dictionary new:colorMapSize. |
|
181 |
] ifFalse:[ |
|
182 |
characterTranslation := Array new:256. |
|
183 |
]. |
|
184 |
||
185 |
self readColorMap:colorMapSize. |
|
186 |
||
187 |
"actually, could make it an image with less depth most of the time ..." |
|
188 |
||
189 |
" |
|
190 |
bitsPerPixel := ((colorMapSize - 1) log:2) truncated + 1. |
|
191 |
" |
|
192 |
colorMapSize > 256 ifTrue:[ |
|
193 |
bitsPerPixel := 24. |
|
194 |
data := ByteArray new:(width * height * 3). |
|
195 |
] ifFalse:[ |
|
196 |
bitsPerPixel := 8. |
|
197 |
data := ByteArray new:(width * height). |
|
198 |
]. |
|
199 |
||
200 |
dstIndex := 1. |
|
201 |
1 to:height do:[:row | |
|
202 |
line := inStream nextLine withoutSpaces. |
|
203 |
[line notNil and:[line startsWith:'/*']] whileTrue:[ |
|
204 |
line := inStream nextLine withoutSpaces. |
|
205 |
]. |
|
206 |
line notNil ifTrue:[ |
|
207 |
line := line withoutSeparators |
|
208 |
]. |
|
209 |
(line notNil and:[line startsWith:'"']) ifFalse:[ |
|
210 |
^ self fileFormatError:'format error (expected pixels)'. |
|
211 |
]. |
|
212 |
charsPerPixel == 1 ifTrue:[ |
|
213 |
srcIndex := 2. "skip dquote" |
|
214 |
1 to:width do:[:col | |
|
215 |
key := line at:srcIndex. |
|
216 |
key ~~ lastKey ifTrue:[ |
|
217 |
lastXLation := characterTranslation at:key asciiValue. |
|
218 |
lastKey := key |
|
219 |
]. |
|
220 |
data at:dstIndex put:lastXLation. |
|
221 |
srcIndex := srcIndex + 1. |
|
222 |
dstIndex := dstIndex + 1 |
|
223 |
] |
|
224 |
] ifFalse:[ |
|
225 |
charsPerPixel == 2 ifTrue:[ |
|
226 |
"/ sorry, but this ugly code does a lot for speed, |
|
227 |
"/ when reading big Xpm files (factor=5 for banner8.xpm) ... |
|
228 |
srcIndex := 2."skip dquote" |
|
229 |
lastChar1 := lastChar2 := nil. |
|
230 |
key := String new:2. |
|
231 |
1 to:width do:[:col | |
|
232 |
c1 := line at:srcIndex. |
|
233 |
c2 := line at:srcIndex+1. |
|
234 |
(c1 ~~ lastChar1 or:[c2 ~~ lastChar2]) ifTrue:[ |
|
235 |
key at:1 put:c1. |
|
236 |
key at:2 put:c2. |
|
237 |
lastXLation := characterTranslation at:key. |
|
238 |
lastChar1 := c1. |
|
239 |
lastChar2 := c2. |
|
240 |
]. |
|
241 |
bitsPerPixel == 24 ifTrue:[ |
|
242 |
data at:dstIndex put:(colorMap at:lastXLation+1) redByte. |
|
243 |
data at:dstIndex+1 put:(colorMap at:lastXLation+1) greenByte. |
|
244 |
data at:dstIndex+2 put:(colorMap at:lastXLation+1) blueByte. |
|
245 |
dstIndex := dstIndex + 3. |
|
246 |
] ifFalse:[ |
|
247 |
data at:dstIndex put:lastXLation. |
|
248 |
dstIndex := dstIndex + 1. |
|
249 |
]. |
|
250 |
srcIndex := srcIndex + 2. |
|
251 |
] |
|
252 |
] ifFalse:[ |
|
253 |
s := line readStream. |
|
254 |
s next. "/ skip dquote |
|
255 |
1 to:width do:[:col | |
|
256 |
key := s next:charsPerPixel. |
|
257 |
"/ data at:dstIndex put:(characterTranslation at:key). |
|
258 |
key ~= lastKey ifTrue:[ |
|
259 |
lastXLation := characterTranslation at:key. |
|
260 |
lastKey := key |
|
261 |
]. |
|
262 |
data at:dstIndex put:lastXLation. |
|
263 |
dstIndex := dstIndex + 1 |
|
264 |
] |
|
265 |
] |
|
266 |
] |
|
267 |
]. |
|
268 |
||
269 |
bitsPerPixel == 24 ifTrue:[ |
|
270 |
photometric := #rgb. |
|
271 |
samplesPerPixel := 3. |
|
272 |
bitsPerSample := #(8 8 8). |
|
273 |
] ifFalse:[ |
|
274 |
photometric := #palette. |
|
275 |
samplesPerPixel := 1. |
|
276 |
bitsPerSample := Array with:bitsPerPixel. |
|
277 |
]. |
|
278 |
||
279 |
maskPixelValue notNil ifTrue:[ |
|
280 |
self buildMaskFromColor:maskPixelValue |
|
281 |
]. |
|
282 |
||
283 |
" |
|
284 |
XPMReader fromStream:('../../goodies/bitmaps/xpmBitmaps/FATAL.xpm' asFilename readStream) |
|
285 |
" |
|
286 |
||
287 |
"Created: / 24.9.1995 / 06:20:06 / claus" |
|
288 |
"Modified: / 24.9.1995 / 07:07:33 / claus" |
|
289 |
"Modified: / 5.7.1996 / 17:27:59 / stefan" |
|
290 |
"Modified: / 27.7.1998 / 20:01:56 / cg" |
|
291 |
! ! |
|
292 |
||
293 |
!XPMReader methodsFor:'reading-private'! |
|
22 | 294 |
|
295 |
colorNameFrom:aStream |
|
296 |
"read either a color-name or value specified in X-notation |
|
297 |
(#rrggbb where rr, gg and bb are 2-digit hex numbers)" |
|
298 |
||
299 |
|s| |
|
300 |
||
301 |
aStream peek == $# ifTrue:[ |
|
28 | 302 |
aStream next. |
303 |
s := '#'. |
|
24 | 304 |
] ifFalse:[ |
28 | 305 |
s := ''. |
22 | 306 |
]. |
28 | 307 |
[aStream peek isLetterOrDigit] whileTrue:[ |
308 |
s := s copyWith:aStream next |
|
24 | 309 |
]. |
310 |
^ s |
|
22 | 311 |
! |
312 |
||
1737 | 313 |
readColorMap:colorMapSize |
314 |
|redMap greenMap blueMap s key lineDone state |
|
315 |
symbolicName monoName greyName grey4Name colorName| |
|
22 | 316 |
|
107 | 317 |
redMap := ByteArray new:colorMapSize. |
318 |
greenMap := ByteArray new:colorMapSize. |
|
319 |
blueMap := ByteArray new:colorMapSize. |
|
1737 | 320 |
|
22 | 321 |
1 to:colorMapSize do:[:colorIndex | |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
322 |
|index line color t word| |
22 | 323 |
|
1737 | 324 |
line := inStream nextLine. |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
325 |
[line notNil and:[line startsWith:'/*']] whileTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
326 |
[line notNil and:[(line endsWith:'*/') not]] whileTrue:[ |
1737 | 327 |
line := inStream nextLine. |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
328 |
]. |
1737 | 329 |
line := inStream nextLine. |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
330 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
331 |
line notNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
332 |
line := line withoutSeparators |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
333 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
334 |
(line notNil and:[line startsWith:'"']) ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
335 |
^ self fileFormatError:'format error (expected color spec)'. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
336 |
]. |
24 | 337 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
338 |
s := ReadStream on:line. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
339 |
s next. "skip quote" |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
340 |
charsPerPixel ~~ 1 ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
341 |
key := s next:charsPerPixel. |
1737 | 342 |
characterTranslation at:key put:colorIndex - 1. |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
343 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
344 |
index := s next asciiValue. |
1737 | 345 |
characterTranslation at:index put:colorIndex - 1. |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
346 |
]. |
22 | 347 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
348 |
lineDone := false. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
349 |
state := nil. |
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
350 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
351 |
[lineDone] whileFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
352 |
s skipSeparators. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
353 |
s peek == $# ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
354 |
word := self colorNameFrom:s |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
355 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
356 |
word := s nextAlphaNumericWord. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
357 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
358 |
word isNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
359 |
lineDone := true |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
360 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
361 |
word = 's' ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
362 |
"/ symbolic name ... |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
363 |
state := $s. symbolicName := ''. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
364 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
365 |
word = 'm' ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
366 |
"/ monochrome data |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
367 |
state := $m. monoName := ''. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
368 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
369 |
word = 'g' ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
370 |
"/ grey data |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
371 |
state := $g. greyName := ''. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
372 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
373 |
word = 'g4' ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
374 |
"/ grey data |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
375 |
state := $G. grey4Name := ''. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
376 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
377 |
word = 'c' ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
378 |
"/ color data |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
379 |
state := $c. colorName := ''. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
380 |
] ifFalse:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
381 |
"/ append to name |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
382 |
state isNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
383 |
^ self fileFormatError:('format error got: ' |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
384 |
, word printString |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
385 |
, ' (expected ''c'',''m'',''g'' or ''s'')'). |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
386 |
]. |
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
387 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
388 |
state == $m ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
389 |
monoName := monoName , ' ' , word. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
390 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
391 |
state == $g ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
392 |
greyName := greyName , ' ' , word. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
393 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
394 |
state == $G ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
395 |
grey4Name := grey4Name , ' ' , word. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
396 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
397 |
state == $c ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
398 |
colorName := colorName , ' ' , word. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
399 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
400 |
state == $s ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
401 |
symbolicName := symbolicName , ' ' , word. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
402 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
403 |
(word startsWith:'#') ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
404 |
state := nil. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
405 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
406 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
407 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
408 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
409 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
410 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
411 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
412 |
]. |
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
413 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
414 |
colorName notNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
415 |
colorName := colorName withoutSeparators |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
416 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
417 |
monoName notNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
418 |
monoName := monoName withoutSeparators |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
419 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
420 |
greyName notNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
421 |
greyName := greyName withoutSeparators |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
422 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
423 |
grey4Name notNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
424 |
grey4Name := grey4Name withoutSeparators |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
425 |
]. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
426 |
symbolicName notNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
427 |
symbolicName := symbolicName withoutSeparators |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
428 |
]. |
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
429 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
430 |
"/ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
431 |
"/ for now - ignore everything, except |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
432 |
"/ colorName (if there is one) |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
433 |
"/ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
434 |
colorName isNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
435 |
colorName := greyName. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
436 |
colorName isNil ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
437 |
colorName := monoName. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
438 |
] |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
439 |
]. |
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
440 |
|
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
441 |
(colorName sameAs: 'none') ifTrue:[ |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
442 |
color := Color noColor. "/ white |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
443 |
redMap at:colorIndex put:0. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
444 |
greenMap at:colorIndex put:0. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
445 |
blueMap at:colorIndex put:0. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
446 |
maskPixelValue := colorIndex-1. |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
447 |
] ifFalse:[ |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1743
diff
changeset
|
448 |
color := Color name:colorName ifIllegal:(Color black). |
1403
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
449 |
redMap at:colorIndex put:(color red asFloat * 255.0 // 100). |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
450 |
greenMap at:colorIndex put:(color green asFloat * 255.0 // 100). |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
451 |
blueMap at:colorIndex put:(color blue asFloat * 255.0 // 100). |
94f9ec117aa5
tuned image reading with 2-char color encoding
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
452 |
]. |
22 | 453 |
]. |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1743
diff
changeset
|
454 |
|
1759
f52382e5a9b8
slowly getting rid of the Colormap class
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
455 |
colorMap := MappedPalette redVector:redMap greenVector:greenMap blueVector:blueMap. |
22 | 456 |
! ! |
41 | 457 |
|
1805 | 458 |
!XPMReader methodsFor:'writing'! |
459 | 459 |
|
460 |
save:image onFile:aFileName |
|
461 |
"save image as XPM file on aFileName. |
|
462 |
Caveat: currently, only a maximum of roughly 50 colors is handled |
|
463 |
(i.e. very simple images)" |
|
464 |
||
465 |
|usedColors nColorsUsed nColors nChars baseName map maskColorIndex |
|
466 |
isMasked imageMask| |
|
467 |
||
1012
8dd3d70caedb
oops - usedColors returns a set.
Claus Gittinger <cg@exept.de>
parents:
1007
diff
changeset
|
468 |
usedColors := image usedColors asArray. |
459 | 469 |
nColors := nColorsUsed := usedColors size. |
470 |
(imageMask := image mask) notNil ifTrue:[ |
|
471 |
nColors := nColors + 1. |
|
472 |
maskColorIndex := nColors. |
|
473 |
]. |
|
474 |
nColors > 256 ifTrue:[ |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
475 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
476 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
477 |
errorString:('XPMReader cannot represent this image (too many colors)'). |
459 | 478 |
]. |
479 |
||
480 |
map := ($a to: $z) asOrderedCollection. |
|
481 |
map addAll:($A to: $Z) asOrderedCollection. |
|
482 |
map addAll:($0 to: $9) asOrderedCollection. |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
483 |
map addAll:#($. $, $` $^ $* $: $; $< $> $? $% $# $& $( $) $- $+ $=) asOrderedCollection. |
459 | 484 |
nChars := 1. |
485 |
||
486 |
nColors > map size ifTrue:[ |
|
668
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
487 |
"/ ^ Image cannotRepresentImageSignal |
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
488 |
"/ raiseWith:image |
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
489 |
"/ errorString:('XPMReader cannot represent this image (too many colors)'). |
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
490 |
map := OrderedCollection new. |
693 | 491 |
$a to: $j do:[:c1 | |
668
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
492 |
map addAll:(($a to: $z) collect:[:c2 | c1 asString , c2 asString]). |
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
493 |
]. |
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
494 |
nChars := 2. |
459 | 495 |
]. |
496 |
||
1710
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1650
diff
changeset
|
497 |
[ |
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1650
diff
changeset
|
498 |
outStream := aFileName asFilename newReadWriteStream. |
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1650
diff
changeset
|
499 |
] on:FileStream openErrorSignal do:[:ex| |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
500 |
^ Image fileCreationErrorSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
501 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
502 |
errorString:('file creation error: ' , aFileName asString). |
459 | 503 |
]. |
504 |
||
505 |
baseName := aFileName asFilename baseName asFilename withoutSuffix asString. |
|
1743
2f206c9f1319
replace $. in c-variables name
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
506 |
baseName replaceAll:$. with:$_. |
459 | 507 |
|
508 |
outStream nextPutLine:'/* XPM */'. |
|
509 |
outStream nextPutLine:'static char *' , baseName , '_xpm[] = {'. |
|
510 |
outStream nextPutLine:'/* width height ncolors chars_per_pixel */'. |
|
511 |
outStream nextPutLine:'"' , image width printString , ' ' |
|
512 |
, image height printString , ' ' |
|
513 |
, nColors printString , ' ' |
|
514 |
, nChars printString , '",'. |
|
515 |
||
516 |
||
517 |
outStream nextPutLine:'/* colors */'. |
|
518 |
1 to:nColorsUsed do:[:idx | |
|
519 |
|clr| |
|
520 |
||
521 |
clr := usedColors at:idx. |
|
522 |
outStream nextPutLine:'"' , (map at:idx) asString , |
|
523 |
' ' , 'c ' , (self colorNameOf:clr) , |
|
524 |
'",'. |
|
525 |
]. |
|
526 |
maskColorIndex notNil ifTrue:[ |
|
527 |
outStream nextPutLine:'"' , (map at:maskColorIndex) asString , |
|
528 |
' c none",'. |
|
529 |
]. |
|
530 |
||
531 |
outStream nextPutLine:'/* pixels */'. |
|
532 |
||
533 |
maskColorIndex isNil ifTrue:[ |
|
534 |
isMasked := false |
|
535 |
]. |
|
560 | 536 |
|
1743
2f206c9f1319
replace $. in c-variables name
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
537 |
0 to:image height - 1 do:[:y | |
459 | 538 |
outStream nextPutAll:'"'. |
1743
2f206c9f1319
replace $. in c-variables name
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
539 |
0 to:image width - 1 do:[:x | |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
540 |
|clr idx| |
459 | 541 |
|
542 |
maskColorIndex notNil ifTrue:[ |
|
560 | 543 |
isMasked := (imageMask pixelAtX:x y:y) == 0 |
459 | 544 |
]. |
545 |
isMasked ifTrue:[ |
|
668
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
546 |
outStream nextPutAll:(map at:maskColorIndex) asString |
459 | 547 |
] ifFalse:[ |
564 | 548 |
clr := image colorAtX:x y:y. |
459 | 549 |
idx := usedColors indexOf:clr. |
668
2c741725cc08
allow save of images with up-to 256 colors
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
550 |
outStream nextPutAll:(map at:idx) asString |
459 | 551 |
] |
552 |
]. |
|
553 |
outStream nextPutLine:'",'. |
|
554 |
]. |
|
469
7b58a1bf581c
dont forget to close the stream at the end
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
555 |
outStream nextPutLine:'};'. |
7b58a1bf581c
dont forget to close the stream at the end
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
556 |
outStream close. |
459 | 557 |
|
1012
8dd3d70caedb
oops - usedColors returns a set.
Claus Gittinger <cg@exept.de>
parents:
1007
diff
changeset
|
558 |
"Modified: / 28.7.1998 / 21:52:13 / cg" |
459 | 559 |
! ! |
560 |
||
1805 | 561 |
!XPMReader methodsFor:'writing-private'! |
562 |
||
563 |
colorNameOf:aColor |
|
564 |
"generate a name for a color. If its a standard color, |
|
565 |
return its name; otherwise return the hex representation." |
|
566 |
||
567 |
#(white black red green blue |
|
568 |
yellow magenta cyan orange) do:[:aStandardColorName | |
|
569 |
aColor = (Color name:aStandardColorName) ifTrue:[ |
|
570 |
^ aStandardColorName. |
|
571 |
] |
|
572 |
]. |
|
573 |
^ '#' |
|
574 |
, (aColor redByte hexPrintString:2) |
|
575 |
, (aColor greenByte hexPrintString:2) |
|
576 |
, (aColor blueByte hexPrintString:2) |
|
577 |
||
578 |
"Created: / 27.2.1997 / 11:48:40 / cg" |
|
579 |
"Modified: / 6.6.1998 / 20:58:49 / cg" |
|
580 |
! ! |
|
581 |
||
384
f139a7fc423b
fixed color reading - color names may consist of multiple
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
582 |
!XPMReader class methodsFor:'documentation'! |
203 | 583 |
|
584 |
version |
|
1805 | 585 |
^ '$Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.54 2003-09-01 14:47:55 cg Exp $' |
203 | 586 |
! ! |
1650 | 587 |
|
41 | 588 |
XPMReader initialize! |