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