]> Pileus Git - ~andy/gtk/commitdiff
new utility function which factors out massive code duplication from the
authorMichael Natterer <mitch@imendio.com>
Wed, 14 Dec 2005 13:58:02 +0000 (13:58 +0000)
committerMichael Natterer <mitch@src.gnome.org>
Wed, 14 Dec 2005 13:58:02 +0000 (13:58 +0000)
2005-12-14  Michael Natterer  <mitch@imendio.com>

* gdk-pixbuf/io-jpeg.c (gdk_pixbuf__jpeg_image_load_lines): new
utility function which factors out massive code duplication from
the commit below.

ChangeLog
ChangeLog.pre-2-10
gdk-pixbuf/io-jpeg.c

index 6e268032884cf9eb42a603a59b852b06a4d03f7f..5c719d77d8cbc19f226cd465f79682ddfb9c3809 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-12-14  Michael Natterer  <mitch@imendio.com>
+
+       * gdk-pixbuf/io-jpeg.c (gdk_pixbuf__jpeg_image_load_lines): new
+       utility function which factors out massive code duplication from
+       the commit below.
+
 2005-12-14  Michael Natterer  <mitch@imendio.com>
 
        * gdk-pixbuf/io-jpeg.c: applied patch from maemo-gtk which avoids
index 6e268032884cf9eb42a603a59b852b06a4d03f7f..5c719d77d8cbc19f226cd465f79682ddfb9c3809 100644 (file)
@@ -1,3 +1,9 @@
+2005-12-14  Michael Natterer  <mitch@imendio.com>
+
+       * gdk-pixbuf/io-jpeg.c (gdk_pixbuf__jpeg_image_load_lines): new
+       utility function which factors out massive code duplication from
+       the commit below.
+
 2005-12-14  Michael Natterer  <mitch@imendio.com>
 
        * gdk-pixbuf/io-jpeg.c: applied patch from maemo-gtk which avoids
index 9c3c064f931fd575a7a6bca4f427ab460d39670c..84376d51ba9761f26dc3f2730a1e75d63439a545 100644 (file)
@@ -546,6 +546,65 @@ gdk_pixbuf__jpeg_image_stop_load (gpointer data, GError **error)
 }
 
 
+static gboolean
+gdk_pixbuf__jpeg_image_load_lines (JpegProgContext  *context,
+                                   GError          **error)
+{
+        struct jpeg_decompress_struct *cinfo = &context->cinfo;
+        guchar *lines[4];
+        guchar **lptr;
+        guchar *rowptr;
+        gint   nlines, i;
+
+        /* keep going until we've done all scanlines */
+        while (cinfo->output_scanline < cinfo->output_height) {
+                lptr = lines;
+                rowptr = context->dptr;
+                for (i=0; i < cinfo->rec_outbuf_height; i++) {
+                        *lptr++ = rowptr;
+                        rowptr += context->pixbuf->rowstride;
+                }
+
+                nlines = jpeg_read_scanlines (cinfo, lines,
+                                              cinfo->rec_outbuf_height);
+                if (nlines == 0)
+                        break;
+
+                switch (cinfo->out_color_space) {
+                case JCS_GRAYSCALE:
+                        explode_gray_into_buf (cinfo, lines);
+                        break;
+                case JCS_RGB:
+                        /* do nothing */
+                        break;
+                case JCS_CMYK:
+                        convert_cmyk_to_rgb (cinfo, lines);
+                        break;
+                default:
+                        if (error && *error == NULL) {
+                                g_set_error (error,
+                                             GDK_PIXBUF_ERROR,
+                                             GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
+                                             _("Unsupported JPEG color space (%s)"),
+                                             colorspace_name (cinfo->out_color_space));
+                        }
+
+                        return FALSE;
+                }
+
+                context->dptr += nlines * context->pixbuf->rowstride;
+
+                /* send updated signal */
+                (* context->updated_func) (context->pixbuf,
+                                           0,
+                                           cinfo->output_scanline - 1,
+                                           cinfo->image_width,
+                                           nlines,
+                                           context->user_data);
+        }
+
+        return TRUE;
+}
 
 
 /*
@@ -705,75 +764,18 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
                        context->did_prescan = TRUE;
                } else if (!cinfo->buffered_image) {
                         /* we're decompressing unbuffered so
-                         * get scanline by scanline from jpeg lib
-                         *
-                         * except for handling multiple passes this is
-                         * virtually identical to the next branch
+                         * simply get scanline by scanline from jpeg lib
                          */
