Image.st
changeset 1644 e06e1c7869fc
parent 1642 c14ef12246aa
child 1646 48ab44c4664f
--- a/Image.st	Wed Apr 23 11:21:26 1997 +0200
+++ b/Image.st	Wed Apr 23 14:17:10 1997 +0200
@@ -9767,7 +9767,8 @@
      srcRow   "{ Class: SmallInteger }"
      dstRow   "{ Class: SmallInteger }"
      inData tmpData usedPixels mapSize 
-     map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel
+     map bitsPerPixel bytesPerLine 
+     byteOrder bitOrder spaceBitsPerPixel
      info bitsPerPixelIn bytesPerLineIn 
      maskR "{ Class: SmallInteger }"
      maskG "{ Class: SmallInteger }"
@@ -9786,52 +9787,52 @@
     device := aDrawable graphicsDevice.
 
     (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
-	"/ a monochrome bitmap ?
-	visType := #StaticGray.
-	depth := 1.
+        "/ a monochrome bitmap ?
+        visType := #StaticGray.
+        depth := 1.
     ] ifFalse:[
-	"
-	 get some attributes of the display device
-	"
-	visType := device visualType.
-	depth := device depth.
+        "
+         get some attributes of the display device
+        "
+        visType := device visualType.
+        depth := device depth.
     ].
 
     "/ kludge for 15bit XFree server
     depth == 15 ifTrue:[
-	depth := 16
+        depth := 16
     ].
 
     (visType == #StaticGray) ifTrue:[
-	(device blackpixel == 0) ifTrue:[
-	    photometric := #blackIs0
-	] ifFalse:[
-	    photometric := #whiteIs0
-	].
-	samplesPerPixel := 1.
-	bitsPerPixel := depth.
-	bitsPerSample := Array with:bitsPerPixel.
+        (device blackpixel == 0) ifTrue:[
+            photometric := #blackIs0
+        ] ifFalse:[
+            photometric := #whiteIs0
+        ].
+        samplesPerPixel := 1.
+        bitsPerPixel := depth.
+        bitsPerSample := Array with:bitsPerPixel.
     ] ifFalse:[
-	((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
-	    photometric := #palette.
-	    samplesPerPixel := 1.
-	    bitsPerPixel := depth.
-	    bitsPerSample := Array with:bitsPerPixel.
-	] ifFalse:[
-	    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
-		photometric := #rgb.
-		samplesPerPixel := 3.
+        ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
+            photometric := #palette.
+            samplesPerPixel := 1.
+            bitsPerPixel := depth.
+            bitsPerSample := Array with:bitsPerPixel.
+        ] ifFalse:[
+            ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
+                photometric := #rgb.
+                samplesPerPixel := 3.
 "/                bitsPerPixel := depth.
 "/                bitsPerSample := Array with:device bitsRed
 "/                                       with:device bitsGreen
 "/                                       with:device bitsBlue
-		bitsPerPixel := 24.
-		bitsPerSample := #(8 8 8).
-	    ] ifFalse:[
-		self error:'screen visual not supported'.
-		^ nil
-	    ]
-	]
+                bitsPerPixel := 24.
+                bitsPerSample := #(8 8 8).
+            ] ifFalse:[
+                self error:'screen visual not supported'.
+                ^ nil
+            ]
+        ]
     ].
 
     "
@@ -9849,13 +9850,13 @@
     "
     spaceBitsPerPixel := bitsPerPixel.
     (bitsPerPixel > 8) ifTrue:[
-	spaceBitsPerPixel := 16.
-	(bitsPerPixel > 16) ifTrue:[
-	    spaceBitsPerPixel := 32.
-	    (bitsPerPixel > 32) ifTrue:[
-		spaceBitsPerPixel := bitsPerPixel.
-	    ]
-	]
+        spaceBitsPerPixel := 16.
+        (bitsPerPixel > 16) ifTrue:[
+            spaceBitsPerPixel := 32.
+            (bitsPerPixel > 32) ifTrue:[
+                spaceBitsPerPixel := bitsPerPixel.
+            ]
+        ]
     ].
 
     bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
@@ -9865,9 +9866,9 @@
      get the pixels
     "
     aDrawable isForm ifTrue:[
-	info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData. 
+        info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData. 
     ] ifFalse:[
-	info := device getBitsFromViewId:aDrawable id x:x y:y width:w height:h into:inData. 
+        info := device getBitsFromViewId:aDrawable id x:x y:y width:w height:h into:inData. 
     ].
 
     "
@@ -9876,15 +9877,28 @@
     byteOrder := info at:#byteOrder.
     bitsPerPixelIn := info at:#bitsPerPixel.
     byteOrder ~~ #msbFirst ifTrue:[
