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