checkin from browser
authorClaus Gittinger <cg@exept.de>
Fri, 14 Jun 1996 19:51:16 +0200
changeset 858 5eb598185858
parent 857 df5125310d86
child 859 34268959162d
checkin from browser
Depth24Image.st
Image.st
--- a/Depth24Image.st	Fri Jun 14 19:04:30 1996 +0200
+++ b/Depth24Image.st	Fri Jun 14 19:51:16 1996 +0200
@@ -253,21 +253,21 @@
     fixB == 0 ifTrue:[ ^ nil].
     "/ simple check
     (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
-	self error:'invalid color array passed'.
-	^ nil
+        self error:'invalid color array passed'.
+        ^ nil
     ].
     fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
 
     deviceDepth := aDevice depth.
     deviceDepth == 8 ifTrue:[
-	has8BitImage := true.
+        has8BitImage := true.
     ] ifFalse:[
-	has8BitImage := false.
-	aDevice supportedImageFormats do:[:fmt |
-	    (fmt at:#bitsPerPixel) == 8 ifTrue:[
-		has8BitImage := true.
-	    ]
-	]
+        has8BitImage := false.
+        aDevice supportedImageFormats do:[:fmt |
+            (fmt at:#bitsPerPixel) == 8 ifTrue:[
+                has8BitImage := true.
+            ]
+        ]
     ].
     has8BitImage ifFalse:[^ nil].
 
@@ -289,81 +289,80 @@
     int __fR, __fG, __fB;
     int iR, iG, iB;
     int idx;
+    int __w = __intVal(w);
 
-    if (__isByteArray(_INST(bytes))
+    if (__isByteArray(__INST(bytes))
      && __isByteArray(pseudoBits)
      && __isByteArray(fixIds)
      && __bothSmallInteger(fixR, fixG)
      && __isSmallInteger(fixB)) {
-	failed = false;
+        failed = false;
 
-	srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
-	dstP = _ByteArrayInstPtr(pseudoBits)->ba_element;
-	idP = _ByteArrayInstPtr(fixIds)->ba_element;
-	__fR = _intVal(fixR)-1;
-	__fG = _intVal(fixG)-1;
-	__fB = _intVal(fixB)-1;
+        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+        idP = __ByteArrayInstPtr(fixIds)->ba_element;
+        __fR = __intVal(fixR)-1;
+        __fG = __intVal(fixG)-1;
+        __fB = __intVal(fixB)-1;
 
-	for (__y=_intVal(h); __y>0; __y--) {
-	    __eR = __eG = __eB = 0;
-	    for (__x=_intVal(w); __x>0; __x--) {
-		int t;
-		int __want;
+        for (__y=__intVal(h); __y>0; __y--) {
+            __eR = __eG = __eB = 0;
+            for (__x=__w; __x>0; __x--) {
+                int __want;
 
-		/*
-		 * wR, wG and wB is the wanted r/g/b value;
-		 * compute the index into the dId table ..
-		 * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
-		 *
-		 * bad kludge: knows how to index into FixColor table
-		 */
-		__wantR = srcP[0] + __eR;
-		__wantG = srcP[1] + __eG;
-		__wantB = srcP[2] + __eB;
-		srcP += 3;
+                /*
+                 * wR, wG and wB is the wanted r/g/b value;
+                 * compute the index into the dId table ..
+                 * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
+                 *
+                 * bad kludge: knows how to index into FixColor table
+                 */
+                __wantR = __want = srcP[0] + __eR;
 
-		if (__wantR > 255) __want = 255;
-		else if (__wantR < 0) __want = 0;
-		else __want = __wantR;
+                if (__want > 255) __want = 255;
+                else if (__want < 0) __want = 0;
+
+                iR = __want * __fR / 128;
+                iR = (iR / 2) + (iR & 1);
 
-		iR = __want * __fR / 128;
-		iR = (iR / 2) + (iR & 1);
-		idx = iR * (__fG+1);
+                __wantG = __want = srcP[1] + __eG;
+                if (__want > 255) __want = 255;
+                else if (__want < 0) __want = 0;
 
-		if (__wantG > 255) __want = 255;
-		else if (__wantG < 0) __want = 0;
-		else __want = __wantG;
+                iG = __want * __fG / 128;
+                iG = (iG / 2) + (iG & 1);
 
-		iG = __want * __fG / 128;
-		iG = (iG / 2) + (iG & 1);
-		idx = (idx + iG) * (__fB+1);
+                __wantB = __want = srcP[2] + __eB;
+                if (__want > 255) __want = 255;
+                else if (__want < 0) __want = 0;
 
-		if (__wantB > 255) __want = 255;
-		else if (__wantB < 0) __want = 0;
-		else __want = __wantB;
+                iB = __want * __fB / 128;
+                iB = (iB / 2) + (iB & 1);
 
-		iB = __want * __fB / 128;
-		iB = (iB / 2) + (iB & 1);
-		idx = idx + iB;
+                idx = iR * (__fG+1);
+                idx = (idx + iG) * (__fB+1);
+                idx = idx + iB;
 
-		/*
-		 * store the corresponding dither colorId
-		 */
-		*dstP++ = idP[idx];
+                /*
+                 * store the corresponding dither colorId
+                 */
+                *dstP++ = idP[idx];
 
-		/*
-		 * the new error:
-		 */
-		__eR = __wantR - (iR * 256 / __fR); 
-		__eG = __wantG - (iG * 256 / __fG); 
-		__eB = __wantB - (iB * 256 / __fB); 
-	    }
-	}
+                srcP += 3;
+
+                /*
+                 * the new error:
+                 */
+                __eR = __wantR - (iR * 256 / __fR); 
+                __eG = __wantG - (iG * 256 / __fG); 
+                __eB = __wantB - (iB * 256 / __fB); 
+            }
+        }
     }
 %}.
     failed ifTrue:[
-	self primitiveFailed.
-	^ nil
+        self primitiveFailed.
+        ^ nil
 
 "/ for non-C programmers:
 "/   the above code is (roughly) equivalent to:
@@ -418,9 +417,9 @@
     f colorMap:fixColors.
     f initGC.
     aDevice drawBits:pseudoBits bitsPerPixel:8 depth:aDevice depth
-	       width:width height:height
-		   x:0 y:0
-		into:(f id) x:0 y:0 width:width height:height with:(f gcId).
+               width:width height:height
+                   x:0 y:0
+                into:(f id) x:0 y:0 width:width height:height with:(f gcId).
     ^ f
 !
 
@@ -1708,5 +1707,5 @@
 !Depth24Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.34 1996-06-14 15:59:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.35 1996-06-14 17:51:16 cg Exp $'
 ! !
--- a/Image.st	Fri Jun 14 19:04:30 1996 +0200
+++ b/Image.st	Fri Jun 14 19:51:16 1996 +0200
@@ -3008,20 +3008,20 @@
         ^ Form width:width height:height fromArray:bytes on:aDevice
     ].
 
