author | Claus Gittinger <cg@exept.de> |
Thu, 13 Sep 2001 11:01:37 +0200 | |
changeset 1506 | 60e56746dce6 |
parent 1495 | 100e4e782f71 |
child 1510 | 4e0133eec046 |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1992 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 |
" |
|
12 |
||
1495 | 13 |
"{ Package: 'stx:libview2' }" |
14 |
||
0 | 15 |
ImageReader subclass:#XBMReader |
195 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
259 | 19 |
category:'Graphics-Images-Support' |
0 | 20 |
! |
21 |
||
21 | 22 |
!XBMReader class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
28 | 27 |
All Rights Reserved |
0 | 28 |
|
21 | 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 |
! |
|
0 | 37 |
|
21 | 38 |
documentation |
39 |
" |
|
40 |
this class provides methods for loading and saving x-bitmap-file images. |
|
41 |
These images can (for example) be created using the bitmap editor supplied |
|
24 | 42 |
with X. |
43 |
Only monochrome images can be represented in this format. |
|
203 | 44 |
Both reading and writing of images is supported. |
195 | 45 |
|
46 |
[See also:] |
|
234 | 47 |
Image Form Icon |
197 | 48 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader |
210 | 49 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
197 | 50 |
XPMReader XWDReader |
220 | 51 |
|
52 |
[author:] |
|
53 |
Claus Gittinger |
|
21 | 54 |
" |
55 |
! ! |
|
0 | 56 |
|
28 | 57 |
!XBMReader class methodsFor:'initialization'! |
58 |
||
59 |
initialize |
|
202 | 60 |
"tell Image-class, that a new fileReader is present |
61 |
for the '.xbm' extension." |
|
62 |
||
647 | 63 |
MIMETypes defineImageType:'image/x-xbitmap' suffix:'xbm' reader:self. |
64 |
MIMETypes defineImageType:nil suffix:'bm' reader:self. |
|
202 | 65 |
|
399 | 66 |
"Modified: 1.2.1997 / 15:08:18 / cg" |
28 | 67 |
! ! |
68 |
||
41 | 69 |
!XBMReader class methodsFor:'testing'! |
70 |
||
135 | 71 |
canRepresent:anImage |
72 |
"return true, if anImage can be represented in my file format" |
|
73 |
||
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
74 |
|photometric clr0 clr1| |
135 | 75 |
|
76 |
(anImage depth ~~ 1) ifTrue:[^ false.]. |
|
1495 | 77 |
|
78 |
photometric := anImage photometric. |
|
79 |
((photometric == #blackIs0) or:[photometric == #whiteIs0]) ifTrue:[^ true]. |
|
80 |
||
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
81 |
photometric == #palette ifTrue:[ |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
82 |
clr0 := anImage colorFromValue:0. |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
83 |
clr1 := anImage colorFromValue:1. |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
84 |
(clr0 = Color white and:[clr1 = Color black]) ifTrue:[^true]. |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
85 |
(clr1 = Color white and:[clr0 = Color black]) ifTrue:[^true]. |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
86 |
]. |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
87 |
^ false |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
88 |
|
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
89 |
"Modified: / 17.8.1998 / 10:17:01 / cg" |
135 | 90 |
! |
91 |
||
41 | 92 |
isValidImageFile:aFileName |
93 |
"return true, if aFileName contains an x-bitmap-file image" |
|
94 |
||
95 |
|line inStream index1 index2 keyword| |
|
96 |
||
97 |
inStream := self streamReadingFile:aFileName. |
|
98 |
inStream isNil ifTrue:[^ false]. |
|
99 |
||
550 | 100 |
Stream readErrorSignal handle:[:ex | |
101 |
line := nil. |
|
102 |
] do:[ |
|
103 |
line := inStream nextLine. |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
104 |
[line notNil and:[line isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
105 |
line := inStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
106 |
]. |
550 | 107 |
]. |
41 | 108 |
line isNil ifTrue:[ |
550 | 109 |
inStream close. |
110 |
^ false |
|
41 | 111 |
]. |
112 |
[line startsWith:'#'] whileFalse:[ |
|
558
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
113 |
Stream readErrorSignal handle:[:ex | |
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
114 |
line := nil. |
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
115 |
] do:[ |
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
116 |
line := inStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
117 |
[line notNil and:[line isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
118 |
line := inStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
119 |
]. |
558
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
120 |
]. |
550 | 121 |
line isNil ifTrue:[ |
122 |
inStream close. |
|
123 |
^ false |
|
124 |
] |
|
41 | 125 |
]. |
126 |
index1 := line indexOf:(Character space). |
|
127 |
index2 := line indexOf:(Character space) startingAt:(index1 + 1). |
|
128 |
(index2 == 0) ifTrue:[ |
|
550 | 129 |
inStream close. |
130 |
^ false |
|
41 | 131 |
]. |
132 |
keyword := line copyFrom:index1 to:(index2 - 1). |
|
133 |
(keyword endsWith:'_width') ifFalse:[ |
|
550 | 134 |
inStream close. |
135 |
^ false |
|
41 | 136 |
]. |
137 |
inStream close. |
|
138 |
^ true |
|
550 | 139 |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
140 |
"Modified: / 18.3.1999 / 11:33:39 / cg" |
41 | 141 |
! ! |
142 |
||
143 |
!XBMReader methodsFor:'reading from file'! |
|
144 |
||
145 |
fromStream:aStream |
|
202 | 146 |
"read an image in xbm format from aStream" |
147 |
||
524 | 148 |
|lineString |
41 | 149 |
index "{ Class: SmallInteger }" |
150 |
dstIndex "{ Class: SmallInteger }" |
|
151 |
bytesPerRow |
|
152 |
lo "{ Class: SmallInteger }" |
|
153 |
hi "{ Class: SmallInteger }" |
|
154 |
val "{ Class: SmallInteger }" |
|
155 |
reverseBits| |
|
156 |
||
157 |
inStream := aStream. |
|
158 |
||
524 | 159 |
lineString := aStream nextLine. |
160 |
lineString isNil ifTrue:[ |
|
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
161 |
^ self fileFormatError:'short file'. |
41 | 162 |
]. |
163 |
||
524 | 164 |
[lineString startsWith:'#'] whileFalse:[ |
165 |
lineString := aStream nextLine. |
|
166 |
lineString isNil ifTrue:[ |
|
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
167 |
^ self fileFormatError:'short file'. |
493 | 168 |
]. |
41 | 169 |
]. |
170 |
||
524 | 171 |
(lineString startsWith:'#define') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
172 |
^ self fileFormatError:'format error (expected #define)'. |
41 | 173 |
]. |
174 |
||
524 | 175 |
index := lineString indexOf:(Character space). |
176 |
index := lineString indexOf:(Character space) startingAt:(index + 1). |
|
41 | 177 |
(index == 0) ifTrue:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
178 |
^ self fileFormatError:'format error'. |
41 | 179 |
]. |
524 | 180 |
((lineString copyTo:index - 1) endsWith:'width') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
181 |
^ self fileFormatError:'format error (expected width)'. |
41 | 182 |
]. |
524 | 183 |
lineString := lineString copyFrom:(index + 1). |
1049 | 184 |
width := Number readFromString:lineString onError:nil. |
185 |
width isNil ifTrue:[ |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
186 |
^ self fileFormatError:'format error (expected width)'. |
1049 | 187 |
]. |
41 | 188 |
|
524 | 189 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
190 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
191 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
192 |
]. |
524 | 193 |
index := lineString indexOf:(Character space). |
194 |
index := lineString indexOf:(Character space) startingAt:(index + 1). |
|
41 | 195 |
(index == 0) ifTrue:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
196 |
^ self fileFormatError:'format error'. |
41 | 197 |
]. |
524 | 198 |
((lineString copyTo:index - 1) endsWith:'height') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
199 |
^ self fileFormatError:'format error (expected height)'. |
41 | 200 |
]. |
524 | 201 |
lineString := lineString copyFrom:(index + 1). |
1049 | 202 |
height := Number readFromString:lineString onError:nil. |
203 |
height isNil ifTrue:[ |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
204 |
^ self fileFormatError:'format error (expected height)'. |
1049 | 205 |
]. |
41 | 206 |
|
207 |
bytesPerRow := width // 8. |
|
208 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
202 | 209 |
bytesPerRow := bytesPerRow + 1 |
41 | 210 |
]. |
211 |
||
212 |
reverseBits := self class reverseBits. |
|
213 |
||
214 |
data := ByteArray new:(bytesPerRow * height). |
|
215 |
dstIndex := 1. |
|
216 |
||
524 | 217 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
218 |
[(lineString startsWith:'#') |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
219 |
or:[lineString isEmpty]] whileTrue:[ |
524 | 220 |
lineString := aStream nextLine. |
41 | 221 |
]. |
222 |
||
524 | 223 |
[lineString notNil and:[(lineString startsWith:'static') not]] whileTrue:[ |
224 |
lineString := aStream nextLine. |
|
53 | 225 |
]. |
524 | 226 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
227 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
228 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
229 |
]. |
53 | 230 |
|
524 | 231 |
[lineString notNil] whileTrue:[ |
1506
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
232 |
dstIndex <= data size ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
233 |
index := 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
234 |
[index ~~ 0] whileTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
235 |
dstIndex <= data size ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
236 |
index := lineString indexOf:$x startingAt:index. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
237 |
(index ~~ 0) ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
238 |
index := index + 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
239 |
hi := (lineString at:index) digitValue. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
240 |
index := index + 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
241 |
lo := (lineString at:index) digitValue. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
242 |
val := (hi bitShift:4) bitOr:lo. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
243 |
data at:dstIndex put:(reverseBits at:(val + 1)). |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
244 |
dstIndex := dstIndex + 1 |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
245 |
] |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
246 |
] ifFalse:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
247 |
index := 0. "/ break loop |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
248 |
] |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
249 |
]. |
202 | 250 |
]. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
251 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
252 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
253 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
254 |
]. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
255 |
|
41 | 256 |
]. |
257 |
photometric := #whiteIs0. |
|
258 |
samplesPerPixel := 1. |
|
259 |
bitsPerSample := #(1). |
|
260 |
||
261 |
" |
|
262 |
XBMReader fromFile:'bitmaps/globe1.xbm' |
|
202 | 263 |
" |
264 |
||
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
265 |
"Modified: / 18.3.1999 / 11:32:46 / cg" |
41 | 266 |
! ! |
267 |
||
3 | 268 |
!XBMReader methodsFor:'writing to file'! |
269 |
||
270 |
save:image onFile:aFileName |
|
202 | 271 |
"save image as XBM file on aFileName. |
272 |
Only depth1 b&w images can be represented in this format." |
|
3 | 273 |
|
33 | 274 |
|reverseBits bits byte |
66 | 275 |
h "{ Class: SmallInteger }" |
33 | 276 |
srcIndex "{ Class: SmallInteger }" |
277 |
rowBytes "{ Class: SmallInteger }" | |
|
3 | 278 |
|
51 | 279 |
(self class canRepresent:image) ifFalse:[ |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
280 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
281 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
282 |
errorString:('XBM format only supports monochrome images'). |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
283 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
284 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
285 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
286 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
287 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
288 |
errorString:('XBM format does not support an imageMask'). |
51 | 289 |
]. |
290 |
||
3 | 291 |
outStream := FileStream newFileNamed:aFileName. |
292 |
outStream isNil ifTrue:[ |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
293 |
^ Image fileCreationErrorSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
294 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
295 |
errorString:('file creation error: ' , aFileName asString). |
3 | 296 |
]. |
297 |
||
298 |
width := image width. |
|
299 |
height := image height. |
|
300 |
photometric := image photometric. |
|
301 |
samplesPerPixel := image samplesPerPixel. |
|
302 |
bitsPerSample := image bitsPerSample. |
|
303 |
colorMap := image colorMap. |
|
304 |
||
305 |
outStream nextPutAll: '#define xbm_width '. |
|
306 |
outStream nextPutAll:(width printString). |
|
307 |
outStream cr. |
|
308 |
outStream nextPutAll: '#define xbm_height '. |
|
309 |
outStream nextPutAll:(height printString). |
|
310 |
outStream cr. |
|
311 |
outStream nextPutAll: 'static char xbm_bits[] = {'; cr. |
|
312 |
||
313 |
reverseBits := self class reverseBits. |
|
314 |
||
315 |
rowBytes := width + 7 // 8. |
|
316 |
data := image bits. |
|
317 |
srcIndex := 1. |
|
318 |
||
66 | 319 |
h := height. |
320 |
h timesRepeat:[ |
|
202 | 321 |
rowBytes timesRepeat:[ |
322 |
outStream nextPutAll: '0x'. |
|
323 |
bits := data at:srcIndex. srcIndex := srcIndex + 1. |
|
324 |
photometric == #blackIs0 ifTrue:[ |
|
325 |
bits := bits bitInvert bitAnd:16rFF |
|
326 |
]. |
|
327 |
byte := (reverseBits at:(bits + 1)). |
|
328 |
byte < 16 ifTrue:[ |
|
329 |
outStream nextPut:$0 |
|
330 |
]. |
|
272
477aeb0d62b6
printOn:radix: -> printOn:base:
Claus Gittinger <cg@exept.de>
parents:
259
diff
changeset
|
331 |
byte printOn:outStream base:16. |
202 | 332 |
outStream nextPutAll: ', '. |
333 |
]. |
|
334 |
outStream cr |
|
3 | 335 |
]. |
336 |
outStream nextPutAll: '};'; cr. |
|
337 |
outStream close |
|
338 |
||
33 | 339 |
" |
340 |
XBMReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.xbm' |
|
341 |
" |
|
342 |
" |
|
343 |
convert sun icon to XBM format: |
|
344 |
||
345 |
XBMReader save:(Image fromFile:'bitmaps/hello_world.icon') onFile:'test.xbm' |
|
346 |
" |
|
202 | 347 |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
348 |
"Modified: 27.2.1997 / 12:46:49 / cg" |
3 | 349 |
! ! |
350 |
||
135 | 351 |
!XBMReader class methodsFor:'documentation'! |
352 |
||
353 |
version |
|
1506
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
354 |
^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.43 2001-09-13 09:01:37 cg Exp $' |
135 | 355 |
! ! |
41 | 356 |
XBMReader initialize! |