[Spice-commits] 6 commits - common/canvas_base.c common/canvas_utils.c

Christophe Fergau teuf at kemper.freedesktop.org
Fri Feb 6 02:49:59 PST 2015


 common/canvas_base.c  |   61 ++++++++++++++++++++++++++++++++++++++++++--------
 common/canvas_utils.c |    8 ++++++
 2 files changed, 60 insertions(+), 9 deletions(-)

New commits:
commit 3aad79d9c64e85bc2b474df427ccbedbf6840591
Author: Javier Celaya <javier.celaya at flexvm.es>
Date:   Tue Feb 3 12:14:28 2015 +0100

    LZ4: Do not include arpa/inet.h in Windows builds

diff --git a/common/canvas_base.c b/common/canvas_base.c
index 7394105..837f1d1 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -27,7 +27,9 @@
 #include <math.h>
 
 #ifdef USE_LZ4
+#ifndef WIN32
 #include <arpa/inet.h>
+#endif
 #include <lz4.h>
 #endif
 #include <spice/macros.h>
commit 9287e53b6c978a2c8eaf3d7f820276e34a678a92
Author: Javier Celaya <javier.celaya at flexvm.es>
Date:   Wed Jan 28 11:49:48 2015 +0100

    LZ4: Add support for 24bit pixman surfaces

diff --git a/common/canvas_base.c b/common/canvas_base.c
index 2f22400..7394105 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -543,6 +543,9 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
             stride_encoded *= 2;
             break;
         case SPICE_BITMAP_FMT_24BIT:
+            format = PIXMAN_r8g8b8;
+            stride_encoded *= 3;
+            break;
         case SPICE_BITMAP_FMT_32BIT:
             format = PIXMAN_x8r8g8b8;
             stride_encoded *= 4;
