[cairo] [PATCH]: pixman: New functions for converting format to/from masks

Carl Worth cworth at cworth.org
Tue Mar 25 13:13:48 PDT 2008


On 25 Mar 2008 20:24:03 +0100, Soeren Sandmann wrote:
> The main issue I see with this is that a pixman format can't really be
> fully described by that struct. For example formats with 16 bits per
> channel or floating point formats will not be describable.
>
> What does describe a pixman format is the format code itself,
> though.

Fair enough.

> The issue with that is that there is no guarantee that the format
> would be supported by pixman, so we would need a couple of new
> functions:

Yes, that's the piece of information that cairo doesn't know.

>         pixman_format_supported_destination ()
>         pixman_format_supported_source()
>
> Both functions would simply return TRUE for all supported formats,
> except that the destination one would return FALSE for YUV formats.

OK, patch attached to do exactly that.

I'll try using this in cairo and I'll let you know if I think I need
anything else.

Thanks for your feedback,

-Carl

-------------- next part --------------
From 7fa668f4ac4be756d097b29240bf15bb71ae6db9 Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth at cworth.org>
Date: Tue, 25 Mar 2008 13:12:29 -0700
Subject: [PATCH] New API: pixman_format_supported_destination and pixman_format_supported_source

These functions allow for callers to use the PIXMAN_FORMAT macro to
construct a format code and to then determine if the resulting code
is supported by pixman for either destination or source surfaces.
---
 pixman/pixman-utils.c |  129 +++++++++++++++++++++++++++++++++++++++++++++++++
 pixman/pixman.h       |    7 +++
 2 files changed, 136 insertions(+), 0 deletions(-)

diff --git a/pixman/pixman-utils.c b/pixman/pixman-utils.c
index 73c1cde..d4e4c77 100644
--- a/pixman/pixman-utils.c
+++ b/pixman/pixman-utils.c
@@ -407,3 +407,132 @@ pixman_malloc_abc (unsigned int a,
     else
 	return malloc (a * b * c);
 }
+
+/**
+ * pixman_format_supported_destination:
+ * @format: A pixman_format_code_t format
+ * 
+ * Return value: whether the provided format code is a supported
+ * format for a pixman surface used as a destination in
+ * rendering.
+ *
+ * Currently, all pixman_format_code_t values are supported
+ * except for the YUV formats.
+ **/
+pixman_bool_t
+pixman_format_supported_destination (pixman_format_code_t format)
+{
+    switch (format) {
+    /* 32 bpp formats */
+    case PIXMAN_a8r8g8b8:
+    case PIXMAN_x8r8g8b8:
+    case PIXMAN_a8b8g8r8:
+    case PIXMAN_x8b8g8r8:
+    case PIXMAN_r8g8b8:
+    case PIXMAN_b8g8r8:
+    case PIXMAN_r5g6b5:
+    case PIXMAN_b5g6r5:
+    /* 16 bpp formats */
+    case PIXMAN_a1r5g5b5:
+    case PIXMAN_x1r5g5b5:
+    case PIXMAN_a1b5g5r5:
+    case PIXMAN_x1b5g5r5:
+    case PIXMAN_a4r4g4b4:
+    case PIXMAN_x4r4g4b4:
+    case PIXMAN_a4b4g4r4:
+    case PIXMAN_x4b4g4r4:
+    /* 8bpp formats */
+    case PIXMAN_a8:
+    case PIXMAN_r3g3b2:
+    case PIXMAN_b2g3r3:
+    case PIXMAN_a2r2g2b2:
+    case PIXMAN_a2b2g2r2:
+    case PIXMAN_c8:
+    case PIXMAN_g8:
+    case PIXMAN_x4a4:
+    case PIXMAN_x4c4:
+    case PIXMAN_x4g4:
+    /* 4bpp formats */
+    case PIXMAN_a4:
+    case PIXMAN_r1g2b1:
+    case PIXMAN_b1g2r1:
+    case PIXMAN_a1r1g1b1:
+    case PIXMAN_a1b1g1r1:
+    case PIXMAN_c4:
+    case PIXMAN_g4:
+    /* 1bpp formats */
+    case PIXMAN_a1:
+    case PIXMAN_g1:
+	return TRUE;
+	
+    /* YUV formats */
+    case PIXMAN_yuy2:
+    case PIXMAN_yv12:
+    default:
+	return FALSE;
+    }
+}
+
+/**
+ * pixman_format_supported_source:
+ * @format: A pixman_format_code_t format
+ * 
+ * Return value: whether the provided format code is a supported
+ * format for a pixman surface used as a source in
+ * rendering.
+ *
+ * Currently, all pixman_format_code_t values are supported.
+ **/
+pixman_bool_t
+pixman_format_supported_source (pixman_format_code_t format)
+{
+    switch (format) {
+    /* 32 bpp formats */
+    case PIXMAN_a8r8g8b8:
+    case PIXMAN_x8r8g8b8:
+    case PIXMAN_a8b8g8r8:
+    case PIXMAN_x8b8g8r8:
+    case PIXMAN_r8g8b8:
+    case PIXMAN_b8g8r8:
+    case PIXMAN_r5g6b5:
+    case PIXMAN_b5g6r5:
+    /* 16 bpp formats */
+    case PIXMAN_a1r5g5b5:
+    case PIXMAN_x1r5g5b5:
+    case PIXMAN_a1b5g5r5:
+    case PIXMAN_x1b5g5r5:
+    case PIXMAN_a4r4g4b4:
+    case PIXMAN_x4r4g4b4:
+    case PIXMAN_a4b4g4r4:
+    case PIXMAN_x4b4g4r4:
+    /* 8bpp formats */
+    case PIXMAN_a8:
+    case PIXMAN_r3g3b2:
+    case PIXMAN_b2g3r3:
+    case PIXMAN_a2r2g2b2:
+    case PIXMAN_a2b2g2r2:
+    case PIXMAN_c8:
+    case PIXMAN_g8:
+    case PIXMAN_x4a4:
+    case PIXMAN_x4c4:
+    case PIXMAN_x4g4:
+    /* 4bpp formats */
+    case PIXMAN_a4:
+    case PIXMAN_r1g2b1:
+    case PIXMAN_b1g2r1:
+    case PIXMAN_a1r1g1b1:
+    case PIXMAN_a1b1g1r1:
+    case PIXMAN_c4:
+    case PIXMAN_g4:
+    /* 1bpp formats */
+    case PIXMAN_a1:
+    case PIXMAN_g1:
+    /* YUV formats */
+    case PIXMAN_yuy2:
+    case PIXMAN_yv12:
+	return TRUE;
+
+    default:
+	return FALSE;
+    }
+}
diff --git a/pixman/pixman.h b/pixman/pixman.h
index c4c5c3b..6a27a3f 100644
--- a/pixman/pixman.h
+++ b/pixman/pixman.h
@@ -503,6 +503,13 @@ typedef enum {
     PIXMAN_yv12 =	PIXMAN_FORMAT(12,PIXMAN_TYPE_YV12,0,0,0,0),
 } pixman_format_code_t;
 
+/* Querying supported format values. */
+PIXMAN_EXPORT
+pixman_bool_t	pixman_format_supported_destination (pixman_format_code_t format);
+
+PIXMAN_EXPORT
+pixman_bool_t	pixman_format_supported_source (pixman_format_code_t format);
+
 /* Constructors */
 PIXMAN_EXPORT
 pixman_image_t *pixman_image_create_solid_fill       (pixman_color_t               *color);
-- 
1.5.5.rc0.24.g86c30

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080325/70104a01/attachment.pgp 


More information about the cairo mailing list