author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 06 Sep 2017 09:47:50 +0200 | |
branch | jv |
changeset 8179 | ced410b68993 |
parent 7816 | f818c6ba6334 |
child 8119 | 1778663d76cd |
child 8426 | e2051b1553f0 |
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 |
" |
|
3263 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
7275 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Image subclass:#Depth1Image |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
17 |
instanceVariableNames:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
18 |
classVariableNames:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
19 |
poolDictionaries:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
20 |
category:'Graphics-Images' |
1 | 21 |
! |
22 |
||
46 | 23 |
!Depth1Image class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 28 |
All Rights Reserved |
3 | 29 |
|
46 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
3 | 38 |
|
46 | 39 |
documentation |
40 |
" |
|
41 |
this class represents bilevel (1 bit / pixel) images. |
|
81 | 42 |
It mainly consists of methods which are already implemented in Image, |
43 |
but reimplemented here for more performance. If you plan to do heavy |
|
44 |
image processing on bilevel images, you may want to add more |
|
45 |
specialized methods here. |
|
611 | 46 |
|
798 | 47 |
#blackIs0 / #whiteIs0 and #palette formats are supported here. |
48 |
||
611 | 49 |
[author:] |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
50 |
Claus Gittinger |
611 | 51 |
|
52 |
[see also:] |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
53 |
Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
54 |
ImageReader |
46 | 55 |
" |
56 |
! ! |
|
3 | 57 |
|
89 | 58 |
!Depth1Image class methodsFor:'queries'! |
59 |
||
60 |
imageDepth |
|
579 | 61 |
"return the depth of images represented by instances of |
62 |
this class - here we return 1" |
|
63 |
||
89 | 64 |
^ 1 |
579 | 65 |
|
66 |
"Modified: 20.4.1996 / 23:40:06 / cg" |
|
89 | 67 |
! ! |
68 |
||
3263 | 69 |
!Depth1Image methodsFor:'accessing-pixels'! |
1 | 70 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
71 |
pixelAtX:x y:y |
7521 | 72 |
"retrieve a pixelValue at x/y; return a pixel value. |
279 | 73 |
The interpretation of the returned value depends on the photometric |
74 |
and the colormap. See also Image>>atX:y:) |
|
75 |
Pixels start at 0@0 for upper left pixel, end at |
|
76 |
(width-1)@(height-1) for lower right pixel" |
|
77 |
||
3842 | 78 |
|index "{Class: SmallInteger}" |
279 | 79 |
byte "{Class: SmallInteger}" |
80 |
mask "{Class: SmallInteger}"| |
|
81 |
||
82 |
%{ /* NOCONTEXT */ |
|
83 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
84 |
OBJ b = __INST(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
85 |
OBJ w = __INST(width); |
1 | 86 |
|
7275 | 87 |
if (__bothSmallInteger(x, y) |
88 |
&& __isSmallInteger(w) |
|
89 |
&& __isByteArrayLike(b) |
|
90 |
&& (__INST(pixelFunction)==nil) ) { |
|
91 |
int _w = __intVal(w); |
|
92 |
int _y = __intVal(y); |
|
93 |
int _x = __intVal(x); |
|
94 |
unsigned _byte; |
|
95 |
int _idx; |
|
279 | 96 |
|
7275 | 97 |
_idx = ((_w + 7) >> 3) * _y + (_x >> 3); |
98 |
if ((unsigned)_idx < __byteArraySize(b)) { |
|
99 |
_byte = __ByteArrayInstPtr(b)->ba_element[_idx]; |
|
100 |
RETURN( (_byte & (0x80 >> (_x & 7))) ? __MKSMALLINT(1) : __MKSMALLINT(0) ); |
|
6303 | 101 |
} |
279 | 102 |
} |
103 |
%}. |
|
104 |
||
6303 | 105 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
106 |
||
3842 | 107 |
"/ the code below is only evaluated if the bytes-collection is |
108 |
"/ not a ByteArray, or the arguments are not integers |
|
109 |
||
110 |
index := (self bytesPerRow * y) + 1 + (x // 8). |
|
279 | 111 |
|
3842 | 112 |
"left pixel is in high bit" |
113 |
byte := bytes at:index. |
|
114 |
mask := 1 bitShift:(7 - (x \\ 8)). |
|
115 |
(byte bitAnd:mask) == 0 ifTrue:[^ 0]. |
|
116 |
^ 1 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
117 |
! |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
118 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
119 |
pixelAtX:x y:y put:aPixelValue |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
120 |
"set a pixels value at x/y to aPixelValue. |
7521 | 121 |
The interpretation of the pixelValue depends on the photometric |
122 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
123 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
124 |
x = width-1, y=height-1 for lower right pixel" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
125 |
|
3842 | 126 |
|index "{Class: SmallInteger}" |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
127 |
byte "{Class: SmallInteger}" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
128 |
mask "{Class: SmallInteger}"| |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
129 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
130 |
%{ /* NOCONTEXT */ |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
131 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
132 |
OBJ b = __INST(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
133 |
OBJ w = __INST(width); |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
134 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
135 |
if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) { |
7521 | 136 |
int _w = __intVal(w); |
137 |
int _y = __intVal(y); |
|
138 |
int _x = __intVal(x); |
|
139 |
int _idx; |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
140 |
|
7521 | 141 |
_idx = ((_w + 7) >> 3) * _y + (_x >> 3); |
142 |
if ((unsigned)_idx < __byteArraySize(b)) { |
|
143 |
if (aPixelValue == __MKSMALLINT(0)) { |
|
144 |
__ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7)); |
|
145 |
} else { |
|
146 |
__ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7)); |
|
147 |
} |
|
148 |
RETURN( self ); |
|
149 |
} |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
150 |
} |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
151 |
%}. |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
152 |
"fall back code for nonByteArray or nonInteger arguments" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
153 |
|
3842 | 154 |
index := (self bytesPerRow * y) + 1 + (x // 8). |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
155 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
156 |
"left pixel is in high bit" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
157 |
byte := bytes at:index. |
7816 | 158 |
mask := #[16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01] at:((x \\ 8) + 1). |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
159 |
aPixelValue == 0 ifTrue:[ |
7521 | 160 |
byte := byte bitAnd:(mask bitInvert) |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
161 |
] ifFalse:[ |
7521 | 162 |
byte := byte bitOr:mask |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
163 |
]. |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
164 |
bytes at:index put:byte |
279 | 165 |
! ! |
166 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
167 |
!Depth1Image methodsFor:'converting'! |
279 | 168 |
|
853 | 169 |
asFormOn:aDevice |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
170 |
"convert a monochrome image to a device form" |
279 | 171 |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
172 |
^ self anyImageAsFormOn:aDevice |
853 | 173 |
! |
174 |
||
6495 | 175 |
clearMaskedPixels |
176 |
colorMap isNil ifTrue:[ |
|
177 |
"this works only for b/w images" |
|
178 |
super clearMaskedPixels. |
|
179 |
]. |
|
180 |
! |
|
181 |
||
853 | 182 |
greyImageAsFormOn:aDevice |
183 |
"convert a greyscale image to a device form" |
|
184 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
185 |
^ self anyImageAsFormOn:aDevice |
279 | 186 |
! |
187 |
||
188 |
greyImageAsMonoFormOn:aDevice |
|
7581 | 189 |
"convert to a monochrome form - that's easy" |
279 | 190 |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
191 |
^ self anyImageAsFormOn:aDevice |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
192 |
! |
279 | 193 |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
194 |
paletteImageAsMonoFormOn:aDevice |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
195 |
"convert a palette image to a b&w monochrome device form" |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
196 |
|
810 | 197 |
|f c0 c1| |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
198 |
|
7498 | 199 |
f := Form imageForm width:width height:height fromArray:self bits onDevice:aDevice. |
810 | 200 |
c0 := self colorFromValue:0. |
201 |
c1 := self colorFromValue:1. |
|
202 |
c0 brightness > 0.5 ifTrue:[ |
|
7425 | 203 |
c0 := f whiteColor. |
810 | 204 |
] ifFalse:[ |
7425 | 205 |
c0 := f blackColor. |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
206 |
]. |
810 | 207 |
c1 brightness > 0.5 ifTrue:[ |
7425 | 208 |
c1 := f whiteColor |
810 | 209 |
] ifFalse:[ |
7425 | 210 |
c1 := f blackColor. |
810 | 211 |
]. |
212 |
f colorMap:(Array with:c0 with:c1). |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
213 |
^ f |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
214 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
215 |
"Modified: 24.4.1997 / 17:51:54 / cg" |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
216 |
! |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
217 |
|
279 | 218 |
paletteImageAsTrueColorFormOn:aDevice |
219 |
"since all devices must support monochrome images, and |
|
220 |
a 2-entry colormap is implemented by ST/X's drawForm methods, |
|
221 |
we can do this on all color devices as a palette image." |
|
222 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
223 |
^ self anyImageAsFormOn:aDevice |
810 | 224 |
|
225 |
" |
|
226 |
|i| |
|
227 |
||
228 |
i := Depth1Image |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
229 |
width:4 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
230 |
height:4 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
231 |
fromArray:#[ 2r00000000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
232 |
2r11110000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
233 |
2r01010000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
234 |
2r10100000 ]. |
810 | 235 |
i photometric:#rgb. |
236 |
i samplesPerPixel:3. |
|
237 |
i bitsPerSample:#(1 0 0). |
|
238 |
||
239 |
i := i magnifiedBy:30. |
|
240 |
i inspect. |
|
241 |
" |
|
242 |
||
853 | 243 |
"Modified: 14.6.1996 / 15:21:37 / cg" |
81 | 244 |
! ! |
245 |
||
89 | 246 |
!Depth1Image methodsFor:'enumerating'! |
81 | 247 |
|
798 | 248 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1 | 249 |
"perform aBlock for each pixel from x1 to x2 in row y. |
250 |
The block is passed the color at each pixel. |
|
251 |
This method allows slighly faster processing of an |
|
252 |
image than using atX:y:, since some processing can be |
|
253 |
avoided when going from pixel to pixel. However, for |
|
254 |
real image processing, specialized methods should be written." |
|
255 |
||
256 |
|srcIndex "{ Class: SmallInteger }" |
|
257 |
byte "{ Class: SmallInteger }" |
|
258 |
mask "{ Class: SmallInteger }" |
|
259 |
x1 "{ Class: SmallInteger }" |
|
260 |
x2 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
261 |
color0 color1 |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
262 |
bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
263 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
264 |
bytes := self bits. |
1 | 265 |
|
266 |
x1 := xLow. |
|
267 |
x2 := xHigh. |
|
268 |
srcIndex := (self bytesPerRow * y) + 1. |
|
269 |
||
270 |
"left pixel is in high bit" |
|
271 |
||
2226 | 272 |
color0 := self colorFromValue:0. |
273 |
color1 := self colorFromValue:1. |
|
1 | 274 |
|
275 |
srcIndex := srcIndex + (x1 // 8). |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
276 |
mask := #[2r10000000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
277 |
2r01000000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
278 |
2r00100000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
279 |
2r00010000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
280 |
2r00001000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
281 |
2r00000100 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
282 |
2r00000010 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
283 |
2r00000001] at:((x1 \\ 8) + 1). |
1 | 284 |
|
798 | 285 |
byte := bytes at:srcIndex. |
1 | 286 |
x1 to:x2 do:[:x | |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
287 |
(byte bitAnd:mask) == 0 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
288 |
aBlock value:x value:color0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
289 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
290 |
aBlock value:x value:color1 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
291 |
]. |
1 | 292 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
293 |
mask := mask bitShift:-1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
294 |
mask == 0 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
295 |
mask := 2r10000000. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
296 |
srcIndex := srcIndex + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
297 |
x < x2 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
298 |
byte := bytes at:srcIndex. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
299 |
] |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
300 |
] |
1 | 301 |
] |
798 | 302 |
|
303 |
"Created: 7.6.1996 / 19:12:26 / cg" |
|
810 | 304 |
"Modified: 10.6.1996 / 10:33:06 / cg" |
46 | 305 |
! |
306 |
||
798 | 307 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
279 | 308 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
309 |
The block is passed the color at each pixel. |
|
310 |
This method allows slighly faster processing of an |
|
311 |
image than using atX:y:, since some processing can be |
|
312 |
avoided when going from pixel to pixel. However, for |
|
313 |
real image processing, specialized methods should be written." |
|
1 | 314 |
|
279 | 315 |
|srcIndex "{ Class: SmallInteger }" |
316 |
byte "{ Class: SmallInteger }" |
|
317 |
mask "{ Class: SmallInteger }" |
|
318 |
x1 "{ Class: SmallInteger }" |
|
319 |
x2 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
320 |
bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
321 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
322 |
bytes := self bits. |
82 | 323 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
324 |
"this method needs more tuning, if used heavily |
279 | 325 |
(fetch 8 bits at once, unroll the loop over these 8 pixels)" |
82 | 326 |
|
279 | 327 |
x1 := xLow. |
328 |
x2 := xHigh. |
|
329 |
srcIndex := (self bytesPerRow * y) + 1. |
|
330 |
||
331 |
"left pixel is in high bit" |
|
82 | 332 |
|
279 | 333 |
srcIndex := srcIndex + (x1 // 8). |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
334 |
mask := #[2r10000000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
335 |
2r01000000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
336 |
2r00100000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
337 |
2r00010000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
338 |
2r00001000 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
339 |
2r00000100 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
340 |
2r00000010 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
341 |
2r00000001] at:((x1 \\ 8) + 1). |
193 | 342 |
|
798 | 343 |
byte := bytes at:srcIndex. |
279 | 344 |
x1 to:x2 do:[:x | |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
345 |
(byte bitAnd:mask) == 0 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
346 |
aBlock value:x value:0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
347 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
348 |
aBlock value:x value:1 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
349 |
]. |
193 | 350 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
351 |
mask := mask bitShift:-1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
352 |
mask == 0 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
353 |
mask := 2r10000000. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
354 |
srcIndex := srcIndex + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
355 |
x < x2 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
356 |
byte := bytes at:srcIndex. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
357 |
] |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
358 |
] |
279 | 359 |
] |
798 | 360 |
|
361 |
"Created: 7.6.1996 / 19:09:38 / cg" |
|
806 | 362 |
"Modified: 8.6.1996 / 13:36:37 / cg" |
82 | 363 |
! ! |
364 |
||
1 | 365 |
!Depth1Image methodsFor:'magnification'! |
366 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
367 |
hardMagnifiedBy:scalePoint |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
368 |
"return a new image magnified by scalePoint, aPoint. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
369 |
This is the general magnification method, handling non-integral values. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
370 |
It is slower than the integral magnification method." |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
371 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
372 |
|mX |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
373 |
mY |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
374 |
newWidth "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
375 |
newHeight "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
376 |
newImage newBits bitsPerPixel newBytesPerRow |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
377 |
newMask |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
378 |
bytes| |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
379 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
380 |
bytes := self bits. |
2988 | 381 |
bytes isNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
382 |
self error:'cannot magnify image without bits'. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
383 |
^ self |
2988 | 384 |
]. |
385 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
386 |
mX := scalePoint x. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
387 |
mY := scalePoint y. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
388 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
389 |
newWidth := (width * mX) truncated. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
390 |
newHeight := (height * mY) truncated. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
391 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
392 |
bitsPerPixel := self depth. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
393 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
394 |
newBits := ByteArray new:(newBytesPerRow * newHeight). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
395 |
|
1577 | 396 |
mask notNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
397 |
newMask := (mask magnifiedBy:scalePoint) |
1577 | 398 |
]. |
399 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
400 |
newImage := self species new. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
401 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
402 |
newImage |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
403 |
width:newWidth |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
404 |
height:newHeight |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
405 |
photometric:photometric |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
406 |
samplesPerPixel:samplesPerPixel |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
407 |
bitsPerSample:bitsPerSample |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
408 |
colorMap:colorMap copy |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
409 |
bits:newBits |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
410 |
mask:newMask. |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
411 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
412 |
"walk over destination image fetching pixels from source image" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
413 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
414 |
mX := mX asFloat. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
415 |
mY := mY asFloat. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
416 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
417 |
%{ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
418 |
{ |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
419 |
OBJ b1 = bytes; |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
420 |
int _w1 = __intVal(__INST(width)); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
421 |
int _y1, _y2; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
422 |
OBJ b2 = newBits; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
423 |
int _w2 = __intVal(newWidth); |
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
424 |
int _h2 = __intVal(newHeight); |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
425 |
int _x2, _x1; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
426 |
int _idx2; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
427 |
unsigned _byte; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
428 |
double _mY = __floatVal(mY); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
429 |
double _mX = __floatVal(mX); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
430 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
431 |
for (_y2 = 0; _y2 < _h2; _y2++) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
432 |
_y1 = (int)( (double)_y2 / _mY); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
433 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
434 |
for (_x2 = 0; _x2 < _w2; _x2++) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
435 |
_x1 = (int)( (double)_x2 / _mX); |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
436 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
437 |
_byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)]; |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
438 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
439 |
if ((_byte & (0x80 >> (_x1 % 8)))) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
440 |
_idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
441 |
__ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
442 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
443 |
} |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
444 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
445 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
446 |
%}. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
447 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
448 |
"/ w := newWidth - 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
449 |
"/ h := newHeight - 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
450 |
"/ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
451 |
"/ 0 to:h do:[:row | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
452 |
"/ dstRow := row. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
453 |
"/ srcRow := (row // mY). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
454 |
"/ 0 to:w do:[:col | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
455 |
"/ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
456 |
"/ dstCol := col. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
457 |
"/ srcCol := col // mX. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
458 |
"/ value := self valueAtX:(col // mX) y:srcRow. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
459 |
"/ newImage atX:col y:row putValue:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
460 |
"/ ] |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
461 |
"/ ]. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
462 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
463 |
^ newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
464 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
465 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
466 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
467 |
"Created: 18.6.1996 / 16:04:26 / cg" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
468 |
! |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
469 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
470 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
471 |
into:dstBytes offset:dstStart factor:mX |
1 | 472 |
|
81 | 473 |
"magnify a single pixel row - can only magnify by integer factors. |
474 |
This method has been specially tuned for magnification by 2 and 4." |
|
1 | 475 |
|
476 |
%{ |
|
477 |
unsigned char *srcP, *dstP; |
|
478 |
int _mag; |
|
479 |
REGISTER int i; |
|
480 |
REGISTER unsigned char _byte; |
|
481 |
int _pixels, bpr; |
|
482 |
REGISTER int outcnt, bits, bit, mask, incnt; |
|
483 |
int shift; |
|
484 |
unsigned char byte1, byte2, byte3, byte4; |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
485 |
OBJ w = __INST(width); |
1 | 486 |
|
487 |
/* helper for monochrome magnification by 2 */ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
488 |
static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
489 |
0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff}; |
1 | 490 |
|
97 | 491 |
if (__bothSmallInteger(srcStart, dstStart) |
492 |
&& __bothSmallInteger(w, mX) |
|
5482
d81219e58155
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4773
diff
changeset
|
493 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
494 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
495 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
496 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
497 |
_pixels = __intVal(w); |
1 | 498 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
499 |
switch (_mag) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
500 |
case 1: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
501 |
break; |
1 | 502 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
503 |
case 2: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
504 |
/* tuned for this common case */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
505 |
while (_pixels > 4) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
506 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
507 |
*dstP++ = mag1[ _byte >> 4 ]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
508 |
*dstP++ = mag1[ _byte & 0x0F ]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
509 |
_pixels -= 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
510 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
511 |
while (_pixels > 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
512 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
513 |
*dstP++ = mag1[ _byte >> 4 ]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
514 |
_pixels -= 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
515 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
516 |
break; |
1 | 517 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
518 |
case 4: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
519 |
/* tuned for this common case */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
520 |
while (_pixels > 6) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
521 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
522 |
byte1 = mag1[_byte >> 4]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
523 |
byte2 = mag1[byte1 & 0xF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
524 |
byte1 = mag1[byte1 >> 4]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
525 |
byte3 = mag1[ _byte & 0x0F ]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
526 |
byte4 = mag1[byte3 & 0xF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
527 |
byte3 = mag1[byte3 >> 4]; |
3842 | 528 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
529 |
*dstP++ = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
530 |
*dstP++ = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
531 |
*dstP++ = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
532 |
*dstP++ = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
533 |
_pixels -= 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
534 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
535 |
while (_pixels > 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
536 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
537 |
byte1 = mag1[_byte >> 4]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
538 |
byte2 = mag1[byte1 & 0xF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
539 |
byte1 = mag1[byte1 >> 4]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
540 |
byte3 = mag1[_byte & 0x0F ]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
541 |
byte4 = mag1[byte3 & 0xF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
542 |
byte3 = mag1[byte3 >> 4]; |
1 | 543 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
544 |
*dstP++ = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
545 |
if (_pixels > 2) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
546 |
*dstP++ = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
547 |
if (_pixels > 4) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
548 |
*dstP++ = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
549 |
if (_pixels > 6) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
550 |
*dstP++ = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
551 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
552 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
553 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
554 |
_pixels -= 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
555 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
556 |
break; |
1 | 557 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
558 |
default: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
559 |
bits = 0, incnt = 0, outcnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
560 |
mask = 0x80; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
561 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
562 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
563 |
if (_byte & mask) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
564 |
bit = 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
565 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
566 |
bit = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
567 |
incnt++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
568 |
if (incnt == 8) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
569 |
incnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
570 |
mask = 0x80; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
571 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
572 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
573 |
mask >>= 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
574 |
} |
1 | 575 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
576 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
577 |
bits = (bits << 1) | bit; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
578 |
outcnt++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
579 |
if (outcnt == 8) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
580 |
*dstP++ = bits; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
581 |
bits = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
582 |
outcnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
583 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
584 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
585 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
586 |
if (outcnt) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
587 |
*dstP = bits << (8-outcnt); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
588 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
589 |
break; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
590 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
591 |
RETURN (self); |
1 | 592 |
} |
81 | 593 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
594 |
super |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
595 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
596 |
into:dstBytes offset:dstStart factor:mX |
1 | 597 |
! ! |
279 | 598 |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
599 |
!Depth1Image methodsFor:'private'! |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
600 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
601 |
anyImageAsFormOn:aDevice |
6380 | 602 |
"convert a 1-bit (possibly monochrome) image to a device form" |
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
603 |
|
6482 | 604 |
|form color0 color1| |
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
605 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
606 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
607 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
608 |
color0 := (self colorFromValue:0) exactOn:aDevice. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
609 |
color1 := (self colorFromValue:1) exactOn:aDevice. |
6380 | 610 |
(color0 isNil or:[color1 isNil]) ifTrue:[ |
611 |
"could not allocate colors, do it the hard way ..." |
|
612 |
^ self paletteImageAsFormOn:aDevice. |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
613 |
]. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
614 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
615 |
"all colors are available, this is easy now" |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
616 |
|
7498 | 617 |
form := Form imageForm onDevice:aDevice. |
6482 | 618 |
form notNil ifTrue:[ |
619 |
form |
|
620 |
colorMap:(Array with:color0 with:color1); |
|
7498 | 621 |
width:width height:height fromArray:self bits; |
622 |
forgetBits. |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
623 |
|
6380 | 624 |
"/ remember deviceForm |
625 |
(device isNil or:[deviceForm isNil]) ifTrue:[ |
|
626 |
device := aDevice. |
|
6482 | 627 |
deviceForm := form. |
6380 | 628 |
maskedPixelsAre0 := nil. |
6381 | 629 |
]. |
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
630 |
]. |
6482 | 631 |
^ form |
4767 | 632 |
|
633 |
"Modified: / 29-05-2007 / 19:32:09 / cg" |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
634 |
! ! |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
635 |
|
279 | 636 |
!Depth1Image methodsFor:'queries'! |
637 |
||
638 |
bitsPerPixel |
|
639 |
"return the number of bits per pixel" |
|
640 |
||
641 |
^ 1 |
|
642 |
! |
|
643 |
||
644 |
bitsPerRow |
|
645 |
"return the number of bits in one scanline of the image" |
|
646 |
||
3868 | 647 |
^ width |
279 | 648 |
! |
649 |
||
650 |
bytesPerRow |
|
651 |
"return the number of bytes in one scanline of the image" |
|
652 |
||
653 |
|nbytes| |
|
654 |
||
655 |
nbytes := width // 8. |
|
656 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
657 |
^ nbytes + 1 |
|
658 |
]. |
|
659 |
^ nbytes |
|
660 |
! |
|
661 |
||
3869 | 662 |
colorFromValue:pixelValue |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
663 |
"given a pixel value, return the corresponding color. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
664 |
Pixel values start with 0." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
665 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
666 |
photometric == #blackIs0 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
667 |
(pixelValue == 0) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
668 |
^ Color black |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
669 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
670 |
^ Color white |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
671 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
672 |
photometric == #whiteIs0 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
673 |
(pixelValue == 0) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
674 |
^ Color white |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
675 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
676 |
^ Color black |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
677 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
678 |
photometric == #palette ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
679 |
pixelValue < colorMap size ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
680 |
^ colorMap at:(pixelValue+1). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
681 |
] |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
682 |
]. |
3869 | 683 |
^ super colorFromValue:pixelValue. |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
684 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
685 |
|
4117 | 686 |
rgbFromValue:pixelValue |
687 |
"given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB). |
|
688 |
Pixel values start with 0." |
|
689 |
||
690 |
photometric == #blackIs0 ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
691 |
(pixelValue == 0) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
692 |
^ 0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
693 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
694 |
^ 16rFFFFFF |
4117 | 695 |
]. |
696 |
photometric == #whiteIs0 ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
697 |
(pixelValue == 0) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
698 |
^ 16rFFFFFF |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
699 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
700 |
^ 0 |
4117 | 701 |
]. |
702 |
photometric == #palette ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
703 |
pixelValue < colorMap size ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
704 |
^ (colorMap at:(pixelValue+1)) rgbValue |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
705 |
] |
4117 | 706 |
]. |
707 |
^ super rgbFromValue:pixelValue. |
|
708 |
! |
|
709 |
||
279 | 710 |
usedColors |
711 |
"return a collection of colors used in the receiver. |
|
2201 | 712 |
For depth1 images, we return the colorMap here, assuming all |
713 |
pixels are used ... |
|
714 |
... which is not really true - it could be all-white or all-black" |
|
279 | 715 |
|
3867 | 716 |
(photometric == #whiteIs0 or:[photometric == #blackIs0]) ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
717 |
^ Array |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
718 |
with:(Color black) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
719 |
with:(Color white). |
279 | 720 |
]. |
3867 | 721 |
photometric == #palette ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
722 |
^ colorMap |
3867 | 723 |
]. |
724 |
^ super usedColors |
|
279 | 725 |
|
726 |
" |
|
727 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
728 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
729 |
" |
|
2201 | 730 |
|
731 |
"Modified: / 28.7.1998 / 22:21:29 / cg" |
|
279 | 732 |
! |
733 |
||
734 |
usedValues |
|
4419 | 735 |
"return a collection of color values used in the receiver." |
736 |
||
737 |
|bits first| |
|
738 |
||
739 |
bits := self bits. |
|
740 |
bits isEmptyOrNil ifTrue:[^ #() ]. |
|
279 | 741 |
|
4419 | 742 |
first := bits at:1. |
7816 | 743 |
((first == 0) or:[(first == 2r11111111)]) ifFalse:[ ^ #[0 1] ]. |
2201 | 744 |
|
4419 | 745 |
bits do:[:eachByte | |
7816 | 746 |
(first bitXor:eachByte) ~~ 0 ifTrue:[ |
747 |
^ #[0 1] |
|
748 |
]. |
|
4419 | 749 |
]. |
7816 | 750 |
^ first == 0 ifTrue:[ #[0] ] ifFalse:[ #[1] ]. |
751 |
||
752 |
"Modified: / 30-01-2017 / 19:21:52 / stefan" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
753 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
754 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
755 |
valueFromColor:aColor |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
756 |
"given a color, return the corresponding pixel value. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
757 |
Non-representable colors return nil." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
758 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
759 |
|clr0 clr1| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
760 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
761 |
photometric == #whiteIs0 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
762 |
clr0 := Color white. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
763 |
clr1 := Color black. |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
764 |
] ifFalse:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
765 |
photometric == #blackIs0 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
766 |
clr0 := Color black. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
767 |
clr1 := Color white. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
768 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
769 |
photometric ~~ #palette ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
770 |
^ super valueFromColor:aColor |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
771 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
772 |
clr0 := colorMap at:1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
773 |
clr1 := colorMap at:2 ifAbsent:nil. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
774 |
] |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
775 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
776 |
aColor = clr0 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
777 |
^ 0. |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
778 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
779 |
aColor = clr1 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5482
diff
changeset
|
780 |
^ 1 |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
781 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
782 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
783 |
" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
784 |
the color is not in the images colormap |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
785 |
" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
786 |
^ nil |
279 | 787 |
! ! |
788 |
||
789 |
!Depth1Image class methodsFor:'documentation'! |
|
790 |
||
791 |
version |
|
7275 | 792 |
^ '$Header$' |
5482
d81219e58155
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4773
diff
changeset
|
793 |
! |
d81219e58155
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4773
diff
changeset
|
794 |
|
d81219e58155
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4773
diff
changeset
|
795 |
version_CVS |
7275 | 796 |
^ '$Header$' |
279 | 797 |
! ! |
6303 | 798 |