Color black vs. Color transparent

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

Color black vs. Color transparent

marcel.taeumel
Hi, there.

In Color class >> colorFromPixelValue:depth: we have:

...
d = 32 ifTrue: [
                "eight bits per component; 8 bits of alpha"
                r := (p bitShift: -16) bitAnd: 16rFF.
                g := (p bitShift: -8) bitAnd: 16rFF.
                b := p bitAnd: 16rFF.
                alpha := p bitShift: -24.
                alpha = 0 ifTrue: [^Color transparent].
                (r = 0 and: [g = 0 and: [b = 0]])  ifTrue: [^Color transparent].
                alpha < 255
                        ifTrue: [^ (Color r: r g: g b: b range: 255) alpha: (alpha asFloat / 255.0)]
                        ifFalse: [^ (Color r: r g: g b: b range: 255)]].
...

This denotes black to transparent. Is this still right?

I have here a form that renders right but after collecting the colors, all is transparent:

 '(Form
        extent: 16@16
        depth: 32
        fromArray: #( 1526726656 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 1526726656 2281701376 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2281701376 2281701376 0 3238002688 2281701376 2264924160 268435456 0 0 0 0 285212672 2264924160 2281701376 3238002688 0 2281701376 2281701376 0 2281701376 0 0 0 0 0 0 0 0 0 0 2281701376 0 2281701376 2281701376 0 2281701376 0 0 0 0 0 0 0 0 0 0 2281701376 0 2281701376 2281701376 0 234881024 0 0 0 0 0 0 0 0 0 0 234881024 0 2281701376 2281701376 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2281701376 2281701376 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2281701376 2281701376 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2281701376 2281701376 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2281701376 2281701376 0 234881024 0 0 0 0 0 0 0 0 0 0 234881024 0 2281701376 2281701376 0 2281701376 0 0 0 0 0 0 0 0 0 0 2281701376 0 2281701376 2281701376 0 2281701376 0 0 0 0 0 0 0 0 0 0 2281701376 0 2281701376 2281701376 0 3271557120 2281701376 2264924160 268435456 0 0 0 0 285212672 2264924160 2281701376 3271557120 0 2281701376 2281701376 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2281701376 1459617792 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 2566914048 1442840576)
        offset: 0@0)'

And after "form collectColors: [:ea | ea]" if get this:

 '(Form
        extent: 16@16
        depth: 32
        fromArray: #( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
        offset: 0@0)'

:-(

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: Color black vs. Color transparent

Bert Freudenberg
On Tue, Aug 2, 2016 at 3:56 PM, marcel.taeumel <[hidden email]> wrote:
Hi, there.

In Color class >> colorFromPixelValue:depth: we have:

...
d = 32 ifTrue: [
                "eight bits per component; 8 bits of alpha"
                r := (p bitShift: -16) bitAnd: 16rFF.
                g := (p bitShift: -8) bitAnd: 16rFF.
                b := p bitAnd: 16rFF.
                alpha := p bitShift: -24.
                alpha = 0 ifTrue: [^Color transparent].
                (r = 0 and: [g = 0 and: [b = 0]])  ifTrue: [^Color transparent].
                alpha < 255
                        ifTrue: [^ (Color r: r g: g b: b range: 255) alpha: (alpha asFloat /
255.0)]
                        ifFalse: [^ (Color r: r g: g b: b range: 255)]].
...

This denotes black to transparent. Is this still right?

It was never "right" but a hack ... Some code treats the pixel value 0 to mean "transparent". In particular (IIRC) 16 bit forms which do not store an alpha value, and 32 bit forms that don't have a proper alpha channel. So they use 0,0,0 to mean "transparent" and "0,0,1" for solid black.

I don't think there's a good reason for this anymore, since we do have enough memory and computation power to do alpha properly. But since it will break some code I'd suggest starting to fix it only after this release.

- Bert -