Bug 81657 - Does not draw with radial pattern if scaling is too small
Summary: Does not draw with radial pattern if scaling is too small
Status: RESOLVED MOVED
Alias: None
Product: cairo
Classification: Unclassified
Component: image backend (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Chris Wilson
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 22098
  Show dependency treegraph
 
Reported: 2014-07-23 05:45 UTC by Jason Crain
Modified: 2018-08-25 14:03 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Jason Crain 2014-07-23 05:45:18 UTC
Cairo will not fill with a radial pattern if the matrix scaling is too small.  The following code is inspired by poppler bug #22098, regarding an incorrectly rendered PDF:

	cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
	cairo_t *cr = cairo_create (surface);
	cairo_scale (cr, 0.001, 0.001);

	cairo_pattern_t *pattern = cairo_pattern_create_radial (0, 0, 0, 0, 0, 50000);
	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
	cairo_pattern_add_color_stop_rgb (pattern, 0, 0, 1, 0);
	cairo_pattern_add_color_stop_rgb (pattern, 1, 0, 0, 1);

	cairo_rectangle (cr, 0, 0, 300000, 300000);
	cairo_set_source (cr, pattern);
	cairo_fill (cr);
	cairo_surface_write_to_png (surface, "a.png");

Cairo will not draw anything with the scaling "0.001", but it will draw if the scaling is larger, such as "0.005".  The exact value seems to change depending on the pattern's matrix, so I might be able to work around the problem with cairo_pattern_set_matrix.  I've noticed the same problem with a surface pattern.

Using cairo and pixman from git master.
Comment 1 Andrea Canciani 2014-07-23 09:31:59 UTC
As you also stated, this does not seems to be radial-specific.
For that code, cairo will apply the following pixman trasform to the pattern:

matrix = {
  [0] = ([0] = 21473526, [1] = 0, [2] = 0)
  [1] = ([0] = 0, [1] = 21473526, [2] = 0)
  [2] = ([0] = 0, [1] = 0, [2] = 65536)
}

(pixman numbers are 16.16 fixed point)

Then in analyze_extents() pixman will try to check that the extents can be transformed by that matrix and still be represented with the internal 31.16 format. This unfortunately is not true (300 * 21473526 > 0x7fffffff), hence pixman bails out.

With the 0.005 scale factor, the matrix has smaller coefficients:

matrix = {
  [0] = ([0] = 4294705, [1] = 0, [2] = 23)
  [1] = ([0] = 0, [1] = 4294705, [2] = 23)
  [2] = ([0] = 0, [1] = 0, [2] = 65536)
}

In this case the extents can be represented internally by pixman (300 * 4294705 < 0x7fffffff), so the gradient is drawn.

It might be possible to improve the pixman transformation generated by cairo and/or to make pixman more forgiving about these kind of numbers.
Comment 2 GitLab Migration User 2018-08-25 14:03:09 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/333.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.