author | Claus Gittinger <cg@exept.de> |
Sun, 29 Jun 2003 00:21:44 +0200 | |
changeset 3900 | 2ee04532b466 |
parent 3897 | 3fbd8f6fc347 |
child 3906 | f77d3b42614a |
permissions | -rw-r--r-- |
5 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
71 | 3 |
All Rights Reserved |
5 | 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:#Depth8Image |
579 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Graphics-Images' |
|
1 | 20 |
! |
21 |
||
1167 | 22 |
!Depth8Image class methodsFor:'documentation'! |
46 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
71 | 27 |
All Rights Reserved |
5 | 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 |
! |
|
5 | 37 |
|
46 | 38 |
documentation |
39 |
" |
|
40 |
this class represents 256-color (8 bit / pixel) images (palette, greyscale ...). |
|
41 |
It mainly consists of methods already implemented in Image, |
|
42 |
reimplemented here for more performance. |
|
611 | 43 |
|
44 |
[author:] |
|
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
45 |
Claus Gittinger |
611 | 46 |
|
47 |
[see also:] |
|
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
48 |
Depth1Image Depth2Image Depth4Image Depth16Image Depth24Image |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
49 |
ImageReader |
46 | 50 |
" |
51 |
! ! |
|
5 | 52 |
|
1167 | 53 |
!Depth8Image class methodsFor:'queries'! |
89 | 54 |
|
55 |
imageDepth |
|
579 | 56 |
"return the depth of images represented by instances of |
57 |
this class - here we return 8" |
|
1 | 58 |
|
59 |
^ 8 |
|
60 |
||
579 | 61 |
"Modified: 20.4.1996 / 23:40:22 / cg" |
81 | 62 |
! ! |
63 |
||
3263 | 64 |
!Depth8Image methodsFor:'accessing-pixels'! |
1 | 65 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
66 |
pixelAtX:x y:y |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
67 |
"retrieve a pixel at x/y; return a pixelValue. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
68 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
69 |
x = width-1, y=height-1 for lower right pixel" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
70 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
71 |
|index "{ Class: SmallInteger }"| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
72 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
73 |
%{ /* NOCONTEXT */ |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
74 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
75 |
OBJ b = _INST(bytes); |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
76 |
OBJ w = _INST(width); |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
77 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
78 |
if (__isByteArray(b) |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
79 |
&& __bothSmallInteger(x, y) |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
80 |
&& __isSmallInteger(w) ) { |
3842 | 81 |
int _idx, _pix; |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
82 |
|
3842 | 83 |
_idx = (__intVal(w) * __intVal(y)) + __intVal(x); |
84 |
if ((unsigned)_idx < __byteArraySize(b)) { |
|
85 |
_pix = __ByteArrayInstPtr(b)->ba_element[_idx]; |
|
86 |
RETURN( __MKSMALLINT(_pix) ); |
|
87 |
} |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
88 |
} |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
89 |
%}. |
3842 | 90 |
"/ the code below is only evaluated if the bytes-collection is |
91 |
"/ not a ByteArray, or the arguments are not integers |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
92 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
93 |
index := (width * y) + 1 + x. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
94 |
^ bytes at:index. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
95 |
! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
96 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
97 |
pixelAtX:x y:y put:aPixelValue |
1 | 98 |
"set the pixel at x/y to aPixelValue. |
99 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
100 |
x = width-1, y=height-1 for lower right pixel" |
|
101 |
||
102 |
|index "{ Class: SmallInteger }"| |
|
103 |
||
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
104 |
%{ /* NOCONTEXT */ |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
105 |
|
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
106 |
OBJ b = _INST(bytes); |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
107 |
OBJ w = _INST(width); |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
108 |
|
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
109 |
if (__isByteArray(b) |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
110 |
&& __bothSmallInteger(x, y) |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
111 |
&& __bothSmallInteger(w, aPixelValue) ) { |
3842 | 112 |
int _idx; |
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
113 |
|
3842 | 114 |
_idx = (__intVal(w) * __intVal(y)) + __intVal(x); |
115 |
if ((unsigned)_idx < __byteArraySize(b)) { |
|
116 |
__ByteArrayInstPtr(b)->ba_element[_idx] = __intVal(aPixelValue); |
|
117 |
RETURN( self ); |
|
118 |
} |
|
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
119 |
} |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
120 |
%}. |
3842 | 121 |
"fall back code for nonByteArray or nonInteger arguments" |
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
122 |
|
1 | 123 |
index := (width * y) + 1 + x. |
124 |
bytes at:index put:aPixelValue. |
|
125 |
! |
|
126 |
||
3872 | 127 |
rowAt:y into:aPixelBuffer startingAt:startIndex |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
128 |
"fill aPixelBuffer with pixel values from a single row. |
3872 | 129 |
Notice: row coordinate starts at 0." |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
130 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
131 |
|srcIdx| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
132 |
|
3872 | 133 |
bytes notNil ifTrue:[ |
134 |
srcIdx := (y * width) + 1. |
|
135 |
aPixelBuffer replaceFrom:startIndex to:startIndex+width-1 with:bytes startingAt:srcIdx. |
|
136 |
^ self. |
|
137 |
]. |
|
138 |
^ super rowAt:y into:aPixelBuffer startingAt:startIndex |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
139 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
140 |
"Modified: 24.4.1997 / 15:47:22 / cg" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
141 |
! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
142 |
|
3872 | 143 |
rowAt:y putAll:pixelArray startingAt:startIndex |
144 |
"store a single rows bits from bits in the pixelArray argument; |
|
145 |
Return the pixelArray. |
|
146 |
Notice: row coordinate starts at 0." |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
147 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
148 |
|dstIdx| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
149 |
|
3872 | 150 |
dstIdx := (y * width) + 1. |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
151 |
self bits replaceFrom:dstIdx to:dstIdx+width-1 with:pixelArray startingAt:startIndex. |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
152 |
^ pixelArray |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
153 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
154 |
"Created: 24.4.1997 / 15:49:42 / cg" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
155 |
! ! |
579 | 156 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
157 |
!Depth8Image methodsFor:'converting'! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
158 |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
159 |
fromImage:anImage |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
160 |
"setup the receiver from another image. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
161 |
The code here is tuned for depth 1, 2 and 4 source images; |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
162 |
other conversions are done in the superclasses fallBack method." |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
163 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
164 |
|srcBytesPerRow "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
165 |
srcIdx "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
166 |
dstIdx "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
167 |
w "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
168 |
h "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
169 |
srcBuffer dstBuffer srcBytes |
3900 | 170 |
srcDepth map bytes| |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
171 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
172 |
srcDepth := anImage depth. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
173 |
(#(1 2 4) includes:srcDepth) ifFalse:[ |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
174 |
^ super fromImage:anImage |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
175 |
]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
176 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
177 |
width := w := anImage width. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
178 |
height := h := anImage height. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
179 |
bytes := ByteArray uninitializedNew:(w * h). |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
180 |
bitsPerSample := self bitsPerSample. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
181 |
samplesPerPixel := self samplesPerPixel. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
182 |
self colormapFromImage:anImage. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
183 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
184 |
colorMap isNil ifTrue:[ |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
185 |
"/ if source has no colorMap, more work is needed ... |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
186 |
map := #( |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
187 |
#[0 16rFF] |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
188 |
#[0 16r55 16rAA 16rFF] |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
189 |
nil |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
190 |
#[16r00 16r11 16r22 16r33 16r44 16r55 16r66 16r77 |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
191 |
16r88 16r99 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF] |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
192 |
) at:srcDepth. |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
193 |
]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
194 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
195 |
self mask:anImage mask. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
196 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
197 |
"/ only expand & translate pixels |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
198 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
199 |
srcBytes := anImage bits. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
200 |
srcBytesPerRow := anImage bytesPerRow. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
201 |
srcBuffer := ByteArray new:srcBytesPerRow. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
202 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
203 |
dstBuffer := ByteArray new:w. |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
204 |
srcIdx := 1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
205 |
dstIdx := 1. |
3900 | 206 |
bytes := self bits. |
207 |
bytes isNil ifTrue:[ |
|
208 |
self bits:(bytes := ByteArray new:(self bytesPerRow * self height)). |
|
209 |
]. |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
210 |
1 to:h do:[:hi | |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
211 |
srcBuffer replaceFrom:1 to:srcBytesPerRow with:srcBytes startingAt:srcIdx. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
212 |
srcBuffer expandPixels:srcDepth width:w height:1 into:dstBuffer mapping:map. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
213 |
bytes replaceFrom:dstIdx to:dstIdx+w-1 with:dstBuffer startingAt:1. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
214 |
dstIdx := dstIdx + w. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
215 |
srcIdx := srcIdx + srcBytesPerRow. |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
216 |
] |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
217 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
218 |
" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
219 |
|i1 i2 i4 i8 i16 i24| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
220 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
221 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
222 |
i2 := Depth2Image fromImage:i1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
223 |
i4 := Depth4Image fromImage:i1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
224 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
225 |
i8 := Depth8Image fromImage:i1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
226 |
i8 inspect. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
227 |
i8 := Depth8Image fromImage:i2. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
228 |
i8 inspect. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
229 |
i8 := Depth8Image fromImage:i4. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
230 |
i8 inspect. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
231 |
" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
232 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
233 |
"Modified: 24.4.1997 / 14:01:14 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
234 |
! ! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
235 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
236 |
!Depth8Image methodsFor:'converting images'! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
237 |
|
1932 | 238 |
anyImageAsPseudoFormOn:aDevice |
239 |
"return a pseudoForm from the palette picture. |
|
240 |
The main work is in color reduction, when not all colors can be aquired. |
|
241 |
This method works for any photometric." |
|
242 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
243 |
|bytes pseudoBits f gcRound has8BitImage deviceDepth |
1932 | 244 |
imgMap newImage pixelRow dColors |
245 |
usedColors usageCounts maxIndex map |
|
246 |
fit scale lastOK error |
|
247 |
div |
|
248 |
bitsPerRGB "{Class: SmallInteger }" |
|
249 |
shift "{Class: SmallInteger }" |
|
250 |
m "{Class: SmallInteger }" |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
251 |
mapSize "{Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
252 |
cube nR nG nB ditherColors clr| |
1932 | 253 |
|
254 |
(cube := aDevice fixColors) notNil ifTrue:[ |
|
2835 | 255 |
nR := aDevice numFixRed. |
256 |
nG := aDevice numFixGreen. |
|
257 |
nB := aDevice numFixBlue. |
|
1932 | 258 |
|
2835 | 259 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
260 |
f := self |
|
261 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
262 |
colors:cube |
|
263 |
nRed:nR |
|
264 |
nGreen:nG |
|
265 |
nBlue:nB. |
|
266 |
] ifFalse:[ |
|
267 |
f := self |
|
268 |
asNearestPaintDepth8FormOn:aDevice |
|
269 |
colors:cube |
|
270 |
nRed:nR |
|
271 |
nGreen:nG |
|
272 |
nBlue:nB. |
|
273 |
]. |
|
274 |
f notNil ifTrue:[^ f]. |
|
1932 | 275 |
]. |
276 |
||
277 |
"find used colors" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
278 |
bytes := self bits. |
1932 | 279 |
usedColors := bytes usedValues. "gets us an array filled with used values" |
2835 | 280 |
"(could use bytes asBag)" |
1932 | 281 |
maxIndex := usedColors max + 1. |
282 |
||
283 |
usedColors size > 20 ifTrue:[ |
|
2835 | 284 |
('Depth8Image [info]: allocating ' , usedColors size printString , ' colors ...') infoPrintCR. |
1932 | 285 |
]. |
286 |
||
287 |
"sort by usage" |
|
288 |
usageCounts := bytes usageCounts. |
|
289 |
usageCounts := usedColors asArray collect:[:clr | usageCounts at:(clr + 1)]. |
|
290 |
usageCounts sort:[:a :b | a > b] with:usedColors. |
|
291 |
||
292 |
"allocate the colors (in order of usage count)" |
|
293 |
||
294 |
imgMap := Array new:maxIndex. |
|
295 |
||
296 |
" |
|
297 |
first, try to get the exact colors ... |
|
298 |
" |
|
299 |
bitsPerRGB := aDevice bitsPerRGB. |
|
300 |
shift := (8 - bitsPerRGB) negated. |
|
301 |
m := (1 bitShift:bitsPerRGB) - 1. |
|
302 |
div := m asFloat. |
|
303 |
||
304 |
fit := true. |
|
305 |
scale := 100.0 / div. "to scale 0..255 into 0.0 .. 100.0" |
|
306 |
lastOK := 0. |
|
307 |
gcRound := 0. |
|
308 |
||
309 |
usedColors do:[:aColorIndex | |
|
2835 | 310 |
|devColor color |
311 |
r "{Class: SmallInteger }" |
|
312 |
g "{Class: SmallInteger }" |
|
313 |
b "{Class: SmallInteger }" |
|
314 |
mapIndex "{Class: SmallInteger }"| |
|
1932 | 315 |
|
2835 | 316 |
fit ifTrue:[ |
317 |
mapIndex := aColorIndex + 1. |
|
318 |
"/ color := colorMap at:mapIndex. |
|
1932 | 319 |
|
2835 | 320 |
color := self colorFromValue:aColorIndex. |
3600 | 321 |
(color isOnDevice:aDevice) ifTrue:[ |
2835 | 322 |
"wow - an immediate hit" |
323 |
devColor := color |
|
324 |
] ifFalse:[ |
|
325 |
devColor := color exactOn:aDevice. |
|
326 |
devColor isNil ifTrue:[ |
|
327 |
" |
|
328 |
could not allocate color - on the first round, do a GC to flush |
|
329 |
unused colors - this may help if some colors where locked by |
|
330 |
already free images. |
|
331 |
" |
|
332 |
gcRound == 0 ifTrue:[ |
|
333 |
ObjectMemory scavenge; finalize. |
|
334 |
devColor := color exactOn:aDevice. |
|
335 |
gcRound := 1 |
|
336 |
]. |
|
337 |
devColor isNil ifTrue:[ |
|
338 |
gcRound == 1 ifTrue:[ |
|
339 |
CollectGarbageWhenRunningOutOfColors ifTrue:[ |
|
340 |
'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR. |
|
341 |
ObjectMemory incrementalGC; finalize. |
|
342 |
devColor := color exactOn:aDevice. |
|
343 |
]. |
|
344 |
gcRound := 2 |
|
345 |
] |
|
346 |
] |
|
347 |
]. |
|
348 |
]. |
|
349 |
(devColor notNil and:[devColor colorId notNil]) ifTrue:[ |
|
350 |
imgMap at:mapIndex put:devColor. |
|
351 |
lastOK := lastOK + 1. |
|
352 |
] ifFalse:[ |
|
353 |
fit := false |
|
354 |
] |
|
355 |
] |
|
1932 | 356 |
]. |
357 |
||
358 |
fit ifFalse:[ |
|
2835 | 359 |
('Depth8Image [info]: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR. |
1932 | 360 |
|
2835 | 361 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
362 |
dColors := imgMap collect:[:clr | clr isNil ifTrue:[clr] |
|
363 |
ifFalse:[clr nearestOn:aDevice]]. |
|
364 |
dColors := dColors select:[:clr | clr notNil]. |
|
365 |
dColors := dColors collect:[:clr | clr exactOn:aDevice]. |
|
366 |
dColors := dColors select:[:clr | clr notNil]. |
|
367 |
dColors := dColors asSet. |
|
368 |
dColors addAll:((aDevice colorMap collect:[:c|c onDevice:aDevice]) |
|
369 |
select:[:c | c colorId notNil]). |
|
370 |
ditherColors := aDevice availableDitherColors. |
|
371 |
ditherColors notNil ifTrue:[ |
|
372 |
dColors addAll:ditherColors. |
|
373 |
]. |
|
374 |
dColors := dColors asArray. |
|
375 |
dColors size > 256 ifTrue:[ |
|
376 |
dColors := dColors copyTo:256 |
|
377 |
]. |
|
378 |
^ self asFloydSteinbergDitheredPseudoFormUsing:dColors on:aDevice |
|
379 |
]. |
|
1932 | 380 |
|
2835 | 381 |
" |
382 |
again, this time allow wrong colors (loop while increasing allowed error) |
|
383 |
" |
|
384 |
error := 1. |
|
385 |
[fit] whileFalse:[ |
|
386 |
fit := true. |
|
387 |
usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex | |
|
388 |
|devColor color |
|
389 |
r "{Class: SmallInteger }" |
|
390 |
g "{Class: SmallInteger }" |
|
391 |
b "{Class: SmallInteger }" |
|
392 |
mapIndex "{Class: SmallInteger }" |
|
393 |
rMask "{Class: SmallInteger }" |
|
394 |
gMask "{Class: SmallInteger }" |
|
395 |
bMask "{Class: SmallInteger }"| |
|
1932 | 396 |
|
2835 | 397 |
fit ifTrue:[ |
398 |
gMask := bMask := rMask := m. |
|
1932 | 399 |
|
2835 | 400 |
mapIndex := aColorIndex + 1. |
401 |
"/ color := colorMap at:mapIndex. |
|
402 |
color := self colorFromValue:aColorIndex. |
|
403 |
r := (color red * 255 / 100.0) rounded. |
|
404 |
g := (color green * 255 / 100.0) rounded. |
|
405 |
b := (color blue * 255 / 100.0) rounded. |
|
1932 | 406 |
|
2835 | 407 |
color := Color red:((r bitShift:shift) bitAnd:rMask) * scale |
408 |
green:((g bitShift:shift) bitAnd:gMask) * scale |
|
409 |
blue:((b bitShift:shift) bitAnd:bMask) * scale. |
|
1932 | 410 |
|
3600 | 411 |
(color isOnDevice:aDevice) ifTrue:[ |
2835 | 412 |
"wow - an immediate hit" |
413 |
devColor := color. |
|
414 |
] ifFalse:[ |
|
415 |
devColor := color nearestOn:aDevice. |
|
416 |
(devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[ |
|
417 |
devColor := nil |
|
418 |
]. |
|
419 |
devColor isNil ifTrue:[ |
|
420 |
" |
|
421 |
no free color - on the first round, do a GC to flush unused |
|
422 |
colors - this may help if some colors where locked by already |
|
423 |
free images. |
|
424 |
" |
|
425 |
gcRound == 0 ifTrue:[ |
|
426 |
ObjectMemory scavenge; finalize. |
|
427 |
devColor := color nearestOn:aDevice. |
|
428 |
(devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[ |
|
429 |
devColor := nil |
|
430 |
]. |
|
431 |
gcRound := 1 |
|
432 |
]. |
|
433 |
devColor isNil ifTrue:[ |
|
434 |
gcRound == 1 ifTrue:[ |
|
435 |
CollectGarbageWhenRunningOutOfColors ifTrue:[ |
|
436 |
'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR. |
|
437 |
ObjectMemory incrementalGC; finalize. |
|
438 |
devColor := color nearestOn:aDevice. |
|
439 |
(devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[ |
|
440 |
devColor := nil |
|
441 |
]. |
|
442 |
]. |
|
443 |
gcRound := 2 |
|
444 |
] |
|
445 |
] |
|
446 |
]. |
|
447 |
]. |
|
448 |
(devColor notNil and:[devColor colorId notNil]) ifTrue:[ |
|
449 |
imgMap at:mapIndex put:devColor. |
|
450 |
lastOK := lastOK + 1. |
|
451 |
] ifFalse:[ |
|
452 |
fit := false |
|
453 |
] |
|
454 |
]. |
|
455 |
]. |
|
1932 | 456 |
|
2835 | 457 |
fit ifTrue:[ |
458 |
('Depth8Image [info]: remaining colors with error <= %1' bindWith:error) infoPrintCR. |
|
459 |
]. |
|
1932 | 460 |
|
2835 | 461 |
error := error * 2. |
462 |
error > 100 ifTrue:[ |
|
463 |
" |
|
464 |
break out, if the error becomes too big. |
|
465 |
" |
|
466 |
'Depth8Image [info]: hard color allocation problem - revert to b&w for remaining colors' infoPrintCR. |
|
467 |
" |
|
468 |
map to b&w as a last fallback. |
|
469 |
(should really do a dither here) |
|
470 |
" |
|
471 |
usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex | |
|
472 |
|color |
|
473 |
mapIndex "{ Class: SmallInteger }"| |
|
1932 | 474 |
|
2835 | 475 |
mapIndex := aColorIndex + 1. |
476 |
"/ color := colorMap at:mapIndex. |
|
477 |
color := self colorFromValue:aColorIndex. |
|
478 |
color brightness > 0.4 ifTrue:[ |
|
479 |
color := Color white. |
|
480 |
] ifFalse:[ |
|
481 |
color := Color black. |
|
482 |
]. |
|
483 |
imgMap at:mapIndex put:(color onDevice:aDevice). |
|
484 |
]. |
|
485 |
fit := true. |
|
486 |
] |
|
487 |
]. |
|
1932 | 488 |
|
2835 | 489 |
error > 10 ifTrue:[ |
490 |
'Depth8Image [info]: not enough colors for a reasonable image' infoPrintCR |
|
491 |
] ifFalse:[ |
|
492 |
'Depth8Image [info]: not enough colors for exact picture' infoPrintCR. |
|
493 |
] |
|
1932 | 494 |
]. |
495 |
||
496 |
" |
|
497 |
create translation map (from image colors to allocated colorIds) |
|
498 |
" |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
499 |
mapSize := imgMap size. |
1932 | 500 |
map := ByteArray new:256. |
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
501 |
1 to:mapSize do:[:i | |
2835 | 502 |
(clr := imgMap at:i) notNil ifTrue:[ |
503 |
map at:i put:clr colorId |
|
504 |
] |
|
1932 | 505 |
]. |
506 |
||
507 |
" |
|
508 |
does the device support 8-bit images ? |
|
509 |
" |
|
510 |
deviceDepth := aDevice depth. |
|
2529
637a5979a3d0
use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
511 |
has8BitImage := (deviceDepth == 8) |
2835 | 512 |
or:[ (aDevice supportedImageFormatForDepth:8) notNil ]. |
1932 | 513 |
|
514 |
" |
|
515 |
finally, create a form on the device and copy (& translate) |
|
516 |
the pixel values |
|
517 |
" |
|
518 |
has8BitImage ifTrue:[ |
|
2835 | 519 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
1932 | 520 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
521 |
bytes |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
522 |
expandPixels:8 "xlate only" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
523 |
width:width height:height |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
524 |
into:pseudoBits |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
525 |
mapping:map. |
1932 | 526 |
|
2835 | 527 |
map := nil. |
1932 | 528 |
|
2835 | 529 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
530 |
f isNil ifTrue:[^ nil]. |
|
531 |
f colorMap:imgMap. |
|
532 |
f initGC. |
|
533 |
aDevice |
|
534 |
drawBits:pseudoBits |
|
535 |
bitsPerPixel:8 |
|
536 |
depth:deviceDepth |
|
537 |
padding:8 |
|
538 |
width:width height:height |
|
539 |
x:0 y:0 |
|
540 |
into:(f id) x:0 y:0 |
|
541 |
width:width height:height |
|
542 |
with:(f gcId). |
|
543 |
^ f |
|
1932 | 544 |
]. |
545 |
||
546 |
" |
|
547 |
slow fall back: convert into appropriate depth image, |
|
548 |
by looping over each pixel individually |
|
549 |
" |
|
550 |
newImage := (Image implementorForDepth:deviceDepth) new. |
|
551 |
newImage width:width. |
|
552 |
newImage height:height. |
|
553 |
newImage bits:(ByteArray uninitializedNew:(height * newImage bytesPerRow)). |
|
554 |
||
555 |
0 to:height-1 do:[:row | |
|
2835 | 556 |
pixelRow := self rowAt:row. |
557 |
pixelRow |
|
558 |
expandPixels:8 "xlate only" |
|
559 |
width:width |
|
560 |
height:1 |
|
561 |
into:pixelRow |
|
562 |
mapping:map. |
|
563 |
newImage rowAt:row putAll:pixelRow |
|
1932 | 564 |
]. |
565 |
||
566 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
|
567 |
f isNil ifTrue:[^ nil]. |
|
568 |
f colorMap:imgMap. |
|
569 |
f initGC. |
|
570 |
||
1998 | 571 |
aDevice |
2835 | 572 |
drawBits:(newImage bits) |
573 |
depth:deviceDepth |
|
574 |
padding:8 |
|
575 |
width:width height:height |
|
576 |
x:0 y:0 |
|
577 |
into:(f id) x:0 y:0 |
|
578 |
width:width height:height |
|
579 |
with:(f gcId). |
|
1932 | 580 |
|
581 |
^ f |
|
582 |
||
583 |
"Modified: 15.10.1997 / 01:48:20 / cg" |
|
584 |
"Created: 19.10.1997 / 04:57:05 / cg" |
|
585 |
! |
|
586 |
||
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
587 |
anyImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
588 |
"return a true-color device-form for the receiver. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
589 |
Supports true color devices with depths: 8, 16, 24 and 32" |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
590 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
591 |
|depth |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
592 |
colorValues |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
593 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
594 |
usedDevicePadding usedDeviceBytesPerRow padd| |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
595 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
596 |
depth := aDevice depth. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
597 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
598 |
"/ gather r/g/b values for all colors in the map ... |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
599 |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
600 |
colorValues := self rgbColormapFor:aDevice. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
601 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
602 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
603 |
usedDeviceDepth := bestFormat at:#depth. |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
604 |
usedDeviceDepth == 1 ifTrue:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
605 |
^ self asMonochromeFormOn:aDevice |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
606 |
]. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
607 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
608 |
usedDevicePadding := bestFormat at:#padding. |
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
609 |
|
2006 | 610 |
usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding. |
611 |
padd := usedDeviceBytesPerRow -( self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:8). |
|
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
612 |
imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
613 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
614 |
"/ for now, only support some depths |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
615 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
616 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
617 |
"/ 16 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
618 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
619 |
"/ now, walk over the image and replace |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
620 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
621 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
622 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
623 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
624 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
625 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
626 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
627 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
628 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
629 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
630 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
631 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
632 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
633 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
634 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
635 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
636 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
637 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
638 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
639 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
640 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
641 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
642 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
643 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
644 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
645 |
&& dstPtr) { |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
646 |
int r,p; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
647 |
int x, y, w, h, nPix; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
648 |
unsigned short pixels[256]; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
649 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
650 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
651 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
652 |
nPix = __arraySize(colorValues); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
653 |
for (p=0; p<nPix; p++) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
654 |
pixels[p] = __intVal(ap[p]); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
655 |
} |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
656 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
657 |
w = __intVal(_INST(width)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
658 |
h = __intVal(_INST(height)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
659 |
r = w; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
660 |
p = __intVal(padd); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
661 |
nPix = w * h; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
662 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
663 |
while (nPix > 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
664 |
unsigned idx, v; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
665 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
666 |
if (((unsigned INT)srcPtr & 3) == 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
667 |
unsigned INT idx4; |
2296 | 668 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
669 |
while (r > 4) { |
2401 | 670 |
#ifdef __MSBFIRST |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
671 |
idx4 = ((unsigned int *)srcPtr)[0]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
672 |
v = pixels[(idx4 >> 24) & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
673 |
((short *)dstPtr)[0] = v; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
674 |
v = pixels[(idx4 >> 16) & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
675 |
((short *)dstPtr)[1] = v; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
676 |
v = pixels[(idx4 >> 8) & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
677 |
((short *)dstPtr)[2] = v; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
678 |
v = pixels[idx4 & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
679 |
((short *)dstPtr)[3] = v; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
680 |
#else |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
681 |
# ifdef __LSBFIRST |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
682 |
idx4 = ((unsigned int *)srcPtr)[0]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
683 |
v = pixels[idx4 & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
684 |
dstPtr[0] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
685 |
dstPtr[1] = (v) & 0xFF; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
686 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
687 |
v = pixels[(idx4 >> 8) & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
688 |
dstPtr[2] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
689 |
dstPtr[3] = (v) & 0xFF; |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
690 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
691 |
v = pixels[(idx4 >> 16) & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
692 |
dstPtr[4] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
693 |
dstPtr[5] = (v) & 0xFF; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
694 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
695 |
v = pixels[(idx4 >> 24) & 0xFF]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
696 |
dstPtr[6] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
697 |
dstPtr[7] = (v) & 0xFF; |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
698 |
# else /* unknown/unspecified - code below works on any machine */ |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
699 |
idx = srcPtr[0]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
700 |
v = pixels[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
701 |
dstPtr[0] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
702 |
dstPtr[1] = (v) & 0xFF; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
703 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
704 |
idx = srcPtr[1]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
705 |
v = pixels[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
706 |
dstPtr[2] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
707 |
dstPtr[3] = (v) & 0xFF; |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
708 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
709 |
idx = srcPtr[2]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
710 |
v = pixels[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
711 |
dstPtr[4] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
712 |
dstPtr[5] = (v) & 0xFF; |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
713 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
714 |
idx = srcPtr[3]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
715 |
v = pixels[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
716 |
dstPtr[6] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
717 |
dstPtr[7] = (v) & 0xFF; |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
718 |
# endif |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
719 |
#endif |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
720 |
r -= 4; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
721 |
dstPtr += 8; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
722 |
nPix -= 4; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
723 |
srcPtr +=4; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
724 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
725 |
} |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
726 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
727 |
nPix--; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
728 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
729 |
idx = *srcPtr++; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
730 |
v = pixels[idx]; |
2401 | 731 |
#ifdef __MSBFIRST |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
732 |
((short *)dstPtr)[0] = v; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
733 |
#else |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
734 |
dstPtr[0] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
735 |
dstPtr[1] = (v) & 0xFF; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
736 |
#endif |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
737 |
dstPtr += 2; |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
738 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
739 |
if (--r == 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
740 |
dstPtr += p; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
741 |
r = w; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
742 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
743 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
744 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
745 |
%}. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
746 |
] ifFalse:[ |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
747 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
748 |
"/ 32 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
749 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
750 |
"/ now, walk over the image and replace |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
751 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
752 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
753 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
754 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
755 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
756 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
757 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
758 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
759 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
760 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
761 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
762 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
763 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
764 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
765 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
766 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
767 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
768 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
769 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
770 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
771 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
772 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
773 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
774 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
775 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
776 |
&& dstPtr) { |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
777 |
int x, y, w, h, nPix; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
778 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
779 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
780 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
781 |
w = __intVal(_INST(width)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
782 |
h = __intVal(_INST(height)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
783 |
nPix = w * h; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
784 |
while (nPix > 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
785 |
unsigned idx, v; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
786 |
OBJ clr; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
787 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
788 |
idx = *srcPtr; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
789 |
clr = ap[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
790 |
v = __intVal(clr); |
2401 | 791 |
#ifdef __MSBFIRST |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
792 |
((long *)dstPtr)[0] = v; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
793 |
#else |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
794 |
dstPtr[0] = (v>>24) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
795 |
dstPtr[1] = (v>>16) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
796 |
dstPtr[2] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
797 |
dstPtr[3] = (v) & 0xFF; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
798 |
#endif |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
799 |
dstPtr += 4; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
800 |
srcPtr += 1; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
801 |
nPix--; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
802 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
803 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
804 |
%}. |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
805 |
] ifFalse:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
806 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
807 |
"/ 8 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
808 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
809 |
"/ now, walk over the image and replace |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
810 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
811 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
812 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
813 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
814 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
815 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
816 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
817 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
818 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
819 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
820 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
821 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
822 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
823 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
824 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
825 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
826 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
827 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
828 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
829 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
830 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
831 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
832 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
833 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
834 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
835 |
&& dstPtr) { |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
836 |
int x, y, w, h, nPix; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
837 |
int r,p; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
838 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
839 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
840 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
841 |
w = __intVal(_INST(width)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
842 |
h = __intVal(_INST(height)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
843 |
r = w; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
844 |
p = __intVal(padd); |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
845 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
846 |
nPix = w * h; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
847 |
while (nPix > 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
848 |
unsigned idx, v; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
849 |
OBJ clr; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
850 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
851 |
idx = *srcPtr; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
852 |
clr = ap[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
853 |
v = __intVal(clr); |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
854 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
855 |
dstPtr[0] = v; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
856 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
857 |
dstPtr += 1; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
858 |
srcPtr += 1; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
859 |
nPix--; |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
860 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
861 |
if (--r == 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
862 |
dstPtr += p; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
863 |
r = w; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
864 |
} |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
865 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
866 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
867 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
868 |
%}. |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
869 |
] ifFalse:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
870 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
871 |
"/ 24 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
872 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
873 |
"/ now, walk over the image and replace |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
874 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
875 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
876 |
%{ |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
877 |
unsigned char *srcPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
878 |
unsigned char *dstPtr = 0; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
879 |
OBJ _bytes = __INST(bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
880 |
|
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
881 |
if (__isByteArray(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
882 |
srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
883 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
884 |
if (__isExternalBytesLike(_bytes)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
885 |
srcPtr = __externalBytesAddress(_bytes); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
886 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
887 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
888 |
if (__isByteArray(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
889 |
dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
890 |
} else { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
891 |
if (__isExternalBytesLike(imageBits)) { |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
892 |
dstPtr = __externalBytesAddress(imageBits); |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
893 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
894 |
} |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
895 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
896 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
897 |
&& __isArray(colorValues) |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
898 |
&& srcPtr |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
899 |
&& dstPtr) { |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
900 |
int x, y, w, h, nPix; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
901 |
int r,p; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
902 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
903 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
904 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
905 |
w = __intVal(_INST(width)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
906 |
h = __intVal(_INST(height)); |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
907 |
r = w; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
908 |
p = __intVal(padd); |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
909 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
910 |
nPix = w * h; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
911 |
while (nPix > 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
912 |
unsigned idx, v; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
913 |
OBJ clr; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
914 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
915 |
idx = *srcPtr; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
916 |
clr = ap[idx]; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
917 |
v = __intVal(clr); |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
918 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
919 |
dstPtr[0] = (v>>16) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
920 |
dstPtr[1] = (v>>8) & 0xFF; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
921 |
dstPtr[2] = (v) & 0xFF; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
922 |
|
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
923 |
dstPtr += 3; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
924 |
srcPtr += 1; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
925 |
nPix--; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
926 |
if (--r == 0) { |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
927 |
dstPtr += p; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
928 |
r = w; |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
929 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
930 |
} |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
931 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
932 |
%}. |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
933 |
] |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
934 |
] |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
935 |
] |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
936 |
]. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
937 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
938 |
imageBits isNil ifTrue:[ |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
939 |
'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
940 |
^ self asMonochromeFormOn:aDevice |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
941 |
]. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
942 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
943 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
944 |
form isNil ifTrue:[^ nil]. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
945 |
form initGC. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
946 |
|
1997 | 947 |
form |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
948 |
copyBitsFrom:imageBits |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
949 |
bitsPerPixel:usedDeviceBitsPerPixel |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
950 |
depth:usedDeviceDepth |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
951 |
padding:usedDevicePadding |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
952 |
width:width height:height |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
953 |
x:0 y:0 |
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
954 |
toX:0 y:0. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
955 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
956 |
^ form |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
957 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
958 |
"Created: 20.10.1995 / 22:05:10 / cg" |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
959 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
960 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
961 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
962 |
asGray8FormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
963 |
"return an 8-bit greyForm from the 8-bit receiver image. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
964 |
Redefined, since only a translation has to be done here." |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
965 |
|
2774 | 966 |
|greyBits map| |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
967 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
968 |
greyBits := ByteArray uninitializedNew:(width * height). |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
969 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
970 |
map := ByteArray uninitializedNew:256. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
971 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
972 |
1 to:256 do:[:i | |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
973 |
map at:i put:((self colorFromValue:(i-1)) brightness * 255) rounded |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
974 |
]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
975 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
976 |
self bits |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
977 |
expandPixels:8 "xlate only" |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
978 |
width:width |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
979 |
height:height |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
980 |
into:greyBits |
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
981 |
mapping:map. |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
982 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
983 |
^ self makeDeviceGrayPixmapOn:aDevice depth:8 fromArray:greyBits |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
984 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
985 |
"Modified: 10.6.1996 / 20:10:14 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
986 |
"Created: 14.6.1996 / 15:23:09 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
987 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
988 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
989 |
asGrayFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
990 |
"get a gray device form. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
991 |
Redefined, since we can do it with simple translate, |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
992 |
if the depth matches my depth." |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
993 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
994 |
(aDevice visualType == #StaticGray) ifTrue:[ |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
995 |
(aDevice depth == 8) ifTrue:[ |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
996 |
^ self asGray8FormOn:aDevice |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
997 |
]. |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
998 |
]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
999 |
^ super asGrayFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1000 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1001 |
"Created: 10.6.1996 / 18:51:19 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1002 |
"Modified: 10.6.1996 / 18:54:36 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1003 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1004 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1005 |
greyImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1006 |
"return a pseudoForm from the gray picture. The main work is |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1007 |
in color reduction, when not all colors can be aquired." |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1008 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1009 |
^ self anyImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1010 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1011 |
"Modified: 19.10.1997 / 04:57:39 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1012 |
"Created: 19.10.1997 / 04:58:41 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1013 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1014 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1015 |
greyImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1016 |
"return a true-color device-form for the grey-image receiver. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1017 |
Supports true color devices with depths: 8, 16, 24 and 32" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1018 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1019 |
|f| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1020 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1021 |
f := self anyImageAsTrueColorFormOn:aDevice. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1022 |
f notNil ifTrue:[^ f]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1023 |
^ super greyImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1024 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1025 |
"Created: / 29.7.1998 / 00:19:46 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1026 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1027 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1028 |
paletteImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1029 |
"return a pseudoForm from the palette picture. The main work is |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1030 |
in color reduction, when not all colors can be aquired." |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1031 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1032 |
^ self anyImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1033 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1034 |
"Modified: 19.10.1997 / 04:57:39 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1035 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1036 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1037 |
paletteImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1038 |
"return a true-color device-form for the palette-image receiver. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1039 |
Supports true color devices with depths: 8, 16, 24 and 32" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1040 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1041 |
|f| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1042 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1043 |
f := self anyImageAsTrueColorFormOn:aDevice. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1044 |
f notNil ifTrue:[^ f]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1045 |
^ super paletteImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1046 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1047 |
"Created: / 24.7.1998 / 01:20:46 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1048 |
"Modified: / 29.7.1998 / 00:19:27 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1049 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1050 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1051 |
rgbImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1052 |
"return a true-color device-form for the rgb-image receiver. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1053 |
Supports true color devices with depths: 8, 16, 24 and 32" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1054 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1055 |
|f| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1056 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1057 |
f := self anyImageAsTrueColorFormOn:aDevice. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1058 |
f notNil ifTrue:[^ f]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1059 |
^ super rgbImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1060 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1061 |
"Created: / 29.7.1998 / 00:21:25 / cg" |
1 | 1062 |
! ! |
1063 |
||
810 | 1064 |
!Depth8Image methodsFor:'dither helpers'! |
1065 |
||
1782 | 1066 |
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
810 | 1067 |
"return the bitmap for a dithered depth-bitmap from the image; |
1068 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1069 |
Redefined to make use of knowing that pixels are 8-bit values." |
|
1070 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1071 |
|dH nDither bytes |
810 | 1072 |
greyLevels greyMap1 greyMap2 |
1073 |
bytesPerRow "{Class: SmallInteger }" |
|
1074 |
bytesPerOutRow "{Class: SmallInteger }" |
|
1075 |
pixelsPerByte "{Class: SmallInteger }" |
|
1076 |
outBits |
|
1077 |
w "{Class: SmallInteger }" |
|
1078 |
h "{Class: SmallInteger }" | |
|
1079 |
||
1080 |
nDither := ditherMatrix size. |
|
1081 |
dH := nDither / dW. |
|
1082 |
||
1083 |
w := width. |
|
1084 |
h := height. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1085 |
bytes := self bits. |
810 | 1086 |
|
1087 |
greyLevels := 1 bitShift:depth. |
|
1088 |
pixelsPerByte := 8 / depth. |
|
1089 |
||
1090 |
bytesPerRow := self bytesPerRow. |
|
1091 |
||
1092 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
1093 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
1094 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1095 |
^ nil |
810 | 1096 |
]. |
1097 |
||
1098 |
greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels |
|
1099 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1100 |
0 |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1101 |
] ifFalse:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1102 |
b truncated |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1103 |
] |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1104 |
]) asByteArray. |
810 | 1105 |
|
1106 |
greyMap2 := self greyMapForRange:(greyLevels-1). |
|
1107 |
greyMap2 := (greyMap2 collect:[:el | |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1108 |
el isNil ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1109 |
0 |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1110 |
] ifFalse:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1111 |
((el - el truncated) "/ the error (0..1) |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1112 |
* nDither) rounded |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1113 |
]]) asByteArray. |
810 | 1114 |
|
1115 |
%{ |
|
1116 |
int __dW = __intVal(dW); |
|
1117 |
int __dH = __intVal(dH); |
|
1118 |
int __byte; |
|
1119 |
int __dT, __dO; |
|
1120 |
int __depth = __intVal(depth); |
|
1121 |
int __dstIdx = 0; |
|
1122 |
int __srcIdx = 0; |
|
1123 |
int __bitCnt; |
|
1124 |
int __grey, __pixel; |
|
1125 |
int __w = __intVal(w); |
|
1126 |
int __h = __intVal(h); |
|
1127 |
int __x; |
|
1128 |
int __y; |
|
1129 |
int __oX, __oY, __dY; |
|
1130 |
int __nextDst; |
|
1131 |
int __nextSrc; |
|
1132 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1133 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
1134 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1135 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
810 | 1136 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1137 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
810 | 1138 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
1139 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
1140 |
||
1141 |
__oY = __dY = 0; |
|
1142 |
for (__y=0; __y<__h; __y++) { |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1143 |
__nextDst = __dstIdx + __bytesPerOutRow; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1144 |
__nextSrc = __srcIdx + __bytesPerRow; |
810 | 1145 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1146 |
__byte = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1147 |
__bitCnt = 8; |
810 | 1148 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1149 |
__oX = 0; |
810 | 1150 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1151 |
for (__x=0; __x<__w; __x++) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1152 |
__grey = __bytes[__srcIdx++]; /* 0..255 */ |
810 | 1153 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1154 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1155 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1156 |
__dT = __ditherMatrix[__dY + __oX]; |
810 | 1157 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1158 |
if (__dO > __dT) /* dither says: next pixel */ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1159 |
__pixel++; |
810 | 1160 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1161 |
__oX++; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1162 |
if (__oX == __dW) __oX = 0; |
810 | 1163 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1164 |
__byte = (__byte << __depth) | __pixel; |
810 | 1165 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1166 |
__bitCnt = __bitCnt - __depth; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1167 |
if (__bitCnt == 0) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1168 |
__outBits[__dstIdx] = __byte; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1169 |
__dstIdx++; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1170 |
__byte = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1171 |
__bitCnt = 8; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1172 |
} |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1173 |
} |
810 | 1174 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1175 |
if (__bitCnt != 8) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1176 |
__byte = __byte << __bitCnt; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1177 |
__outBits[__dstIdx] = __byte; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1178 |
} |
810 | 1179 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1180 |
__oY++; __dY += __dW; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1181 |
if (__oY == __dH) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1182 |
__oY = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1183 |
__dY = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1184 |
} |
810 | 1185 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1186 |
__srcIdx = __nextSrc; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1187 |
__dstIdx = __nextDst; |
810 | 1188 |
} |
1189 |
%}. |
|
1190 |
^ outBits |
|
1191 |
! |
|
1192 |
||
1193 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
1194 |
"return the dithered monochrome bits for the receiver image; |
|
1195 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1196 |
Redefined to make use of knowing that pixels are 8-bit values." |
|
1197 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1198 |
|dH nDither bytes |
810 | 1199 |
greyMap monoBits |
1200 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
1201 |
bytesPerRow "{Class: SmallInteger }" |
|
1202 |
w "{Class: SmallInteger }" |
|
1203 |
h "{Class: SmallInteger }"| |
|
1204 |
||
1205 |
nDither := ditherMatrix size. |
|
1206 |
dH := nDither / dW. |
|
1207 |
||
1208 |
w := width. |
|
1209 |
h := height. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1210 |
bytes := self bits. |
810 | 1211 |
|
1212 |
bytesPerRow := self bytesPerRow. |
|
1213 |
||
1214 |
bytesPerMonoRow := w + 7 // 8. |
|
1215 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
1216 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1217 |
^ nil |
810 | 1218 |
]. |
1219 |
||
1220 |
greyMap := self greyByteMapForRange:nDither. |
|
1221 |
||
1222 |
%{ |
|
1223 |
int __dW = __intVal(dW); |
|
1224 |
int __dH = __intVal(dH); |
|
1225 |
int __byte; |
|
1226 |
int __dT; |
|
1227 |
int __dstIdx = 0; |
|
1228 |
int __srcIdx = 0; |
|
1229 |
int __bitCnt; |
|
1230 |
int __grey; |
|
1231 |
int __w = __intVal(w); |
|
1232 |
int __h = __intVal(h); |
|
1233 |
int __x; |
|
1234 |
int __y; |
|
1235 |
int __oX, __oY, __dY; |
|
1236 |
int __nextDst; |
|
1237 |
int __nextSrc; |
|
1238 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1239 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
1240 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1241 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
810 | 1242 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1243 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
810 | 1244 |
unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
1245 |
||
1246 |
__oY = __dY = 0; |
|
1247 |
for (__y=0; __y<__h; __y++) { |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1248 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1249 |
__nextSrc = __srcIdx + __bytesPerRow; |
810 | 1250 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1251 |
__byte = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1252 |
__bitCnt = 8; |
810 | 1253 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1254 |
__oX = 0; |
810 | 1255 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1256 |
for (__x=__w; __x>0; __x--) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1257 |
__grey = __bytes[__srcIdx]; /* 0..255 */ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1258 |
__srcIdx++; |
810 | 1259 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1260 |
__grey = __greyMap[__grey]; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1261 |
__dT = __ditherMatrix[__dY + __oX]; |
810 | 1262 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1263 |
__oX++; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1264 |
if (__oX == __dW) __oX = 0; |
810 | 1265 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1266 |
__byte = __byte << 1; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1267 |
if (__grey > __dT) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1268 |
__byte = __byte | 1; /* white */ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1269 |
} |
810 | 1270 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1271 |
__bitCnt--; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1272 |
if (__bitCnt == 0) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1273 |
__monoBits[__dstIdx] = __byte; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1274 |
__dstIdx++; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1275 |
__byte = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1276 |
__bitCnt = 8; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1277 |
} |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1278 |
} |
810 | 1279 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1280 |
if (__bitCnt != 8) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1281 |
__byte = __byte << __bitCnt; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1282 |
__monoBits[__dstIdx] = __byte; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1283 |
} |
810 | 1284 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1285 |
__oY++; __dY += __dW; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1286 |
if (__oY == __dH) { |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1287 |
__oY = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1288 |
__dY = 0; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1289 |
} |
810 | 1290 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1291 |
__srcIdx = __nextSrc; |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1292 |
__dstIdx = __nextDst; |
810 | 1293 |
} |
1294 |
%}. |
|
1295 |
||
1296 |
^ monoBits |
|
1297 |
||
1298 |
" |
|
1299 |
|i f| |
|
1300 |
||
1609 | 1301 |
i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
810 | 1302 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
1303 |
||
1304 |
||
1305 |
|i f| |
|
1306 |
||
1609 | 1307 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
810 | 1308 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
1309 |
||
1310 |
||
1311 |
|i f| |
|
1312 |
||
1313 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
1314 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
1315 |
||
1316 |
||
1317 |
|i f| |
|
1318 |
||
1319 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
1320 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
1321 |
" |
|
1322 |
||
1323 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
1324 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
1325 |
! ! |
|
1326 |
||
579 | 1327 |
!Depth8Image methodsFor:'enumerating'! |
1 | 1328 |
|
798 | 1329 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1330 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
1331 |
The block is passed the color at each pixel. |
|
1332 |
This method allows slighly faster processing of an |
|
1333 |
image than using atX:y:, since some processing can be |
|
1334 |
avoided when going from pixel to pixel. However, for |
|
1335 |
real image processing, specialized methods should be written." |
|
1336 |
||
1337 |
|srcIndex "{ Class: SmallInteger }" |
|
1338 |
value "{ Class: SmallInteger }" |
|
1339 |
x1 "{ Class: SmallInteger }" |
|
1340 |
x2 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1341 |
color colorArray bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1342 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1343 |
bytes := self bits. |
798 | 1344 |
|
1345 |
x1 := xLow. |
|
1346 |
x2 := xHigh. |
|
1347 |
srcIndex := (width * y) + 1 + x1. |
|
1348 |
||
810 | 1349 |
colorArray := Array new:256. |
1350 |
||
941 | 1351 |
x1 to:x2 do:[:x | |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1352 |
value := bytes at:srcIndex. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1353 |
srcIndex := srcIndex + 1. |
798 | 1354 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1355 |
color := colorArray at:value+1. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1356 |
color isNil ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1357 |
color := self colorFromValue:value. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1358 |
colorArray at:value+1 put:color |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1359 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1360 |
aBlock value:x value:color |
941 | 1361 |
] |
1362 |
||
1363 |
"Created: 7.6.1996 / 19:12:35 / cg" |
|
1364 |
"Modified: 11.7.1996 / 20:22:32 / cg" |
|
1365 |
! |
|
798 | 1366 |
|
941 | 1367 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
1368 |
"perform aBlock for each pixel in the rectangle |
|
1369 |
yStart..yEnd / xStart..xEnd. |
|
1370 |
The block is passed the color at each pixel. |
|
1371 |
This method allows slighly faster processing of an |
|
1372 |
image than using individual atX:y: accesses, |
|
1373 |
both since some processing can be avoided when going from pixel to pixel, |
|
1374 |
and since the color composition is done outside of the pixel loop. |
|
1375 |
However, for real high performance image processing, specialized methods |
|
1376 |
should be written which know how to deal with specific photometric interpretations." |
|
798 | 1377 |
|
941 | 1378 |
|srcIndex "{ Class: SmallInteger }" |
1379 |
srcNext "{ Class: SmallInteger }" |
|
1380 |
bytesPerRow "{ Class: SmallInteger }" |
|
1381 |
value "{ Class: SmallInteger }" |
|
1382 |
x1 "{ Class: SmallInteger }" |
|
1383 |
x2 "{ Class: SmallInteger }" |
|
1384 |
y1 "{ Class: SmallInteger }" |
|
1385 |
y2 "{ Class: SmallInteger }" |
|
2248
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1386 |
colorArray |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1387 |
maxColor bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1388 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1389 |
bytes := self bits. |
798 | 1390 |
|
941 | 1391 |
x1 := xStart. |
1392 |
x2 := xEnd. |
|
1393 |
y1 := yStart. |
|
1394 |
y2 := yEnd. |
|
1395 |
||
1396 |
srcIndex := (width * y1) + x1 + 1 . |
|
1397 |
bytesPerRow := self bytesPerRow. |
|
1398 |
||
1399 |
colorArray := self realColorMap. |
|
2248
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1400 |
maxColor := colorArray size. |
941 | 1401 |
|
1402 |
y1 to:y2 do:[:y | |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1403 |
srcNext := srcIndex + bytesPerRow. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1404 |
x1 to:x2 do:[:x | |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1405 |
value := bytes at:srcIndex. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1406 |
srcIndex := srcIndex + 1. |
798 | 1407 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1408 |
value >= maxColor ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1409 |
value := 0. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1410 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1411 |
aBlock value:x value:y value:(colorArray at:value+1) |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1412 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1413 |
srcIndex := srcNext. |
798 | 1414 |
]. |
941 | 1415 |
^ self |
746 | 1416 |
|
2248
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1417 |
"Created: / 7.6.1996 / 19:12:35 / cg" |
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1418 |
"Modified: / 17.8.1998 / 10:17:45 / cg" |
579 | 1419 |
! |
1 | 1420 |
|
798 | 1421 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
579 | 1422 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
1423 |
The block is passed the pixelValue at each pixel. |
|
1424 |
This method allows slighly faster processing of an |
|
1425 |
image than using valueAtX:y:, since some processing can be |
|
1426 |
avoided when going from pixel to pixel. However, for |
|
1427 |
real image processing, specialized methods should be written." |
|
1 | 1428 |
|
579 | 1429 |
|srcIndex "{ Class: SmallInteger }" |
1430 |
pixelValue "{ Class: SmallInteger }" |
|
1431 |
x1 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1432 |
x2 "{ Class: SmallInteger }" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1433 |
bytes| |
1 | 1434 |
|
579 | 1435 |
x1 := xLow. |
1436 |
x2 := xHigh. |
|
1437 |
srcIndex := (width * y) + 1 + x1. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1438 |
bytes := self bits. |
579 | 1439 |
|
1440 |
x1 to:x2 do:[:x | |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1441 |
pixelValue := bytes at:srcIndex. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1442 |
srcIndex := srcIndex + 1. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1443 |
aBlock value:x value:pixelValue |
579 | 1444 |
] |
798 | 1445 |
|
1446 |
"Created: 7.6.1996 / 19:09:47 / cg" |
|
941 | 1447 |
! |
1448 |
||
1449 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
1450 |
"perform aBlock for each pixel in the rectangle |
|
1451 |
yStart..yEnd / xStart..xEnd. |
|
1452 |
The block is passed the pixelValue at each pixel. |
|
1453 |
This method allows slighly faster processing of an |
|
1454 |
image than using individual valueAtX:y: accesses, |
|
1455 |
since some processing can be avoided when going from pixel to pixel.. |
|
1456 |
However, for real high performance image processing, specialized methods |
|
1457 |
should be written which know how to deal with specific photometric interpretations." |
|
1458 |
||
1459 |
|srcIndex "{ Class: SmallInteger }" |
|
1460 |
srcNext "{ Class: SmallInteger }" |
|
1461 |
bytesPerRow "{ Class: SmallInteger }" |
|
1462 |
value "{ Class: SmallInteger }" |
|
1463 |
x1 "{ Class: SmallInteger }" |
|
1464 |
x2 "{ Class: SmallInteger }" |
|
1465 |
y1 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1466 |
y2 "{ Class: SmallInteger }" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1467 |
bytes| |
941 | 1468 |
|
1469 |
x1 := xStart. |
|
1470 |
x2 := xEnd. |
|
1471 |
y1 := yStart. |
|
1472 |
y2 := yEnd. |
|
1473 |
||
1474 |
srcIndex := (width * y1) + x1 + 1 . |
|
1475 |
bytesPerRow := self bytesPerRow. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1476 |
bytes := self bits. |
941 | 1477 |
|
1478 |
y1 to:y2 do:[:y | |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1479 |
srcNext := srcIndex + bytesPerRow. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1480 |
x1 to:x2 do:[:x | |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1481 |
value := bytes at:srcIndex. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1482 |
srcIndex := srcIndex + 1. |
941 | 1483 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1484 |
aBlock value:x value:y value:value |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1485 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1486 |
srcIndex := srcNext. |
941 | 1487 |
]. |
1488 |
^ self |
|
1489 |
||
1490 |
"Modified: 11.7.1996 / 20:06:47 / cg" |
|
1491 |
"Created: 11.7.1996 / 20:08:11 / cg" |
|
1 | 1492 |
! ! |
1493 |
||
12 | 1494 |
!Depth8Image methodsFor:'image manipulations'! |
1495 |
||
1577 | 1496 |
hardMagnifiedBy:scalePoint |
1497 |
"return a new image magnified by scalePoint, aPoint. |
|
12 | 1498 |
This is the general magnification method, handling non-integral values" |
1 | 1499 |
|
1500 |
|mX mY |
|
1501 |
newWidth "{ Class: SmallInteger }" |
|
1502 |
newHeight "{ Class: SmallInteger }" |
|
89 | 1503 |
w "{ Class: SmallInteger }" |
1 | 1504 |
h "{ Class: SmallInteger }" |
1505 |
newImage newBytes |
|
1506 |
value "{ Class: SmallInteger }" |
|
1507 |
srcRowIdx "{ Class: SmallInteger }" |
|
1508 |
srcIndex "{ Class: SmallInteger }" |
|
1577 | 1509 |
dstIndex "{ Class: SmallInteger }" |
1510 |
newMask| |
|
1 | 1511 |
|
1577 | 1512 |
mX := scalePoint x. |
1513 |
mY := scalePoint y. |
|
1 | 1514 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
1515 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
1516 |
||
1517 |
newWidth := (width * mX) truncated. |
|
1518 |
newHeight := (height * mY) truncated. |
|
1519 |
||
1520 |
newBytes := ByteArray uninitializedNew:(newWidth * newHeight). |
|
1521 |
||
1577 | 1522 |
mask notNil ifTrue:[ |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1523 |
newMask := (mask magnifiedBy:scalePoint) |
1577 | 1524 |
]. |
1525 |
||
1 | 1526 |
newImage := self species new. |
887 | 1527 |
newImage |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1528 |
width:newWidth |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1529 |
height:newHeight |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1530 |
photometric:photometric |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1531 |
samplesPerPixel:samplesPerPixel |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1532 |
bitsPerSample:#(8) |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1533 |
colorMap:colorMap copy |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1534 |
bits:newBytes |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1535 |
mask:newMask. |
1 | 1536 |
|
1537 |
"walk over destination image fetching pixels from source image" |
|
1538 |
||
1539 |
mY := mY asFloat. |
|
1540 |
mX := mX asFloat. |
|
1541 |
%{ |
|
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
1542 |
unsigned char *__dstP = __ByteArrayInstPtr(newBytes)->ba_element; |
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
1543 |
unsigned char *__srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
1658 | 1544 |
unsigned char *__srcRowP; |
1545 |
int __width = __intVal(_INST(width)); |
|
1546 |
int __w = __intVal(newWidth) - 1; |
|
1547 |
int __h = __intVal(newHeight) - 1; |
|
1548 |
int __row, __col; |
|
1549 |
double __mX = _floatVal(mX); |
|
1550 |
double __mY = _floatVal(mY); |
|
1 | 1551 |
|
1658 | 1552 |
for (__row = 0; __row <= __h; __row++) { |
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1553 |
__srcRowP = __srcP + (__width * (int)((double)__row / __mY)); |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1554 |
for (__col = 0; __col <= __w; __col++) { |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1555 |
*__dstP++ = __srcRowP[(int)((double)__col / __mX)]; |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1556 |
} |
1 | 1557 |
} |
1558 |
%} |
|
1559 |
. |
|
89 | 1560 |
"/ the above C-code is equivalent to: |
1561 |
"/ |
|
1562 |
"/ dstIndex := 1. |
|
1563 |
"/ w := newWidth - 1. |
|
1564 |
"/ h := newHeight - 1. |
|
1565 |
"/ 0 to:h do:[:row | |
|
1566 |
"/ srcRowIdx := (width * (row // mY)) + 1. |
|
1567 |
"/ 0 to:w do:[:col | |
|
1568 |
"/ srcIndex := srcRowIdx + (col // mX). |
|
1569 |
"/ value := bytes at:srcIndex. |
|
1570 |
"/ newBytes at:dstIndex put:value. |
|
1571 |
"/ dstIndex := dstIndex + 1 |
|
1572 |
"/ ] |
|
1573 |
"/ ]. |
|
1574 |
"/ |
|
1 | 1575 |
|
1576 |
^ newImage |
|
579 | 1577 |
! |
1578 |
||
1579 |
magnifyRowFrom:srcBytes offset:srcStart |
|
3842 | 1580 |
into:dstBytes offset:dstStart factor:mX |
579 | 1581 |
|
1582 |
"magnify a single pixel row - can only magnify by integer factors. |
|
1583 |
Specially tuned for factors 2,3 and 4." |
|
1584 |
||
1585 |
%{ |
|
1586 |
REGISTER unsigned char *srcP, *dstP; |
|
1587 |
REGISTER unsigned char _byte; |
|
2184
b8daa402967f
tuned magnification by multiples-of-2
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1588 |
unsigned _word; |
579 | 1589 |
int _mag; |
1590 |
REGISTER int i; |
|
1591 |
int _pixels; |
|
1592 |
OBJ w = _INST(width); |
|
1593 |
||
1594 |
if (__bothSmallInteger(srcStart, dstStart) |
|
1595 |
&& __bothSmallInteger(w, mX) |
|
1596 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
|
3842 | 1597 |
_mag = __intVal(mX); |
1598 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
|
1599 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
|
1600 |
_pixels = __intVal(w); |
|
579 | 1601 |
|
3842 | 1602 |
switch (_mag) { |
1603 |
case 1: |
|
1604 |
break; |
|
579 | 1605 |
|
3842 | 1606 |
case 2: |
1607 |
/* special code for common case */ |
|
1608 |
if (((INT)dstP & 1) == 0) { |
|
1609 |
while (_pixels--) { |
|
1610 |
_byte = *srcP++; |
|
1611 |
_word = (_byte<<8) | _byte; |
|
1612 |
((short *)dstP)[0] = _word; |
|
1613 |
dstP += 2; |
|
1614 |
} |
|
1615 |
} else { |
|
1616 |
while (_pixels--) { |
|
1617 |
_byte = *srcP++; |
|
1618 |
*dstP++ = _byte; |
|
1619 |
*dstP++ = _byte; |
|
1620 |
} |
|
1621 |
} |
|
1622 |
break; |
|
2184
b8daa402967f
tuned magnification by multiples-of-2
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1623 |
|
3842 | 1624 |
case 3: |
1625 |
/* special code for common case */ |
|
1626 |
while (_pixels--) { |
|
1627 |
_byte = *srcP++; |
|
1628 |
*dstP++ = _byte; |
|
1629 |
*dstP++ = _byte; |
|
1630 |
*dstP++ = _byte; |
|
1631 |
} |
|
1632 |
break; |
|
579 | 1633 |
|
3842 | 1634 |
case 4: |
1635 |
/* special code for common case */ |
|
1636 |
if (((INT)dstP & 3) == 0) { |
|
1637 |
while (_pixels--) { |
|
1638 |
_byte = *srcP++; |
|
1639 |
_word = (_byte<<8) | _byte; |
|
1640 |
_word = (_word<<16) | _word; |
|
1641 |
((int *)dstP)[0] = _word; |
|
1642 |
dstP += 4; |
|
1643 |
} |
|
1644 |
} else { |
|
1645 |
while (_pixels--) { |
|
1646 |
_byte = *srcP++; |
|
1647 |
*dstP++ = _byte; |
|
1648 |
*dstP++ = _byte; |
|
1649 |
*dstP++ = _byte; |
|
1650 |
*dstP++ = _byte; |
|
1651 |
} |
|
1652 |
} |
|
1653 |
break; |
|
579 | 1654 |
|
3842 | 1655 |
default: |
1656 |
if ((((INT)dstP & 1) == 0) |
|
1657 |
&& ((_mag & 1) == 0)) { |
|
1658 |
while (_pixels--) { |
|
1659 |
_byte = *srcP++; |
|
1660 |
_word = (_byte<<8) | _byte; |
|
1661 |
for (i=_mag; i>0; i-=2) { |
|
1662 |
((short *)dstP)[0] = _word; |
|
1663 |
dstP += 2; |
|
1664 |
} |
|
1665 |
} |
|
1666 |
} else { |
|
1667 |
while (_pixels--) { |
|
1668 |
_byte = *srcP++; |
|
1669 |
for (i=_mag; i>0; i--) |
|
1670 |
*dstP++ = _byte; |
|
1671 |
} |
|
1672 |
} |
|
1673 |
break; |
|
1674 |
} |
|
1675 |
RETURN (self); |
|
579 | 1676 |
} |
3842 | 1677 |
%}. |
1678 |
super |
|
1679 |
magnifyRowFrom:srcBytes offset:srcStart |
|
1680 |
into:dstBytes offset:dstStart factor:mX |
|
1 | 1681 |
! ! |
579 | 1682 |
|
1683 |
!Depth8Image methodsFor:'private'! |
|
1684 |
||
1685 |
dither1PlaneUsingMap:map on:aDevice |
|
1686 |
"a helper for dithering palette and greyscale images" |
|
1687 |
||
1688 |
|f |
|
1689 |
patterns formBytes |
|
1690 |
pixel0bytes pixel1bytes |
|
1691 |
clr ditherPattern |
|
1692 |
nColors "{Class: SmallInteger }" |
|
1693 |
w "{Class: SmallInteger }" |
|
1694 |
h "{Class: SmallInteger }"| |
|
1695 |
||
1696 |
nColors := map size. |
|
1697 |
w := width. |
|
1698 |
h := height. |
|
1699 |
||
1700 |
formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h. |
|
1701 |
patterns := Array new:nColors. |
|
1702 |
pixel0bytes := ByteArray uninitializedNew:nColors. |
|
1703 |
pixel1bytes := ByteArray uninitializedNew:nColors. |
|
1704 |
||
1705 |
" |
|
1706 |
extract dither patterns and values to use for 1/0 bits |
|
1707 |
in those from the dithercolors |
|
1708 |
" |
|
1709 |
1 to:nColors do:[:i | |
|
2835 | 1710 |
clr := (map at:i) onDevice:aDevice. |
1711 |
ditherPattern := clr ditherForm. |
|
579 | 1712 |
|
2835 | 1713 |
ditherPattern isNil ifTrue:[ |
1714 |
patterns at:i put:#[2r11111111 |
|
1715 |
2r11111111 |
|
1716 |
2r11111111 |
|
1717 |
2r11111111 |
|
1718 |
2r11111111 |
|
1719 |
2r11111111 |
|
1720 |
2r11111111 |
|
1721 |
2r11111111]. |
|
1722 |
pixel0bytes at:i put:clr colorId. |
|
1723 |
pixel1bytes at:i put:clr colorId |
|
1724 |
] ifFalse:[ |
|
1725 |
patterns at:i put:(ditherPattern bits). |
|
1726 |
pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId. |
|
1727 |
pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId. |
|
1728 |
]. |
|
579 | 1729 |
]. |
1730 |
||
1731 |
%{ |
|
1732 |
unsigned char *_srcP, *_dstP; |
|
1733 |
OBJ _patternBytes; |
|
1658 | 1734 |
unsigned char __mask = 0x80; |
579 | 1735 |
unsigned char _outBits = 0; |
1736 |
unsigned char _last, _v, _patternBits, _p0, _p1; |
|
1737 |
int _h, _w; |
|
1738 |
int _patternOffset = 0; |
|
1739 |
||
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
1740 |
_srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
1741 |
_dstP = __ByteArrayInstPtr(formBytes)->ba_element; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
1742 |
for (_h = __intVal(h); _h; _h--) { |
2835 | 1743 |
_last = -1; |
1744 |
for (_w = __intVal(w); _w; _w--) { |
|
1745 |
_v = *_srcP++; |
|
1746 |
if (_v != _last) { |
|
1747 |
_patternBytes = __ArrayInstPtr(patterns)->a_element[_v]; |
|
1748 |
if (__isByteArray(_patternBytes)) { |
|
1749 |
_patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset]; |
|
1750 |
} else if (__isArray(_patternBytes)) { |
|
1751 |
_patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]); |
|
1752 |
} |
|
1753 |
_p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v]; |
|
1754 |
_p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v]; |
|
1755 |
_last = _v; |
|
1756 |
} |
|
1757 |
_outBits <<= 1; |
|
1758 |
if (_patternBits & __mask) |
|
1759 |
_outBits |= _p1; |
|
1760 |
else |
|
1761 |
_outBits |= _p0; |
|
1762 |
__mask >>= 1; |
|
1763 |
if (__mask == 0) { |
|
1764 |
__mask = 0x80; |
|
1765 |
*_dstP++ = _outBits; |
|
1766 |
_outBits = 0; |
|
1767 |
} |
|
1768 |
} |
|
1769 |
if (__mask != 0x80) { |
|
1770 |
while (__mask != 0) { |
|
1771 |
_outBits <<= 1; |
|
1772 |
__mask >>= 1; |
|
1773 |
} |
|
1774 |
*_dstP++ = _outBits; |
|
1775 |
__mask = 0x80; |
|
1776 |
_outBits = 0; |
|
1777 |
} |
|
1778 |
_patternOffset++; |
|
1779 |
if (_patternOffset == 8) |
|
1780 |
_patternOffset = 0; |
|
579 | 1781 |
} |
1782 |
%} |
|
1783 |
. |
|
1784 |
f := Form width:w height:h fromArray:formBytes. |
|
1785 |
^ f |
|
1786 |
! |
|
1787 |
||
1788 |
dither2PlaneUsingMap:map on:aDevice |
|
1789 |
"a helper for dithering palette and greyscale images" |
|
1790 |
||
1791 |
|f |
|
1792 |
patterns formBytes |
|
1793 |
pixel0bytes pixel1bytes |
|
1794 |
clr ditherPattern |
|
1795 |
nColors "{Class: SmallInteger }" |
|
1796 |
w "{Class: SmallInteger }" |
|
1797 |
h "{Class: SmallInteger }"| |
|
1798 |
||
1799 |
nColors := map size. |
|
1800 |
w := width. |
|
1801 |
h := height. |
|
1802 |
||
1803 |
formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h. |
|
1804 |
patterns := Array new:nColors. |
|
1805 |
pixel0bytes := ByteArray uninitializedNew:nColors. |
|
1806 |
pixel1bytes := ByteArray uninitializedNew:nColors. |
|
1807 |
||
1808 |
"extract dither patterns and values to use for 1/0 bits |
|
1809 |
in those from the dithercolors" |
|
1810 |
||
1811 |
1 to:nColors do:[:i | |
|
2835 | 1812 |
clr := (map at:i) onDevice:aDevice. |
1813 |
ditherPattern := clr ditherForm. |
|
579 | 1814 |
|
2835 | 1815 |
ditherPattern isNil ifTrue:[ |
1816 |
patterns at:i put:#[2r11111111 |
|
1817 |
2r11111111 |
|
1818 |
2r11111111 |
|
1819 |
2r11111111 |
|
1820 |
2r11111111 |
|
1821 |
2r11111111 |
|
1822 |
2r11111111 |
|
1823 |
2r11111111]. |
|
1824 |
pixel0bytes at:i put:clr colorId. |
|
1825 |
pixel1bytes at:i put:clr colorId |
|
1826 |
] ifFalse:[ |
|
1827 |
patterns at:i put:(ditherPattern bits). |
|
1828 |
pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId. |
|
1829 |
pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId. |
|
1830 |
]. |
|
579 | 1831 |
]. |
1832 |
||
1833 |
%{ |
|
1834 |
unsigned char *_srcP, *_dstP; |
|
1835 |
OBJ _patternBytes; |
|
1658 | 1836 |
unsigned char __mask = 0x80; |
579 | 1837 |
unsigned char _outBits = 0; |
1838 |
unsigned char _last, _v, _patternBits, _p0, _p1; |
|
1839 |
int _h, _w; |
|
1840 |
int _patternOffset = 0; |
|
1841 |
int _outCount; |
|
1842 |
||
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
1843 |
_srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
1844 |
_dstP = __ByteArrayInstPtr(formBytes)->ba_element; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
1845 |
for (_h = __intVal(h); _h; _h--) { |
2835 | 1846 |
_last = -1; |
1847 |
_outCount = 0; |
|
1848 |
for (_w = __intVal(w); _w; _w--) { |
|
1849 |
_v = *_srcP++; |
|
1850 |
if (_v != _last) { |
|
1851 |
_patternBytes = __ArrayInstPtr(patterns)->a_element[_v]; |
|
1852 |
if (__isByteArray(_patternBytes)) { |
|
1853 |
_patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset]; |
|
1854 |
} else if (__isArray(_patternBytes)) { |
|
1855 |
_patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]); |
|
1856 |
} |
|
1857 |
_p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v]; |
|
1858 |
_p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v]; |
|
1859 |
_last = _v; |
|
1860 |
} |
|
1861 |
_outBits <<= 2; |
|
1862 |
if (_patternBits & __mask) |
|
1863 |
_outBits |= _p1; |
|
1864 |
else |
|
1865 |
_outBits |= _p0; |
|
1866 |
__mask >>= 1; |
|
1867 |
_outCount++; |
|
1868 |
if (_outCount == 4) { |
|
1869 |
*_dstP++ = _outBits; |
|
1870 |
_outCount = 0; |
|
1871 |
if (__mask == 0) { |
|
1872 |
__mask = 0x80; |
|
1873 |
} |
|
1874 |
} |
|
1875 |
} |
|
1876 |
if (_outCount) { |
|
1877 |
do { |
|
1878 |
_outBits <<= 2; |
|
1879 |
} while (++_outCount != 4); |
|
1880 |
*_dstP++ = _outBits; |
|
1881 |
} |
|
1882 |
__mask = 0x80; |
|
1883 |
_outBits = 0; |
|
1884 |
_patternOffset++; |
|
1885 |
if (_patternOffset == 8) |
|
1886 |
_patternOffset = 0; |
|
579 | 1887 |
} |
1888 |
%} |
|
1889 |
. |
|
1890 |
f := Form width:w height:h depth:2. |
|
1891 |
f initGC. |
|
927
c4bc2a7ff733
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
1892 |
f graphicsDevice |
2835 | 1893 |
drawBits:formBytes |
1894 |
depth:2 |
|
1895 |
padding:8 |
|
1896 |
width:w height:h |
|
1897 |
x:0 y:0 |
|
1898 |
into:f id |
|
1899 |
x:0 y:0 |
|
1900 |
width:w height:h |
|
1901 |
with:f gcId. |
|
579 | 1902 |
^ f |
1903 |
! ! |
|
1904 |
||
1905 |
!Depth8Image methodsFor:'queries'! |
|
1906 |
||
1907 |
bitsPerPixel |
|
1908 |
"return the number of bits per pixel" |
|
1909 |
||
1910 |
^ 8 |
|
1911 |
! |
|
1912 |
||
1913 |
bitsPerRow |
|
1914 |
"return the number of bits in one scanline of the image" |
|
1915 |
||
3868 | 1916 |
^ width * 8 |
579 | 1917 |
! |
1918 |
||
1919 |
bytesPerRow |
|
1920 |
"return the number of bytes in one scanline of the image" |
|
1921 |
||
1922 |
^ width |
|
1923 |
! |
|
1924 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1925 |
colorFromValue:pixelValue |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1926 |
"given a pixel value, return the corresponding color. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1927 |
Pixel values start with 0." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1928 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1929 |
photometric == #whiteIs0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1930 |
^ Color gray:100 - (100 / 255 * pixelValue) |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1931 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1932 |
photometric == #blackIs0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1933 |
^ Color gray:(100 / 255 * pixelValue) |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1934 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1935 |
photometric == #palette ifTrue:[ |
3869 | 1936 |
pixelValue < colorMap size ifTrue:[ |
1937 |
^ colorMap at:(pixelValue + 1) |
|
1938 |
] |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1939 |
]. |
3869 | 1940 |
^ super colorFromValue:pixelValue |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1941 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1942 |
|
3273
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1943 |
realUsedValues |
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1944 |
"return a collection of color values used in the receiver." |
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1945 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1946 |
^ self bits usedValues |
3273
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1947 |
! |
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1948 |
|
579 | 1949 |
usedValues |
1950 |
"return a collection of color values used in the receiver." |
|
1951 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1952 |
^ self bits usedValues |
579 | 1953 |
! ! |
1954 |
||
1167 | 1955 |
!Depth8Image class methodsFor:'documentation'! |
579 | 1956 |
|
1957 |
version |
|
3900 | 1958 |
^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.105 2003-06-28 22:21:44 cg Exp $' |
579 | 1959 |
! ! |