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