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