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