--- a/Image.st Thu Mar 03 10:16:44 2016 +0100
+++ b/Image.st Thu Mar 03 19:23:29 2016 +0100
@@ -179,7 +179,7 @@
instance is a frame or nil,
if its not part of a sequence.
- bitsPerPixel not used in ST/X
+ bitsPerPixel obsolete - not used in ST/X (kept for a while for subclasses)
depth - these have been added in instVar-slots
maxPixelValue - according to the ST-80's image class.
rowByteSize - to allow loading of st-80 images
@@ -246,7 +246,8 @@
photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
is partially redundant and its handling stupid (not to say: braindamaged ;-).
The only excuse is that it grew over time, had to incorporate various alien/older schemes for
- compatibility reasons. All of the above belongs into the single colorMap which must migrate from
+ compatibility reasons (mostly coming from tiff format, which was the very first supported format).
+ All of the above belongs into the single colorMap which must migrate from
a stupid seqColl to a color-aware real colorMap.
(we are in the process of doing so...)
@@ -686,6 +687,7 @@
examples_functionalImages
"
Functional images (please read 'Functional Images' by Conal Elliot, Microsoft Research).
+ These have no underyling pixelstorage, but instead compute the pixel-value via a block.
Plain x/y mapping:
[exBegin]
@@ -3512,7 +3514,7 @@
existing image may confuse later pixel interpretation."
depth := self depth.
- bitsPerPixel := d.
+ "/ bitsPerPixel := d.
d == 24 ifTrue:[
samplesPerPixel := 3.
bitsPerSample := #(8 8 8)
@@ -3523,7 +3525,8 @@
] ifFalse:[
d == 16 ifTrue:[
samplesPerPixel := 3.
- bitsPerSample := #(5 5 5)
+ bitsPerSample := #(5 5 5).
+ "/ bitsPerPixel := 15.
] ifFalse:[
samplesPerPixel := 1.
bitsPerSample := ByteArray with:d
@@ -5826,7 +5829,7 @@
self createPixelStore.
depth := self depth.
bitsPerSample := self bitsPerSample.
- bitsPerPixel := self bitsPerPixel.
+ "/ bitsPerPixel := self bitsPerPixel.
samplesPerPixel := self samplesPerPixel.
self colormapFromImage:anImage.
@@ -14261,71 +14264,71 @@
b "{ Class: SmallInteger }"
word "{ Class: SmallInteger }"
lword
- device ddepth isMSB|
+ device ddepth isMSB bpp|
depth := self depth.
- bitsPerPixel := self bitsPerPixel.
+ bpp := "bitsPerPixel :=" self bitsPerPixel.
device := aDrawable graphicsDevice.
(aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
- "/ a monochrome bitmap ?
- visType := #StaticGray.
- ddepth := 1.
+ "/ a monochrome bitmap ?
+ visType := #StaticGray.
+ ddepth := 1.
] ifFalse:[
- (aDrawable isForm) ifFalse:[
- "
- get some attributes of the display device
- "
- visType := device visualType.
- ddepth := device depth.
- ] ifTrue:[
- ddepth := aDrawable depth.
- visType := aDrawable photometric
- ].
+ (aDrawable isForm) ifFalse:[
+ "
+ get some attributes of the display device
+ "
+ visType := device visualType.
+ ddepth := device depth.
+ ] ifTrue:[
+ ddepth := aDrawable depth.
+ visType := aDrawable photometric
+ ].
].
"/ kludge for 15bit XFree server
ddepth == 15 ifTrue:[
- ddepth := 16
+ ddepth := 16
].
aDrawable isForm ifTrue:[
- photometric := aDrawable photometric.
- samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
- bitsPerSample := ddepth == 24 ifTrue:#[8 8 8 ] ifFalse:[ByteArray with:bitsPerPixel].
+ photometric := aDrawable photometric.
+ samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
+ bitsPerSample := ddepth == 24 ifTrue:#[8 8 8 ] ifFalse:[ByteArray with:bpp].
] ifFalse:[
- (visType == #StaticGray) ifTrue:[
- (device blackpixel == 0) ifTrue:[
- photometric := #blackIs0
- ] ifFalse:[
- photometric := #whiteIs0
- ].
- samplesPerPixel := 1.
- bitsPerPixel := ddepth.
- bitsPerSample := ByteArray with:bitsPerPixel.
- ] ifFalse:[
- ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
- photometric := #palette.
- samplesPerPixel := 1.
- bitsPerPixel := ddepth.
- bitsPerSample := ByteArray with:bitsPerPixel.
- ] ifFalse:[
- ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
- photometric := #rgb.
- samplesPerPixel := 3.
- "/ bitsPerPixel := depth.
+ (visType == #StaticGray) ifTrue:[
+ (device blackpixel == 0) ifTrue:[
+ photometric := #blackIs0
+ ] ifFalse:[
+ photometric := #whiteIs0
+ ].
+ samplesPerPixel := 1.
+ bpp := "bitsPerPixel :=" ddepth.
+ bitsPerSample := ByteArray with:bpp.
+ ] ifFalse:[
+ ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bpp := "bitsPerPixel :=" ddepth.
+ bitsPerSample := ByteArray with:bpp.
+ ] ifFalse:[
+ ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
+ photometric := #rgb.
+ samplesPerPixel := 3.
+ "/ bpp := "bitsPerPixel :=" depth.
"/ bitsPerSample := ByteArray with:device bitsRed
"/ with:device bitsGreen
"/ with:device bitsBlue
- bitsPerPixel := 24.
- bitsPerSample := #(8 8 8).
- ] ifFalse:[
- self error:'screen visual not supported'.
- ^ nil
- ]
- ]
- ].
+ bpp := "bitsPerPixel :=" 24.
+ bitsPerSample := #(8 8 8).
+ ] ifFalse:[
+ self error:'screen visual not supported'.
+ ^ nil
+ ]
+ ]
+ ].
].
"
@@ -14338,18 +14341,18 @@
y := aRectangle top.
"
- a kludge: we dont know in advance how much we are going to need
+ a kludge: we don't know in advance how much we are going to need
(its too late when info is present ...)
"
- spaceBitsPerPixel := bitsPerPixel.
- (bitsPerPixel > 8) ifTrue:[
- spaceBitsPerPixel := 16.
- (bitsPerPixel > 16) ifTrue:[
- spaceBitsPerPixel := 32.
- (bitsPerPixel > 32) ifTrue:[
- spaceBitsPerPixel := bitsPerPixel.
- ]
- ]
+ spaceBitsPerPixel := bpp.
+ (bpp > 8) ifTrue:[
+ spaceBitsPerPixel := 16.
+ (bpp > 16) ifTrue:[
+ spaceBitsPerPixel := 32.
+ (bpp > 32) ifTrue:[
+ spaceBitsPerPixel := bpp.
+ ]
+ ]
].
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
@@ -14360,9 +14363,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.
].
bitsPerPixelIn := info at:#bitsPerPixel.
@@ -14375,132 +14378,132 @@
"/ mhmh - thats not needed
bitsPerPixelIn < 8 ifTrue:[
- bitOrder := info at:#bitOrder.
- bitOrder ~~ #msbFirst ifTrue:[
- inData
- expandPixels:8
- width:(inData size)
- height:1
- into:inData
- mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
- ].
+ bitOrder := info at:#bitOrder.
+ bitOrder ~~ #msbFirst ifTrue:[
+ inData
+ expandPixels:8
+ width:(inData size)
+ height:1
+ into:inData
+ mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
+ ].
].
"
check, if the devices padding is different ..
or if the bitsPerPixels are different
"
- bytesPerLineIn := (info at:#bytesPerLine). "what I got"
- bytesPerLine := (w * bitsPerPixel + 7) // 8. "what I want"
+ bytesPerLineIn := (info at:#bytesPerLine). "what I got"
+ bytesPerLine := (w * bpp + 7) // 8. "what I want"
maskR := info at:#redMask ifAbsent:0.
maskG := info at:#greenMask ifAbsent:0.
maskB := info at:#blueMask ifAbsent:0.
((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 == 0 ifTrue:[
- bitsR := device bitsRed.
- bitsG := device bitsGreen.
- bitsB := device bitsBlue.
- maskR := (1 bitShift:bitsR) - 1.
- maskG := (1 bitShift:bitsG) - 1.
- maskB := (1 bitShift:bitsB) - 1.
- shR := device shiftRed negated.
- shG := device shiftGreen negated.
- shB := device shiftBlue negated.
- ] ifFalse:[
- shR := (maskR lowBit - 1) negated.
- bitsR := maskR highBit - maskR lowBit + 1.
- maskR := maskR bitShift:shR.
- shG := (maskG lowBit - 1) negated.
- bitsG := maskG highBit - maskG lowBit + 1.
- maskG := maskG bitShift:shG.
- shB := (maskB lowBit - 1) negated.
- bitsB := maskB highBit - maskB lowBit + 1.
- maskB := maskB bitShift:shB.
- ].
- shR2 := (8 - bitsR).
- shG2 := (8 - bitsG).
- shB2 := (8 - bitsB).
-
- ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
- "/ 'reformatting 32->24...' printNL.
- 1 to:h do:[:hi |
- srcIndex := srcRow.
- dstIndex := dstRow.
-
- 1 to:w do:[:wi |
- lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
- r := (lword bitShift:shR) bitAnd:maskR.
- g := (lword bitShift:shG) bitAnd:maskG.
- b := (lword 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:isMSB.
- 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.
- self shouldImplement.
- ^ 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
- ]
- ]
+ or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
+ tmpData := inData.
+ inData := ByteArray uninitializedNew:(bytesPerLine * height).
+
+ srcRow := 1.
+ dstRow := 1.
+
+ bitsPerPixelIn ~~ bpp ifTrue:[
+ "/ for now, only 32 -> 24 is supported
+
+ maskR == 0 ifTrue:[
+ bitsR := device bitsRed.
+ bitsG := device bitsGreen.
+ bitsB := device bitsBlue.
+ maskR := (1 bitShift:bitsR) - 1.
+ maskG := (1 bitShift:bitsG) - 1.
+ maskB := (1 bitShift:bitsB) - 1.
+ shR := device shiftRed negated.
+ shG := device shiftGreen negated.
+ shB := device shiftBlue negated.
+ ] ifFalse:[
+ shR := (maskR lowBit - 1) negated.
+ bitsR := maskR highBit - maskR lowBit + 1.
+ maskR := maskR bitShift:shR.
+ shG := (maskG lowBit - 1) negated.
+ bitsG := maskG highBit - maskG lowBit + 1.
+ maskG := maskG bitShift:shG.
+ shB := (maskB lowBit - 1) negated.
+ bitsB := maskB highBit - maskB lowBit + 1.
+ maskB := maskB bitShift:shB.
+ ].
+ shR2 := (8 - bitsR).
+ shG2 := (8 - bitsG).
+ shB2 := (8 - bitsB).
+
+ ((bitsPerPixelIn == 32) and:[bpp == 24]) ifTrue:[
+ "/ 'reformatting 32->24...' printNL.
+ 1 to:h do:[:hi |
+ srcIndex := srcRow.
+ dstIndex := dstRow.
+
+ 1 to:w do:[:wi |
+ lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
+ r := (lword bitShift:shR) bitAnd:maskR.
+ g := (lword bitShift:shG) bitAnd:maskG.
+ b := (lword 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:[bpp == 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:isMSB.
+ 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 , ' -> ' ,
+ bpp printString) errorPrintCR.
+ self shouldImplement.
+ ^ 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
+ ]
].
self bits:inData.
@@ -14508,24 +14511,24 @@
"/ if not #palette we are done, the pixel values are the rgb/grey values
"/
photometric == #palette ifTrue:[
- "/
- "/ 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)
- ]
- ].
- self setColorMap:map.
+ "/
+ "/ 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)
+ ]
+ ].
+ self setColorMap:map.
].
"Modified: / 9.1.1998 / 21:32:36 / stefan"