diff --git a/common/canvas_utils.c b/common/canvas_utils.c
index d52292b..0d1591a 100644
--- a/common/canvas_utils.c
+++ b/common/canvas_utils.c
@@ -165,6 +165,10 @@ pixman_image_t * surface_create(pixman_format_code_t format, int width, int heig
             bitmap_info.inf.bmiHeader.biBitCount = 32;
             nstride = width * 4;
             break;
+        case PIXMAN_r8g8b8:
+            bitmap_info.inf.bmiHeader.biBitCount = 24;
+            nstride = SPICE_ALIGN(width * 3, 4);
+            break;
         case PIXMAN_x1r5g5b5:
         case PIXMAN_r5g6b5:
             bitmap_info.inf.bmiHeader.biBitCount = 16;
@@ -233,6 +237,10 @@ pixman_image_t * surface_create(pixman_format_code_t format, int width, int heig
         case PIXMAN_x8r8g8b8:
             stride = width * 4;
             break;
+        case PIXMAN_r8g8b8:
+            // NOTE: LZ4 also decodes to RGB24
+            stride = SPICE_ALIGN(width * 3, 4);
+            break;
         case PIXMAN_x1r5g5b5:
         case PIXMAN_r5g6b5:
             stride = SPICE_ALIGN(width * 2, 4);
commit d167e2ead84b62f7af08a153dc95365910796ae5
Author: Javier Celaya <javier.celaya at flexvm.es>
Date:   Wed Jan 28 11:49:47 2015 +0100

    LZ4: Fix the row alignment when it is not on a 32bit boundary
    
    Fix the row alignment for 16/24 bpp images when it is not in a 32bit
    boundary. This is needed for 16bpp images when the width is an odd
    number, and for the future support of 24bpp images.

diff --git a/common/canvas_base.c b/common/canvas_base.c
index d621b39..2f22400 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -522,8 +522,7 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
 {
     pixman_image_t *surface = NULL;
     int dec_size, enc_size, available;
-    int stride;
-    int stride_abs;
+    int stride, stride_abs, stride_encoded;
     uint8_t *dest, *data, *data_end;
     int width, height, top_down;
     LZ4_streamDecode_t *stream;
@@ -534,19 +533,23 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     data = image->u.lz4.data->chunk[0].data;
     data_end = data + image->u.lz4.data->chunk[0].len;
     width = image->descriptor.width;
+    stride_encoded = width;
     height = image->descriptor.height;
     top_down = *(data++);
     spice_format = *(data++);
     switch (spice_format) {
         case SPICE_BITMAP_FMT_16BIT:
             format = PIXMAN_x1r5g5b5;
+            stride_encoded *= 2;
             break;
         case SPICE_BITMAP_FMT_24BIT:
         case SPICE_BITMAP_FMT_32BIT:
             format = PIXMAN_x8r8g8b8;
+            stride_encoded *= 4;
             break;
         case SPICE_BITMAP_FMT_RGBA:
             format = PIXMAN_a8r8g8b8;
+            stride_encoded *= 4;
             break;
         default:
             spice_warning("Unsupported bitmap format %d with LZ4\n", spice_format);
@@ -590,6 +593,21 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
         data += enc_size;
     } while (data < data_end);
 
+    if (stride_abs > stride_encoded) {
+        // Fix the row alignment
+        int row;
+        dest = (uint8_t *)pixman_image_get_data(surface);
+        if (!top_down) {
+            dest -= (stride_abs * (height - 1));
+        }
+        for (row = height - 1; row > 0; --row) {
+            uint32_t *dest_aligned, *dest_misaligned;
+            dest_aligned = (uint32_t *)(dest + stride_abs*row);
+            dest_misaligned = (uint32_t*)(dest + stride_encoded*row);
+            memmove(dest_aligned, dest_misaligned, stride_encoded);
+        }
+    }
+
     LZ4_freeStreamDecode(stream);
     return surface;
 }
commit f76fc28fc54200e1302ca6ffd289d9fc829cc272
Author: Javier Celaya <javier.celaya at flexvm.es>
Date:   Wed Jan 28 11:49:46 2015 +0100

    LZ4: Decode the image format from the stream

diff --git a/common/canvas_base.c b/common/canvas_base.c
index d5bd9d0..d621b39 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -527,6 +527,8 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     uint8_t *dest, *data, *data_end;
     int width, height, top_down;
     LZ4_streamDecode_t *stream;
+    uint8_t spice_format;
+    pixman_format_code_t format;
 
     spice_chunks_linearize(image->u.lz4.data);
     data = image->u.lz4.data->chunk[0].data;
@@ -534,12 +536,28 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     width = image->descriptor.width;
     height = image->descriptor.height;
     top_down = *(data++);
+    spice_format = *(data++);
+    switch (spice_format) {
+        case SPICE_BITMAP_FMT_16BIT:
+            format = PIXMAN_x1r5g5b5;
+            break;
+        case SPICE_BITMAP_FMT_24BIT:
+        case SPICE_BITMAP_FMT_32BIT:
+            format = PIXMAN_x8r8g8b8;
+            break;
+        case SPICE_BITMAP_FMT_RGBA:
+            format = PIXMAN_a8r8g8b8;
+            break;
+        default:
+            spice_warning("Unsupported bitmap format %d with LZ4\n", spice_format);
+            return NULL;
+    }
 
     surface = surface_create(
 #ifdef WIN32
                              canvas->dc,
 #endif
-                             PIXMAN_a8r8g8b8,
+                             format,
                              width, height, top_down);
     if (surface == NULL) {
         spice_warning("create surface failed");
commit 83c0d642edd0126df14a7fc4881412be2ad55e15
Author: Javier Celaya <javier.celaya at flexvm.es>
Date:   Wed Jan 28 11:49:45 2015 +0100

    LZ4: Adjust reading the top_down flag
    
    Adjust the way the top_down flag is read to the corresponding change in
    the wire protocol.

diff --git a/common/canvas_base.c b/common/canvas_base.c
index f2898ca..d5bd9d0 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -525,7 +525,7 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     int stride;
     int stride_abs;
     uint8_t *dest, *data, *data_end;
-    int width, height, direction;
+    int width, height, top_down;
     LZ4_streamDecode_t *stream;
 
     spice_chunks_linearize(image->u.lz4.data);
@@ -533,14 +533,14 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     data_end = data + image->u.lz4.data->chunk[0].len;
     width = image->descriptor.width;
     height = image->descriptor.height;
-    direction = *(data++);
+    top_down = *(data++);
 
     surface = surface_create(
 #ifdef WIN32
                              canvas->dc,
 #endif
                              PIXMAN_a8r8g8b8,
-                             width, height, direction == 0);
+                             width, height, top_down);
     if (surface == NULL) {
         spice_warning("create surface failed");
         return NULL;
@@ -551,7 +551,7 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     stride = pixman_image_get_stride(surface);
     stride_abs = abs(stride);
     available = height * stride_abs;
-    if (direction == 1) {
+    if (!top_down) {
         dest -= (stride_abs * (height - 1));
     }
 
commit 6049db492f527a8d48ca951613fa5fe467646aaa
Author: Javier Celaya <javier.celaya at flexvm.es>
Date:   Wed Jan 28 11:49:44 2015 +0100

    LZ4: Fix output buffer size

diff --git a/common/canvas_base.c b/common/canvas_base.c
index 64d0aae..f2898ca 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -521,7 +521,7 @@ static pixman_image_t *canvas_get_jpeg(CanvasBase *canvas, SpiceImage *image)
 static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
 {
     pixman_image_t *surface = NULL;
-    int dec_size, enc_size;
+    int dec_size, enc_size, available;
     int stride;
     int stride_abs;
     uint8_t *dest, *data, *data_end;
@@ -550,6 +550,7 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
     dest = (uint8_t *)pixman_image_get_data(surface);
     stride = pixman_image_get_stride(surface);
     stride_abs = abs(stride);
+    available = height * stride_abs;
     if (direction == 1) {
         dest -= (stride_abs * (height - 1));
     }
@@ -559,7 +560,7 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
         enc_size = ntohl(*((uint32_t *)data));
         data += 4;
         dec_size = LZ4_decompress_safe_continue(stream, (const char *) data,
-                                                (char *) dest, enc_size, height * stride_abs);
+                                                (char *) dest, enc_size, available);
         if (dec_size <= 0) {
             spice_warning("Error decoding LZ4 block\n");
             pixman_image_unref(surface);
@@ -567,6 +568,7 @@ static pixman_image_t *canvas_get_lz4(CanvasBase *canvas, SpiceImage *image)
             break;
         }
         dest += dec_size;
+        available -= dec_size;
         data += enc_size;
     } while (data < data_end);
 


More information about the Spice-commits mailing list