Depth24Image.st
changeset 694 f6c8fc8419bd
parent 611 e0442439a3c6
child 746 f5479d603f64
--- a/Depth24Image.st	Sat May 18 11:40:40 1996 +0200
+++ b/Depth24Image.st	Sat May 18 15:55:32 1996 +0200
@@ -725,7 +725,7 @@
      pixel0bytes pixel1bytes ditherPattern
      ditherColors first delta|
 
-    Transcript showCr:'dithering ..'. Transcript endEntry.
+    Transcript showCR:'dithering ..'. Transcript endEntry.
 
     h := height.
     w := width.
@@ -736,17 +736,17 @@
     first := (100 / nDither / 2).
     delta := 100 / nDither.
     0 to:nDither-1 do:[:i |
-	ditherColors at:i+1 put:(Color grey:(i * delta + first)).
+        ditherColors at:i+1 put:(Color grey:(i * delta + first)).
     ].
 
     nColors := 256.
     map := Array new:256.
     1 to:256 do:[:i |
-	v := i - 1.
-	" v is now in the range 0 .. 255 "
-	v := (v * (nDither - 1) // 255) rounded.
-	" v is now 0 .. nDither-1 "
-	map at:i put:(ditherColors at:(v + 1))
+        v := i - 1.
+        " v is now in the range 0 .. 255 "
+        v := (v * (nDither - 1) // 255) rounded.
+        " v is now 0 .. nDither-1 "
+        map at:i put:(ditherColors at:(v + 1))
     ].
 
     "tuning - code below is so slooow"
@@ -758,190 +758,190 @@
 
     depth := aDevice depth.
     depth == 1 ifTrue:[
-	formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h.
-	patterns := Array new:nColors.
-	pixel0bytes := ByteArray uninitializedNew:nColors.
-	pixel1bytes := ByteArray uninitializedNew:nColors.
+        formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h.
+        patterns := Array new:nColors.
+        pixel0bytes := ByteArray uninitializedNew:nColors.
+        pixel1bytes := ByteArray uninitializedNew:nColors.
 
-	"extract dither patterns and values to use for 1/0 bits
-	 in those from the dithercolors"
+        "extract dither patterns and values to use for 1/0 bits
+         in those from the dithercolors"
 
-	1 to:nColors do:[:i |
-	    clr := (map at:i) on:aDevice.
-	    ditherPattern := clr ditherForm.
+        1 to:nColors do:[:i |
+            clr := (map at:i) on:aDevice.
+            ditherPattern := clr ditherForm.
 
-	    ditherPattern isNil ifTrue:[
-		patterns at:i put:#[2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111].
-		pixel0bytes at:i put:clr colorId.
-		pixel1bytes at:i put:clr colorId
-	    ] ifFalse:[
-		patterns at:i put:(ditherPattern bits).
-		pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
-		pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
-	    ].
-	].
+            ditherPattern isNil ifTrue:[
+                patterns at:i put:#[2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111].
+                pixel0bytes at:i put:clr colorId.
+                pixel1bytes at:i put:clr colorId
+            ] ifFalse:[
+                patterns at:i put:(ditherPattern bits).
+                pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
+                pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
+            ].
+        ].
 
-	srcIndex := 1.
-	dstIndex := 1.
-	mask := 16r80.
-	outBits := 0.
-	patternOffset := 1.
-	1 to:h do:[:dstY |
-	    last := nil.
-	    1 to:w do:[:dstX |
-		r := bytes at:srcIndex.
-		g := bytes at:(srcIndex + 1).
-		b := bytes at:(srcIndex + 2).
-		srcIndex := srcIndex + 3.
+        srcIndex := 1.
+        dstIndex := 1.
+        mask := 16r80.
+        outBits := 0.
+        patternOffset := 1.
+        1 to:h do:[:dstY |
+            last := nil.
+            1 to:w do:[:dstX |
+                r := bytes at:srcIndex.
+                g := bytes at:(srcIndex + 1).
+                b := bytes at:(srcIndex + 2).
+                srcIndex := srcIndex + 3.
 
-		v := ((3 * r) + (6 * g) + (1 * b)).                "pixel grey value (*10)"
-		v == last ifFalse:[
-		    index := v // 10 + 1.                          "index into map"
+                v := ((3 * r) + (6 * g) + (1 * b)).                "pixel grey value (*10)"
+                v == last ifFalse:[
+                    index := v // 10 + 1.                          "index into map"
 
-		    patternBytes := patterns at:index.             "dither pattern for color"
-		    patternBits := patternBytes at:patternOffset.  "dither row"
-		    p0 := pixel0bytes at:index.                         "value for 0-dither bit"
-		    p1 := pixel1bytes at:index.                         "value for 1-dither bit"
-		    last := v.
-		].
-		outBits := outBits bitShift:1.
+                    patternBytes := patterns at:index.             "dither pattern for color"
+                    patternBits := patternBytes at:patternOffset.  "dither row"
+                    p0 := pixel0bytes at:index.                         "value for 0-dither bit"
+                    p1 := pixel1bytes at:index.                         "value for 1-dither bit"
+                    last := v.
+                ].
+                outBits := outBits bitShift:1.
 
-		(patternBits bitAnd:mask) == 0 ifTrue:[
-		    outBits := outBits bitOr:p0.
-		] ifFalse:[
-		    outBits := outBits bitOr:p1
-		].
-		mask := mask bitShift:-1.
-		mask == 0 ifTrue:[
-		    mask := 16r80.
-		    formBytes at:dstIndex put:outBits.
-		    dstIndex := dstIndex + 1.
-		    outBits := 0
-		]
-	    ].
-	    mask == 16r80 ifFalse:[
-		[mask == 0] whileFalse:[
-		    mask := mask bitShift:-1.
-		    outBits := outBits bitShift:1.
-		].
-		formBytes at:dstIndex put:outBits.
-		dstIndex := dstIndex + 1.
-		mask := 16r80.
-		outBits := 0
-	    ].
-	    patternOffset := patternOffset + 1.
-	    patternOffset == 9 ifTrue:[
-		patternOffset := 1
-	    ]
-	].
-	f := Form width:w height:h fromArray:formBytes.
-	^ f
+                (patternBits bitAnd:mask) == 0 ifTrue:[
+                    outBits := outBits bitOr:p0.
+                ] ifFalse:[
+                    outBits := outBits bitOr:p1
+                ].
+                mask := mask bitShift:-1.
+                mask == 0 ifTrue:[
+                    mask := 16r80.
+                    formBytes at:dstIndex put:outBits.
+                    dstIndex := dstIndex + 1.
+                    outBits := 0
+                ]
+            ].
+            mask == 16r80 ifFalse:[
+                [mask == 0] whileFalse:[
+                    mask := mask bitShift:-1.
+                    outBits := outBits bitShift:1.
+                ].
+                formBytes at:dstIndex put:outBits.
+                dstIndex := dstIndex + 1.
+                mask := 16r80.
+                outBits := 0
+            ].
+            patternOffset := patternOffset + 1.
+            patternOffset == 9 ifTrue:[
+                patternOffset := 1
+            ]
+        ].
+        f := Form width:w height:h fromArray:formBytes.
+        ^ f
     ].
 
     depth == 2 ifTrue:[
-	formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h.
-	patterns := Array new:nColors.
-	pixel0bytes := ByteArray uninitializedNew:nColors.
-	pixel1bytes := ByteArray uninitializedNew:nColors.
+        formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h.
+        patterns := Array new:nColors.
+        pixel0bytes := ByteArray uninitializedNew:nColors.
+        pixel1bytes := ByteArray uninitializedNew:nColors.
 
-	"extract dither patterns and values to use for 1/0 bits
-	 in those from the dithercolors"
+        "extract dither patterns and values to use for 1/0 bits
+         in those from the dithercolors"
 
-	1 to:nColors do:[:i |
-	    clr := (map at:i) on:aDevice.
-	    ditherPattern := clr ditherForm.
+        1 to:nColors do:[:i |
+            clr := (map at:i) on:aDevice.
+            ditherPattern := clr ditherForm.
 
-	    ditherPattern isNil ifTrue:[
-		patterns at:i put:#[2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111
-				    2r11111111].
-		pixel0bytes at:i put:clr colorId.
-		pixel1bytes at:i put:clr colorId
-	    ] ifFalse:[
-		patterns at:i put:(ditherPattern bits).
-		pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
-		pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
-	    ].
-	].
+            ditherPattern isNil ifTrue:[
+                patterns at:i put:#[2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111
+                                    2r11111111].
+                pixel0bytes at:i put:clr colorId.
+                pixel1bytes at:i put:clr colorId
+            ] ifFalse:[
+                patterns at:i put:(ditherPattern bits).
+                pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
+                pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
+            ].
+        ].
 
-	srcIndex := 1.
-	dstIndex := 1.
-	mask := 16r80.
-	outBits := 0.
-	patternOffset := 1.
-	1 to:h do:[:dstY |
-	    last := nil.
-	    outCount := 0.
-	    mask := 16r80.
-	    outBits := 0.
-	    1 to:w do:[:dstX |
-		r := bytes at:srcIndex.
-		srcIndex := srcIndex + 1.
-		g := bytes at:srcIndex.
-		srcIndex := srcIndex + 1.
-		b := bytes at:srcIndex.
-		srcIndex := srcIndex + 1.
+        srcIndex := 1.
+        dstIndex := 1.
+        mask := 16r80.
+        outBits := 0.
+        patternOffset := 1.
+        1 to:h do:[:dstY |
+            last := nil.
+            outCount := 0.
+            mask := 16r80.
+            outBits := 0.
+            1 to:w do:[:dstX |
+                r := bytes at:srcIndex.
+                srcIndex := srcIndex + 1.
+                g := bytes at:srcIndex.
+                srcIndex := srcIndex + 1.
+                b := bytes at:srcIndex.
+                srcIndex := srcIndex + 1.
 
-		v := ((3 * r) + (6 * g) + (1 * b)).                "pixel grey value (*10)"
-		v == last ifFalse:[
-		    index := v // 10 + 1.                          "index into map"
+                v := ((3 * r) + (6 * g) + (1 * b)).                "pixel grey value (*10)"
+                v == last ifFalse:[
+                    index := v // 10 + 1.                          "index into map"
 
-		    patternBytes := patterns at:index.             "dither pattern for color"
-		    patternBits := patternBytes at:patternOffset.  "dither row"
-		    p0 := pixel0bytes at:index.                    "value for 0-dither bit"
-		    p1 := pixel1bytes at:index.                    "value for 1-dither bit"
-		    last := v.
-		].
-		outBits := outBits bitShift:2.
+                    patternBytes := patterns at:index.             "dither pattern for color"
+                    patternBits := patternBytes at:patternOffset.  "dither row"
+                    p0 := pixel0bytes at:index.                    "value for 0-dither bit"
+                    p1 := pixel1bytes at:index.                    "value for 1-dither bit"
+                    last := v.
+                ].
+                outBits := outBits bitShift:2.
 
-		(patternBits bitAnd:mask) == 0 ifTrue:[
-		    outBits := outBits bitOr:p0.
-		] ifFalse:[
-		    outBits := outBits bitOr:p1
-		].
-		mask := mask bitShift:-1.
-		outCount := outCount + 1.
-		outCount == 4 ifTrue:[
-		    formBytes at:dstIndex put:outBits.
-		    dstIndex := dstIndex + 1.
-		    outBits := 0.
-		    outCount := 0.
-		    mask == 0 ifTrue:[
-			mask := 16r80.
-		    ]
-		]
-	    ].
-	    (outCount == 0) ifFalse:[
-		[outCount == 4] whileFalse:[
-		    outCount := outCount + 1.
-		    outBits := outBits bitShift:2.
-		].
-		formBytes at:dstIndex put:outBits.
-		dstIndex := dstIndex + 1.
-	    ].
-	    patternOffset := patternOffset + 1.
-	    patternOffset == 9 ifTrue:[
-		patternOffset := 1
-	    ]
-	].
-	f := Form width:w height:h depth:depth.
-	f initGC.
-	f device drawBits:formBytes depth:2
-		    width:w height:h x:0 y:0
-		     into:f id x:0 y:0 width:w height:h with:f gcId.
-	^ f
+                (patternBits bitAnd:mask) == 0 ifTrue:[
+                    outBits := outBits bitOr:p0.
+                ] ifFalse:[
+                    outBits := outBits bitOr:p1
+                ].
+                mask := mask bitShift:-1.
+                outCount := outCount + 1.
+                outCount == 4 ifTrue:[
+                    formBytes at:dstIndex put:outBits.
+                    dstIndex := dstIndex + 1.
+                    outBits := 0.
+                    outCount := 0.
+                    mask == 0 ifTrue:[
+                        mask := 16r80.
+                    ]
+                ]
+            ].
+            (outCount == 0) ifFalse:[
+                [outCount == 4] whileFalse:[
+                    outCount := outCount + 1.
+                    outBits := outBits bitShift:2.
+                ].
+                formBytes at:dstIndex put:outBits.
+                dstIndex := dstIndex + 1.
+            ].
+            patternOffset := patternOffset + 1.
+            patternOffset == 9 ifTrue:[
+                patternOffset := 1
+            ]
+        ].
+        f := Form width:w height:h depth:depth.
+        f initGC.
+        f device drawBits:formBytes depth:2
+                    width:w height:h x:0 y:0
+                     into:f id x:0 y:0 width:w height:h with:f gcId.
+        ^ f
     ].
 
     "draw each pixel using dither color (let others do the dithering)
