[cairo] cairo_image_surface_create(), limited width

Stanisław Jeśmanowicz stan at jesmanowicz.com
Sun Aug 2 11:25:14 UTC 2020


Hello all,,

I am using  x11-libs/cairo library on Unix/Linux platforms for a long time.
Back in 2005 I have found out one limitation, that caused me a problem
to generate running text (ticker) form rss feeds.
Basically the ticker generates a 'long thin image', where width can be
quite big and height relatively small.
I had to modify function _cairo_image_surface_is_size_valid() in file
src/cairo-image-surface.c

I have forgot to send this observation then, but better late then never ...

The original function, as in cairo-1.17.3:

/* Limit on the width / height of an image surface in pixels.  This is
 * mainly determined by coordinates of things sent to pixman at the
 * moment being in 16.16 format. */
#define MAX_IMAGE_SIZE 32767
...
static cairo_bool_t
_cairo_image_surface_is_size_valid (int width, int height)
{
    return 0 <= width  &&  width <= MAX_IMAGE_SIZE &&
       0 <= height && height <= MAX_IMAGE_SIZE;
}

Modified function:

static cairo_bool_t
_cairo_image_surface_is_size_valid (int width, pixman_format_code_t
pixman_format)
{
    uint64_t stride = (uint64_t) (width * PIXMAN_FORMAT_BPP(pixman_format));
    return (stride > INT32_MAX) ? 0 : 1;
}
And my 'long images' ware working  OK then.

Some questions regarding the original implementation:

- What is 16.16  pixman format?
  As I see in the pixman 0.40.0 implementation:
   CAIRO_FORMAT_ARGB32 is PIXMAN_a8r8g8b8 (this is what I mostly use)
   and one of the 16 pixman format is PIXMAN_r5g6b5

- Where from came the MAX_IMAGE_SIZE 32767?
  It is maximum of 16-bit integer - 1, hex 0x7FFF

- Do we really need this conservative  check
(_cairo_image_surface_is_size_valid()) ?
  Because pixman checks this also and much more precisely in function
create_bits_image_internal()
  (pixman/pixman-bits-image.c, line 1335):
 
 return_val_if_fail (
    bits == NULL || (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
 
Please consider to change it like in the attached patch file,
or remove the check completely.

Best regards,
Stanislaw Jesmanowicz

-- 
__________________________________________________________

Stanislaw Jesmanowicz      stan <at> jesmanowicz <dot> com
Amsterdam                  voice : + 31 20 6126193
The Netherlands            mobile: + 31  653380520 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-image-surface.patch
Type: text/x-patch
Size: 2402 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20200802/6612a9c3/attachment.bin>


More information about the cairo mailing list