diff --git a/pixman/src/icformat.c b/pixman/src/icformat.c index 62a171d..f47ee67 100644 --- a/pixman/src/icformat.c +++ b/pixman/src/icformat.c @@ -41,6 +41,12 @@ pixman_format_create (pixman_format_name 0xff0000, 0x00ff00, 0x0000ff); + case PIXMAN_FORMAT_NAME_BGR24: + return pixman_format_create_masks (32, + 0x0, + 0x0000ff, + 0x00ff00, + 0xff0000); case PIXMAN_FORMAT_NAME_A8: return pixman_format_create_masks (8, 0xff, 0, 0, 0); diff --git a/pixman/src/pixman.h b/pixman/src/pixman.h index ca24e33..36abe20 100644 --- a/pixman/src/pixman.h +++ b/pixman/src/pixman.h @@ -225,6 +225,7 @@ typedef enum pixman_operator { typedef enum pixman_format_name { PIXMAN_FORMAT_NAME_ARGB32, PIXMAN_FORMAT_NAME_RGB24, + PIXMAN_FORMAT_NAME_BGR24, PIXMAN_FORMAT_NAME_A8, PIXMAN_FORMAT_NAME_A1, PIXMAN_FORMAT_NAME_RGB16_565 diff --git a/pixman/update.pl b/pixman/update.pl index eb3ae33..97494ae 100644 --- a/pixman/update.pl +++ b/pixman/update.pl @@ -27,6 +27,7 @@ s/IcOperatorInReverse/PIXMAN_OPERATOR_IN s/IcOperatorSaturate/PIXMAN_OPERATOR_SATURATE/g; s/IcFormatNameARGB32/PIXMAN_FORMAT_NAME_AR_GB32/g; s/IcFormatNameRGB24/PIXMAN_FORMAT_NAME_RG_B24/g; +s/IcFormatNameBGR24/PIXMAN_FORMAT_NAME_BG_R24/g; s/IcFilterBilinear/PIXMAN_FILTER_BILINEAR/g; s/IcOperatorClear/PIXMAN_OPERATOR_CLEAR/g; s/IcFilterNearest/PIXMAN_FILTER_NEAREST/g; diff --git a/src/cairo-color.c b/src/cairo-color.c index e202af2..b822f30 100644 --- a/src/cairo-color.c +++ b/src/cairo-color.c @@ -89,6 +89,13 @@ _cairo_color_init_rgb (cairo_color_t *co _cairo_color_init_rgba (color, red, green, blue, 1.0); } +void +_cairo_color_init_bgr (cairo_color_t *color, + double blue, double green, double red) +{ + _cairo_color_init_rgba (color, blue, green, red, 1.0); +} + /* We multiply colors by (0x10000 - epsilon), such that we get a uniform * range even for 0xffff. In other words, (1.0 - epsilon) would convert * to 0xffff, not 0xfffe. diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 8957e4c..49dbff7 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -47,6 +47,7 @@ _cairo_format_bpp (cairo_format_t format case CAIRO_FORMAT_RGB16_565: return 16; case CAIRO_FORMAT_RGB24: + case CAIRO_FORMAT_BGR24: case CAIRO_FORMAT_ARGB32: return 32; } @@ -102,6 +103,11 @@ _cairo_format_from_pixman_format (pixman bm == 0x000000ff) return CAIRO_FORMAT_ARGB32; if (am == 0x0 && + rm == 0x000000ff && + gm == 0x0000ff00 && + bm == 0x00ff0000) + return CAIRO_FORMAT_BGR24; + if (am == 0x0 && rm == 0x00ff0000 && gm == 0x0000ff00 && bm == 0x000000ff) @@ -202,6 +208,9 @@ _create_pixman_format (cairo_format_t fo case CAIRO_FORMAT_RGB24: return pixman_format_create (PIXMAN_FORMAT_NAME_RGB24); break; + case CAIRO_FORMAT_BGR24: + return pixman_format_create (PIXMAN_FORMAT_NAME_BGR24); + break; case CAIRO_FORMAT_ARGB32: default: return pixman_format_create (PIXMAN_FORMAT_NAME_ARGB32); @@ -495,6 +504,7 @@ _cairo_content_from_format (cairo_format case CAIRO_FORMAT_ARGB32: return CAIRO_CONTENT_COLOR_ALPHA; case CAIRO_FORMAT_RGB24: + case CAIRO_FORMAT_BGR24: case CAIRO_FORMAT_RGB16_565: return CAIRO_CONTENT_COLOR; case CAIRO_FORMAT_A8: diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 1a62c66..7f034db 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -333,6 +333,45 @@ cairo_pattern_create_rgb (double red, do } /** + * cairo_pattern_create_bgr: + * @red: red component of the color + * @green: green component of the color + * @blue: blue component of the color + * + * Creates a new cairo_pattern_t corresponding to an opaque color. The + * color components are floating point numbers in the range 0 to 1. + * If the values passed in are outside that range, they will be + * clamped. + * + * Return value: the newly created #cairo_pattern_t if succesful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + **/ +cairo_pattern_t * +cairo_pattern_create_bgr (double blue, double green, double red) +{ + cairo_pattern_t *pattern; + cairo_color_t color; + + _cairo_restrict_value (&red, 0.0, 1.0); + _cairo_restrict_value (&green, 0.0, 1.0); + _cairo_restrict_value (&blue, 0.0, 1.0); + + _cairo_color_init_bgr (&color, blue, green, red); + + pattern = _cairo_pattern_create_solid (&color); + if (pattern->status) + _cairo_error (pattern->status); + + return pattern; +} + +/** * cairo_pattern_create_rgba: * @red: red component of the color * @green: green component of the color diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index b55eca0..07293ec 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -179,6 +179,8 @@ _CAIRO_FORMAT_DEPTH (cairo_format_t form return 8; case CAIRO_FORMAT_RGB24: return 24; + case CAIRO_FORMAT_BGR24: + return 24; case CAIRO_FORMAT_ARGB32: default: return 32; @@ -196,6 +198,8 @@ _CAIRO_FORMAT_TO_XRENDER_FORMAT(Display pict_format = PictStandardA8; break; case CAIRO_FORMAT_RGB24: pict_format = PictStandardRGB24; break; + case CAIRO_FORMAT_BGR24: + pict_format = PictStandardBGR24; break; case CAIRO_FORMAT_ARGB32: default: pict_format = PictStandardARGB32; break; @@ -372,6 +376,14 @@ _CAIRO_MASK_FORMAT (cairo_format_masks_t *format = CAIRO_FORMAT_RGB24; return True; } + if (masks->alpha_mask == 0x00000000 && + masks->red_mask == 0x000000ff && + masks->green_mask == 0x0000ff00 && + masks->blue_mask == 0x00ff0000) + { + *format = CAIRO_FORMAT_BGR24; + return True; + } break; case 8: if (masks->alpha_mask == 0xff) @@ -2454,6 +2466,8 @@ _cairo_xlib_surface_add_glyph (Display * data = new; } break; + case CAIRO_FORMAT_BGR24: + break; case CAIRO_FORMAT_RGB24: default: ASSERT_NOT_REACHED; diff --git a/src/cairo.c b/src/cairo.c index 4d005ba..5641ed5 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -601,6 +601,34 @@ cairo_set_source_rgb (cairo_t *cr, doubl } /** + * cairo_set_source_bgr + * @cr: a cairo context + * @blue: blue component of color + * @green: green component of color + * @red: red component of color + * + * Sets the source pattern within @cr to an opaque color. This opaque + * color will then be used for any subsequent drawing operation until + * a new source pattern is set. + * + * The color components are floating point numbers in the range 0 to + * 1. If the values passed in are outside that range, they will be + * clamped. + **/ +void +cairo_set_source_bgr (cairo_t *cr, double blue, double green, double red) +{ + cairo_pattern_t *pattern; + + if (cr->status) + return; + + pattern = cairo_pattern_create_bgr (blue, green, red); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); +} + +/** * cairo_set_source_rgba: * @cr: a cairo context * @red: red component of color diff --git a/src/cairo.h b/src/cairo.h index ab860e8..b801a73 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -318,6 +318,9 @@ cairo_public void cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue); cairo_public void +cairo_set_source_bgr (cairo_t *cr, double blue, double green, double red); + +cairo_public void cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, double alpha); @@ -1339,6 +1342,9 @@ cairo_surface_set_fallback_resolution (c * @CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with * the upper 8 bits unused. Red, Green, and Blue are stored * in the remaining 24 bits in that order. + * @CAIRO_FORMAT_BGR24: each pixel is a 32-bit quantity, with + * the upper 8 bits unused. Blue, Green, and Red are stored + * in the remaining 24 bits in that order. * @CAIRO_FORMAT_A8: each pixel is a 8-bit quantity holding * an alpha value. * @CAIRO_FORMAT_A1: each pixel is a 1-bit quantity holding @@ -1357,6 +1363,7 @@ cairo_surface_set_fallback_resolution (c typedef enum _cairo_format { CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24, + CAIRO_FORMAT_BGR24, CAIRO_FORMAT_A8, CAIRO_FORMAT_A1, CAIRO_FORMAT_RGB16_565 @@ -1406,6 +1413,9 @@ cairo_public cairo_pattern_t * cairo_pattern_create_rgb (double red, double green, double blue); cairo_public cairo_pattern_t * +cairo_pattern_create_bgr (double blue, double green, double red); + +cairo_public cairo_pattern_t * cairo_pattern_create_rgba (double red, double green, double blue, double alpha); @@ -1473,6 +1483,11 @@ cairo_pattern_add_color_stop_rgb (cairo_ double red, double green, double blue); cairo_public void +cairo_pattern_add_color_stop_bgr (cairo_pattern_t *pattern, + double offset, + double blue, double green, double red); + +cairo_public void cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, double offset, double red, double green, double blue, @@ -1626,6 +1641,7 @@ #define cairo_matrix_set_affine cairo_ #define cairo_matrix_set_identity cairo_matrix_set_identity_REPLACED_BY_cairo_matrix_init_identity #define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_REPLACED_BY_cairo_pattern_add_color_stop_rgba #define cairo_set_rgb_color cairo_set_rgb_color_REPLACED_BY_cairo_set_source_rgb +#define cairo_set_bgr_color cairo_set_bgr_color_REPLACED_BY_cairo_set_source_bgr #define cairo_set_pattern cairo_set_pattern_REPLACED_BY_cairo_set_source #define cairo_xlib_surface_create_for_pixmap_with_visual cairo_xlib_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xlib_surface_create #define cairo_xlib_surface_create_for_window_with_visual cairo_xlib_surface_create_for_window_with_visual_REPLACED_BY_cairo_xlib_surface_create diff --git a/src/cairoint.h b/src/cairoint.h index 9ecb072..aa77baf 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -1355,6 +1355,10 @@ _cairo_color_init_rgb (cairo_color_t *co double red, double green, double blue); cairo_private void +_cairo_color_init_bgr (cairo_color_t *color, + double blue, double green, double red); + +cairo_private void _cairo_color_init_rgba (cairo_color_t *color, double red, double green, double blue, double alpha);