gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_start-


From: Benjamin Wolsey
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_start-529-ge98c536
Date: Thu, 07 Apr 2011 08:03:14 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  e98c536313d35e69060a190055d6eeaa985c4a10 (commit)
      from  abe191af0cf1a8df11061686bbb01badd9b0580f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=e98c536313d35e69060a190055d6eeaa985c4a10


commit e98c536313d35e69060a190055d6eeaa985c4a10
Author: Benjamin Wolsey <address@hidden>
Date:   Thu Apr 7 09:45:11 2011 +0200

    Fix copyPixels() for overlapping ranges
    
    Copying to a range starting within the source range causes odd behaviour
    (and UB with std::copy), so test and handle that case.

diff --git a/libcore/asobj/flash/display/BitmapData_as.cpp 
b/libcore/asobj/flash/display/BitmapData_as.cpp
index 16f758b..bf5b677 100644
--- a/libcore/asobj/flash/display/BitmapData_as.cpp
+++ b/libcore/asobj/flash/display/BitmapData_as.cpp
@@ -750,6 +750,12 @@ bitmapdata_copyPixels(const fn_call& fn)
     BitmapData_as::iterator targ = pixelAt(*ptr, destX, destY);
     BitmapData_as::iterator src = pixelAt(*source, sourceX, sourceY);
 
+    const bool sameImage = (ptr == source);
+    const bool copyToXRange = sameImage && 
+        (destX >= sourceX && destX < sourceX + destW);
+    const bool copyToYRange = sameImage &&
+        (destY >= sourceY && destY < sourceY + destH);
+
     // Just being careful...
     assert(sourceX + destW <= static_cast<int>(source->width()));
     assert(sourceY + destH <= static_cast<int>(source->height()));
@@ -759,10 +765,39 @@ bitmapdata_copyPixels(const fn_call& fn)
     // Copy for the width and height of the *dest* image.
     // We have already ensured that the copied area
     // is inside both bitmapdatas.
-    for (int i = 0; i < destH; ++i) {
-        std::copy(src, src + destW, targ);
-        targ += ptr->width();
-        src += source->width();
+    //
+    // If the destination y-range starts within the source y-range, copy from
+    // bottom to top.
+    // If the destination x-range starts within the source x-range, copy from
+    // right to left.
+    if (copyToYRange) {
+        assert(destH > 0);
+        targ += (destH - 1) * ptr->width();
+        src += (destH - 1) * source->width();
+        // Copy from bottom to top.
+        for (int i = destH; i > 0; --i) {
+            if (copyToXRange) {
+                std::copy_backward(src, src + destW, targ + destW);
+            }
+            else {
+                std::copy(src, src + destW, targ);
+            }
+            targ -= ptr->width();
+            src -= source->width();
+        }
+    }
+    else {
+        // Normal copy from top to bottom.
+        for (int i = 0; i < destH; ++i) {
+            if (copyToXRange) {
+                std::copy_backward(src, src + destW, targ + destW);
+            }
+            else {
+                std::copy(src, src + destW, targ);
+            }
+            targ += ptr->width();
+            src += source->width();
+        }
     }
 
     ptr->updateObjects();
diff --git a/testsuite/actionscript.all/BitmapData.as 
b/testsuite/actionscript.all/BitmapData.as
index 708ac4a..4d6a002 100644
--- a/testsuite/actionscript.all/BitmapData.as
+++ b/testsuite/actionscript.all/BitmapData.as
@@ -643,6 +643,28 @@ dest.copyPixels(source, new Rect(0, 0, 100, 100), new 
Point(200, 50));
  check_equals(dest.getPixel(10, 52), 0xff0000);
  check_equals(dest.getPixel(90, 90), 0xff0000);
 
+// Check self copies!
+
+source = new flash.display.BitmapData(100, 100, false);
+
+// Should be the same
+source.fillRect(new Rect(0, 0, 50, 50), 0x00ff00);
+source.copyPixels(source, new Rect(35, 35, 20, 20), new Point(35, 35));
+
+ check_equals(source.getPixel(55, 45), 0xffffff);
+ check_equals(source.getPixel(60, 60), 0xffffff);
+ check_equals(source.getPixel(45, 55), 0xffffff);
+ check_equals(source.getPixel(45, 45), 0x00ff00);
+
+source.copyPixels(source, new Rect(20, 20, 50, 50), new Point(45, 45));
+ // Bottom right corner is still white
+ check_equals(source.getPixel(90, 90), 0xffffff);
+ check_equals(source.getPixel(55, 42), 0xffffff);
+ check_equals(source.getPixel(42, 55), 0xffffff);
+ check_equals(source.getPixel(55, 55), 0x00ff00);
+ check_equals(source.getPixel(55, 70), 0x00ff00);
+ check_equals(source.getPixel(70, 55), 0x00ff00);
+
 // copyChannel
 
 // This function seems to work as expected for single channel to single 
@@ -967,6 +989,6 @@ flash.display.BitmapData.prototype = e;
 // END OF TEST
 //-------------------------------------------------------------
 
-totals(340);
+totals(350);
 
 #endif // OUTPUT_VERSION >= 8

-----------------------------------------------------------------------

Summary of changes:
 libcore/asobj/flash/display/BitmapData_as.cpp |   43 ++++++++++++++++++++++--
 testsuite/actionscript.all/BitmapData.as      |   24 +++++++++++++-
 2 files changed, 62 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

[Prev in Thread] Current Thread [Next in Thread]