author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:26:07 +0200 | |
changeset 611 | e0442439a3c6 |
parent 579 | e381761190c4 |
child 798 | 31ed4a1d4b4a |
permissions | -rw-r--r-- |
3 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 3 |
All Rights Reserved |
3 | 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 |
" |
|
1 | 12 |
|
13 |
Image subclass:#Depth1Image |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
14 |
instanceVariableNames:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
15 |
classVariableNames:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
16 |
poolDictionaries:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
17 |
category:'Graphics-Images' |
1 | 18 |
! |
19 |
||
46 | 20 |
!Depth1Image class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 25 |
All Rights Reserved |
3 | 26 |
|
46 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
3 | 35 |
|
46 | 36 |
documentation |
37 |
" |
|
38 |
this class represents bilevel (1 bit / pixel) images. |
|
81 | 39 |
It mainly consists of methods which are already implemented in Image, |
40 |
but reimplemented here for more performance. If you plan to do heavy |
|
41 |
image processing on bilevel images, you may want to add more |
|
42 |
specialized methods here. |
|
611 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittinger |
|
46 |
||
47 |
[see also:] |
|
48 |
Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image |
|
49 |
ImageReader |
|
46 | 50 |
" |
51 |
! ! |
|
3 | 52 |
|
89 | 53 |
!Depth1Image class methodsFor:'queries'! |
54 |
||
55 |
imageDepth |
|
579 | 56 |
"return the depth of images represented by instances of |
57 |
this class - here we return 1" |
|
58 |
||
89 | 59 |
^ 1 |
579 | 60 |
|
61 |
"Modified: 20.4.1996 / 23:40:06 / cg" |
|
89 | 62 |
! ! |
63 |
||
81 | 64 |
!Depth1Image methodsFor:'accessing'! |
1 | 65 |
|
66 |
atX:x y:y |
|
67 |
"retrieve a pixel at x/y; return a color. |
|
68 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
69 |
x = width-1, y=height-1 for lower right pixel" |
|
70 |
||
38 | 71 |
|lineIndex "{ Class: SmallInteger }" |
72 |
byte "{ Class: SmallInteger }" |
|
73 |
shift "{ Class: SmallInteger }" |
|
89 | 74 |
value "{ Class: SmallInteger }" |
75 |
p| |
|
1 | 76 |
|
77 |
lineIndex := (self bytesPerRow * y) + 1. |
|
78 |
||
79 |
"left pixel is in high bit" |
|
80 |
byte := bytes at:(lineIndex + (x // 8)). |
|
81 |
shift := #(-7 -6 -5 -4 -3 -2 -1 0) at:((x \\ 8) + 1). |
|
82 |
value := (byte bitShift:shift) bitAnd:1. |
|
89 | 83 |
(p := photometric) == #whiteIs0 ifTrue:[ |
84 |
value := 1-value. |
|
85 |
p := #blackIs0 |
|
1 | 86 |
]. |
89 | 87 |
p == #blackIs0 ifTrue:[ |
81 | 88 |
(value == 0) ifTrue:[ |
89 |
^ Color black |
|
90 |
]. |
|
91 |
^ Color white |
|
1 | 92 |
]. |
89 | 93 |
p ~~ #palette ifTrue:[ |
81 | 94 |
self error:'format not supported'. |
95 |
^ nil |
|
1 | 96 |
]. |
38 | 97 |
value := value + 1. |
89 | 98 |
^ colorMap at:value |
1 | 99 |
! |
100 |
||
279 | 101 |
atX:x y:y put:aColor |
102 |
"set the pixel at x/y to aColor. |
|
103 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
104 |
x = width-1, y=height-1 for lower right pixel. |
|
105 |
This method checks, if it is possible to store the color |
|
106 |
in the image; i.e. for b/w images, the color MUST be black |
|
107 |
or white; for palette images it must be present in the palette." |
|
108 |
||
109 |
|clr0 clr1| |
|
110 |
||
111 |
photometric == #whiteIs0 ifTrue:[ |
|
112 |
clr0 := Color white. |
|
113 |
clr1 := Color black. |
|
114 |
] ifFalse:[ |
|
115 |
photometric == #blackIs0 ifTrue:[ |
|
116 |
clr0 := Color black. |
|
117 |
clr1 := Color white. |
|
118 |
] ifFalse:[ |
|
119 |
photometric ~~ #palette ifTrue:[ |
|
120 |
self error:'format not supported'. |
|
121 |
^ nil |
|
122 |
]. |
|
123 |
clr0 := colorMap at:1. |
|
124 |
clr1 := colorMap at:2. |
|
125 |
] |
|
126 |
]. |
|
127 |
aColor = clr0 ifTrue:[ |
|
128 |
self atX:x y:y putValue:0. |
|
129 |
^ self |
|
130 |
]. |
|
131 |
aColor = clr1 ifTrue:[ |
|
132 |
self atX:x y:y putValue:1. |
|
133 |
^ self |
|
134 |
]. |
|
135 |
" |
|
136 |
the color to be stored is not in the images colormap |
|
137 |
" |
|
138 |
self error:'invalid color' |
|
139 |
! |
|
140 |
||
1 | 141 |
atX:x y:y putValue:aPixelValue |
81 | 142 |
"set a pixels value at x/y to aPixelValue. |
1 | 143 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
144 |
x = width-1, y=height-1 for lower right pixel" |
|
145 |
||
146 |
|bytesPerRow "{Class: SmallInteger}" |
|
147 |
index "{Class: SmallInteger}" |
|
148 |
byte "{Class: SmallInteger}" |
|
149 |
mask "{Class: SmallInteger}"| |
|
150 |
||
151 |
%{ /* NOCONTEXT */ |
|
97 | 152 |
|
153 |
OBJ b = _INST(bytes); |
|
154 |
OBJ w = _INST(width); |
|
155 |
||
156 |
if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) { |
|
157 |
int _w = _intVal(w); |
|
81 | 158 |
int _y = _intVal(y); |
159 |
int _x = _intVal(x); |
|
160 |
int _idx; |
|
1 | 161 |
|
81 | 162 |
_idx = (_w + 7) / 8 * _y + (_x / 8); |
315
2abc494f0c45
_-macros replaced by __-macros
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
163 |
if (aPixelValue == __MKSMALLINT(0)) { |
97 | 164 |
_ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x % 8)); |
81 | 165 |
} else { |
97 | 166 |
_ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x % 8)); |
81 | 167 |
} |
168 |
RETURN( self ); |
|
1 | 169 |
} |
81 | 170 |
%}. |
171 |
"fall back code for nonByteArray or nonInteger arguments" |
|
172 |
||
1 | 173 |
bytesPerRow := width // 8. |
174 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
81 | 175 |
bytesPerRow := bytesPerRow + 1 |
1 | 176 |
]. |
177 |
index := (bytesPerRow * y) + 1 + (x // 8). |
|
178 |
||
179 |
"left pixel is in high bit" |
|
180 |
byte := bytes at:index. |
|
181 |
mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1). |
|
182 |
aPixelValue == 0 ifTrue:[ |
|
81 | 183 |
byte := byte bitAnd:(mask bitInvert) |
1 | 184 |
] ifFalse:[ |
81 | 185 |
byte := byte bitOr:mask |
1 | 186 |
]. |
187 |
bytes at:index put:byte |
|
188 |
! |
|
189 |
||
279 | 190 |
valueAtX:x y:y |
191 |
"retrieve a pixelValue at x/y; return a number. |
|
192 |
The interpretation of the returned value depends on the photometric |
|
193 |
and the colormap. See also Image>>atX:y:) |
|
194 |
Pixels start at 0@0 for upper left pixel, end at |
|
195 |
(width-1)@(height-1) for lower right pixel" |
|
196 |
||
197 |
|bytesPerRow "{Class: SmallInteger}" |
|
198 |
index "{Class: SmallInteger}" |
|
199 |
byte "{Class: SmallInteger}" |
|
200 |
mask "{Class: SmallInteger}"| |
|
201 |
||
202 |
%{ /* NOCONTEXT */ |
|
203 |
||
204 |
OBJ b = _INST(bytes); |
|
205 |
OBJ w = _INST(width); |
|
1 | 206 |
|
279 | 207 |
if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) { |
208 |
int _w = _intVal(w); |
|
209 |
int _y = _intVal(y); |
|
210 |
int _x = _intVal(x); |
|
211 |
unsigned _byte; |
|
212 |
||
213 |
_byte = _ByteArrayInstPtr(b)->ba_element[(_w + 7) / 8 * _y + (_x / 8)]; |
|
315
2abc494f0c45
_-macros replaced by __-macros
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
214 |
RETURN( (_byte & (0x80 >> (_x % 8))) ? __MKSMALLINT(1) : __MKSMALLINT(0) ); |
279 | 215 |
} |
216 |
%}. |
|
217 |
||
218 |
"/ the above is equivalent to: |
|
219 |
"/ (notice that the code below is evaluated if the bytes-collection is |
|
220 |
"/ not a byteArray, or the arguments are not integers) |
|
221 |
||
222 |
"/ bytesPerRow := width // 8. |
|
223 |
"/ ((width \\ 8) ~~ 0) ifTrue:[ |
|
224 |
"/ bytesPerRow := bytesPerRow + 1 |
|
225 |
"/ ]. |
|
226 |
"/ index := (bytesPerRow * y) + 1 + (x // 8). |
|
227 |
"/ |
|
228 |
"/ "left pixel is in high bit" |
|
229 |
"/ byte := bytes at:index. |
|
230 |
"/ mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1). |
|
231 |
"/ (byte bitAnd:mask) == 0 ifTrue:[^ 0]. |
|
232 |
"/ ^ 1 |
|
1 | 233 |
|
279 | 234 |
"/ since that cannot happen, we faile here |
235 |
self primitiveFailed. |
|
236 |
^ 0 |
|
237 |
! ! |
|
238 |
||
239 |
!Depth1Image methodsFor:'converting greyscale images'! |
|
240 |
||
241 |
greyImageAsFormOn:aDevice |
|
242 |
"convert a greyscale image to a device form" |
|
243 |
||
244 |
|f| |
|
245 |
||
246 |
f := Form width:width height:height fromArray:bytes on:aDevice. |
|
337
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
247 |
f notNil ifTrue:[ |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
248 |
photometric == #blackIs0 ifTrue:[ |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
249 |
f function:#xor. |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
250 |
f paint:(Color colorId:1). |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
251 |
f fillRectangleX:0 y:0 width:width height:height |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
252 |
] |
1 | 253 |
]. |
279 | 254 |
^ f |
255 |
! |
|
256 |
||
257 |
greyImageAsMonoFormOn:aDevice |
|
258 |
"convert to a monochrome form - thats easy" |
|
259 |
||
260 |
^ self greyImageAsFormOn:aDevice |
|
261 |
! ! |
|
262 |
||
263 |
!Depth1Image methodsFor:'converting palette images'! |
|
264 |
||
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
265 |
paletteImageAsMonoFormOn:aDevice |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
266 |
"convert a palette image to a device form" |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
267 |
|
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
268 |
|f| |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
269 |
|
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
270 |
f := Form width:width height:height fromArray:bytes on:aDevice. |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
271 |
f notNil ifTrue:[ |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
272 |
(colorMap at:1) brightness < (colorMap at:2) brightness ifTrue:[ |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
273 |
f function:#xor. |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
274 |
f paint:(Color colorId:1). |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
275 |
f fillRectangleX:0 y:0 width:width height:height |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
276 |
] |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
277 |
]. |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
278 |
^ f |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
279 |
|
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
280 |
"Created: 20.2.1996 / 16:26:15 / cg" |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
281 |
! |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
282 |
|
279 | 283 |
paletteImageAsPseudoFormOn:aDevice |
284 |
"return a pseudo-deviceForm from the palette image." |
|
285 |
||
286 |
|f| |
|
287 |
||
38 | 288 |
" |
279 | 289 |
this is easy, since Form already supports colorMaps |
38 | 290 |
" |
279 | 291 |
f := Form width:width height:height fromArray:bytes. |
337
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
292 |
f notNil ifTrue:[ |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
293 |
f colorMap:colorMap. |
15deeed5ac81
be tolerant if form creation fails
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
294 |
]. |
279 | 295 |
^ f |
296 |
! |
|
297 |
||
298 |
paletteImageAsTrueColorFormOn:aDevice |
|
299 |
"since all devices must support monochrome images, and |
|
300 |
a 2-entry colormap is implemented by ST/X's drawForm methods, |
|
301 |
we can do this on all color devices as a palette image." |
|
302 |
||
303 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
81 | 304 |
! ! |
305 |
||
89 | 306 |
!Depth1Image methodsFor:'enumerating'! |
81 | 307 |
|
1 | 308 |
atY:y from:xLow to:xHigh do:aBlock |
309 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
310 |
The block is passed the color at each pixel. |
|
311 |
This method allows slighly faster processing of an |
|
312 |
image than using atX:y:, since some processing can be |
|
313 |
avoided when going from pixel to pixel. However, for |
|
314 |
real image processing, specialized methods should be written." |
|
315 |
||
316 |
|srcIndex "{ Class: SmallInteger }" |
|
317 |
byte "{ Class: SmallInteger }" |
|
318 |
mask "{ Class: SmallInteger }" |
|
319 |
x1 "{ Class: SmallInteger }" |
|
320 |
x2 "{ Class: SmallInteger }" |
|
321 |
color0 color1 color| |
|
322 |
||
323 |
x1 := xLow. |
|
324 |
x2 := xHigh. |
|
325 |
srcIndex := (self bytesPerRow * y) + 1. |
|
326 |
||
327 |
"left pixel is in high bit" |
|
328 |
||
329 |
photometric == #whiteIs0 ifTrue:[ |
|
81 | 330 |
color0 := Color white. |
331 |
color1 := Color black |
|
1 | 332 |
] ifFalse:[ |
81 | 333 |
photometric == #blackIs0 ifTrue:[ |
334 |
color0 := Color black. |
|
335 |
color1 := Color white |
|
336 |
] ifFalse:[ |
|
337 |
photometric == #palette ifTrue:[ |
|
89 | 338 |
color0 := colorMap at:1. |
339 |
color1 := colorMap at:2 |
|
81 | 340 |
] ifFalse:[ |
341 |
self error:'format not supported'. |
|
342 |
^ nil |
|
343 |
] |
|
344 |
] |
|
1 | 345 |
]. |
346 |
||
347 |
srcIndex := srcIndex + (x1 // 8). |
|
12 | 348 |
mask := #[2r10000000 |
81 | 349 |
2r01000000 |
350 |
2r00100000 |
|
351 |
2r00010000 |
|
352 |
2r00001000 |
|
353 |
2r00000100 |
|
354 |
2r00000010 |
|
355 |
2r00000001] at:((x1 \\ 8) + 1). |
|
1 | 356 |
|
357 |
x1 to:x2 do:[:x | |
|
81 | 358 |
byte := bytes at:srcIndex. |
359 |
(byte bitAnd:mask) == 0 ifTrue:[ |
|
360 |
color := color0 |
|
361 |
] ifFalse:[ |
|
362 |
color := color1 |
|
363 |
]. |
|
364 |
aBlock value:x value:color. |
|
1 | 365 |
|
81 | 366 |
mask := mask bitShift:-1. |
367 |
mask == 0 ifTrue:[ |
|
368 |
mask := 2r10000000. |
|
369 |
srcIndex := srcIndex + 1 |
|
370 |
] |
|
1 | 371 |
] |
46 | 372 |
! |
373 |
||
279 | 374 |
valueAtY:y from:xLow to:xHigh do:aBlock |
375 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
376 |
The block is passed the color at each pixel. |
|
377 |
This method allows slighly faster processing of an |
|
378 |
image than using atX:y:, since some processing can be |
|
379 |
avoided when going from pixel to pixel. However, for |
|
380 |
real image processing, specialized methods should be written." |
|
1 | 381 |
|
279 | 382 |
|srcIndex "{ Class: SmallInteger }" |
383 |
byte "{ Class: SmallInteger }" |
|
384 |
mask "{ Class: SmallInteger }" |
|
385 |
x1 "{ Class: SmallInteger }" |
|
386 |
x2 "{ Class: SmallInteger }" |
|
387 |
pixelValue| |
|
82 | 388 |
|
279 | 389 |
"this method needs more tuning, if used heavily |
390 |
(fetch 8 bits at once, unroll the loop over these 8 pixels)" |
|
82 | 391 |
|
279 | 392 |
x1 := xLow. |
393 |
x2 := xHigh. |
|
394 |
srcIndex := (self bytesPerRow * y) + 1. |
|
395 |
||
396 |
"left pixel is in high bit" |
|
82 | 397 |
|
279 | 398 |
srcIndex := srcIndex + (x1 // 8). |
399 |
mask := #[2r10000000 |
|
400 |
2r01000000 |
|
401 |
2r00100000 |
|
402 |
2r00010000 |
|
403 |
2r00001000 |
|
404 |
2r00000100 |
|
405 |
2r00000010 |
|
406 |
2r00000001] at:((x1 \\ 8) + 1). |
|
193 | 407 |
|
279 | 408 |
x1 to:x2 do:[:x | |
409 |
byte := bytes at:srcIndex. |
|
410 |
(byte bitAnd:mask) == 0 ifTrue:[ |
|
411 |
pixelValue := 0 |
|
412 |
] ifFalse:[ |
|
413 |
pixelValue := 1 |
|
414 |
]. |
|
415 |
aBlock value:x value:pixelValue. |
|
193 | 416 |
|
279 | 417 |
mask := mask bitShift:-1. |
418 |
mask == 0 ifTrue:[ |
|
419 |
mask := 2r10000000. |
|
420 |
srcIndex := srcIndex + 1 |
|
421 |
] |
|
422 |
] |
|
82 | 423 |
! ! |
424 |
||
1 | 425 |
!Depth1Image methodsFor:'magnification'! |
426 |
||
427 |
magnifyRowFrom:srcBytes offset:srcStart |
|
81 | 428 |
into:dstBytes offset:dstStart factor:mX |
1 | 429 |
|
81 | 430 |
"magnify a single pixel row - can only magnify by integer factors. |
431 |
This method has been specially tuned for magnification by 2 and 4." |
|
1 | 432 |
|
433 |
%{ |
|
434 |
unsigned char *srcP, *dstP; |
|
435 |
int _mag; |
|
436 |
REGISTER int i; |
|
437 |
REGISTER unsigned char _byte; |
|
438 |
int _pixels, bpr; |
|
439 |
REGISTER int outcnt, bits, bit, mask, incnt; |
|
440 |
int shift; |
|
441 |
unsigned char byte1, byte2, byte3, byte4; |
|
97 | 442 |
OBJ w = _INST(width); |
1 | 443 |
|
444 |
/* helper for monochrome magnification by 2 */ |
|
445 |
static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, |
|
81 | 446 |
0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff}; |
1 | 447 |
|
97 | 448 |
if (__bothSmallInteger(srcStart, dstStart) |
449 |
&& __bothSmallInteger(w, mX) |
|
35 | 450 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
81 | 451 |
_mag = _intVal(mX); |
452 |
srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart); |
|
453 |
dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart); |
|
97 | 454 |
_pixels = _intVal(w); |
1 | 455 |
|
81 | 456 |
switch (_mag) { |
457 |
case 1: |
|
458 |
break; |
|
1 | 459 |
|
81 | 460 |
case 2: |
461 |
/* tuned for this common case */ |
|
462 |
while (_pixels > 0) { |
|
463 |
_byte = *srcP++; |
|
464 |
*dstP++ = mag1[ _byte >> 4 ]; |
|
465 |
if (_pixels > 4) { |
|
466 |
*dstP++ = mag1[ _byte & 0x0F ]; |
|
467 |
} |
|
468 |
_pixels -= 8; |
|
469 |
} |
|
470 |
break; |
|
1 | 471 |
|
81 | 472 |
case 4: |
473 |
/* tuned for this common case */ |
|
474 |
while (_pixels > 0) { |
|
475 |
_byte = *srcP++; |
|
476 |
byte1 = mag1[_byte >> 4]; |
|
477 |
byte2 = mag1[byte1 & 0xF]; |
|
478 |
byte1 = mag1[byte1 >> 4]; |
|
479 |
byte3 = mag1[ _byte & 0x0F ]; |
|
480 |
byte4 = mag1[byte3 & 0xF]; |
|
481 |
byte3 = mag1[byte3 >> 4]; |
|
1 | 482 |
|
81 | 483 |
*dstP++ = byte1; |
484 |
if (_pixels > 2) { |
|
485 |
*dstP++ = byte2; |
|
486 |
if (_pixels > 4) { |
|
487 |
*dstP++ = byte3; |
|
488 |
if (_pixels > 6) { |
|
489 |
*dstP++ = byte4; |
|
490 |
} |
|
491 |
} |
|
492 |
} |
|
493 |
_pixels -= 8; |
|
494 |
} |
|
495 |
break; |
|
1 | 496 |
|
81 | 497 |
default: |
498 |
bits = 0, incnt = 0, outcnt = 0; |
|
499 |
mask = 0x80; |
|
500 |
_byte = *srcP++; |
|
501 |
while (_pixels--) { |
|
502 |
if (_byte & mask) |
|
503 |
bit = 1; |
|
504 |
else |
|
505 |
bit = 0; |
|
506 |
incnt++; |
|
507 |
if (incnt == 8) { |
|
508 |
incnt = 0; |
|
509 |
mask = 0x80; |
|
510 |
_byte = *srcP++; |
|
511 |
} else { |
|
512 |
mask >>= 1; |
|
513 |
} |
|
1 | 514 |
|
81 | 515 |
for (i=_mag; i>0; i--) { |
516 |
bits = (bits << 1) | bit; |
|
517 |
outcnt++; |
|
518 |
if (outcnt == 8) { |
|
519 |
*dstP++ = bits; |
|
520 |
bits = 0; |
|
521 |
outcnt = 0; |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
break; |
|
526 |
} |
|
527 |
RETURN (self); |
|
1 | 528 |
} |
81 | 529 |
%}. |
1 | 530 |
self primitiveFailed |
531 |
! ! |
|
279 | 532 |
|
533 |
!Depth1Image methodsFor:'queries'! |
|
534 |
||
535 |
bitsPerPixel |
|
536 |
"return the number of bits per pixel" |
|
537 |
||
538 |
^ 1 |
|
539 |
! |
|
540 |
||
541 |
bitsPerRow |
|
542 |
"return the number of bits in one scanline of the image" |
|
543 |
||
544 |
^ width |
|
545 |
! |
|
546 |
||
547 |
bitsPerSample |
|
548 |
"return the number of bits per sample. |
|
549 |
The return value is an array of bits-per-plane." |
|
550 |
||
551 |
^ #(1) |
|
552 |
! |
|
553 |
||
554 |
bytesPerRow |
|
555 |
"return the number of bytes in one scanline of the image" |
|
556 |
||
557 |
|nbytes| |
|
558 |
||
559 |
nbytes := width // 8. |
|
560 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
561 |
^ nbytes + 1 |
|
562 |
]. |
|
563 |
^ nbytes |
|
564 |
! |
|
565 |
||
566 |
samplesPerPixel |
|
567 |
"return the number of samples per pixel in the image." |
|
568 |
||
569 |
^ 1 |
|
570 |
! |
|
571 |
||
572 |
usedColors |
|
573 |
"return a collection of colors used in the receiver. |
|
574 |
For depth1 images, this is very easy" |
|
575 |
||
576 |
photometric ~~ #palette ifTrue:[ |
|
577 |
^ Array with:Color white with:Color black. |
|
578 |
]. |
|
579 |
^ colorMap |
|
580 |
||
581 |
" |
|
582 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
583 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
584 |
" |
|
585 |
! |
|
586 |
||
587 |
usedValues |
|
588 |
"return a collection of color values used in the receiver. |
|
589 |
For depth1 images, this is very easy" |
|
590 |
||
591 |
^ #(0 1) |
|
592 |
! ! |
|
593 |
||
594 |
!Depth1Image class methodsFor:'documentation'! |
|
595 |
||
596 |
version |
|
611 | 597 |
^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.20 1996-04-25 16:21:18 cg Exp $' |
279 | 598 |
! ! |