@@ -954,34 +954,36 @@
 
     srcIndex := 1.
     0 to:h-1 do:[:dstY |
-	run := 0.
-	last := nil.
-	0 to:w-1 do:[:dstX |
-	    r := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    g := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    b := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
+        run := 0.
+        last := nil.
+        0 to:w-1 do:[:dstX |
+            r := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            g := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            b := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
 
-	    v := ((3 * r) + (6 * g) + (1 * b)) // 10.
+            v := ((3 * r) + (6 * g) + (1 * b)) // 10.
 
-	    clr := map at:(v + 1).
+            clr := map at:(v + 1).
 
-	    clr == last ifTrue:[
-		run := run + 1
-	    ] ifFalse:[
-		(run ~~ 0) ifTrue:[
-		    f fillRectangleX:dstX-run y:dstY width:run height:1.
-		].
-		run := 1.
-		f paint:clr.
-		last := clr
-	    ].
-	].
-	f fillRectangleX:width-run y:dstY width:run height:1.
+            clr == last ifTrue:[
+                run := run + 1
+            ] ifFalse:[
+                (run ~~ 0) ifTrue:[
+                    f fillRectangleX:dstX-run y:dstY width:run height:1.
+                ].
+                run := 1.
+                f paint:clr.
+                last := clr
+            ].
+        ].
+        f fillRectangleX:width-run y:dstY width:run height:1.
     ].
     ^ f
+
+    "Modified: 18.5.1996 / 15:41:58 / cg"
 !
 
 rgbImageAsPseudoFormOn:aDevice
@@ -1742,5 +1744,5 @@
 !Depth24Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.23 1996-04-25 16:22:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.24 1996-05-18 13:54:37 cg Exp $'
 ! !