Re: Question about blend()
[email protected] Tue, 10 Dec 2024 07:31:59 -0600
| Newsgroups | gmane.comp.lib.fox-toolkit.user |
|---|---|
| Message-ID | <[email protected]> |
On 2024-12-10 02:50, Jean Truc wrote:
> Hi again,
>
> sorry, I forgot the title in my previous message and I was not clear.
>
> My question is simple : to blend an icon that has transparency I can
> do:
>
> icon->blend(background_color);
> icon->create();
>
> But if the background color changes, then:
>
> icon->blend(new_background_color);
> icon->render();
>
> doesn't changes the previous blending.
>
> What I am missing?
image->blend(clr) changes the RGB of the image as follows"
Rpix = Rclr * (1 - Apix) + Rpix * Apix
Gpix = Gclr * (1 - Apix) + Gpix * Apix
Bpix = Bclr * (1 - Apix) + Bpix * Apix
where (Rpix,Gpix,Bpix,Apix) is the Red, Green, Blue, and Alpha of the
image,
and (Rclr,Gclr,Bclr) is the pixel of the background. Thus, for opaque
pixels,
i.e. alpha==1, we keep the original pixel value; for alpha==0
(transparant),
we set the color to the background, and for partial alpha's its
somewhere
in between.
In other words, the original image is lost. To re-blend it, you would
want
to make a copy of the original pixel buffer, so you can put it back.
It is important to know that the drawing API (unlike, e.g. OpenGL) does
not do
transparency, and thus we need to simulate it in the client code.
FXImage::render() creates a non-alpha containing pixel representation at
the
X11 server, where the drawing API actually operates.
For many cases, after the X11-side buffer has been filled from the local
pixel array, we no longer need the local pixel array, and can thus
delete
it (the option IMAGE_KEEP prevents this, allowing you to make
modifications
to the pixel array and render() again).
You can get a pointer to the pixel array via:
FXColor* pixels = image->getData();
and its size:
FXint width = image->getWidth();
FXint height= image->getHeight();
Technically, I think image->blend() should perhaps modify the alpha
and set it to 1, as after the blend operation, the image should be
interpreted
as being opaque....
Hope this helps,
-- JVZ