author | Claus Gittinger <cg@exept.de> |
Sat, 12 Feb 2000 16:34:44 +0100 | |
changeset 3178 | 8f2b7efc4837 |
parent 2864 | dd151bfdff9d |
child 3263 | bd92a12c9316 |
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:#Depth2Image |
|
579 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Images' |
|
1 | 18 |
! |
19 |
||
46 | 20 |
!Depth2Image 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 four-color (2 bit / pixel) images |
|
39 |
(as used mainly on the NeXT). |
|
40 |
It mainly consists of methods already implemented in Image, |
|
41 |
reimplemented here for more performance. |
|
611 | 42 |
|
798 | 43 |
#blackIs0 / #whiteIs0 and #palette formats are supported here. |
44 |
||
611 | 45 |
[author:] |
46 |
Claus Gittinger |
|
47 |
||
48 |
[see also:] |
|
49 |
Depth1Image Depth4Image Depth8Image Depth16Image Depth24Image |
|
50 |
ImageReader |
|
46 | 51 |
" |
52 |
! ! |
|
3 | 53 |
|
89 | 54 |
!Depth2Image class methodsFor:'queries'! |
55 |
||
56 |
imageDepth |
|
579 | 57 |
"return the depth of images represented by instances of |
58 |
this class - here we return 2" |
|
59 |
||
89 | 60 |
^ 2 |
579 | 61 |
|
62 |
"Modified: 20.4.1996 / 23:40:12 / cg" |
|
89 | 63 |
! ! |
64 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
65 |
!Depth2Image methodsFor:'accessing - pixels'! |
1 | 66 |
|
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
67 |
colorAtX:x y:y |
1 | 68 |
"retrieve a pixel at x/y; return a color. |
69 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
70 |
x = width-1, y=height-1 for lower right pixel" |
|
71 |
||
38 | 72 |
|lineIndex "{ Class: SmallInteger }" |
73 |
byte "{ Class: SmallInteger }" |
|
74 |
shift "{ Class: SmallInteger }" |
|
89 | 75 |
value "{ Class: SmallInteger }" |
154 | 76 |
p grey| |
1 | 77 |
|
78 |
lineIndex := (self bytesPerRow * y) + 1. |
|
79 |
||
80 |
"left pixel in high bits" |
|
81 |
byte := bytes at:(lineIndex + (x // 4)). |
|
154 | 82 |
|
1 | 83 |
shift := #(-6 -4 -2 0) at:((x \\ 4) + 1). |
84 |
value := (byte bitShift:shift) bitAnd:3. |
|
89 | 85 |
p := photometric. |
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
86 |
|
89 | 87 |
p == #whiteIs0 ifTrue:[ |
746 | 88 |
value := 3 - value. |
89 |
p := #blackIs0 |
|
1 | 90 |
]. |
154 | 91 |
p == #blackIs0 ifTrue:[ |
746 | 92 |
(value == 0) ifTrue:[ |
93 |
^ Color black |
|
94 |
]. |
|
95 |
(value == 3) ifTrue:[ |
|
96 |
^ Color white |
|
97 |
]. |
|
98 |
(value == 1) ifTrue:[ |
|
99 |
grey := 33 |
|
100 |
] ifFalse:[ |
|
101 |
grey := 67 |
|
102 |
]. |
|
103 |
^ Color gray:grey |
|
1 | 104 |
]. |
105 |
photometric ~~ #palette ifTrue:[ |
|
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
106 |
^ self colorFromValue:value |
1 | 107 |
]. |
89 | 108 |
^ colorMap at:(value+1). |
746 | 109 |
|
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
110 |
"Modified: 8.6.1996 / 10:52:38 / cg" |
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
111 |
"Created: 24.4.1997 / 17:33:41 / cg" |
1 | 112 |
! |
113 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
114 |
pixelAtX:x y:y |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
115 |
"retrieve a pixel at x/y; return a pixel value. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
116 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
117 |
x = width-1, y=height-1 for lower right pixel" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
118 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
119 |
|lineIndex "{ Class: SmallInteger }" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
120 |
byte "{ Class: SmallInteger }" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
121 |
shift "{ Class: SmallInteger }" | |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
122 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
123 |
lineIndex := (self bytesPerRow * y) + 1. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
124 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
125 |
"left pixel in high bits" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
126 |
byte := bytes at:(lineIndex + (x // 4)). |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
127 |
shift := #(-6 -4 -2 0) at:((x \\ 4) + 1). |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
128 |
^ (byte bitShift:shift) bitAnd:3. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
129 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
130 |
"Created: 24.4.1997 / 16:06:39 / cg" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
131 |
! |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
132 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
133 |
pixelAtX:x y:y put:aPixelValue |
1 | 134 |
"set the pixel at x/y to aPixelValue. |
135 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
136 |
x = width-1, y=height-1 for lower right pixel" |
|
137 |
||
38 | 138 |
|lineIndex "{ Class: SmallInteger }" |
139 |
index "{ Class: SmallInteger }" |
|
140 |
byte "{ Class: SmallInteger }" |
|
141 |
shift "{ Class: SmallInteger }" | |
|
1 | 142 |
|
143 |
lineIndex := (self bytesPerRow * y) + 1. |
|
144 |
||
145 |
"left pixel is in high bits" |
|
146 |
index := lineIndex + (x // 4). |
|
147 |
byte := bytes at:index. |
|
148 |
shift := #(6 4 2 0) at:((x \\ 4) + 1). |
|
149 |
byte := (byte bitAnd:(3 bitShift:shift) bitInvert) bitOr:(aPixelValue bitShift:shift). |
|
150 |
bytes at:index put:byte |
|
151 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
152 |
"Created: 24.4.1997 / 17:06:36 / cg" |
1 | 153 |
! ! |
154 |
||
3178 | 155 |
!Depth2Image methodsFor:'converting images'! |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
156 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
157 |
anyImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
158 |
"return a true-color device-form for the receiver. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
159 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
160 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
161 |
|depth |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
162 |
colorValues |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
163 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
164 |
usedDevicePadding usedDeviceBytesPerRow padd n| |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
165 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
166 |
depth := aDevice depth. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
167 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
168 |
"/ gather r/g/b values for all colors in the map ... |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
169 |
|
2204
d58ed106b422
use common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
170 |
colorValues := self rgbColormapFor:aDevice. |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
171 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
172 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
173 |
usedDeviceDepth := bestFormat at:#depth. |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
174 |
usedDeviceDepth == 1 ifTrue:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
175 |
^ self asMonochromeFormOn:aDevice |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
176 |
]. |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
177 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
178 |
usedDevicePadding := bestFormat at:#padding. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
179 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
180 |
usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
181 |
padd := usedDeviceBytesPerRow -( self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:8). |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
182 |
imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
183 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
184 |
"/ for now, only support some depths |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
185 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
186 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
187 |
"/ 16 bits/pixel |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
188 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
189 |
"/ now, walk over the image and replace |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
190 |
"/ colorMap indices by color values in the bits array |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
191 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
192 |
%{ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
193 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
194 |
&& __isArray(colorValues) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
195 |
&& __isByteArray(_INST(bytes)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
196 |
&& __isByteArray(imageBits)) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
197 |
int r,p; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
198 |
int x, y, w, h, nPix; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
199 |
int byte, shift; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
200 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
201 |
unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
202 |
unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
203 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
204 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
205 |
w = __intVal(_INST(width)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
206 |
h = __intVal(_INST(height)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
207 |
r = 0; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
208 |
p = __intVal(padd); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
209 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
210 |
nPix = w * h; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
211 |
shift = -2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
212 |
while (nPix-- > 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
213 |
unsigned idx, v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
214 |
OBJ clr; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
215 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
216 |
if (shift < 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
217 |
byte = *srcPtr++; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
218 |
shift = 6; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
219 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
220 |
idx = (byte >> shift) & 3; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
221 |
shift -= 2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
222 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
223 |
clr = ap[idx]; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
224 |
v = __intVal(clr); |
2401 | 225 |
#ifdef __MSBFIRST |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
226 |
((short *)dstPtr)[0] = v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
227 |
#else |
2225
8fb244eaaf90
the SWAP_BYTES macro does not work yet.
Claus Gittinger <cg@exept.de>
parents:
2214
diff
changeset
|
228 |
# ifdef xxSWAP_BYTES |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
229 |
SWAP_BYTES(v); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
230 |
((short *)dstPtr)[0] = v; |
2214
452bd64584d6
use SWAP_BYTES macro, if defined
Claus Gittinger <cg@exept.de>
parents:
2204
diff
changeset
|
231 |
# else |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
232 |
dstPtr[0] = (v>>8) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
233 |
dstPtr[1] = (v) & 0xFF; |
2214
452bd64584d6
use SWAP_BYTES macro, if defined
Claus Gittinger <cg@exept.de>
parents:
2204
diff
changeset
|
234 |
# endif |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
235 |
#endif |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
236 |
dstPtr += 2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
237 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
238 |
if (++r == w) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
239 |
dstPtr += p; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
240 |
r = 0; |
2204
d58ed106b422
use common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
241 |
shift = -2; |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
242 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
243 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
244 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
245 |
%}. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
246 |
] ifFalse:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
247 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
248 |
"/ 32 bits/pixel |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
249 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
250 |
"/ now, walk over the image and replace |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
251 |
"/ colorMap indices by color values in the bits array |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
252 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
253 |
%{ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
254 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
255 |
&& __isArray(colorValues) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
256 |
&& __isByteArray(_INST(bytes)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
257 |
&& __isByteArray(imageBits)) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
258 |
int x, y, w, h, nPix; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
259 |
int r,p; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
260 |
int byte, shift; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
261 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
262 |
unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
263 |
unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
264 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
265 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
266 |
w = __intVal(_INST(width)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
267 |
h = __intVal(_INST(height)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
268 |
r = 0; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
269 |
p = __intVal(padd); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
270 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
271 |
nPix = w * h; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
272 |
shift = -2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
273 |
while (nPix > 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
274 |
unsigned idx, v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
275 |
OBJ clr; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
276 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
277 |
if (shift < 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
278 |
byte = *srcPtr++; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
279 |
shift = 6; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
280 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
281 |
idx = (byte >> shift) & 3; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
282 |
shift -= 2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
283 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
284 |
clr = ap[idx]; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
285 |
v = __intVal(clr); |
2401 | 286 |
#ifdef __MSBFIRST |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
287 |
((long *)dstPtr)[0] = v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
288 |
#else |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
289 |
dstPtr[0] = (v>>24) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
290 |
dstPtr[1] = (v>>16) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
291 |
dstPtr[2] = (v>>8) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
292 |
dstPtr[3] = (v) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
293 |
#endif |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
294 |
dstPtr += 4; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
295 |
nPix--; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
296 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
297 |
if (++r == w) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
298 |
dstPtr += p; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
299 |
r = 0; |
2204
d58ed106b422
use common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
300 |
shift = -2; |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
301 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
302 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
303 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
304 |
%}. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
305 |
] ifFalse:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
306 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
307 |
"/ 8 bits/pixel |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
308 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
309 |
"/ now, walk over the image and replace |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
310 |
"/ colorMap indices by color values in the bits array |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
311 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
312 |
%{ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
313 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
314 |
&& __isArray(colorValues) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
315 |
&& __isByteArray(_INST(bytes)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
316 |
&& __isByteArray(imageBits)) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
317 |
int x, y, w, h, nPix; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
318 |
int r,p, byte, shift; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
319 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
320 |
unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
321 |
unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
322 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
323 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
324 |
w = __intVal(_INST(width)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
325 |
h = __intVal(_INST(height)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
326 |
r = 0; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
327 |
p = __intVal(padd); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
328 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
329 |
nPix = w * h; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
330 |
shift = -2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
331 |
while (nPix > 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
332 |
unsigned idx, v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
333 |
OBJ clr; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
334 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
335 |
if (shift < 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
336 |
byte = *srcPtr++; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
337 |
shift = 6; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
338 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
339 |
idx = (byte >> shift) & 3; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
340 |
shift -= 2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
341 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
342 |
clr = ap[idx]; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
343 |
v = __intVal(clr); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
344 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
345 |
dstPtr[0] = v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
346 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
347 |
dstPtr += 1; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
348 |
nPix--; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
349 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
350 |
if (++r == w) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
351 |
dstPtr += p; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
352 |
r = 0; |
2204
d58ed106b422
use common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
353 |
shift = -2; |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
354 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
355 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
356 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
357 |
%}. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
358 |
] ifFalse:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
359 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
360 |
"/ 24 bits/pixel |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
361 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
362 |
"/ now, walk over the image and replace |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
363 |
"/ colorMap indices by color values in the bits array |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
364 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
365 |
%{ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
366 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
367 |
&& __isArray(colorValues) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
368 |
&& __isByteArray(_INST(bytes)) |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
369 |
&& __isByteArray(imageBits)) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
370 |
int x, y, w, h, nPix; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
371 |
int r, p, byte, shift; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
372 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
373 |
unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
374 |
unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
375 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
376 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
377 |
w = __intVal(_INST(width)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
378 |
h = __intVal(_INST(height)); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
379 |
r = 0; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
380 |
p = __intVal(padd); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
381 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
382 |
nPix = w * h; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
383 |
shift = -2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
384 |
while (nPix > 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
385 |
unsigned idx, v; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
386 |
OBJ clr; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
387 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
388 |
if (shift < 0) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
389 |
byte = *srcPtr++; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
390 |
shift = 6; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
391 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
392 |
idx = (byte >> shift) & 3; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
393 |
shift -= 2; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
394 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
395 |
clr = ap[idx]; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
396 |
v = __intVal(clr); |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
397 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
398 |
dstPtr[0] = (v>>16) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
399 |
dstPtr[1] = (v>>8) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
400 |
dstPtr[2] = (v) & 0xFF; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
401 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
402 |
dstPtr += 3; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
403 |
nPix--; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
404 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
405 |
if (++r == w) { |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
406 |
dstPtr += p; |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
407 |
r = 0; |
2204
d58ed106b422
use common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
408 |
shift = -2; |
2200
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
409 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
410 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
411 |
} |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
412 |
%}. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
413 |
] ifFalse:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
414 |
'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
415 |
^ nil |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
416 |
] |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
417 |
] |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
418 |
] |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
419 |
]. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
420 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
421 |
imageBits isNil ifTrue:[ |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
422 |
^ nil |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
423 |
]. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
424 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
425 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
426 |
form isNil ifTrue:[^ nil]. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
427 |
form initGC. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
428 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
429 |
form |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
430 |
copyBitsFrom:imageBits |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
431 |
bitsPerPixel:usedDeviceBitsPerPixel |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
432 |
depth:usedDeviceDepth |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
433 |
padding:usedDevicePadding |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
434 |
width:width height:height |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
435 |
x:0 y:0 |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
436 |
toX:0 y:0. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
437 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
438 |
^ form |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
439 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
440 |
"Created: 20.10.1995 / 22:05:10 / cg" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
441 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
442 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
443 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
444 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
445 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
446 |
! |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
447 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
448 |
greyImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
449 |
"return a true-color device-form for the grey-image receiver. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
450 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
451 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
452 |
|f| |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
453 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
454 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
455 |
f notNil ifTrue:[^ f]. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
456 |
^ super greyImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
457 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
458 |
"Created: / 28.7.1998 / 16:57:32 / cg" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
459 |
! |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
460 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
461 |
paletteImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
462 |
"return a true-color device-form for the palette-image receiver. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
463 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
464 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
465 |
|f| |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
466 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
467 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
468 |
f notNil ifTrue:[^ f]. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
469 |
^ super paletteImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
470 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
471 |
"Created: / 28.7.1998 / 16:57:47 / cg" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
472 |
! |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
473 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
474 |
rgbImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
475 |
"return a true-color device-form for the rgb-image receiver. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
476 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
477 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
478 |
|f| |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
479 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
480 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
481 |
f notNil ifTrue:[^ f]. |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
482 |
^ super rgbImageAsTrueColorFormOn:aDevice |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
483 |
|
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
484 |
"Created: / 28.7.1998 / 16:58:01 / cg" |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
485 |
! ! |
4e3c5b30b2c1
tuned conversion to true-color.
Claus Gittinger <cg@exept.de>
parents:
2178
diff
changeset
|
486 |
|
810 | 487 |
!Depth2Image methodsFor:'dither helpers'! |
798 | 488 |
|
489 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
490 |
"return the dithered monochrome bits for the receiver image; |
|
491 |
with a constant ditherMatrix, this can be used for thresholding. |
|
492 |
Redefined to make use of knowing that pixels are 2-bit values." |
|
493 |
||
494 |
|f dH nDither |
|
495 |
greyMap monoBits |
|
496 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
497 |
bytesPerRow "{Class: SmallInteger }" |
|
498 |
w "{Class: SmallInteger }" |
|
499 |
h "{Class: SmallInteger }"| |
|
500 |
||
501 |
nDither := ditherMatrix size. |
|
502 |
dH := nDither / dW. |
|
503 |
||
504 |
w := width. |
|
505 |
h := height. |
|
506 |
||
507 |
bytesPerRow := self bytesPerRow. |
|
508 |
||
509 |
bytesPerMonoRow := w + 7 // 8. |
|
510 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
511 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
512 |
^ nil |
|
513 |
]. |
|
514 |
||
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
515 |
greyMap := self greyByteMapForRange:nDither. |
798 | 516 |
|
517 |
%{ |
|
518 |
int __dW = __intVal(dW); |
|
519 |
int __dH = __intVal(dH); |
|
520 |
int __byte; |
|
521 |
int __dT; |
|
522 |
int __dstIdx = 0; |
|
523 |
int __srcIdx = 0; |
|
524 |
int __bitCnt; |
|
525 |
int __inByte; |
|
526 |
int __grey; |
|
527 |
int __w = __intVal(w); |
|
528 |
int __h = __intVal(h); |
|
529 |
int __x; |
|
530 |
int __y; |
|
531 |
int __oX, __oY, __dY; |
|
532 |
int __nextDst; |
|
533 |
int __nextSrc; |
|
534 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
535 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
536 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1656
diff
changeset
|
537 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
808 | 538 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
798 | 539 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
540 |
unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
|
541 |
||
542 |
__oY = __dY = 0; |
|
543 |
for (__y=0; __y<__h; __y++) { |
|
544 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
|
545 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
546 |
||
547 |
__byte = 0; |
|
548 |
__bitCnt = 8; |
|
549 |
||
550 |
__oX = 0; |
|
551 |
||
552 |
for (__x=0; __x<__w; __x++) { |
|
553 |
if ((__x & 3) == 0) { |
|
554 |
__inByte = __bytes[__srcIdx]; /* 0..255 */ |
|
555 |
__srcIdx++; |
|
556 |
} else { |
|
557 |
__inByte = __inByte << 2; |
|
558 |
} |
|
559 |
__grey = (__inByte >> 6) & 3; |
|
560 |
||
561 |
__grey = __greyMap[__grey]; |
|
562 |
__dT = __ditherMatrix[__dY + __oX]; |
|
563 |
||
564 |
__oX++; |
|
565 |
if (__oX == __dW) __oX = 0; |
|
566 |
||
567 |
__byte = __byte << 1; |
|
568 |
if (__grey > __dT) { |
|
569 |
__byte = __byte | 1; /* white */ |
|
570 |
} |
|
571 |
||
572 |
__bitCnt--; |
|
573 |
if (__bitCnt == 0) { |
|
574 |
__monoBits[__dstIdx] = __byte; |
|
575 |
__dstIdx++; |
|
576 |
__byte = 0; |
|
577 |
__bitCnt = 8; |
|
578 |
} |
|
579 |
} |
|
580 |
||
581 |
if (__bitCnt != 8) { |
|
582 |
__byte = __byte << __bitCnt; |
|
583 |
__monoBits[__dstIdx] = __byte; |
|
584 |
} |
|
585 |
||
586 |
__oY++; __dY += __dW; |
|
587 |
if (__oY == __dH) { |
|
588 |
__oY = 0; |
|
589 |
__dY = 0; |
|
590 |
} |
|
591 |
||
592 |
__srcIdx = __nextSrc; |
|
593 |
__dstIdx = __nextDst; |
|
594 |
} |
|
595 |
%}. |
|
596 |
||
597 |
^ monoBits |
|
598 |
||
599 |
||
600 |
! ! |
|
601 |
||
280 | 602 |
!Depth2Image methodsFor:'enumerating'! |
603 |
||
798 | 604 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
280 | 605 |
"perform aBlock for each pixel from x1 to x2 in row y. |
606 |
The block is passed the color at each pixel. |
|
607 |
This method allows slighly faster processing of an |
|
608 |
image than using atX:y:, since some processing can be |
|
609 |
avoided when going from pixel to pixel. However, for |
|
610 |
real image processing, specialized methods should be written." |
|
611 |
||
612 |
|srcIndex "{ Class: SmallInteger }" |
|
613 |
byte "{ Class: SmallInteger }" |
|
614 |
shift "{ Class: SmallInteger }" |
|
615 |
value "{ Class: SmallInteger }" |
|
616 |
x1 "{ Class: SmallInteger }" |
|
617 |
x2 "{ Class: SmallInteger }" |
|
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
618 |
color0 color1 color2 color3| |
280 | 619 |
|
2226 | 620 |
color0 := self colorFromValue:0. |
621 |
color1 := self colorFromValue:1. |
|
622 |
color2 := self colorFromValue:2. |
|
623 |
color3 := self colorFromValue:3. |
|
280 | 624 |
|
625 |
"left pixel in high bits" |
|
626 |
||
627 |
x1 := xLow. |
|
628 |
x2 := xHigh. |
|
629 |
||
630 |
srcIndex := (self bytesPerRow * y) + 1. |
|
631 |
srcIndex := srcIndex + (x1 // 4). |
|
632 |
shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1). |
|
633 |
||
798 | 634 |
byte := bytes at:srcIndex. |
280 | 635 |
x1 to:x2 do:[:x | |
2226 | 636 |
|clr| |
637 |
||
746 | 638 |
value := (byte bitShift:shift) bitAnd:3. |
280 | 639 |
|
746 | 640 |
(value == 0) ifTrue:[ |
2226 | 641 |
clr := color0 |
746 | 642 |
] ifFalse:[ |
643 |
(value == 1) ifTrue:[ |
|
2226 | 644 |
clr := color1 |
746 | 645 |
] ifFalse:[ |
646 |
(value == 2) ifTrue:[ |
|
2226 | 647 |
clr := color2 |
746 | 648 |
] ifFalse:[ |
2226 | 649 |
clr := color3 |
746 | 650 |
] |
651 |
] |
|
652 |
]. |
|
2226 | 653 |
aBlock value:x value:clr. |
280 | 654 |
|
746 | 655 |
shift == 0 ifTrue:[ |
656 |
shift := -6. |
|
798 | 657 |
srcIndex := srcIndex + 1. |
806 | 658 |
x < x2 ifTrue:[ |
798 | 659 |
byte := bytes at:srcIndex. |
660 |
] |
|
746 | 661 |
] ifFalse:[ |
662 |
shift := shift + 2. |
|
663 |
] |
|
280 | 664 |
]. |
746 | 665 |
|
798 | 666 |
"Created: 7.6.1996 / 19:12:31 / cg" |
810 | 667 |
"Modified: 10.6.1996 / 10:32:47 / cg" |
280 | 668 |
! |
669 |
||
798 | 670 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
280 | 671 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
672 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
673 |
This method allows slighly faster processing of an |
|
674 |
image than using valueAtX:y:, since some processing can be |
|
675 |
avoided when going from pixel to pixel. However, for |
|
676 |
real image processing, specialized methods should be written." |
|
677 |
||
678 |
|srcIndex "{ Class: SmallInteger }" |
|
679 |
byte "{ Class: SmallInteger }" |
|
680 |
shift "{ Class: SmallInteger }" |
|
681 |
value "{ Class: SmallInteger }" |
|
682 |
x1 "{ Class: SmallInteger }" |
|
683 |
x2 "{ Class: SmallInteger }"| |
|
684 |
||
685 |
"left pixel in high bits" |
|
686 |
||
687 |
x1 := xLow. |
|
688 |
x2 := xHigh. |
|
689 |
||
690 |
srcIndex := (self bytesPerRow * y) + 1. |
|
691 |
srcIndex := srcIndex + (x1 // 4). |
|
692 |
shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1). |
|
693 |
||
798 | 694 |
byte := bytes at:srcIndex. |
280 | 695 |
x1 to:x2 do:[:x | |
798 | 696 |
value := (byte bitShift:shift) bitAnd:3. |
280 | 697 |
|
798 | 698 |
aBlock value:x value:value. |
280 | 699 |
|
798 | 700 |
shift == 0 ifTrue:[ |
701 |
shift := -6. |
|
702 |
srcIndex := srcIndex + 1. |
|
806 | 703 |
x < x2 ifTrue:[ |
798 | 704 |
byte := bytes at:srcIndex. |
705 |
] |
|
706 |
] ifFalse:[ |
|
707 |
shift := shift + 2. |
|
708 |
] |
|
280 | 709 |
]. |
798 | 710 |
|
711 |
"Created: 7.6.1996 / 19:09:42 / cg" |
|
806 | 712 |
"Modified: 8.6.1996 / 13:36:28 / cg" |
280 | 713 |
! ! |
714 |
||
1 | 715 |
!Depth2Image methodsFor:'magnification'! |
716 |
||
717 |
magnifyRowFrom:srcBytes offset:srcStart |
|
2178 | 718 |
into:dstBytes offset:dstStart factor:mX |
1 | 719 |
|
720 |
"magnify a single pixel row - can only magnify by integer factors" |
|
721 |
||
722 |
%{ |
|
723 |
unsigned char *srcP, *dstP; |
|
724 |
int _mag; |
|
725 |
REGISTER int i; |
|
726 |
REGISTER unsigned char _byte; |
|
727 |
int _pixels; |
|
728 |
REGISTER int outcnt, bits, bit, mask, incnt; |
|
729 |
int shift; |
|
97 | 730 |
OBJ w = _INST(width); |
1 | 731 |
|
2178 | 732 |
/* helper for two-plane magnification by 2 |
733 |
* 0000 -> 0000 0000 |
|
734 |
* 0001 -> 0000 0101 |
|
735 |
* ... |
|
736 |
* 1111 -> 1111 1111 |
|
737 |
*/ |
|
1 | 738 |
static unsigned char mag2[16] = {0x00, 0x05, 0x0a, 0x0f, 0x50, 0x55, 0x5a, 0x5f, |
2178 | 739 |
0xa0, 0xa5, 0xaa, 0xaf, 0xf0, 0xf5, 0xfa, 0xff}; |
740 |
/* helper for two-plane magnification by 4 */ |
|
741 |
static unsigned char mag4[16] = {0x00, 0x55, 0xaa, 0xff}; |
|
1 | 742 |
|
97 | 743 |
if (__bothSmallInteger(srcStart, dstStart) |
744 |
&& __bothSmallInteger(w, mX) |
|
35 | 745 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
2178 | 746 |
_mag = __intVal(mX); |
747 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
|
748 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
|
749 |
_pixels = __intVal(w); |
|
750 |
||
751 |
switch (_mag) { |
|
752 |
case 1: |
|
753 |
break; |
|
1 | 754 |
|
2178 | 755 |
case 2: |
756 |
/* tuned for this common case */ |
|
757 |
while (_pixels > 0) { |
|
758 |
_byte = *srcP++; |
|
759 |
*dstP++ = mag2[ _byte >> 4 ]; |
|
760 |
if (_pixels > 2) { |
|
761 |
*dstP++ = mag2[ _byte & 0x0F ]; |
|
762 |
} |
|
763 |
_pixels -= 4; |
|
764 |
} |
|
765 |
break; |
|
1 | 766 |
|
2178 | 767 |
case3: |
768 |
/* tuned for this common case */ |
|
769 |
bits = 0, incnt = 0, outcnt = 0; |
|
770 |
shift = 6; |
|
771 |
_byte = *srcP++; |
|
772 |
while (_pixels--) { |
|
773 |
bit = (_byte >> shift) & 3; |
|
774 |
incnt++; |
|
775 |
if (incnt == 4) { |
|
776 |
incnt = 0; |
|
777 |
shift = 6; |
|
778 |
_byte = *srcP++; |
|
779 |
} else { |
|
780 |
shift -= 2; |
|
781 |
} |
|
782 |
||
783 |
switch (outcnt) { |
|
784 |
case 0: |
|
785 |
/* next three pixels */ |
|
786 |
bits = (((bit << 2) | bit) << 2) | bit; |
|
787 |
outcnt = 3; |
|
788 |
break; |
|
789 |
||
790 |
case 1: |
|
791 |
/* next three pixels & store */ |
|
792 |
bits = (((((bits << 2) | bit) << 2) | bit) << 2) | bit; |
|
793 |
*dstP++ = bits; |
|
794 |
outcnt = 0; |
|
795 |
break; |
|
796 |
||
797 |
case 2: |
|
798 |
/* next two pixels & store */ |
|
799 |
bits = (((bits << 2) | bit) << 2) | bit; |
|
800 |
*dstP++ = bits; |
|
801 |
bits = bit; |
|
802 |
outcnt = 1; |
|
803 |
break; |
|
1 | 804 |
|
2178 | 805 |
case 3: |
806 |
/* next pixel & store */ |
|
807 |
bits = (bits << 2) | bit; |
|
808 |
*dstP++ = bits; |
|
809 |
bits = (bit << 2) | bit; |
|
810 |
outcnt = 2; |
|
811 |
break; |
|
812 |
} |
|
813 |
} |
|
814 |
if (outcnt) { |
|
815 |
*dstP = bits << ((4-outcnt)*2); |
|
816 |
} |
|
817 |
break; |
|
818 |
||
819 |
case 4: |
|
820 |
/* tuned for this common case */ |
|
821 |
incnt = 0; |
|
822 |
shift = 6; |
|
823 |
_byte = *srcP++; |
|
824 |
while (_pixels--) { |
|
825 |
bit = (_byte >> shift) & 3; |
|
826 |
incnt++; |
|
827 |
if (incnt == 4) { |
|
828 |
incnt = 0; |
|
829 |
shift = 6; |
|
830 |
_byte = *srcP++; |
|
831 |
} else { |
|
832 |
shift -= 2; |
|
833 |
} |
|
834 |
*dstP++ = mag4[bit]; |
|
835 |
} |
|
836 |
break; |
|
1 | 837 |
|
2178 | 838 |
default: |
839 |
bits = 0, incnt = 0, outcnt = 0; |
|
840 |
shift = 6; |
|
841 |
_byte = *srcP++; |
|
842 |
while (_pixels--) { |
|
843 |
bit = (_byte >> shift) & 3; |
|
844 |
incnt++; |
|
845 |
if (incnt == 4) { |
|
846 |
incnt = 0; |
|
847 |
shift = 6; |
|
848 |
_byte = *srcP++; |
|
849 |
} else { |
|
850 |
shift -= 2; |
|
851 |
} |
|
1 | 852 |
|
2178 | 853 |
for (i=_mag; i>0; i--) { |
854 |
bits = (bits << 2) | bit; |
|
855 |
outcnt++; |
|
856 |
if (outcnt == 4) { |
|
857 |
*dstP++ = bits; |
|
858 |
bits = 0; |
|
859 |
outcnt = 0; |
|
860 |
} |
|
861 |
} |
|
862 |
} |
|
863 |
if (outcnt) { |
|
864 |
*dstP = bits << ((4-outcnt)*2); |
|
865 |
} |
|
866 |
break; |
|
867 |
||
868 |
} |
|
869 |
RETURN (self); |
|
1 | 870 |
} |
871 |
%} |
|
872 |
. |
|
873 |
self primitiveFailed |
|
874 |
! ! |
|
280 | 875 |
|
876 |
!Depth2Image methodsFor:'queries'! |
|
877 |
||
878 |
bitsPerPixel |
|
879 |
"return the number of bits per pixel" |
|
880 |
||
881 |
^ 2 |
|
882 |
! |
|
883 |
||
884 |
bitsPerRow |
|
885 |
"return the number of bits in one scanline of the image" |
|
886 |
||
887 |
^ width * 2 |
|
888 |
! |
|
889 |
||
890 |
bytesPerRow |
|
891 |
"return the number of bytes in one scanline of the image" |
|
892 |
||
893 |
|nbytes| |
|
894 |
||
895 |
nbytes := width // 4. |
|
896 |
((width \\ 4) ~~ 0) ifTrue:[ |
|
897 |
^ nbytes + 1 |
|
898 |
]. |
|
899 |
^ nbytes |
|
900 |
! |
|
901 |
||
902 |
usedColors |
|
903 |
"return a collection of colors used in the receiver. |
|
2201 | 904 |
For depth2 images, we return the colorMap here, assuming all |
905 |
pixels are used ... |
|
906 |
... which is not really true - it could use not all colors" |
|
280 | 907 |
|
908 |
photometric ~~ #palette ifTrue:[ |
|
746 | 909 |
^ Array with:Color black |
910 |
with:(Color gray:33) |
|
911 |
with:(Color gray:67) |
|
2278 | 912 |
with:Color white. |
280 | 913 |
]. |
914 |
^ colorMap |
|
746 | 915 |
|
2278 | 916 |
"Modified: / 24.8.1998 / 18:38:08 / cg" |
280 | 917 |
! |
918 |
||
919 |
usedValues |
|
2201 | 920 |
"return a collection of color values used in the receiver. |
921 |
For depth2 images, we assuming all pixel values are present ... |
|
922 |
... which is not really true" |
|
280 | 923 |
|
924 |
"actually, this is wrong - we have to look if those are |
|
925 |
really used. However, assume that we dont care for |
|
926 |
those extra colors here ..." |
|
927 |
||
928 |
^ #(0 1 2 3) |
|
2201 | 929 |
|
930 |
"Modified: / 28.7.1998 / 22:23:15 / cg" |
|
280 | 931 |
! ! |
932 |
||
933 |
!Depth2Image class methodsFor:'documentation'! |
|
934 |
||
935 |
version |
|
3178 | 936 |
^ '$Header: /cvs/stx/stx/libview/Depth2Image.st,v 1.39 2000-02-12 15:34:44 cg Exp $' |
280 | 937 |
! ! |