[cairo-commit] 3 commits - src/cairo-image-surface.c src/cairoint.h src/cairo-xlib-surface.c
Carl Worth
cworth at kemper.freedesktop.org
Wed Mar 19 14:19:43 PDT 2008
src/cairo-image-surface.c | 117 +++++++++++++++++++++++-----------------------
src/cairo-xlib-surface.c | 32 +++++++++---
src/cairoint.h | 15 +++--
3 files changed, 94 insertions(+), 70 deletions(-)
New commits:
commit 7f4b967c020042779748021fa32fddfc3f0def28
Author: Carl Worth <cworth at cworth.org>
Date: Fri Mar 14 16:51:24 2008 +0100
Make CAIRO_FORMAT_STRIDE_FOR_WIDTH_BPP available to the cairo internals.
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 36acc4f..edadcd8 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -403,9 +403,6 @@ _cairo_image_surface_create_with_content (cairo_content_t content,
width, height);
}
-/* pixman required stride alignment in bytes. should be power of two. */
-#define STRIDE_ALIGNMENT (sizeof (uint32_t))
-
/**
* cairo_format_stride_for_width:
* @format: A #cairo_format_t value
@@ -447,7 +444,7 @@ cairo_format_stride_for_width (cairo_format_t format,
if ((unsigned) (width) >= (INT32_MAX - 7) / (unsigned) (bpp))
return -1;
- return ((bpp*width+7)/8 + STRIDE_ALIGNMENT-1) & ~(STRIDE_ALIGNMENT-1);
+ return CAIRO_STRIDE_FOR_WIDTH_BPP (width, bpp);
}
slim_hidden_def (cairo_format_stride_for_width);
@@ -506,7 +503,7 @@ cairo_image_surface_create_for_data (unsigned char *data,
if (! CAIRO_FORMAT_VALID (format))
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
- if ((stride & (STRIDE_ALIGNMENT-1)) != 0)
+ if ((stride & (CAIRO_STRIDE_ALIGNMENT-1)) != 0)
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
pixman_format = _cairo_format_to_pixman_format_code (format);
diff --git a/src/cairoint.h b/src/cairoint.h
index 84aa61b..0a66f25 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1829,6 +1829,11 @@ _cairo_surface_has_device_transform (cairo_surface_t *surface);
#define CAIRO_FORMAT_INVALID ((unsigned int) -1)
#define CAIRO_FORMAT_VALID(format) ((format) <= CAIRO_FORMAT_A1)
+/* pixman-required stride alignment in bytes. */
+#define CAIRO_STRIDE_ALIGNMENT (sizeof (uint32_t))
+#define CAIRO_STRIDE_FOR_WIDTH_BPP(w,bpp) \
+ (((bpp)*(w)+7)/8 + CAIRO_STRIDE_ALIGNMENT-1) & ~(CAIRO_STRIDE_ALIGNMENT-1)
+
#define CAIRO_CONTENT_VALID(content) ((content) && \
(((content) & ~(CAIRO_CONTENT_COLOR | \
CAIRO_CONTENT_ALPHA | \
commit eb31c52febd615a92ef0c7204f9fa056ef01b536
Author: Carl Worth <cworth at cworth.org>
Date: Fri Mar 14 16:48:41 2008 +0100
Make _pixman_format_to_masks accept a cairo_format_masks_t structure
This makes it work similarly to _pixman_format_from_masks
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 87abf16..36acc4f 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -221,59 +221,55 @@ _pixman_format_from_masks (cairo_format_masks_t *masks,
/* XXX: This function should really live inside pixman. */
void
_pixman_format_to_masks (pixman_format_code_t pixman_format,
- uint32_t *bpp,
- uint32_t *red,
- uint32_t *green,
- uint32_t *blue)
+ cairo_format_masks_t *masks)
{
- *red = 0x0;
- *green = 0x0;
- *blue = 0x0;
+ masks->red_mask = 0x0;
+ masks->green_mask = 0x0;
+ masks->blue_mask = 0x0;
switch (pixman_format)
{
case PIXMAN_a8r8g8b8:
case PIXMAN_x8r8g8b8:
default:
- *bpp = 32;
- *red = 0x00ff0000;
- *green = 0x0000ff00;
- *blue = 0x000000ff;
+ masks->bpp = 32;
+ masks->red_mask = 0x00ff0000;
+ masks->green_mask = 0x0000ff00;
+ masks->blue_mask = 0x000000ff;
break;
case PIXMAN_a8b8g8r8:
case PIXMAN_x8b8g8r8:
- *bpp = 32;
- *red = 0x000000ff;
- *green = 0x0000ff00;
- *blue = 0x00ff0000;
+ masks->bpp = 32;
+ masks->red_mask = 0x000000ff;
+ masks->green_mask = 0x0000ff00;
+ masks->blue_mask = 0x00ff0000;
break;
case PIXMAN_r5g6b5:
- *bpp = 16;
- *red = 0xf800;
- *green = 0x07e0;
- *blue = 0x001f;
+ masks->bpp = 16;
+ masks->red_mask = 0xf800;
+ masks->green_mask = 0x07e0;
+ masks->blue_mask = 0x001f;
break;
case PIXMAN_x1r5g5b5:
- *bpp = 16;
- *red = 0x7c00;
- *green = 0x03e0;
- *blue = 0x001f;
+ masks->bpp = 16;
+ masks->red_mask = 0x7c00;
+ masks->green_mask = 0x03e0;
+ masks->blue_mask = 0x001f;
break;
case PIXMAN_a8:
- *bpp = 8;
+ masks->bpp = 8;
break;
case PIXMAN_a1:
- *bpp = 1;
+ masks->bpp = 1;
break;
}
}
-
/* XXX: This function really should be eliminated. We don't really
* want to advertise a cairo image surface that supports any possible
* format. A minimal step would be to replace this function with one
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index cd1814b..b8bea7c 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -735,11 +735,11 @@ _draw_image_surface (cairo_xlib_surface_t *surface,
int dst_y)
{
XImage ximage;
- uint32_t bpp, red, green, blue;
+ cairo_format_masks_t image_masks;
int native_byte_order = _native_byte_order_lsb () ? LSBFirst : MSBFirst;
cairo_status_t status;
- _pixman_format_to_masks (image->pixman_format, &bpp, &red, &green, &blue);
+ _pixman_format_to_masks (image->pixman_format, &image_masks);
ximage.width = image->width;
ximage.height = image->height;
@@ -751,10 +751,10 @@ _draw_image_surface (cairo_xlib_surface_t *surface,
ximage.bitmap_pad = 32; /* always for libpixman */
ximage.depth = image->depth;
ximage.bytes_per_line = image->stride;
- ximage.bits_per_pixel = bpp;
- ximage.red_mask = red;
- ximage.green_mask = green;
- ximage.blue_mask = blue;
+ ximage.bits_per_pixel = image_masks.bpp;
+ ximage.red_mask = image_masks.red_mask;
+ ximage.green_mask = image_masks.green_mask;
+ ximage.blue_mask = image_masks.blue_mask;
ximage.xoffset = 0;
XInitImage (&ximage);
diff --git a/src/cairoint.h b/src/cairoint.h
index fdeeae5..84aa61b 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1854,10 +1854,7 @@ _pixman_format_from_masks (cairo_format_masks_t *masks,
cairo_private void
_pixman_format_to_masks (pixman_format_code_t pixman_format,
- uint32_t *bpp,
- uint32_t *red,
- uint32_t *green,
- uint32_t *blue);
+ cairo_format_masks_t *masks);
cairo_private cairo_surface_t *
_cairo_image_surface_create_with_pixman_format (unsigned char *data,
commit cdb1ae97f241ec6b24d64b0fa5447d26f6bc5318
Author: Carl Worth <cworth at cworth.org>
Date: Sun Jan 27 10:31:58 2008 -0800
Move assertion failure for unsupported masks up one level
We're moving the assertion up from inside _pixman_format_to_mask
to its callers. This will allow us to selectively eliminate the
assertion from the supported xlib backend, while leaving it in
the unsupported glitz and xcb backends for now.
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 57dbdb8..87abf16 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -142,8 +142,9 @@ _cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image,
}
/* XXX: This function should really live inside pixman. */
-pixman_format_code_t
-_pixman_format_from_masks (cairo_format_masks_t *masks)
+cairo_int_status_t
+_pixman_format_from_masks (cairo_format_masks_t *masks,
+ pixman_format_code_t *format_ret)
{
switch (masks->bpp) {
case 32:
@@ -152,28 +153,32 @@ _pixman_format_from_masks (cairo_format_masks_t *masks)
masks->green_mask == 0x0000ff00 &&
masks->blue_mask == 0x000000ff)
{
- return PIXMAN_a8r8g8b8;
+ *format_ret = PIXMAN_a8r8g8b8;
+ return CAIRO_STATUS_SUCCESS;
}
if (masks->alpha_mask == 0x00000000 &&
masks->red_mask == 0x00ff0000 &&
masks->green_mask == 0x0000ff00 &&
masks->blue_mask == 0x000000ff)
{
- return PIXMAN_x8r8g8b8;
+ *format_ret = PIXMAN_x8r8g8b8;
+ return CAIRO_STATUS_SUCCESS;
}
if (masks->alpha_mask == 0xff000000 &&
masks->red_mask == 0x000000ff &&
masks->green_mask == 0x0000ff00 &&
masks->blue_mask == 0x00ff0000)
{
- return PIXMAN_a8b8g8r8;
+ *format_ret = PIXMAN_a8b8g8r8;
+ return CAIRO_STATUS_SUCCESS;
}
if (masks->alpha_mask == 0x00000000 &&
masks->red_mask == 0x000000ff &&
masks->green_mask == 0x0000ff00 &&
masks->blue_mask == 0x00ff0000)
{
- return PIXMAN_x8b8g8r8;
+ *format_ret = PIXMAN_x8b8g8r8;
+ return CAIRO_STATUS_SUCCESS;
}
break;
case 16:
@@ -182,44 +187,35 @@ _pixman_format_from_masks (cairo_format_masks_t *masks)
masks->green_mask == 0x07e0 &&
masks->blue_mask == 0x001f)
{
- return PIXMAN_r5g6b5;
+ *format_ret = PIXMAN_r5g6b5;
+ return CAIRO_STATUS_SUCCESS;
}
if (masks->alpha_mask == 0x0000 &&
masks->red_mask == 0x7c00 &&
masks->green_mask == 0x03e0 &&
masks->blue_mask == 0x001f)
{
- return PIXMAN_x1r5g5b5;
+ *format_ret = PIXMAN_x1r5g5b5;
+ return CAIRO_STATUS_SUCCESS;
}
break;
case 8:
if (masks->alpha_mask == 0xff)
{
- return PIXMAN_a8;
+ *format_ret = PIXMAN_a8;
+ return CAIRO_STATUS_SUCCESS;
}
break;
case 1:
if (masks->alpha_mask == 0x1)
{
- return PIXMAN_a1;
+ *format_ret = PIXMAN_a1;
+ return CAIRO_STATUS_SUCCESS;
}
break;
}
- fprintf (stderr,
- "Error: Cairo " PACKAGE_VERSION " does not yet support the requested image format:\n"
- "\tDepth: %d\n"
- "\tAlpha mask: 0x%08lx\n"
- "\tRed mask: 0x%08lx\n"
- "\tGreen mask: 0x%08lx\n"
- "\tBlue mask: 0x%08lx\n"
- "Please file an enhancement request (quoting the above) at:\n"
- PACKAGE_BUGREPORT "\n",
- masks->bpp, masks->alpha_mask,
- masks->red_mask, masks->green_mask, masks->blue_mask);
-
- ASSERT_NOT_REACHED;
- return 0;
+ return CAIRO_INT_STATUS_UNSUPPORTED;
}
/* XXX: This function should really live inside pixman. */
@@ -289,9 +285,25 @@ _cairo_image_surface_create_with_masks (unsigned char *data,
int height,
int stride)
{
+ cairo_int_status_t status;
pixman_format_code_t pixman_format;
- pixman_format = _pixman_format_from_masks (masks);
+ status = _pixman_format_from_masks (masks, &pixman_format);
+ if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
+ fprintf (stderr,
+ "Error: Cairo " PACKAGE_VERSION " does not yet support the requested image format:\n"
+ "\tDepth: %d\n"
+ "\tAlpha mask: 0x%08lx\n"
+ "\tRed mask: 0x%08lx\n"
+ "\tGreen mask: 0x%08lx\n"
+ "\tBlue mask: 0x%08lx\n"
+ "Please file an enhancement request (quoting the above) at:\n"
+ PACKAGE_BUGREPORT "\n",
+ masks->bpp, masks->alpha_mask,
+ masks->red_mask, masks->green_mask, masks->blue_mask);
+
+ ASSERT_NOT_REACHED;
+ }
return _cairo_image_surface_create_with_pixman_format (data,
pixman_format,
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 59dd45b..cd1814b 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -461,12 +461,12 @@ _get_image_surface (cairo_xlib_surface_t *surface,
cairo_image_surface_t **image_out,
cairo_rectangle_int_t *image_rect)
{
+ cairo_int_status_t status;
cairo_image_surface_t *image;
XImage *ximage;
short x1, y1, x2, y2;
cairo_format_masks_t masks;
pixman_format_code_t pixman_format;
- cairo_status_t status;
x1 = 0;
y1 = 0;
@@ -600,7 +600,23 @@ _get_image_surface (cairo_xlib_surface_t *surface,
masks.alpha_mask = 0xffffffff;
}
- pixman_format = _pixman_format_from_masks (&masks);
+ status = _pixman_format_from_masks (&masks, &pixman_format);
+ if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
+ fprintf (stderr,
+ "Error: Cairo " PACKAGE_VERSION " does not yet support the requested image format:\n"
+ "\tDepth: %d\n"
+ "\tAlpha mask: 0x%08lx\n"
+ "\tRed mask: 0x%08lx\n"
+ "\tGreen mask: 0x%08lx\n"
+ "\tBlue mask: 0x%08lx\n"
+ "Please file an enhancement request (quoting the above) at:\n"
+ PACKAGE_BUGREPORT "\n",
+ masks.bpp, masks.alpha_mask,
+ masks.red_mask, masks.green_mask, masks.blue_mask);
+
+ ASSERT_NOT_REACHED;
+ }
+
image = (cairo_image_surface_t*)
_cairo_image_surface_create_with_pixman_format ((unsigned char *) ximage->data,
pixman_format,
diff --git a/src/cairoint.h b/src/cairoint.h
index c36a2a8..fdeeae5 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1848,8 +1848,9 @@ cairo_private cairo_surface_t *
_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image,
pixman_format_code_t pixman_format);
-cairo_private pixman_format_code_t
-_pixman_format_from_masks (cairo_format_masks_t *masks);
+cairo_private cairo_int_status_t
+_pixman_format_from_masks (cairo_format_masks_t *masks,
+ pixman_format_code_t *format_ret);
cairo_private void
_pixman_format_to_masks (pixman_format_code_t pixman_format,
More information about the cairo-commit
mailing list