mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-03 18:40:18 +01:00
[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.
This commit is contained in:
parent
b181f40949
commit
06b375aee9
3 changed files with 12 additions and 6 deletions
|
|
@ -440,6 +440,7 @@ cairo_format_stride_for_width (cairo_format_t format,
|
|||
|
||||
return ((bpp*width+7)/8 + STRIDE_ALIGNMENT-1) & ~(STRIDE_ALIGNMENT-1);
|
||||
}
|
||||
slim_hidden_def (cairo_format_stride_for_width);
|
||||
|
||||
/**
|
||||
* cairo_image_surface_create_for_data:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -2244,6 +2244,7 @@ slim_hidden_proto (cairo_image_surface_create);
|
|||
slim_hidden_proto (cairo_image_surface_create_for_data);
|
||||
slim_hidden_proto (cairo_image_surface_get_height);
|
||||
slim_hidden_proto (cairo_image_surface_get_width);
|
||||
slim_hidden_proto (cairo_format_stride_for_width);
|
||||
slim_hidden_proto (cairo_line_to);
|
||||
slim_hidden_proto (cairo_mask);
|
||||
slim_hidden_proto (cairo_matrix_init);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue