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