<div dir="ltr"><br><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 21, 2013 at 9:02 PM, Jeremy White <span dir="ltr"><<a href="mailto:jwhite@codeweavers.com" target="_blank">jwhite@codeweavers.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Vincent,<br>
<div class="im"><br>
> +function flip_image_data(img)<br>
> +{<br>
> +    var w = img.width;<br>
> +    var h = img.height;<br>
> +    var temp_w = w;<br>
> +    var temp_h = h;<br>
> +    var buff = new Uint8Array(img.width * img.height * 4);<br>
> +    while (temp_h--)<br>
> +    {<br>
> +        while (temp_w--)<br>
> +        {<br>
> +            buff[(temp_h * w + temp_w) * 4] = img.data[((h - temp_h -<br>
> 1) * w + temp_w) * 4];<br>
> +            buff[(temp_h * w + temp_w) * 4 + 1] = img.data[((h - temp_h<br>
> - 1) * w + temp_w) * 4 + 1];<br>
> +            buff[(temp_h * w + temp_w) * 4 + 2] = img.data[((h - temp_h<br>
> - 1) * w + temp_w) * 4 + 2];<br>
> +            buff[(temp_h * w + temp_w) * 4 + 3] = img.data[((h - temp_h<br>
> - 1) * w + temp_w) * 4 + 3];<br>
> +        }<br>
> +        temp_w = w;<br>
> +    }<br>
> +    img.data.set(buff);<br>
<br>
</div>Couldn't this be done more simply by swapping line by line, rather than<br>
pixel by pixel?  If I'm not mistaken, the Uint8Array set() method will<br>
take an array and offset as a parameter, and you can get a subarray<br>
fairly easily.  I have no idea if that will provide a performance boost,<br>
but it will least enable the Javascript engines to try.<br></blockquote><div><br></div><div style>Well I didn't know about this function but I saw that generally built-in</div><div style>array functions aren’t so efficient compared to raw loops. Anyway I</div>

<div style>made as you said and I didn’t notice any significant performance</div><div style>gain or loss.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
Either way, if you could resubmit this as a discrete git-format-patch<br>
entry (probably with signed-off-by while you're at it), I'd appreciate it.<br>
<div class=""><div class="h5"><br>
Cheers,<br>
<br>
Jeremy<br>
_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
</div></div></blockquote></div><br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>Signed-off-by: Vincent Desprez <<a href="mailto:vincent.desprez@apwise.com">vincent.desprez@apwise.com</a>></div>

<div class="gmail_extra" style>---</div><div class="gmail_extra" style>display.js | 3 ---<br>lz.js | 16 ++++++++++++++++<br>2 files changed, 16 insertions(+), 3 deletions(-)<br><br>diff --git a/display.js b/display.js<br>

index 15d43d3..e4ae64b 100644<br>--- a/display.js<br>+++ b/display.js<br>@@ -243,9 +243,6 @@ SpiceDisplayConn.prototype.process_channel_message = function(msg)<br>                     return false;<br>                 }<br>

 <br>-                if (draw_copy.data.src_bitmap.lz_rgb.top_down != 1)<br>-                    this.log_warn("FIXME: Implement non top down support for lz_rgb");<br>-<br>                 var source_img = convert_spice_lz_rgb_to_web(canvas.context,<br>

                                             draw_copy.data.src_bitmap.lz_rgb);<br>                 if (! source_img)<br>diff --git a/lz.js b/lz.js<br>index 2914c37..5c3452f 100644<br>--- a/lz.js<br>+++ b/lz.js<br>@@ -141,6 +141,19 @@ function lz_rgb32_decompress(in_buf, at, out_buf, type, default_alpha)<br>

     return encoder - 1;<br> }<br> <br>+function flip_image_data(img)<br>+{<br>+    var wb = img.width * 4;</div><div class="gmail_extra"><pre style="color:rgb(0,0,0);word-wrap:break-word;white-space:pre-wrap">+    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);
 </pre></div><div class="gmail_extra"><br></div></div></div>