-	bitsPerPixelIn == 16 ifTrue:[
-	    "/ must swap bytes
-	    inData swapBytes
-	] ifFalse:[
-	    bitsPerPixelIn == 32 ifTrue:[
-		"/ must swap longs
-		inData swapLongs
-	    ]
-	]
+        bitsPerPixelIn == 16 ifTrue:[
+            "/ must swap bytes
+            inData swapBytes
+        ] ifFalse:[
+            bitsPerPixelIn == 32 ifTrue:[
+                "/ must swap longs
+                inData swapLongs
+            ]
+        ]
+    ].
+
+    "
+     check if bitorder is what I like (msbFirst)
+    "
+    bitOrder := info at:#bitOrder.
+    bitOrder ~~ #msbFirst ifTrue:[
+        inData 
+            expandPixels:8 
+            width:(inData size)
+            height:1 
+            into:inData
+            mapping:(ImageReader reverseBits).
     ].
 
     "
@@ -9896,91 +9910,91 @@
 
     ((bytesPerLine ~~ bytesPerLineIn) 
     or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
-	tmpData := inData.
-	inData := ByteArray uninitializedNew:(bytesPerLine * height).
-
-	srcRow := 1.
-	dstRow := 1.
-
-	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
-	    "/ for now, only 32 -> 24 is supported
-
-	    maskR := (1 bitShift:device bitsRed) - 1.
-	    maskG := (1 bitShift:device bitsGreen) - 1.
-	    maskB := (1 bitShift:device bitsBlue) - 1.
-	    shR := device shiftRed negated.
-	    shG := device shiftGreen negated.
-	    shB := device shiftBlue negated.
-	    shR2 := (8 - device bitsRed).
-	    shG2 := (8 - device bitsGreen).
-	    shB2 := (8 - device bitsBlue).
-
-	    ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
-		"/ 'reformatting 32->24...' printNL.
-		1 to:h do:[:hi |
-		    srcIndex := srcRow.
-		    dstIndex := dstRow.
-
-		    1 to:w do:[:wi |
-			word := tmpData doubleWordAt:srcIndex MSB:true.
-			r := (word bitShift:shR) bitAnd:maskR.
-			g := (word bitShift:shG) bitAnd:maskG.
-			b := (word bitShift:shB) bitAnd:maskB.
-
-			inData at:dstIndex   put:r.
-			inData at:dstIndex+1 put:g.
-			inData at:dstIndex+2 put:b.
-			srcIndex := srcIndex + 4.
-			dstIndex := dstIndex + 3.
-		    ].
-		    dstRow := dstRow + bytesPerLine.
-		    srcRow := srcRow + bytesPerLineIn
-		]
-	    ] ifFalse:[
-		((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
-		    "/ 'reformatting 16->24...' printNL.
-		    1 to:h do:[:hi |
-			srcIndex := srcRow.
-			dstIndex := dstRow.
-
-			1 to:w do:[:wi |
-			    word := tmpData wordAt:srcIndex MSB:true.
-			    r := (word bitShift:shR) bitAnd:maskR.
-			    g := (word bitShift:shG) bitAnd:maskG.
-			    b := (word bitShift:shB) bitAnd:maskB.
-
-			    inData at:dstIndex   put:(r bitShift:shR2).
-			    inData at:dstIndex+1 put:(g bitShift:shG2).
-			    inData at:dstIndex+2 put:(b bitShift:shB2).
-			    srcIndex := srcIndex + 2.
-			    dstIndex := dstIndex + 3.
-			].
-			dstRow := dstRow + bytesPerLine.
-			srcRow := srcRow + bytesPerLineIn
-		    ]
-		] ifFalse:[
-		    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
-							bitsPerPixel printString) errorPrintCR.
-		    ^ nil
-		]
-	    ].
-	] ifFalse:[
-	    "
-	     repad in the buffer
-	    "
-	    1 to:h do:[:hi |
-		inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
-			      with:tmpData startingAt:srcRow.
-		dstRow := dstRow + bytesPerLine.
-		srcRow := srcRow + bytesPerLineIn
-	    ]
-	]
+        tmpData := inData.
+        inData := ByteArray uninitializedNew:(bytesPerLine * height).
+
+        srcRow := 1.
+        dstRow := 1.
+
+        bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
+            "/ for now, only 32 -> 24 is supported
+
+            maskR := (1 bitShift:device bitsRed) - 1.
+            maskG := (1 bitShift:device bitsGreen) - 1.
+            maskB := (1 bitShift:device bitsBlue) - 1.
+            shR := device shiftRed negated.
+            shG := device shiftGreen negated.
+            shB := device shiftBlue negated.
+            shR2 := (8 - device bitsRed).
+            shG2 := (8 - device bitsGreen).
+            shB2 := (8 - device bitsBlue).
+
+            ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
+                "/ 'reformatting 32->24...' printNL.
+                1 to:h do:[:hi |
+                    srcIndex := srcRow.
+                    dstIndex := dstRow.
+
+                    1 to:w do:[:wi |
+                        word := tmpData doubleWordAt:srcIndex MSB:true.
+                        r := (word bitShift:shR) bitAnd:maskR.
+                        g := (word bitShift:shG) bitAnd:maskG.
+                        b := (word bitShift:shB) bitAnd:maskB.
+
+                        inData at:dstIndex   put:r.
+                        inData at:dstIndex+1 put:g.
+                        inData at:dstIndex+2 put:b.
+                        srcIndex := srcIndex + 4.
+                        dstIndex := dstIndex + 3.
+                    ].
+                    dstRow := dstRow + bytesPerLine.
+                    srcRow := srcRow + bytesPerLineIn
+                ]
+            ] ifFalse:[
+                ((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
+                    "/ 'reformatting 16->24...' printNL.
+                    1 to:h do:[:hi |
+                        srcIndex := srcRow.
+                        dstIndex := dstRow.
+
+                        1 to:w do:[:wi |
+                            word := tmpData wordAt:srcIndex MSB:true.
+                            r := (word bitShift:shR) bitAnd:maskR.
+                            g := (word bitShift:shG) bitAnd:maskG.
+                            b := (word bitShift:shB) bitAnd:maskB.
+
+                            inData at:dstIndex   put:(r bitShift:shR2).
+                            inData at:dstIndex+1 put:(g bitShift:shG2).
+                            inData at:dstIndex+2 put:(b bitShift:shB2).
+                            srcIndex := srcIndex + 2.
+                            dstIndex := dstIndex + 3.
+                        ].
+                        dstRow := dstRow + bytesPerLine.
+                        srcRow := srcRow + bytesPerLineIn
+                    ]
+                ] ifFalse:[
+                    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
+                                                        bitsPerPixel printString) errorPrintCR.
+                    ^ nil
+                ]
+            ].
+        ] ifFalse:[
+            "
+             repad in the buffer
+            "
+            1 to:h do:[:hi |
+                inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
+                              with:tmpData startingAt:srcRow.
+                dstRow := dstRow + bytesPerLine.
+                srcRow := srcRow + bytesPerLineIn
+            ]
+        ]
     ] ifFalse:[
-	(bytesPerLine * height) ~~ inData size ifTrue:[
-	    tmpData := inData.
-	    inData := ByteArray uninitializedNew:(bytesPerLine * height).
-	    inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
-	]
+        (bytesPerLine * height) ~~ inData size ifTrue:[
+            tmpData := inData.
+            inData := ByteArray uninitializedNew:(bytesPerLine * height).
+            inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
+        ]
     ].
     bytes := inData.
 
