--- a/Image.st Thu May 31 17:52:02 2007 +0200
+++ b/Image.st Wed Jun 06 18:56:56 2007 +0200
@@ -1035,11 +1035,11 @@
cls := self.
cls == Image ifTrue:[
- cls := self implementorForDepth:1
- ].
- ^ cls new width:w height:h depth:1
-
- "Modified: / 30.9.1998 / 22:31:40 / cg"
+ cls := self implementorForDepth:1
+ ].
+ ^ cls new width:w height:h
+
+ "Modified: / 06-06-2007 / 11:10:55 / cg"
!
width:w height:h depth:d
@@ -3858,58 +3858,58 @@
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
mask notNil ifTrue:[
- mask := mask onDevice:aDevice
+ mask := mask onDevice:aDevice
].
(aDevice depth == 1
or:[aDevice hasGrayscales not]) ifTrue:[
- form := self asMonochromeFormOn:aDevice.
+ form := self asMonochromeFormOn:aDevice.
] ifFalse:[
- ((visual := aDevice visualType) == #StaticGray) ifTrue:[
- form := self asGrayFormOn:aDevice.
- ] ifFalse:[
- (visual == #PseudoColor
- or:[visual == #StaticColor]) ifTrue:[
- form := self asPseudoFormQuickOn:aDevice.
- ].
- ]
+ ((visual := aDevice visualType) == #StaticGray) ifTrue:[
+ form := self asGrayFormOn:aDevice.
+ ] ifFalse:[
+ (visual == #PseudoColor
+ or:[visual == #StaticColor]) ifTrue:[
+ form := self asPseudoFormQuickOn:aDevice.
+ ].
+ ]
].
form isNil ifTrue:[
- (photometric == #palette) ifTrue:[
- form := self paletteImageAsFormOn:aDevice
- ] ifFalse:[
- (photometric == #rgb) ifTrue:[
- form := self rgbImageAsFormOn:aDevice
- ] ifFalse:[
- (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
- form := self rgbImageAsFormOn:aDevice
- ] ifFalse:[
- form := self greyImageAsFormOn:aDevice
- ]
- ]
- ].
+ (photometric == #palette) ifTrue:[
+ form := self paletteImageAsFormOn:aDevice
+ ] ifFalse:[
+ (photometric == #rgb or:[photometric == #rgba]) ifTrue:[
+ form := self rgbImageAsFormOn:aDevice
+ ] ifFalse:[
+ (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
+ form := self rgbImageAsFormOn:aDevice
+ ] ifFalse:[
+ form := self greyImageAsFormOn:aDevice
+ ]
+ ]
+ ].
].
(device isNil or:[aDevice == device]) ifTrue:[
- "remember this form in the receiver ..."
-
- form notNil ifTrue:[
- form := form asImageForm.
- deviceForm := form.
- maskedPixelsAre0 := nil.
- device isNil ifTrue:[
- device := aDevice.
- Lobby register:self
- ] ifFalse:[
- Lobby registerChange:self
- ].
- "
- can save space, by not keeping the images data-bits
- twice (here and in the device form)
- "
- form forgetBits
- ]
+ "remember this form in the receiver ..."
+
+ form notNil ifTrue:[
+ form := form asImageForm.
+ deviceForm := form.
+ maskedPixelsAre0 := nil.
+ device isNil ifTrue:[
+ device := aDevice.
+ Lobby register:self
+ ] ifFalse:[
+ Lobby registerChange:self
+ ].
+ "
+ can save space, by not keeping the images data-bits
+ twice (here and in the device form)
+ "
+ form forgetBits
+ ]
].
^ form
@@ -3921,7 +3921,7 @@
(i asFormOn:Display) inspect.
"
- "Modified: / 22.8.1998 / 13:34:04 / cg"
+ "Modified: / 06-06-2007 / 12:18:43 / cg"
!
asGrayFormOn:aDevice
@@ -5099,52 +5099,52 @@
height := anImage height.
bitsPerSample := self bitsPerSample.
samplesPerPixel := self samplesPerPixel.
-
- self colormapFromImage:anImage photometric:photometricOrNil.
-
+ photometricOrNil == #palette ifTrue:[
+ self colormapFromImage:anImage photometric:photometricOrNil.
+ ].
self mask:anImage mask.
samePhotometric := (photometric == anImage photometric).
((self depth = anImage depth)
and:[samePhotometric]) ifTrue:[
- self bits:(anImage bits copy).
- ^ self.
+ self bits:(anImage bits copy).
+ ^ self.
].
self bits:(ByteArray uninitializedNew:(self bytesPerRow * height)).
self depth >= anImage depth ifTrue:[
- anImage depth <= 12 ifTrue:[
-
- "/ if my depth is greater, all colors can be represented,
- "/ and the loop can be done over pixel values ...
-
- (colorMap isNil or:[samePhotometric not]) ifTrue:[
- map := Array new:(1 bitShift:anImage depth).
- 1 to:map size do:[:i |
- clr := anImage colorFromValue:(i - 1).
- map at:i put:(self valueFromColor:clr).
- ].
- ].
- mappedRowPixels := self pixelArraySpecies new:width.
- h := height-1.
- w := width.
- 0 to:h do:[:row |
- anImage rowAt:row into:mappedRowPixels startingAt:1.
- map notNil ifTrue:[
- 1 to:w do:[:i |
- mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
- ].
- ].
- self rowAt:row putAll:mappedRowPixels
- ].
- ^ self
- ].
+ anImage depth <= 12 ifTrue:[
+
+ "/ if my depth is greater, all colors can be represented,
+ "/ and the loop can be done over pixel values ...
+
+ (colorMap isNil or:[samePhotometric not]) ifTrue:[
+ map := Array new:(1 bitShift:anImage depth).
+ 1 to:map size do:[:i |
+ clr := anImage colorFromValue:(i - 1).
+ map at:i put:(self valueFromColor:clr).
+ ].
+ ].
+ mappedRowPixels := self pixelArraySpecies new:width.
+ h := height-1.
+ w := width.
+ 0 to:h do:[:row |
+ anImage rowAt:row into:mappedRowPixels startingAt:1.
+ map notNil ifTrue:[
+ 1 to:w do:[:i |
+ mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
+ ].
+ ].
+ self rowAt:row putAll:mappedRowPixels
+ ].
+ ^ self
+ ].
].
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
- self colorAtX:x y:y put:clr
+ self colorAtX:x y:y put:clr
].
"
@@ -5167,9 +5167,9 @@
i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
Transcript showCR:(
- Time millisecondsToRun:[
- i24 := Depth24Image fromImage:i.
- ]
+ Time millisecondsToRun:[
+ i24 := Depth24Image fromImage:i.
+ ]
).
i24 inspect.
"
@@ -5178,11 +5178,11 @@
i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
MessageTally spyOn:[
- i24 := Depth24Image fromImage:i.
+ i24 := Depth24Image fromImage:i.
]
"
- "Modified: 23.6.1997 / 19:38:59 / cg"
+ "Modified: / 05-06-2007 / 23:56:52 / cg"
!
fromSubImage:anImage in:aRectangle
@@ -11614,69 +11614,82 @@
The implementation below is generic and slow
- this method is typically redefined in subclasses."
- |p maxPixel clr r g b c m y k|
+ |p maxPixel clr r g b c m y k a|
p := photometric.
p isNil ifTrue:[
- colorMap notNil ifTrue:[
- p := #palette
- ] ifFalse:[
+ colorMap notNil ifTrue:[
+ p := #palette
+ ] ifFalse:[
"/ 'Image [warning]: no photometric - assume greyscale' infoPrintCR
- p := #blackIs0
- ]
+ p := #blackIs0
+ ]
].
p == #blackIs0 ifTrue:[
- maxPixel := (1 bitShift:self bitsPerPixel) - 1.
- ^ Color gray:(pixelValue * (100 / maxPixel)).
+ maxPixel := (1 bitShift:self bitsPerPixel) - 1.
+ ^ Color gray:(pixelValue * (100 / maxPixel)).
].
p == #whiteIs0 ifTrue:[
- maxPixel := (1 bitShift:self bitsPerPixel) - 1.
- ^ Color gray:100 - (pixelValue * (100 / maxPixel)).
+ maxPixel := (1 bitShift:self bitsPerPixel) - 1.
+ ^ Color gray:100 - (pixelValue * (100 / maxPixel)).
].
p == #palette ifTrue:[
- pixelValue >= colorMap size ifTrue:[
- ^ Color black
- ].
- clr := colorMap at:(pixelValue + 1).
- clr isNil ifTrue:[
- ^ Color black.
- ].
- ^ clr.
+ pixelValue >= colorMap size ifTrue:[
+ ^ Color black
+ ].
+ clr := colorMap at:(pixelValue + 1).
+ clr isNil ifTrue:[
+ ^ Color black.
+ ].
+ ^ clr.
].
p == #rgb ifTrue:[
- r := self redBitsOf:pixelValue.
- g := self greenBitsOf:pixelValue.
- b := self blueBitsOf:pixelValue.
- "/ must scale to byte value...
- r := r bitShift:(8 - (bitsPerSample at:1)).
- g := g bitShift:(8 - (bitsPerSample at:2)).
- b := b bitShift:(8 - (bitsPerSample at:3)).
- ^ Color redByte:r greenByte:g blueByte:b
+ r := self redBitsOf:pixelValue.
+ g := self greenBitsOf:pixelValue.
+ b := self blueBitsOf:pixelValue.
+ "/ must scale to byte value...
+ r := r bitShift:(8 - (bitsPerSample at:1)).
+ g := g bitShift:(8 - (bitsPerSample at:2)).
+ b := b bitShift:(8 - (bitsPerSample at:3)).
+ ^ Color redByte:r greenByte:g blueByte:b
+ ].
+
+ p == #rgba ifTrue:[
+ r := self redBitsOf:pixelValue.
+ g := self greenBitsOf:pixelValue.
+ b := self blueBitsOf:pixelValue.
+ a := self alphaBitsOf:pixelValue.
+ "/ must scale to byte value...
+ r := r bitShift:(8 - (bitsPerSample at:1)).
+ g := g bitShift:(8 - (bitsPerSample at:2)).
+ b := b bitShift:(8 - (bitsPerSample at:3)).
+ a := a bitShift:(8 - (bitsPerSample at:4)).
+ ^ Color redByte:r greenByte:g blueByte:b alphaByte:a
].
p == #cmyk ifTrue:[
- c := self cyanComponentOfCMYK:pixelValue.
- m := self magentaComponentOfCMYK:pixelValue.
- y := self yellowComponentOfCMYK:pixelValue.
- k := self blackComponentOfCMYK:pixelValue.
- ^ Color cyan:c magenta:m yellow:y black:k.
+ c := self cyanComponentOfCMYK:pixelValue.
+ m := self magentaComponentOfCMYK:pixelValue.
+ y := self yellowComponentOfCMYK:pixelValue.
+ k := self blackComponentOfCMYK:pixelValue.
+ ^ Color cyan:c magenta:m yellow:y black:k.
].
p == #cmy ifTrue:[
- c := self cyanComponentOfCMY:pixelValue.
- m := self magentaComponentOfCMY:pixelValue.
- y := self yellowComponentOfCMY:pixelValue.
- ^ Color cyan:c magenta:m yellow:y.
+ c := self cyanComponentOfCMY:pixelValue.
+ m := self magentaComponentOfCMY:pixelValue.
+ y := self yellowComponentOfCMY:pixelValue.
+ ^ Color cyan:c magenta:m yellow:y.
].
self error:'invalid (unsupported) photometric'
- "Created: 8.6.1996 / 08:46:18 / cg"
- "Modified: 28.1.1997 / 12:05:22 / cg"
+ "Created: / 08-06-1996 / 08:46:18 / cg"
+ "Modified: / 06-06-2007 / 11:21:57 / cg"
!
cyanComponentOfCMY:pixel
@@ -12200,7 +12213,7 @@
"given a color, return the corresponding pixel value.
Non-representable colors return nil."
- |pixel maxPixel redBits greenBits blueBits r g b|
+ |pixel maxPixel redBits greenBits blueBits alphaBits r g b a|
photometric == #whiteIs0 ifTrue:[
maxPixel := (1 bitShift:self bitsPerPixel) - 1.
@@ -12244,10 +12257,26 @@
]
].
+ photometric == #rgba ifTrue:[
+ samplesPerPixel >= 4 ifTrue:[
+ redBits := bitsPerSample at:1.
+ greenBits := bitsPerSample at:2.
+ blueBits := bitsPerSample at:3.
+ alphaBits := bitsPerSample at:4.
+
+ "/ map r/g/b/a to 0..255
+ r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
+ g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
+ b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
+ a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
+ pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
+ ^ pixel
+ ]
+ ].
ImageErrorSignal raiseErrorString:'format not supported'.
^ nil
- "Modified: / 27-05-2007 / 14:07:26 / cg"
+ "Modified: / 06-06-2007 / 11:26:15 / cg"
!
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
@@ -12884,7 +12913,7 @@
!Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.393 2007-05-31 15:26:08 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.394 2007-06-06 16:56:56 cg Exp $'
! !
Image initialize!