author | Claus Gittinger <cg@exept.de> |
Thu, 30 Jul 1998 15:08:37 +0200 | |
changeset 2208 | eb1122c8d556 |
parent 2201 | 7272763312a0 |
child 2211 | 81f63e913adc |
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)). |
2208
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
267 |
|
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
268 |
device isNil ifTrue:[ |
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
269 |
deviceForm isNil ifTrue:[ |
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
270 |
device := aDevice. |
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
271 |
deviceForm := f. |
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
272 |
] |
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
273 |
] |
1 | 274 |
]. |
279 | 275 |
^ f |
853 | 276 |
|
2208
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
277 |
"Created: / 14.6.1996 / 15:20:00 / cg" |
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
278 |
"Modified: / 30.7.1998 / 14:42:46 / cg" |
853 | 279 |
! |
280 |
||
281 |
greyImageAsFormOn:aDevice |
|
282 |
"convert a greyscale image to a device form" |
|
283 |
||
284 |
^ self asFormOn:aDevice |
|
285 |
||
286 |
"Modified: 14.6.1996 / 15:21:04 / cg" |
|
279 | 287 |
! |
288 |
||
289 |
greyImageAsMonoFormOn:aDevice |
|
290 |
"convert to a monochrome form - thats easy" |
|
291 |
||
853 | 292 |
^ self asFormOn:aDevice |
293 |
||
294 |
"Modified: 14.6.1996 / 15:21:09 / cg" |
|
279 | 295 |
! ! |
296 |
||
297 |
!Depth1Image methodsFor:'converting palette images'! |
|
298 |
||
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
299 |
paletteImageAsMonoFormOn:aDevice |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
300 |
"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
|
301 |
|
810 | 302 |
|f c0 c1| |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
303 |
|
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
304 |
f := Form width:width height:height fromArray:bytes on:aDevice. |
810 | 305 |
c0 := self colorFromValue:0. |
306 |
c1 := self colorFromValue:1. |
|
307 |
c0 brightness > 0.5 ifTrue:[ |
|
308 |
c0 := Color white |
|
309 |
] ifFalse:[ |
|
310 |
c0 := Color black. |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
311 |
]. |
810 | 312 |
c1 brightness > 0.5 ifTrue:[ |
313 |
c1 := Color white |
|
314 |
] ifFalse:[ |
|
315 |
c1 := Color black. |
|
316 |
]. |
|
317 |
f colorMap:(Array with:c0 with:c1). |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
318 |
^ f |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
319 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
320 |
"Modified: 24.4.1997 / 17:51:54 / cg" |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
321 |
! |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
322 |
|
279 | 323 |
paletteImageAsPseudoFormOn:aDevice |
324 |
"return a pseudo-deviceForm from the palette image." |
|
325 |
||
853 | 326 |
^ self asFormOn:aDevice |
279 | 327 |
|
853 | 328 |
"Modified: 14.6.1996 / 15:21:33 / cg" |
279 | 329 |
! |
330 |
||
331 |
paletteImageAsTrueColorFormOn:aDevice |
|
332 |
"since all devices must support monochrome images, and |
|
333 |
a 2-entry colormap is implemented by ST/X's drawForm methods, |
|
334 |
we can do this on all color devices as a palette image." |
|
335 |
||
853 | 336 |
^ self asFormOn:aDevice |
810 | 337 |
|
338 |
" |
|
339 |
|i| |
|
340 |
||
341 |
i := Depth1Image |
|
342 |
width:4 |
|
343 |
height:4 |
|
344 |
fromArray:#[ 2r00000000 |
|
345 |
2r11110000 |
|
346 |
2r01010000 |
|
347 |
2r10100000 ]. |
|
348 |
i photometric:#rgb. |
|
349 |
i samplesPerPixel:3. |
|
350 |
i bitsPerSample:#(1 0 0). |
|
351 |
||
352 |
i := i magnifiedBy:30. |
|
353 |
i inspect. |
|
354 |
" |
|
355 |
||
853 | 356 |
"Modified: 14.6.1996 / 15:21:37 / cg" |
81 | 357 |
! ! |
358 |
||
89 | 359 |
!Depth1Image methodsFor:'enumerating'! |
81 | 360 |
|
798 | 361 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1 | 362 |
"perform aBlock for each pixel from x1 to x2 in row y. |
363 |
The block is passed the color at each pixel. |
|
364 |
This method allows slighly faster processing of an |
|
365 |
image than using atX:y:, since some processing can be |
|
366 |
avoided when going from pixel to pixel. However, for |
|
367 |
real image processing, specialized methods should be written." |
|
368 |
||
369 |
|srcIndex "{ Class: SmallInteger }" |
|
370 |
byte "{ Class: SmallInteger }" |
|
371 |
mask "{ Class: SmallInteger }" |
|
372 |
x1 "{ Class: SmallInteger }" |
|
373 |
x2 "{ Class: SmallInteger }" |
|
805 | 374 |
color0 color1| |
1 | 375 |
|
376 |
x1 := xLow. |
|
377 |
x2 := xHigh. |
|
378 |
srcIndex := (self bytesPerRow * y) + 1. |
|
379 |
||
380 |
"left pixel is in high bit" |
|
381 |
||
382 |
photometric == #whiteIs0 ifTrue:[ |
|
798 | 383 |
color0 := Color white. |
384 |
color1 := Color black |
|
1 | 385 |
] ifFalse:[ |
798 | 386 |
photometric == #blackIs0 ifTrue:[ |
387 |
color0 := Color black. |
|
388 |
color1 := Color white |
|
389 |
] ifFalse:[ |
|
390 |
photometric == #palette ifTrue:[ |
|
391 |
color0 := colorMap at:1. |
|
392 |
color1 := colorMap at:2 |
|
393 |
] ifFalse:[ |
|
810 | 394 |
color0 := self colorFromValue:0. |
395 |
color1 := self colorFromValue:1. |
|
798 | 396 |
] |
397 |
] |
|
1 | 398 |
]. |
399 |
||
400 |
srcIndex := srcIndex + (x1 // 8). |
|
12 | 401 |
mask := #[2r10000000 |
798 | 402 |
2r01000000 |
403 |
2r00100000 |
|
404 |
2r00010000 |
|
405 |
2r00001000 |
|
406 |
2r00000100 |
|
407 |
2r00000010 |
|
408 |
2r00000001] at:((x1 \\ 8) + 1). |
|
1 | 409 |
|
798 | 410 |
byte := bytes at:srcIndex. |
1 | 411 |
x1 to:x2 do:[:x | |
798 | 412 |
(byte bitAnd:mask) == 0 ifTrue:[ |
413 |
aBlock value:x value:color0 |
|
414 |
] ifFalse:[ |
|
415 |
aBlock value:x value:color1 |
|
416 |
]. |
|
1 | 417 |
|
798 | 418 |
mask := mask bitShift:-1. |
419 |
mask == 0 ifTrue:[ |
|
420 |
mask := 2r10000000. |
|
421 |
srcIndex := srcIndex + 1. |
|
806 | 422 |
x < x2 ifTrue:[ |
798 | 423 |
byte := bytes at:srcIndex. |
424 |
] |
|
425 |
] |
|
1 | 426 |
] |
798 | 427 |
|
428 |
"Created: 7.6.1996 / 19:12:26 / cg" |
|
810 | 429 |
"Modified: 10.6.1996 / 10:33:06 / cg" |
46 | 430 |
! |
431 |
||
798 | 432 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
279 | 433 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
434 |
The block is passed the color at each pixel. |
|
435 |
This method allows slighly faster processing of an |
|
436 |
image than using atX:y:, since some processing can be |
|
437 |
avoided when going from pixel to pixel. However, for |
|
438 |
real image processing, specialized methods should be written." |
|
1 | 439 |
|
279 | 440 |
|srcIndex "{ Class: SmallInteger }" |
441 |
byte "{ Class: SmallInteger }" |
|
442 |
mask "{ Class: SmallInteger }" |
|
443 |
x1 "{ Class: SmallInteger }" |
|
444 |
x2 "{ Class: SmallInteger }" |
|
445 |
pixelValue| |
|
82 | 446 |
|
279 | 447 |
"this method needs more tuning, if used heavily |
448 |
(fetch 8 bits at once, unroll the loop over these 8 pixels)" |
|
82 | 449 |
|
279 | 450 |
x1 := xLow. |
451 |
x2 := xHigh. |
|
452 |
srcIndex := (self bytesPerRow * y) + 1. |
|
453 |
||
454 |
"left pixel is in high bit" |
|
82 | 455 |
|
279 | 456 |
srcIndex := srcIndex + (x1 // 8). |
457 |
mask := #[2r10000000 |
|
798 | 458 |
2r01000000 |
459 |
2r00100000 |
|
460 |
2r00010000 |
|
461 |
2r00001000 |
|
462 |
2r00000100 |
|
463 |
2r00000010 |
|
464 |
2r00000001] at:((x1 \\ 8) + 1). |
|
193 | 465 |
|
798 | 466 |
byte := bytes at:srcIndex. |
279 | 467 |
x1 to:x2 do:[:x | |
798 | 468 |
(byte bitAnd:mask) == 0 ifTrue:[ |
469 |
aBlock value:x value:0 |
|
470 |
] ifFalse:[ |
|
471 |
aBlock value:x value:1 |
|
472 |
]. |
|
193 | 473 |
|
798 | 474 |
mask := mask bitShift:-1. |
475 |
mask == 0 ifTrue:[ |
|
476 |
mask := 2r10000000. |
|
477 |
srcIndex := srcIndex + 1. |
|
806 | 478 |
x < x2 ifTrue:[ |
798 | 479 |
byte := bytes at:srcIndex. |
480 |
] |
|
481 |
] |
|
279 | 482 |
] |
798 | 483 |
|
484 |
"Created: 7.6.1996 / 19:09:38 / cg" |
|
806 | 485 |
"Modified: 8.6.1996 / 13:36:37 / cg" |
82 | 486 |
! ! |
487 |
||
1 | 488 |
!Depth1Image methodsFor:'magnification'! |
489 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
490 |
hardMagnifiedBy:scalePoint |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
491 |
"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
|
492 |
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
|
493 |
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
|
494 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
495 |
|mX |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
496 |
mY |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
497 |
newWidth "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
498 |
newHeight "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
499 |
w "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
500 |
h "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
501 |
newImage newBits bitsPerPixel newBytesPerRow |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
502 |
value srcRow srcCol |
1577 | 503 |
dstBytes dstRow dstCol newMask| |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
504 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
505 |
mX := scalePoint x. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
506 |
mY := scalePoint y. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
507 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
508 |
newWidth := (width * mX) truncated. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
509 |
newHeight := (height * mY) truncated. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
510 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
511 |
bitsPerPixel := self depth. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
512 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
513 |
newBits := ByteArray new:(newBytesPerRow * newHeight). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
514 |
|
1577 | 515 |
mask notNil ifTrue:[ |
516 |
newMask := (mask magnifiedBy:scalePoint) |
|
517 |
]. |
|
518 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
519 |
newImage := self species new. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
520 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
521 |
newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
522 |
width:newWidth |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
523 |
height:newHeight |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
524 |
photometric:photometric |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
525 |
samplesPerPixel:samplesPerPixel |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
526 |
bitsPerSample:bitsPerSample |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
527 |
colorMap:colorMap copy |
1577 | 528 |
bits:newBits |
529 |
mask:newMask. |
|
886
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 |
"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
|
532 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
533 |
mX := mX asFloat. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
534 |
mY := mY asFloat. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
535 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
536 |
%{ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
537 |
{ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
538 |
OBJ b1 = __INST(bytes); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
539 |
int _w1 = __intVal(__INST(width)); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
540 |
int _y1, _y2; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
541 |
OBJ b2 = newBits; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
542 |
int _w2 = __intVal(newWidth); |
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
543 |
int _h2 = __intVal(newHeight); |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
544 |
int _x2, _x1; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
545 |
int _idx2; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
546 |
unsigned _byte; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
547 |
double _mY = __floatVal(mY); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
548 |
double _mX = __floatVal(mX); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
549 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
550 |
for (_y2 = 0; _y2 < _h2; _y2++) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
551 |
_y1 = (int)( (double)_y2 / _mY); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
552 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
553 |
for (_x2 = 0; _x2 < _w2; _x2++) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
554 |
_x1 = (int)( (double)_x2 / _mX); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
555 |
|
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1655
diff
changeset
|
556 |
_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
|
557 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
558 |
if ((_byte & (0x80 >> (_x1 % 8)))) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
559 |
_idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8); |
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1655
diff
changeset
|
560 |
__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
|
561 |
} |
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 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
564 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
565 |
%}. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
566 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
567 |
"/ w := newWidth - 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
568 |
"/ h := newHeight - 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
569 |
"/ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
570 |
"/ 0 to:h do:[:row | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
571 |
"/ dstRow := row. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
572 |
"/ srcRow := (row // mY). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
573 |
"/ 0 to:w do:[:col | |
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 |
"/ dstCol := col. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
576 |
"/ srcCol := col // mX. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
577 |
"/ 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
|
578 |
"/ 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
|
579 |
"/ ] |
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 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
582 |
^ newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
583 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
584 |
"((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
|
585 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
586 |
"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
|
587 |
! |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
588 |
|
1 | 589 |
magnifyRowFrom:srcBytes offset:srcStart |
2179 | 590 |
into:dstBytes offset:dstStart factor:mX |
1 | 591 |
|
81 | 592 |
"magnify a single pixel row - can only magnify by integer factors. |
593 |
This method has been specially tuned for magnification by 2 and 4." |
|
1 | 594 |
|
595 |
%{ |
|
596 |
unsigned char *srcP, *dstP; |
|
597 |
int _mag; |
|
598 |
REGISTER int i; |
|
599 |
REGISTER unsigned char _byte; |
|
600 |
int _pixels, bpr; |
|
601 |
REGISTER int outcnt, bits, bit, mask, incnt; |
|
602 |
int shift; |
|
603 |
unsigned char byte1, byte2, byte3, byte4; |
|
97 | 604 |
OBJ w = _INST(width); |
1 | 605 |
|
606 |
/* helper for monochrome magnification by 2 */ |
|
607 |
static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, |
|
2179 | 608 |
0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff}; |
1 | 609 |
|
97 | 610 |
if (__bothSmallInteger(srcStart, dstStart) |
611 |
&& __bothSmallInteger(w, mX) |
|
35 | 612 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
2179 | 613 |
_mag = __intVal(mX); |
614 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
|
615 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
|
616 |
_pixels = __intVal(w); |
|
1 | 617 |
|
2179 | 618 |
switch (_mag) { |
619 |
case 1: |
|
620 |
break; |
|
1 | 621 |
|
2179 | 622 |
case 2: |
623 |
/* tuned for this common case */ |
|
624 |
while (_pixels > 0) { |
|
625 |
_byte = *srcP++; |
|
626 |
*dstP++ = mag1[ _byte >> 4 ]; |
|
627 |
if (_pixels > 4) { |
|
628 |
*dstP++ = mag1[ _byte & 0x0F ]; |
|
629 |
} |
|
630 |
_pixels -= 8; |
|
631 |
} |
|
632 |
break; |
|
1 | 633 |
|
2179 | 634 |
case 4: |
635 |
/* tuned for this common case */ |
|
636 |
while (_pixels > 0) { |
|
637 |
_byte = *srcP++; |
|
638 |
byte1 = mag1[_byte >> 4]; |
|
639 |
byte2 = mag1[byte1 & 0xF]; |
|
640 |
byte1 = mag1[byte1 >> 4]; |
|
641 |
byte3 = mag1[ _byte & 0x0F ]; |
|
642 |
byte4 = mag1[byte3 & 0xF]; |
|
643 |
byte3 = mag1[byte3 >> 4]; |
|
1 | 644 |
|
2179 | 645 |
*dstP++ = byte1; |
646 |
if (_pixels > 2) { |
|
647 |
*dstP++ = byte2; |
|
648 |
if (_pixels > 4) { |
|
649 |
*dstP++ = byte3; |
|
650 |
if (_pixels > 6) { |
|
651 |
*dstP++ = byte4; |
|
652 |
} |
|
653 |
} |
|
654 |
} |
|
655 |
_pixels -= 8; |
|
656 |
} |
|
657 |
break; |
|
1 | 658 |
|
2179 | 659 |
default: |
660 |
bits = 0, incnt = 0, outcnt = 0; |
|
661 |
mask = 0x80; |
|
662 |
_byte = *srcP++; |
|
663 |
while (_pixels--) { |
|
664 |
if (_byte & mask) |
|
665 |
bit = 1; |
|
666 |
else |
|
667 |
bit = 0; |
|
668 |
incnt++; |
|
669 |
if (incnt == 8) { |
|
670 |
incnt = 0; |
|
671 |
mask = 0x80; |
|
672 |
_byte = *srcP++; |
|
673 |
} else { |
|
674 |
mask >>= 1; |
|
675 |
} |
|
1 | 676 |
|
2179 | 677 |
for (i=_mag; i>0; i--) { |
678 |
bits = (bits << 1) | bit; |
|
679 |
outcnt++; |
|
680 |
if (outcnt == 8) { |
|
681 |
*dstP++ = bits; |
|
682 |
bits = 0; |
|
683 |
outcnt = 0; |
|
684 |
} |
|
685 |
} |
|
686 |
} |
|
687 |
if (outcnt) { |
|
688 |
*dstP = bits << (8-outcnt); |
|
689 |
} |
|
690 |
break; |
|
691 |
} |
|
692 |
RETURN (self); |
|
1 | 693 |
} |
81 | 694 |
%}. |
1 | 695 |
self primitiveFailed |
696 |
! ! |
|
279 | 697 |
|
698 |
!Depth1Image methodsFor:'queries'! |
|
699 |
||
700 |
bitsPerPixel |
|
701 |
"return the number of bits per pixel" |
|
702 |
||
703 |
^ 1 |
|
704 |
! |
|
705 |
||
706 |
bitsPerRow |
|
707 |
"return the number of bits in one scanline of the image" |
|
708 |
||
709 |
^ width |
|
710 |
! |
|
711 |
||
712 |
bytesPerRow |
|
713 |
"return the number of bytes in one scanline of the image" |
|
714 |
||
715 |
|nbytes| |
|
716 |
||
717 |
nbytes := width // 8. |
|
718 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
719 |
^ nbytes + 1 |
|
720 |
]. |
|
721 |
^ nbytes |
|
722 |
! |
|
723 |
||
724 |
usedColors |
|
725 |
"return a collection of colors used in the receiver. |
|
2201 | 726 |
For depth1 images, we return the colorMap here, assuming all |
727 |
pixels are used ... |
|
728 |
... which is not really true - it could be all-white or all-black" |
|
279 | 729 |
|
730 |
photometric ~~ #palette ifTrue:[ |
|
2201 | 731 |
^ Array with:Color white with:Color black. |
279 | 732 |
]. |
733 |
^ colorMap |
|
734 |
||
735 |
" |
|
736 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
737 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
738 |
" |
|
2201 | 739 |
|
740 |
"Modified: / 28.7.1998 / 22:21:29 / cg" |
|
279 | 741 |
! |
742 |
||
743 |
usedValues |
|
744 |
"return a collection of color values used in the receiver. |
|
2201 | 745 |
For depth1 images, we assuming both 1- and 0-pixels are present ... |
746 |
... which is not really true - it could be all-white or all-black" |
|
279 | 747 |
|
748 |
^ #(0 1) |
|
2201 | 749 |
|
750 |
"Modified: / 28.7.1998 / 22:22:43 / cg" |
|
279 | 751 |
! ! |
752 |
||
753 |
!Depth1Image class methodsFor:'documentation'! |
|
754 |
||
755 |
version |
|
2208
eb1122c8d556
remember deviceForm in asFormOn:;
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
756 |
^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.36 1998-07-30 13:08:37 cg Exp $' |
279 | 757 |
! ! |