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