author | Claus Gittinger <cg@exept.de> |
Wed, 21 Jan 1998 00:28:29 +0100 | |
changeset 1999 | 9ccc51eea588 |
parent 1932 | 6afe07d9c88c |
child 2042 | 58c0228331bb |
permissions | -rw-r--r-- |
3 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 3 |
All Rights Reserved |
3 | 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 |
|
1932 | 13 |
'From Smalltalk/X, Version:3.2.1 on 19-oct-1997 at 5:20:41 pm' ! |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
14 |
|
1 | 15 |
Image subclass:#Depth24Image |
579 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Graphics-Images' |
|
1 | 20 |
! |
21 |
||
1167 | 22 |
!Depth24Image class methodsFor:'documentation'! |
46 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 27 |
All Rights Reserved |
3 | 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 |
! |
|
3 | 37 |
|
46 | 38 |
documentation |
39 |
" |
|
40 |
this class represents true-color (24 bit / pixel) images. |
|
41 |
It mainly consists of methods already implemented in Image, |
|
42 |
reimplemented here for more performance. |
|
611 | 43 |
|
798 | 44 |
Only the #rgb format is supported here. |
45 |
||
611 | 46 |
[author:] |
47 |
Claus Gittinger |
|
48 |
||
49 |
[see also:] |
|
50 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image |
|
51 |
ImageReader |
|
46 | 52 |
" |
53 |
! ! |
|
3 | 54 |
|
1167 | 55 |
!Depth24Image class methodsFor:'queries'! |
89 | 56 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
57 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
58 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
59 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
60 |
^ #rgb |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
61 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
62 |
"Created: 10.6.1996 / 18:08:25 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
63 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
64 |
|
89 | 65 |
imageDepth |
579 | 66 |
"return the depth of images represented by instances of |
67 |
this class - here we return 24" |
|
68 |
||
89 | 69 |
^ 24 |
579 | 70 |
|
71 |
"Modified: 20.4.1996 / 23:39:50 / cg" |
|
89 | 72 |
! ! |
73 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
74 |
!Depth24Image methodsFor:'accessing - pixels'! |
1 | 75 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
76 |
colorAtX:x y:y |
1 | 77 |
"retrieve a pixel at x/y; return a color. |
78 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
79 |
x = width-1, y=height-1 for lower right pixel" |
|
80 |
||
38 | 81 |
|index "{ Class: SmallInteger }" |
82 |
rVal gVal bVal| |
|
1 | 83 |
|
84 |
index := 1 + (((width * y) + x) * 3). |
|
85 |
rVal := bytes at:(index). |
|
86 |
gVal := bytes at:(index + 1). |
|
87 |
bVal := bytes at:(index + 2). |
|
88 |
||
89 |
photometric ~~ #rgb ifTrue:[ |
|
1666 | 90 |
^ super colorAtX:x y:y |
1 | 91 |
]. |
1350 | 92 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
93 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
94 |
"Created: 24.4.1997 / 17:32:47 / cg" |
1666 | 95 |
"Modified: 24.4.1997 / 21:32:37 / cg" |
1 | 96 |
! |
97 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
98 |
colorAtX:x y:y put:aColor |
89 | 99 |
"set the pixel at x/y to aColor. |
100 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
101 |
x = width-1, y=height-1 for lower right pixel." |
|
102 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
103 |
|index "{ Class: SmallInteger }"| |
89 | 104 |
|
105 |
index := 1 + (((width * y) + x) * 3). |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
106 |
bytes at:(index) put:(aColor redByte). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
107 |
bytes at:(index + 1) put:(aColor greenByte). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
108 |
bytes at:(index + 2) put:(aColor blueByte). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
109 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
110 |
"Created: 24.4.1997 / 17:32:59 / cg" |
89 | 111 |
! |
112 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
113 |
pixelAtX:x y:y |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
114 |
"retrieve a pixel at x/y; return a color. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
115 |
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:
1629
diff
changeset
|
116 |
x = width-1, y=height-1 for lower right pixel" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
117 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
118 |
|index "{ Class: SmallInteger }" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
119 |
rVal "{ Class: SmallInteger }" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
120 |
gVal "{ Class: SmallInteger }" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
121 |
bVal "{ Class: SmallInteger }"| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
122 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
123 |
index := 1 + (((width * y) + x) * 3). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
124 |
rVal := bytes at:(index). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
125 |
gVal := bytes at:(index + 1). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
126 |
bVal := bytes at:(index + 2). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
127 |
^ (((rVal bitShift:8) bitOr:gVal) bitShift:8) bitOr:bVal |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
128 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
129 |
"Created: 24.4.1997 / 16:06:34 / cg" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
130 |
! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
131 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
132 |
pixelAtX:x y:y put:aPixelValue |
1 | 133 |
"set a pixel at x/y to aPixelValue, which is 24 bits RGB. |
134 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
135 |
x = width-1, y=height-1 for lower right pixel" |
|
136 |
||
137 |
|index "{ Class: SmallInteger }" |
|
138 |
val "{ Class: SmallInteger }" | |
|
139 |
||
140 |
index := 1 + (((width * y) + x) * 3). |
|
141 |
val := aPixelValue. |
|
142 |
bytes at:(index + 2) put:(val bitAnd:16rFF). |
|
143 |
val := val bitShift:-8. |
|
144 |
bytes at:(index + 1) put:(val bitAnd:16rFF). |
|
145 |
val := val bitShift:-8. |
|
146 |
bytes at:(index) put:val. |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
147 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
148 |
"Created: 24.4.1997 / 17:06:33 / cg" |
1 | 149 |
! |
150 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
151 |
rowAt:rowIndex putAll:pixelArray |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
152 |
"replace a single rows bits from bits in the pixelArray argument; |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
153 |
Notice: row indexing starts at 0." |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
154 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
155 |
|dstIdx pixel| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
156 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
157 |
dstIdx := (rowIndex * self bytesPerRow) + 1. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
158 |
1 to:width do:[:col | |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
159 |
pixel := pixelArray at:col. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
160 |
bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
161 |
bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
162 |
bytes at:dstIdx+2 put:(pixel bitAnd:16rFF). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
163 |
dstIdx := dstIdx + 3. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
164 |
]. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
165 |
^ pixelArray |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
166 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
167 |
"Created: 24.4.1997 / 15:43:08 / cg" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
168 |
! |
1 | 169 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
170 |
rowAt:rowIndex putAll:pixelArray startingAt:startIndex |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
171 |
"store a single rows bits from bits in the pixelArray argument; |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
172 |
Return the pixelArray. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
173 |
Notice: row indexing starts at 0." |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
174 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
175 |
|dstIdx pixel| |
1 | 176 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
177 |
dstIdx := (rowIndex * self bytesPerRow) + 1. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
178 |
1 to:width do:[:col | |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
179 |
pixel := pixelArray at:(startIndex + col). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
180 |
bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
181 |
bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
182 |
bytes at:dstIdx+2 put:(pixel bitAnd:16rFF). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
183 |
dstIdx := dstIdx + 3. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
184 |
]. |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
185 |
^ pixelArray |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
186 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
187 |
"Created: 24.4.1997 / 15:50:27 / cg" |
1 | 188 |
! ! |
189 |
||
190 |
!Depth24Image methodsFor:'converting rgb images'! |
|
191 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
192 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
193 |
"return a grey form from the receiver. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
194 |
Redefined to use special code when converting to 8-bit |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
195 |
greyScale displays." |
1 | 196 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
197 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
198 |
aDevice depth == 8 ifTrue:[ |
816 | 199 |
^ self makeDeviceGrayPixmapOn:aDevice depth:aDevice depth fromArray:(self threshold8BitGrayBits) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
200 |
]. |
1 | 201 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
202 |
^ super asGrayFormOn:aDevice |
1 | 203 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
204 |
"Created: 10.6.1996 / 19:00:45 / cg" |
816 | 205 |
"Modified: 10.6.1996 / 20:10:19 / cg" |
1 | 206 |
! |
207 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
208 |
asThresholdGrayImageDepth:depth |
808 | 209 |
"return an 8-bit grey image from the rgb picture. |
210 |
Pixel values are reduced to a 0..255 grey level." |
|
1 | 211 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
212 |
depth == 8 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
213 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
214 |
^ Depth8Image |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
215 |
width:width |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
216 |
height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
217 |
fromArray:(self threshold8BitGrayBits) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
218 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
219 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
220 |
^ super asThresholdGrayImageDepth:depth |
808 | 221 |
|
222 |
" |
|
223 |
|i| |
|
224 |
||
225 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
226 |
(i asThresholdGrayImageDepth:8) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
227 |
(i asThresholdGrayImageDepth:4) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
228 |
(i asThresholdGrayImageDepth:2) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
229 |
(i asThresholdGrayImageDepth:1) inspect. |
808 | 230 |
" |
1 | 231 |
|
808 | 232 |
" |
233 |
|i| |
|
234 |
||
235 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
236 |
((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:2) inspect |
808 | 237 |
" |
238 |
||
239 |
" |
|
240 |
|i| |
|
1 | 241 |
|
808 | 242 |
i := Image fromFile:'bitmaps/granite.tiff'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
243 |
((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:4) inspect |
808 | 244 |
" |
245 |
||
246 |
" |
|
247 |
|i| |
|
248 |
||
249 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
250 |
(i asThresholdGrayImageDepth:8) asOrderedDitheredMonochromeImage inspect |
808 | 251 |
" |
252 |
||
253 |
"Created: 8.6.1996 / 13:58:46 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
254 |
"Modified: 10.6.1996 / 19:11:18 / cg" |
1 | 255 |
! |
256 |
||
282 | 257 |
rgbImageAsDitheredPseudoFormOn:aDevice |
258 |
"return a dithered pseudocolor form from the rgb-picture. |
|
259 |
This method depends on fixColors being allocated (see Color>>getColors*)" |
|
260 |
||
1607 | 261 |
|ditherColors| |
262 |
||
263 |
(ditherColors := aDevice fixColors) notNil ifTrue:[ |
|
264 |
^ self |
|
265 |
rgbImageAsDitheredPseudoFormOn:aDevice |
|
266 |
colors:ditherColors |
|
267 |
nRed:aDevice numFixRed |
|
268 |
nGreen:aDevice numFixGreen |
|
269 |
nBlue:aDevice numFixBlue |
|
270 |
]. |
|
271 |
||
272 |
ditherColors := Set new. |
|
273 |
ditherColors addAll:(aDevice ditherColors). |
|
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
274 |
ditherColors addAll:(aDevice deviceColors). |
1607 | 275 |
ditherColors := ditherColors asArray. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
276 |
^ self |
1607 | 277 |
rgbImageAsDitheredPseudoFormOn:aDevice |
278 |
colors:ditherColors. |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
279 |
|
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
280 |
"Modified: 22.4.1997 / 11:59:44 / cg" |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
281 |
! |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
282 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
283 |
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
284 |
"return a dithered 8-bit pseudocolor form from the rgb-picture, using |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
285 |
arbitrary fix colors in fixColors." |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
286 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
287 |
|pseudoBits f |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
288 |
h "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
289 |
w "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
290 |
numFix "{Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
291 |
srcIndex "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
292 |
dstIndex "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
293 |
deviceDepth has8BitImage |
1607 | 294 |
fixIds fixRed fixGreen fixBlue failed cache idsUsed usedColors| |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
295 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
296 |
numFix := fixColors size. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
297 |
numFix == 256 ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
298 |
"/ algorithm below only handles 255 colors. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
299 |
numFix := 255. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
300 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
301 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
1607 | 302 |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
303 |
fixRed := (fixColors asArray collect:[:clr | clr redByte]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
304 |
fixGreen := (fixColors asArray collect:[:clr | clr greenByte]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
305 |
fixBlue := (fixColors asArray collect:[:clr | clr blueByte]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
306 |
cache := ByteArray new:(1 bitShift:14). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
307 |
cache atAllPut:16rFF. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
308 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
309 |
deviceDepth := aDevice depth. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
310 |
deviceDepth == 8 ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
311 |
has8BitImage := true. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
312 |
] ifFalse:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
313 |
has8BitImage := false. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
314 |
aDevice supportedImageFormats do:[:fmt | |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
315 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
316 |
has8BitImage := true. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
317 |
] |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
318 |
] |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
319 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
320 |
has8BitImage ifFalse:[^ nil]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
321 |
|
1607 | 322 |
idsUsed := ByteArray new:(fixIds size). |
323 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
324 |
'Depth24Image [info]: dithering ...' infoPrintCR. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
325 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
326 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
327 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
328 |
h := height. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
329 |
w := width. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
330 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
331 |
%{ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
332 |
int __x, __y, __numFix; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
333 |
int __eR, __eG, __eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
334 |
unsigned char *srcP, *dstP; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
335 |
int pix; |
1607 | 336 |
unsigned char *idP, *usedIdP, *redP, *greenP, *blueP, *cacheP; |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
337 |
int __w = __intVal(w); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
338 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
339 |
if (__isByteArray(__INST(bytes)) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
340 |
&& __isSmallInteger(numFix) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
341 |
&& __isByteArray(pseudoBits) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
342 |
&& __isByteArray(cache) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
343 |
&& __isByteArray(fixIds) |
1607 | 344 |
&& __isByteArray(idsUsed) |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
345 |
&& __isByteArray(fixRed) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
346 |
&& __isByteArray(fixGreen) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
347 |
&& __isByteArray(fixBlue) ) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
348 |
failed = false; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
349 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
350 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
351 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
352 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
1607 | 353 |
usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element; |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
354 |
redP = __ByteArrayInstPtr(fixRed)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
355 |
greenP = __ByteArrayInstPtr(fixGreen)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
356 |
blueP = __ByteArrayInstPtr(fixBlue)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
357 |
cacheP = __ByteArrayInstPtr(cache)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
358 |
__numFix = __intVal(numFix); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
359 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
360 |
for (__y=__intVal(h); __y>0; __y--) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
361 |
__eR = __eG = __eB = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
362 |
for (__x=__w; __x>0; __x--) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
363 |
int cacheIdx, clrIdx; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
364 |
int __wantR, __wantG, __wantB; |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
365 |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
366 |
__wantR = srcP[0] + __eR; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
367 |
if (__wantR > 255) __wantR = 255; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
368 |
else if (__wantR < 0) __wantR = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
369 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
370 |
__wantG = srcP[1] + __eG; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
371 |
if (__wantG > 255) __wantG = 255; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
372 |
else if (__wantG < 0) __wantG = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
373 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
374 |
__wantB = srcP[2] + __eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
375 |
if (__wantB > 255) __wantB = 255; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
376 |
else if (__wantB < 0) __wantB = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
377 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
378 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
379 |
* compute cache index |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
380 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
381 |
cacheIdx = ((__wantR & 0xF8) >> 3); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
382 |
cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
383 |
cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
384 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
385 |
clrIdx = cacheP[cacheIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
386 |
if (clrIdx == 0xFF) { /* invalid slot */ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
387 |
unsigned minErr, minIdx; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
388 |
int i; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
389 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
390 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
391 |
* must search ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
392 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
393 |
minErr = 0x7FFFFFF; minIdx = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
394 |
for (i=0; i<__numFix; i++) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
395 |
unsigned cR, cG, cB, e; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
396 |
int eR, eG, eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
397 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
398 |
cR = redP[i]; cG = greenP[i]; cB = blueP[i]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
399 |
eR = cR - __wantR; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
400 |
if (eR < 0) eR = -eR; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
401 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
402 |
eG = cG - __wantG; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
403 |
if (eG < 0) eG = -eG; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
404 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
405 |
eB = cB - __wantB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
406 |
if (eB < 0) eB = -eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
407 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
408 |
e = eR + eG + eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
409 |
if (e < minErr) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
410 |
minErr = e; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
411 |
minIdx = i; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
412 |
if (e < 7) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
413 |
break; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
414 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
415 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
416 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
417 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
418 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
419 |
* minIdx is now index into fixColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
420 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
421 |
cacheP[cacheIdx] = clrIdx = minIdx; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
422 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
423 |
printf("want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
424 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
425 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
426 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
427 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
428 |
* store the corresponding dither colorId |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
429 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
430 |
*dstP++ = idP[clrIdx]; |
1607 | 431 |
usedIdP[clrIdx] = 1; |
432 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
433 |
srcP += 3; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
434 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
435 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
436 |
* the new error: |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
437 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
438 |
__eR = __wantR - redP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
439 |
__eG = __wantG - greenP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
440 |
__eB = __wantB - blueP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
441 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
442 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
443 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
444 |
%}. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
445 |
failed ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
446 |
self primitiveFailed. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
447 |
^ nil |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
448 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
449 |
|
1607 | 450 |
"/ not all colors may be really in use ... |
451 |
usedColors := fixColors copy. |
|
452 |
idsUsed keysAndValuesDo:[:idx :flag | |
|
453 |
flag == 0 ifTrue:[ |
|
454 |
usedColors at:idx put:nil |
|
455 |
] |
|
456 |
]. |
|
457 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
458 |
f := Form width:width height:height depth:aDevice depth on:aDevice. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
459 |
f isNil ifTrue:[^ nil]. |
1607 | 460 |
f colorMap:usedColors. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
461 |
f initGC. |
1999
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
462 |
aDevice |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
463 |
drawBits:pseudoBits |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
464 |
bitsPerPixel:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
465 |
depth:aDevice depth |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
466 |
padding:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
467 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
468 |
x:0 y:0 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
469 |
into:(f id) |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
470 |
x:0 y:0 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
471 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
472 |
with:(f gcId). |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
473 |
^ f |
282 | 474 |
! |
475 |
||
476 |
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
477 |
"return a dithered pseudocolor form from the rgb-picture, |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
478 |
using colors from a colorCube for dithering." |
282 | 479 |
|
480 |
|pseudoBits f |
|
481 |
h "{ Class: SmallInteger }" |
|
482 |
w "{ Class: SmallInteger }" |
|
483 |
"/ eR "{Class: SmallInteger }" |
|
484 |
"/ eG "{Class: SmallInteger }" |
|
485 |
"/ eB "{Class: SmallInteger }" |
|
486 |
"/ wantR "{Class: SmallInteger }" |
|
487 |
"/ wantG "{Class: SmallInteger }" |
|
488 |
"/ wantB "{Class: SmallInteger }" |
|
489 |
fixR "{Class: SmallInteger }" |
|
490 |
fixG "{Class: SmallInteger }" |
|
491 |
fixB "{Class: SmallInteger }" |
|
492 |
srcIndex "{ Class: SmallInteger }" |
|
493 |
dstIndex "{ Class: SmallInteger }" |
|
494 |
deviceDepth has8BitImage |
|
1607 | 495 |
fixIds idsUsed failed usedColors| |
282 | 496 |
|
497 |
fixR := nRed. |
|
498 |
fixR == 0 ifTrue:[ ^ nil]. |
|
499 |
fixG := nGreen. |
|
500 |
fixG == 0 ifTrue:[ ^ nil]. |
|
501 |
fixB := nBlue. |
|
502 |
fixB == 0 ifTrue:[ ^ nil]. |
|
503 |
"/ simple check |
|
504 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
858 | 505 |
self error:'invalid color array passed'. |
506 |
^ nil |
|
282 | 507 |
]. |
508 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
1607 | 509 |
idsUsed := ByteArray new:(fixIds size). |
282 | 510 |
|
511 |
deviceDepth := aDevice depth. |
|
512 |
deviceDepth == 8 ifTrue:[ |
|
858 | 513 |
has8BitImage := true. |
282 | 514 |
] ifFalse:[ |
858 | 515 |
has8BitImage := false. |
516 |
aDevice supportedImageFormats do:[:fmt | |
|
517 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
518 |
has8BitImage := true. |
|
519 |
] |
|
520 |
] |
|
282 | 521 |
]. |
522 |
has8BitImage ifFalse:[^ nil]. |
|
523 |
||
1167 | 524 |
'Depth24Image [info]: dithering ...' infoPrintCR. |
282 | 525 |
|
526 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
527 |
||
528 |
h := height. |
|
529 |
w := width. |
|
530 |
||
531 |
%{ |
|
532 |
int __x, __y; |
|
533 |
int __eR, __eG, __eB; |
|
534 |
int __wantR, __wantG, __wantB; |
|
535 |
unsigned char *srcP, *dstP; |
|
536 |
unsigned char *redP, *greenP, *blueP; |
|
537 |
int pix; |
|
538 |
unsigned char *idP; |
|
1607 | 539 |
unsigned char *usedIdP; |
282 | 540 |
int __fR, __fG, __fB; |
541 |
int iR, iG, iB; |
|
542 |
int idx; |
|
858 | 543 |
int __w = __intVal(w); |
1817 | 544 |
int leftToRight; |
282 | 545 |
|
858 | 546 |
if (__isByteArray(__INST(bytes)) |
282 | 547 |
&& __isByteArray(pseudoBits) |
548 |
&& __isByteArray(fixIds) |
|
1607 | 549 |
&& __isByteArray(idsUsed) |
282 | 550 |
&& __bothSmallInteger(fixR, fixG) |
551 |
&& __isSmallInteger(fixB)) { |
|
858 | 552 |
failed = false; |
282 | 553 |
|
858 | 554 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
555 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
556 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
1607 | 557 |
usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element; |
858 | 558 |
__fR = __intVal(fixR)-1; |
559 |
__fG = __intVal(fixG)-1; |
|
560 |
__fB = __intVal(fixB)-1; |
|
282 | 561 |
|
1818 | 562 |
__eR = __eG = __eB = 0; |
563 |
||
1817 | 564 |
leftToRight = 1; |
858 | 565 |
for (__y=__intVal(h); __y>0; __y--) { |
1817 | 566 |
if (leftToRight) { |
567 |
for (__x=__w; __x>0; __x--) { |
|
568 |
int __want; |
|
569 |
||
570 |
/* |
|
571 |
* wR, wG and wB is the wanted r/g/b value; |
|
572 |
* compute the index into the dId table .. |
|
573 |
* values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1 |
|
574 |
* |
|
575 |
* bad kludge: knows how to index into FixColor table |
|
576 |
*/ |
|
577 |
__wantR = __want = srcP[0] + __eR; |
|
578 |
||
579 |
if (__want > 255) __want = 255; |
|
580 |
else if (__want < 0) __want = 0; |
|
581 |
||
582 |
iR = __want * __fR / 128; |
|
583 |
iR = (iR / 2) + (iR & 1); |
|
282 | 584 |
|
1817 | 585 |
__wantG = __want = srcP[1] + __eG; |
586 |
if (__want > 255) __want = 255; |
|
587 |
else if (__want < 0) __want = 0; |
|
588 |
||
589 |
iG = __want * __fG / 128; |
|
590 |
iG = (iG / 2) + (iG & 1); |
|
591 |
||
592 |
__wantB = __want = srcP[2] + __eB; |
|
593 |
if (__want > 255) __want = 255; |
|
594 |
else if (__want < 0) __want = 0; |
|
282 | 595 |
|
1817 | 596 |
iB = __want * __fB / 128; |
597 |
iB = (iB / 2) + (iB & 1); |
|
598 |
||
599 |
idx = iR * (__fG+1); |
|
600 |
idx = (idx + iG) * (__fB+1); |
|
601 |
idx = idx + iB; |
|
858 | 602 |
|
1817 | 603 |
/* |
604 |
* store the corresponding dither colorId |
|
605 |
*/ |
|
606 |
*dstP++ = idP[idx]; |
|
607 |
usedIdP[idx] = 1; |
|
282 | 608 |
|
1817 | 609 |
srcP += 3; |
282 | 610 |
|
1817 | 611 |
/* |
612 |
* the new error: |
|
613 |
*/ |
|
614 |
__eR = __wantR - (iR * 256 / __fR); |
|
615 |
__eG = __wantG - (iG * 256 / __fG); |
|
616 |
__eB = __wantB - (iB * 256 / __fB); |
|
617 |
} |
|
618 |
leftToRight = 0; |
|
619 |
} else { |
|
620 |
srcP += (__w*3); |
|
621 |
dstP += __w; |
|
622 |
for (__x=__w; __x>0; __x--) { |
|
623 |
int __want; |
|
282 | 624 |
|
1817 | 625 |
/* |
626 |
* wR, wG and wB is the wanted r/g/b value; |
|
627 |
* compute the index into the dId table .. |
|
628 |
* values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1 |
|
629 |
* |
|
630 |
* bad kludge: knows how to index into FixColor table |
|
631 |
*/ |
|
632 |
srcP -= 3; |
|
633 |
__wantR = __want = srcP[0] + __eR; |
|
282 | 634 |
|
1817 | 635 |
if (__want > 255) __want = 255; |
636 |
else if (__want < 0) __want = 0; |
|
637 |
||
638 |
iR = __want * __fR / 128; |
|
639 |
iR = (iR / 2) + (iR & 1); |
|
282 | 640 |
|
1817 | 641 |
__wantG = __want = srcP[1] + __eG; |
642 |
if (__want > 255) __want = 255; |
|
643 |
else if (__want < 0) __want = 0; |
|
644 |
||
645 |
iG = __want * __fG / 128; |
|
646 |
iG = (iG / 2) + (iG & 1); |
|
647 |
||
648 |
__wantB = __want = srcP[2] + __eB; |
|
649 |
if (__want > 255) __want = 255; |
|
650 |
else if (__want < 0) __want = 0; |
|
651 |
||
652 |
iB = __want * __fB / 128; |
|
653 |
iB = (iB / 2) + (iB & 1); |
|
282 | 654 |
|
1817 | 655 |
idx = iR * (__fG+1); |
656 |
idx = (idx + iG) * (__fB+1); |
|
657 |
idx = idx + iB; |
|
658 |
||
659 |
/* |
|
660 |
* store the corresponding dither colorId |
|
661 |
*/ |
|
662 |
*--dstP = idP[idx]; |
|
663 |
usedIdP[idx] = 1; |
|
858 | 664 |
|
1817 | 665 |
/* |
666 |
* the new error: |
|
667 |
*/ |
|
668 |
__eR = __wantR - (iR * 256 / __fR); |
|
669 |
__eG = __wantG - (iG * 256 / __fG); |
|
670 |
__eB = __wantB - (iB * 256 / __fB); |
|
671 |
} |
|
672 |
srcP += (__w*3); |
|
673 |
dstP += __w; |
|
674 |
leftToRight = 1; |
|
858 | 675 |
} |
676 |
} |
|
282 | 677 |
} |
678 |
%}. |
|
679 |
failed ifTrue:[ |
|
858 | 680 |
self primitiveFailed. |
681 |
^ nil |
|
282 | 682 |
|
683 |
"/ for non-C programmers: |
|
1218
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
684 |
"/ the above code is (roughly) equivalent to: |
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
685 |
"/ (but it is just as ugly looking as the above ;-) |
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
686 |
"/ |
282 | 687 |
"/ srcIndex := 1. |
688 |
"/ dstIndex := 1. |
|
689 |
"/ 1 to:h do:[:y | |
|
690 |
"/ eR := eG := eB := 0. |
|
691 |
"/ 1 to:w do:[:x | |
|
692 |
"/ |pixel "{ Class: SmallInteger }" |
|
693 |
"/ clr |
|
694 |
"/ idx "{ Class: SmallInteger }" |
|
695 |
"/ iR "{ Class: SmallInteger }" |
|
696 |
"/ iG "{ Class: SmallInteger }" |
|
697 |
"/ iB "{ Class: SmallInteger }" |
|
698 |
"/ wR "{ Class: SmallInteger }" |
|
699 |
"/ wG "{ Class: SmallInteger }" |
|
700 |
"/ wB "{ Class: SmallInteger }" | |
|
701 |
"/ |
|
702 |
"/ wantR := ((bytes at:srcIndex) + eR). srcIndex := srcIndex + 1. |
|
703 |
"/ wantG := ((bytes at:srcIndex) + eG). srcIndex := srcIndex + 1. |
|
704 |
"/ wantB := ((bytes at:srcIndex) + eB). srcIndex := srcIndex + 1. |
|
705 |
"/ wR := wantR. |
|
706 |
"/ wR > 255 ifTrue:[wR := 255] ifFalse:[wR < 0 ifTrue:[wR := 0]]. |
|
707 |
"/ wG := wantG. |
|
708 |
"/ wG > 255 ifTrue:[wG := 255] ifFalse:[wG < 0 ifTrue:[wG := 0]]. |
|
709 |
"/ wB := wantB. |
|
710 |
"/ wB > 255 ifTrue:[wB := 255] ifFalse:[wB < 0 ifTrue:[wB := 0]]. |
|
711 |
"/ |
|
712 |
"/ iR := wR * (fixR-1) // 128. |
|
713 |
"/ iR := (iR // 2) + (iR bitAnd:1). |
|
714 |
"/ iG := wG * (fixG-1) // 128. |
|
715 |
"/ iG := (iG // 2) + (iG bitAnd:1). |
|
716 |
"/ iB := wB * (fixB-1) // 128. |
|
717 |
"/ iB := (iB // 2) + (iB bitAnd:1). |
|
718 |
"/ idx := (iR * fixR + iG) * fixB + iB + 1. |
|
719 |
"/ |
|
720 |
"/ clr := fixColors at:idx. |
|
721 |
"/ |
|
722 |
"/ eR := wantR - (clr red * 2) asInteger. |
|
723 |
"/ eG := wantG - (clr green * 2) asInteger. |
|
724 |
"/ eB := wantB - (clr blue * 2) asInteger. |
|
725 |
"/ |
|
726 |
"/ pixel := clr colorId. |
|
727 |
"/ pseudoBits at:dstIndex put:pixel. |
|
728 |
"/ |
|
729 |
"/ dstIndex := dstIndex + 1 |
|
730 |
"/ ]. |
|
731 |
]. |
|
732 |
||
1607 | 733 |
"/ not all colors may be really in use ... |
734 |
usedColors := fixColors copy. |
|
735 |
idsUsed keysAndValuesDo:[:idx :flag | |
|
736 |
flag == 0 ifTrue:[ |
|
737 |
usedColors at:idx put:nil |
|
738 |
] |
|
739 |
]. |
|
740 |
||
282 | 741 |
f := Form width:width height:height depth:aDevice depth on:aDevice. |
742 |
f isNil ifTrue:[^ nil]. |
|
1607 | 743 |
f colorMap:usedColors. |
282 | 744 |
f initGC. |
1999
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
745 |
aDevice |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
746 |
drawBits:pseudoBits |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
747 |
bitsPerPixel:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
748 |
depth:aDevice depth |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
749 |
padding:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
750 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
751 |
x:0 y:0 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
752 |
into:(f id) |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
753 |
x:0 y:0 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
754 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
755 |
with:(f gcId). |
282 | 756 |
^ f |
757 |
! |
|
758 |
||
1 | 759 |
rgbImageAsPseudoFormOn:aDevice |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
760 |
"return a pseudocolor form from the rgb-picture. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
761 |
If a colorCube is used, pass the work on to the cube-dither |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
762 |
code. Otherwise, allocate as many colors as possible, then |
1607 | 763 |
use those for dithering. |
764 |
Could be improved, by searching for (& allocating) |
|
765 |
heavily used colors and/or min-max colors first." |
|
1 | 766 |
|
767 |
|pseudoBits f |
|
768 |
r "{ Class: SmallInteger }" |
|
769 |
g "{ Class: SmallInteger }" |
|
770 |
b "{ Class: SmallInteger }" |
|
771 |
srcIndex "{ Class: SmallInteger }" |
|
772 |
dstIndex "{ Class: SmallInteger }" |
|
773 |
rMask "{ Class: SmallInteger }" |
|
774 |
gMask "{ Class: SmallInteger }" |
|
775 |
bMask "{ Class: SmallInteger }" |
|
776 |
redArray greenArray blueArray |
|
777 |
dataSize "{ Class: SmallInteger }" |
|
778 |
nColors "{ Class: SmallInteger }" |
|
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
779 |
fit fitMap colors color ditherColors |
1 | 780 |
fast |
781 |
colorIndex "{ Class: SmallInteger }" |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
782 |
depth nColorCells deep nColorsNeeded| |
89 | 783 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
784 |
aDevice fixColors notNil ifTrue:[ |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
785 |
"/ no need to look for used colors - dithering anyway ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
786 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
787 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
788 |
f notNil ifTrue:[^ f]. |
89 | 789 |
]. |
1 | 790 |
|
791 |
"find used colors; build color-tree" |
|
792 |
||
793 |
fit := false. |
|
794 |
fitMap := false. |
|
795 |
depth := aDevice depth. |
|
796 |
nColorCells := aDevice ncells. |
|
797 |
||
89 | 798 |
deep := (depth > 8). |
799 |
||
1 | 800 |
rMask := 2r11111111. |
801 |
gMask := 2r11111111. |
|
802 |
bMask := 2r11111111. |
|
803 |
||
1167 | 804 |
'Depth24Image [info]: allocating colors ...' infoPrintCR. |
66 | 805 |
|
1 | 806 |
[fit] whileFalse:[ |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
807 |
[fitMap] whileFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
808 |
srcIndex := 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
809 |
redArray := Array new:256. |
1 | 810 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
811 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
812 |
find used colors, build [r][g][b] 3-dimensional array |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
813 |
containing true for used colors |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
814 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
815 |
nColors := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
816 |
srcIndex := 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
817 |
dataSize := bytes size. |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
818 |
[(srcIndex < dataSize) |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
819 |
and:[nColors <= nColorCells]] whileTrue:[ |
1 | 820 |
%{ |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
821 |
if (__isByteArray(_INST(bytes))) { |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
822 |
int sI = _intVal(srcIndex); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
823 |
unsigned char *cp = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
1 | 824 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
825 |
r = __MKSMALLINT((cp[sI - 1] & _intVal(rMask)) + 1); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
826 |
g = __MKSMALLINT((cp[sI] & _intVal(gMask)) + 1); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
827 |
b = __MKSMALLINT((cp[sI + 1] & _intVal(bMask)) + 1); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
828 |
srcIndex = __MKSMALLINT(sI + 3); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
829 |
fast = true; |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
830 |
} else { |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
831 |
fast = false; |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
832 |
} |
1 | 833 |
%} |
834 |
. |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
835 |
fast ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
836 |
r := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
837 |
r := (r bitAnd:rMask) + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
838 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
839 |
g := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
840 |
g := (g bitAnd:gMask) + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
841 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
842 |
b := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
843 |
b := (b bitAnd:bMask) + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
844 |
srcIndex := srcIndex + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
845 |
]. |
1 | 846 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
847 |
greenArray := redArray at:r. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
848 |
greenArray isNil ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
849 |
greenArray := Array new:256. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
850 |
redArray at:r put:greenArray |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
851 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
852 |
blueArray := greenArray at:g. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
853 |
blueArray isNil ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
854 |
deep ifTrue:[blueArray := Array new:256] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
855 |
ifFalse:[blueArray := ByteArray new:256]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
856 |
greenArray at:g put:blueArray |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
857 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
858 |
(blueArray at:b) == 0 ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
859 |
blueArray at:b put:1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
860 |
nColors := nColors + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
861 |
(nColors > nColorCells) ifTrue:[ |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
862 |
"/ 'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR. |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
863 |
srcIndex := dataSize + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
864 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
865 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
866 |
]. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
867 |
nColorsNeeded isNil ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
868 |
nColorsNeeded := nColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
869 |
]. |
1 | 870 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
871 |
"again with less color bits if it does not fit colormap" |
1 | 872 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
873 |
(nColors <= nColorCells) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
874 |
fitMap := true |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
875 |
] ifFalse:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
876 |
"/ must try again - cutting off some bits |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
877 |
"/ blue bits are snipped off faster. |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
878 |
(bMask == 2r11111111) ifTrue:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
879 |
bMask := 2r11111100 |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
880 |
] ifFalse:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
881 |
(bMask == 2r11111100) ifTrue:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
882 |
bMask := 2r11110000 |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
883 |
] ifFalse:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
884 |
(rMask == 2r11111111) ifTrue:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
885 |
rMask := 2r11111100. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
886 |
gMask := 2r11111100. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
887 |
] ifFalse:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
888 |
rMask := (rMask bitShift:1) bitAnd:2r11111111. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
889 |
gMask := (gMask bitShift:1) bitAnd:2r11111111. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
890 |
bMask := (bMask bitShift:1) bitAnd:2r11111111 |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
891 |
] |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
892 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
893 |
]. |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
894 |
"/ 'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR. |
38 | 895 |
" |
1 | 896 |
'masks:' print. rMask print. ' ' print. gMask print. ' ' print. |
897 |
bMask printNewline |
|
38 | 898 |
" |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
899 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
900 |
]. |
1 | 901 |
|
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
902 |
"/ 'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR. |
89 | 903 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
904 |
colors := Array new:nColors. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
905 |
colorIndex := 1. |
1 | 906 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
907 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
908 |
now, we have reduced things to the number of colors |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
909 |
which are theoretically supported by the devices colormap. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
910 |
allocate all used colors in walking over true entries in |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
911 |
the [r][g][b] table - this may still fail, |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
912 |
if we run out of device colors. |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
913 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
914 |
fit := true. |
1 | 915 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
916 |
r := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
917 |
redArray do:[:greenArray | |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
918 |
(fit and:[greenArray notNil]) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
919 |
g := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
920 |
greenArray do:[:blueArray | |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
921 |
(fit and:[blueArray notNil]) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
922 |
b := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
923 |
blueArray do:[:present | |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
924 |
|id| |
89 | 925 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
926 |
(fit and:[present ~~ 0]) ifTrue:[ |
1237 | 927 |
color := Color redByte:r |
928 |
greenByte:g |
|
929 |
blueByte:b. |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
930 |
color := color on:aDevice. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
931 |
(id := color colorId) isNil ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
932 |
fit := false |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
933 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
934 |
colors at:colorIndex put:color. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
935 |
colorIndex := colorIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
936 |
blueArray at:(b + 1) put:id |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
937 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
938 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
939 |
b := b + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
940 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
941 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
942 |
g := g + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
943 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
944 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
945 |
r := r + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
946 |
]. |
1 | 947 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
948 |
"again with less color bits if we did not get all colors" |
1 | 949 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
950 |
fit ifFalse:[ |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
951 |
"/ 'Depth24Image [info]: could not allocate color(s)' infoPrintCR. |
1 | 952 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
953 |
"free the allocated colors" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
954 |
colors atAllPut:nil. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
955 |
"a kludge - force immediate freeing of colors" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
956 |
ObjectMemory scavenge; finalize. |
1 | 957 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
958 |
"cut off one more color-bit - cut off blue first" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
959 |
(bMask == 2r11111111) ifTrue:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
960 |
bMask := 2r11111100 |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
961 |
] ifFalse:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
962 |
(bMask == 2r11111100) ifTrue:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
963 |
bMask := 2r11110000 |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
964 |
] ifFalse:[ |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
965 |
(rMask == 2r11111111) ifTrue:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
966 |
rMask := 2r11111100. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
967 |
gMask := 2r11111100. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
968 |
] ifFalse:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
969 |
rMask := (rMask bitShift:1) bitAnd:2r11111111. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
970 |
gMask := (gMask bitShift:1) bitAnd:2r11111111. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
971 |
bMask := (bMask bitShift:1) bitAnd:2r11111111 |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
972 |
] |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
973 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
974 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
975 |
fitMap := false. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
976 |
redArray := nil |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
977 |
] |
1 | 978 |
]. |
979 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
980 |
(nColors ~~ nColorsNeeded) ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
981 |
"/ mhmh - did not get all colors ... |
1607 | 982 |
"/ add existing colors and dither. |
983 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
984 |
'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
985 |
nColorsNeeded infoPrint. ' image colors.' infoPrintCR. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
986 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
987 |
"/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
988 |
"/ dither using those we got ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
989 |
"/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
990 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
991 |
colors := colors asSet. |
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
992 |
"/ ditherColors := aDevice availableDitherColors. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
993 |
"/ ditherColors notNil ifTrue:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
994 |
"/ colors addAll:ditherColors. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
995 |
"/ ]. |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
996 |
"/ colors addAll:aDevice deviceColors. |
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
997 |
colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]). |
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
998 |
colors := colors select:[:c | c colorId notNil]. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
999 |
colors := colors asArray. |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1000 |
colors size > 256 ifTrue:[ |
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1001 |
colors := colors copyTo:256 |
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1002 |
]. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1003 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1004 |
f notNil ifTrue:[^ f]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1005 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1006 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1007 |
|
1 | 1008 |
"create pseudocolor bits and translate" |
1009 |
||
1010 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
1011 |
||
1012 |
srcIndex := 1. |
|
1013 |
dstIndex := 1. |
|
1014 |
||
89 | 1015 |
(rMask == 2r11111111 |
1016 |
and:[gMask == 2r11111111 |
|
1017 |
and:[bMask == 2r11111111]]) ifTrue:[ |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1018 |
[srcIndex < dataSize] whileTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1019 |
r := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1020 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1021 |
g := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1022 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1023 |
b := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1024 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1025 |
greenArray := redArray at:(r + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1026 |
blueArray := greenArray at:(g + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1027 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1028 |
dstIndex := dstIndex + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1029 |
] |
89 | 1030 |
] ifFalse:[ |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1031 |
[srcIndex < dataSize] whileTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1032 |
r := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1033 |
r := r bitAnd:rMask. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1034 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1035 |
g := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1036 |
g := g bitAnd:gMask. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1037 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1038 |
b := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1039 |
b := b bitAnd:bMask. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1040 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1041 |
greenArray := redArray at:(r + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1042 |
blueArray := greenArray at:(g + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1043 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1044 |
dstIndex := dstIndex + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
1045 |
] |
1 | 1046 |
]. |
1047 |
||
89 | 1048 |
f := Form width:width height:height depth:depth on:aDevice. |
1 | 1049 |
f isNil ifTrue:[^ nil]. |
1050 |
f colorMap:colors. |
|
1051 |
f initGC. |
|
1999
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1052 |
aDevice |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1053 |
drawBits:pseudoBits |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1054 |
bitsPerPixel:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1055 |
depth:depth |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1056 |
padding:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1057 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1058 |
x:0 y:0 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1059 |
into:(f id) |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1060 |
x:0 y:0 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1061 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1062 |
with:(f gcId). |
1 | 1063 |
^ f |
194 | 1064 |
! |
1065 |
||
1066 |
rgbImageAsTrueColorFormOn:aDevice |
|
1067 |
"return a truecolor form from the rgb-picture." |
|
1068 |
||
1069 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
1070 |
myDepth form imageBits destIndex srcIndex |
|
856 | 1071 |
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue| |
194 | 1072 |
|
1073 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
236 | 1074 |
usedDeviceDepth := bestFormat at:#depth. |
1075 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
|
194 | 1076 |
|
1077 |
rightShiftR := (8 - aDevice bitsRed). |
|
1078 |
rightShiftG := (8 - aDevice bitsGreen). |
|
1079 |
rightShiftB := (8 - aDevice bitsBlue). |
|
1080 |
||
1081 |
shiftRed := aDevice shiftRed. |
|
1082 |
shiftGreen := aDevice shiftGreen. |
|
1083 |
shiftBlue := aDevice shiftBlue. |
|
1084 |
||
1085 |
"/ |
|
1086 |
"/ for now, only a few formats are supported |
|
1087 |
"/ |
|
1088 |
myDepth := self bitsPerPixel. |
|
1089 |
myDepth == usedDeviceBitsPerPixel ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1090 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1091 |
"/ first, the trivial case, where the depths match |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1092 |
"/ 24 bit/pixel |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1093 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1094 |
imageBits := bytes. |
194 | 1095 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1096 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1097 |
"/ 16 bit/pixel ... |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1098 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1099 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1100 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
194 | 1101 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1102 |
"/ now, walk over the image and compose 16bit values from the r/g/b triples |
194 | 1103 |
|
856 | 1104 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1105 |
if (__bothSmallInteger(_INST(height),_INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1106 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1107 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1108 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1109 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1110 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1111 |
int rShRed = __intVal(rightShiftR), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1112 |
rShGreen = __intVal(rightShiftG), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1113 |
rShBlue = __intVal(rightShiftB), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1114 |
lShRed = __intVal(shiftRed), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1115 |
lShGreen = __intVal(shiftGreen), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1116 |
lShBlue = __intVal(shiftBlue); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1117 |
int x, y, w; |
194 | 1118 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1119 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1120 |
unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
194 | 1121 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1122 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1123 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1124 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1125 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1126 |
unsigned v; |
194 | 1127 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1128 |
v = srcPtr[0] << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1129 |
v |= (srcPtr[1] << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1130 |
v |= (srcPtr[2] << lShBlue); |
194 | 1131 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1132 |
((short *)dstPtr)[0] = v; |
194 | 1133 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1134 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1135 |
dstPtr[1] = (v) & 0xFF; |
194 | 1136 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1137 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1138 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1139 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1140 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1141 |
} else { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1142 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1143 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1144 |
unsigned r, g, b, v; |
194 | 1145 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1146 |
r = srcPtr[0] >> rShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1147 |
g = srcPtr[1] >> rShGreen; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1148 |
b = srcPtr[2] >> rShBlue; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1149 |
v = r << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1150 |
v |= (g << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1151 |
v |= (b << lShBlue); |
194 | 1152 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1153 |
((short *)dstPtr)[0] = v; |
194 | 1154 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1155 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1156 |
dstPtr[1] = (v) & 0xFF; |
194 | 1157 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1158 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1159 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1160 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1161 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1162 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1163 |
} |
194 | 1164 |
%}. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1165 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1166 |
"/ |
856 | 1167 |
"/ 32 bits/pixel ... |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1168 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1169 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1170 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
194 | 1171 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1172 |
"/ now, walk over the image and compose 32bit values from the r/g/b triples |
194 | 1173 |
|
856 | 1174 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1175 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1176 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1177 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1178 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1179 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1180 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1181 |
int rShRed = __intVal(rightShiftR), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1182 |
rShGreen = __intVal(rightShiftG), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1183 |
rShBlue = __intVal(rightShiftB), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1184 |
lShRed = __intVal(shiftRed), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1185 |
lShGreen = __intVal(shiftGreen), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1186 |
lShBlue = __intVal(shiftBlue); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1187 |
int x, y, w; |
194 | 1188 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1189 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1190 |
unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
194 | 1191 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1192 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1193 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1194 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1195 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1196 |
unsigned v; |
194 | 1197 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1198 |
v = srcPtr[0] << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1199 |
v |= (srcPtr[1] << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1200 |
v |= (srcPtr[2] << lShBlue); |
194 | 1201 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1202 |
((int *)dstPtr)[0] = v; |
194 | 1203 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1204 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1205 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1206 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1207 |
dstPtr[3] = (v) & 0xFF; |
194 | 1208 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1209 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1210 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1211 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1212 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1213 |
} else { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1214 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1215 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1216 |
unsigned r, g, b, v; |
194 | 1217 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1218 |
r = srcPtr[0] >> rShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1219 |
g = srcPtr[1] >> rShGreen; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1220 |
b = srcPtr[2] >> rShBlue; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1221 |
v = r << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1222 |
v |= (g << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1223 |
v |= (b << lShBlue); |
194 | 1224 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1225 |
((int *)dstPtr)[0] = v; |
194 | 1226 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1227 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1228 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1229 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1230 |
dstPtr[3] = (v) & 0xFF; |
194 | 1231 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1232 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1233 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1234 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1235 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1236 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1237 |
} |
194 | 1238 |
%}. |
856 | 1239 |
] ifFalse:[ |
1240 |
"/ |
|
1241 |
"/ 8 bits/pixel ... |
|
1242 |
"/ |
|
1243 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
1244 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
1245 |
||
1246 |
"/ now, walk over the image and compose 8bit values from the r/g/b triples |
|
194 | 1247 |
|
856 | 1248 |
%{ |
1249 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
1250 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
1251 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
1252 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
1253 |
&& __isByteArray(_INST(bytes)) |
|
1254 |
&& __isByteArray(imageBits)) { |
|
1255 |
int rShRed = __intVal(rightShiftR), |
|
1256 |
rShGreen = __intVal(rightShiftG), |
|
1257 |
rShBlue = __intVal(rightShiftB), |
|
1258 |
lShRed = __intVal(shiftRed), |
|
1259 |
lShGreen = __intVal(shiftGreen), |
|
1260 |
lShBlue = __intVal(shiftBlue); |
|
1261 |
int x, y, w; |
|
194 | 1262 |
|
856 | 1263 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1264 |
unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
194 | 1265 |
|
856 | 1266 |
w = __intVal(_INST(width)); |
1267 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
1268 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
|
1269 |
for (x=w; x > 0; x--) { |
|
1270 |
unsigned v; |
|
194 | 1271 |
|
856 | 1272 |
v = srcPtr[0] << lShRed; |
1273 |
v |= (srcPtr[1] << lShGreen); |
|
1274 |
v |= (srcPtr[2] << lShBlue); |
|
1275 |
dstPtr[0] = v; |
|
194 | 1276 |
|
856 | 1277 |
dstPtr += 1; |
1278 |
srcPtr += 3; |
|
1279 |
} |
|
1280 |
} |
|
1281 |
} else { |
|
1282 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
|
1283 |
for (x=w; x > 0; x--) { |
|
1284 |
unsigned r, g, b, v; |
|
194 | 1285 |
|
856 | 1286 |
r = srcPtr[0] >> rShRed; |
1287 |
g = srcPtr[1] >> rShGreen; |
|
1288 |
b = srcPtr[2] >> rShBlue; |
|
1289 |
v = r << lShRed; |
|
1290 |
v |= (g << lShGreen); |
|
1291 |
v |= (b << lShBlue); |
|
1292 |
||
1293 |
dstPtr[0] = v; |
|
1294 |
||
1295 |
dstPtr += 1; |
|
1296 |
srcPtr += 3; |
|
1297 |
} |
|
1298 |
} |
|
1299 |
} |
|
1300 |
} |
|
1301 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1302 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1303 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1304 |
] |
194 | 1305 |
]. |
1306 |
||
1307 |
imageBits isNil ifTrue:[ |
|
856 | 1308 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
1309 |
usedDeviceBitsPerPixel errorPrintCR. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1310 |
^ self asMonochromeFormOn:aDevice |
194 | 1311 |
]. |
1312 |
||
1313 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
1314 |
form isNil ifTrue:[ |
|
1177
e89408c15bb5
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
1315 |
'Depth24Image [warning]: display bitmap creation failed' errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1316 |
^ nil |
194 | 1317 |
]. |
1318 |
form initGC. |
|
1319 |
||
1320 |
form |
|
1999
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1321 |
copyBitsFrom:imageBits |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1322 |
bitsPerPixel:usedDeviceBitsPerPixel |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1323 |
depth:usedDeviceDepth |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1324 |
padding:8 |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1325 |
width:width height:height |
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
1326 |
x:0 y:0 toX:0 y:0. |
194 | 1327 |
|
1328 |
^ form |
|
1329 |
||
1330 |
"Modified: 21.10.1995 / 19:30:11 / cg" |
|
810 | 1331 |
! ! |
1332 |
||
1333 |
!Depth24Image methodsFor:'dither helpers'! |
|
1334 |
||
1779 | 1335 |
floydSteinbergDitheredGrayBitsDepth:depth |
1336 |
"return the bits for dithering a depth gray bitmap from the image. |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1337 |
Redefined to make use of knowing that pixels are 24 bit r/g/b" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1338 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1339 |
|dstIndex "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1340 |
nextDst "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1341 |
bytesPerRow "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1342 |
bytesPerOutRow "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1343 |
outBits greyMap1 greyMap2 greyLevels |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1344 |
errorArray |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1345 |
errorArray1 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1346 |
e t v |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1347 |
w "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1348 |
h "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1349 |
bitCnt "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1350 |
byte "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1351 |
grey dT |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1352 |
eR eRB eB eLB | |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1353 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1354 |
(samplesPerPixel ~~ 3 |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1355 |
or:[bitsPerSample ~= #(8 8 8) |
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1356 |
or:[depth > 8]]) ifTrue:[ |
1779 | 1357 |
^ super floydSteinbergDitheredGrayBitsDepth:depth |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1358 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1359 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1360 |
w := width. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1361 |
h := height. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1362 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1363 |
bytesPerRow := self bytesPerRow. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1364 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1365 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1366 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1367 |
^ nil |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1368 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1369 |
|
1932 | 1370 |
depth ~~ 8 ifTrue:[ |
1371 |
greyLevels := (1 bitShift:depth) - 1. |
|
1372 |
greyMap1 := Array new:256. |
|
1373 |
greyMap2 := Array new:256. |
|
1374 |
1 to:256 do:[:i | |
|
1375 |
v := (greyLevels / 255 * (i-1)). |
|
1376 |
greyMap1 at:i put:v. |
|
1377 |
greyMap2 at:i put:v. |
|
1378 |
]. |
|
1379 |
greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray. |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1380 |
|
1932 | 1381 |
greyMap2 := (greyMap2 collect:[:el | |
1382 |
((el - el truncated) "/ the error (0..1) |
|
1383 |
* 255) rounded]) asByteArray. |
|
1384 |
||
1385 |
errorArray := ByteArray new:(w + 2) * 2. |
|
1386 |
errorArray1 := ByteArray new:(w + 2) * 2. |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1387 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1388 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1389 |
%{ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1390 |
int __byte; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1391 |
int __dT, __err, __e16, __eR, __eB, __eRB, __eLB; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1392 |
int __depth = __intVal(depth); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1393 |
int __dstIdx = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1394 |
int __srcIdx = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1395 |
int __bitCnt; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1396 |
int __grey; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1397 |
int __w = __intVal(w); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1398 |
int __h = __intVal(h); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1399 |
int __x; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1400 |
int __y; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1401 |
int __nextDst; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1402 |
int __nextSrc; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1403 |
int __bytesPerRow = __intVal(bytesPerRow); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1404 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1405 |
int __pixel; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1406 |
int __greyLevels = __intVal(greyLevels); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1407 |
|
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1408 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1409 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1410 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1411 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1412 |
short *__errorArray = (short *)(__ByteArrayInstPtr(errorArray)->ba_element); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1413 |
short *__errorArray1 = (short *)(__ByteArrayInstPtr(errorArray1)->ba_element); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1414 |
short *__t; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1415 |
|
1932 | 1416 |
if (__depth == 8) { |
1417 |
/* |
|
1418 |
* special code for destination depth 8 |
|
1419 |
*/ |
|
1420 |
for (__y=0; __y<__h; __y++) { |
|
1421 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
1422 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
1423 |
for (__x=0; __x<__w; __x++) { |
|
1424 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
1425 |
+ (__bytes[__srcIdx+1] * 6) |
|
1426 |
+ __bytes[__srcIdx+2]; |
|
1427 |
__pixel = __grey / 10; /* 0 .. 255 */ |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1428 |
|
1932 | 1429 |
__srcIdx += 3; |
1430 |
__outBits[__dstIdx] = __pixel; |
|
1431 |
__dstIdx++; |
|
1432 |
} |
|
1433 |
__srcIdx = __nextSrc; |
|
1434 |
__dstIdx = __nextDst; |
|
1435 |
} |
|
1436 |
} else { |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1437 |
bzero(errorArray1, (__w+2) * 2); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1438 |
|
1932 | 1439 |
__bitCnt = 8; |
1440 |
for (__y=0; __y<__h; __y++) { |
|
1441 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
1442 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
1443 |
||
1444 |
__byte = 0; |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1445 |
|
1932 | 1446 |
__t = __errorArray; |
1447 |
__errorArray = __errorArray1; |
|
1448 |
__errorArray1 = __t; |
|
1449 |
bzero(errorArray1, (__w+2) * 2); |
|
1450 |
||
1451 |
for (__x=0; __x<__w; __x++) { |
|
1452 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
1453 |
+ (__bytes[__srcIdx+1] * 6) |
|
1454 |
+ __bytes[__srcIdx+2]; |
|
1455 |
__grey = __grey / 10; /* 0 .. 255 */ |
|
1456 |
||
1457 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
|
1458 |
__err = __greyMap2[__grey]; /* 0.. 255 - error) */ |
|
1459 |
__err += __errorArray[__x+1]; |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1460 |
|
1932 | 1461 |
if (__err > 127) { /* dither says: next pixel */ |
1462 |
if ( __pixel != __greyLevels) |
|
1463 |
__pixel++; |
|
1464 |
__err = __err - 255; |
|
1465 |
} else { |
|
1466 |
} |
|
1467 |
if (__err) { |
|
1468 |
__e16 = __err >> 4; |
|
1469 |
__eR = __e16 * 7; /* 7/16 -> right pixel */ |
|
1470 |
__eRB = __e16 * 1; /* 1/16 -> right below */ |
|
1471 |
__eB = __e16 * 5; /* 5/16 -> below */ |
|
1472 |
__eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */ |
|
1473 |
||
1474 |
__errorArray [__x+1+1] += __eR; |
|
1475 |
__errorArray1[__x+1+1] += __eRB; |
|
1476 |
__errorArray1[__x+1 ] += __eB; |
|
1477 |
__errorArray1[__x+1-1] += __eLB; |
|
1478 |
} |
|
1479 |
||
1480 |
__srcIdx += 3; |
|
1481 |
||
1482 |
__byte = (__byte << __depth) | __pixel; |
|
1483 |
||
1484 |
__bitCnt = __bitCnt - __depth; |
|
1485 |
if (__bitCnt == 0) { |
|
1486 |
__outBits[__dstIdx] = __byte; |
|
1487 |
__dstIdx++; |
|
1488 |
__byte = 0; |
|
1489 |
__bitCnt = 8; |
|
1490 |
} |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1491 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1492 |
|
1932 | 1493 |
if (__bitCnt != 8) { |
1494 |
__byte = __byte << __bitCnt; |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1495 |
__outBits[__dstIdx] = __byte; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1496 |
__bitCnt = 8; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1497 |
} |
1932 | 1498 |
__srcIdx = __nextSrc; |
1499 |
__dstIdx = __nextDst; |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1500 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1501 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1502 |
%}. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1503 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1504 |
^ outBits |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1505 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1506 |
"Created: 10.6.1996 / 13:28:22 / cg" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1507 |
"Modified: 10.6.1996 / 15:09:07 / cg" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1508 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1509 |
! |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1510 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1511 |
floydSteinbergDitheredMonochromeBits |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1512 |
"return the bitmap for a dithered monochrome bitmap from the image. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1513 |
Redefined to make use of knowing that pixels are 24 bit r/g/b" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1514 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1515 |
|
1779 | 1516 |
^ self floydSteinbergDitheredGrayBitsDepth:1 |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1517 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1518 |
"Created: 10.6.1996 / 22:55:59 / cg" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1519 |
! |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1520 |
|
1782 | 1521 |
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
810 | 1522 |
"return the bitmap for a dithered depth-bitmap from the image; |
1523 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1524 |
Redefined to make use of knowing that pixels are 24-bit values." |
|
1525 |
||
1526 |
|f dH nDither v range |
|
1527 |
greyMap1 greyMap2 greyLevels outBits |
|
1528 |
bytesPerOutRow "{Class: SmallInteger }" |
|
1529 |
bytesPerRow "{Class: SmallInteger }" |
|
1530 |
w "{Class: SmallInteger }" |
|
1531 |
h "{Class: SmallInteger }"| |
|
1532 |
||
1533 |
photometric ~~ #rgb ifTrue:[ |
|
1534 |
self error:'invalid format'. |
|
1535 |
^ nil |
|
1536 |
]. |
|
1537 |
||
1538 |
nDither := ditherMatrix size. |
|
1539 |
dH := nDither / dW. |
|
1540 |
||
1541 |
w := width. |
|
1542 |
h := height. |
|
1543 |
||
1544 |
greyLevels := 1 bitShift:depth. |
|
1545 |
bytesPerRow := self bytesPerRow. |
|
1546 |
||
1547 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
1548 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
1549 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
|
1550 |
^ nil |
|
1551 |
]. |
|
1552 |
||
1553 |
greyMap1 := Array new:256. |
|
1554 |
greyMap2 := Array new:256. |
|
1555 |
range := greyLevels-1. |
|
1556 |
1 to:256 do:[:i | |
|
1557 |
v := (range / 255 * (i-1)). |
|
1558 |
greyMap1 at:i put:v. |
|
1559 |
greyMap2 at:i put:v. |
|
1560 |
]. |
|
1561 |
||
1562 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
1563 |
0 |
|
1564 |
] ifFalse:[ |
|
1565 |
b truncated |
|
1566 |
] |
|
1567 |
]) asByteArray. |
|
1568 |
||
1569 |
greyMap2 := (greyMap2 collect:[:el | |
|
1570 |
el isNil ifTrue:[ |
|
1571 |
0 |
|
1572 |
] ifFalse:[ |
|
1573 |
((el - el truncated) "/ the error (0..1) |
|
1574 |
* nDither) rounded |
|
1575 |
]]) asByteArray. |
|
1576 |
%{ |
|
1577 |
int __dW = __intVal(dW); |
|
1578 |
int __dH = __intVal(dH); |
|
1579 |
int __byte; |
|
1580 |
int __nDither = __intVal(nDither); |
|
1581 |
int __dT, __dO; |
|
1582 |
int __depth = __intVal(depth); |
|
1583 |
int __dstIdx = 0; |
|
1584 |
int __srcIdx = 0; |
|
1585 |
int __bitCnt; |
|
1586 |
int __grey; |
|
1587 |
int __w = __intVal(w); |
|
1588 |
int __h = __intVal(h); |
|
1589 |
int __x; |
|
1590 |
int __y; |
|
1591 |
int __oX, __oY, __dY; |
|
1592 |
int __nextDst; |
|
1593 |
int __nextSrc; |
|
1594 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1595 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
1596 |
int __pixel; |
|
1597 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1598 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
810 | 1599 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
1600 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1601 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
|
1602 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
1603 |
||
1604 |
__oY = __dY = 0; |
|
1605 |
for (__y=0; __y<__h; __y++) { |
|
1606 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
1607 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
1608 |
||
1609 |
__byte = 0; |
|
1610 |
__bitCnt = 8; |
|
1611 |
||
1612 |
__oX = 0; |
|
1613 |
||
1614 |
for (__x=0; __x<__w; __x++) { |
|
1615 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
1616 |
+ (__bytes[__srcIdx+1] * 6) |
|
1617 |
+ __bytes[__srcIdx+2]; |
|
1618 |
__grey = __grey / 10; /* 0 .. 255 */ |
|
1619 |
||
1620 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
|
1621 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
|
1622 |
__dT = __ditherMatrix[__dY + __oX]; |
|
1623 |
||
1624 |
if (__dO > __dT) /* dither says: next pixel */ |
|
1625 |
__pixel++; |
|
1626 |
||
1627 |
__srcIdx += 3; |
|
1628 |
||
1629 |
__oX++; |
|
1630 |
if (__oX == __dW) __oX = 0; |
|
1631 |
||
1632 |
__byte = (__byte << __depth) | __pixel; |
|
1633 |
||
1634 |
__bitCnt = __bitCnt - __depth; |
|
1635 |
if (__bitCnt == 0) { |
|
1636 |
__outBits[__dstIdx] = __byte; |
|
1637 |
__dstIdx++; |
|
1638 |
__byte = 0; |
|
1639 |
__bitCnt = 8; |
|
1640 |
} |
|
1641 |
} |
|
1642 |
||
1643 |
if (__bitCnt != 8) { |
|
1644 |
__byte = __byte << __bitCnt; |
|
1645 |
__outBits[__dstIdx] = __byte; |
|
1646 |
} |
|
1647 |
||
1648 |
__oY++; __dY += __dW; |
|
1649 |
if (__oY == __dH) { |
|
1650 |
__oY = 0; |
|
1651 |
__dY = 0; |
|
1652 |
} |
|
1653 |
||
1654 |
__srcIdx = __nextSrc; |
|
1655 |
__dstIdx = __nextDst; |
|
1656 |
} |
|
1657 |
%}. |
|
1658 |
||
1659 |
^ outBits |
|
1660 |
||
1661 |
" |
|
1662 |
|i| |
|
1663 |
||
1664 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1665 |
i asOrderedDitheredMonochromeImage inspect. |
|
1666 |
i asOrderedDitheredDepth2GrayImage inspect. |
|
1667 |
i asOrderedDitheredDepth4GrayImage inspect. |
|
1668 |
i asOrderedDitheredDepth8GrayImage inspect. |
|
1669 |
" |
|
1670 |
||
1671 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
1672 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
808 | 1673 |
! |
1674 |
||
810 | 1675 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
1676 |
"return the dithered monochrome bits for the receiver image; |
|
1677 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1678 |
Redefined to make use of knowing that pixels are 24-bit values." |
|
1679 |
||
1680 |
|f dH nDither |
|
1681 |
greyMap monoBits |
|
1682 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
1683 |
bytesPerRow "{Class: SmallInteger }" |
|
1684 |
w "{Class: SmallInteger }" |
|
1685 |
h "{Class: SmallInteger }"| |
|
1686 |
||
1687 |
photometric ~~ #rgb ifTrue:[ |
|
1688 |
self error:'invalid format'. |
|
1689 |
^ nil |
|
1690 |
]. |
|
1691 |
||
1692 |
nDither := ditherMatrix size. |
|
1693 |
dH := nDither / dW. |
|
1694 |
||
1695 |
w := width. |
|
1696 |
h := height. |
|
1697 |
||
1698 |
bytesPerRow := self bytesPerRow. |
|
1699 |
||
1700 |
bytesPerMonoRow := w + 7 // 8. |
|
1701 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
1702 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
1703 |
^ nil |
|
1704 |
]. |
|
1705 |
||
1706 |
%{ |
|
1707 |
int __dW = __intVal(dW); |
|
1708 |
int __dH = __intVal(dH); |
|
1709 |
int __byte; |
|
1710 |
int __nDither = __intVal(nDither); |
|
1711 |
int __dT; |
|
1712 |
int __dstIdx = 0; |
|
1713 |
int __srcIdx = 0; |
|
1714 |
int __bitCnt; |
|
1715 |
int __grey; |
|
1716 |
int __w = __intVal(w); |
|
1717 |
int __h = __intVal(h); |
|
1718 |
int __x; |
|
1719 |
int __y; |
|
1720 |
int __oX, __oY, __dY; |
|
1721 |
int __nextDst; |
|
1722 |
int __nextSrc; |
|
1723 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1724 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
1725 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1726 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
810 | 1727 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
1728 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1729 |
||
1730 |
__oY = __dY = 0; |
|
1731 |
for (__y=0; __y<__h; __y++) { |
|
1732 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
|
1733 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
1734 |
||
1735 |
__byte = 0; |
|
1736 |
__bitCnt = 8; |
|
1737 |
||
1738 |
__oX = 0; |
|
1739 |
||
1740 |
for (__x=0; __x<__w; __x++) { |
|
1741 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
1742 |
+ (__bytes[__srcIdx+1] * 6) |
|
1743 |
+ __bytes[__srcIdx+2]; |
|
1744 |
__grey = __grey * (__nDither+1) / 2550; /* 0 .. nDither+1 */ |
|
1745 |
__srcIdx += 3; |
|
1746 |
||
1747 |
__dT = __ditherMatrix[__dY + __oX]; |
|
1748 |
||
1749 |
__oX++; |
|
1750 |
if (__oX == __dW) __oX = 0; |
|
1751 |
||
1752 |
__byte = __byte << 1; |
|
1753 |
if (__grey > __dT) { |
|
1754 |
__byte = __byte | 1; /* white */ |
|
1755 |
} |
|
1756 |
||
1757 |
__bitCnt--; |
|
1758 |
if (__bitCnt == 0) { |
|
1759 |
__monoBits[__dstIdx] = __byte; |
|
1760 |
__dstIdx++; |
|
1761 |
__byte = 0; |
|
1762 |
__bitCnt = 8; |
|
1763 |
} |
|
1764 |
} |
|
1765 |
||
1766 |
if (__bitCnt != 8) { |
|
1767 |
__byte = __byte << __bitCnt; |
|
1768 |
__monoBits[__dstIdx] = __byte; |
|
1769 |
} |
|
1770 |
||
1771 |
__oY++; __dY += __dW; |
|
1772 |
if (__oY == __dH) { |
|
1773 |
__oY = 0; |
|
1774 |
__dY = 0; |
|
1775 |
} |
|
1776 |
||
1777 |
__srcIdx = __nextSrc; |
|
1778 |
__dstIdx = __nextDst; |
|
1779 |
} |
|
1780 |
%}. |
|
1781 |
||
1782 |
^ monoBits |
|
1783 |
||
1784 |
" |
|
1785 |
|i f| |
|
1786 |
||
1787 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1788 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
1789 |
" |
|
1790 |
||
1791 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
1792 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
1793 |
! |
|
1794 |
||
1795 |
threshold8BitGrayBits |
|
808 | 1796 |
"return the bits for an 8-bit grey image from the receiver. |
1797 |
Special code, since this is a common case." |
|
1798 |
||
1799 |
|greyBits |
|
1800 |
srcIndex "{ Class: SmallInteger }" |
|
1801 |
dstIndex "{ Class: SmallInteger }"| |
|
1802 |
||
1803 |
greyBits := ByteArray uninitializedNew:(width * height). |
|
1804 |
%{ |
|
1805 |
register unsigned char *srcPtr, *dstPtr; |
|
1806 |
register __v; |
|
1807 |
register i; |
|
1808 |
||
1809 |
if ((__Class(__INST(bytes)) == ByteArray) |
|
1810 |
&& (__Class(greyBits) == ByteArray)) { |
|
1811 |
srcPtr = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1812 |
dstPtr = __ByteArrayInstPtr(greyBits)->ba_element; |
|
1813 |
||
1814 |
i = __intVal(__INST(height)) * __intVal(__INST(width)); |
|
1815 |
||
1816 |
for (; i > 0; i--) { |
|
1817 |
__v = (srcPtr[0] * 3); /* 3*r + 6*g + b ; 0 .. 2550 */ |
|
1818 |
__v += (srcPtr[1] * 6); |
|
1819 |
__v += srcPtr[2]; |
|
1820 |
srcPtr += 3; |
|
1821 |
__v /= 10; /* 0..255 */ |
|
1822 |
*dstPtr++ = __v ; |
|
1823 |
} |
|
1824 |
} |
|
1825 |
%}. |
|
1826 |
^ greyBits |
|
1827 |
||
1 | 1828 |
! ! |
1829 |
||
282 | 1830 |
!Depth24Image methodsFor:'enumerating'! |
1 | 1831 |
|
798 | 1832 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
282 | 1833 |
"perform aBlock for each pixel from x1 to x2 in row y. |
1834 |
The block is passed the color at each pixel. |
|
1835 |
This method allows slighly faster processing of an |
|
1836 |
image than using atX:y:, since some processing can be |
|
1837 |
avoided when going from pixel to pixel. However, for |
|
1838 |
real image processing, specialized methods should be written." |
|
1 | 1839 |
|
282 | 1840 |
|srcIndex "{ Class: SmallInteger }" |
1841 |
x1 "{ Class: SmallInteger }" |
|
1842 |
x2 "{ Class: SmallInteger }" |
|
1843 |
rVal "{ Class: SmallInteger }" |
|
1844 |
gVal "{ Class: SmallInteger }" |
|
1845 |
bVal "{ Class: SmallInteger }" |
|
1846 |
lastR lastG lastB lastColor| |
|
1847 |
||
1848 |
photometric ~~ #rgb ifTrue:[ |
|
805 | 1849 |
^ super colorsAtY:y from:xLow to:xHigh do:aBlock. |
282 | 1850 |
]. |
1851 |
||
1852 |
x1 := xLow. |
|
1853 |
x2 := xHigh. |
|
1854 |
||
1855 |
srcIndex := 1 + (((width * y) + x1) * 3). |
|
1 | 1856 |
|
282 | 1857 |
x1 to:x2 do:[:x | |
798 | 1858 |
rVal := bytes at:(srcIndex). |
1859 |
gVal := bytes at:(srcIndex + 1). |
|
1860 |
bVal := bytes at:(srcIndex + 2). |
|
1861 |
srcIndex := srcIndex + 3. |
|
1862 |
||
1863 |
(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[ |
|
1350 | 1864 |
lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal * 100 / 255. |
798 | 1865 |
lastR := rVal. |
1866 |
lastG := gVal. |
|
1867 |
lastB := bVal. |
|
1868 |
]. |
|
1869 |
aBlock value:x value:lastColor |
|
282 | 1870 |
] |
798 | 1871 |
|
1872 |
"Created: 7.6.1996 / 19:12:28 / cg" |
|
805 | 1873 |
"Modified: 8.6.1996 / 10:16:51 / cg" |
282 | 1874 |
! |
1 | 1875 |
|
798 | 1876 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
282 | 1877 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
1878 |
The block is passed the pixelValue at each pixel. |
|
1879 |
This method allows slighly faster processing of an |
|
1880 |
image than using valueAtX:y:, since some processing can be |
|
1881 |
avoided when going from pixel to pixel. However, for |
|
1882 |
real image processing, specialized methods should be written. |
|
1883 |
Notice that the pixelValue is the r/g/b value packed into an integer |
|
1884 |
(r bitShift:16) bitOr:(g bitSHift:8) bitOr:b" |
|
1885 |
||
1886 |
|srcIndex "{ Class: SmallInteger }" |
|
1887 |
x1 "{ Class: SmallInteger }" |
|
1888 |
x2 "{ Class: SmallInteger }" |
|
1889 |
r "{ Class: SmallInteger }" |
|
1890 |
g "{ Class: SmallInteger }" |
|
1891 |
b "{ Class: SmallInteger }"| |
|
1892 |
||
1893 |
x1 := xLow. |
|
1894 |
x2 := xHigh. |
|
1895 |
||
1896 |
srcIndex := 1 + (((width * y) + x1) * 3). |
|
1897 |
||
1898 |
x1 to:x2 do:[:x | |
|
798 | 1899 |
r := bytes at:(srcIndex). |
1900 |
g := bytes at:(srcIndex + 1). |
|
1901 |
b := bytes at:(srcIndex + 2). |
|
1902 |
srcIndex := srcIndex + 3. |
|
1903 |
aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b) |
|
282 | 1904 |
] |
798 | 1905 |
|
1906 |
"Created: 7.6.1996 / 19:09:40 / cg" |
|
282 | 1907 |
! ! |
1908 |
||
1767 | 1909 |
!Depth24Image methodsFor:'image manipulations'! |
1910 |
||
1911 |
negative |
|
1912 |
|index newImage newBytes nBytes r g b| |
|
1913 |
||
1914 |
photometric ~~ #rgb ifTrue:[ |
|
1915 |
^ super negative. |
|
1916 |
]. |
|
1917 |
newImage := self copy. |
|
1918 |
nBytes := bytes size. |
|
1919 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
1920 |
index := 1. |
|
1921 |
[index < nBytes] whileTrue:[ |
|
1922 |
r := bytes at:index. |
|
1923 |
newBytes at:index put:(255-r). |
|
1924 |
index := index + 1. |
|
1925 |
g := bytes at:index. |
|
1926 |
newBytes at:index put:(255-g). |
|
1927 |
index := index + 1. |
|
1928 |
b := bytes at:index. |
|
1929 |
newBytes at:index put:(255-b). |
|
1930 |
index := index + 1. |
|
1931 |
]. |
|
1932 |
^ newImage |
|
1933 |
||
1934 |
"Modified: 23.6.1997 / 09:57:19 / cg" |
|
1935 |
! ! |
|
1936 |
||
282 | 1937 |
!Depth24Image methodsFor:'magnification'! |
1 | 1938 |
|
1738 | 1939 |
hardAntiAliasedMagnifiedBy:scalePoint |
1940 |
"return a new image magnified by scalePoint, aPoint. |
|
1941 |
This interpolates pixels and is therefore slower." |
|
1942 |
||
1943 |
|mX |
|
1944 |
mY |
|
1945 |
newWidth "{ Class: SmallInteger }" |
|
1946 |
newHeight "{ Class: SmallInteger }" |
|
1947 |
w "{ Class: SmallInteger }" |
|
1948 |
h "{ Class: SmallInteger }" |
|
1949 |
newImage newBits bitsPerPixel newBytesPerRow newMask |
|
1950 |
value |
|
1951 |
srcRow pixelArray| |
|
1952 |
||
1953 |
mX := scalePoint x. |
|
1954 |
mY := scalePoint y. |
|
1955 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
1956 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
1957 |
||
1958 |
newWidth := (width * mX) truncated. |
|
1959 |
newHeight := (height * mY) truncated. |
|
1960 |
||
1961 |
bitsPerPixel := self depth. |
|
1962 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
1963 |
newBits := ByteArray new: "uninitializedNew:" (newBytesPerRow * newHeight). |
|
1932 | 1964 |
newBits isNil ifTrue:[^ nil]. |
1738 | 1965 |
|
1966 |
mask notNil ifTrue:[ |
|
1967 |
newMask := (mask magnifiedBy:scalePoint) |
|
1968 |
]. |
|
1969 |
||
1970 |
newImage := self species new. |
|
1971 |
newImage |
|
1972 |
width:newWidth |
|
1973 |
height:newHeight |
|
1974 |
photometric:photometric |
|
1975 |
samplesPerPixel:samplesPerPixel |
|
1976 |
bitsPerSample:bitsPerSample |
|
1977 |
colorMap:colorMap copy |
|
1978 |
bits:newBits |
|
1979 |
mask:newMask. |
|
1980 |
||
1981 |
mY := mY asFloat. |
|
1982 |
mX := mX asFloat. |
|
1983 |
||
1984 |
%{ |
|
1985 |
REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBits)->ba_element; |
|
1986 |
unsigned char *_srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
1987 |
unsigned char *_srcRowP, *sP; |
|
1988 |
int _width3 = __intVal(_INST(width)) * 3; |
|
1989 |
int _oldW = __intVal(_INST(width)) - 1; |
|
1990 |
int _oldH = __intVal(_INST(height)) - 1; |
|
1991 |
int _w = __intVal(newWidth) - 1; |
|
1992 |
int _h = __intVal(newHeight) - 1; |
|
1993 |
int _row, _col; |
|
1994 |
double _mX = __floatVal(mX); |
|
1995 |
double _mY = __floatVal(mY); |
|
1996 |
||
1997 |
for (_row = 0; _row <= _h; _row++) { |
|
1998 |
double _srcY; |
|
1999 |
double _dY; |
|
2000 |
int _sR; |
|
2001 |
||
2002 |
_srcY = ((double)_row / _mY); |
|
2003 |
_sR = (int)_srcY; |
|
2004 |
_dY = _srcY - ((double)_sR); |
|
2005 |
_srcRowP = _srcP + (_width3 * _sR); |
|
2006 |
||
2007 |
for (_col = 0; _col <= _w; _col++) { |
|
2008 |
unsigned int rHere, gHere, bHere; |
|
2009 |
unsigned int rRight, gRight, bRight; |
|
2010 |
unsigned int rRightBelow, gRightBelow, bRightBelow; |
|
2011 |
unsigned int rBelow, gBelow, bBelow; |
|
2012 |
unsigned int _r, _g, _b; |
|
2013 |
double wHere, wRight, wRightBelow, wBelow, sumW; |
|
2014 |
double _srcX; |
|
2015 |
double _dX; |
|
2016 |
int _sC; |
|
2017 |
||
2018 |
_srcX = ((double)_col / _mX); |
|
2019 |
_sC = (int)_srcX; |
|
2020 |
_dX = _srcX - ((double)_sC); |
|
2021 |
sP = _srcRowP + (_sC * 3); |
|
2022 |
||
2023 |
rHere = sP[0]; |
|
2024 |
gHere = sP[1]; |
|
2025 |
bHere = sP[2]; |
|
2026 |
||
2027 |
if (_sC < _oldW) { |
|
2028 |
rRight = sP[3]; |
|
2029 |
gRight = sP[4]; |
|
2030 |
bRight = sP[5]; |
|
2031 |
||
2032 |
if (_sR < _oldH) { |
|
2033 |
rBelow = sP[0+_width3]; |
|
2034 |
gBelow = sP[1+_width3]; |
|
2035 |
bBelow = sP[2+_width3]; |
|
2036 |
rRightBelow = sP[3+_width3]; |
|
2037 |
gRightBelow = sP[4+_width3]; |
|
2038 |
bRightBelow = sP[5+_width3]; |
|
2039 |
} else { |
|
2040 |
rRightBelow = rHere; |
|
2041 |
gRightBelow = gHere; |
|
2042 |
bRightBelow = bHere; |
|
2043 |
rBelow = rHere; |
|
2044 |
gBelow = gHere; |
|
2045 |
bBelow = bHere; |
|
2046 |
} |
|
2047 |
} else { |
|
2048 |
rRight = rRightBelow = rHere; |
|
2049 |
gRight = gRightBelow = gHere; |
|
2050 |
bRight = bRightBelow = bHere; |
|
2051 |
if (_sR < _oldH) { |
|
2052 |
rBelow = sP[0+_width3]; |
|
2053 |
gBelow = sP[1+_width3]; |
|
2054 |
bBelow = sP[2+_width3]; |
|
2055 |
} else { |
|
2056 |
rBelow = rHere; |
|
2057 |
gBelow = gHere; |
|
2058 |
bBelow = bHere; |
|
2059 |
} |
|
2060 |
} |
|
2061 |
||
2062 |
wHere = (1.0 - _dX) * (1.0 - _dY); |
|
2063 |
wRight = _dX * (1.0 - _dY); |
|
2064 |
wBelow = _dY * (1.0 - _dX); |
|
2065 |
wRightBelow = _dX * _dY; |
|
2066 |
sumW = wHere + wRight + wBelow + wRightBelow; |
|
2067 |
||
2068 |
_r = ((rHere * wHere) + (rRight * wRight) + (rBelow * wBelow) + (rRightBelow * wRightBelow)) / sumW; |
|
2069 |
_g = ((gHere * wHere) + (gRight * wRight) + (gBelow * wBelow) + (gRightBelow * wRightBelow)) / sumW; |
|
2070 |
_b = ((bHere * wHere) + (bRight * wRight) + (bBelow * wBelow) + (bRightBelow * wRightBelow)) / sumW; |
|
2071 |
||
2072 |
_dstP[0] = _r; |
|
2073 |
_dstP[1] = _g; |
|
2074 |
_dstP[2] = _b; |
|
2075 |
||
2076 |
_dstP += 3; |
|
2077 |
} |
|
2078 |
} |
|
2079 |
%}. |
|
2080 |
||
2081 |
^ newImage |
|
2082 |
||
2083 |
" |
|
2084 |
|i| |
|
2085 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
|
2086 |
i hardAntiAliasedMagnifiedBy:2@2 |
|
2087 |
" |
|
2088 |
" |
|
2089 |
|i| |
|
2090 |
i := Depth24Image width:3 height:3 fromArray:#[ 0 0 0 0 0 0 0 0 0 |
|
2091 |
0 0 0 255 255 255 0 0 0 |
|
2092 |
0 0 0 0 0 0 0 0 0]. |
|
2093 |
i hardAntiAliasedMagnifiedBy:8@8 |
|
2094 |
" |
|
2095 |
||
2096 |
"Modified: 2.6.1997 / 12:28:18 / cg" |
|
2097 |
"Created: 2.6.1997 / 13:18:53 / cg" |
|
2098 |
! |
|
2099 |
||
1577 | 2100 |
hardMagnifiedBy:scalePoint |
2101 |
"return a new image magnified by scalePoint, aPoint. |
|
1 | 2102 |
This is the general magnification method, handling non-integral values" |
2103 |
||
2104 |
|mX mY |
|
2105 |
newWidth "{ Class: SmallInteger }" |
|
2106 |
newHeight "{ Class: SmallInteger }" |
|
2107 |
w "{ Class: SmallInteger }" |
|
2108 |
h "{ Class: SmallInteger }" |
|
2109 |
newImage newBytes |
|
2110 |
value "{ Class: SmallInteger }" |
|
2111 |
srcRowIdx "{ Class: SmallInteger }" |
|
2112 |
srcIndex "{ Class: SmallInteger }" |
|
1577 | 2113 |
dstIndex "{ Class: SmallInteger }" |
2114 |
newMask| |
|
1 | 2115 |
|
1577 | 2116 |
mX := scalePoint x. |
2117 |
mY := scalePoint y. |
|
1 | 2118 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
2119 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
2120 |
||
2121 |
newWidth := (width * mX) truncated. |
|
2122 |
newHeight := (height * mY) truncated. |
|
2123 |
newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight). |
|
2124 |
||
1577 | 2125 |
mask notNil ifTrue:[ |
2126 |
newMask := (mask magnifiedBy:scalePoint) |
|
2127 |
]. |
|
2128 |
||
1 | 2129 |
newImage := self species new. |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2130 |
newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2131 |
width:newWidth |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2132 |
height:newHeight |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2133 |
photometric:photometric |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2134 |
samplesPerPixel:samplesPerPixel |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2135 |
bitsPerSample:#(8 8 8) |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2136 |
colorMap:nil |
1577 | 2137 |
bits:newBytes |
2138 |
mask:newMask. |
|
1 | 2139 |
|
2140 |
"walk over destination image fetching pixels from source image" |
|
2141 |
||
2142 |
mY := mY asFloat. |
|
2143 |
mX := mX asFloat. |
|
2144 |
%{ |
|
2145 |
REGISTER unsigned char *_dstP = _ByteArrayInstPtr(newBytes)->ba_element; |
|
2146 |
unsigned char *_srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
2147 |
unsigned char *_srcRowP, *sP; |
|
2148 |
int _width3 = _intVal(_INST(width)) * 3; |
|
2149 |
int _w = _intVal(newWidth) - 1; |
|
2150 |
int _h = _intVal(newHeight) - 1; |
|
2151 |
int _row, _col; |
|
2152 |
double _mX = _floatVal(mX); |
|
2153 |
double _mY = _floatVal(mY); |
|
2154 |
||
2155 |
for (_row = 0; _row <= _h; _row++) { |
|
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2156 |
_srcRowP = _srcP + (_width3 * (int)((double)_row / _mY)); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2157 |
for (_col = 0; _col <= _w; _col++) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2158 |
sP = _srcRowP + (((int)((double)_col / _mX)) * 3); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2159 |
_dstP[0] = sP[0]; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2160 |
_dstP[1] = sP[1]; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2161 |
_dstP[2] = sP[2]; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2162 |
_dstP += 3; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2163 |
} |
1 | 2164 |
} |
2165 |
%} |
|
2166 |
. |
|
81 | 2167 |
" the above C-code is equivalent to: |
2168 |
||
1 | 2169 |
dstIndex := 1. |
2170 |
w := newWidth - 1. |
|
2171 |
h := newHeight - 1. |
|
2172 |
0 to:h do:[:row | |
|
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2173 |
srcRowIdx := (width * 3 * (row // mY)) + 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2174 |
0 to:w do:[:col | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2175 |
srcIndex := srcRowIdx + ((col // mX) * 3). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2176 |
value := bytes at:srcIndex. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2177 |
newBytes at:dstIndex put:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2178 |
value := bytes at:(srcIndex + 1). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2179 |
newBytes at:(dstIndex + 1) put:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2180 |
value := bytes at:(srcIndex + 2). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2181 |
newBytes at:(dstIndex + 2) put:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2182 |
dstIndex := dstIndex + 3 |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
2183 |
] |
1 | 2184 |
]. |
2185 |
" |
|
2186 |
^ newImage |
|
282 | 2187 |
! |
2188 |
||
2189 |
magnifyRowFrom:srcBytes offset:srcStart |
|
2190 |
into:dstBytes offset:dstStart factor:mX |
|
2191 |
||
2192 |
"magnify a single pixel row - can only magnify by integer factors" |
|
2193 |
||
2194 |
%{ |
|
2195 |
unsigned char *srcP, *dstP; |
|
2196 |
int _mag; |
|
2197 |
REGISTER int i; |
|
2198 |
REGISTER unsigned char byte1, byte2, byte3; |
|
2199 |
int _pixels; |
|
2200 |
OBJ w = _INST(width); |
|
2201 |
||
2202 |
if (__bothSmallInteger(srcStart, dstStart) |
|
2203 |
&& __bothSmallInteger(w, mX) |
|
2204 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
|
2205 |
_mag = _intVal(mX); |
|
2206 |
srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart); |
|
2207 |
dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart); |
|
2208 |
_pixels = _intVal(w); |
|
2209 |
||
2210 |
while (_pixels--) { |
|
2211 |
byte1 = *srcP; |
|
2212 |
byte2 = *(srcP+1); |
|
2213 |
byte3 = *(srcP+2); |
|
2214 |
srcP += 3; |
|
2215 |
for (i=_mag; i>0; i--) { |
|
2216 |
*dstP = byte1; |
|
2217 |
*(dstP+1) = byte2; |
|
2218 |
*(dstP+2) = byte3; |
|
2219 |
dstP += 3; |
|
2220 |
} |
|
2221 |
} |
|
2222 |
RETURN (self); |
|
2223 |
} |
|
2224 |
%} |
|
2225 |
. |
|
2226 |
self primitiveFailed |
|
1 | 2227 |
! ! |
282 | 2228 |
|
2229 |
!Depth24Image methodsFor:'queries'! |
|
2230 |
||
2231 |
bitsPerPixel |
|
2232 |
"return the number of bits per pixel" |
|
2233 |
||
2234 |
^ 24 |
|
2235 |
! |
|
2236 |
||
2237 |
bitsPerRow |
|
2238 |
"return the number of bits in one scanline of the image" |
|
2239 |
||
2240 |
^ width * 24 |
|
2241 |
! |
|
2242 |
||
2243 |
bitsPerSample |
|
2244 |
"return the number of bits per sample. |
|
2245 |
The return value is an array of bits-per-plane." |
|
2246 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
2247 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
282 | 2248 |
^ #(8 8 8) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
2249 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
2250 |
"Modified: 10.6.1996 / 18:02:33 / cg" |
282 | 2251 |
! |
2252 |
||
805 | 2253 |
blueBitsOf:pixel |
2254 |
^ pixel bitAnd:16rFF. |
|
2255 |
||
2256 |
"Created: 8.6.1996 / 09:56:20 / cg" |
|
2257 |
! |
|
2258 |
||
2259 |
blueComponentOf:pixel |
|
2260 |
^ (100.0 / 255.0) * (pixel bitAnd:16rFF) |
|
2261 |
||
2262 |
"Created: 8.6.1996 / 08:42:44 / cg" |
|
2263 |
"Modified: 8.6.1996 / 09:57:41 / cg" |
|
2264 |
! |
|
2265 |
||
282 | 2266 |
bytesPerRow |
2267 |
"return the number of bytes in one scanline of the image" |
|
2268 |
||
2269 |
^ width * 3 |
|
2270 |
! |
|
2271 |
||
805 | 2272 |
greenBitsOf:pixel |
2273 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
2274 |
||
2275 |
"Modified: 8.6.1996 / 08:56:28 / cg" |
|
2276 |
"Created: 8.6.1996 / 09:56:30 / cg" |
|
2277 |
! |
|
2278 |
||
2279 |
greenComponentOf:pixel |
|
2280 |
^ (100.0 / 255.0) * (pixel bitShift:-8) bitAnd:16rFF. |
|
2281 |
||
2282 |
"Created: 8.6.1996 / 08:42:37 / cg" |
|
2283 |
"Modified: 8.6.1996 / 09:57:32 / cg" |
|
2284 |
! |
|
2285 |
||
2286 |
redBitsOf:pixel |
|
2287 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
2288 |
||
2289 |
"Modified: 8.6.1996 / 08:56:31 / cg" |
|
2290 |
"Created: 8.6.1996 / 09:56:39 / cg" |
|
2291 |
! |
|
2292 |
||
2293 |
redComponentOf:pixel |
|
2294 |
^ (100.0 / 255.0) * (pixel bitShift:-16) bitAnd:16rFF. |
|
2295 |
||
2296 |
"Created: 8.6.1996 / 08:42:25 / cg" |
|
2297 |
"Modified: 8.6.1996 / 09:57:23 / cg" |
|
2298 |
! |
|
2299 |
||
282 | 2300 |
samplesPerPixel |
2301 |
"return the number of samples per pixel in the image." |
|
2302 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
2303 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
282 | 2304 |
^ 3 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
2305 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
2306 |
"Modified: 10.6.1996 / 18:03:09 / cg" |
282 | 2307 |
! ! |
2308 |
||
1167 | 2309 |
!Depth24Image class methodsFor:'documentation'! |
282 | 2310 |
|
2311 |
version |
|
1999
9ccc51eea588
always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents:
1932
diff
changeset
|
2312 |
^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.59 1998-01-20 23:28:29 cg Exp $' |
282 | 2313 |
! ! |