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