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