summaryrefslogtreecommitdiff
path: root/gdk-pixbuf
diff options
context:
space:
mode:
authorMichael Natterer <mitch@imendio.com>2005-12-14 13:58:02 +0000
committerMichael Natterer <mitch@src.gnome.org>2005-12-14 13:58:02 +0000
commit8eb6210f7af8ea0e73267191fff08394194b792d (patch)
tree8c48d2072cdb871b615042afc261f3f3968848ef /gdk-pixbuf
parente6bd877ce7d4d7df54b87af98e1f7708c9340342 (diff)
downloadgdk-pixbuf-8eb6210f7af8ea0e73267191fff08394194b792d.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.
Diffstat (limited to 'gdk-pixbuf')
-rw-r--r--gdk-pixbuf/io-jpeg.c178
1 files changed, 70 insertions, 108 deletions
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c
index 9c3c064f9..84376d51b 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