diff options
author | Federico Mena Quintero <federico@redhat.com> | 1999-10-22 15:18:03 +0000 |
---|---|---|
committer | Arturo Espinosa <unammx@src.gnome.org> | 1999-10-22 15:18:03 +0000 |
commit | 9de0d0c9c308ce9f212387317312e480f1468369 (patch) | |
tree | e3ba3f178e9f0d2ca2d749333f64a73a248d62a4 | |
parent | 04823f40c43c3db621c66d25b17113faa7f1fbf3 (diff) | |
download | gtk+-9de0d0c9c308ce9f212387317312e480f1468369.tar.gz |
Patch from Kristian Hogsberg Kristensen <hogsberg@daimi.au.dk> to avoid
1999-10-22 Federico Mena Quintero <federico@redhat.com>
* src/io-png.c (image_load): Patch from Kristian Hogsberg
Kristensen <hogsberg@daimi.au.dk> to avoid allocating extra row
buffers; the rows can be read in directly into the main pixel
buffer.
-rw-r--r-- | gdk-pixbuf/ChangeLog | 7 | ||||
-rw-r--r-- | gdk-pixbuf/io-png.c | 52 |
2 files changed, 14 insertions, 45 deletions
diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index b9b56060b2..205f992518 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,10 @@ +1999-10-22 Federico Mena Quintero <federico@redhat.com> + + * src/io-png.c (image_load): Patch from Kristian Hogsberg + Kristensen <hogsberg@daimi.au.dk> to avoid allocating extra row + buffers; the rows can be read in directly into the main pixel + buffer. + 1999-10-20 Federico Mena Quintero <federico@redhat.com> * src/gdk-pixbuf-io.c (image_handler_load): Free path. diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c index 733a505826..75a31f6f16 100644 --- a/gdk-pixbuf/io-png.c +++ b/gdk-pixbuf/io-png.c @@ -43,9 +43,9 @@ image_load (FILE *f) png_structp png_ptr; png_infop info_ptr, end_info; gint i, depth, ctype, inttype, passes, bpp; - png_uint_32 w, h, x, y; + png_uint_32 w, h; png_bytepp rows; - guchar *pixels, *temp, *rowdata; + guchar *pixels; png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) @@ -114,57 +114,19 @@ image_load (FILE *f) bpp = 3; pixels = malloc (w * h * bpp); - rows = malloc (h * sizeof (png_bytep)); - - if (!pixels || !rows) { - if (pixels) - free (pixels); - - if (rows) - free (rows); - + if (!pixels) { png_destroy_read_struct (&png_ptr, &info_ptr, &end_info); return NULL; } - /* Icky code, but it has to be done... */ - for (i = 0; i < h; i++) { - if ((rows[i] = malloc (w * bpp)) == NULL) { - int n; + rows = g_new (png_bytep, h); - for (n = 0; n < i; n++) - free (rows[i]); + for (i = 0; i < h; i++) + rows[i] = pixels + i * w * bpp; - free (rows); - free (pixels); - png_destroy_read_struct (&png_ptr, &info_ptr, &end_info); - return NULL; - } - } - - /* And we FINALLY get here... */ png_read_image (png_ptr, rows); png_destroy_read_struct (&png_ptr, &info_ptr, &end_info); - - /* Now stuff the bytes into pixels & free rows[y] */ - - temp = pixels; - - for (y = 0; y < h; y++) { - rowdata = rows[y]; - for (x = 0; x < w; x++) { - temp[0] = rowdata[(x * bpp)]; - temp[1] = rowdata[(x * bpp) + 1]; - temp[2] = rowdata[(x * bpp) + 2]; - - if (bpp == 4) - temp[3] = rowdata[(x * bpp) + 3]; - - temp += bpp; - } - free (rows[y]); - } - free (rows); + g_free (rows); if (ctype & PNG_COLOR_MASK_ALPHA) return gdk_pixbuf_new_from_data (pixels, ART_PIX_RGB, TRUE, |