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