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