author | mawalch |
Thu, 07 Jul 2016 20:21:42 +0200 | |
changeset 7407 | 42d2b51f3c19 |
parent 7361 | ebd5415005b8 |
child 7424 | 79d2310a0c43 |
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 |
" |
|
3263 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
6837 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Image subclass:#Depth8Image |
579 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Graphics-Images' |
|
1 | 21 |
! |
22 |
||
1167 | 23 |
!Depth8Image class methodsFor:'documentation'! |
46 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
71 | 28 |
All Rights Reserved |
5 | 29 |
|
46 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
5 | 38 |
|
46 | 39 |
documentation |
40 |
" |
|
41 |
this class represents 256-color (8 bit / pixel) images (palette, greyscale ...). |
|
42 |
It mainly consists of methods already implemented in Image, |
|
43 |
reimplemented here for more performance. |
|
611 | 44 |
|
45 |
[author:] |
|
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
46 |
Claus Gittinger |
611 | 47 |
|
48 |
[see also:] |
|
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
49 |
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
|
50 |
ImageReader |
46 | 51 |
" |
52 |
! ! |
|
5 | 53 |
|
1167 | 54 |
!Depth8Image class methodsFor:'queries'! |
89 | 55 |
|
4889 | 56 |
defaultPhotometric |
6310 | 57 |
"return the default photometric pixel interpretation. |
58 |
This may be a somewhat old leftover from times, when tiff was the first image file type to be read. |
|
59 |
Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one. |
|
60 |
However, in the meantime, many other classes depend on that, so that it should be kept as an API |
|
61 |
- even when the internal representation will be replaced by something better in the future." |
|
62 |
||
4889 | 63 |
^ #palette |
64 |
! |
|
65 |
||
89 | 66 |
imageDepth |
579 | 67 |
"return the depth of images represented by instances of |
68 |
this class - here we return 8" |
|
1 | 69 |
|
70 |
^ 8 |
|
71 |
||
579 | 72 |
"Modified: 20.4.1996 / 23:40:22 / cg" |
81 | 73 |
! ! |
74 |
||
3263 | 75 |
!Depth8Image methodsFor:'accessing-pixels'! |
1 | 76 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
77 |
pixelAtX:x y:y |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
78 |
"retrieve a pixel at x/y; return a pixelValue. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
82 |
|index "{ Class: SmallInteger }"| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
83 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
84 |
%{ /* NOCONTEXT */ |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
85 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
86 |
OBJ b = __INST(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
87 |
OBJ w = __INST(width); |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
88 |
|
5472
5508a0ac6319
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5453
diff
changeset
|
89 |
if (__isByteArrayLike(b) |
4718 | 90 |
&& __bothSmallInteger(x, y) |
7276 | 91 |
&& __isSmallInteger(w) |
92 |
&& (__INST(pixelFunction)==nil) ) { |
|
6299 | 93 |
int _idx, _pix; |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
94 |
|
6299 | 95 |
_idx = (__intVal(w) * __intVal(y)) + __intVal(x); |
96 |
if ((unsigned)_idx < __byteArraySize(b)) { |
|
97 |
_pix = __ByteArrayInstPtr(b)->ba_element[_idx]; |
|
98 |
RETURN( __MKSMALLINT(_pix) ); |
|
99 |
} |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
100 |
} |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
101 |
%}. |
6299 | 102 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
103 |
||
3842 | 104 |
"/ the code below is only evaluated if the bytes-collection is |
105 |
"/ 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
|
106 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
107 |
index := (width * y) + 1 + x. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
108 |
^ bytes at:index. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
109 |
! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
110 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
111 |
pixelAtX:x y:y put:aPixelValue |
1 | 112 |
"set the pixel at x/y to aPixelValue. |
113 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
114 |
x = width-1, y=height-1 for lower right pixel" |
|
115 |
||
116 |
|index "{ Class: SmallInteger }"| |
|
117 |
||
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
118 |
%{ /* NOCONTEXT */ |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
119 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
120 |
OBJ b = __INST(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
121 |
OBJ w = __INST(width); |
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
122 |
|
5472
5508a0ac6319
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5453
diff
changeset
|
123 |
if (__isByteArrayLike(b) |
4718 | 124 |
&& __bothSmallInteger(x, y) |
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
125 |
&& __bothSmallInteger(w, aPixelValue) ) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
126 |
int _idx; |
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
127 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
128 |
_idx = (__intVal(w) * __intVal(y)) + __intVal(x); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
129 |
if ((unsigned)_idx < __byteArraySize(b)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
130 |
__ByteArrayInstPtr(b)->ba_element[_idx] = __intVal(aPixelValue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
131 |
RETURN( self ); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
132 |
} |
1634
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
133 |
} |
72ee64fad9fe
tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
134 |
%}. |
3842 | 135 |
"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
|
136 |
|
1 | 137 |
index := (width * y) + 1 + x. |
138 |
bytes at:index put:aPixelValue. |
|
139 |
! |
|
140 |
||
3872 | 141 |
rowAt:y into:aPixelBuffer startingAt:startIndex |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
142 |
"fill aPixelBuffer with pixel values from a single row. |
3872 | 143 |
Notice: row coordinate starts at 0." |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
144 |
|
5851
ce6442599a43
changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
5472
diff
changeset
|
145 |
|srcIdx endIndex n| |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
146 |
|
3872 | 147 |
bytes notNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
148 |
srcIdx := (y * width) + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
149 |
n := width. |
5851
ce6442599a43
changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
5472
diff
changeset
|
150 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
151 |
endIndex := srcIdx+width-1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
152 |
endIndex > bytes size ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
153 |
self assert:(bytes size >= endIndex). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
154 |
endIndex := bytes size. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
155 |
n := endIndex - srcIdx + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
156 |
]. |
5851
ce6442599a43
changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
5472
diff
changeset
|
157 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
158 |
aPixelBuffer replaceFrom:startIndex to:startIndex+n-1 with:bytes startingAt:srcIdx. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
159 |
^ self. |
3872 | 160 |
]. |
161 |
^ super rowAt:y into:aPixelBuffer startingAt:startIndex |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
162 |
|
5851
ce6442599a43
changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
5472
diff
changeset
|
163 |
"Modified: / 16-02-2012 / 15:58:01 / cg" |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
164 |
! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
165 |
|
3872 | 166 |
rowAt:y putAll:pixelArray startingAt:startIndex |
167 |
"store a single rows bits from bits in the pixelArray argument; |
|
168 |
Return the pixelArray. |
|
169 |
Notice: row coordinate starts at 0." |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
170 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
171 |
|dstIdx| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
172 |
|
3872 | 173 |
dstIdx := (y * width) + 1. |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
174 |
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
|
175 |
^ pixelArray |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
176 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
177 |
"Created: 24.4.1997 / 15:49:42 / cg" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
178 |
! ! |
579 | 179 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
180 |
!Depth8Image methodsFor:'converting'! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1634
diff
changeset
|
181 |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
182 |
fromImage:anImage |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
183 |
"setup the receiver from another image. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
187 |
|srcBytesPerRow "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
188 |
srcIdx "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
189 |
dstIdx "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
190 |
w "{ Class: SmallInteger }" |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
191 |
h "{ Class: SmallInteger }" |
4718 | 192 |
srcBuffer dstBuffer srcBytes |
3900 | 193 |
srcDepth map bytes| |
2202
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 |
srcDepth := anImage depth. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
196 |
(#(1 2 4) includes:srcDepth) ifFalse:[ |
4718 | 197 |
^ super fromImage:anImage |
2202
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 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
200 |
width := w := anImage width. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
201 |
height := h := anImage height. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
202 |
bytes := ByteArray uninitializedNew:(w * h). |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
203 |
bitsPerSample := self bitsPerSample. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
204 |
samplesPerPixel := self samplesPerPixel. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
205 |
self colormapFromImage:anImage. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
206 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
207 |
colorMap isNil ifTrue:[ |
4718 | 208 |
"/ if source has no colorMap, more work is needed ... |
209 |
map := #( |
|
210 |
#[0 16rFF] |
|
211 |
#[0 16r55 16rAA 16rFF] |
|
212 |
nil |
|
213 |
#[16r00 16r11 16r22 16r33 16r44 16r55 16r66 16r77 |
|
214 |
16r88 16r99 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF] |
|
215 |
) at:srcDepth. |
|
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 |
self mask:anImage mask. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
219 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
220 |
"/ only expand & translate pixels |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
221 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
222 |
srcBytes := anImage bits. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
223 |
srcBytesPerRow := anImage bytesPerRow. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
224 |
srcBuffer := ByteArray new:srcBytesPerRow. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
225 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
226 |
dstBuffer := ByteArray new:w. |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
227 |
srcIdx := 1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
228 |
dstIdx := 1. |
3900 | 229 |
bytes := self bits. |
230 |
bytes isNil ifTrue:[ |
|
4718 | 231 |
self bits:(bytes := ByteArray new:(self bytesPerRow * self height)). |
3900 | 232 |
]. |
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
233 |
1 to:h do:[:hi | |
4718 | 234 |
srcBuffer replaceFrom:1 to:srcBytesPerRow with:srcBytes startingAt:srcIdx. |
235 |
srcBuffer expandPixels:srcDepth width:w height:1 into:dstBuffer mapping:map. |
|
236 |
bytes replaceFrom:dstIdx to:dstIdx+w-1 with:dstBuffer startingAt:1. |
|
237 |
dstIdx := dstIdx + w. |
|
238 |
srcIdx := srcIdx + srcBytesPerRow. |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
239 |
] |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
240 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
241 |
" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
242 |
|i1 i2 i4 i8 i16 i24| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
243 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
244 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
245 |
i2 := Depth2Image fromImage:i1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
246 |
i4 := Depth4Image fromImage:i1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
247 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
248 |
i8 := Depth8Image fromImage:i1. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
249 |
i8 inspect. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
250 |
i8 := Depth8Image fromImage:i2. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
251 |
i8 inspect. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
252 |
i8 := Depth8Image fromImage:i4. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
253 |
i8 inspect. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
254 |
" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
255 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
256 |
"Modified: 24.4.1997 / 14:01:14 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
257 |
! ! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
258 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
259 |
!Depth8Image methodsFor:'converting images'! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
260 |
|
1932 | 261 |
anyImageAsPseudoFormOn:aDevice |
4718 | 262 |
"return a pseudoForm from the palette picture. |
7407 | 263 |
The main work is in color reduction, when not all colors can be acquired. |
1932 | 264 |
This method works for any photometric." |
265 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
266 |
|bytes pseudoBits f gcRound has8BitImage deviceDepth |
1932 | 267 |
imgMap newImage pixelRow dColors |
268 |
usedColors usageCounts maxIndex map |
|
4718 | 269 |
fit scale lastOK error |
270 |
div |
|
1932 | 271 |
bitsPerRGB "{Class: SmallInteger }" |
272 |
shift "{Class: SmallInteger }" |
|
4718 | 273 |
m "{Class: SmallInteger }" |
274 |
mapSize "{Class: SmallInteger }" |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
275 |
cube nR nG nB ditherColors clr| |
1932 | 276 |
|
277 |
(cube := aDevice fixColors) notNil ifTrue:[ |
|
7407 | 278 |
nR := aDevice numFixRed. |
279 |
nG := aDevice numFixGreen. |
|
280 |
nB := aDevice numFixBlue. |
|
1932 | 281 |
|
7407 | 282 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
283 |
f := self |
|
284 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
285 |
colors:cube |
|
286 |
nRed:nR |
|
287 |
nGreen:nG |
|
288 |
nBlue:nB. |
|
289 |
] ifFalse:[ |
|
290 |
f := self |
|
291 |
asNearestPaintDepth8FormOn:aDevice |
|
292 |
colors:cube |
|
293 |
nRed:nR |
|
294 |
nGreen:nG |
|
295 |
nBlue:nB. |
|
296 |
]. |
|
297 |
f notNil ifTrue:[^ f]. |
|
1932 | 298 |
]. |
299 |
||
300 |
"find used colors" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
301 |
bytes := self bits. |
1932 | 302 |
usedColors := bytes usedValues. "gets us an array filled with used values" |
7407 | 303 |
"(could use bytes asBag)" |
1932 | 304 |
maxIndex := usedColors max + 1. |
305 |
||
306 |
usedColors size > 20 ifTrue:[ |
|
7407 | 307 |
('Depth8Image [info]: allocating ' , usedColors size printString , ' colors ...') infoPrintCR. |
1932 | 308 |
]. |
309 |
||
310 |
"sort by usage" |
|
311 |
usageCounts := bytes usageCounts. |
|
6039
6883ca47d798
Don't do collect:[] as:Array and select:[] as:Array
Stefan Vogel <sv@exept.de>
parents:
6036
diff
changeset
|
312 |
usageCounts := (usedColors collect:[:clr | usageCounts at:(clr + 1)]) asArray. |
1932 | 313 |
usageCounts sort:[:a :b | a > b] with:usedColors. |
314 |
||
315 |
"allocate the colors (in order of usage count)" |
|
316 |
||
317 |
imgMap := Array new:maxIndex. |
|
318 |
||
319 |
" |
|
320 |
first, try to get the exact colors ... |
|
321 |
" |
|
322 |
bitsPerRGB := aDevice bitsPerRGB. |
|
323 |
shift := (8 - bitsPerRGB) negated. |
|
324 |
m := (1 bitShift:bitsPerRGB) - 1. |
|
325 |
div := m asFloat. |
|
326 |
||
327 |
fit := true. |
|
328 |
scale := 100.0 / div. "to scale 0..255 into 0.0 .. 100.0" |
|
329 |
lastOK := 0. |
|
330 |
gcRound := 0. |
|
331 |
||
332 |
usedColors do:[:aColorIndex | |
|
7407 | 333 |
|devColor color |
334 |
r "{Class: SmallInteger }" |
|
335 |
g "{Class: SmallInteger }" |
|
336 |
b "{Class: SmallInteger }" |
|
337 |
mapIndex "{Class: SmallInteger }"| |
|
1932 | 338 |
|
7407 | 339 |
fit ifTrue:[ |
340 |
mapIndex := aColorIndex + 1. |
|
341 |
"/ color := colorMap at:mapIndex. |
|
1932 | 342 |
|
7407 | 343 |
color := self colorFromValue:aColorIndex. |
344 |
(color isOnDevice:aDevice) ifTrue:[ |
|
345 |
"wow - an immediate hit" |
|
346 |
devColor := color |
|
347 |
] ifFalse:[ |
|
348 |
devColor := color exactOn:aDevice. |
|
349 |
devColor isNil ifTrue:[ |
|
350 |
" |
|
351 |
could not allocate color - on the first round, do a GC to flush |
|
352 |
unused colors - this may help if some colors where locked by |
|
353 |
already free images. |
|
354 |
" |
|
355 |
gcRound == 0 ifTrue:[ |
|
356 |
ObjectMemory scavenge; finalize. |
|
357 |
devColor := color exactOn:aDevice. |
|
358 |
gcRound := 1 |
|
359 |
]. |
|
360 |
devColor isNil ifTrue:[ |
|
361 |
gcRound == 1 ifTrue:[ |
|
362 |
CollectGarbageWhenRunningOutOfColors ifTrue:[ |
|
363 |
'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR. |
|
364 |
ObjectMemory incrementalGC; finalize. |
|
365 |
devColor := color exactOn:aDevice. |
|
366 |
]. |
|
367 |
gcRound := 2 |
|
368 |
] |
|
369 |
] |
|
370 |
]. |
|
371 |
]. |
|
372 |
(devColor notNil and:[devColor colorId notNil]) ifTrue:[ |
|
373 |
imgMap at:mapIndex put:devColor. |
|
374 |
lastOK := lastOK + 1. |
|
375 |
] ifFalse:[ |
|
376 |
fit := false |
|
377 |
] |
|
378 |
] |
|
1932 | 379 |
]. |
380 |
||
381 |
fit ifFalse:[ |
|
7407 | 382 |
('Depth8Image [info]: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR. |
1932 | 383 |
|
7407 | 384 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
385 |
dColors := imgMap collect:[:clr | clr isNil ifTrue:[clr] |
|
386 |
ifFalse:[clr nearestOn:aDevice]]. |
|
387 |
dColors := dColors select:[:clr | clr notNil] thenCollect:[:clr | clr exactOn:aDevice]. |
|
388 |
dColors := dColors asSet. |
|
389 |
dColors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice] thenSelect:[:c | c colorId notNil]). |
|
390 |
ditherColors := aDevice availableDitherColors. |
|
391 |
ditherColors notNil ifTrue:[ |
|
392 |
dColors addAll:ditherColors. |
|
393 |
]. |
|
394 |
dColors := dColors asArray. |
|
395 |
dColors size > 256 ifTrue:[ |
|
396 |
dColors := dColors copyTo:256 |
|
397 |
]. |
|
398 |
^ self asFloydSteinbergDitheredPseudoFormUsing:dColors on:aDevice |
|
399 |
]. |
|
1932 | 400 |
|
7407 | 401 |
" |
402 |
again, this time allow wrong colors (loop while increasing allowed error) |
|
403 |
" |
|
404 |
error := 1. |
|
405 |
[fit] whileFalse:[ |
|
406 |
fit := true. |
|
407 |
usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex | |
|
408 |
|devColor color |
|
409 |
r "{Class: SmallInteger }" |
|
410 |
g "{Class: SmallInteger }" |
|
411 |
b "{Class: SmallInteger }" |
|
412 |
mapIndex "{Class: SmallInteger }" |
|
413 |
rMask "{Class: SmallInteger }" |
|
414 |
gMask "{Class: SmallInteger }" |
|
415 |
bMask "{Class: SmallInteger }"| |
|
1932 | 416 |
|
7407 | 417 |
fit ifTrue:[ |
418 |
gMask := bMask := rMask := m. |
|
1932 | 419 |
|
7407 | 420 |
mapIndex := aColorIndex + 1. |
421 |
"/ color := colorMap at:mapIndex. |
|
422 |
color := self colorFromValue:aColorIndex. |
|
423 |
r := (color red * 255 / 100.0) rounded. |
|
424 |
g := (color green * 255 / 100.0) rounded. |
|
425 |
b := (color blue * 255 / 100.0) rounded. |
|
1932 | 426 |
|
7407 | 427 |
color := Color red:((r bitShift:shift) bitAnd:rMask) * scale |
428 |
green:((g bitShift:shift) bitAnd:gMask) * scale |
|
429 |
blue:((b bitShift:shift) bitAnd:bMask) * scale. |
|
1932 | 430 |
|
7407 | 431 |
(color isOnDevice:aDevice) ifTrue:[ |
432 |
"wow - an immediate hit" |
|
433 |
devColor := color. |
|
434 |
] ifFalse:[ |
|
435 |
devColor := color nearestOn:aDevice. |
|
436 |
(devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[ |
|
437 |
devColor := nil |
|
438 |
]. |
|
439 |
devColor isNil ifTrue:[ |
|
440 |
" |
|
441 |
no free color - on the first round, do a GC to flush unused |
|
442 |
colors - this may help if some colors where locked by already |
|
443 |
free images. |
|
444 |
" |
|
445 |
gcRound == 0 ifTrue:[ |
|
446 |
ObjectMemory scavenge; finalize. |
|
447 |
devColor := color nearestOn:aDevice. |
|
448 |
(devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[ |
|
449 |
devColor := nil |
|
450 |
]. |
|
451 |
gcRound := 1 |
|
452 |
]. |
|
453 |
devColor isNil ifTrue:[ |
|
454 |
gcRound == 1 ifTrue:[ |
|
455 |
CollectGarbageWhenRunningOutOfColors ifTrue:[ |
|
456 |
'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR. |
|
457 |
ObjectMemory incrementalGC; finalize. |
|
458 |
devColor := color nearestOn:aDevice. |
|
459 |
(devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[ |
|
460 |
devColor := nil |
|
461 |
]. |
|
462 |
]. |
|
463 |
gcRound := 2 |
|
464 |
] |
|
465 |
] |
|
466 |
]. |
|
467 |
]. |
|
468 |
(devColor notNil and:[devColor colorId notNil]) ifTrue:[ |
|
469 |
imgMap at:mapIndex put:devColor. |
|
470 |
lastOK := lastOK + 1. |
|
471 |
] ifFalse:[ |
|
472 |
fit := false |
|
473 |
] |
|
474 |
]. |
|
475 |
]. |
|
1932 | 476 |
|
7407 | 477 |
fit ifTrue:[ |
478 |
('Depth8Image [info]: remaining colors with error <= %1' bindWith:error) infoPrintCR. |
|
479 |
]. |
|
1932 | 480 |
|
7407 | 481 |
error := error * 2. |
482 |
error > 100 ifTrue:[ |
|
483 |
" |
|
484 |
break out, if the error becomes too big. |
|
485 |
" |
|
486 |
'Depth8Image [info]: hard color allocation problem - revert to b&w for remaining colors' infoPrintCR. |
|
487 |
" |
|
488 |
map to b&w as a last fallback. |
|
489 |
(should really do a dither here) |
|
490 |
" |
|
491 |
usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex | |
|
492 |
|color |
|
493 |
mapIndex "{ Class: SmallInteger }"| |
|
1932 | 494 |
|
7407 | 495 |
mapIndex := aColorIndex + 1. |
496 |
"/ color := colorMap at:mapIndex. |
|
497 |
color := self colorFromValue:aColorIndex. |
|
498 |
color brightness > 0.4 ifTrue:[ |
|
499 |
color := Color white. |
|
500 |
] ifFalse:[ |
|
501 |
color := Color black. |
|
502 |
]. |
|
503 |
imgMap at:mapIndex put:(color onDevice:aDevice). |
|
504 |
]. |
|
505 |
fit := true. |
|
506 |
] |
|
507 |
]. |
|
1932 | 508 |
|
7407 | 509 |
error > 10 ifTrue:[ |
510 |
'Depth8Image [info]: not enough colors for a reasonable image' infoPrintCR |
|
511 |
] ifFalse:[ |
|
512 |
'Depth8Image [info]: not enough colors for exact picture' infoPrintCR. |
|
513 |
] |
|
1932 | 514 |
]. |
515 |
||
516 |
" |
|
517 |
create translation map (from image colors to allocated colorIds) |
|
518 |
" |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
519 |
mapSize := imgMap size. |
1932 | 520 |
map := ByteArray new:256. |
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2529
diff
changeset
|
521 |
1 to:mapSize do:[:i | |
7407 | 522 |
(clr := imgMap at:i) notNil ifTrue:[ |
523 |
map at:i put:clr colorId |
|
524 |
] |
|
1932 | 525 |
]. |
526 |
||
527 |
" |
|
528 |
does the device support 8-bit images ? |
|
529 |
" |
|
530 |
deviceDepth := aDevice depth. |
|
2529
637a5979a3d0
use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
531 |
has8BitImage := (deviceDepth == 8) |
7407 | 532 |
or:[ (aDevice supportedImageFormatForDepth:8) notNil ]. |
1932 | 533 |
|
534 |
" |
|
535 |
finally, create a form on the device and copy (& translate) |
|
536 |
the pixel values |
|
537 |
" |
|
538 |
has8BitImage ifTrue:[ |
|
7407 | 539 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
1932 | 540 |
|
7407 | 541 |
bytes |
542 |
expandPixels:8 "xlate only" |
|
543 |
width:width height:height |
|
544 |
into:pseudoBits |
|
545 |
mapping:map. |
|
1932 | 546 |
|
7407 | 547 |
map := nil. |
1932 | 548 |
|
7407 | 549 |
f := Form width:width height:height depth:deviceDepth onDevice:aDevice. |
550 |
f isNil ifTrue:[^ nil]. |
|
551 |
f colorMap:imgMap. |
|
552 |
f initGC. |
|
553 |
aDevice |
|
554 |
drawBits:pseudoBits |
|
555 |
bitsPerPixel:8 |
|
556 |
depth:deviceDepth |
|
557 |
padding:8 |
|
558 |
width:width height:height |
|
559 |
x:0 y:0 |
|
560 |
into:(f id) x:0 y:0 |
|
561 |
width:width height:height |
|
562 |
with:(f gcId). |
|
563 |
^ f |
|
1932 | 564 |
]. |
565 |
||
566 |
" |
|
567 |
slow fall back: convert into appropriate depth image, |
|
568 |
by looping over each pixel individually |
|
569 |
" |
|
570 |
newImage := (Image implementorForDepth:deviceDepth) new. |
|
571 |
newImage width:width. |
|
572 |
newImage height:height. |
|
573 |
newImage bits:(ByteArray uninitializedNew:(height * newImage bytesPerRow)). |
|
574 |
||
575 |
0 to:height-1 do:[:row | |
|
7407 | 576 |
pixelRow := self rowAt:row. |
577 |
pixelRow |
|
578 |
expandPixels:8 "xlate only" |
|
579 |
width:width |
|
580 |
height:1 |
|
581 |
into:pixelRow |
|
582 |
mapping:map. |
|
583 |
newImage rowAt:row putAll:pixelRow |
|
1932 | 584 |
]. |
585 |
||
4783
717a41ef31e4
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4764
diff
changeset
|
586 |
f := Form width:width height:height depth:deviceDepth onDevice:aDevice. |
1932 | 587 |
f isNil ifTrue:[^ nil]. |
4718 | 588 |
f colorMap:imgMap. |
1932 | 589 |
f initGC. |
590 |
||
1998 | 591 |
aDevice |
7407 | 592 |
drawBits:(newImage bits) |
593 |
depth:deviceDepth |
|
594 |
padding:8 |
|
595 |
width:width height:height |
|
596 |
x:0 y:0 |
|
597 |
into:(f id) x:0 y:0 |
|
598 |
width:width height:height |
|
599 |
with:(f gcId). |
|
1932 | 600 |
|
601 |
^ f |
|
602 |
||
603 |
"Modified: 15.10.1997 / 01:48:20 / cg" |
|
604 |
"Created: 19.10.1997 / 04:57:05 / cg" |
|
605 |
! |
|
606 |
||
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
607 |
anyImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
608 |
"return a true-color device-form for the receiver. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
609 |
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
|
610 |
|
4718 | 611 |
|depth |
612 |
colorValues |
|
613 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
614 |
usedDevicePadding usedDeviceBytesPerRow padd| |
1603
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 |
depth := aDevice depth. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
617 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
618 |
"/ 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
|
619 |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
620 |
colorValues := self rgbColormapFor:aDevice. |
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 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
623 |
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
|
624 |
usedDeviceDepth == 1 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
625 |
^ self asMonochromeFormOn:aDevice |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
626 |
]. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
627 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
628 |
usedDevicePadding := bestFormat at:#padding. |
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
629 |
|
2006 | 630 |
usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding. |
631 |
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
|
632 |
imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
633 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
634 |
"/ for now, only support some depths |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
635 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
636 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
637 |
"/ 16 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
638 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
639 |
"/ now, walk over the image and replace |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
640 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
641 |
|
4718 | 642 |
%{ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
643 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
644 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
645 |
OBJ _bytes = __INST(bytes); |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
646 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
647 |
if (__isByteArrayLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
648 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
649 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
650 |
if (__isExternalBytesLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
651 |
srcPtr = __externalBytesAddress(_bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
652 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
653 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
654 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
655 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
656 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
657 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
658 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
659 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
660 |
} |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
661 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
662 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
663 |
&& __isArrayLike(colorValues) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
664 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
665 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
666 |
int r,p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
667 |
int x, y, w, h, nPix; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
668 |
unsigned short pixels[256]; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
669 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
670 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
671 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
672 |
nPix = __arraySize(colorValues); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
673 |
for (p=0; p<nPix; p++) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
674 |
pixels[p] = __intVal(ap[p]); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
675 |
} |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
676 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
677 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
678 |
h = __intVal(__INST(height)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
679 |
r = w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
680 |
p = __intVal(padd); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
681 |
nPix = w * h; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
682 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
683 |
while (nPix > 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
684 |
unsigned idx, v; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
685 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
686 |
if (((unsigned INT)srcPtr & 3) == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
687 |
unsigned INT idx4; |
2296 | 688 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
689 |
while (r > 4) { |
4718 | 690 |
#ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
691 |
idx4 = ((unsigned int *)srcPtr)[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
692 |
v = pixels[(idx4 >> 24) & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
693 |
((short *)dstPtr)[0] = v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
694 |
v = pixels[(idx4 >> 16) & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
695 |
((short *)dstPtr)[1] = v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
696 |
v = pixels[(idx4 >> 8) & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
697 |
((short *)dstPtr)[2] = v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
698 |
v = pixels[idx4 & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
699 |
((short *)dstPtr)[3] = v; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
700 |
#else |
4718 | 701 |
# ifdef __LSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
702 |
idx4 = ((unsigned int *)srcPtr)[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
703 |
v = pixels[idx4 & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
704 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
705 |
dstPtr[1] = (v) & 0xFF; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
706 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
707 |
v = pixels[(idx4 >> 8) & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
708 |
dstPtr[2] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
709 |
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
|
710 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
711 |
v = pixels[(idx4 >> 16) & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
712 |
dstPtr[4] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
713 |
dstPtr[5] = (v) & 0xFF; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
714 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
715 |
v = pixels[(idx4 >> 24) & 0xFF]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
716 |
dstPtr[6] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
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 |
# else /* unknown/unspecified - code below works on any machine */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
719 |
idx = srcPtr[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
720 |
v = pixels[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
721 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
722 |
dstPtr[1] = (v) & 0xFF; |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
723 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
724 |
idx = srcPtr[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
725 |
v = pixels[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
726 |
dstPtr[2] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
727 |
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
|
728 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
729 |
idx = srcPtr[2]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
730 |
v = pixels[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
731 |
dstPtr[4] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
732 |
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
|
733 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
734 |
idx = srcPtr[3]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
735 |
v = pixels[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
736 |
dstPtr[6] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
737 |
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
|
738 |
# endif |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
739 |
#endif |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
740 |
r -= 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
741 |
dstPtr += 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
742 |
nPix -= 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
743 |
srcPtr +=4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
744 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
745 |
} |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
746 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
747 |
nPix--; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
748 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
749 |
idx = *srcPtr++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
750 |
v = pixels[idx]; |
2401 | 751 |
#ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
752 |
((short *)dstPtr)[0] = v; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
753 |
#else |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
754 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
755 |
dstPtr[1] = (v) & 0xFF; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
756 |
#endif |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
757 |
dstPtr += 2; |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
758 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
759 |
if (--r == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
760 |
dstPtr += p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
761 |
r = w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
762 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
763 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
764 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
765 |
%}. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
766 |
] ifFalse:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
767 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
768 |
"/ 32 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
769 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
770 |
"/ now, walk over the image and replace |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
771 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
772 |
|
4718 | 773 |
%{ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
774 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
775 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
776 |
OBJ _bytes = __INST(bytes); |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
777 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
778 |
if (__isByteArrayLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
779 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
780 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
781 |
if (__isExternalBytesLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
782 |
srcPtr = __externalBytesAddress(_bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
783 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
784 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
785 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
786 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
787 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
788 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
789 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
790 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
791 |
} |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
792 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
793 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
794 |
&& __isArrayLike(colorValues) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
795 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
796 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
797 |
int x, y, w, h, nPix; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
798 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
799 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
800 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
801 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
802 |
h = __intVal(__INST(height)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
803 |
nPix = w * h; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
804 |
while (nPix > 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
805 |
unsigned idx, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
806 |
OBJ clr; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
807 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
808 |
idx = *srcPtr; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
809 |
clr = ap[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
810 |
v = __intVal(clr); |
2401 | 811 |
#ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
812 |
((long *)dstPtr)[0] = v; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
813 |
#else |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
814 |
dstPtr[0] = (v>>24) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
815 |
dstPtr[1] = (v>>16) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
816 |
dstPtr[2] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
817 |
dstPtr[3] = (v) & 0xFF; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
818 |
#endif |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
819 |
dstPtr += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
820 |
srcPtr += 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
821 |
nPix--; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
822 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
823 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
824 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
825 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
826 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
827 |
"/ 8 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
828 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
829 |
"/ now, walk over the image and replace |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
830 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
831 |
|
4718 | 832 |
%{ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
833 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
834 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
835 |
OBJ _bytes = __INST(bytes); |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
836 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
837 |
if (__isByteArrayLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
838 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
839 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
840 |
if (__isExternalBytesLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
841 |
srcPtr = __externalBytesAddress(_bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
842 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
843 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
844 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
845 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
846 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
847 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
848 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
849 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
850 |
} |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
851 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
852 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
853 |
&& __isArrayLike(colorValues) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
854 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
855 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
856 |
int x, y, w, h, nPix; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
857 |
int r,p; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
858 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
859 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
860 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
861 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
862 |
h = __intVal(__INST(height)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
863 |
r = w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
864 |
p = __intVal(padd); |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
865 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
866 |
nPix = w * h; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
867 |
while (nPix > 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
868 |
unsigned idx, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
869 |
OBJ clr; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
870 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
871 |
idx = *srcPtr; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
872 |
clr = ap[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
873 |
v = __intVal(clr); |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
874 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
875 |
dstPtr[0] = v; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
876 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
877 |
dstPtr += 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
878 |
srcPtr += 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
879 |
nPix--; |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
880 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
881 |
if (--r == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
882 |
dstPtr += p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
883 |
r = w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
884 |
} |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
885 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
886 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
887 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
888 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
889 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
890 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
891 |
"/ 24 bits/pixel |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
892 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
893 |
"/ now, walk over the image and replace |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
894 |
"/ colorMap indices by color values in the bits array |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
895 |
|
4718 | 896 |
%{ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
897 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
898 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
899 |
OBJ _bytes = __INST(bytes); |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
900 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
901 |
if (__isByteArrayLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
902 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
903 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
904 |
if (__isExternalBytesLike(_bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
905 |
srcPtr = __externalBytesAddress(_bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
906 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
907 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
908 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
909 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
910 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
911 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
912 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
913 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
914 |
} |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
915 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
916 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
917 |
&& __isArrayLike(colorValues) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
918 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
919 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
920 |
int x, y, w, h, nPix; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
921 |
int r,p; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
922 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
923 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
924 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
925 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
926 |
h = __intVal(__INST(height)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
927 |
r = w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
928 |
p = __intVal(padd); |
1994
2f12026904e3
oops - care for image padding
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
929 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
930 |
nPix = w * h; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
931 |
while (nPix > 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
932 |
unsigned idx, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
933 |
OBJ clr; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
934 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
935 |
idx = *srcPtr; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
936 |
clr = ap[idx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
937 |
v = __intVal(clr); |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
938 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
939 |
dstPtr[0] = (v>>16) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
940 |
dstPtr[1] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
941 |
dstPtr[2] = (v) & 0xFF; |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
942 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
943 |
dstPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
944 |
srcPtr += 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
945 |
nPix--; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
946 |
if (--r == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
947 |
dstPtr += p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
948 |
r = w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
949 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
950 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
951 |
} |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
952 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
953 |
] |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
954 |
] |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
955 |
] |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
956 |
]. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
957 |
|
4718 | 958 |
imageBits isNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
959 |
'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
960 |
^ self asMonochromeFormOn:aDevice |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
961 |
]. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
962 |
|
4764 | 963 |
form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
964 |
form isNil ifTrue:[^ nil]. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
965 |
form initGC. |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
966 |
|
1997 | 967 |
form |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
968 |
copyBitsFrom:imageBits |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
969 |
bitsPerPixel:usedDeviceBitsPerPixel |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
970 |
depth:usedDeviceDepth |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
971 |
padding:usedDevicePadding |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
972 |
width:width height:height |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
973 |
x:0 y:0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
974 |
toX:0 y:0. |
1603
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
975 |
|
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
976 |
^ form |
8697ffae0880
moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
977 |
|
4764 | 978 |
"Created: / 20-10-1995 / 22:05:10 / cg" |
979 |
"Modified: / 29-05-2007 / 19:22:06 / cg" |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
980 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
981 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
982 |
asGray8FormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
983 |
"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
|
984 |
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
|
985 |
|
2774 | 986 |
|greyBits map| |
2202
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 |
greyBits := ByteArray uninitializedNew:(width * height). |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
989 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
990 |
map := ByteArray uninitializedNew:256. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
991 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
992 |
1 to:256 do:[:i | |
4718 | 993 |
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
|
994 |
]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
995 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
996 |
self bits |
4718 | 997 |
expandPixels:8 "xlate only" |
998 |
width:width |
|
999 |
height:height |
|
1000 |
into:greyBits |
|
1001 |
mapping:map. |
|
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1002 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1003 |
^ self makeDeviceGrayPixmapOn:aDevice depth:8 fromArray:greyBits |
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 |
"Modified: 10.6.1996 / 20:10:14 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1006 |
"Created: 14.6.1996 / 15:23:09 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1007 |
! |
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 |
asGrayFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1010 |
"get a gray device form. |
4718 | 1011 |
Redefined, since we can do it with simple translate, |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1012 |
if the depth matches my depth." |
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 |
(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
|
1015 |
(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
|
1016 |
^ self asGray8FormOn:aDevice |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
1017 |
]. |
2202
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 |
^ super asGrayFormOn:aDevice |
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 |
"Created: 10.6.1996 / 18:51:19 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1022 |
"Modified: 10.6.1996 / 18:54:36 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1023 |
! |
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 |
greyImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1026 |
"return a pseudoForm from the gray picture. The main work is |
7407 | 1027 |
in color reduction, when not all colors can be acquired." |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1028 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1029 |
^ self anyImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1030 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1031 |
"Modified: 19.10.1997 / 04:57:39 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1032 |
"Created: 19.10.1997 / 04:58:41 / cg" |
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 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1035 |
greyImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1036 |
"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
|
1037 |
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
|
1038 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1039 |
|f| |
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 := self anyImageAsTrueColorFormOn:aDevice. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1042 |
f notNil ifTrue:[^ f]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1043 |
^ super greyImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1044 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1045 |
"Created: / 29.7.1998 / 00:19:46 / cg" |
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 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1048 |
paletteImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1049 |
"return a pseudoForm from the palette picture. The main work is |
7407 | 1050 |
in color reduction, when not all colors can be acquired." |
2202
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1051 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1052 |
^ self anyImageAsPseudoFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1053 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1054 |
"Modified: 19.10.1997 / 04:57:39 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1055 |
! |
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 |
paletteImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1058 |
"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
|
1059 |
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
|
1060 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1061 |
|f| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1062 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1063 |
f := self anyImageAsTrueColorFormOn:aDevice. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1064 |
f notNil ifTrue:[^ f]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1065 |
^ super paletteImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1066 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1067 |
"Created: / 24.7.1998 / 01:20:46 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1068 |
"Modified: / 29.7.1998 / 00:19:27 / cg" |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1069 |
! |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1070 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1071 |
rgbImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1072 |
"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
|
1073 |
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
|
1074 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1075 |
|f| |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1076 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1077 |
f := self anyImageAsTrueColorFormOn:aDevice. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1078 |
f notNil ifTrue:[^ f]. |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1079 |
^ super rgbImageAsTrueColorFormOn:aDevice |
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1080 |
|
03d4cf38f4a5
tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1081 |
"Created: / 29.7.1998 / 00:21:25 / cg" |
1 | 1082 |
! ! |
1083 |
||
810 | 1084 |
!Depth8Image methodsFor:'dither helpers'! |
1085 |
||
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1086 |
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1087 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
4718 | 1088 |
which must be a depth-8 image. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1089 |
This method expects an array of colors to be used for dithering |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1090 |
(which need not be a colorCubes colors)." |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1091 |
|
4718 | 1092 |
|pseudoBits |
1093 |
rgbBytes |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1094 |
ditherRGBBytes ditherColors |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1095 |
w "{Class: SmallInteger }" |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1096 |
h "{Class: SmallInteger }" |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1097 |
index "{Class: SmallInteger }" |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1098 |
ditherIds failed lastColor qScramble |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1099 |
clrLookup lookupPos |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1100 |
error clr| |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1101 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1102 |
"/ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1103 |
"/ collect color components as integer values (for integer arithmetic) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1104 |
"/ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1105 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1106 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1107 |
photometric == #palette ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1108 |
lastColor := colorMap size - 1 |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1109 |
] ifFalse:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1110 |
lastColor := 255. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1111 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1112 |
index := 1. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1113 |
0 to:lastColor do:[:pix | |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1114 |
clr := self colorFromValue:pix. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1115 |
rgbBytes at:index put:(clr redByte). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1116 |
rgbBytes at:index+1 put:(clr greenByte). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1117 |
rgbBytes at:index+2 put:(clr blueByte). |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1118 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1119 |
index := index + 3. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1120 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1121 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1122 |
"/ collect valid ditherColors ... |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1123 |
aMapOrNil isNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1124 |
ditherColors := colors select:[:clr | clr notNil]. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1125 |
] ifFalse:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1126 |
ditherColors := colors |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1127 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1128 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1129 |
"/ ... and sort by manhatten distance from black |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1130 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1131 |
qScramble := #( |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1132 |
"/ 2rX00X00X00X00 |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1133 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1134 |
2r000000000000 "/ 0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1135 |
2r000000000100 "/ 1 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1136 |
2r000000100000 "/ 2 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1137 |
2r000000100100 "/ 3 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1138 |
2r000100000000 "/ 4 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1139 |
2r000100000100 "/ 5 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1140 |
2r000100100000 "/ 6 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1141 |
2r000100100100 "/ 7 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1142 |
2r100000000000 "/ 8 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1143 |
2r100000000100 "/ 9 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1144 |
2r100000100000 "/ a |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1145 |
2r100000100100 "/ b |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1146 |
2r100100000000 "/ c |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1147 |
2r100100000100 "/ d |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1148 |
2r100100100000 "/ e |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1149 |
2r100100100100 "/ f |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1150 |
). |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1151 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1152 |
ditherColors := ditherColors sort:[:a :b | |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1153 |
|cr "{Class: SmallInteger }" |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1154 |
cg "{Class: SmallInteger }" |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1155 |
cb "{Class: SmallInteger }" |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1156 |
i1 "{Class: SmallInteger }" |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1157 |
i2 "{Class: SmallInteger }"| |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1158 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1159 |
cr := a redByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1160 |
cg := a greenByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1161 |
cb := a blueByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1162 |
i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1163 |
i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1164 |
i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1165 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1166 |
cr := b redByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1167 |
cg := b greenByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1168 |
cb := b blueByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1169 |
i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1170 |
i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1171 |
i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1172 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1173 |
i1 < i2 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1174 |
]. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1175 |
aMapOrNil isNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1176 |
ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1177 |
] ifFalse:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1178 |
ditherIds := aMapOrNil asByteArray |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1179 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1180 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1181 |
"/ build an index table, for fast lookup from manhatten-r-g-b distance |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1182 |
"/ to the position in the colorList |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1183 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1184 |
clrLookup := ByteArray new:(4096). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1185 |
index := 0. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1186 |
ditherColors keysAndValuesDo:[:clrPosition :clr | |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1187 |
|r g b i| |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1188 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1189 |
r := clr redByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1190 |
g := clr greenByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1191 |
b := clr blueByte. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1192 |
i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1193 |
i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1194 |
i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1195 |
lookupPos := i. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1196 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1197 |
[index < lookupPos] whileTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1198 |
clrLookup at:(index+1) put:(clrPosition-1-1). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1199 |
index := index + 1 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1200 |
] |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1201 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1202 |
clrLookup from:index+1 to:4096 put:(ditherColors size - 1). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1203 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1204 |
"/ [index <= (4095)] whileTrue:[ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1205 |
"/ clrLookup at:(index+1) put:(ditherColors size - 1). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1206 |
"/ index := index + 1. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1207 |
"/ ]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1208 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1209 |
"/ collect ditherColor components |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1210 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1211 |
lastColor := ditherColors size. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1212 |
ditherIds := ByteArray uninitializedNew:lastColor. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1213 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1214 |
index := 1. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1215 |
1 to:lastColor do:[:pix | |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1216 |
clr := ditherColors at:pix. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1217 |
ditherRGBBytes at:index put:(clr redByte). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1218 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1219 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1220 |
aMapOrNil isNil ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1221 |
ditherIds at:pix put:clr colorId. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1222 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1223 |
ditherIds at:pix put:(aMapOrNil at:pix). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1224 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1225 |
index := index + 3. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1226 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1227 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1228 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1229 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1230 |
w := width + 2. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1231 |
error := ByteArray uninitializedNew:w*(3*2). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1232 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1233 |
w := width. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1234 |
h := height. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1235 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1236 |
failed := true. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1237 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1238 |
%{ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1239 |
int __x, __y; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1240 |
int __eR, __eG, __eB; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1241 |
unsigned char *srcP, *dstP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1242 |
unsigned char *rgbP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1243 |
unsigned char *idP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1244 |
unsigned char *dp; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1245 |
unsigned char *__clrLookup; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1246 |
short *errP, *eP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1247 |
int __fR, __fG, __fB; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1248 |
int iR, iG, iB; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1249 |
int idx; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1250 |
int __w = __intVal(w); |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1251 |
int __h = __intVal(h); |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1252 |
int __nColors = __intVal(lastColor); |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1253 |
int __wR = -1, __wG, __wB; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1254 |
static int __qScramble[16] = { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1255 |
0x000 /* 2r000000000000 0 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1256 |
0x004 /* 2r000000000100 1 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1257 |
0x020 /* 2r000000100000 2 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1258 |
0x024 /* 2r000000100100 3 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1259 |
0x100 /* 2r000100000000 4 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1260 |
0x104 /* 2r000100000100 5 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1261 |
0x120 /* 2r000100100000 6 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1262 |
0x124 /* 2r000100100100 7 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1263 |
0x800 /* 2r100000000000 8 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1264 |
0x804 /* 2r100000000100 9 */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1265 |
0x820 /* 2r100000100000 a */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1266 |
0x824 /* 2r100000100100 b */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1267 |
0x900 /* 2r100100000000 c */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1268 |
0x904 /* 2r100100000100 d */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1269 |
0x920 /* 2r100100100000 e */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1270 |
0x924 /* 2r100100100100 f */, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1271 |
}; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1272 |
|
5472
5508a0ac6319
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5453
diff
changeset
|
1273 |
if (__isByteArrayLike(__INST(bytes)) |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1274 |
&& __isByteArray(pseudoBits) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1275 |
&& __isByteArray(rgbBytes) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1276 |
&& __isByteArray(ditherRGBBytes) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1277 |
&& __isByteArray(ditherIds) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1278 |
&& __isByteArray(clrLookup) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1279 |
&& __isByteArray(error)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1280 |
failed = false; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1281 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1282 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1283 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1284 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1285 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1286 |
__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1287 |
errP = (short *) __ByteArrayInstPtr(error)->ba_element; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1288 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1289 |
/* |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1290 |
* clear error accumulator |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1291 |
*/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1292 |
eP = errP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1293 |
bzero(eP, (__w+2) * 2 * 3); |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1294 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1295 |
for (__y=__h; __y>0; __y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1296 |
__eR = __eG = __eB = 0; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1297 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1298 |
eP = &(errP[3]); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1299 |
__eR = eP[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1300 |
__eG = eP[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1301 |
__eB = eP[2]; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1302 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1303 |
for (__x=__w; __x>0; __x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1304 |
int __want; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1305 |
int pix; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1306 |
int __wantR, __wantG, __wantB; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1307 |
int idx; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1308 |
int tR, tG, tB; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1309 |
int nR, nG, nB; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1310 |
int dR, dG, dB; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1311 |
int minDelta, bestIdx; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1312 |
int cnt; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1313 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1314 |
pix = *srcP++; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1315 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1316 |
/* |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1317 |
* wR, wG and wB is the wanted r/g/b value; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1318 |
*/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1319 |
idx = pix+pix+pix; /* pix * 3 */ |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1320 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1321 |
__wantR = rgbP[idx] + __eR; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1322 |
__wantG = rgbP[idx+1] + __eG; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1323 |
__wantB = rgbP[idx+2] + __eB; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1324 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1325 |
#define RED_SCALE 30 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1326 |
#define GREEN_SCALE 59 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1327 |
#define BLUE_SCALE 11 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1328 |
#define GOOD_DELTA 30 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1329 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1330 |
#define xRED_SCALE 1 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1331 |
#define xGREEN_SCALE 1 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1332 |
#define xBLUE_SCALE 1 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1333 |
#define xGOOD_DELTA 3 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1334 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1335 |
#define FAST_LOOKUP |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1336 |
/* #define ONE_SHOT */ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1337 |
#define NPROBE 8 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1338 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1339 |
#ifndef FAST_LOOKUP |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1340 |
if ((__wantR == __wR) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1341 |
&& (__wantG == __wG) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1342 |
&& (__wantB == __wB)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1343 |
/* |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1344 |
* same color again - reuse last bestMatch |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1345 |
*/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1346 |
} else |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1347 |
#endif |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1348 |
{ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1349 |
__wR = __wantR; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1350 |
__wG = __wantG; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1351 |
__wB = __wantB; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1352 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1353 |
#ifdef FAST_LOOKUP |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1354 |
if(__wR > 255) __wR = 255; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1355 |
else if (__wR < 0) __wR = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1356 |
if(__wG > 255) __wG = 255; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1357 |
else if (__wG < 0) __wG = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1358 |
if(__wB > 255) __wB = 255; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1359 |
else if (__wB < 0) __wB = 0; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1360 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1361 |
{ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1362 |
int lookupIndex; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1363 |
int idx, idx0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1364 |
int d, delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1365 |
unsigned char *dp0; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1366 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1367 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1368 |
lookupIndex = __qScramble[((__wR & 0xF0)>>4)]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1369 |
lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1370 |
lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1371 |
idx = bestIdx =__clrLookup[lookupIndex]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1372 |
dp += (idx+idx+idx); |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1373 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1374 |
/* try color at lookupIndex */ |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1375 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1376 |
d = dp[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1377 |
delta = (__wR - d) * RED_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1378 |
if (delta < 0) delta = -delta; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1379 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1380 |
d = dp[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1381 |
if (__wG > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1382 |
delta += (__wG - d) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1383 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1384 |
delta += (d - __wG) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1385 |
d = dp[2]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1386 |
if (__wB > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1387 |
delta += (__wB - d) * BLUE_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1388 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1389 |
delta += (d - __wB) * BLUE_SCALE; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1390 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1391 |
if (delta <= GOOD_DELTA) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1392 |
goto foundBest; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1393 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1394 |
minDelta = delta; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1395 |
# ifndef ONE_SHOT |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1396 |
idx0 = idx; dp0 = dp; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1397 |
cnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1398 |
while ((++cnt <= NPROBE) && (idx > 0)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1399 |
/* try previous color(s) */ |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1400 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1401 |
idx--; dp -= 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1402 |
d = dp[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1403 |
delta = (__wR - d) * RED_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1404 |
if (delta < 0) delta = -delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1405 |
d = dp[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1406 |
if (__wG > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1407 |
delta += (__wG - d) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1408 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1409 |
delta += (d - __wG) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1410 |
d = dp[2]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1411 |
if (__wB > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1412 |
delta += (__wB - d) * BLUE_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1413 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1414 |
delta += (d - __wB) * BLUE_SCALE; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1415 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1416 |
if (delta < minDelta) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1417 |
bestIdx = idx; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1418 |
if (delta <= GOOD_DELTA) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1419 |
goto foundBest; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1420 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1421 |
minDelta = delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1422 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1423 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1424 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1425 |
idx = idx0; dp = dp0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1426 |
cnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1427 |
while ((++cnt <= NPROBE) && (++idx < __nColors)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1428 |
/* try next color */ |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1429 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1430 |
dp += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1431 |
d = dp[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1432 |
delta = (__wR - d) * RED_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1433 |
if (delta < 0) delta = -delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1434 |
d = dp[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1435 |
if (__wG > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1436 |
delta += (__wG - d) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1437 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1438 |
delta += (d - __wG) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1439 |
d = dp[2]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1440 |
if (__wB > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1441 |
delta += (__wB - d) * BLUE_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1442 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1443 |
delta += (d - __wB) * BLUE_SCALE; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1444 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1445 |
if (delta < minDelta) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1446 |
bestIdx = idx; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1447 |
if (delta <= GOOD_DELTA) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1448 |
goto foundBest; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1449 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1450 |
minDelta = delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1451 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1452 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1453 |
# endif |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1454 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1455 |
foundBest: ; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1456 |
#else |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1457 |
/* |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1458 |
if(__wR > 255) __wR = 255; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1459 |
else if (__wR < 0) __wR = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1460 |
if(__wG > 255) __wG = 255; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1461 |
else if (__wG < 0) __wG = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1462 |
if(__wB > 255) __wB = 255; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1463 |
else if (__wB < 0) __wB = 0; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1464 |
*/ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1465 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1466 |
/* find the best matching color */ |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1467 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1468 |
minDelta = 99999; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1469 |
bestIdx = -1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1470 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1471 |
for (idx = 0; idx<__nColors; idx++) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1472 |
int d, delta; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1473 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1474 |
d = dp[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1475 |
delta = (__wR - d) * RED_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1476 |
if (delta < 0) delta = -delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1477 |
if (delta < minDelta) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1478 |
d = dp[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1479 |
if (__wG > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1480 |
delta += (__wG - d) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1481 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1482 |
delta += (d - __wG) * GREEN_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1483 |
if (delta < minDelta) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1484 |
d = dp[2]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1485 |
if (__wB > d) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1486 |
delta += (__wB - d) * BLUE_SCALE; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1487 |
else |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1488 |
delta += (d - __wB) * BLUE_SCALE; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1489 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1490 |
if (delta < minDelta) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1491 |
bestIdx = idx; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1492 |
if (delta <= GOOD_DELTA) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1493 |
break; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1494 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1495 |
minDelta = delta; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1496 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1497 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1498 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1499 |
dp += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1500 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1501 |
#endif |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1502 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1503 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1504 |
dp += bestIdx * 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1505 |
dR = dp[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1506 |
dG = dp[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1507 |
dB = dp[2]; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1508 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1509 |
/* |
4724 | 1510 |
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n", |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1511 |
__wantR, __wantG, __wantB, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1512 |
__wR, __wG, __wB, |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1513 |
dR, dG, dB); |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1514 |
*/ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1515 |
/* |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1516 |
* store the corresponding dither colors colorId |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1517 |
*/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1518 |
*dstP++ = idP[bestIdx]; |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1519 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1520 |
/* |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1521 |
* the new error & distribute the error |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1522 |
*/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1523 |
__eR = __wantR - dR; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1524 |
if (__eR) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1525 |
tR = __eR >> 4; /* 16th of error */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1526 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1527 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1528 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1529 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1530 |
__eR = nR; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1531 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1532 |
__eR = eP[3]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1533 |
eP[0] = eP[-3] = eP[3] = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1534 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1535 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1536 |
__eG = __wantG - dG; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1537 |
if (__eG) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1538 |
tG = __eG >> 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1539 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1540 |
eP[1] = tG*5; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1541 |
eP[-2] = tG*3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1542 |
eP[4] = __eG - (tG*15); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1543 |
__eG = nG; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1544 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1545 |
__eG = eP[4]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1546 |
eP[1] = eP[-2] = eP[4] = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1547 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1548 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1549 |
__eB = __wantB - dB; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1550 |
if (__eB) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1551 |
tB = __eB >> 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1552 |
nB = eP[5] + (tB * 7); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1553 |
eP[2] = tB*5; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1554 |
eP[-1] = tB*3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1555 |
eP[5] = __eB - (tB*15); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1556 |
__eB = nB; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1557 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1558 |
__eB = eP[5]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1559 |
eP[2] = eP[-1] = eP[5] = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1560 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1561 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1562 |
eP += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1563 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1564 |
} |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1565 |
} |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1566 |
%}. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1567 |
failed ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1568 |
self primitiveFailed. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
1569 |
^ nil |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1570 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1571 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1572 |
^ pseudoBits |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1573 |
! |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
1574 |
|
1782 | 1575 |
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
810 | 1576 |
"return the bitmap for a dithered depth-bitmap from the image; |
1577 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1578 |
Redefined to make use of knowing that pixels are 8-bit values." |
|
1579 |
||
4718 | 1580 |
|dH nDither bytes |
810 | 1581 |
greyLevels greyMap1 greyMap2 |
1582 |
bytesPerRow "{Class: SmallInteger }" |
|
1583 |
bytesPerOutRow "{Class: SmallInteger }" |
|
1584 |
pixelsPerByte "{Class: SmallInteger }" |
|
1585 |
outBits |
|
1586 |
w "{Class: SmallInteger }" |
|
1587 |
h "{Class: SmallInteger }" | |
|
1588 |
||
1589 |
nDither := ditherMatrix size. |
|
1590 |
dH := nDither / dW. |
|
1591 |
||
1592 |
w := width. |
|
1593 |
h := height. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1594 |
bytes := self bits. |
810 | 1595 |
|
1596 |
greyLevels := 1 bitShift:depth. |
|
1597 |
pixelsPerByte := 8 / depth. |
|
1598 |
||
1599 |
bytesPerRow := self bytesPerRow. |
|
1600 |
||
1601 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
1602 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
1603 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
|
4718 | 1604 |
^ nil |
810 | 1605 |
]. |
1606 |
||
1607 |
greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels |
|
1608 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
4718 | 1609 |
0 |
1610 |
] ifFalse:[ |
|
1611 |
b truncated |
|
1612 |
] |
|
1613 |
]) asByteArray. |
|
810 | 1614 |
|
1615 |
greyMap2 := self greyMapForRange:(greyLevels-1). |
|
4718 | 1616 |
greyMap2 := (greyMap2 collect:[:el | |
1617 |
el isNil ifTrue:[ |
|
1618 |
0 |
|
1619 |
] ifFalse:[ |
|
1620 |
((el - el truncated) "/ the error (0..1) |
|
1621 |
* nDither) rounded |
|
1622 |
]]) asByteArray. |
|
810 | 1623 |
|
1624 |
%{ |
|
1625 |
int __dW = __intVal(dW); |
|
1626 |
int __dH = __intVal(dH); |
|
1627 |
int __byte; |
|
1628 |
int __dT, __dO; |
|
1629 |
int __depth = __intVal(depth); |
|
1630 |
int __dstIdx = 0; |
|
1631 |
int __srcIdx = 0; |
|
1632 |
int __bitCnt; |
|
1633 |
int __grey, __pixel; |
|
1634 |
int __w = __intVal(w); |
|
1635 |
int __h = __intVal(h); |
|
1636 |
int __x; |
|
1637 |
int __y; |
|
1638 |
int __oX, __oY, __dY; |
|
1639 |
int __nextDst; |
|
1640 |
int __nextSrc; |
|
1641 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1642 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
1643 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1644 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
810 | 1645 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1646 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
810 | 1647 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
1648 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
1649 |
||
1650 |
__oY = __dY = 0; |
|
1651 |
for (__y=0; __y<__h; __y++) { |
|
4718 | 1652 |
__nextDst = __dstIdx + __bytesPerOutRow; |
1653 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
810 | 1654 |
|
4718 | 1655 |
__byte = 0; |
1656 |
__bitCnt = 8; |
|
810 | 1657 |
|
4718 | 1658 |
__oX = 0; |
810 | 1659 |
|
4718 | 1660 |
for (__x=0; __x<__w; __x++) { |
1661 |
__grey = __bytes[__srcIdx++]; /* 0..255 */ |
|
810 | 1662 |
|
4718 | 1663 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
1664 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
|
1665 |
__dT = __ditherMatrix[__dY + __oX]; |
|
810 | 1666 |
|
4718 | 1667 |
if (__dO > __dT) /* dither says: next pixel */ |
1668 |
__pixel++; |
|
810 | 1669 |
|
4718 | 1670 |
__oX++; |
1671 |
if (__oX == __dW) __oX = 0; |
|
810 | 1672 |
|
4718 | 1673 |
__byte = (__byte << __depth) | __pixel; |
810 | 1674 |
|
4718 | 1675 |
__bitCnt = __bitCnt - __depth; |
1676 |
if (__bitCnt == 0) { |
|
1677 |
__outBits[__dstIdx] = __byte; |
|
1678 |
__dstIdx++; |
|
1679 |
__byte = 0; |
|
1680 |
__bitCnt = 8; |
|
1681 |
} |
|
1682 |
} |
|
810 | 1683 |
|
4718 | 1684 |
if (__bitCnt != 8) { |
1685 |
__byte = __byte << __bitCnt; |
|
1686 |
__outBits[__dstIdx] = __byte; |
|
1687 |
} |
|
810 | 1688 |
|
4718 | 1689 |
__oY++; __dY += __dW; |
1690 |
if (__oY == __dH) { |
|
1691 |
__oY = 0; |
|
1692 |
__dY = 0; |
|
1693 |
} |
|
810 | 1694 |
|
4718 | 1695 |
__srcIdx = __nextSrc; |
1696 |
__dstIdx = __nextDst; |
|
810 | 1697 |
} |
1698 |
%}. |
|
1699 |
^ outBits |
|
1700 |
! |
|
1701 |
||
1702 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
1703 |
"return the dithered monochrome bits for the receiver image; |
|
1704 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1705 |
Redefined to make use of knowing that pixels are 8-bit values." |
|
1706 |
||
4718 | 1707 |
|dH nDither bytes |
810 | 1708 |
greyMap monoBits |
1709 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
1710 |
bytesPerRow "{Class: SmallInteger }" |
|
1711 |
w "{Class: SmallInteger }" |
|
1712 |
h "{Class: SmallInteger }"| |
|
1713 |
||
1714 |
nDither := ditherMatrix size. |
|
1715 |
dH := nDither / dW. |
|
1716 |
||
1717 |
w := width. |
|
1718 |
h := height. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1719 |
bytes := self bits. |
810 | 1720 |
|
1721 |
bytesPerRow := self bytesPerRow. |
|
1722 |
||
1723 |
bytesPerMonoRow := w + 7 // 8. |
|
1724 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
1725 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
4718 | 1726 |
^ nil |
810 | 1727 |
]. |
1728 |
||
1729 |
greyMap := self greyByteMapForRange:nDither. |
|
1730 |
||
1731 |
%{ |
|
1732 |
int __dW = __intVal(dW); |
|
1733 |
int __dH = __intVal(dH); |
|
1734 |
int __byte; |
|
1735 |
int __dT; |
|
1736 |
int __dstIdx = 0; |
|
1737 |
int __srcIdx = 0; |
|
1738 |
int __bitCnt; |
|
1739 |
int __grey; |
|
1740 |
int __w = __intVal(w); |
|
1741 |
int __h = __intVal(h); |
|
1742 |
int __x; |
|
1743 |
int __y; |
|
1744 |
int __oX, __oY, __dY; |
|
1745 |
int __nextDst; |
|
1746 |
int __nextSrc; |
|
1747 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1748 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
1749 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1750 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
810 | 1751 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1752 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
810 | 1753 |
unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
1754 |
||
1755 |
__oY = __dY = 0; |
|
1756 |
for (__y=0; __y<__h; __y++) { |
|
4718 | 1757 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
1758 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
810 | 1759 |
|
4718 | 1760 |
__byte = 0; |
1761 |
__bitCnt = 8; |
|
810 | 1762 |
|
4718 | 1763 |
__oX = 0; |
810 | 1764 |
|
4718 | 1765 |
for (__x=__w; __x>0; __x--) { |
1766 |
__grey = __bytes[__srcIdx]; /* 0..255 */ |
|
1767 |
__srcIdx++; |
|
810 | 1768 |
|
4718 | 1769 |
__grey = __greyMap[__grey]; |
1770 |
__dT = __ditherMatrix[__dY + __oX]; |
|
810 | 1771 |
|
4718 | 1772 |
__oX++; |
1773 |
if (__oX == __dW) __oX = 0; |
|
810 | 1774 |
|
4718 | 1775 |
__byte = __byte << 1; |
1776 |
if (__grey > __dT) { |
|
1777 |
__byte = __byte | 1; /* white */ |
|
1778 |
} |
|
810 | 1779 |
|
4718 | 1780 |
__bitCnt--; |
1781 |
if (__bitCnt == 0) { |
|
1782 |
__monoBits[__dstIdx] = __byte; |
|
1783 |
__dstIdx++; |
|
1784 |
__byte = 0; |
|
1785 |
__bitCnt = 8; |
|
1786 |
} |
|
1787 |
} |
|
810 | 1788 |
|
4718 | 1789 |
if (__bitCnt != 8) { |
1790 |
__byte = __byte << __bitCnt; |
|
1791 |
__monoBits[__dstIdx] = __byte; |
|
1792 |
} |
|
810 | 1793 |
|
4718 | 1794 |
__oY++; __dY += __dW; |
1795 |
if (__oY == __dH) { |
|
1796 |
__oY = 0; |
|
1797 |
__dY = 0; |
|
1798 |
} |
|
810 | 1799 |
|
4718 | 1800 |
__srcIdx = __nextSrc; |
1801 |
__dstIdx = __nextDst; |
|
810 | 1802 |
} |
1803 |
%}. |
|
1804 |
||
1805 |
^ monoBits |
|
1806 |
||
1807 |
" |
|
1808 |
|i f| |
|
1809 |
||
1609 | 1810 |
i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
810 | 1811 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
1812 |
||
1813 |
||
1814 |
|i f| |
|
1815 |
||
1609 | 1816 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
810 | 1817 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
1818 |
||
1819 |
||
1820 |
|i f| |
|
1821 |
||
1822 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
1823 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
1824 |
||
1825 |
||
1826 |
|i f| |
|
1827 |
||
1828 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
1829 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
1830 |
" |
|
1831 |
||
1832 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
1833 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
1834 |
! ! |
|
1835 |
||
579 | 1836 |
!Depth8Image methodsFor:'enumerating'! |
1 | 1837 |
|
798 | 1838 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1839 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
1840 |
The block is passed the color at each pixel. |
|
1841 |
This method allows slighly faster processing of an |
|
1842 |
image than using atX:y:, since some processing can be |
|
1843 |
avoided when going from pixel to pixel. However, for |
|
1844 |
real image processing, specialized methods should be written." |
|
1845 |
||
1846 |
|srcIndex "{ Class: SmallInteger }" |
|
1847 |
value "{ Class: SmallInteger }" |
|
1848 |
x1 "{ Class: SmallInteger }" |
|
1849 |
x2 "{ Class: SmallInteger }" |
|
7322 | 1850 |
color cachedColorArray pixelBytes lastValue lastColor| |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1851 |
|
7322 | 1852 |
pixelBytes := self bits. |
798 | 1853 |
|
1854 |
x1 := xLow. |
|
1855 |
x2 := xHigh. |
|
1856 |
srcIndex := (width * y) + 1 + x1. |
|
1857 |
||
7322 | 1858 |
cachedColorArray := Array new:256. |
810 | 1859 |
|
941 | 1860 |
x1 to:x2 do:[:x | |
7322 | 1861 |
value := pixelBytes at:srcIndex. |
1862 |
srcIndex := srcIndex + 1. |
|
1863 |
||
1864 |
value == lastValue ifTrue:[ |
|
1865 |
color := lastColor |
|
1866 |
] ifFalse:[ |
|
1867 |
color := cachedColorArray at:value+1. |
|
1868 |
color isNil ifTrue:[ |
|
1869 |
color := self colorFromValue:value. |
|
1870 |
cachedColorArray at:value+1 put:color |
|
1871 |
]. |
|
1872 |
lastValue := value. lastColor := color. |
|
1873 |
]. |
|
1874 |
aBlock value:x value:color |
|
941 | 1875 |
] |
1876 |
||
1877 |
"Created: 7.6.1996 / 19:12:35 / cg" |
|
1878 |
"Modified: 11.7.1996 / 20:22:32 / cg" |
|
1879 |
! |
|
798 | 1880 |
|
941 | 1881 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
1882 |
"perform aBlock for each pixel in the rectangle |
|
1883 |
yStart..yEnd / xStart..xEnd. |
|
1884 |
The block is passed the color at each pixel. |
|
1885 |
This method allows slighly faster processing of an |
|
4718 | 1886 |
image than using individual atX:y: accesses, |
941 | 1887 |
both since some processing can be avoided when going from pixel to pixel, |
4718 | 1888 |
and since the color composition is done outside of the pixel loop. |
1889 |
However, for real high performance image processing, specialized methods |
|
941 | 1890 |
should be written which know how to deal with specific photometric interpretations." |
798 | 1891 |
|
941 | 1892 |
|srcIndex "{ Class: SmallInteger }" |
1893 |
srcNext "{ Class: SmallInteger }" |
|
1894 |
bytesPerRow "{ Class: SmallInteger }" |
|
1895 |
value "{ Class: SmallInteger }" |
|
1896 |
x1 "{ Class: SmallInteger }" |
|
1897 |
x2 "{ Class: SmallInteger }" |
|
1898 |
y1 "{ Class: SmallInteger }" |
|
1899 |
y2 "{ Class: SmallInteger }" |
|
2248
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1900 |
colorArray |
7323 | 1901 |
maxColor pixelBytes lastPixel lastColor| |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1902 |
|
7323 | 1903 |
pixelBytes := self bits. |
798 | 1904 |
|
941 | 1905 |
x1 := xStart. |
1906 |
x2 := xEnd. |
|
1907 |
y1 := yStart. |
|
1908 |
y2 := yEnd. |
|
1909 |
||
1910 |
srcIndex := (width * y1) + x1 + 1 . |
|
1911 |
bytesPerRow := self bytesPerRow. |
|
1912 |
||
1913 |
colorArray := self realColorMap. |
|
2248
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1914 |
maxColor := colorArray size. |
941 | 1915 |
|
1916 |
y1 to:y2 do:[:y | |
|
7323 | 1917 |
srcNext := srcIndex + bytesPerRow. |
1918 |
x1 to:x2 do:[:x | |
|
1919 |
value := pixelBytes at:srcIndex ifAbsent:0. |
|
1920 |
srcIndex := srcIndex + 1. |
|
798 | 1921 |
|
7323 | 1922 |
value ~~ lastPixel ifTrue:[ |
1923 |
lastPixel := value. |
|
1924 |
value >= maxColor ifTrue:[ |
|
1925 |
value := 0. |
|
1926 |
]. |
|
1927 |
lastColor := colorArray at:value+1. |
|
1928 |
]. |
|
1929 |
aBlock value:x value:y value:lastColor |
|
1930 |
]. |
|
1931 |
srcIndex := srcNext. |
|
798 | 1932 |
]. |
746 | 1933 |
|
2248
20fc22184ef5
care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents:
2202
diff
changeset
|
1934 |
"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
|
1935 |
"Modified: / 17.8.1998 / 10:17:45 / cg" |
579 | 1936 |
! |
1 | 1937 |
|
798 | 1938 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
579 | 1939 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
1940 |
The block is passed the pixelValue at each pixel. |
|
1941 |
This method allows slighly faster processing of an |
|
1942 |
image than using valueAtX:y:, since some processing can be |
|
1943 |
avoided when going from pixel to pixel. However, for |
|
1944 |
real image processing, specialized methods should be written." |
|
1 | 1945 |
|
579 | 1946 |
|srcIndex "{ Class: SmallInteger }" |
1947 |
pixelValue "{ Class: SmallInteger }" |
|
1948 |
x1 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1949 |
x2 "{ Class: SmallInteger }" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1950 |
bytes| |
1 | 1951 |
|
579 | 1952 |
x1 := xLow. |
1953 |
x2 := xHigh. |
|
1954 |
srcIndex := (width * y) + 1 + x1. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1955 |
bytes := self bits. |
579 | 1956 |
|
1957 |
x1 to:x2 do:[:x | |
|
4718 | 1958 |
pixelValue := bytes at:srcIndex. |
1959 |
srcIndex := srcIndex + 1. |
|
1960 |
aBlock value:x value:pixelValue |
|
579 | 1961 |
] |
798 | 1962 |
|
1963 |
"Created: 7.6.1996 / 19:09:47 / cg" |
|
941 | 1964 |
! |
1965 |
||
1966 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
1967 |
"perform aBlock for each pixel in the rectangle |
|
1968 |
yStart..yEnd / xStart..xEnd. |
|
1969 |
The block is passed the pixelValue at each pixel. |
|
1970 |
This method allows slighly faster processing of an |
|
4718 | 1971 |
image than using individual valueAtX:y: accesses, |
1972 |
since some processing can be avoided when going from pixel to pixel.. |
|
1973 |
However, for real high performance image processing, specialized methods |
|
941 | 1974 |
should be written which know how to deal with specific photometric interpretations." |
1975 |
||
1976 |
|srcIndex "{ Class: SmallInteger }" |
|
1977 |
srcNext "{ Class: SmallInteger }" |
|
1978 |
bytesPerRow "{ Class: SmallInteger }" |
|
1979 |
value "{ Class: SmallInteger }" |
|
1980 |
x1 "{ Class: SmallInteger }" |
|
1981 |
x2 "{ Class: SmallInteger }" |
|
1982 |
y1 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1983 |
y2 "{ Class: SmallInteger }" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1984 |
bytes| |
941 | 1985 |
|
1986 |
x1 := xStart. |
|
1987 |
x2 := xEnd. |
|
1988 |
y1 := yStart. |
|
1989 |
y2 := yEnd. |
|
1990 |
||
1991 |
srcIndex := (width * y1) + x1 + 1 . |
|
1992 |
bytesPerRow := self bytesPerRow. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1993 |
bytes := self bits. |
941 | 1994 |
|
1995 |
y1 to:y2 do:[:y | |
|
4718 | 1996 |
srcNext := srcIndex + bytesPerRow. |
1997 |
x1 to:x2 do:[:x | |
|
1998 |
value := bytes at:srcIndex. |
|
1999 |
srcIndex := srcIndex + 1. |
|
941 | 2000 |
|
4718 | 2001 |
aBlock value:x value:y value:value |
2002 |
]. |
|
2003 |
srcIndex := srcNext. |
|
941 | 2004 |
]. |
2005 |
^ self |
|
2006 |
||
2007 |
"Modified: 11.7.1996 / 20:06:47 / cg" |
|
2008 |
"Created: 11.7.1996 / 20:08:11 / cg" |
|
1 | 2009 |
! ! |
2010 |
||
12 | 2011 |
!Depth8Image methodsFor:'image manipulations'! |
2012 |
||
1577 | 2013 |
hardMagnifiedBy:scalePoint |
2014 |
"return a new image magnified by scalePoint, aPoint. |
|
12 | 2015 |
This is the general magnification method, handling non-integral values" |
1 | 2016 |
|
2017 |
|mX mY |
|
2018 |
newWidth "{ Class: SmallInteger }" |
|
2019 |
newHeight "{ Class: SmallInteger }" |
|
89 | 2020 |
w "{ Class: SmallInteger }" |
1 | 2021 |
h "{ Class: SmallInteger }" |
2022 |
newImage newBytes |
|
2023 |
value "{ Class: SmallInteger }" |
|
2024 |
srcRowIdx "{ Class: SmallInteger }" |
|
2025 |
srcIndex "{ Class: SmallInteger }" |
|
1577 | 2026 |
dstIndex "{ Class: SmallInteger }" |
2027 |
newMask| |
|
1 | 2028 |
|
1577 | 2029 |
mX := scalePoint x. |
2030 |
mY := scalePoint y. |
|
1 | 2031 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
2032 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
2033 |
||
2034 |
newWidth := (width * mX) truncated. |
|
2035 |
newHeight := (height * mY) truncated. |
|
2036 |
||
2037 |
newBytes := ByteArray uninitializedNew:(newWidth * newHeight). |
|
2038 |
||
1577 | 2039 |
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
|
2040 |
newMask := (mask magnifiedBy:scalePoint) |
1577 | 2041 |
]. |
2042 |
||
1 | 2043 |
newImage := self species new. |
4718 | 2044 |
newImage |
2045 |
width:newWidth |
|
2046 |
height:newHeight |
|
2047 |
photometric:photometric |
|
2048 |
samplesPerPixel:samplesPerPixel |
|
2049 |
bitsPerSample:#(8) |
|
2786
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
2050 |
colorMap:colorMap copy |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
2051 |
bits:newBytes |
a6a053ee4c76
oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents:
2774
diff
changeset
|
2052 |
mask:newMask. |
1 | 2053 |
|
2054 |
"walk over destination image fetching pixels from source image" |
|
2055 |
||
2056 |
mY := mY asFloat. |
|
2057 |
mX := mX asFloat. |
|
2058 |
%{ |
|
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
2059 |
unsigned char *__dstP = __ByteArrayInstPtr(newBytes)->ba_element; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2060 |
unsigned char *__srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
1658 | 2061 |
unsigned char *__srcRowP; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2062 |
int __width = __intVal(__INST(width)); |
1658 | 2063 |
int __w = __intVal(newWidth) - 1; |
2064 |
int __h = __intVal(newHeight) - 1; |
|
2065 |
int __row, __col; |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2066 |
double __mX = __floatVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2067 |
double __mY = __floatVal(mY); |
1 | 2068 |
|
1658 | 2069 |
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
|
2070 |
__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
|
2071 |
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
|
2072 |
*__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
|
2073 |
} |
1 | 2074 |
} |
2075 |
%} |
|
2076 |
. |
|
89 | 2077 |
"/ the above C-code is equivalent to: |
2078 |
"/ |
|
2079 |
"/ dstIndex := 1. |
|
2080 |
"/ w := newWidth - 1. |
|
2081 |
"/ h := newHeight - 1. |
|
2082 |
"/ 0 to:h do:[:row | |
|
2083 |
"/ srcRowIdx := (width * (row // mY)) + 1. |
|
2084 |
"/ 0 to:w do:[:col | |
|
2085 |
"/ srcIndex := srcRowIdx + (col // mX). |
|
2086 |
"/ value := bytes at:srcIndex. |
|
2087 |
"/ newBytes at:dstIndex put:value. |
|
2088 |
"/ dstIndex := dstIndex + 1 |
|
2089 |
"/ ] |
|
2090 |
"/ ]. |
|
2091 |
"/ |
|
1 | 2092 |
|
2093 |
^ newImage |
|
579 | 2094 |
! |
2095 |
||
4718 | 2096 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2097 |
into:dstBytes offset:dstStart factor:mX |
579 | 2098 |
|
2099 |
"magnify a single pixel row - can only magnify by integer factors. |
|
2100 |
Specially tuned for factors 2,3 and 4." |
|
2101 |
||
2102 |
%{ |
|
2103 |
REGISTER unsigned char *srcP, *dstP; |
|
2104 |
REGISTER unsigned char _byte; |
|
2184
b8daa402967f
tuned magnification by multiples-of-2
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
2105 |
unsigned _word; |
579 | 2106 |
int _mag; |
2107 |
REGISTER int i; |
|
2108 |
int _pixels; |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2109 |
OBJ w = __INST(width); |
579 | 2110 |
|
2111 |
if (__bothSmallInteger(srcStart, dstStart) |
|
2112 |
&& __bothSmallInteger(w, mX) |
|
5472
5508a0ac6319
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5453
diff
changeset
|
2113 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2114 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2115 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2116 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2117 |
_pixels = __intVal(w); |
579 | 2118 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2119 |
switch (_mag) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2120 |
case 1: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2121 |
break; |
579 | 2122 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2123 |
case 2: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2124 |
/* special code for common case */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2125 |
if (((INT)dstP & 1) == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2126 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2127 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2128 |
_word = (_byte<<8) | _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2129 |
((short *)dstP)[0] = _word; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2130 |
dstP += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2131 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2132 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2133 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2134 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2135 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2136 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2137 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2138 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2139 |
break; |
2184
b8daa402967f
tuned magnification by multiples-of-2
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
2140 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2141 |
case 3: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2142 |
/* special code for common case */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2143 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2144 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2145 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2146 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2147 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2148 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2149 |
break; |
579 | 2150 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2151 |
case 4: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2152 |
/* special code for common case */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2153 |
if (((INT)dstP & 3) == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2154 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2155 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2156 |
_word = (_byte<<8) | _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2157 |
_word = (_word<<16) | _word; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2158 |
((int *)dstP)[0] = _word; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2159 |
dstP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2160 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2161 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2162 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2163 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2164 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2165 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2166 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2167 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2168 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2169 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2170 |
break; |
579 | 2171 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2172 |
default: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2173 |
if ((((INT)dstP & 1) == 0) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2174 |
&& ((_mag & 1) == 0)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2175 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2176 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2177 |
_word = (_byte<<8) | _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2178 |
for (i=_mag; i>0; i-=2) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2179 |
((short *)dstP)[0] = _word; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2180 |
dstP += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2181 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2182 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2183 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2184 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2185 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2186 |
for (i=_mag; i>0; i--) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2187 |
*dstP++ = _byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2188 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2189 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2190 |
break; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2191 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2192 |
RETURN (self); |
579 | 2193 |
} |
3842 | 2194 |
%}. |
4718 | 2195 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2196 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2197 |
into:dstBytes offset:dstStart factor:mX |
1 | 2198 |
! ! |
579 | 2199 |
|
2200 |
!Depth8Image methodsFor:'private'! |
|
2201 |
||
2202 |
dither1PlaneUsingMap:map on:aDevice |
|
2203 |
"a helper for dithering palette and greyscale images" |
|
2204 |
||
2205 |
|f |
|
2206 |
patterns formBytes |
|
2207 |
pixel0bytes pixel1bytes |
|
2208 |
clr ditherPattern |
|
2209 |
nColors "{Class: SmallInteger }" |
|
2210 |
w "{Class: SmallInteger }" |
|
2211 |
h "{Class: SmallInteger }"| |
|
2212 |
||
2213 |
nColors := map size. |
|
2214 |
w := width. |
|
2215 |
h := height. |
|
2216 |
||
2217 |
formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h. |
|
2218 |
patterns := Array new:nColors. |
|
2219 |
pixel0bytes := ByteArray uninitializedNew:nColors. |
|
2220 |
pixel1bytes := ByteArray uninitializedNew:nColors. |
|
2221 |
||
2222 |
" |
|
2223 |
extract dither patterns and values to use for 1/0 bits |
|
2224 |
in those from the dithercolors |
|
2225 |
" |
|
2226 |
1 to:nColors do:[:i | |
|
4718 | 2227 |
clr := (map at:i) onDevice:aDevice. |
2228 |
ditherPattern := clr ditherForm. |
|
579 | 2229 |
|
4718 | 2230 |
ditherPattern isNil ifTrue:[ |
2231 |
patterns at:i put:#[2r11111111 |
|
2232 |
2r11111111 |
|
2233 |
2r11111111 |
|
2234 |
2r11111111 |
|
2235 |
2r11111111 |
|
2236 |
2r11111111 |
|
2237 |
2r11111111 |
|
2238 |
2r11111111]. |
|
2239 |
pixel0bytes at:i put:clr colorId. |
|
2240 |
pixel1bytes at:i put:clr colorId |
|
2241 |
] ifFalse:[ |
|
2242 |
patterns at:i put:(ditherPattern bits). |
|
2243 |
pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId. |
|
2244 |
pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId. |
|
2245 |
]. |
|
579 | 2246 |
]. |
2247 |
||
2248 |
%{ |
|
2249 |
unsigned char *_srcP, *_dstP; |
|
2250 |
OBJ _patternBytes; |
|
1658 | 2251 |
unsigned char __mask = 0x80; |
579 | 2252 |
unsigned char _outBits = 0; |
2253 |
unsigned char _last, _v, _patternBits, _p0, _p1; |
|
2254 |
int _h, _w; |
|
2255 |
int _patternOffset = 0; |
|
2256 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2257 |
_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
2258 |
_dstP = __ByteArrayInstPtr(formBytes)->ba_element; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
2259 |
for (_h = __intVal(h); _h; _h--) { |
4718 | 2260 |
_last = -1; |
2261 |
for (_w = __intVal(w); _w; _w--) { |
|
2262 |
_v = *_srcP++; |
|
2263 |
if (_v != _last) { |
|
2264 |
_patternBytes = __ArrayInstPtr(patterns)->a_element[_v]; |
|
2265 |
if (__isByteArray(_patternBytes)) { |
|
2266 |
_patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset]; |
|
2267 |
} else if (__isArrayLike(_patternBytes)) { |
|
2268 |
_patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]); |
|
2269 |
} |
|
2270 |
_p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v]; |
|
2271 |
_p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v]; |
|
2272 |
_last = _v; |
|
2273 |
} |
|
2274 |
_outBits <<= 1; |
|
2275 |
if (_patternBits & __mask) |
|
2276 |
_outBits |= _p1; |
|
2277 |
else |
|
2278 |
_outBits |= _p0; |
|
2279 |
__mask >>= 1; |
|
2280 |
if (__mask == 0) { |
|
2281 |
__mask = 0x80; |
|
2282 |
*_dstP++ = _outBits; |
|
2283 |
_outBits = 0; |
|
2284 |
} |
|
2285 |
} |
|
2286 |
if (__mask != 0x80) { |
|
2287 |
while (__mask != 0) { |
|
2288 |
_outBits <<= 1; |
|
2289 |
__mask >>= 1; |
|
2290 |
} |
|
2291 |
*_dstP++ = _outBits; |
|
2292 |
__mask = 0x80; |
|
2293 |
_outBits = 0; |
|
2294 |
} |
|
2295 |
_patternOffset++; |
|
2296 |
if (_patternOffset == 8) |
|
2297 |
_patternOffset = 0; |
|
579 | 2298 |
} |
2299 |
%} |
|
2300 |
. |
|
2301 |
f := Form width:w height:h fromArray:formBytes. |
|
2302 |
^ f |
|
2303 |
! |
|
2304 |
||
2305 |
dither2PlaneUsingMap:map on:aDevice |
|
2306 |
"a helper for dithering palette and greyscale images" |
|
2307 |
||
2308 |
|f |
|
2309 |
patterns formBytes |
|
2310 |
pixel0bytes pixel1bytes |
|
2311 |
clr ditherPattern |
|
2312 |
nColors "{Class: SmallInteger }" |
|
2313 |
w "{Class: SmallInteger }" |
|
2314 |
h "{Class: SmallInteger }"| |
|
2315 |
||
2316 |
nColors := map size. |
|
2317 |
w := width. |
|
2318 |
h := height. |
|
2319 |
||
2320 |
formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h. |
|
2321 |
patterns := Array new:nColors. |
|
2322 |
pixel0bytes := ByteArray uninitializedNew:nColors. |
|
2323 |
pixel1bytes := ByteArray uninitializedNew:nColors. |
|
2324 |
||
2325 |
"extract dither patterns and values to use for 1/0 bits |
|
2326 |
in those from the dithercolors" |
|
2327 |
||
2328 |
1 to:nColors do:[:i | |
|
6837 | 2329 |
clr := (map at:i) onDevice:aDevice. |
2330 |
ditherPattern := clr ditherForm. |
|
579 | 2331 |
|
6837 | 2332 |
ditherPattern isNil ifTrue:[ |
2333 |
patterns at:i put:#[2r11111111 |
|
2334 |
2r11111111 |
|
2335 |
2r11111111 |
|
2336 |
2r11111111 |
|
2337 |
2r11111111 |
|
2338 |
2r11111111 |
|
2339 |
2r11111111 |
|
2340 |
2r11111111]. |
|
2341 |
pixel0bytes at:i put:clr colorId. |
|
2342 |
pixel1bytes at:i put:clr colorId |
|
2343 |
] ifFalse:[ |
|
2344 |
patterns at:i put:(ditherPattern bits). |
|
2345 |
pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId. |
|
2346 |
pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId. |
|
2347 |
]. |
|
579 | 2348 |
]. |
2349 |
||
2350 |
%{ |
|
2351 |
unsigned char *_srcP, *_dstP; |
|
2352 |
OBJ _patternBytes; |
|
1658 | 2353 |
unsigned char __mask = 0x80; |
579 | 2354 |
unsigned char _outBits = 0; |
2355 |
unsigned char _last, _v, _patternBits, _p0, _p1; |
|
2356 |
int _h, _w; |
|
2357 |
int _patternOffset = 0; |
|
2358 |
int _outCount; |
|
2359 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6039
diff
changeset
|
2360 |
_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
2361 |
_dstP = __ByteArrayInstPtr(formBytes)->ba_element; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
2362 |
for (_h = __intVal(h); _h; _h--) { |
6837 | 2363 |
_last = -1; |
2364 |
_outCount = 0; |
|
2365 |
for (_w = __intVal(w); _w; _w--) { |
|
2366 |
_v = *_srcP++; |
|
2367 |
if (_v != _last) { |
|
2368 |
_patternBytes = __ArrayInstPtr(patterns)->a_element[_v]; |
|
2369 |
if (__isByteArray(_patternBytes)) { |
|
2370 |
_patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset]; |
|
2371 |
} else if (__isArrayLike(_patternBytes)) { |
|
2372 |
_patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]); |
|
2373 |
} |
|
2374 |
_p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v]; |
|
2375 |
_p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v]; |
|
2376 |
_last = _v; |
|
2377 |
} |
|
2378 |
_outBits <<= 2; |
|
2379 |
if (_patternBits & __mask) |
|
2380 |
_outBits |= _p1; |
|
2381 |
else |
|
2382 |
_outBits |= _p0; |
|
2383 |
__mask >>= 1; |
|
2384 |
_outCount++; |
|
2385 |
if (_outCount == 4) { |
|
2386 |
*_dstP++ = _outBits; |
|
2387 |
_outCount = 0; |
|
2388 |
if (__mask == 0) { |
|
2389 |
__mask = 0x80; |
|
2390 |
} |
|
2391 |
} |
|
2392 |
} |
|
2393 |
if (_outCount) { |
|
2394 |
do { |
|
2395 |
_outBits <<= 2; |
|
2396 |
} while (++_outCount != 4); |
|
2397 |
*_dstP++ = _outBits; |
|
2398 |
} |
|
2399 |
__mask = 0x80; |
|
2400 |
_outBits = 0; |
|
2401 |
_patternOffset++; |
|
2402 |
if (_patternOffset == 8) |
|
2403 |
_patternOffset = 0; |
|
579 | 2404 |
} |
2405 |
%} |
|
2406 |
. |
|
6837 | 2407 |
f := Form width:w height:h depth:2 onDevice:aDevice. |
7361 | 2408 |
f isNil ifTrue:[^ nil]. |
579 | 2409 |
f initGC. |
4718 | 2410 |
f graphicsDevice |
6837 | 2411 |
drawBits:formBytes |
2412 |
depth:2 |
|
2413 |
padding:8 |
|
2414 |
width:w height:h |
|
2415 |
x:0 y:0 |
|
2416 |
into:f id |
|
2417 |
x:0 y:0 |
|
2418 |
width:w height:h |
|
2419 |
with:f gcId. |
|
579 | 2420 |
^ f |
2421 |
! ! |
|
2422 |
||
2423 |
!Depth8Image methodsFor:'queries'! |
|
2424 |
||
2425 |
bitsPerPixel |
|
2426 |
"return the number of bits per pixel" |
|
2427 |
||
2428 |
^ 8 |
|
2429 |
! |
|
2430 |
||
2431 |
bitsPerRow |
|
2432 |
"return the number of bits in one scanline of the image" |
|
2433 |
||
3868 | 2434 |
^ width * 8 |
579 | 2435 |
! |
2436 |
||
2437 |
bytesPerRow |
|
2438 |
"return the number of bytes in one scanline of the image" |
|
2439 |
||
2440 |
^ width |
|
2441 |
! |
|
2442 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2443 |
colorFromValue:pixelValue |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2444 |
"given a pixel value, return the corresponding color. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2445 |
Pixel values start with 0." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2446 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2447 |
photometric == #whiteIs0 ifTrue:[ |
4718 | 2448 |
^ Color gray:100 - (100 / 255 * pixelValue) |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2449 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2450 |
photometric == #blackIs0 ifTrue:[ |
4718 | 2451 |
^ Color gray:(100 / 255 * pixelValue) |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2452 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2453 |
photometric == #palette ifTrue:[ |
4718 | 2454 |
pixelValue < colorMap size ifTrue:[ |
2455 |
^ colorMap at:(pixelValue + 1) |
|
2456 |
] |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2457 |
]. |
3869 | 2458 |
^ super colorFromValue:pixelValue |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2459 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2460 |
|
3273
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2461 |
realUsedValues |
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2462 |
"return a collection of color values used in the receiver." |
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2463 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2464 |
^ self bits usedValues |
3273
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2465 |
! |
f4cb380e0ae9
usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
2466 |
|
579 | 2467 |
usedValues |
2468 |
"return a collection of color values used in the receiver." |
|
2469 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2470 |
^ self bits usedValues |
579 | 2471 |
! ! |
2472 |
||
1167 | 2473 |
!Depth8Image class methodsFor:'documentation'! |
579 | 2474 |
|
2475 |
version |
|
7276 | 2476 |
^ '$Header$' |
5371
8825c8866613
changed: #colorsFromX:y:toX:y:do:
Claus Gittinger <cg@exept.de>
parents:
5331
diff
changeset
|
2477 |
! |
8825c8866613
changed: #colorsFromX:y:toX:y:do:
Claus Gittinger <cg@exept.de>
parents:
5331
diff
changeset
|
2478 |
|
8825c8866613
changed: #colorsFromX:y:toX:y:do:
Claus Gittinger <cg@exept.de>
parents:
5331
diff
changeset
|
2479 |
version_CVS |
7276 | 2480 |
^ '$Header$' |
579 | 2481 |
! ! |
6036 | 2482 |