@@ -9989,31 +10003,31 @@
     ((visType == #StaticGray) 
     or:[visType == #TrueColor
     or:[visType == #DirectColor]]) ifTrue:[
-	"
-	 were done, the pixel values are the rgb/grey values
-	"
+        "
+         were done, the pixel values are the rgb/grey values
+        "
     ] ifFalse:[
-	"
-	 what we have now are the color numbers - still need the r/g/b values.
-	 find out, which colors are in the picture
-	"
-	usedPixels := inData usedValues.
-	mapSize := usedPixels max + 1.
-
-	"get the palette"
-	map := Array new:mapSize.
-	usedPixels do:[:colorIndex |
-	    |i|
-
-	    i := colorIndex + 1.
-	    device getRGBFrom:colorIndex into:[:r :g :b |
-		map at:i put:(Color red:r green:g blue:b)
-	    ]
-	].
-	colorMap := map.
-    ].
-
-    "Modified: 19.3.1997 / 13:45:01 / cg"
+        "
+         what we have now are the color numbers - still need the r/g/b values.
+         find out, which colors are in the picture
+        "
+        usedPixels := inData usedValues.
+        mapSize := usedPixels max + 1.
+
+        "get the palette"
+        map := Array new:mapSize.
+        usedPixels do:[:colorIndex |
+            |i|
+
+            i := colorIndex + 1.
+            device getRGBFrom:colorIndex into:[:r :g :b |
+                map at:i put:(Color red:r green:g blue:b)
+            ]
+        ].
+        colorMap := map.
+    ].
+
+    "Modified: 23.4.1997 / 14:16:19 / cg"
 !
 
 fromScreen:aRectangle
@@ -10181,6 +10195,6 @@
 !Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.181 1997-04-23 09:04:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.182 1997-04-23 12:17:10 cg Exp $'
 ! !
 Image initialize!