mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-28 14:31:10 +00:00
7ef5dec32d
1999-10-20 Federico Mena Quintero <federico@redhat.com> * src/gdk-pixbuf.h (GdkPixbuf): Removed the unref_fn field. Now all memory management of the buffer is done by libart. * src/gdk-pixbuf.c (gdk_pixbuf_unref): Do destruction here. Removed gdk_pixbuf_destroy, gdk_pixbuf_duplicate. * src/gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Implemented in terms of the libart functions. Removed the old code. * src/gdk-pixbuf-io.c (image_handler_load): Removed the save symbols. Saving will not be implemented in GdkPixbuf. * src/io-gif.c: Removed the saving stub. (image_load): Fixed memory management to fail gracefully if we run out of memory while loading the image. Close the gif file when we are done. This still needs more error handling for the DGif functions. * src/io-jpeg.c (image_load): Some robustness fixes. * src/io-png.c: Removed the saving stuff. (image_load): Some memory management fixes. * src/io-tiff.c (image_load): Ditto. * src/io-xpm.c (pixbuf_create_from_xpm): Ditto.
101 lines
2.5 KiB
C
101 lines
2.5 KiB
C
/* GdkPixbuf library - JPEG image loader
|
||
*
|
||
* Copyright (C) 1999 Mark Crichton
|
||
* Copyright (C) 1999 The Free Software Foundation
|
||
*
|
||
* Authors: Mark Crichton <crichton@gimp.org>
|
||
* Federico Mena-Quintero <federico@gimp.org>
|
||
*
|
||
* This library is free software; you can redistribute it and/or
|
||
* modify it under the terms of the GNU Library General Public
|
||
* License as published by the Free Software Foundation; either
|
||
* version 2 of the License, or (at your option) any later version.
|
||
*
|
||
* This library is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
* Library General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU Library General Public
|
||
* License along with this library; if not, write to the
|
||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||
* Boston, MA 02111-1307, USA.
|
||
*/
|
||
|
||
/* Following code (almost) blatantly ripped from Imlib */
|
||
|
||
#include <config.h>
|
||
#include <stdio.h>
|
||
#include <tiffio.h>
|
||
#include "gdk-pixbuf.h"
|
||
|
||
|
||
|
||
/* Destroy notification function for the libart pixbuf */
|
||
static void
|
||
free_buffer (gpointer user_data, gpointer data)
|
||
{
|
||
free (data);
|
||
}
|
||
|
||
/* Shared library entry point */
|
||
GdkPixbuf *
|
||
image_load (FILE *f)
|
||
{
|
||
TIFF *tiff;
|
||
guchar *pixels, *tmppix;
|
||
gint w, h, x, y, num_pixs, fd;
|
||
uint32 *rast, *tmp_rast;
|
||
|
||
fd = fileno (f);
|
||
tiff = TIFFFdOpen (fd, "libpixbuf-tiff", "r");
|
||
|
||
if (!tiff)
|
||
return NULL;
|
||
|
||
TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &w);
|
||
TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &h);
|
||
num_pixs = w * h;
|
||
|
||
/* Yes, it needs to be _TIFFMalloc... */
|
||
rast = (uint32 *) _TIFFmalloc (num_pixs * sizeof (uint32));
|
||
|
||
if (!rast) {
|
||
TIFFClose (tiff);
|
||
return NULL;
|
||
}
|
||
|
||
if (TIFFReadRGBAImage (tiff, w, h, rast, 0)) {
|
||
pixels = malloc (num_pixs * 4);
|
||
if (!pixels) {
|
||
_TIFFfree (rast);
|
||
TIFFClose (tiff);
|
||
return NULL;
|
||
}
|
||
tmppix = pixels;
|
||
|
||
for (y = 0; y < h; y++) {
|
||
/* Unexplainable...are tiffs backwards? */
|
||
/* Also looking at the GIMP plugin, this
|
||
* whole reading thing can be a bit more
|
||
* robust.
|
||
*/
|
||
tmp_rast = rast + ((h - y - 1) * w);
|
||
for (x = 0; x < w; x++) {
|
||
tmppix[0] = TIFFGetR (*tmp_rast);
|
||
tmppix[1] = TIFFGetG (*tmp_rast);
|
||
tmppix[2] = TIFFGetB (*tmp_rast);
|
||
tmppix[3] = TIFFGetA (*tmp_rast);
|
||
tmp_rast++;
|
||
tmppix += 4;
|
||
}
|
||
}
|
||
}
|
||
_TIFFfree (rast);
|
||
TIFFClose (tiff);
|
||
|
||
return gdk_pixbuf_new_from_data (pixels, ART_PIX_RGB, TRUE,
|
||
w, h, w * 4,
|
||
free_buffer, NULL);
|
||
}
|