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