[cairo] Premultiplied transparency causes streaks in images
Andrea Canciani
ranma42 at gmail.com
Fri Nov 12 01:40:38 PST 2010
On Fri, Nov 12, 2010 at 10:17 AM, Paril <paril at alteredsoftworks.com> wrote:
> No, test.png was created by Cairo, and then pixel data (which is
> premultiplied, as I am aware of) was copied to a GDI+ Bitmap and saved. I
> did this to get an idea of what Cairo was doing internally.
As you say test.png was not created with cairo png API (see
http://cairographics.org/manual/cairo-PNG-Support.html )
If GDI+ expects nonpremultiplied data, you have to unpremultiply it when
copying to the GDI+ bitmap.
Please check if unpremultiplying the data fixes your test image (and/or
if saving test.png through cairo API makes it look correct).
PS: it looks like GDI+ should be able to handle both premultiplied
and nonpremultiplied data:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx
>
> What I did with this output was tested this out in GIMP to see what effect
> this "brush" had; this output produced the same streaking in GIMP as it did
> in my test program, which leads me to believe that Cairo is using these
> premultiplied values during painting, which it should not be doing, as the
> white transparency is turning into black.
>
> I don't have the time at the moment to put together a test app, all I have
> is my C# painting program, but all it is doing is using some of the basic
> stuff from Mono.Cairo to draw images onto the form. Here's what I am doing,
> in order:
>
> 1) Brush is selected from list; an empty Cairo ImageSurface is made to hold
> the brush image.
> 2) All of the pixels in the bitmap (acquired from DevIL) are iterated
> though.
> 3) The color values are multiplied by the color selected in the color
> picker. The alpha from color picker is discarded, and only used later on.
> 4) Since I am setting pixel data directly, I am multiplying the r, g and b
> values by the alpha value.
> 5) Data is set to the ARGB integer from said color.
> 6) Drawing, by clicking on the form, is done by getting this brush image,
> creating a SurfacePattern on the brush, setting its filter to Gaussian,
> creating a Matrix (for the Scale operation) and scaling it, setting the
> pattern's scale, creating context, translating to x/y of mouse, setting
> source to pattern, PaintWithAlpha on alpha set in the color picker.
More information about the cairo
mailing list