]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/io-jpeg.c
[quartz] Delete the typedef of GdkDevicePrivate
[~andy/gtk] / gdk-pixbuf / io-jpeg.c
index 2e25871f036a69c5ce4f13cae75593b77dde8ebc..cc1db97e6d0fab5978a2994adf4afeaefaa66f9c 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 
-#include <config.h>
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -468,7 +468,6 @@ gdk_pixbuf__jpeg_image_load (FILE *f, GError **error)
        cinfo.err = jpeg_std_error (&jerr.pub);
        jerr.pub.error_exit = fatal_error_handler;
         jerr.pub.output_message = output_message_handler;
-
         jerr.error = error;
         
        if (sigsetjmp (jerr.setjmp_buffer, 1)) {
@@ -523,10 +522,10 @@ gdk_pixbuf__jpeg_image_load (FILE *f, GError **error)
                  * crappy JPEG library
                  */
                 if (error && *error == NULL) {
-                        g_set_error (error,
-                                     GDK_PIXBUF_ERROR,
-                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                                     _("Insufficient memory to load image, try exiting some applications to free memory"));
+                        g_set_error_literal (error,
+                                             GDK_PIXBUF_ERROR,
+                                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                             _("Insufficient memory to load image, try exiting some applications to free memory"));
                 }
                 
                return NULL;
@@ -657,26 +656,26 @@ gdk_pixbuf__jpeg_image_begin_load (GdkPixbufModuleSizeFunc size_func,
        context->src_initialized = FALSE;
        context->in_output = FALSE;
 
+        /* From jpeglib.h: "NB: you must set up the error-manager
+         * BEFORE calling jpeg_create_xxx". */
+       context->cinfo.err = jpeg_std_error (&context->jerr.pub);
+       context->jerr.pub.error_exit = fatal_error_handler;
+        context->jerr.pub.output_message = output_message_handler;
+        context->jerr.error = error;
+
        /* create libjpeg structures */
        jpeg_create_decompress (&context->cinfo);
 
        context->cinfo.src = (struct jpeg_source_mgr *) g_try_malloc (sizeof (my_source_mgr));
        if (!context->cinfo.src) {
-               g_set_error (error,
-                            GDK_PIXBUF_ERROR,
-                            GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                            _("Couldn't allocate memory for loading JPEG file"));
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Couldn't allocate memory for loading JPEG file"));
                return NULL;
        }
        memset (context->cinfo.src, 0, sizeof (my_source_mgr));
-       
-       src = (my_src_ptr) context->cinfo.src;
 
-       context->cinfo.err = jpeg_std_error (&context->jerr.pub);
-       context->jerr.pub.error_exit = fatal_error_handler;
-        context->jerr.pub.output_message = output_message_handler;
-        context->jerr.error = error;
-        
        src = (my_src_ptr) context->cinfo.src;
        src->pub.init_source = init_source;
        src->pub.fill_input_buffer = fill_input_buffer;
@@ -914,14 +913,15 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
                        if (context->size_func) {
                                (* context->size_func) (&width, &height, context->user_data);
                                if (width == 0 || height == 0) {
-                                       g_set_error (error,
-                                                    GDK_PIXBUF_ERROR,
-                                                    GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                                                    _("Transformed JPEG has zero width or height."));
+                                       g_set_error_literal (error,
+                                                             GDK_PIXBUF_ERROR,
+                                                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                                             _("Transformed JPEG has zero width or height."));
                                        return FALSE;
                                }
                        }
                        
+                       cinfo->scale_num = 1;
                        for (cinfo->scale_denom = 2; cinfo->scale_denom <= 8; cinfo->scale_denom *= 2) {
                                jpeg_calc_output_dimensions (cinfo);
                                if (cinfo->output_width < width || cinfo->output_height < height) {
@@ -938,10 +938,10 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
                                                          cinfo->output_height);
 
                        if (context->pixbuf == NULL) {
-                                g_set_error (error,
-                                             GDK_PIXBUF_ERROR,
-                                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                                             _("Couldn't allocate memory for loading JPEG file"));
+                                g_set_error_literal (error,
+                                                     GDK_PIXBUF_ERROR,
+                                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                                     _("Couldn't allocate memory for loading JPEG file"));
                                 return FALSE;
                        }
                
@@ -1047,7 +1047,7 @@ to_callback_do_write (j_compress_ptr cinfo, gsize length)
        ToFunctionDestinationManager *destmgr;
 
        destmgr = (ToFunctionDestinationManager*) cinfo->dest;
-        if (!destmgr->save_func (destmgr->buffer,
+        if (!destmgr->save_func ((gchar *)destmgr->buffer,
                                 length,
                                 destmgr->error,
                                 destmgr->user_data)) {
@@ -1058,10 +1058,10 @@ to_callback_do_write (j_compress_ptr cinfo, gsize length)
                 * which it should have.
                 */
                if (errmgr->error && *errmgr->error == NULL) {
-                       g_set_error (errmgr->error,
-                                    GDK_PIXBUF_ERROR,
-                                    GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                                    "write function failed");
+                       g_set_error_literal (errmgr->error,
+                                             GDK_PIXBUF_ERROR,
+                                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                             "write function failed");
                }
                siglongjmp (errmgr->setjmp_buffer, 1);
                g_assert_not_reached ();
@@ -1171,29 +1171,30 @@ real_save_jpeg (GdkPixbuf          *pixbuf,
        */
        buf = g_try_malloc (w * 3 * sizeof (guchar));
        if (!buf) {
-              g_set_error (error,
-                           GDK_PIXBUF_ERROR,
-                           GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                           _("Couldn't allocate memory for loading JPEG file"));
+              g_set_error_literal (error,
+                                    GDK_PIXBUF_ERROR,
+                                    GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                    _("Couldn't allocate memory for loading JPEG file"));
               return FALSE;
        }
        if (to_callback) {
               to_callback_destmgr.buffer = g_try_malloc (TO_FUNCTION_BUF_SIZE);
               if (!to_callback_destmgr.buffer) {
-                      g_set_error (error,
-                                   GDK_PIXBUF_ERROR,
-                                   GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                                   _("Couldn't allocate memory for loading JPEG file"));
+                      g_set_error_literal (error,
+                                            GDK_PIXBUF_ERROR,
+                                            GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                            _("Couldn't allocate memory for loading JPEG file"));
+                       g_free (buf);
                       return FALSE;
               }
        }
 
        /* set up error handling */
+       cinfo.err = jpeg_std_error (&(jerr.pub));
        jerr.pub.error_exit = fatal_error_handler;
        jerr.pub.output_message = output_message_handler;
        jerr.error = error;
        
-       cinfo.err = jpeg_std_error (&(jerr.pub));
        if (sigsetjmp (jerr.setjmp_buffer, 1)) {
                jpeg_destroy_compress (&cinfo);
                g_free (buf);