author | Claus Gittinger <cg@exept.de> |
Thu, 10 Apr 2003 16:26:11 +0200 | |
changeset 1745 | 4fa0fad2a463 |
parent 1710 | ad35e6a18e98 |
child 1805 | 93f557cbe600 |
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:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1710
diff
changeset
|
19 |
category:'Graphics-Images-Readers' |
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 |
|
1521 | 76 |
(anImage depth == 1) ifTrue:[ |
77 |
photometric := anImage photometric. |
|
78 |
((photometric == #blackIs0) or:[photometric == #whiteIs0]) ifTrue:[^ true]. |
|
1495 | 79 |
|
1521 | 80 |
photometric == #palette ifTrue:[ |
81 |
clr0 := anImage colorFromValue:0. |
|
82 |
clr1 := anImage colorFromValue:1. |
|
83 |
(clr0 = Color white and:[clr1 = Color black]) ifTrue:[^true]. |
|
84 |
(clr1 = Color white and:[clr0 = Color black]) ifTrue:[^true]. |
|
85 |
]. |
|
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
86 |
]. |
1521 | 87 |
Transcript showCR:'XBMReader: not a b&w image.'. |
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
88 |
^ false |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
89 |
|
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
90 |
"Modified: / 17.8.1998 / 10:17:01 / cg" |
135 | 91 |
! |
92 |
||
41 | 93 |
isValidImageFile:aFileName |
94 |
"return true, if aFileName contains an x-bitmap-file image" |
|
95 |
||
96 |
|line inStream index1 index2 keyword| |
|
97 |
||
98 |
inStream := self streamReadingFile:aFileName. |
|
99 |
inStream isNil ifTrue:[^ false]. |
|
100 |
||
550 | 101 |
Stream readErrorSignal handle:[:ex | |
102 |
line := nil. |
|
103 |
] do:[ |
|
1510
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
104 |
Stream lineTooLongErrorSignal handle:[:ex | |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
105 |
line := nil. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
106 |
Transcript showCR:'long line'. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
107 |
ex return. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
108 |
] do:[ |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
109 |
line := inStream nextLine. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
110 |
]. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
111 |
[line notNil and:[line isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
112 |
line := inStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
113 |
]. |
550 | 114 |
]. |
41 | 115 |
line isNil ifTrue:[ |
550 | 116 |
inStream close. |
117 |
^ false |
|
41 | 118 |
]. |
119 |
[line startsWith:'#'] whileFalse:[ |
|
558
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
120 |
Stream readErrorSignal handle:[:ex | |
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
121 |
line := nil. |
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
122 |
] do:[ |
1510
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
123 |
Stream lineTooLongErrorSignal handle:[:ex | |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
124 |
line := nil. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
125 |
Transcript showCR:'long line'. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
126 |
ex return. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
127 |
] do:[ |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
128 |
line := inStream nextLine. |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
129 |
]. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
130 |
[line notNil and:[line isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
131 |
line := inStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
132 |
]. |
558
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
133 |
]. |
550 | 134 |
line isNil ifTrue:[ |
135 |
inStream close. |
|
136 |
^ false |
|
137 |
] |
|
41 | 138 |
]. |
139 |
index1 := line indexOf:(Character space). |
|
140 |
index2 := line indexOf:(Character space) startingAt:(index1 + 1). |
|
141 |
(index2 == 0) ifTrue:[ |
|
550 | 142 |
inStream close. |
143 |
^ false |
|
41 | 144 |
]. |
145 |
keyword := line copyFrom:index1 to:(index2 - 1). |
|
146 |
(keyword endsWith:'_width') ifFalse:[ |
|
550 | 147 |
inStream close. |
148 |
^ false |
|
41 | 149 |
]. |
150 |
inStream close. |
|
151 |
^ true |
|
550 | 152 |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
153 |
"Modified: / 18.3.1999 / 11:33:39 / cg" |
41 | 154 |
! ! |
155 |
||
156 |
!XBMReader methodsFor:'reading from file'! |
|
157 |
||
158 |
fromStream:aStream |
|
202 | 159 |
"read an image in xbm format from aStream" |
160 |
||
524 | 161 |
|lineString |
41 | 162 |
index "{ Class: SmallInteger }" |
163 |
dstIndex "{ Class: SmallInteger }" |
|
164 |
bytesPerRow |
|
165 |
lo "{ Class: SmallInteger }" |
|
166 |
hi "{ Class: SmallInteger }" |
|
167 |
val "{ Class: SmallInteger }" |
|
168 |
reverseBits| |
|
169 |
||
170 |
inStream := aStream. |
|
171 |
||
524 | 172 |
lineString := aStream nextLine. |
173 |
lineString isNil ifTrue:[ |
|
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
174 |
^ self fileFormatError:'short file'. |
41 | 175 |
]. |
176 |
||
524 | 177 |
[lineString startsWith:'#'] whileFalse:[ |
178 |
lineString := aStream nextLine. |
|
179 |
lineString isNil ifTrue:[ |
|
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
180 |
^ self fileFormatError:'short file'. |
493 | 181 |
]. |
41 | 182 |
]. |
183 |
||
524 | 184 |
(lineString startsWith:'#define') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
185 |
^ self fileFormatError:'format error (expected #define)'. |
41 | 186 |
]. |
187 |
||
524 | 188 |
index := lineString indexOf:(Character space). |
189 |
index := lineString indexOf:(Character space) startingAt:(index + 1). |
|
41 | 190 |
(index == 0) ifTrue:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
191 |
^ self fileFormatError:'format error'. |
41 | 192 |
]. |
524 | 193 |
((lineString copyTo:index - 1) endsWith:'width') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
194 |
^ self fileFormatError:'format error (expected width)'. |
41 | 195 |
]. |
524 | 196 |
lineString := lineString copyFrom:(index + 1). |
1049 | 197 |
width := Number readFromString:lineString onError:nil. |
198 |
width isNil ifTrue:[ |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
199 |
^ self fileFormatError:'format error (expected width)'. |
1049 | 200 |
]. |
41 | 201 |
|
524 | 202 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
203 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
204 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
205 |
]. |
524 | 206 |
index := lineString indexOf:(Character space). |
207 |
index := lineString indexOf:(Character space) startingAt:(index + 1). |
|
41 | 208 |
(index == 0) ifTrue:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
209 |
^ self fileFormatError:'format error'. |
41 | 210 |
]. |
524 | 211 |
((lineString copyTo:index - 1) endsWith:'height') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
212 |
^ self fileFormatError:'format error (expected height)'. |
41 | 213 |
]. |
524 | 214 |
lineString := lineString copyFrom:(index + 1). |
1049 | 215 |
height := Number readFromString:lineString onError:nil. |
216 |
height isNil ifTrue:[ |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
217 |
^ self fileFormatError:'format error (expected height)'. |
1049 | 218 |
]. |
41 | 219 |
|
220 |
bytesPerRow := width // 8. |
|
221 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
202 | 222 |
bytesPerRow := bytesPerRow + 1 |
41 | 223 |
]. |
224 |
||
225 |
reverseBits := self class reverseBits. |
|
226 |
||
227 |
data := ByteArray new:(bytesPerRow * height). |
|
228 |
dstIndex := 1. |
|
229 |
||
524 | 230 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
231 |
[(lineString startsWith:'#') |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
232 |
or:[lineString isEmpty]] whileTrue:[ |
524 | 233 |
lineString := aStream nextLine. |
41 | 234 |
]. |
235 |
||
524 | 236 |
[lineString notNil and:[(lineString startsWith:'static') not]] whileTrue:[ |
237 |
lineString := aStream nextLine. |
|
53 | 238 |
]. |
524 | 239 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
240 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
241 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
242 |
]. |
53 | 243 |
|
524 | 244 |
[lineString notNil] whileTrue:[ |
1506
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
245 |
dstIndex <= data size ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
246 |
index := 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
247 |
[index ~~ 0] whileTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
248 |
dstIndex <= data size ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
249 |
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
|
250 |
(index ~~ 0) ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
251 |
index := index + 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
252 |
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
|
253 |
index := index + 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
dstIndex := dstIndex + 1 |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
258 |
] |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
259 |
] ifFalse:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
260 |
index := 0. "/ break loop |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
261 |
] |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
262 |
]. |
202 | 263 |
]. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
264 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
265 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
266 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
267 |
]. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
268 |
|
41 | 269 |
]. |
270 |
photometric := #whiteIs0. |
|
271 |
samplesPerPixel := 1. |
|
272 |
bitsPerSample := #(1). |
|
273 |
||
274 |
" |
|
275 |
XBMReader fromFile:'bitmaps/globe1.xbm' |
|
202 | 276 |
" |
277 |
||
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
278 |
"Modified: / 18.3.1999 / 11:32:46 / cg" |
41 | 279 |
! ! |
280 |
||
3 | 281 |
!XBMReader methodsFor:'writing to file'! |
282 |
||
283 |
save:image onFile:aFileName |
|
202 | 284 |
"save image as XBM file on aFileName. |
285 |
Only depth1 b&w images can be represented in this format." |
|
3 | 286 |
|
33 | 287 |
|reverseBits bits byte |
66 | 288 |
h "{ Class: SmallInteger }" |
33 | 289 |
srcIndex "{ Class: SmallInteger }" |
290 |
rowBytes "{ Class: SmallInteger }" | |
|
3 | 291 |
|
51 | 292 |
(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
|
293 |
^ Image cannotRepresentImageSignal |
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:('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
|
296 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
297 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
298 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
299 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
300 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
301 |
errorString:('XBM format does not support an imageMask'). |
51 | 302 |
]. |
303 |
||
1710
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1521
diff
changeset
|
304 |
[ |
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1521
diff
changeset
|
305 |
outStream := aFileName asFilename newReadWriteStream. |
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1521
diff
changeset
|
306 |
] on:FileStream openErrorSignal do:[:ex| |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
307 |
^ Image fileCreationErrorSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
308 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
309 |
errorString:('file creation error: ' , aFileName asString). |
3 | 310 |
]. |
311 |
||
312 |
width := image width. |
|
313 |
height := image height. |
|
314 |
photometric := image photometric. |
|
315 |
samplesPerPixel := image samplesPerPixel. |
|
316 |
bitsPerSample := image bitsPerSample. |
|
317 |
colorMap := image colorMap. |
|
318 |
||
319 |
outStream nextPutAll: '#define xbm_width '. |
|
320 |
outStream nextPutAll:(width printString). |
|
321 |
outStream cr. |
|
322 |
outStream nextPutAll: '#define xbm_height '. |
|
323 |
outStream nextPutAll:(height printString). |
|
324 |
outStream cr. |
|
325 |
outStream nextPutAll: 'static char xbm_bits[] = {'; cr. |
|
326 |
||
327 |
reverseBits := self class reverseBits. |
|
328 |
||
329 |
rowBytes := width + 7 // 8. |
|
330 |
data := image bits. |
|
331 |
srcIndex := 1. |
|
332 |
||
66 | 333 |
h := height. |
334 |
h timesRepeat:[ |
|
202 | 335 |
rowBytes timesRepeat:[ |
336 |
outStream nextPutAll: '0x'. |
|
337 |
bits := data at:srcIndex. srcIndex := srcIndex + 1. |
|
338 |
photometric == #blackIs0 ifTrue:[ |
|
339 |
bits := bits bitInvert bitAnd:16rFF |
|
340 |
]. |
|
341 |
byte := (reverseBits at:(bits + 1)). |
|
342 |
byte < 16 ifTrue:[ |
|
343 |
outStream nextPut:$0 |
|
344 |
]. |
|
272
477aeb0d62b6
printOn:radix: -> printOn:base:
Claus Gittinger <cg@exept.de>
parents:
259
diff
changeset
|
345 |
byte printOn:outStream base:16. |
202 | 346 |
outStream nextPutAll: ', '. |
347 |
]. |
|
348 |
outStream cr |
|
3 | 349 |
]. |
350 |
outStream nextPutAll: '};'; cr. |
|
351 |
outStream close |
|
352 |
||
33 | 353 |
" |
354 |
XBMReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.xbm' |
|
355 |
" |
|
356 |
" |
|
357 |
convert sun icon to XBM format: |
|
358 |
||
359 |
XBMReader save:(Image fromFile:'bitmaps/hello_world.icon') onFile:'test.xbm' |
|
360 |
" |
|
202 | 361 |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
362 |
"Modified: 27.2.1997 / 12:46:49 / cg" |
3 | 363 |
! ! |
364 |
||
135 | 365 |
!XBMReader class methodsFor:'documentation'! |
366 |
||
367 |
version |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1710
diff
changeset
|
368 |
^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.47 2003-04-10 14:25:21 cg Exp $' |
135 | 369 |
! ! |
1710
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1521
diff
changeset
|
370 |
|
41 | 371 |
XBMReader initialize! |