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