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