[cairo] Premultiplied transparency causes streaks in images
paril at alteredsoftworks.com
Fri Nov 12 01:46:07 PST 2010
Here, I just threw this together very very quickly in C#; it CLEARLY shows
the output "streaking" black transparent pixels down the purple brush
stroke, when the expected output should show a complete purple circle with
the same color on the inside of the capsule-like shape.
It should be rather easy to convert to C/C++. I used no .NET-specific
classes; DevIL for the image loading and Cairo for the drawing, just as I
use in the actual program.
The reason I suspect premultiplication is because the only time these
streaks can be created is when the background transparency is turned from
white to black - which is done by multiplying the color values by their
alpha. If all of the images' alpha and color values remain, when they are
blended they should not create any streaks at all.
On Fri, Nov 12, 2010 at 4:40 AM, Andrea Canciani <ranma42 at gmail.com> wrote:
> On Fri, Nov 12, 2010 at 10:17 AM, Paril <paril at alteredsoftworks.com>
> > 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:
> > What I did with this output was tested this out in GIMP to see what
> > this "brush" had; this output produced the same streaking in GIMP as it
> > 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
> > white transparency is turning into black.
> > I don't have the time at the moment to put together a test app, all I
> > 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
> > in order:
> > 1) Brush is selected from list; an empty Cairo ImageSurface is made to
> > 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
> > 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.
> From your description, it is not clear to me if the problem you are seeing
> here is related with [non]premultiplication problems, but once you manage
> to fix the save-to-png routine, you should be able to check that the brush
> you have in step 5 is correct.
> > I can wrap up my current C# work and put it online if that will work - I
> > don't know if you can look at that at all, otherwise I'll put together a
> > application for it.
> Your description has been quite detailed, so I hope we can help you fix
> the problem without much additional work.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo