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