[cairo] Aliased corner with rounded rectangle

Bill Spitzak spitzak at gmail.com
Wed Aug 8 17:59:49 UTC 2018


You have to change the OpenGL compositing to over the premultiplied image.
I think glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR) is what you need.

On Wed, Aug 8, 2018 at 8:16 AM, Lorenzo <gatti88 at libero.it> wrote:

> Hi,
>
> i have a problem with the creation of a rounded rectangle with cairo.
>
> Environment info:
>
> cairo version: 1.14.8-1
>
> OS: linux
>
>
> A linux client creates a rounded rectangle with the following code:
>
>         let x = 0.0
>         let y = 0.0
>         let w = Double(size.w)
>         let h = Double(size.h)
>         let r = 20.0
>
>         logger.verbose("rounded rectangle x=\(x),y=\(y),w=\(w),h=\(h),r=
> \(r)")
>
>         cairo_move_to(context, x, y + r)
>         cairo_arc(context, x + r, y + r, r, Double.pi, -Double.pi / 2.0)
>         cairo_line_to(context, x + w - r, y)
>         cairo_arc(context, x + w - r, y + r, r, -Double.pi / 2.0, 0.0)
>         cairo_line_to(context, x + w, y + h - r)
>         cairo_arc(context, x + w - r, y + h - r, r, 0.0, Double.pi / 2.0)
>         cairo_line_to(context, x + r, y + h)
>         cairo_arc(context, x + r, y + h - r, r, Double.pi / 2.0, Double.pi)
>         cairo_close_path(context)
>
>
>         cairo_set_source_rgba(context, cl.red, cl.green, cl.blue,
> cl.alpha);
>         cairo_fill(context)
>
>
> After the surface fill  i have 2 different operations to be performed:
>
>     - write the png on the disk using "cairo_surface_write_to_png(surface,
> "testcairo.png")"
>
>     - display the png with opengl es 3.0 as a texture (done by copy the
> surface raw bytes with cairo_image_surface_get_data(surface)
>
>       in a shared memory used by the opengl server program)
>
>
> Save the image on disk is ok, the image is good.
>
> Display the image as a texture with opengl results in an ugly image:
> corners have some black pixels around them.
>
> Why this difference?
>
>
> I have done some checks:
>
> - data obtained with cairo_image_surface_get_data are the same that the
> graphics server loads from the shared memory (checked PixelxPixel) so the
> data transfer don't is the problem (checked also any signed/unsigned byte
> conversion)
>
> - loading the disk png as a texture instead of loading data from the
> shared memory results in a good image with no problems.
>
>
> My opinion is that the cairo_surface_write_to_png performs an antialiasing
> algorithm and accessing raw data bypass it taking the original image.
>
>
> Is my opinion correct? If yes, any advice to solve the problem?
>
>
> Regards,
>
> Lorenzo.
>
>
>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> https://lists.cairographics.org/mailman/listinfo/cairo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20180808/116ecdf5/attachment.html>


More information about the cairo mailing list