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.
This commit is contained in:
Michael Natterer 2005-12-14 13:58:02 +00:00 committed by Michael Natterer
parent 49e4882358
commit e675ca627f
3 changed files with 82 additions and 108 deletions

View 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

View 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

View 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