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