summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-01-25 15:57:31 +0100
committerBenjamin Otte <otte@redhat.com>2010-04-23 23:30:09 +0200
commit5e7f245a4d159ce19cc70724477ef9d2faf33318 (patch)
treefac8273eadd7342349819872a9c2875e442d4508
parentafb26f759a0dc6ea5ba5973297ef7acce4387be6 (diff)
Add RGBA32, BGRA32 and ABGR32 formats
-rw-r--r--src/cairo-image-surface.c26
-rw-r--r--src/cairo-xlib-display.c3
-rw-r--r--src/cairo.h35
-rw-r--r--src/cairoint.h32
-rw-r--r--util/cairo-script/cairo-script-operators.c12
-rw-r--r--util/cairo-trace/trace.c13
6 files changed, 80 insertions, 41 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 473777f5..8e741504 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -88,7 +88,13 @@ _cairo_format_from_pixman_format (pixman_format_code_t pixman_format)
return CAIRO_FORMAT_A1;
case PIXMAN_r5g6b5:
return CAIRO_FORMAT_RGB16_565;
- case PIXMAN_a8b8g8r8: case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8:
+ case PIXMAN_a8b8g8r8:
+ return CAIRO_FORMAT_ABGR32;
+ case PIXMAN_r8g8b8a8:
+ return CAIRO_FORMAT_RGBA32;
+ case PIXMAN_b8g8r8a8:
+ return CAIRO_FORMAT_BGRA32;
+ case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8:
case PIXMAN_b8g8r8: case PIXMAN_b5g6r5:
case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5:
case PIXMAN_x1b5g5r5: case PIXMAN_a4r4g4b4: case PIXMAN_x4r4g4b4:
@@ -100,7 +106,6 @@ _cairo_format_from_pixman_format (pixman_format_code_t pixman_format)
case PIXMAN_g4: case PIXMAN_g1:
case PIXMAN_yuy2: case PIXMAN_yv12:
case PIXMAN_b8g8r8x8:
- case PIXMAN_b8g8r8a8:
case PIXMAN_x2b10g10r10:
case PIXMAN_a2b10g10r10:
case PIXMAN_x2r10g10b10:
@@ -281,6 +286,15 @@ _cairo_format_to_pixman_format_code (cairo_format_t format)
case CAIRO_FORMAT_RGB16_565:
ret = PIXMAN_r5g6b5;
break;
+ case CAIRO_FORMAT_RGBA32:
+ ret = PIXMAN_r8g8b8a8;
+ break;
+ case CAIRO_FORMAT_BGRA32:
+ ret = PIXMAN_b8g8r8a8;
+ break;
+ case CAIRO_FORMAT_ABGR32:
+ ret = PIXMAN_a8b8g8r8;
+ break;
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_INVALID:
default:
@@ -773,10 +787,12 @@ cairo_content_t
_cairo_content_from_format (cairo_format_t format)
{
switch (format) {
+ case CAIRO_FORMAT_ABGR32:
case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_RGBA32:
return CAIRO_CONTENT_COLOR_ALPHA;
case CAIRO_FORMAT_RGB24:
- return CAIRO_CONTENT_COLOR;
case CAIRO_FORMAT_RGB16_565:
return CAIRO_CONTENT_COLOR;
case CAIRO_FORMAT_A8:
@@ -794,8 +810,10 @@ int
_cairo_format_bits_per_pixel (cairo_format_t format)
{
switch (format) {
+ case CAIRO_FORMAT_ABGR32:
case CAIRO_FORMAT_ARGB32:
- return 32;
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_RGBA32:
case CAIRO_FORMAT_RGB24:
return 32;
case CAIRO_FORMAT_RGB16_565:
diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index 0b6fbebb..757c8838 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -595,6 +595,9 @@ _cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display,
}
case CAIRO_FORMAT_INVALID:
default:
+ case CAIRO_FORMAT_RGBA32:
+ case CAIRO_FORMAT_ABGR32:
+ case CAIRO_FORMAT_BGRA32:
ASSERT_NOT_REACHED;
case CAIRO_FORMAT_ARGB32:
pict_format = PictStandardARGB32; break;
diff --git a/src/cairo.h b/src/cairo.h
index 8448bded..04548815 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2263,14 +2263,36 @@ cairo_surface_has_show_text_glyphs (cairo_surface_t *surface);
* endianess of the platform. On a big-endian machine, the
* first pixel is in the uppermost bit, on a little-endian
* machine the first pixel is in the least-significant bit.
- * @CAIRO_FORMAT_RGB16_565: This format value is deprecated. It has
- * never been properly implemented in cairo and should not be used
- * by applications. (since 1.2)
+ * @CAIRO_FORMAT_RGB16_565: each bit is a 16bit quantity. The upper
+ * 5 bits hold the red value, the next 6 bits hold green. The lower
+ * 5 bits contain the blue value. (since 1.2)
+ * @CAIRO_FORMAT_RGBA32: each pixel is a 32-bit quantity, with
+ * red in the upper 8 bits, then green, then blue, then alpha.
+ * The 32-bit quantities are stored native-endian. This is the
+ * format used by GdkPixbuf and HTML5's canvas on big endian
+ * machines.
+ * @CAIRO_FORMAT_ABGR32: each pixel is a 32-bit quantity, with
+ * alpha in the upper 8 bits, then blue, then green, then red.
+ * The 32-bit quantities are stored native-endian. This is the
+ * format used by GdkPixbuf and HTML5's canvas on little endian
+ * machines.
+ * @CAIRO_FORMAT_BGRA32: each pixel is a 32-bit quantity, with
+ * blue in the upper 8 bits, then green, then red, then alpha.
+ * The 32-bit quantities are stored native-endian.
*
* #cairo_format_t is used to identify the memory format of
* image data.
*
- * New entries may be added in future versions.
+ * Cairo by default only optimizes performance of the
+ * formats @CAIRO_FORMAT_ARGB32, @CAIRO_FORMAT_RGB24 and
+ * @CAIRO_FORMAT_A8. Other formats may internally be converted to
+ * these formats and should only be used for cases where the data
+ * format is required.
+ *
+ * New entries may be added in future versions on an as-needed basis.
+ * If you need support for a new format, please file a bug. Do not
+ * try to convert the format yourself before passing it to Cairo.
+ * This is likely to be slower and harder to support.
**/
typedef enum _cairo_format {
CAIRO_FORMAT_INVALID = -1,
@@ -2278,7 +2300,10 @@ typedef enum _cairo_format {
CAIRO_FORMAT_RGB24 = 1,
CAIRO_FORMAT_A8 = 2,
CAIRO_FORMAT_A1 = 3,
- CAIRO_FORMAT_RGB16_565 = 4
+ CAIRO_FORMAT_RGB16_565 = 4,
+ CAIRO_FORMAT_RGBA32 = 5,
+ CAIRO_FORMAT_ABGR32 = 6,
+ CAIRO_FORMAT_BGRA32 = 7
} cairo_format_t;
/**
diff --git a/src/cairoint.h b/src/cairoint.h
index 2d37ac50..00ac0713 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2116,38 +2116,8 @@ _cairo_surface_has_device_transform (cairo_surface_t *surface) cairo_pure;
/* cairo-image-surface.c */
-/* XXX: In cairo 1.2.0 we added a new %CAIRO_FORMAT_RGB16_565 but
- * neglected to adjust this macro. The net effect is that it's
- * impossible to externally create an image surface with this
- * format. This is perhaps a good thing since we also neglected to fix
- * up things like cairo_surface_write_to_png() for the new format
- * (-Wswitch-enum will tell you where). Is it obvious that format was
- * added in haste?
- *
- * The reason for the new format was to allow the xlib backend to be
- * used on X servers with a 565 visual. So the new format did its job
- * for that, even without being considered "valid" for the sake of
- * things like cairo_image_surface_create().
- *
- * Since 1.2.0 we ran into the same situtation with X servers with BGR
- * visuals. This time we invented #cairo_internal_format_t instead,
- * (see it for more discussion).
- *
- * The punchline is that %CAIRO_FORMAT_VALID must not conside any
- * internal format to be valid. Also we need to decide if the
- * RGB16_565 should be moved to instead be an internal format. If so,
- * this macro need not change for it. (We probably will need to leave
- * an RGB16_565 value in the header files for the sake of code that
- * might have that value in it.)
- *
- * If we do decide to start fully supporting RGB16_565 as an external
- * format, then %CAIRO_FORMAT_VALID needs to be adjusted to include
- * it. But that should not happen before all necessary code is fixed
- * to support it (at least cairo_surface_write_to_png() and a few spots
- * in cairo-xlib-surface.c--again see -Wswitch-enum).
- */
#define CAIRO_FORMAT_VALID(format) ((format) >= CAIRO_FORMAT_ARGB32 && \
- (format) <= CAIRO_FORMAT_RGB16_565)
+ (format) <= CAIRO_FORMAT_BGRA32)
#define CAIRO_FORMAT_MAX_PLANES 4
#define CAIRO_COLOR_SPACE_VALID(colorspace) ((colorspace) <= CAIRO_COLOR_SPACE_YCBCR_JPEG)
diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c
index b4a1a95b..1af6fd7f 100644
--- a/util/cairo-script/cairo-script-operators.c
+++ b/util/cairo-script/cairo-script-operators.c
@@ -2848,6 +2848,9 @@ _image_read_raw (csi_file_t *src,
break;
default:
case CAIRO_FORMAT_INVALID:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_RGBA32:
+ case CAIRO_FORMAT_ABGR32:
case CAIRO_FORMAT_ARGB32:
len = 4 * width * height;
break;
@@ -2911,6 +2914,9 @@ _image_read_raw (csi_file_t *src,
break;
case CAIRO_FORMAT_INVALID:
case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_ABGR32:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_RGBA32:
/* stride == width */
break;
}
@@ -2997,6 +3003,9 @@ _image_read_raw (csi_file_t *src,
break;
case CAIRO_FORMAT_INVALID:
case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_ABGR32:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_RGBA32:
/* stride == width */
break;
}
@@ -3018,6 +3027,9 @@ _image_read_raw (csi_file_t *src,
}
break;
case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_ABGR32:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_RGBA32:
{
uint32_t *rgba = (uint32_t *) data;
for (x = len/4; x--; rgba++) {
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index fd83ee93..fbfa2fa5 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -1456,6 +1456,9 @@ _format_to_string (cairo_format_t format)
switch (format) {
f(INVALID);
f(ARGB32);
+ f(ABGR32);
+ f(RGBA32);
+ f(BGRA32);
f(RGB24);
f(RGB16_565);
f(A8);
@@ -1589,7 +1592,10 @@ _emit_image (cairo_surface_t *image,
case CAIRO_FORMAT_RGB24: len = 3*width; break;
default:
case CAIRO_FORMAT_INVALID:
- case CAIRO_FORMAT_ARGB32: len = 4*width; break;
+ case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_RGBA32:
+ case CAIRO_FORMAT_BGRA32:
+ case CAIRO_FORMAT_ABGR32: len = 4*width; break;
}
_trace_printf (" /source ");
@@ -1686,6 +1692,9 @@ _emit_image (cairo_surface_t *image,
}
break;
case CAIRO_FORMAT_ARGB32:
+ case CAIRO_FORMAT_ABGR32:
+ case CAIRO_FORMAT_RGBA32:
+ case CAIRO_FORMAT_BGRA32:
for (row = height; row--; ) {
uint32_t *src = (uint32_t *) data;
uint32_t *dst = (uint32_t *) rowdata;
@@ -3691,7 +3700,9 @@ cairo_surface_write_to_png_stream (cairo_surface_t *surface,
_enter_trace ();
_emit_line_info ();
if (surface != NULL && _write_lock ()) {
+#if CAIRO_HAS_SYMBOL_LOOKUP
char symbol[1024];
+#endif
_trace_printf ("%% s%ld ", _get_surface_id (surface));
#if CAIRO_HAS_SYMBOL_LOOKUP