wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6.17k stars 1.77k forks source link

wxMemoryDC does not preserve alpha with GTK2 #15735

Open wxtrac opened 10 years ago

wxtrac commented 10 years ago

Issue migrated from trac ticket # 15735

component: wxGTK | priority: normal | keywords: wxGraphicsContext, transparency, alpha

2013-11-30 13:00:59: alexandrub created the issue


(copied from wx-users)

ACB> Here is a patch to the "drawing" sample and 2 pngs with alpha channel. ACB> Both non-visible patches should appear in the resulting bitmap. But only ACB> the first is visible, as the second is only painted over the invisible ACB> channel. ACB> As documented in the algorithm paper:
ACB> http://keithp.com/~keithp/porterduff/p253-porter.pdf the composition modes ACB> wxCOMPOSITION_OVER or wxCOMPOSITION_DEST_OVER should do just that. ACB> ACB> Am I missing something here?

It looks like this ought to work but OTOH I don't see anything obviously wrong in wxCairoContext::DrawBitmap() code neither: wxGraphicsBitmap should have the correct alpha channel and Cairo should take care of the rest. In short, this needs to be debugged to see what is really going on here. If you can try to do it, it would be great. If not, please open a Trac ticket and attach your diff and bitmaps to it so that at least a record of this bug is left.

Thanks, VZ

wxtrac commented 10 years ago

2013-11-30 13:01:15: alexandrub uploaded file demo_dest.png (0.4 KiB)

demo_dest.png

wxtrac commented 10 years ago

2013-11-30 13:01:26: alexandrub uploaded file demo_source.png (0.4 KiB)

demo_source.png

wxtrac commented 10 years ago

2013-11-30 13:02:55: alexandrub uploaded file wx_graphics_context.diff (1.1 KiB)

wxtrac commented 10 years ago

2013-11-30 21:51:50: @paulcor changed status from new to confirmed

2013-11-30 21:51:50: @paulcor changed title from [wxGTK] wxGraphicsContext does not handle alpha channel PNGs to wxMemoryDC does not preserve alpha with GTK2

2013-11-30 21:51:50: @paulcor commented

When creating a wxMemoryDC from a wxBitmap with alpha, the best we can currently do with GTK2 is to convert the alpha to a mask. Drawing on the bitmap does not affect the mask, and the mask is later converted back to alpha, wiping out any drawing in the masked area. This could in theory be fixed for GTK+ 2.8 and later by using Cairo instead of GDK (see #10066).

You can work around this by drawing directly to a window instead of a bitmap.