diff options
author | Michael Natterer <mitch@imendio.com> | 2005-12-14 13:58:02 +0000 |
---|---|---|
committer | Michael Natterer <mitch@src.gnome.org> | 2005-12-14 13:58:02 +0000 |
commit | e675ca627f67ef8d98690173032688f90901322e (patch) | |
tree | 1c0979cfa27546bca7d769a3d5f522bbd37cffda | |
parent | 49e4882358a2953f349dcb1fbe1c81979d9eaef9 (diff) | |
download | gtk+-e675ca627f67ef8d98690173032688f90901322e.tar.gz |
new utility function which factors out massive code duplication from the
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.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 6 | ||||
-rw-r--r-- | gdk-pixbuf/io-jpeg.c | 178 |
3 files changed, 82 insertions, 108 deletions
@@ -1,5 +1,11 @@ 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 the allocation of an intermediate buffer for non-progressive jpegs. Fixed bug #305894. 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,5 +1,11 @@ 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 the allocation of an intermediate buffer for non-progressive jpegs. Fixed bug #305894. 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 |