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