-                       guchar *lines[4];
-                       guchar **lptr;
-                       guchar *rowptr;
-                       gint   nlines, i;
-
-                       /* keep going until we've done all scanlines */
-                       while (cinfo->output_scanline < cinfo->output_height) {
-                               lptr = lines;
-                               rowptr = context->dptr;
-                               for (i=0; i < cinfo->rec_outbuf_height; i++) {
-                                       *lptr++ = rowptr;
-                                       rowptr += context->pixbuf->rowstride;
-                               }
-
-                               nlines = jpeg_read_scanlines (cinfo, lines,
-                                                             cinfo->rec_outbuf_height);
-                               if (nlines == 0)
-                                       break;
-
-                               switch (cinfo->out_color_space) {
-                                   case JCS_GRAYSCALE:
-                                           explode_gray_into_buf (cinfo, lines);
-                                           break;
-                                   case JCS_RGB:
-                                           /* do nothing */
-                                           break;
-                                   case JCS_CMYK:
-                                           convert_cmyk_to_rgb (cinfo, lines);
-                                           break;
-                                   default:
-                                           if (error && *error == NULL) {
-                                                   g_set_error (error,
-                                                                GDK_PIXBUF_ERROR,
-                                                                GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
-                                                                _("Unsupported JPEG color space (%s)"),
-                                                                colorspace_name (cinfo->out_color_space));
-                                           }
-
-                                           return FALSE;
-                               }
-
-                               context->dptr += nlines * context->pixbuf->rowstride;
-
-                               /* send updated signal */
-                               (* context->updated_func) (context->pixbuf,
-                                                          0,
-                                                          cinfo->output_scanline-1,
-                                                          cinfo->image_width,
-                                                          nlines,
-                                                          context->user_data);
-                       }
+                        if (! gdk_pixbuf__jpeg_image_load_lines (context,
+                                                                 error))
+                                return FALSE;
 
                        if (cinfo->output_scanline >= cinfo->output_height)
                                return TRUE;
                } else {
-                        /* we're decompressing so feed jpeg lib scanlines
-                         *
-                         * except for handling multiple passes this is
-                         * virtually identical to the previous branch
+                        /* we're decompressing buffered (progressive)
+                         * so feed jpeg lib scanlines
                          */
-                       guchar *lines[4];
-                       guchar **lptr;
-                       guchar *rowptr;
-                       gint   nlines, i;
 
                        /* keep going until we've done all passes */
                        while (!jpeg_input_complete (cinfo)) {
@@ -785,53 +787,13 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
                                        else
                                                break;
                                }
-                               /* keep going until we've done all scanlines */
-                               while (cinfo->output_scanline < cinfo->output_height) {
-                                       lptr = lines;
-                                       rowptr = context->dptr;
-                                       for (i=0; i < cinfo->rec_outbuf_height; i++) {
-                                               *lptr++ = rowptr;
-                                               rowptr += context->pixbuf->rowstride;
-                                       }
-                                       
-                                       nlines = jpeg_read_scanlines (cinfo, lines,
-                                                                     cinfo->rec_outbuf_height);
-                                       if (nlines == 0)
-                                               break;
 
-                                       switch (cinfo->out_color_space) {
-                                           case JCS_GRAYSCALE:
-                                                   explode_gray_into_buf (cinfo, lines);
-                                                   break;
-                                           case JCS_RGB:
-                                                   /* do nothing */
-                                                   break;
-                                           case JCS_CMYK:
-                                                   convert_cmyk_to_rgb (cinfo, lines);
-                                                   break;
-                                           default:
-                                                   if (error && *error == NULL) {
-                                                           g_set_error (error,
-                                                                        GDK_PIXBUF_ERROR,
-                                                                        GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
-                                                                        _("Unsupported JPEG color space (%s)"),
-                                                                        colorspace_name (cinfo->out_color_space)); 
-                                                   }
-                                                   
-                                                   return FALSE;
-                                       }
+                                /* get scanlines from jpeg lib */
+                                if (! gdk_pixbuf__jpeg_image_load_lines (context,
+                                                                         error))
+                                        return FALSE;
 
-                                       context->dptr += nlines * context->pixbuf->rowstride;
-                                       
-                                       /* send updated signal */
-                                       (* context->updated_func) (context->pixbuf,
-                                                                  0, 
-                                                                  cinfo->output_scanline-1,
-                                                                  cinfo->image_width, 
-                                                                  nlines,
-                                                                  context->user_data);
-                               }
-                               if (cinfo->output_scanline >= cinfo->output_height && 
+                               if (cinfo->output_scanline >= cinfo->output_height &&
                                    jpeg_finish_output (cinfo))
                                        context->in_output = FALSE;
                                else