summaryrefslogtreecommitdiff
path: root/src/cairo-png.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-02-29 11:55:01 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-03-04 09:31:21 +0000
commit06b375aee999220ce294c22fa50a3040c19d5492 (patch)
tree42ad8d5ca769e69c6d154a7218613b9b710efcd4 /src/cairo-png.c
parentb181f40949a855c957dc6e7a1033981a2ed7d05a (diff)
[cairo-png] Use cairo_format_stride_for_width()
Use cairo_format_stride_for_width() instead of assuming the pixel size and manually calculating the row stride. This should make it easier to support loading multiple image formats in future.
Diffstat (limited to 'src/cairo-png.c')
-rw-r--r--src/cairo-png.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/cairo-png.c b/src/cairo-png.c
index 10306184..de09086a 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -399,10 +399,9 @@ read_png (png_rw_ptr read_func,
png_info *info;
png_byte *data = NULL;
png_byte **row_pointers = NULL;
- png_uint_32 png_width, png_height, stride;
- int depth, color_type, interlace;
+ png_uint_32 png_width, png_height;
+ int depth, color_type, interlace, stride;
unsigned int i;
- unsigned int pixel_size;
cairo_status_t status;
/* XXX: Perhaps we'll want some other error handlers? */
@@ -476,8 +475,13 @@ read_png (png_rw_ptr read_func,
png_read_update_info (png, info);
- pixel_size = 4;
- data = _cairo_malloc_abc (png_height, png_width, pixel_size);
+ stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, png_width);
+ if (stride < 0) {
+ surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
+ goto BAIL;
+ }
+
+ data = _cairo_malloc_ab (png_height, stride);
if (data == NULL) {
surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
goto BAIL;
@@ -490,7 +494,7 @@ read_png (png_rw_ptr read_func,
}
for (i = 0; i < png_height; i++)
- row_pointers[i] = &data[i * png_width * pixel_size];
+ row_pointers[i] = &data[i * stride];
png_read_image (png, row_pointers);
png_read_end (png, info);