diff -Nru spice-html5-0.1.7/debian/changelog spice-html5-0.1.7/debian/changelog
--- spice-html5-0.1.7/debian/changelog 2018-02-13 12:24:15.000000000 +0100
+++ spice-html5-0.1.7/debian/changelog 2019-07-12 17:39:24.000000000 +0200
@@ -1,3 +1,11 @@
+spice-html5 (0.1.7-2ubuntu1) bionic; urgency=medium
+
+ * d/p/fix-windows-spice-upside-down.patch
+ d/p/fix-windows-spice-upside-down-bitmaps.patch
+ Fix window spice upside down display (LP: #1836361)
+
+ -- Dariusz Gadomski Fri, 12 Jul 2019 17:39:24 +0200
+
spice-html5 (0.1.7-2) unstable; urgency=medium
[ Daniel Baumann ]
diff -Nru spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down-bitmaps.patch spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down-bitmaps.patch
--- spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down-bitmaps.patch 1970-01-01 01:00:00.000000000 +0100
+++ spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down-bitmaps.patch 2019-07-12 17:39:24.000000000 +0200
@@ -0,0 +1,51 @@
+Description: Handle non topdown bitmaps
+ Backport of an upstream patch.
+ .
+ spice-html5 (0.1.7-2ubuntu1) bionic; urgency=medium
+ .
+ * d/p/fix-windows-spice-upside-down-bitmaps.patch:
+ Handle non topdown bitmaps (LP: #1836361)
+Origin: upstream, https://github.com/freedesktop/spice-html5/commit/7ba763feb5322f0c97758070075b60cee5464f47
+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1836361
+
+--- spice-html5-0.1.7.orig/bitmap.js
++++ spice-html5-0.1.7/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;
diff -Nru spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down.patch spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down.patch
--- spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down.patch 1970-01-01 01:00:00.000000000 +0100
+++ spice-html5-0.1.7/debian/patches/fix-windows-spice-upside-down.patch 2019-07-12 17:39:24.000000000 +0200
@@ -0,0 +1,53 @@
+Description: Handling non-topdown lz_rgb
+Author: Vincent Desprez
+Origin: upstream, https://gitlab.com/spice/spice-html5/commit/bfa85a7117fcf28ff19f2507f61db4620da2e828
+Last-Update: 2018-08-16
+
+diff --git a/display.js b/display.js
+index 12fbab0..464c72d 100644
+--- a/display.js
++++ b/display.js
+@@ -288,9 +288,6 @@ SpiceDisplayConn.prototype.process_channel_message = function(msg)
+ return false;
+ }
+
+- if (draw_copy.data.src_bitmap.lz_rgb.top_down != 1)
+- this.log_warn("FIXME: Implement non top down support for lz_rgb");
+-
+ var source_img = convert_spice_lz_to_web(canvas.context,
+ draw_copy.data.src_bitmap.lz_rgb);
+ if (! source_img)
+diff --git a/lz.js b/lz.js
+index 4292eac..53c1141 100644
+--- a/lz.js
++++ b/lz.js
+@@ -141,6 +141,19 @@ function lz_rgb32_decompress(in_buf, at, out_buf, type, default_alpha)
+ return encoder - 1;
+ }
+
++function flip_image_data(img)
++{
++ var wb = img.width * 4;
++ var h = img.height;
++ var temp_h = h;
++ var buff = new Uint8Array(img.width * img.height * 4);
++ while (temp_h--)
++ {
++ buff.set(img.data.subarray(temp_h * wb, (temp_h + 1) * wb), (h - temp_h - 1) * wb);
++ }
++ img.data.set(buff);
++}
++
+ function convert_spice_lz_to_web(context, lz_image)
+ {
+ var at;
+@@ -150,6 +163,9 @@ function convert_spice_lz_to_web(context, lz_image)
+ var ret = context.createImageData(lz_image.width, lz_image.height);
+
+ at = lz_rgb32_decompress(u8, 0, ret.data, LZ_IMAGE_TYPE_RGB32, lz_image.type != LZ_IMAGE_TYPE_RGBA);
++ if (!lz_image.top_down)
++ flip_image_data(ret);
++
+ if (lz_image.type == LZ_IMAGE_TYPE_RGBA)
+ lz_rgb32_decompress(u8, at, ret.data, LZ_IMAGE_TYPE_RGBA, false);
+ }
diff -Nru spice-html5-0.1.7/debian/patches/series spice-html5-0.1.7/debian/patches/series
--- spice-html5-0.1.7/debian/patches/series 2018-02-13 12:24:15.000000000 +0100
+++ spice-html5-0.1.7/debian/patches/series 2019-07-12 17:39:24.000000000 +0200
@@ -1 +1,3 @@
add-ctrl-alt-del-button.patch
+fix-windows-spice-upside-down.patch
+fix-windows-spice-upside-down-bitmaps.patch