]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/io-jpeg.c
Fix comments to not claim that all three of these files are the JPEG image
[~andy/gtk] / gdk-pixbuf / io-jpeg.c
index 0845a3dc3ca17710e5926b23935cb3b73481f80a..06deb42f6cd2188467f5cb2e965bc7f36f4d6e51 100644 (file)
  *          Michael Fulbright <drmike@redhat.com>
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser 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.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser 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 <string.h>
 #include <setjmp.h>
 #include <jpeglib.h>
-#include "gdk-pixbuf.h"
+#include "gdk-pixbuf-private.h"
 #include "gdk-pixbuf-io.h"
 
+#ifndef HAVE_SIGSETJMP
+#define sigjmp_buf jmp_buf
+#define sigsetjmp(jb, x) setjmp(jb)
+#define siglongjmp longjmp
+#endif
 \f
 
 /* we are a "source manager" as far as libjpeg is concerned */
@@ -108,14 +113,16 @@ fatal_error_handler (j_common_ptr cinfo)
        errmgr = (struct error_handler_data *) cinfo->err;
        cinfo->err->output_message (cinfo);
        siglongjmp (errmgr->setjmp_buffer, 1);
-       return;
+
+       /* incase the jmp buf isn't initted? */
+       exit(1);
 }
 
-/* Destroy notification function for the libart pixbuf */
+/* Destroy notification function for the pixbuf */
 static void
-free_buffer (gpointer user_data, gpointer data)
+free_buffer (guchar *pixels, gpointer data)
 {
-       free (data);
+       free (pixels);
 }
 
 
@@ -215,7 +222,7 @@ gdk_pixbuf__jpeg_image_load (FILE *f)
        jpeg_finish_decompress (&cinfo);
        jpeg_destroy_decompress (&cinfo);
 
-       return gdk_pixbuf_new_from_data (pixels, ART_PIX_RGB, FALSE,
+       return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE, 8,
                                         w, h, w * 3,
                                         free_buffer, NULL);
 }
@@ -300,6 +307,7 @@ gdk_pixbuf__jpeg_image_begin_load (ModulePreparedNotifyFunc prepared_func,
        src = (my_src_ptr) context->cinfo.src;
 
        context->cinfo.err = jpeg_std_error (&context->jerr.pub);
+       context->jerr.pub.error_exit = fatal_error_handler;
 
        src = (my_src_ptr) context->cinfo.src;
        src->pub.init_source = init_source;
@@ -328,8 +336,13 @@ gdk_pixbuf__jpeg_image_stop_load (gpointer data)
        if (context->pixbuf)
                gdk_pixbuf_unref (context->pixbuf);
 
-       jpeg_finish_decompress(&context->cinfo);
-       jpeg_destroy_decompress(&context->cinfo);
+       /* if we have an error? */
+       if (sigsetjmp (context->jerr.setjmp_buffer, 1)) {
+               jpeg_destroy_decompress (&context->cinfo);
+       } else {
+               jpeg_finish_decompress(&context->cinfo);
+               jpeg_destroy_decompress(&context->cinfo);
+       }
 
        if (context->cinfo.src) {
                my_src_ptr src = (my_src_ptr) context->cinfo.src;
@@ -373,6 +386,10 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data, guchar *buf, guint size)
          *                    have a grasp of what the flow needs to be!
          */
 
+       /* check for fatal error */
+       if (sigsetjmp (context->jerr.setjmp_buffer, 1)) {
+               return FALSE;
+       }
 
        /* skip over data if requested, handle unsigned int sizes cleanly */
        /* only can happen if we've already called jpeg_get_header once   */
@@ -451,8 +468,8 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data, guchar *buf, guint size)
                                return FALSE;
                        }
 #endif
-                       context->pixbuf = gdk_pixbuf_new(ART_PIX_RGB, 
-                                                        /*have_alpha*/ FALSE,
+                       context->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
+                                                        FALSE,
                                                         8, 
                                                         cinfo->image_width,
                                                         cinfo->image_height);
@@ -463,7 +480,7 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data, guchar *buf, guint size)
                        }
 
                        /* Use pixbuf buffer to store decompressed data */
-                       context->dptr = context->pixbuf->art_pixbuf->pixels;
+                       context->dptr = context->pixbuf->pixels;
 
                        /* Notify the client that we are ready to go */
                        (* context->prepared_func) (context->pixbuf,
@@ -497,7 +514,7 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data, guchar *buf, guint size)
                                rowptr = context->dptr;
                                for (i=0; i < cinfo->rec_outbuf_height; i++) {
                                        *lptr++ = rowptr;
-                                       rowptr += context->pixbuf->art_pixbuf->rowstride;
+                                       rowptr += context->pixbuf->rowstride;
                                }
 
                                nlines = jpeg_read_scanlines (cinfo, lines,
@@ -509,7 +526,7 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data, guchar *buf, guint size)
                                if (cinfo->output_components == 1)
                                        explode_gray_into_buf (cinfo, lines);
 
-                               context->dptr += nlines * context->pixbuf->art_pixbuf->rowstride;
+                               context->dptr += nlines * context->pixbuf->rowstride;
 
                                /* send updated signal */
                                (* context->updated_func) (context->pixbuf,