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