author | Stefan Vogel <sv@exept.de> |
Wed, 29 Apr 2020 22:34:37 +0200 | |
changeset 4460 | e067415ddf46 |
parent 4449 | 1d8968d59997 |
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 |
" |
|
1495 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
3570 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
ImageReader subclass:#XBMReader |
195 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1710
diff
changeset
|
20 |
category:'Graphics-Images-Readers' |
0 | 21 |
! |
22 |
||
21 | 23 |
!XBMReader class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
28 | 28 |
All Rights Reserved |
0 | 29 |
|
21 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
0 | 38 |
|
21 | 39 |
documentation |
40 |
" |
|
41 |
this class provides methods for loading and saving x-bitmap-file images. |
|
42 |
These images can (for example) be created using the bitmap editor supplied |
|
24 | 43 |
with X. |
44 |
Only monochrome images can be represented in this format. |
|
203 | 45 |
Both reading and writing of images is supported. |
195 | 46 |
|
47 |
[See also:] |
|
234 | 48 |
Image Form Icon |
4101 | 49 |
BlitImageReader FaceReader GIFReader JPEGReader MacOSXIconReader |
50 |
PBMReader PCXReader PNGReader |
|
210 | 51 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
197 | 52 |
XPMReader XWDReader |
220 | 53 |
|
54 |
[author:] |
|
55 |
Claus Gittinger |
|
21 | 56 |
" |
1812 | 57 |
! |
58 |
||
59 |
examples |
|
60 |
" |
|
61 |
Reading from a file: |
|
62 |
[exBegin] |
|
63 |
|image| |
|
64 |
||
65 |
image := Image fromFile:('../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'). |
|
66 |
image inspect |
|
67 |
[exEnd] |
|
68 |
||
69 |
||
70 |
Saving to a file: |
|
71 |
[exBegin] |
|
72 |
|image| |
|
73 |
||
74 |
image := Image fromScreen:(0@0 corner:30@30). |
|
75 |
image := image asThresholdMonochromeImage. |
|
76 |
XBMReader save:image onFile:'/tmp/test.xbm'. |
|
77 |
'/tmp/test.xbm' asFilename contents asString inspect. |
|
78 |
(Image fromFile:('/tmp/test.xbm')) inspect. |
|
79 |
[exEnd] |
|
80 |
||
81 |
||
82 |
Or directly into a stream: |
|
83 |
[exBegin] |
|
84 |
|image stream| |
|
85 |
||
86 |
image := Image fromScreen:(0@0 corner:30@30). |
|
87 |
image := image asThresholdMonochromeImage. |
|
88 |
stream := WriteStream on:(String new). |
|
89 |
XPMReader save:image onStream:stream. |
|
90 |
stream contents inspect. |
|
91 |
[exEnd] |
|
92 |
" |
|
21 | 93 |
! ! |
0 | 94 |
|
28 | 95 |
!XBMReader class methodsFor:'initialization'! |
96 |
||
97 |
initialize |
|
202 | 98 |
"tell Image-class, that a new fileReader is present |
99 |
for the '.xbm' extension." |
|
100 |
||
647 | 101 |
MIMETypes defineImageType:'image/x-xbitmap' suffix:'xbm' reader:self. |
102 |
MIMETypes defineImageType:nil suffix:'bm' reader:self. |
|
202 | 103 |
|
399 | 104 |
"Modified: 1.2.1997 / 15:08:18 / cg" |
28 | 105 |
! ! |
106 |
||
41 | 107 |
!XBMReader class methodsFor:'testing'! |
108 |
||
135 | 109 |
canRepresent:anImage |
110 |
"return true, if anImage can be represented in my file format" |
|
111 |
||
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
112 |
|photometric clr0 clr1| |
135 | 113 |
|
1521 | 114 |
(anImage depth == 1) ifTrue:[ |
115 |
photometric := anImage photometric. |
|
116 |
((photometric == #blackIs0) or:[photometric == #whiteIs0]) ifTrue:[^ true]. |
|
1495 | 117 |
|
1521 | 118 |
photometric == #palette ifTrue:[ |
119 |
clr0 := anImage colorFromValue:0. |
|
120 |
clr1 := anImage colorFromValue:1. |
|
121 |
(clr0 = Color white and:[clr1 = Color black]) ifTrue:[^true]. |
|
122 |
(clr1 = Color white and:[clr0 = Color black]) ifTrue:[^true]. |
|
123 |
]. |
|
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
124 |
]. |
3570 | 125 |
('XBMReader [info]: image depth is not 1 (only b&w images).') infoPrintCR. |
1046
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
126 |
^ false |
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
127 |
|
8670e67344de
fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
128 |
"Modified: / 17.8.1998 / 10:17:01 / cg" |
135 | 129 |
! |
130 |
||
41 | 131 |
isValidImageFile:aFileName |
132 |
"return true, if aFileName contains an x-bitmap-file image" |
|
133 |
||
4373 | 134 |
|ok line inStream index1 index2 keyword| |
41 | 135 |
|
136 |
inStream := self streamReadingFile:aFileName. |
|
137 |
inStream isNil ifTrue:[^ false]. |
|
138 |
||
4373 | 139 |
ok := false. |
550 | 140 |
Stream readErrorSignal handle:[:ex | |
141 |
] do:[ |
|
1510
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
142 |
Stream lineTooLongErrorSignal handle:[:ex | |
2804 | 143 |
Transcript showCR:'XBMReader [info]: long line'. |
1510
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
144 |
] do:[ |
4e0133eec046
care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents:
1506
diff
changeset
|
145 |
line := inStream nextLine. |
4373 | 146 |
"/ skip empty lines |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
147 |
[line notNil and:[line isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
148 |
line := inStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
149 |
]. |
4373 | 150 |
line notNil ifTrue:[ |
151 |
[line isNil or:[line startsWith:'#']] whileFalse:[ |
|
152 |
line := inStream nextLine. |
|
153 |
]. |
|
154 |
"/ skip empty lines |
|
155 |
[line notNil and:[line isEmpty]] whileTrue:[ |
|
156 |
line := inStream nextLine. |
|
157 |
]. |
|
158 |
line notNil ifTrue:[ |
|
159 |
index1 := line indexOf:(Character space). |
|
160 |
index2 := line indexOf:(Character space) startingAt:(index1 + 1). |
|
161 |
(index2 ~~ 0) ifTrue:[ |
|
162 |
keyword := line copyFrom:index1 to:(index2 - 1). |
|
163 |
ok := (keyword endsWith:'_width') |
|
164 |
]. |
|
165 |
]. |
|
166 |
]. |
|
558
98c4c983a02b
oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents:
550
diff
changeset
|
167 |
]. |
41 | 168 |
]. |
169 |
inStream close. |
|
4373 | 170 |
^ ok |
171 |
||
172 |
" |
|
173 |
XBMReader isValidImageFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm' |
|
174 |
XBMReader isValidImageFile:'fooBar' |
|
175 |
XBMReader isValidImageFile:'../../goodies/bitmaps/xpmBitmaps/device_images/ljet.xpm' |
|
176 |
XBMReader isValidImageFile:'../../goodies/bitmaps/bitmaps/gifImages/garfield.gif' |
|
177 |
" |
|
550 | 178 |
|
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
179 |
"Modified: / 18.3.1999 / 11:33:39 / cg" |
41 | 180 |
! ! |
181 |
||
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
182 |
!XBMReader methodsFor:'private-reading'! |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
183 |
|
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
184 |
extractValueFor:keyword fromLine:lineString |
2051 | 185 |
|index1 index2 value restString| |
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
186 |
|
2051 | 187 |
index1 := lineString indexOf:(Character space). |
188 |
index2 := lineString indexOf:(Character space) startingAt:(index1 + 1). |
|
189 |
(index2 == 0) ifTrue:[ |
|
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
190 |
^ nil. |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
191 |
]. |
2051 | 192 |
((lineString copyTo:index2 - 1) endsWith:keyword) ifFalse:[ |
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
193 |
^ nil. |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
194 |
]. |
2051 | 195 |
restString := lineString copyFrom:(index2 + 1). |
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
196 |
value := Number readFromString:restString onError:nil. |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
197 |
value isNil ifTrue:[ |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
198 |
^ nil. |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
199 |
]. |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
200 |
^ value |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
201 |
! ! |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
202 |
|
1805 | 203 |
!XBMReader methodsFor:'reading'! |
41 | 204 |
|
205 |
fromStream:aStream |
|
3895 | 206 |
"read an image in xbm format from aStream. |
207 |
Leave image description in instance variables. |
|
208 |
(i.e. to get the image, ask with image)." |
|
202 | 209 |
|
524 | 210 |
|lineString |
41 | 211 |
index "{ Class: SmallInteger }" |
212 |
dstIndex "{ Class: SmallInteger }" |
|
213 |
bytesPerRow |
|
214 |
lo "{ Class: SmallInteger }" |
|
215 |
hi "{ Class: SmallInteger }" |
|
216 |
val "{ Class: SmallInteger }" |
|
217 |
reverseBits| |
|
218 |
||
219 |
inStream := aStream. |
|
220 |
||
524 | 221 |
lineString := aStream nextLine. |
222 |
lineString isNil ifTrue:[ |
|
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
223 |
^ self fileFormatError:'short file'. |
41 | 224 |
]. |
225 |
||
524 | 226 |
[lineString startsWith:'#'] whileFalse:[ |
227 |
lineString := aStream nextLine. |
|
228 |
lineString isNil ifTrue:[ |
|
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
229 |
^ self fileFormatError:'short file'. |
493 | 230 |
]. |
41 | 231 |
]. |
232 |
||
524 | 233 |
(lineString startsWith:'#define') ifFalse:[ |
816
fe0abc1f956d
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
234 |
^ self fileFormatError:'format error (expected #define)'. |
41 | 235 |
]. |
236 |
||
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
237 |
width := self extractValueFor:'width' fromLine:lineString. |
1049 | 238 |
width isNil ifTrue:[ |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
239 |
^ self fileFormatError:'format error (expected width)'. |
1049 | 240 |
]. |
41 | 241 |
|
524 | 242 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
243 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
244 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
245 |
]. |
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
246 |
height := self extractValueFor:'height' fromLine:lineString. |
1049 | 247 |
height isNil ifTrue:[ |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
248 |
^ self fileFormatError:'format error (expected height)'. |
1049 | 249 |
]. |
41 | 250 |
|
1844
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
251 |
self reportDimension. |
85c539787d5b
dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents:
1814
diff
changeset
|
252 |
|
41 | 253 |
bytesPerRow := width // 8. |
254 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
202 | 255 |
bytesPerRow := bytesPerRow + 1 |
41 | 256 |
]. |
257 |
||
258 |
reverseBits := self class reverseBits. |
|
259 |
||
260 |
data := ByteArray new:(bytesPerRow * height). |
|
261 |
dstIndex := 1. |
|
262 |
||
524 | 263 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
264 |
[(lineString startsWith:'#') |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
265 |
or:[lineString isEmpty]] whileTrue:[ |
524 | 266 |
lineString := aStream nextLine. |
41 | 267 |
]. |
268 |
||
524 | 269 |
[lineString notNil and:[(lineString startsWith:'static') not]] whileTrue:[ |
270 |
lineString := aStream nextLine. |
|
53 | 271 |
]. |
524 | 272 |
lineString := aStream nextLine. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
273 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
274 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
275 |
]. |
53 | 276 |
|
524 | 277 |
[lineString notNil] whileTrue:[ |
1506
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
278 |
dstIndex <= data size ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
279 |
index := 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
280 |
[index ~~ 0] whileTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
281 |
dstIndex <= data size ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
282 |
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
|
283 |
(index ~~ 0) ifTrue:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
284 |
index := index + 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
285 |
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
|
286 |
index := index + 1. |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
dstIndex := dstIndex + 1 |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
291 |
] |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
292 |
] ifFalse:[ |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
293 |
index := 0. "/ break loop |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
294 |
] |
60e56746dce6
ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
295 |
]. |
202 | 296 |
]. |
1144
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
297 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
298 |
[lineString notNil and:[lineString isEmpty]] whileTrue:[ |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
299 |
lineString := aStream nextLine. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
300 |
]. |
c86a1e3e3884
ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents:
1049
diff
changeset
|
301 |
|
41 | 302 |
]. |
303 |
photometric := #whiteIs0. |
|
304 |
samplesPerPixel := 1. |
|
3914 | 305 |
bitsPerSample := #[1]. |
41 | 306 |
|
307 |
" |
|
308 |
XBMReader fromFile:'bitmaps/globe1.xbm' |
|
202 | 309 |
" |
310 |
||
3914 | 311 |
"Modified: / 22-02-2017 / 14:27:21 / cg" |
41 | 312 |
! ! |
313 |
||
1805 | 314 |
!XBMReader methodsFor:'writing'! |
3 | 315 |
|
1812 | 316 |
save:image onStream:aStream |
317 |
"save image as XBM cdata on aStream. |
|
318 |
Only depth1 b&w images can be represented in this format." |
|
319 |
||
33 | 320 |
|reverseBits bits byte |
66 | 321 |
h "{ Class: SmallInteger }" |
33 | 322 |
srcIndex "{ Class: SmallInteger }" |
323 |
rowBytes "{ Class: SmallInteger }" | |
|
3 | 324 |
|
51 | 325 |
(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
|
326 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
327 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
328 |
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
|
329 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
330 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
331 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
332 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
333 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
334 |
errorString:('XBM format does not support an imageMask'). |
51 | 335 |
]. |
336 |
||
1812 | 337 |
outStream := aStream. |
3 | 338 |
|
339 |
width := image width. |
|
340 |
height := image height. |
|
341 |
photometric := image photometric. |
|
342 |
samplesPerPixel := image samplesPerPixel. |
|
343 |
bitsPerSample := image bitsPerSample. |
|
344 |
colorMap := image colorMap. |
|
345 |
||
4448 | 346 |
outStream nextPutLine: '#define xbm_width %1' with:(width printString). |
347 |
outStream nextPutLine: '#define xbm_height %1' with:(height printString). |
|
348 |
outStream nextPutLine: 'static char xbm_bits[] = {'. |
|
3 | 349 |
|
350 |
reverseBits := self class reverseBits. |
|
351 |
||
4448 | 352 |
rowBytes := (width + 7) // 8. |
3 | 353 |
data := image bits. |
354 |
srcIndex := 1. |
|
355 |
||
66 | 356 |
h := height. |
357 |
h timesRepeat:[ |
|
202 | 358 |
rowBytes timesRepeat:[ |
359 |
outStream nextPutAll: '0x'. |
|
360 |
bits := data at:srcIndex. srcIndex := srcIndex + 1. |
|
361 |
photometric == #blackIs0 ifTrue:[ |
|
362 |
bits := bits bitInvert bitAnd:16rFF |
|
363 |
]. |
|
364 |
byte := (reverseBits at:(bits + 1)). |
|
365 |
byte < 16 ifTrue:[ |
|
366 |
outStream nextPut:$0 |
|
367 |
]. |
|
272
477aeb0d62b6
printOn:radix: -> printOn:base:
Claus Gittinger <cg@exept.de>
parents:
259
diff
changeset
|
368 |
byte printOn:outStream base:16. |
202 | 369 |
outStream nextPutAll: ', '. |
370 |
]. |
|
371 |
outStream cr |
|
3 | 372 |
]. |
4448 | 373 |
outStream nextPutLine: '};'. |
3 | 374 |
|
33 | 375 |
" |
4449 | 376 |
|file original restored| |
377 |
||
378 |
original := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'. |
|
379 |
file := String streamContents:[:stream | |
|
380 |
XBMReader save:original onStream:stream |
|
381 |
]. |
|
382 |
restored := XBMReader fromStream:(file readStream). |
|
383 |
self assert:(restored = original) |
|
33 | 384 |
" |
3 | 385 |
! ! |
386 |
||
135 | 387 |
!XBMReader class methodsFor:'documentation'! |
388 |
||
389 |
version |
|
3570 | 390 |
^ '$Header$' |
2804 | 391 |
! |
392 |
||
393 |
version_CVS |
|
3570 | 394 |
^ '$Header$' |
135 | 395 |
! ! |
1710
ad35e6a18e98
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1521
diff
changeset
|
396 |
|
3570 | 397 |
|
41 | 398 |
XBMReader initialize! |