author | Claus Gittinger <cg@exept.de> |
Fri, 11 Apr 2003 02:09:05 +0200 | |
changeset 3851 | 34637f468b2a |
parent 3842 | e97ae6061e75 |
child 3866 | c01473a90934 |
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 |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
181 |
usedDevicePadding usedDeviceBytesPerRow padd| |
2186
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 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
210 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
211 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
212 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
213 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
214 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
215 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
216 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
217 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
218 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
219 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
220 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
221 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
222 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
223 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
224 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
225 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
226 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
227 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
228 |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
229 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
230 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
231 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
232 |
&& dstPtr) { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
233 |
int r,p; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
234 |
int x, y, w, h, nPix; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
235 |
int byte; |
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 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
238 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
239 |
w = __intVal(_INST(width)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
240 |
h = __intVal(_INST(height)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
241 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
242 |
p = __intVal(padd); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
243 |
nPix = w * h; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
244 |
while (nPix-- > 0) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
245 |
unsigned idx, v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
246 |
OBJ clr; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
247 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
248 |
if (r & 1) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
249 |
idx = byte & 0xF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
250 |
} else { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
251 |
byte = *srcPtr++; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
252 |
idx = (byte>>4) & 0xF; |
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 |
clr = ap[idx]; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
255 |
v = __intVal(clr); |
2401 | 256 |
#ifdef __MSBFIRST |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
257 |
((short *)dstPtr)[0] = v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
258 |
#else |
2225
8fb244eaaf90
the SWAP_BYTES macro does not work yet.
Claus Gittinger <cg@exept.de>
parents:
2215
diff
changeset
|
259 |
# ifdef xxSWAP_BYTES |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2523
diff
changeset
|
260 |
SWAP_BYTES(v); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2523
diff
changeset
|
261 |
((short *)dstPtr)[0] = v; |
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
262 |
# else |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
263 |
dstPtr[0] = (v>>8) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
264 |
dstPtr[1] = (v) & 0xFF; |
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
265 |
# endif |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
266 |
#endif |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
267 |
dstPtr += 2; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
268 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
269 |
if (++r == w) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
270 |
dstPtr += p; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
271 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
272 |
} |
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 |
} |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
275 |
%}. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
276 |
] ifFalse:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
277 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
278 |
"/ 32 bits/pixel |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
279 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
280 |
"/ now, walk over the image and replace |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
281 |
"/ colorMap indices by color values in the bits array |
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 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
284 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
285 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
286 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
287 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
288 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
289 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
290 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
291 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
292 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
293 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
294 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
295 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
296 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
297 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
298 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
299 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
300 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
301 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
302 |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
303 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
304 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
305 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
306 |
&& dstPtr) { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
307 |
int x, y, w, h, nPix; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
308 |
int r,p; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
309 |
int byte; |
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 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
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 |
w = __intVal(_INST(width)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
314 |
h = __intVal(_INST(height)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
315 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
316 |
p = __intVal(padd); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
317 |
nPix = w * h; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
318 |
while (nPix > 0) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
319 |
unsigned idx, v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
320 |
OBJ clr; |
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 (r & 1) { |
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
323 |
idx = byte & 0xF; |
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
324 |
} else { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
325 |
byte = *srcPtr++; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
326 |
idx = (byte>>4) & 0xF; |
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 |
clr = ap[idx]; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
329 |
v = __intVal(clr); |
2401 | 330 |
#ifdef __MSBFIRST |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
331 |
((long *)dstPtr)[0] = v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
332 |
#else |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
333 |
dstPtr[0] = (v>>24) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
334 |
dstPtr[1] = (v>>16) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
335 |
dstPtr[2] = (v>>8) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
336 |
dstPtr[3] = (v) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
337 |
#endif |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
338 |
dstPtr += 4; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
339 |
nPix--; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
340 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
341 |
if (++r == w) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
342 |
dstPtr += p; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
343 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
344 |
} |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
345 |
} |
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 |
%}. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
348 |
] ifFalse:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
349 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
350 |
"/ 8 bits/pixel |
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 |
"/ now, walk over the image and replace |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
353 |
"/ colorMap indices by color values in the bits array |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
354 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
355 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
356 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
357 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
358 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
359 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
360 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
361 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
362 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
363 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
364 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
365 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
366 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
367 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
368 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
369 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
370 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
371 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
372 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
373 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
374 |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
375 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
376 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
377 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
378 |
&& dstPtr) { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
379 |
int x, y, w, h, nPix; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
380 |
int r,p, byte; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
381 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
382 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
383 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
384 |
w = __intVal(_INST(width)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
385 |
h = __intVal(_INST(height)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
386 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
387 |
p = __intVal(padd); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
388 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
389 |
nPix = w * h; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
390 |
while (nPix > 0) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
391 |
unsigned idx, v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
392 |
OBJ clr; |
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 |
if (r & 1) { |
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
395 |
idx = byte & 0xF; |
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
396 |
} else { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
397 |
byte = *srcPtr++; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
398 |
idx = (byte>>4) & 0xF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
399 |
} |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
400 |
clr = ap[idx]; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
401 |
v = __intVal(clr); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
402 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
403 |
dstPtr[0] = v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
404 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
405 |
dstPtr += 1; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
406 |
nPix--; |
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 |
if (++r == w) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
409 |
dstPtr += p; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
410 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
411 |
} |
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 |
] ifFalse:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
416 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
417 |
"/ 24 bits/pixel |
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 |
"/ now, walk over the image and replace |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
420 |
"/ colorMap indices by color values in the bits array |
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 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
423 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
424 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
425 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
426 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
427 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
428 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
429 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
430 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
431 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
432 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
433 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
434 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
435 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
436 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
437 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
438 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
439 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
440 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
441 |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
442 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
443 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
444 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
445 |
&& dstPtr) { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
446 |
int x, y, w, h, nPix; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
447 |
int r, p, byte; |
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 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
450 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
451 |
w = __intVal(_INST(width)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
452 |
h = __intVal(_INST(height)); |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
453 |
r = 0; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
454 |
p = __intVal(padd); |
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 |
nPix = w * h; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
457 |
while (nPix > 0) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
458 |
unsigned idx, v; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
459 |
OBJ clr; |
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 |
if (r & 1) { |
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
462 |
idx = byte & 0xF; |
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
463 |
} else { |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
464 |
byte = *srcPtr++; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
465 |
idx = (byte>>4) & 0xF; |
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 |
clr = ap[idx]; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
468 |
v = __intVal(clr); |
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 |
dstPtr[0] = (v>>16) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
471 |
dstPtr[1] = (v>>8) & 0xFF; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
472 |
dstPtr[2] = (v) & 0xFF; |
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 |
dstPtr += 3; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
475 |
nPix--; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
476 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
477 |
if (++r == w) { |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
478 |
dstPtr += p; |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
479 |
r = 0; |
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 |
} |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
482 |
} |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
483 |
%}. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
484 |
] ifFalse:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
485 |
'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
486 |
^ nil |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
487 |
] |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
488 |
] |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
489 |
] |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
490 |
]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
491 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
492 |
imageBits isNil ifTrue:[ |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
493 |
^ nil |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
494 |
]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
495 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
496 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
497 |
form isNil ifTrue:[^ nil]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
498 |
form initGC. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
499 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
500 |
form |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
501 |
copyBitsFrom:imageBits |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
502 |
bitsPerPixel:usedDeviceBitsPerPixel |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
503 |
depth:usedDeviceDepth |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
504 |
padding:usedDevicePadding |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
505 |
width:width height:height |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
506 |
x:0 y:0 |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
507 |
toX:0 y:0. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
508 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
509 |
^ form |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
510 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
511 |
"Created: 20.10.1995 / 22:05:10 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
512 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
513 |
! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
514 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
515 |
greyImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
516 |
"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
|
517 |
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
|
518 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
519 |
|f| |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
520 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
521 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
522 |
f notNil ifTrue:[^ f]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
523 |
^ super greyImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
524 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
525 |
"Created: / 24.7.1998 / 01:21:28 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
526 |
! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
527 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
528 |
paletteImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
529 |
"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
|
530 |
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
|
531 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
532 |
|f| |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
533 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
534 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
535 |
f notNil ifTrue:[^ f]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
536 |
^ super paletteImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
537 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
538 |
"Created: / 24.7.1998 / 01:20:46 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
539 |
! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
540 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
541 |
rgbImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
542 |
"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
|
543 |
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
|
544 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
545 |
|f| |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
546 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
547 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
548 |
f notNil ifTrue:[^ f]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
549 |
^ super rgbImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
550 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
551 |
"Created: / 24.7.1998 / 01:21:57 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
552 |
! ! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
553 |
|
810 | 554 |
!Depth4Image methodsFor:'dither helpers'! |
798 | 555 |
|
1782 | 556 |
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
806 | 557 |
"return the bitmap for a dithered depth-bitmap from the image; |
558 |
with a constant ditherMatrix, this can be used for thresholding. |
|
559 |
Redefined to make use of knowing that pixels are 4-bit values." |
|
560 |
||
561 |
|dH nDither |
|
562 |
greyLevels greyMap1 greyMap2 |
|
563 |
bytesPerRow "{Class: SmallInteger }" |
|
564 |
bytesPerOutRow "{Class: SmallInteger }" |
|
565 |
pixelsPerByte "{Class: SmallInteger }" |
|
566 |
outBits |
|
567 |
w "{Class: SmallInteger }" |
|
568 |
h "{Class: SmallInteger }" | |
|
569 |
||
570 |
nDither := ditherMatrix size. |
|
571 |
dH := nDither / dW. |
|
572 |
||
573 |
w := width. |
|
574 |
h := height. |
|
575 |
||
576 |
greyLevels := 1 bitShift:depth. |
|
577 |
pixelsPerByte := 8 / depth. |
|
578 |
||
579 |
bytesPerRow := self bytesPerRow. |
|
580 |
||
581 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
582 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
583 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
|
584 |
^ nil |
|
585 |
]. |
|
586 |
||
587 |
greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels |
|
588 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
589 |
0 |
|
590 |
] ifFalse:[ |
|
591 |
b truncated |
|
592 |
] |
|
593 |
]) asByteArray. |
|
594 |
||
595 |
greyMap2 := self greyMapForRange:(greyLevels-1). |
|
596 |
greyMap2 := (greyMap2 collect:[:el | |
|
597 |
el isNil ifTrue:[ |
|
598 |
0 |
|
599 |
] ifFalse:[ |
|
600 |
((el - el truncated) "/ the error (0..1) |
|
601 |
* nDither) rounded |
|
602 |
]]) asByteArray. |
|
603 |
||
604 |
%{ |
|
605 |
int __dW = __intVal(dW); |
|
606 |
int __dH = __intVal(dH); |
|
607 |
int __byte; |
|
608 |
int __dT, __dO; |
|
609 |
int __depth = __intVal(depth); |
|
610 |
int __dstIdx = 0; |
|
611 |
int __srcIdx = 0; |
|
612 |
int __bitCnt; |
|
613 |
int __inByte; |
|
614 |
int __grey, __pixel; |
|
615 |
int __w = __intVal(w); |
|
616 |
int __h = __intVal(h); |
|
617 |
int __x; |
|
618 |
int __y; |
|
619 |
int __oX, __oY, __dY; |
|
620 |
int __nextDst; |
|
621 |
int __nextSrc; |
|
622 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
623 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
624 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
625 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
808 | 626 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
806 | 627 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
628 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
|
629 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
630 |
||
631 |
__oY = __dY = 0; |
|
632 |
for (__y=0; __y<__h; __y++) { |
|
633 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
634 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
635 |
||
636 |
__byte = 0; |
|
637 |
__bitCnt = 8; |
|
638 |
||
639 |
__oX = 0; |
|
640 |
||
641 |
for (__x=0; __x<__w; __x++) { |
|
642 |
if (__x & 1) { |
|
643 |
/* odd */ |
|
644 |
__grey = __inByte & 0xF; |
|
645 |
__srcIdx++; |
|
646 |
} else { |
|
647 |
__inByte = __bytes[__srcIdx]; |
|
648 |
__grey = (__inByte >> 4) & 0xF; |
|
649 |
} |
|
650 |
||
651 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
|
652 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
|
653 |
__dT = __ditherMatrix[__dY + __oX]; |
|
654 |
||
655 |
if (__dO > __dT) /* dither says: next pixel */ |
|
656 |
__pixel++; |
|
657 |
||
658 |
__oX++; |
|
659 |
if (__oX == __dW) __oX = 0; |
|
660 |
||
661 |
__byte = (__byte << __depth) | __pixel; |
|
662 |
||
663 |
__bitCnt = __bitCnt - __depth; |
|
664 |
if (__bitCnt == 0) { |
|
665 |
__outBits[__dstIdx] = __byte; |
|
666 |
__dstIdx++; |
|
667 |
__byte = 0; |
|
668 |
__bitCnt = 8; |
|
669 |
} |
|
670 |
} |
|
671 |
||
672 |
if (__bitCnt != 8) { |
|
673 |
__byte = __byte << __bitCnt; |
|
674 |
__outBits[__dstIdx] = __byte; |
|
675 |
} |
|
676 |
||
677 |
__oY++; __dY += __dW; |
|
678 |
if (__oY == __dH) { |
|
679 |
__oY = 0; |
|
680 |
__dY = 0; |
|
681 |
} |
|
682 |
||
683 |
__srcIdx = __nextSrc; |
|
684 |
__dstIdx = __nextDst; |
|
685 |
} |
|
686 |
%}. |
|
687 |
^ outBits |
|
688 |
||
689 |
! |
|
690 |
||
798 | 691 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
692 |
"return the dithered monochrome bits for the receiver image; |
|
693 |
with a constant ditherMatrix, this can be used for thresholding. |
|
694 |
Redefined to make use of knowing that pixels are 4-bit values." |
|
695 |
||
696 |
|f dH nDither |
|
697 |
greyMap monoBits |
|
698 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
699 |
bytesPerRow "{Class: SmallInteger }" |
|
700 |
w "{Class: SmallInteger }" |
|
701 |
h "{Class: SmallInteger }"| |
|
702 |
||
703 |
nDither := ditherMatrix size. |
|
704 |
dH := nDither / dW. |
|
705 |
||
706 |
w := width. |
|
707 |
h := height. |
|
708 |
||
709 |
bytesPerRow := self bytesPerRow. |
|
710 |
||
711 |
bytesPerMonoRow := w + 7 // 8. |
|
712 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
713 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
714 |
^ nil |
|
715 |
]. |
|
716 |
||
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
717 |
greyMap := self greyByteMapForRange:nDither. |
798 | 718 |
|
719 |
%{ |
|
720 |
int __dW = __intVal(dW); |
|
721 |
int __dH = __intVal(dH); |
|
722 |
int __byte; |
|
723 |
int __dT; |
|
724 |
int __dstIdx = 0; |
|
725 |
int __srcIdx = 0; |
|
726 |
int __bitCnt; |
|
727 |
int __inByte; |
|
728 |
int __grey; |
|
729 |
int __w = __intVal(w); |
|
730 |
int __h = __intVal(h); |
|
731 |
int __x; |
|
732 |
int __y; |
|
733 |
int __oX, __oY, __dY; |
|
734 |
int __nextDst; |
|
735 |
int __nextSrc; |
|
736 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
737 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
738 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
739 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
808 | 740 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
798 | 741 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
742 |
unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
|
743 |
||
744 |
__oY = __dY = 0; |
|
745 |
for (__y=0; __y<__h; __y++) { |
|
746 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
|
747 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
748 |
||
749 |
__byte = 0; |
|
750 |
__bitCnt = 8; |
|
751 |
||
752 |
__oX = 0; |
|
753 |
||
754 |
for (__x=0; __x<__w; __x++) { |
|
755 |
if (__x & 1) { |
|
756 |
/* odd */ |
|
757 |
__grey = __inByte & 0xF; |
|
758 |
__srcIdx++; |
|
759 |
} else { |
|
760 |
__inByte = __bytes[__srcIdx]; /* 0..255 */ |
|
761 |
__grey = (__inByte >> 4) & 0xF; |
|
762 |
} |
|
763 |
||
764 |
__grey = __greyMap[__grey]; |
|
765 |
__dT = __ditherMatrix[__dY + __oX]; |
|
766 |
||
767 |
__oX++; |
|
768 |
if (__oX == __dW) __oX = 0; |
|
769 |
||
770 |
__byte = __byte << 1; |
|
771 |
if (__grey > __dT) { |
|
772 |
__byte = __byte | 1; /* white */ |
|
773 |
} |
|
774 |
||
775 |
__bitCnt--; |
|
776 |
if (__bitCnt == 0) { |
|
777 |
__monoBits[__dstIdx] = __byte; |
|
778 |
__dstIdx++; |
|
779 |
__byte = 0; |
|
780 |
__bitCnt = 8; |
|
781 |
} |
|
782 |
} |
|
783 |
||
784 |
if (__bitCnt != 8) { |
|
785 |
__byte = __byte << __bitCnt; |
|
786 |
__monoBits[__dstIdx] = __byte; |
|
787 |
} |
|
788 |
||
789 |
__oY++; __dY += __dW; |
|
790 |
if (__oY == __dH) { |
|
791 |
__oY = 0; |
|
792 |
__dY = 0; |
|
793 |
} |
|
794 |
||
795 |
__srcIdx = __nextSrc; |
|
796 |
__dstIdx = __nextDst; |
|
797 |
} |
|
798 |
%}. |
|
799 |
||
800 |
^ monoBits |
|
801 |
! ! |
|
802 |
||
89 | 803 |
!Depth4Image methodsFor:'enumerating'! |
81 | 804 |
|
798 | 805 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1 | 806 |
"perform aBlock for each pixel from x1 to x2 in row y. |
807 |
The block is passed the color at each pixel. |
|
808 |
This method allows slighly faster processing of an |
|
809 |
image than using atX:y:, since some processing can be |
|
810 |
avoided when going from pixel to pixel. However, for |
|
811 |
real image processing, specialized methods should be written." |
|
812 |
||
813 |
|srcIndex "{ Class: SmallInteger }" |
|
814 |
byte "{ Class: SmallInteger }" |
|
815 |
shift "{ Class: SmallInteger }" |
|
816 |
value "{ Class: SmallInteger }" |
|
817 |
x1 "{ Class: SmallInteger }" |
|
818 |
x2 "{ Class: SmallInteger }" |
|
2523 | 819 |
colorArray| |
1 | 820 |
|
2226 | 821 |
colorArray := ((0 to:15) collect:[:i | self colorFromValue:i]) asArray. |
1 | 822 |
|
823 |
x1 := xLow. |
|
824 |
x2 := xHigh. |
|
810 | 825 |
|
1 | 826 |
srcIndex := (self bytesPerRow * y) + 1. |
827 |
srcIndex := srcIndex + (x1 // 2). |
|
12 | 828 |
x1 even ifTrue:[ |
746 | 829 |
shift := -4 |
12 | 830 |
] ifFalse:[ |
746 | 831 |
shift := 0 |
12 | 832 |
]. |
1 | 833 |
|
2197
1b88e629091d
avoid a byte fetch in colorsAtY:from:to:do:
Claus Gittinger <cg@exept.de>
parents:
2186
diff
changeset
|
834 |
byte := bytes at:srcIndex. |
1 | 835 |
x1 to:x2 do:[:x | |
746 | 836 |
shift == 0 ifTrue:[ |
837 |
value := byte bitAnd:16rF. |
|
838 |
shift := -4. |
|
839 |
srcIndex := srcIndex + 1. |
|
840 |
] ifFalse:[ |
|
841 |
byte := bytes at:srcIndex. |
|
842 |
value := (byte bitShift:-4) bitAnd:16rF. |
|
843 |
shift := 0 |
|
844 |
]. |
|
810 | 845 |
aBlock value:x value:(colorArray at:(value + 1)). |
1 | 846 |
] |
746 | 847 |
|
2197
1b88e629091d
avoid a byte fetch in colorsAtY:from:to:do:
Claus Gittinger <cg@exept.de>
parents:
2186
diff
changeset
|
848 |
"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
|
849 |
"Modified: / 28.7.1998 / 21:26:11 / cg" |
280 | 850 |
! |
851 |
||
798 | 852 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
280 | 853 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
854 |
The block is passed the pixelValue at each pixel. |
|
855 |
This method allows slighly faster processing of an |
|
856 |
image than using valueAtX:y:, since some processing can be |
|
857 |
avoided when going from pixel to pixel. However, for |
|
858 |
real image processing, specialized methods should be written." |
|
859 |
||
860 |
|srcIndex "{ Class: SmallInteger }" |
|
861 |
byte "{ Class: SmallInteger }" |
|
862 |
shift "{ Class: SmallInteger }" |
|
863 |
pixelValue "{ Class: SmallInteger }" |
|
864 |
x1 "{ Class: SmallInteger }" |
|
865 |
x2 "{ Class: SmallInteger }" |
|
866 |
| |
|
867 |
||
868 |
x1 := xLow. |
|
869 |
x2 := xHigh. |
|
870 |
srcIndex := (self bytesPerRow * y) + 1. |
|
871 |
srcIndex := srcIndex + (x1 // 2). |
|
872 |
x1 even ifTrue:[ |
|
798 | 873 |
shift := -4 |
280 | 874 |
] ifFalse:[ |
798 | 875 |
shift := 0 |
280 | 876 |
]. |
877 |
||
878 |
x1 to:x2 do:[:x | |
|
798 | 879 |
shift == 0 ifTrue:[ |
880 |
byte := bytes at:srcIndex. |
|
881 |
pixelValue := byte bitAnd:16rF. |
|
882 |
shift := -4. |
|
883 |
srcIndex := srcIndex + 1. |
|
884 |
] ifFalse:[ |
|
885 |
byte := bytes at:srcIndex. |
|
886 |
pixelValue := (byte bitShift:-4) bitAnd:16rF. |
|
887 |
shift := 0 |
|
888 |
]. |
|
889 |
aBlock value:x value:pixelValue. |
|
280 | 890 |
] |
798 | 891 |
|
892 |
"Created: 7.6.1996 / 19:09:45 / cg" |
|
1 | 893 |
! ! |
894 |
||
895 |
!Depth4Image methodsFor:'magnification'! |
|
896 |
||
897 |
magnifyRowFrom:srcBytes offset:srcStart |
|
2179 | 898 |
into:dstBytes offset:dstStart factor:mX |
1 | 899 |
|
89 | 900 |
"magnify a single pixel row - can only magnify by integer factors. |
901 |
Specially tuned for factor 2." |
|
1 | 902 |
|
903 |
%{ |
|
904 |
unsigned char *srcP, *dstP; |
|
905 |
int _mag; |
|
906 |
REGISTER int i; |
|
907 |
REGISTER unsigned char _byte; |
|
908 |
int _pixels; |
|
909 |
REGISTER int outcnt, bits, bit; |
|
97 | 910 |
OBJ w = _INST(width); |
1 | 911 |
|
97 | 912 |
if (__bothSmallInteger(srcStart, dstStart) |
913 |
&& __bothSmallInteger(w, mX) |
|
35 | 914 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
2179 | 915 |
_mag = __intVal(mX); |
916 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
|
917 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
|
918 |
_pixels = __intVal(w); |
|
1 | 919 |
|
2179 | 920 |
switch (_mag) { |
921 |
case 1: |
|
922 |
break; |
|
923 |
||
924 |
case 2: |
|
925 |
_byte = *srcP++; |
|
926 |
while (_pixels) { |
|
927 |
bit = (_byte >> 4) & 0xF; |
|
928 |
bits = (bit << 4) | bit; |
|
929 |
*dstP++ = bits; |
|
1 | 930 |
|
2179 | 931 |
if (--_pixels) { |
932 |
bit = _byte & 0xF; |
|
933 |
bits = (bit << 4) | bit; |
|
934 |
*dstP++ = bits; |
|
935 |
_byte = *srcP++; |
|
936 |
_pixels--; |
|
937 |
} |
|
938 |
} |
|
939 |
break; |
|
1 | 940 |
|
2179 | 941 |
default: |
942 |
bits = 0, outcnt = 0; |
|
943 |
_byte = *srcP++; |
|
944 |
while (_pixels) { |
|
945 |
bit = (_byte >> 4) & 0xF; |
|
1 | 946 |
|
2179 | 947 |
for (i=_mag; i>0; i--) { |
948 |
bits = (bits << 4) | bit; |
|
949 |
outcnt++; |
|
950 |
if (outcnt == 2) { |
|
951 |
*dstP++ = bits; |
|
952 |
bits = 0; |
|
953 |
outcnt = 0; |
|
954 |
} |
|
955 |
} |
|
1 | 956 |
|
2179 | 957 |
if (--_pixels) { |
958 |
bit = _byte & 0xF; |
|
959 |
for (i=_mag; i>0; i--) { |
|
960 |
bits = (bits << 4) | bit; |
|
961 |
outcnt++; |
|
962 |
if (outcnt == 2) { |
|
963 |
*dstP++ = bits; |
|
964 |
bits = 0; |
|
965 |
outcnt = 0; |
|
966 |
} |
|
967 |
} |
|
968 |
_byte = *srcP++; |
|
969 |
_pixels--; |
|
970 |
} |
|
971 |
} |
|
972 |
if (outcnt) { |
|
973 |
*dstP = bits << 4; |
|
974 |
} |
|
1 | 975 |
|
2179 | 976 |
break; |
977 |
} |
|
978 |
RETURN (self); |
|
1 | 979 |
} |
3842 | 980 |
%}. |
981 |
super |
|
982 |
magnifyRowFrom:srcBytes offset:srcStart |
|
983 |
into:dstBytes offset:dstStart factor:mX |
|
1 | 984 |
! ! |
280 | 985 |
|
986 |
!Depth4Image methodsFor:'queries'! |
|
987 |
||
988 |
bitsPerPixel |
|
989 |
"return the number of bits per pixel" |
|
990 |
||
991 |
^ 4 |
|
992 |
! |
|
993 |
||
994 |
bitsPerRow |
|
995 |
"return the number of bits in one scanline of the image" |
|
996 |
||
997 |
^ width * 4 |
|
998 |
! |
|
999 |
||
1000 |
bytesPerRow |
|
1001 |
"return the number of bytes in one scanline of the image" |
|
1002 |
||
1003 |
|nbytes| |
|
1004 |
||
1005 |
nbytes := width // 2. |
|
1006 |
width odd ifTrue:[ |
|
1007 |
^ nbytes + 1 |
|
1008 |
]. |
|
1009 |
^ nbytes |
|
1010 |
! |
|
1011 |
||
1012 |
usedValues |
|
1013 |
"return a collection of color values used in the receiver." |
|
1014 |
||
1015 |
|useFlags usedValues| |
|
1016 |
||
1017 |
useFlags := Array new:16 withAll:false. |
|
1018 |
width even ifFalse:[ |
|
798 | 1019 |
0 to:self height - 1 do:[:y | |
1020 |
self valuesAtY:y from:0 to:self width - 1 do:[:x :pixel | |
|
1021 |
useFlags at:(pixel + 1) put:true |
|
1022 |
] |
|
1023 |
]. |
|
280 | 1024 |
] ifTrue:[ |
798 | 1025 |
bytes usedValues do:[:byte | |
1026 |
useFlags at:(byte bitShift:-4)+1 put:true. |
|
1027 |
useFlags at:(byte bitAnd:2r1111)+1 put:true. |
|
1028 |
]. |
|
280 | 1029 |
]. |
2265 | 1030 |
^ (0 to:15) select:[:i | useFlags at:(i+1)]. |
798 | 1031 |
|
2265 | 1032 |
"/ usedValues := OrderedCollection new. |
1033 |
"/ 1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]]. |
|
1034 |
"/ ^ usedValues |
|
1035 |
||
1036 |
"Modified: / 24.8.1998 / 13:56:59 / cg" |
|
280 | 1037 |
! ! |
1038 |
||
1039 |
!Depth4Image class methodsFor:'documentation'! |
|
1040 |
||
1041 |
version |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
1042 |
^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.42 2003-04-11 00:09:05 cg Exp $' |
280 | 1043 |
! ! |