From e675ca627f67ef8d98690173032688f90901322e Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 14 Dec 2005 13:58:02 +0000 Subject: new utility function which factors out massive code duplication from the 2005-12-14 Michael Natterer * 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 | 6 ++ ChangeLog.pre-2-10 | 6 ++ gdk-pixbuf/io-jpeg.c | 178 ++++++++++++++++++++------------------------------- 3 files changed, 82 insertions(+), 108 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e26803288..5c719d77d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-12-14 Michael Natterer + + * 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 * gdk-pixbuf/io-jpeg.c: applied patch from maemo-gtk which avoids diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6e26803288..5c719d77d8 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +2005-12-14 Michael Natterer + + * 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 * gdk-pixbuf/io-jpeg.c: applied patch from maemo-gtk which avoids diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c index 9c3c064f93..84376d51ba 100644 --- a/gdk-pixbuf/io-jpeg.c +++ b/gdk-pixbuf/io-jpeg.c @@ -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 -- cgit v1.2.1