[patch] batch scanlines when loading JPEG...



Hi guys,

I've written and tested a small patch that increases efficiency
(particularly in small-cache systems) of loading JPEG images: override
the recommended lines with what we've already allocated; increase
batch size from 4 to 8 lines.

Please consider for inclusion and tweak as needed (eg reducing the
batch size to the original limit of 4).

Many thanks,
  Daniel

Signed-off-by: Daniel J Blueman <daniel blueman gmail com>
-- 
Daniel J Blueman
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c
index 680a209..77a37e6 100644
--- a/gdk-pixbuf/io-jpeg.c
+++ b/gdk-pixbuf/io-jpeg.c
@@ -46,6 +46,7 @@
 
 /* we are a "source manager" as far as libjpeg is concerned */
 #define JPEG_PROG_BUF_SIZE 65536
+#define LINEBUF_SIZE 8
 
 typedef struct {
 	struct jpeg_source_mgr pub;   /* public fields */
@@ -454,7 +455,7 @@ gdk_pixbuf__jpeg_image_load (FILE *f, GError **error)
 	char   otag_str[5];
 	GdkPixbuf * volatile pixbuf = NULL;
 	guchar *dptr;
-	guchar *lines[4]; /* Used to expand rows, via rec_outbuf_height, 
+	guchar *lines[LINEBUF_SIZE]; /* Used to expand rows, via rec_outbuf_height, 
                            * from the header file: 
                            * " Usually rec_outbuf_height will be 1 or 2, 
                            * at most 4."
@@ -511,6 +512,9 @@ gdk_pixbuf__jpeg_image_load (FILE *f, GError **error)
 	cinfo.do_fancy_upsampling = FALSE;
 	cinfo.do_block_smoothing = FALSE;
 
+	/* batch line updates for efficiency */
+	cinfo.rec_outbuf_height = cinfo.rec_outbuf_height > LINEBUF_SIZE ? cinfo.rec_outbuf_height : LINEBUF_SIZE;
+
 	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 
 				 cinfo.out_color_components == 4 ? TRUE : FALSE, 
 				 8, cinfo.output_width, cinfo.output_height);
@@ -738,7 +742,7 @@ gdk_pixbuf__jpeg_image_load_lines (JpegProgContext  *context,
                                    GError          **error)
 {
         struct jpeg_decompress_struct *cinfo = &context->cinfo;
-        guchar *lines[4];
+        guchar *lines[LINEBUF_SIZE];
         guchar **lptr;
         guchar *rowptr;
         gint   nlines, i;
@@ -968,6 +972,9 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data,
 			cinfo->do_fancy_upsampling = FALSE;
 			cinfo->do_block_smoothing = FALSE;
 
+			/* batch line updates f	or efficiency */
+			cinfo->rec_outbuf_height = cinfo.rec_outbuf_height > LINEBUF_SIZE ? cinfo.rec_outbuf_height : LINEBUF_SIZE;
+
 			if (rc == JPEG_SUSPENDED)
 				continue;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]