image: split cairo_image_surface_coerce()

Split into a general cairo_image_surface_coerce() that coerces to one of
the 3 supported formats (ARGB32, RGB24, A8) based on content and the
more general cairo_image_surface_coerce_to_format() that coerces to a
specified format.
This commit is contained in:
Benjamin Otte 2010-02-23 21:01:13 +01:00
parent b7c42b6aaa
commit 8bb06915ed
10 changed files with 30 additions and 34 deletions

View file

@ -71,8 +71,7 @@ _cairo_gl_glyph_cache_add_glyph (cairo_gl_context_t *ctx,
{
cairo_bool_t is_supported;
clone = _cairo_image_surface_coerce (glyph_surface,
_cairo_format_from_content (glyph_surface->base.content));
clone = _cairo_image_surface_coerce (glyph_surface);
if (unlikely (clone->base.status))
return clone->base.status;

View file

@ -693,8 +693,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
{
cairo_bool_t is_supported;
clone = _cairo_image_surface_coerce (src,
_cairo_format_from_content (src->base.content));
clone = _cairo_image_surface_coerce (src);
if (unlikely (clone->base.status))
return clone->base.status;

View file

@ -4320,8 +4320,18 @@ const cairo_surface_backend_t _cairo_image_surface_backend = {
/* A convenience function for when one needs to coerce an image
* surface to an alternate format. */
cairo_image_surface_t *
_cairo_image_surface_coerce (cairo_image_surface_t *surface,
cairo_format_t format)
_cairo_image_surface_coerce (cairo_image_surface_t *surface)
{
return _cairo_image_surface_coerce_to_format (surface,
_cairo_format_from_content (surface->base.content));
}
/* A convenience function for when one needs to coerce an image
* surface to an alternate format. */
cairo_image_surface_t *
_cairo_image_surface_coerce_to_format (cairo_image_surface_t *surface,
cairo_format_t format)
{
cairo_image_surface_t *clone;
cairo_status_t status;

View file

@ -172,8 +172,7 @@ write_png (cairo_surface_t *surface,
/* Handle the various fallback formats (e.g. low bit-depth XServers)
* by coercing them to a simpler format using pixman.
*/
clone = _cairo_image_surface_coerce (image,
_cairo_format_from_content (image->base.content));
clone = _cairo_image_surface_coerce (image);
status = clone->base.status;
if (unlikely (status))
goto BAIL1;

View file

@ -2302,7 +2302,7 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
cairo_fixed_t px, py;
cairo_status_t status;
mask = _cairo_image_surface_coerce (mask, CAIRO_FORMAT_A1);
mask = _cairo_image_surface_coerce_to_format (mask, CAIRO_FORMAT_A1);
status = mask->base.status;
if (unlikely (status))
return status;

View file

@ -1202,9 +1202,7 @@ _emit_image_surface (cairo_script_surface_t *surface,
uint32_t len;
if (image->format == CAIRO_FORMAT_INVALID) {
clone =
_cairo_image_surface_coerce (image,
_cairo_format_from_content (image->base.content));
clone = _cairo_image_surface_coerce (image);
} else {
clone = (cairo_image_surface_t *)
cairo_surface_reference (&image->base);

View file

@ -736,8 +736,8 @@ _cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t *document,
if (unlikely (status))
return status;
image = _cairo_image_surface_coerce (scaled_glyph->surface,
CAIRO_FORMAT_A1);
image = _cairo_image_surface_coerce_to_format (scaled_glyph->surface,
CAIRO_FORMAT_A1);
status = image->base.status;
if (unlikely (status))
return status;

View file

@ -120,7 +120,7 @@ _cairo_type3_glyph_surface_emit_image (cairo_type3_glyph_surface_t *surface,
cairo_status_t status;
/* The only image type supported by Type 3 fonts are 1-bit masks */
image = _cairo_image_surface_coerce (image, CAIRO_FORMAT_A1);
image = _cairo_image_surface_coerce_to_format (image, CAIRO_FORMAT_A1);
status = image->base.status;
if (unlikely (status))
return status;

View file

@ -1342,29 +1342,16 @@ _cairo_xcb_surface_picture (cairo_xcb_surface_t *target,
_cairo_surface_release_source_image (source, image, image_extra);
} else {
cairo_image_surface_t *conv;
cairo_format_t format;
xcb_render_pictformat_t render_format;
/* XXX XRenderPutImage! */
switch (image->base.content) {
case CAIRO_CONTENT_ALPHA:
format = CAIRO_FORMAT_A8;
break;
case CAIRO_CONTENT_COLOR:
format = CAIRO_FORMAT_RGB24;
break;
case CAIRO_CONTENT_COLOR_ALPHA:
format = CAIRO_FORMAT_ARGB32;
break;
}
conv = _cairo_image_surface_coerce (image, format);
conv = _cairo_image_surface_coerce (image);
_cairo_surface_release_source_image (source, image, image_extra);
if (unlikely (conv->base.status))
return (cairo_xcb_picture_t *) conv;
render_format = target->screen->connection->standard_formats[format];
render_format = target->screen->connection->standard_formats[conv->format];
picture = _picture_from_image (target, render_format, conv, NULL);
cairo_surface_destroy (&conv->base);
}
@ -4000,8 +3987,8 @@ _cairo_xcb_surface_add_glyph (cairo_xcb_connection_t *connection,
* format.
*/
if (glyph_surface->format != glyphset_info->format) {
glyph_surface = _cairo_image_surface_coerce (glyph_surface,
glyphset_info->format);
glyph_surface = _cairo_image_surface_coerce_to_format (glyph_surface,
glyphset_info->format);
status = glyph_surface->base.status;
if (unlikely (status))
goto BAIL;

View file

@ -2205,8 +2205,12 @@ cairo_private void
_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface);
cairo_private cairo_image_surface_t *
_cairo_image_surface_coerce (cairo_image_surface_t *surface,
cairo_format_t format);
_cairo_image_surface_coerce (cairo_image_surface_t *surface);
cairo_private cairo_image_surface_t *
_cairo_image_surface_coerce_to_format (cairo_image_surface_t *surface,
cairo_format_t format);
cairo_private void
_cairo_image_surface_span_render_row (int y,
const cairo_half_open_span_t *spans,