[Spice-devel] [PATCH spice-html5 2/2] Handle non topdown bitmaps

Pavel Grunt pgrunt at redhat.com
Tue Jan 10 21:54:57 UTC 2017


---
 bitmap.js | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/bitmap.js b/bitmap.js
index 03f5127..91278d7 100644
--- a/bitmap.js
+++ b/bitmap.js
@@ -26,25 +26,31 @@
 function convert_spice_bitmap_to_web(context, spice_bitmap)
 {
     var ret;
-    var offset, x;
+    var offset, x, src_offset = 0, src_dec = 0;
     var u8 = new Uint8Array(spice_bitmap.data);
     if (spice_bitmap.format != SPICE_BITMAP_FMT_32BIT &&
         spice_bitmap.format != SPICE_BITMAP_FMT_RGBA)
         return undefined;
 
+    if (!(spice_bitmap.flags & SPICE_BITMAP_FLAGS_TOP_DOWN))
+    {
+        src_offset = (spice_bitmap.y - 1 ) * spice_bitmap.stride;
+        src_dec = 2 * spice_bitmap.stride;
+    }
+
     ret = context.createImageData(spice_bitmap.x, spice_bitmap.y);
-    for (offset = 0; offset < (spice_bitmap.y * spice_bitmap.stride); )
-        for (x = 0; x < spice_bitmap.x; x++, offset += 4)
+    for (offset = 0; offset < (spice_bitmap.y * spice_bitmap.stride); src_offset -= src_dec)
+        for (x = 0; x < spice_bitmap.x; x++, offset += 4, src_offset += 4)
         {
-            ret.data[offset + 0 ] = u8[offset + 2];
-            ret.data[offset + 1 ] = u8[offset + 1];
-            ret.data[offset + 2 ] = u8[offset + 0];
+            ret.data[offset + 0 ] = u8[src_offset + 2];
+            ret.data[offset + 1 ] = u8[src_offset + 1];
+            ret.data[offset + 2 ] = u8[src_offset + 0];
 
             // FIXME - We effectively treat all images as having SPICE_IMAGE_FLAGS_HIGH_BITS_SET
             if (spice_bitmap.format == SPICE_BITMAP_FMT_32BIT)
                 ret.data[offset + 3] = 255;
             else
-                ret.data[offset + 3] = u8[offset];
+                ret.data[offset + 3] = u8[src_offset];
         }
 
     return ret;
-- 
2.11.0



More information about the Spice-devel mailing list