mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-21 06:20:33 +01:00
Rewrite to use cairo_image_surface_create_from_png rather than custom read_png_argb32. In addition to being simpler, this eliminates the leak of the image data buffer.
Add calls to cairo_pattern_destroy to close two memory leaks.
This commit is contained in:
parent
d8500060a9
commit
40edca337e
3 changed files with 20 additions and 11 deletions
10
ChangeLog
10
ChangeLog
|
|
@ -1,3 +1,13 @@
|
|||
2005-07-14 Carl Worth <cworth@cworth.org>
|
||||
|
||||
* test/cairo-test.c: (cairo_test_create_png_pattern): Rewrite to
|
||||
use cairo_image_surface_create_from_png rather than custom
|
||||
read_png_argb32. In addition to being simpler, this eliminates the
|
||||
leak of the image data buffer.
|
||||
|
||||
* test/trap-clip.c: (set_gradient_pattern), (set_image_pattern):
|
||||
Add calls to cairo_pattern_destroy to close two memory leaks.
|
||||
|
||||
2005-07-14 Carl Worth <cworth@cworth.org>
|
||||
|
||||
* src/cairo-pattern.c: (_cairo_pattern_acquire_surfaces): Fix up
|
||||
|
|
|
|||
|
|
@ -583,28 +583,25 @@ cairo_test_create_png_pattern (cairo_t *cr, const char *filename)
|
|||
{
|
||||
cairo_surface_t *image;
|
||||
cairo_pattern_t *pattern;
|
||||
unsigned char *buffer;
|
||||
unsigned int w, h, stride;
|
||||
read_png_status_t status;
|
||||
char *srcdir = getenv ("srcdir");
|
||||
|
||||
status = read_png_argb32 (filename, &buffer, &w,&h, &stride);
|
||||
if (status != READ_PNG_SUCCESS) {
|
||||
image = cairo_image_surface_create_from_png (filename);
|
||||
if (image == NULL) {
|
||||
if (srcdir) {
|
||||
char *srcdir_filename;
|
||||
xasprintf (&srcdir_filename, "%s/%s", srcdir, filename);
|
||||
status = read_png_argb32 (srcdir_filename, &buffer, &w,&h, &stride);
|
||||
image = cairo_image_surface_create_from_png (srcdir_filename);
|
||||
free (srcdir_filename);
|
||||
}
|
||||
if (image == NULL)
|
||||
return NULL;
|
||||
}
|
||||
if (status != READ_PNG_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_ARGB32,
|
||||
w, h, stride);
|
||||
|
||||
pattern = cairo_pattern_create_for_surface (image);
|
||||
|
||||
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
||||
|
||||
cairo_surface_destroy (image);
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ set_gradient_pattern (cairo_t *cr, int x, int y)
|
|||
cairo_pattern_add_color_stop_rgba (pattern, 0, 1, 1, 1, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 1, 0, 0, 0.4, 1);
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_pattern_destroy (pattern);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -64,6 +65,7 @@ set_image_pattern (cairo_t *cr, int x, int y)
|
|||
|
||||
pattern = cairo_test_create_png_pattern (cr, png_filename);
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_pattern_destroy (pattern);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue