Re: [PATCH spice-html5]Handling non top-down lz_rgb

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

 




On Mon, Jan 21, 2013 at 9:02 PM, Jeremy White <jwhite@xxxxxxxxxxxxxxx> wrote:
Hi Vincent,

> +function flip_image_data(img)
> +{
> +    var w = img.width;
> +    var h = img.height;
> +    var temp_w = w;
> +    var temp_h = h;
> +    var buff = new Uint8Array(img.width * img.height * 4);
> +    while (temp_h--)
> +    {
> +        while (temp_w--)
> +        {
> +            buff[(temp_h * w + temp_w) * 4] = img.data[((h - temp_h -
> 1) * w + temp_w) * 4];
> +            buff[(temp_h * w + temp_w) * 4 + 1] = img.data[((h - temp_h
> - 1) * w + temp_w) * 4 + 1];
> +            buff[(temp_h * w + temp_w) * 4 + 2] = img.data[((h - temp_h
> - 1) * w + temp_w) * 4 + 2];
> +            buff[(temp_h * w + temp_w) * 4 + 3] = img.data[((h - temp_h
> - 1) * w + temp_w) * 4 + 3];
> +        }
> +        temp_w = w;
> +    }
> +    img.data.set(buff);

Couldn't this be done more simply by swapping line by line, rather than
pixel by pixel?  If I'm not mistaken, the Uint8Array set() method will
take an array and offset as a parameter, and you can get a subarray
fairly easily.  I have no idea if that will provide a performance boost,
but it will least enable the _javascript_ engines to try.

Well I didn't know about this function but I saw that generally built-in
array functions aren’t so efficient compared to raw loops. Anyway I
made as you said and I didn’t notice any significant performance
gain or loss.

Either way, if you could resubmit this as a discrete git-format-patch
entry (probably with signed-off-by while you're at it), I'd appreciate it.

Cheers,

Jeremy
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




Signed-off-by: Vincent Desprez <vincent.desprez@xxxxxxxxxx>
---
display.js | 3 ---
lz.js | 16 ++++++++++++++++
2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/display.js b/display.js
index 15d43d3..e4ae64b 100644
--- a/display.js
+++ b/display.js
@@ -243,9 +243,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_rgb_to_web(canvas.context,
                                             draw_copy.data.src_bitmap.lz_rgb);
                 if (! source_img)
diff --git a/lz.js b/lz.js
index 2914c37..5c3452f 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_rgb_to_web(context, lz_rgb)
 {
     var u8 = new Uint8Array(lz_rgb.data);
@@ -151,6 +164,9 @@ function convert_spice_lz_rgb_to_web(context, lz_rgb)
     var ret = context.createImageData(lz_rgb.width, lz_rgb.height);
 
     at = lz_rgb32_decompress(u8, 0, ret.data, LZ_IMAGE_TYPE_RGB32, lz_rgb.type != LZ_IMAGE_TYPE_RGBA);
+    if (!lz_rgb.top_down)
+        flip_image_data(ret);
+
     if (lz_rgb.type == LZ_IMAGE_TYPE_RGBA)
         lz_rgb32_decompress(u8, at, ret.data, LZ_IMAGE_TYPE_RGBA, false);
 

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]