Displaying images with alpha

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Displaying images with alpha

henrik.johansen
Hi!
AFAICT, it's not possible to display images with alpha data.
Is there something I've missed, or, if not, are there any plans for supporting displaying images with alphaData?
I can sort of hack around it by creating masks based on alphaData where alpha < threshold (which is read correctly from my png sources with colorType=6) in CgDeviceIndependentImage, 
by modifying:
transparencyMask
 
"Answer the transparency mask or nil if there are no transparent pixels"
 alphaData isNil ifFalse
: [^self alphaMaskImage].
 transparentPixel isNil ifTrue
: [ ^ nil ].
 transparencyMask isNil ifFalse
: [ ^ transparencyMask ].
 
^ transparencyMask := self colorMaskImage: transparentPixel

and implementing:
alphaMaskImage
 
"Answer a new CgDeviceIndependentImage with the same width and
 height as the receiver, but depth one, with zero bits whereever
 alphaData is zero"



 
| row w answer |
 row
:= (self depth > 8 ifTrue: [ Array ] ifFalse: [ ByteArray ]) new: (w := self width).
 answer
:= CgDeviceIndependentImage
 width
: w
 height
: self height
 depth
: 1
 palette
: (CgIndexedPalette grayRamp: 2).
 
0 to: self height - 1 do: [ :y | |rowStart|
 rowStart
:= y * self width.
 
 
1 to: w do: [ :i |
"Threshold; fully transparent, alpha 0"
 row at
: i put: ((alphaData at: rowStart + i) = 0 ifTrue: [ 0 ] ifFalse: [ 1 ]) ].
 answer
 putPixels
: 0
 y
: y
 width
: self width
 pixels
: row
 startIndex
: 1].
 
^ answer

But it would be nicer if this was/is available without having to modify core classes, and using true alpha instead of a mask-approximation :)

Cheers,
Henry

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Displaying images with alpha

Seth Berman
Greetings Henry,

You are correct. There are some changes required for both the CgImage primitive code (escgi dll/so) and the Smalltalk image code.
We are interested in supporting PNG with true alpha support and this item is scheduled with that work package.

I'm not exactly sure on the timing at the moment as a lot of features are pouring into 9.2.
After 9.2 our themes will probably shift more towards UI related development which
this will more naturally fit into.

Thanks for providing this code, btw.  Looks great!

- Seth

On Wednesday, April 3, 2019 at 11:22:01 AM UTC-4, [hidden email] wrote:
Hi!
AFAICT, it's not possible to display images with alpha data.
Is there something I've missed, or, if not, are there any plans for supporting displaying images with alphaData?
I can sort of hack around it by creating masks based on alphaData where alpha < threshold (which is read correctly from my png sources with colorType=6) in CgDeviceIndependentImage, 
by modifying:
transparencyMask
 
"Answer the transparency mask or nil if there are no transparent pixels"
 alphaData isNil ifFalse
: [^self alphaMaskImage].
 transparentPixel isNil ifTrue
: [ ^ nil ].
 transparencyMask isNil ifFalse
: [ ^ transparencyMask ].
 
^ transparencyMask := self colorMaskImage: transparentPixel

and implementing:
alphaMaskImage
 
"Answer a new CgDeviceIndependentImage with the same width and
 height as the receiver, but depth one, with zero bits whereever
 alphaData is zero"



 
| row w answer |
 row
:= (self depth > 8 ifTrue: [ Array ] ifFalse: [ ByteArray ]) new: (w := self width).
 answer
:= CgDeviceIndependentImage
 width
: w
 height
: self height
 depth
: 1
 palette
: (CgIndexedPalette grayRamp: 2).
 
0 to: self height - 1 do: [ :y | |rowStart|
 rowStart
:= y * self width.
 
 
1 to: w do: [ :i |
"Threshold; fully transparent, alpha 0"
 row at
: i put: ((alphaData at: rowStart + i) = 0 ifTrue: [ 0 ] ifFalse: [ 1 ]) ].
 answer
 putPixels
: 0
 y
: y
 width
: self width
 pixels
: row
 startIndex
: 1].
 
^ answer

But it would be nicer if this was/is available without having to modify core classes, and using true alpha instead of a mask-approximation :)

Cheers,
Henry

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.