--- a/Depth8Image.st Sun Jul 02 18:18:17 1995 +0200
+++ b/Depth8Image.st Sun Jul 02 22:48:08 1995 +0200
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.23 1995-07-02 16:15:33 claus Exp $
+$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.24 1995-07-02 20:48:08 claus Exp $
'!
!Depth8Image class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.23 1995-07-02 16:15:33 claus Exp $
+$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.24 1995-07-02 20:48:08 claus Exp $
"
!
@@ -692,19 +692,13 @@
|pseudoBits f has8BitImage deviceDepth
redBytes greenBytes blueBytes
-"/ eR "{Class: SmallInteger }"
-"/ eG "{Class: SmallInteger }"
-"/ eB "{Class: SmallInteger }"
-"/ wantR "{Class: SmallInteger }"
-"/ wantG "{Class: SmallInteger }"
-"/ wantB "{Class: SmallInteger }"
w "{Class: SmallInteger }"
h "{Class: SmallInteger }"
index "{Class: SmallInteger }"
fixR "{Class: SmallInteger }"
fixG "{Class: SmallInteger }"
fixB "{Class: SmallInteger }"
- fixIds failed|
+ fixIds failed map|
aDevice ~~ Display ifTrue:[^ nil].
@@ -762,10 +756,8 @@
%{
int __x, __y;
int __eR, __eG, __eB;
- int __wantR, __wantG, __wantB;
unsigned char *srcP, *dstP;
unsigned char *redP, *greenP, *blueP;
- int pix;
unsigned char *idP;
int __fR, __fG, __fB;
int iR, iG, iB;
@@ -794,8 +786,9 @@
for (__y=_intVal(h); __y>0; __y--) {
__eR = __eG = __eB = 0;
for (__x=_intVal(w); __x>0; __x--) {
- int t;
int __want;
+ int pix;
+ int __wantR, __wantG, __wantB;
pix = *srcP++;
@@ -814,28 +807,37 @@
else if (__wantR < 0) __want = 0;
else __want = __wantR;
- iR = __want * __fR / 128;
- iR = (iR / 2) + (iR & 1);
+ iR = (__want * __fR + 128) / 255; /* red index rounded */
+#ifdef OLD
+ iR = __want * __fR / 128; /* red index * 2 */
+ iR = (iR / 2) + (iR & 1); /* red index rounded */
+#endif
idx = iR * (__fG+1);
if (__wantG > 255) __want = 255;
else if (__wantG < 0) __want = 0;
else __want = __wantG;
+ iG = (__want * __fG + 128) / 255; /* green index rounded */
+#ifdef OLD
iG = __want * __fG / 128;
iG = (iG / 2) + (iG & 1);
+#endif
idx = (idx + iG) * (__fB+1);
if (__wantB > 255) __want = 255;
else if (__wantB < 0) __want = 0;
else __want = __wantB;
+ iB = (__want * __fB + 128) / 255; /* blue index rounded */
+#ifdef OLD
iB = __want * __fB / 128;
iB = (iB / 2) + (iB & 1);
+#endif
idx = idx + iB;
/*
- * store the corresponding dither colorId
+ * store the corresponding dither colors colorId
*/
*dstP++ = idP[idx];
@@ -852,57 +854,21 @@
failed ifTrue:[
self primitiveFailed.
^ nil
-
-"/ for non-C programmers:
-"/ the above code is (roughly) equivalent to:
-"/
-"/ index := 1.
-"/ 1 to:h do:[:y |
-"/ eR := eG := eB := 0.
-"/ 1 to:w do:[:x |
-"/ |pixel "{ Class: SmallInteger }"
-"/ clr
-"/ wR "{ Class: SmallInteger }"
-"/ wG "{ Class: SmallInteger }"
-"/ wB "{ Class: SmallInteger }" |
-"/
-"/ pixel := (bytes at:index) + 1.
-"/
-"/ wantR := ((redBytes at:pixel) + eR).
-"/ wantG := ((greenBytes at:pixel) + eG).
-"/ wantB := ((blueBytes at:pixel) + eB).
-"/ wR := wantR.
-"/ wR > 200 ifTrue:[wR := 200] ifFalse:[wR < 0 ifTrue:[wR := 0]].
-"/ wG := wantG.
-"/ wG > 200 ifTrue:[wG := 200] ifFalse:[wG < 0 ifTrue:[wG := 0]].
-"/ wB := wantB.
-"/ wB > 200 ifTrue:[wB := 200] ifFalse:[wB < 0 ifTrue:[wB := 0]].
-"/
-"/ iR := wR * (fixR-1) / 128.
-"/ iR := (iR / 2) + (iR bitAnd:1).
-"/ iG := wG * (fixG-1) / 128.
-"/ iG := (iG / 2) + (iG bitAnd:1).
-"/ iB := wB * (fixB-1) / 128.
-"/ iB := (iB / 2) + (iB bitAnd:1).
-"/ idx := (iR * fixR + iG) * fixB + iB.
-"/ clr := fixColors at:idx.
-"/
-"/ eR := wantR - (clr red * 2) asInteger.
-"/ eG := wantG - (clr green * 2) asInteger.
-"/ eB := wantB - (clr blue * 2) asInteger.
-"/
-"/ pixel := clr colorId.
-"/ pseudoBits at:index put:pixel.
-"/
-"/ index := index + 1
-"/ ].
-"/ ].
].
f := Form width:width height:height depth:deviceDepth on:aDevice.
f isNil ifTrue:[^ nil].
- f colorMap:fixColors.
+ "/
+ "/ have to create a funny colorMap, where
+ "/ color at:index == color colorId:index
+ "/
+ map := Array new:256.
+ fixColors do:[:clr |
+ map at:clr colorId + 1 put:clr
+ ].
+ f colorMap:map.
f initGC.
+ f bits:pseudoBits.
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth
width:width height:height
x:0 y:0
@@ -911,9 +877,10 @@
^ f
"
- example: color reduction from Depth8 to Depth4 can be done by:
+ example:
+ color reduction from Depth8 to Depth4 (dithering) can be done by:
- |img8 reducedImg8 img4 map|
+ |img8 reducedImg8 img4 map form|
map := #(
(0 0 0)
@@ -937,7 +904,7 @@
nRed:2
nGreen:3
nBlue:2.
- img8 := Depth8Image fromForm:form.
+ img8 := Depth8Image fromForm:form. 'dithered version of original image'.
img4 := Depth4Image fromImage:img8.
"
!