-    (aDevice visualType == #PseudoColor 
-    or:[aDevice visualType == #GrayScale
-    or:[aDevice visualType == #StaticColor]]) ifTrue:[
-        ^ self greyImageAsPseudoFormOn:aDevice
-    ].
-
     (aDevice visualType == #TrueColor) ifTrue:[
         ^ self greyImageAsTrueColorFormOn:aDevice
     ].
 
-    'IMAGE: cannot convert this format' errorPrintCR.
-    ^ self asMonochromeFormOn:aDevice
-
-    "Modified: 10.6.1996 / 19:18:07 / cg"
+"/    (aDevice visualType == #PseudoColor 
+"/    or:[aDevice visualType == #GrayScale
+"/    or:[aDevice visualType == #StaticColor]]) ifTrue:[
+
+    "/ PseudoColor conversion also works for StaticColor,
+    "/ GrayScale and DirectColor; although possibly with suboptimal results
+
+    ^ self greyImageAsPseudoFormOn:aDevice
+
+    "Modified: 14.6.1996 / 19:32:01 / cg"
 !
 
 greyImageAsPseudoFormOn:aDevice
@@ -3255,16 +3255,13 @@
 
         ^ self paletteImageAsTrueColorFormOn:aDevice
     ].
-    (type == #PseudoColor) ifTrue:[
-        ^ self paletteImageAsPseudoFormOn:aDevice
-    ].
-    (type == #StaticColor) ifTrue:[
-        ^ self paletteImageAsPseudoFormOn:aDevice
-    ].
-    "/ dumb fallback: every device should implement b&w images ...
-    ^ self asMonochromeFormOn:aDevice
-
-    "Modified: 14.6.1996 / 17:44:50 / cg"
+
+    "/ the PseudoColor conversion also works for
+    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
+
+    ^ self paletteImageAsPseudoFormOn:aDevice
+
+    "Modified: 14.6.1996 / 19:31:01 / cg"
 !
 
 paletteImageAsPseudoFormOn:aDevice
@@ -3567,9 +3564,13 @@
     (visual == #TrueColor) ifTrue:[
         ^ self rgbImageAsTrueColorFormOn:aDevice
     ].
+
+    "/ PseudoColor conversion also works for StaticColor, GrayScale
+    "/ and DirectColor displays; although possibly with suboptimal results
+
     ^ self rgbImageAsPseudoFormOn:aDevice
 
-    "Modified: 14.6.1996 / 17:21:08 / cg"
+    "Modified: 14.6.1996 / 19:30:06 / cg"
 !
 
 rgbImageAsPseudoFormOn:aDevice
@@ -4058,7 +4059,10 @@
 !
 
 floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
-    "return a floyd-steinberg dithered bitmap from the receiver picture. 
+    "return a floyd-steinberg dithered bitmap from the receiver picture,
+     which must be a depth-8 image. 
+     This is a special-cased dither method for 8-bit palette images being displayed on
+     an 8-bit pseudoColor display, AND fixColor dithering is used.
      Use the colors in the fixColors array, which must be fixR x fixG x fixB
      colors assigned to aDevice, such as the preallocated colors of the
      Color class. 
@@ -4066,9 +4070,8 @@
      also be used to dither an 8bit image into a smaller number of colors,
      for example to create dithered Depth4Images from Depth8Images."
 
-    |pseudoBits f has8BitImage deviceDepth
+    |pseudoBits  
      rgbBytes
-     lastClr "{Class: SmallInteger }"
      w       "{Class: SmallInteger }"
      h       "{Class: SmallInteger }"
      index   "{Class: SmallInteger }"
@@ -4078,6 +4081,8 @@
      fixIds failed map lastColor
      error clr|
 
+    self depth ~~ 8 ifTrue:[^ nil].
+
     fixR := nRed.
     fixR == 0 ifTrue:[ ^ nil].
     fixG := nGreen.
@@ -6753,6 +6758,6 @@
 !Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.96 1996-06-14 15:57:21 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.97 1996-06-14 17:50:25 cg Exp $'
 ! !
 Image initialize!