[cairo] cairo_paint_with_alpha() bug in windows

Anmol Mishra amish153 at hotmail.com
Sun Nov 28 12:13:29 UTC 2021


There is a vertical banding issue when using cairo_paint_with_alpha() in windows libcairo v1.17.4. It is worse in ARGB32 than in RGBA128F. I found no issues on a Mac. If it matters, I used the vcpkg cairo build, as that seems to be the best way to access the latest cairo builds on windows.

For opacity 1.0, (which internally uses cairo_paint() - there is no issue).

For ARGB32, it is an issue in blend modes - color burn, color dodge, soft light, hue, saturation, color, luminosity. For RGBA128F, it is an issue in most blending modes.

This seems to appear with scale and shear operators.

>>> Sample Code >>>

// CAIRO_FORMAT_RGBA128F CAIRO_FORMAT_ARGB32
#define CAIRO_PIXFMT CAIRO_FORMAT_RGBA128F

  cairo_t *target_cr=NULL;
        cairo_surface_t *target;

        target = cairo_image_surface_create_for_data
            (fd.target.buf, CAIRO_PIXFMT, fd.target.w, fd.target.h, fd.target.stride);

        // TBD return some sort of out of mem error
        if (cairo_surface_status(target)!= CAIRO_STATUS_SUCCESS)
            return -1;

        target_cr = cairo_create(target);

        cairo_t *source_cr=NULL;
        cairo_surface_t *source;

        source = cairo_image_surface_create_for_data
            (fd.source.buf, CAIRO_PIXFMT, fd.source.w, fd.source.h, fd.source.stride);

        // TBD return some sort of out of mem error
        if (cairo_surface_status(source)!= CAIRO_STATUS_SUCCESS)
            return -1;

        source_cr = cairo_create(source);

        const double fx = fd.scale.x, fy = fd.scale.y;
        const double Tx = tan(fd.shear.x), Ty = tan(fd.shear.y);
        const int64_t cx = fd.center.x, cy = fd.center.y,
            dx = fd.t.x, dy = fd.t.y;

        const int64_t centerx = fd.w / 2.0f, centery = fd.h / 2.0f;

        cairo_matrix_t a, b;

        cairo_translate(target_cr, cx, cy);        cairo_rotate(target_cr, fd.rotation);
               cairo_translate(target_cr, -cx, -cy);

/******Start scale and shear*******/

        cairo_scale(target_cr, fx, fy);

// No issues with translation
        cairo_translate(target_cr, dx, dy);

        cairo_matrix_init(&a, 1, 0, Tx, 1, 0, 0);
        cairo_transform(target_cr, &a);

        cairo_matrix_init(&b, 1, Ty, 0, 1, 0, 0);
        cairo_transform(target_cr, &b);

        cairo_translate(target_cr, -centerx, -centery);

/******End scale and shear*******/

        cairo_set_operator(target_cr, cairo_op[fd.mode]);
        cairo_surface_flush(target);
        cairo_set_source_surface(target_cr, source, (int64_t)fd.origin.x, (int64_t)fd.origin.y);

        cairo_paint_with_alpha(target_cr, fd.opacity);
        cairo_surface_flush(target);

        if (source_cr)
            cairo_destroy(source_cr);
        if (source)
            cairo_surface_destroy(source);

        if (target_cr)
            cairo_destroy(target_cr);
        if (target)
            cairo_surface_destroy(target);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20211128/43e0734b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: banding.jpeg
Type: image/jpeg
Size: 54688 bytes
Desc: banding.jpeg
URL: <https://lists.cairographics.org/archives/cairo/attachments/20211128/43e0734b/attachment-0001.jpeg>


More information about the cairo mailing list