summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-jpeg.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@redhat.com>1999-10-20 21:20:49 +0000
committerArturo Espinosa <unammx@src.gnome.org>1999-10-20 21:20:49 +0000
commit7ef5dec32dac9e31f745b4e05deb8ee6fa10350c (patch)
tree8dfa010c18dfbb4d457d812cc266d572ac2e136c /gdk-pixbuf/io-jpeg.c
parent46da5c2bec71558218f654e26b70200993ecbbe4 (diff)
downloadgtk+-7ef5dec32dac9e31f745b4e05deb8ee6fa10350c.tar.gz
Removed the unref_fn field. Now all memory management of the buffer is
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.
Diffstat (limited to 'gdk-pixbuf/io-jpeg.c')
-rw-r--r--gdk-pixbuf/io-jpeg.c155
1 files changed, 85 insertions, 70 deletions
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c
index 448e8c4fd1..f35176a8cb 100644
--- a/gdk-pixbuf/io-jpeg.c
+++ b/gdk-pixbuf/io-jpeg.c
@@ -1,129 +1,144 @@
-/*
- io-jpeg.c: GdkPixbuf loader for jpeg files.
-
- Based on io-jpeg from gdk_imlib, but not much.
-
- This code is licensed under the Lesser GNU
- General Public License, version 2.1.
-
- Author:
- Michael Zucchi <zucchi@zedzone.mmc.com.au>
-*/
+/* GdkPixbuf library - JPEG image loader
+ *
+ * Copyright (C) 1999 Michael Zucchi
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Michael Zucchi <zucchi@zedzone.mmc.com.au>
+ * 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.
+ */
#include <config.h>
#include <stdio.h>
-#include <glib.h>
#include <setjmp.h>
-#include "gdk-pixbuf.h"
-/*#include "gdk-pixbuf-io.h"*/
#include <jpeglib.h>
+#include "gdk-pixbuf.h"
+
+
/* error handler data */
-struct iojpeg_JPEG_error_mgr {
+struct error_handler_data {
struct jpeg_error_mgr pub;
sigjmp_buf setjmp_buffer;
};
static void
-g_JPEGFatalErrorHandler(j_common_ptr cinfo)
+fatal_error_handler (j_common_ptr cinfo)
{
/* FIXME:
* We should somehow signal what error occurred to the caller so the
* caller can handle the error message */
- struct iojpeg_JPEG_error_mgr *errmgr;
+ struct error_handler_data *errmgr;
- errmgr = (struct iojpeg_JPEG_error_mgr *) cinfo->err;
- cinfo->err->output_message(cinfo);
- siglongjmp(errmgr->setjmp_buffer, 1);
+ errmgr = (struct error_handler_data *) cinfo->err;
+ cinfo->err->output_message (cinfo);
+ siglongjmp (errmgr->setjmp_buffer, 1);
return;
}
+/* 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)
+image_load (FILE *f)
{
- int w,h,i,j;
- art_u8 *pixels=NULL, *dptr;
- unsigned char *lines[4], /* Used to expand rows, via rec_outbuf_height, from
- the header file:
- "* Usually rec_outbuf_height will be 1 or 2, at most 4." */
- **lptr;
+ int w, h, i, j;
+ guchar *pixels = NULL, *dptr;
+ guchar *lines[4]; /* Used to expand rows, via rec_outbuf_height, from the header file:
+ * "* Usually rec_outbuf_height will be 1 or 2, at most 4."
+ */
+ guchar **lptr;
struct jpeg_decompress_struct cinfo;
- struct iojpeg_JPEG_error_mgr jerr;
+ struct error_handler_data jerr;
GdkPixbuf *pixbuf;
/* setup error handler */
- cinfo.err = jpeg_std_error(&(jerr.pub));
- jerr.pub.error_exit = g_JPEGFatalErrorHandler;
+ cinfo.err = jpeg_std_error (&jerr.pub);
+ jerr.pub.error_exit = fatal_error_handler;
- if (sigsetjmp(jerr.setjmp_buffer, 1)) {
+ if (sigsetjmp (jerr.setjmp_buffer, 1)) {
/* Whoops there was a jpeg error */
- if (pixels != NULL)
- art_free(pixels);
- jpeg_destroy_decompress(&cinfo);
+ if (pixels)
+ free (pixels);
+
+ jpeg_destroy_decompress (&cinfo);
return NULL;
}
/* load header, setup */
- jpeg_create_decompress(&cinfo);
- jpeg_stdio_src(&cinfo, f);
- jpeg_read_header(&cinfo, TRUE);
- jpeg_start_decompress(&cinfo);
+ jpeg_create_decompress (&cinfo);
+ jpeg_stdio_src (&cinfo, f);
+ jpeg_read_header (&cinfo, TRUE);
+ jpeg_start_decompress (&cinfo);
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
w = cinfo.output_width;
h = cinfo.output_height;
- g_print("w: %d h: %d\n", w, h);
- pixels = art_alloc(h * w * 3);
- if (pixels == NULL) {
- jpeg_destroy_decompress(&cinfo);
+ pixels = malloc (h * w * 3);
+ if (!pixels) {
+ jpeg_destroy_decompress (&cinfo);
return NULL;
}
+
dptr = pixels;
/* decompress all the lines, a few at a time */
while (cinfo.output_scanline < cinfo.output_height) {
lptr = lines;
- for (i=0;i<cinfo.rec_outbuf_height;i++) {
- *lptr++=dptr;
- dptr+=w*3;
+ for (i = 0; i < cinfo.rec_outbuf_height; i++) {
+ *lptr++ = dptr;
+ dptr += w * 3;
}
- jpeg_read_scanlines(&cinfo, lines, cinfo.rec_outbuf_height);
- if (cinfo.output_components==1) {
- /* expand grey->colour */
- /* expand from the end of the memory down, so we can use
- the same buffer */
- for (i=cinfo.rec_outbuf_height-1;i>=0;i--) {
- unsigned char *from, *to;
- from = lines[i]+w-1;
- to = lines[i]+w*3-3;
- for (j=w-1;j>=0;j--) {
+
+ jpeg_read_scanlines (&cinfo, lines, cinfo.rec_outbuf_height);
+ if (cinfo.output_components == 1) {
+ /* Expand grey->colour. Expand from the end of the
+ * memory down, so we can use the same buffer.
+ */
+ for (i = cinfo.rec_outbuf_height - 1; i >= 0; i--) {
+ guchar *from, *to;
+
+ from = lines[i] + w - 1;
+ to = lines[i] + w * 3 - 3;
+ for (j = w - 1; j >= 0; j--) {
to[0] = from[0];
to[1] = from[0];
to[2] = from[0];
- to-=3;
+ to -= 3;
from--;
}
}
}
}
- jpeg_finish_decompress(&cinfo);
- jpeg_destroy_decompress(&cinfo);
+ jpeg_finish_decompress (&cinfo);
+ jpeg_destroy_decompress (&cinfo);
+
+ return gdk_pixbuf_new_from_data (pixels, ART_PIX_RGB, FALSE,
+ w, h, w * 3,
+ free_buffer, NULL);
- /* finish off, create the pixbuf */
- pixbuf = gdk_pixbuf_new (art_pixbuf_new_rgb (pixels, w, h, (w * 3)),
- NULL);
- if (!pixbuf)
- art_free (pixels);
-
return pixbuf;
}
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */