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