summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cairo-debug.c3
-rw-r--r--src/cairo-image-surface.c81
-rw-r--r--src/cairo-pdf-surface.c10
-rw-r--r--src/cairo-png.c2
-rw-r--r--src/cairo-ps-surface.c9
-rw-r--r--src/cairo-scaled-font.c10
-rw-r--r--src/cairo-surface-subsurface.c4
-rw-r--r--src/cairo-svg-surface.c5
-rw-r--r--src/cairo-xlib-surface.c18
-rw-r--r--src/cairoint.h5
10 files changed, 83 insertions, 64 deletions
diff --git a/src/cairo-debug.c b/src/cairo-debug.c
index c4f70dfb..8bab7acb 100644
--- a/src/cairo-debug.c
+++ b/src/cairo-debug.c
@@ -98,7 +98,6 @@ _cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface)
if (! RUNNING_ON_VALGRIND)
return;
- bits = image->data;
switch (image->format) {
case CAIRO_FORMAT_A1:
width = (image->width + 7)/8;
@@ -120,10 +119,10 @@ _cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface)
}
for (row = 0; row < image->height; row++) {
+ bits = cairo_image_surface_get_data_for_row (image, row);
VALGRIND_CHECK_MEM_IS_DEFINED (bits, width);
/* and then silence any future valgrind warnings */
VALGRIND_MAKE_MEM_DEFINED (bits, width);
- bits += image->stride;
}
}
#endif
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 75388264..cd26ec77 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -147,13 +147,11 @@ _cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image,
surface->pixman_format = pixman_format;
surface->format = _cairo_format_from_pixman_format (pixman_format);
- surface->data = (uint8_t *) pixman_image_get_data (pixman_image);
surface->owns_data = FALSE;
surface->transparency = CAIRO_IMAGE_UNKNOWN;
surface->width = width;
surface->height = height;
- surface->stride = pixman_image_get_stride (pixman_image);
surface->depth = pixman_image_get_depth (pixman_image);
return &surface->base;
@@ -519,7 +517,7 @@ cairo_image_surface_get_data (cairo_surface_t *surface)
return NULL;
}
- return image_surface->data;
+ return (unsigned char *) pixman_image_get_data (image_surface->pixman_image);
}
slim_hidden_def (cairo_image_surface_get_data);
@@ -615,7 +613,7 @@ cairo_image_surface_get_stride (cairo_surface_t *surface)
return 0;
}
- return image_surface->stride;
+ return pixman_image_get_stride (image_surface->pixman_image);
}
slim_hidden_def (cairo_image_surface_get_stride);
@@ -704,16 +702,14 @@ _cairo_image_surface_finish (void *abstract_surface)
{
cairo_image_surface_t *surface = abstract_surface;
+ if (surface->owns_data)
+ free (pixman_image_get_data (surface->pixman_image));
+
if (surface->pixman_image) {
pixman_image_unref (surface->pixman_image);
surface->pixman_image = NULL;
}
- if (surface->owns_data) {
- free (surface->data);
- surface->data = NULL;
- }
-
return CAIRO_STATUS_SUCCESS;
}
@@ -1251,8 +1247,8 @@ _pixman_image_for_surface (const cairo_surface_pattern_t *pattern,
pixman_image = pixman_image_create_bits (source->pixman_format,
source->width,
source->height,
- (uint32_t *) source->data,
- source->stride);
+ pixman_image_get_data (source->pixman_image),
+ pixman_image_get_stride (source->pixman_image));
if (unlikely (pixman_image == NULL))
return NULL;
} else if (type == CAIRO_INTERNAL_SURFACE_TYPE_SUBSURFACE) {
@@ -1283,11 +1279,13 @@ _pixman_image_for_surface (const cairo_surface_pattern_t *pattern,
/* Avoid sub-byte offsets, force a copy in that case. */
if (PIXMAN_FORMAT_BPP (source->pixman_format) >= 8) {
+ uint8_t *data = cairo_image_surface_get_data_for_row (source, sub->extents.y);
+ data += sub->extents.x * PIXMAN_FORMAT_BPP(source->pixman_format)/8;
pixman_image = pixman_image_create_bits (source->pixman_format,
sub->extents.width,
sub->extents.height,
- (uint32_t *) (source->data + sub->extents.x * PIXMAN_FORMAT_BPP(source->pixman_format)/8 + sub->extents.y * source->stride),
- source->stride);
+ (uint32_t *) data,
+ pixman_image_get_stride (source->pixman_image));
if (unlikely (pixman_image == NULL))
return NULL;
}
@@ -1325,8 +1323,8 @@ _pixman_image_for_surface (const cairo_surface_pattern_t *pattern,
pixman_image = pixman_image_create_bits (source->pixman_format,
source->width,
source->height,
- (uint32_t *) source->data,
- source->stride);
+ pixman_image_get_data (source->pixman_image),
+ pixman_image_get_stride (source->pixman_image));
if (unlikely (pixman_image == NULL)) {
_cairo_surface_release_source_image (pattern->surface,
cleanup->image,
@@ -1589,7 +1587,9 @@ _cairo_image_surface_fixup_unbounded_boxes (cairo_image_surface_t *dst,
cairo_box_t box;
cairo_status_t status;
struct _cairo_boxes_chunk *chunk;
- int i;
+ pixman_color_t color = { 0, };
+ pixman_box32_t *pixman_boxes;
+ int i, j;
if (boxes->num_boxes <= 1 && clip_region == NULL) {
_cairo_image_surface_fixup_unbounded (dst, extents, NULL);
@@ -1643,22 +1643,32 @@ _cairo_image_surface_fixup_unbounded_boxes (cairo_image_surface_t *dst,
&clear);
}
- if (likely (status == CAIRO_STATUS_SUCCESS)) {
- for (chunk = &clear.chunks; chunk != NULL; chunk = chunk->next) {
- for (i = 0; i < chunk->count; i++) {
- int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
- int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
- int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
- int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
+ if (unlikely (status != CAIRO_STATUS_SUCCESS))
+ goto CLEANUP;
- pixman_fill ((uint32_t *) dst->data, dst->stride / sizeof (uint32_t),
- PIXMAN_FORMAT_BPP (dst->pixman_format),
- x1, y1, x2 - x1, y2 - y1,
- 0);
- }
- }
+ pixman_boxes = _cairo_malloc_ab (sizeof (pixman_box32_t), clear.num_boxes);
+ if (unlikely (boxes == NULL))
+ goto CLEANUP;
+
+ j = 0;
+ for (chunk = &clear.chunks; chunk != NULL; chunk = chunk->next) {
+ for (i = 0; i < chunk->count; i++) {
+ pixman_boxes[j].x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
+ pixman_boxes[j].y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
+ pixman_boxes[j].x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
+ pixman_boxes[j].y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
+ j++;
+ }
}
+ pixman_image_fill_boxes (PIXMAN_OP_CLEAR,
+ dst->pixman_image,
+ &color,
+ clear.num_boxes,
+ pixman_boxes);
+
+ free (pixman_boxes);
+CLEANUP:
_cairo_boxes_fini (&clear);
return status;
@@ -2468,8 +2478,8 @@ _fill_unaligned_boxes (cairo_image_surface_t *dst,
if (x2 > x1 && y2 > y1) {
cairo_box_t b;
- pixman_fill ((uint32_t *) dst->data,
- dst->stride / sizeof (uint32_t),
+ pixman_fill ((uint32_t *) pixman_image_get_data (dst->pixman_image),
+ pixman_image_get_stride (dst->pixman_image) / sizeof (uint32_t),
PIXMAN_FORMAT_BPP (dst->pixman_format),
x1, y1, x2 - x1, y2 - y1,
pixel);
@@ -2726,7 +2736,8 @@ _composite_boxes (cairo_image_surface_t *dst,
if (x2 == x1 || y2 == y1)
continue;
- pixman_fill ((uint32_t *) dst->data, dst->stride / sizeof (uint32_t),
+ pixman_fill ((uint32_t *) pixman_image_get_data (dst->pixman_image),
+ pixman_image_get_stride (dst->pixman_image) / sizeof (uint32_t),
PIXMAN_FORMAT_BPP (dst->pixman_format),
x1, y1, x2 - x1, y2 - y1,
pixel);
@@ -4392,6 +4403,8 @@ cairo_image_transparency_t
_cairo_image_analyze_transparency (cairo_image_surface_t *image)
{
int x, y;
+ uint32_t *data;
+ unsigned int stride;
if (image->transparency != CAIRO_IMAGE_UNKNOWN)
return image->transparency;
@@ -4415,8 +4428,10 @@ _cairo_image_analyze_transparency (cairo_image_surface_t *image)
return image->transparency = CAIRO_IMAGE_HAS_ALPHA;
image->transparency = CAIRO_IMAGE_IS_OPAQUE;
+ data = pixman_image_get_data (image->pixman_image);
+ stride = pixman_image_get_stride (image->pixman_image) / sizeof (uint32_t);
for (y = 0; y < image->height; y++) {
- uint32_t *pixel = (uint32_t *) (image->data + y * image->stride);
+ uint32_t *pixel = (data + y * stride);
for (x = 0; x < image->width; x++, pixel++) {
int a = (*pixel & 0xff000000) >> 24;
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index ce1a8026..4b790d87 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1770,7 +1770,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
i = 0;
for (y = 0; y < image->height; y++) {
if (image->format == CAIRO_FORMAT_ARGB32) {
- pixel32 = (uint32_t *) (image->data + y * image->stride);
+ pixel32 = (uint32_t *) cairo_image_surface_get_data_for_row (image, y);
for (x = 0; x < image->width; x++, pixel32++) {
a = (*pixel32 & 0xff000000) >> 24;
@@ -1779,7 +1779,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
opaque = FALSE;
}
} else if (image->format == CAIRO_FORMAT_A8){
- pixel8 = (uint8_t *) (image->data + y * image->stride);
+ pixel8 = (uint8_t *) cairo_image_surface_get_data_for_row (image, y);
for (x = 0; x < image->width; x++, pixel8++) {
a = *pixel8;
@@ -1788,7 +1788,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
opaque = FALSE;
}
} else { /* image->format == CAIRO_FORMAT_A1 */
- pixel8 = (uint8_t *) (image->data + y * image->stride);
+ pixel8 = (uint8_t *) cairo_image_surface_get_data_for_row (image, y);
for (x = 0; x < (image->width + 7) / 8; x++, pixel8++) {
a = *pixel8;
@@ -1864,7 +1864,7 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t *surface,
i = 0;
for (y = 0; y < image->height; y++) {
- pixel = (uint32_t *) (image->data + y * image->stride);
+ pixel = (uint32_t *) cairo_image_surface_get_data_for_row (image, y);
for (x = 0; x < image->width; x++, pixel++) {
/* XXX: We're un-premultiplying alpha here. My reading of the PDF
@@ -4301,7 +4301,7 @@ _cairo_pdf_emit_imagemask (cairo_image_surface_t *image,
num_cols = (image->width + 7) / 8;
for (row = 0; row < image->height; row++) {
- byte = image->data + row * image->stride;
+ byte = cairo_image_surface_get_data_for_row (image, row);
for (col = 0; col < num_cols; col++) {
output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
_cairo_output_stream_write (stream, &output_byte, 1);
diff --git a/src/cairo-png.c b/src/cairo-png.c
index 10ad804f..b3af91f4 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -184,7 +184,7 @@ write_png (cairo_surface_t *surface,
}
for (i = 0; i < clone->height; i++)
- rows[i] = (png_byte *) clone->data + i * clone->stride;
+ rows[i] = (png_byte *) cairo_image_surface_get_data_for_row (clone, i);
png = png_create_write_struct (PNG_LIBPNG_VER_STRING, &status,
png_simple_error_callback,
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index fa0979be..258071bd 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -497,7 +497,8 @@ _cairo_ps_emit_imagemask (cairo_image_surface_t *image,
_cairo_output_stream_printf (stream,
" /DataSource {<\n ");
- for (row = image->data, rows = image->height; rows; row += image->stride, rows--) {
+ for (rows = 0; rows < image->height; rows++) {
+ row = cairo_image_surface_get_data_for_row (image, rows);
for (byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) {
uint8_t output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
_cairo_output_stream_printf (stream, "%02x ", output_byte);
@@ -2116,7 +2117,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface,
i = 0;
for (y = 0; y < image->height; y++) {
/* mask row */
- pixel = (uint32_t *) (image->data + y * image->stride);
+ pixel = (uint32_t *) cairo_image_surface_get_data_for_row (image, y);
bit = 7;
for (x = 0; x < image->width; x++, pixel++) {
if (bit == 7)
@@ -2133,7 +2134,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface,
i++;
/* image row*/
- pixel = (uint32_t *) (image->data + y * image->stride);
+ pixel = (uint32_t *) cairo_image_surface_get_data_for_row (image, y);
for (x = 0; x < image->width; x++, pixel++) {
data[i++] = (*pixel & 0x00ff0000) >> 16;
data[i++] = (*pixel & 0x0000ff00) >> 8;
@@ -2143,7 +2144,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t *surface,
} else {
i = 0;
for (y = 0; y < opaque_image->height; y++) {
- pixel = (uint32_t *) (opaque_image->data + y * opaque_image->stride);
+ pixel = (uint32_t *) cairo_image_surface_get_data_for_row (opaque_image, y);
for (x = 0; x < opaque_image->width; x++, pixel++) {
data[i++] = (*pixel & 0x00ff0000) >> 16;
data[i++] = (*pixel & 0x0000ff00) >> 8;
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 861c0ab0..f7371f07 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -2300,12 +2300,13 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
double tx, double ty)
{
const uint8_t *row;
- int rows, cols, bytes_per_row;
+ int cols, bytes_per_row;
int x, y, bit;
double xoff, yoff;
cairo_fixed_t x0, y0;
cairo_fixed_t px, py;
cairo_status_t status;
+ unsigned int stride;
mask = _cairo_image_surface_coerce_to_format (mask, CAIRO_FORMAT_A1);
status = mask->base.status;
@@ -2317,9 +2318,10 @@ _trace_mask_to_path (cairo_image_surface_t *mask,
y0 = _cairo_fixed_from_double (ty - yoff);
bytes_per_row = (mask->width + 7) / 8;
- row = mask->data;
- for (y = 0, rows = mask->height; rows--; row += mask->stride, y++) {
- const uint8_t *byte_ptr = row;
+ row = (uint8_t *) pixman_image_get_data (mask->pixman_image);
+ stride = pixman_image_get_stride (mask->pixman_image);
+ for (y = 0; y < mask->height; y++) {
+ const uint8_t *byte_ptr = cairo_image_surface_get_data_for_row (mask, y);
x = 0;
py = _cairo_fixed_from_int (y);
for (cols = bytes_per_row; cols--; ) {
diff --git a/src/cairo-surface-subsurface.c b/src/cairo-surface-subsurface.c
index a4b345b0..0134fbd0 100644
--- a/src/cairo-surface-subsurface.c
+++ b/src/cairo-surface-subsurface.c
@@ -296,7 +296,7 @@ _cairo_surface_subsurface_acquire_source_image (void *abstrac
if (PIXMAN_FORMAT_BPP (extra->image->pixman_format) > 8) {
assert ((PIXMAN_FORMAT_BPP (extra->image->pixman_format) % 8) == 0);
- data = extra->image->data + surface->extents.y * extra->image->stride;
+ data = cairo_image_surface_get_data_for_row (extra->image, surface->extents.y);
data += PIXMAN_FORMAT_BPP (extra->image->pixman_format) / 8 * surface->extents.x;
image = (cairo_image_surface_t *)
@@ -304,7 +304,7 @@ _cairo_surface_subsurface_acquire_source_image (void *abstrac
extra->image->pixman_format,
surface->extents.width,
surface->extents.height,
- extra->image->stride);
+ pixman_image_get_stride (extra->image->pixman_image));
if (unlikely ((status = image->base.status)))
goto CLEANUP_IMAGE;
} else {
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 6ba3f314..a362addd 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -746,7 +746,7 @@ _cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t *document,
cairo_image_surface_t *image;
cairo_status_t status;
uint8_t *row, *byte;
- int rows, cols;
+ int cols;
int x, y, bit;
status = _cairo_scaled_glyph_lookup (scaled_font,
@@ -768,7 +768,8 @@ _cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t *document,
&image->base.device_transform_inverse, NULL);
_cairo_output_stream_printf (document->xml_node_glyphs, ">/n");
- for (y = 0, row = image->data, rows = image->height; rows; row += image->stride, rows--, y++) {
+ for (y = 0; y < image->height; y++) {
+ row = cairo_image_surface_get_data_for_row (image, y);
for (x = 0, byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) {
uint8_t output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
for (bit = 7; bit >= 0 && x < image->width; bit--, x++) {
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index f127a9c3..eea7baf0 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1104,8 +1104,8 @@ _draw_image_surface (cairo_xlib_surface_t *surface,
int ret;
ximage.bits_per_pixel = image_masks.bpp;
- ximage.bytes_per_line = image->stride;
- ximage.data = (char *)image->data;
+ ximage.bytes_per_line = pixman_image_get_stride (image->pixman_image);
+ ximage.data = (char *) pixman_image_get_data (image->pixman_image);
own_data = FALSE;
ret = XInitImage (&ximage);
@@ -1167,8 +1167,8 @@ _draw_image_surface (cairo_xlib_surface_t *surface,
goto BAIL;
}
- rowstride = image->stride >> 2;
- row = (uint32_t *) image->data;
+ rowstride = pixman_image_get_stride (image->pixman_image) >> 2;
+ row = pixman_image_get_data (image->pixman_image);
x0 = dst_x + surface->base.device_transform.x0;
y0 = dst_y + surface->base.device_transform.y0;
for (y = 0, y_off = y0 % ARRAY_LENGTH (dither_pattern);
@@ -4054,14 +4054,14 @@ _cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display,
glyph_info.xOff = scaled_glyph->x_advance;
glyph_info.yOff = scaled_glyph->y_advance;
- data = glyph_surface->data;
+ data = (unsigned char *) pixman_image_get_data (glyph_surface->pixman_image);
/* flip formats around */
switch (_cairo_xlib_get_glyphset_index_for_format (scaled_glyph->surface->format)) {
case GLYPHSET_INDEX_A1:
/* local bitmaps are always stored with bit == byte */
if (_native_byte_order_lsb() != (BitmapBitOrder (display->display) == LSBFirst)) {
- int c = glyph_surface->stride * glyph_surface->height;
+ int c = pixman_image_get_stride (glyph_surface->pixman_image) * glyph_surface->height;
unsigned char *d;
unsigned char *new, *n;
@@ -4086,7 +4086,7 @@ _cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display,
break;
case GLYPHSET_INDEX_ARGB32:
if (_native_byte_order_lsb() != (ImageByteOrder (display->display) == LSBFirst)) {
- unsigned int c = glyph_surface->stride * glyph_surface->height / 4;
+ unsigned int c = pixman_image_get_stride (glyph_surface->pixman_image) * glyph_surface->height / 4;
const uint32_t *d;
uint32_t *new, *n;
@@ -4113,9 +4113,9 @@ _cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display,
XRenderAddGlyphs (display->display, glyphset_info->glyphset,
&glyph_index, &glyph_info, 1,
(char *) data,
- glyph_surface->stride * glyph_surface->height);
+ pixman_image_get_stride (glyph_surface->pixman_image) * glyph_surface->height);
- if (data != glyph_surface->data)
+ if (data != (unsigned char *) pixman_image_get_data (glyph_surface->pixman_image))
free (data);
_cairo_xlib_scaled_glyph_set_glyphset_info (scaled_glyph, glyphset_info);
diff --git a/src/cairoint.h b/src/cairoint.h
index b4e8196a..9c886ec3 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -824,11 +824,9 @@ struct _cairo_image_surface {
pixman_format_code_t pixman_format;
cairo_format_t format;
- unsigned char *data;
int width;
int height;
- int stride;
int depth;
pixman_image_t *pixman_image;
@@ -2203,6 +2201,9 @@ _cairo_image_surface_create_with_content (cairo_content_t content,
cairo_private void
_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface);
+#define cairo_image_surface_get_data_for_row(image,y) \
+ (((uint8_t *) pixman_image_get_data ((image)->pixman_image)) + (y) * pixman_image_get_stride ((image)->pixman_image))
+
cairo_private cairo_image_surface_t *
_cairo_image_surface_coerce (cairo_image_surface_t *surface);