ImageForm color with alpha

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

ImageForm color with alpha

Stéphane Rollandin
Hello all,

Why is it that

        (Morph new color: (Color blue alpha: 0.5))

and

        (Morph new color: (Color blue alpha: 0.5)) imageForm asMorph

do not have the same color?


Stef

Reply | Threaded
Open this post in threaded view
|

Re: ImageForm color with alpha

Bert Freudenberg
On Mon, Dec 10, 2018 at 3:36 AM Stéphane Rollandin <[hidden email]> wrote:
Hello all,

Why is it that

        (Morph new color: (Color blue alpha: 0.5))

and

        (Morph new color: (Color blue alpha: 0.5)) imageForm asMorph

do not have the same color?

Because ImageMorph is using "Form blend" rule instead of "Form blendAlphaScaled".

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: ImageForm color with alpha

Stéphane Rollandin
>

>     Why is it that
>
>              (Morph new color: (Color blue alpha: 0.5))
>
>     and
>
>              (Morph new color: (Color blue alpha: 0.5)) imageForm asMorph
>
>     do not have the same color?
>
>
> Because ImageMorph is using "Form blend" rule instead of "Form
> blendAlphaScaled".

Where does this happen? Using SketchMorph instead of ImageMorph shows
the same behavior.

The only way I found so far to fix the issue is to subclass FormCanvas
as FormCanvas2, with the single method #setFillColor: where I changed
the #blend send to #blendAlpha, and then to redefine
#imageForm:forRectangle: in Rectangle as

imageForm: depth forRectangle: rect
        | canvas |
        canvas := FormCanvas2 extent: rect extent depth: depth.
        canvas translateBy: rect topLeft negated
                during:[:tempCanvas| tempCanvas fullDrawMorph: self].
        ^ canvas form offset: rect topLeft

(see attached code)

Is there another way to have a Form exactly faithful to the displayed
morph? And shouldn't that be the defaut behavior of #imageForm (in other
words, isn't the current behavior a bug)?

Best,

Stef



Morph-imageFormforRectangle.st (558 bytes) Download Attachment
FormCanvas2.st (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ImageForm color with alpha

marcel.taeumel
Hi, there.

Hmm... according to Canvas >> #translucentImage:at:sourceRect: and FormCanvas >> #setFillColor: (via FormCanvas >> #frameAndFillRectangle:...) both use "Form blend".

It should produce the same result.

Maybe the Form (via #imageForm) itself is created differently. See Morph >> #imageForm:forRectangle: and FormCanvas >> #transformBy:clippingTo:during:smoothing:.

There are only two senders of #blendAlphaScaled. 

Best,
Marcel

Am 11.12.2018 09:00:36 schrieb Stéphane Rollandin <[hidden email]>:

>

> Why is it that
>
>         (Morph new color: (Color blue alpha: 0.5))
>
> and
>
>         (Morph new color: (Color blue alpha: 0.5)) imageForm asMorph
>
> do not have the same color?
>
>
> Because ImageMorph is using "Form blend" rule instead of "Form
> blendAlphaScaled".


Where does this happen? Using SketchMorph instead of ImageMorph shows
the same behavior.

The only way I found so far to fix the issue is to subclass FormCanvas
as FormCanvas2, with the single method #setFillColor: where I changed
the #blend send to #blendAlpha, and then to redefine
#imageForm:forRectangle: in Rectangle as

imageForm: depth forRectangle: rect
| canvas |
canvas := FormCanvas2 extent: rect extent depth: depth.
canvas translateBy: rect topLeft negated
during:[:tempCanvas| tempCanvas fullDrawMorph: self].
^ canvas form offset: rect topLeft

(see attached code)

Is there another way to have a Form exactly faithful to the displayed
morph? And shouldn't that be the defaut behavior of #imageForm (in other
words, isn't the current behavior a bug)?

Best,

Stef



Reply | Threaded
Open this post in threaded view
|

Re: ImageForm color with alpha

Stéphane Rollandin
> Hmm... according to Canvas >> #translucentImage:at:sourceRect: and
> FormCanvas >> #setFillColor: (via FormCanvas >>
> #frameAndFillRectangle:...) both use "Form blend".
>
> It should produce the same result.
>
> Maybe the Form (via #imageForm) itself is created differently. See Morph
>  >> #imageForm:forRectangle: and FormCanvas >>
> #transformBy:clippingTo:during:smoothing:.
>
> There are only two senders of #blendAlphaScaled.

Ah! It seems that simply using #blendAlphaScaled in
#translucentImage:at:sourceRect: does the trick...

Stef

Reply | Threaded
Open this post in threaded view
|

Re: ImageForm color with alpha

Stéphane Rollandin
> Ah! It seems that simply using #blendAlphaScaled in
> #translucentImage:at:sourceRect: does the trick...

Unfortunately this has side effects. For example, #dimmed is now broken...

Stef

Reply | Threaded
Open this post in threaded view
|

Re: ImageForm color with alpha

marcel.taeumel
Hmm... that's not good for an arbitrary form with alpha informationen. Why not use #blend the entire time here? Isn't #blendAlpha and #blendAlphaScaled kind of a performance trick?

blend
"Answer the integer denoting BitBlt's alpha blend combination rule."
^24

blendAlpha
"Answer the integer denoting BitBlt's blend-with-constant-alpha rule."
^ 30

blendAlphaScaled
"Answer the integer denoting BitBlt's blend-with-alpha-scaled rule."
^ 34

Best,
Marcel

Am 11.12.2018 11:52:14 schrieb Stéphane Rollandin <[hidden email]>:

> Ah! It seems that simply using #blendAlphaScaled in
> #translucentImage:at:sourceRect: does the trick...

Unfortunately this has side effects. For example, #dimmed is now broken...

Stef