[haiku-3rdparty-dev] Re: Problem Rendering semi-transparent pixels in Haiku on a child BView of a BBitmap (B_RGBA32 colorspace)

  • From: hey68 you <hey68you@xxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Mon, 15 Feb 2010 15:11:32 +0000

That fixed it !!!!

Thanks a million Stephan - You are Amazing, because you're always helpful
and polite. [?]

Now I can finally release a good-looking version of my
BeDock<http://www.bebits.com/app/4522>for Haiku.

Cheers,
hey68you

On Mon, Feb 15, 2010 at 2:25 PM, Stephan Assmus <superstippi@xxxxxx> wrote:

>
> On 2010-02-15 at 15:16:10 [+0100], hey68 you <hey68you@xxxxxxxxx> wrote:
> > Hello,
> >
> >     In Haiku, I'm seeing a problem in rendering semi-transparent pixels
> of
> > .png images drawn on a child view of a BBitmap using the B_RGBA32
> > colorspace.
> >     Fully Transparent and Fully Opaque pixels are rendered correctly,
> > whereas the semi-transparent pixels are rendered
> >     in the solid color which the Bits of the BBitmap are initialized with
> > (in the following code snippet (from yab))
> >
> >     I'm trying to debug this problem, but now I think this is a problem
> with
> > Haiku, as the same code works as expected in BeOS r5.
> >
> > I also don't think this is a problem with the .png translator since
> drawing
> > semi-transparent .png images straight onto view (not a child view of a
> > BBitmap) is working ok.
> >
> > Or perhaps this is a bug in the yab source code (snippet below) that I
> don't
> > understand?
> >
> > >From the code below, it looks like the BBitmap using the B_RGBA32
> > >colorspace
> > is initialized as fully transparent , white color.  Then when we try to
> draw
> > "myBitmap" (which in my case has some semi-transparent pixels) on to the
> > BView child of the BBitmap (using bview->SetDrawingMode(B_OP_ALPHA))
> *ONLY*
> > the fully-transparent or fully-opaque pixels are rendered correctly onto
> the
> > BBitmap (i.e. as fully-transparent are completly see-through).
> >
> > *BUT* the semi-transparent pixels are displayed in solid white ??
> >
> > Does anybody understand where the problem is (assuming that I've
> described
> > the problem correctly and clearly)?
> >
> > void YabInterface::Bitmap(double w, double h, const char* id)
> > {
> >     char *t;
> >     BBitmap *b = new BBitmap(BRect(0,0,w-1,h-1), B_RGBA32, true);
> >     BView *bview = new BView(BRect(0,0,w-1,h-1), id, B_FOLLOW_NONE, 0);
> >     b->AddChild(bview);
> >     t = (char*)b->Bits();
> >
> >     for(int i=0; i<w*h*4; i = i + 4)
> >     {
> >         t[i] = t[i+1] = t[i+2] = 255;    //    white
> >         t[i+3] = 0;                        //    Fully-transparent ??
> >     }
> >
> >     yabbitmaps->AddItem(b);
> > }
> >
> > /* Now we try to draw "myBitmap" onto the BView child of the BBitmap
> created
> > above */
> > ...
> > ...
> > BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i);
> > BView *bview = b->FindView(window);
> >     if(bview)
> >     {
> >             b->Lock();
> >             bview->SetDrawingMode(B_OP_ALPHA);
> >             bview->DrawBitmap(myBitmap, newframe);
> >
> > ...
>
> Have you setup the blending mode correctly? You need B_PIXEL_ALPHA and
> B_ALPHA_COMPOSITE. B_ALPHA_OVERLAY (the default) is for rendering to the
> screen, and assumes the destination alpha is always solid (as with frame
> buffers). For rendering into offscreen views, with real compositing, you
> need
> to use B_ALPHA_COMPOSITE as the alpha function, only that will regard the
> destination alpha at all.
>
> If this works on BeOS, it's even a bug, or at least an unnecessary
> assignment
> operation, since B_ALPHA_OVERLAY implies completely solid destination.
>
> Here is the code:
>
> ...
> BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i);
> BView *bview = b->FindView(window);
>    if(bview)
>    {
>            b->Lock();
>            bview->SetDrawingMode(B_OP_ALPHA);
> +           bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE);
>            bview->DrawBitmap(myBitmap, newframe);
>
> ...
>
> Does that fix the problem for you?
>
> Best regards,
> -Stephan
>
>

GIF image

Other related posts: