[Spice-devel] JPEG error - Application transferred too few scanlines

Christophe Fergeau cfergeau at redhat.com
Thu Jul 28 10:08:57 PDT 2011


Hey,

On Wed, Jul 27, 2011 at 06:11:32PM +0200, Christophe Fergeau wrote:
> Yep, I broke that in master, it's caused by the mjpeg changes, the "height"
> used when calling mjpeg_encoder_new is 1 byte less than the height which is
> then used in the loop around mjpeg_encoder_encode_scanline.

I went further debugging that, image sizes get rounded to the next even
number. I didn't notice that when I wrote the code, so the loop sending the
image to encode line by line to libjpeg uses the non-rounded height for
odd-sized images. And then libjpeg is right in complaining that one line is
missing :) The (ugly) attached  patch seems to be working as a workaround,
but I'll come up with a better fix.

Christophe
-------------- next part --------------
commit 74eb7e06184baf2b671c540225645d88f01d8abd
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Thu Jul 28 13:30:24 2011 +0200

    fix

diff --git a/server/red_worker.c b/server/red_worker.c
index 6737940..0ae53a7 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -7329,11 +7329,12 @@ static int encode_frame (RedWorker *worker, const SpiceRect *src,
         red_get_image_line(worker, chunks, &offset, &chunk, image_stride);
     }
 
-    const int image_height = src->bottom - src->top;
-    const int image_width = src->right - src->left;
+    const unsigned int stream_height = src->bottom - src->top;
+    const unsigned int stream_width = src->right - src->left;
+    uint8_t *src_line;
 
-    for (i = 0; i < image_height; i++) {
-        uint8_t *src_line =
+    for (i = 0; i < stream_height; i++) {
+        src_line =
             (uint8_t *)red_get_image_line(worker, chunks, &offset, &chunk, image_stride);
 
         if (!src_line) {
@@ -7341,10 +7342,14 @@ static int encode_frame (RedWorker *worker, const SpiceRect *src,
         }
 
         src_line += src->left * mjpeg_encoder_get_bytes_per_pixel(stream->mjpeg_encoder);
-        if (mjpeg_encoder_encode_scanline(stream->mjpeg_encoder, src_line, image_width) == 0)
+        if (mjpeg_encoder_encode_scanline(stream->mjpeg_encoder, src_line, stream_width) == 0)
             return FALSE;
     }
 
+    if ((stream_height > 0) && (stream_height != SPICE_ALIGN(src->bottom - src->top, 2)))
+        if (mjpeg_encoder_encode_scanline(stream->mjpeg_encoder, src_line, stream_width) == 0)
+            return FALSE;
+
     return TRUE;
 }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20110728/c51cb53a/attachment.pgp>


More information about the Spice-devel mailing list