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-523-g636caca
Date: Wed, 06 Apr 2011 15:18:09 +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  636caca17e0577f50f0e9b4a5dbe04e9e058e036 (commit)
       via  f4d1bc5f8dbe961b08c8710aa0fefa66ebc92628 (commit)
      from  cb87566f744bef7b77cc7cba89d68fa3ba6df510 (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=636caca17e0577f50f0e9b4a5dbe04e9e058e036


commit 636caca17e0577f50f0e9b4a5dbe04e9e058e036
Author: Benjamin Wolsey <address@hidden>
Date:   Wed Apr 6 16:56:20 2011 +0200

    Cleanup.

diff --git a/libcore/asobj/flash/display/BitmapData_as.cpp 
b/libcore/asobj/flash/display/BitmapData_as.cpp
index 51d1dce..16f758b 100644
--- a/libcore/asobj/flash/display/BitmapData_as.cpp
+++ b/libcore/asobj/flash/display/BitmapData_as.cpp
@@ -178,11 +178,10 @@ private:
     const bool _greyscale;
 };
 
-}
+} // anonymous namespace
 
 BitmapData_as::BitmapData_as(as_object* owner,
         std::auto_ptr<image::GnashImage> im)
-   
     :
     _owner(owner),
     _cachedBitmap(0)

http://git.savannah.gnu.org/cgit//commit/?id=f4d1bc5f8dbe961b08c8710aa0fefa66ebc92628


commit f4d1bc5f8dbe961b08c8710aa0fefa66ebc92628
Author: Benjamin Wolsey <address@hidden>
Date:   Wed Apr 6 16:55:37 2011 +0200

    Implement BitmapData.noise.

diff --git a/libcore/asobj/flash/display/BitmapData_as.cpp 
b/libcore/asobj/flash/display/BitmapData_as.cpp
index 711ee7f..51d1dce 100644
--- a/libcore/asobj/flash/display/BitmapData_as.cpp
+++ b/libcore/asobj/flash/display/BitmapData_as.cpp
@@ -24,6 +24,7 @@
 #include <sstream>
 #include <algorithm>
 #include <queue>
+#include <boost/random.hpp>
 
 #include "MovieClip.h"
 #include "GnashImage.h"
@@ -44,6 +45,7 @@
 #include "ASConversions.h"
 #include "flash/geom/ColorTransform_as.h"
 #include "NativeFunction.h"
+#include "GnashNumeric.h"
 
 namespace gnash {
 
@@ -109,6 +111,75 @@ namespace {
     }
 }
 
+/// Local functors.
+namespace {
+
+/// Random number generator for noise
+//
+/// This uses the fastest RNG available; it's still more
+/// homogeneous than the Adobe one.
+template<typename RNG = boost::rand48>
+struct Noise
+{
+    Noise(int seed, boost::uint8_t low, boost::uint8_t high)
+        :
+        rng(seed),
+        dist(low, high),
+        uni(rng, dist)
+    {}
+
+    boost::uint8_t operator()() {
+        return uni();
+    }
+
+private:
+    RNG rng;
+    boost::uniform_int<> dist;
+    boost::variate_generator<RNG, boost::uniform_int<> > uni;
+};
+
+template<typename NoiseGenerator>
+struct NoiseAdapter
+{
+    NoiseAdapter(NoiseGenerator& n, boost::uint8_t bitmask, bool grey)
+        :
+        _gen(n),
+        _bitmask(bitmask),
+        _greyscale(grey)
+    {}
+
+    boost::uint32_t operator()() {
+
+        if (_greyscale) {
+            boost::uint8_t val = _gen();
+            return val | val << 8 | val << 16;
+        }
+
+        boost::uint32_t ret = 0;
+
+        if (_bitmask & 1) {
+            ret |= (_gen() << 16);
+        }
+        if (_bitmask & 2) {
+            ret |= _gen() << 8;
+        }
+        if (_bitmask & 4) {
+            ret |= _gen();
+        }
+        if (_bitmask & 8) {
+            ret |= _gen() << 24;
+        }
+        return ret;
+    }
+
+private:
+    NoiseGenerator& _gen;
+    const boost::uint8_t _bitmask;
+    const bool _greyscale;
+};
+
+}
+
 BitmapData_as::BitmapData_as(as_object* owner,
         std::auto_ptr<image::GnashImage> im)
    
@@ -914,8 +985,34 @@ as_value
 bitmapdata_noise(const fn_call& fn)
 {
        BitmapData_as* ptr = ensure<ThisIsNative<BitmapData_as> >(fn);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+    if (ptr->disposed()) return as_value();
+
+    if (fn.nargs < 1) {
+        return as_value();
+    }
+    const int seed = toInt(fn.arg(0), getVM(fn));
+
+    const boost::uint8_t low = fn.nargs > 1 ?
+        clamp(toInt(fn.arg(1), getVM(fn)), 0, 255) : 0;
+
+    const boost::uint8_t high = fn.nargs > 2 ?
+        clamp<int>(toInt(fn.arg(2), getVM(fn)), low, 255) : 255;
+
+    const boost::uint8_t chans = fn.nargs > 3 ?
+        std::abs(toInt(fn.arg(3), getVM(fn))) & 15 : 1 | 2 | 4;
+
+    const bool greyscale = fn.nargs > 4 ?
+        toBool(fn.arg(4), getVM(fn)) : false;
+
+    Noise<> noise(seed, low, high);
+
+    NoiseAdapter<Noise<> > n(noise, chans, greyscale);
+
+    std::generate(ptr->begin(), ptr->end(), n);
+    
+    ptr->updateObjects();
+
        return as_value();
 }
 
diff --git a/testsuite/actionscript.all/BitmapData.as 
b/testsuite/actionscript.all/BitmapData.as
index 84c0190..708ac4a 100644
--- a/testsuite/actionscript.all/BitmapData.as
+++ b/testsuite/actionscript.all/BitmapData.as
@@ -796,6 +796,104 @@ dest.copyChannel(src, new Rect(0, 0, 100, 100), new 
Point(0, 0), 6, 4);
  check_equals(dest.getPixel(25, 75), 0xffff00); // Yellow
  check_equals(dest.getPixel(75, 75), 0xffff00); // Yellow
 
+// noise().
+
+// Tests that a particular color does not appear.
+testNoColor = function(bd, mask) {
+   var width = bd.width;
+   var height = bd.height;
+   for (var i = 0; i < height; ++i) {
+       for (var j = 0; j < width; ++j) {
+           if ( (bd.getPixel32(i, j) & mask) != 0) return false;
+       };
+   };
+   return true;
+};
+
+// Tests that a particular color is within a specified range
+testColorRange = function(bd, mask, low, high) {
+    var width = bd.width;
+    var height = bd.height;
+
+    var shift = 0;
+    if (mask == 0xff00) shift = 8;
+    if (mask == 0xff0000) shift = 16;
+    if (mask == 0xff000000) shift = 24;
+
+    for (var i = 0; i < height; ++i) {
+        for (var j = 0; j < width; ++j) {
+            var pix = (bd.getPixel32(i, j) & mask) >> shift;
+            if (pix < low || pix > high) {
+                return false;
+            };
+        };
+    };
+    return true;
+};
+
+// Tests that a particular color is within a specified range
+testGreys = function(bd, low, high) {
+    var width = bd.width;
+    var height = bd.height;
+
+    for (var i = 0; i < height; ++i) {
+        for (var j = 0; j < width; ++j) {
+            var r = (bd.getPixel32(i, j) & 0xff0000) >> 16;
+            var g = (bd.getPixel32(i, j) & 0xff00) >> 8;
+            var b = (bd.getPixel32(i, j) & 0xff);
+            if (r != g || g != b) return false;
+            if (r < low || r > high) return false;
+        };
+    };
+    return true;
+};
+
+ns = new flash.display.BitmapData(15, 15, false);
+
+// Noise on red and green channels from 0 to 255
+ns.noise(203, 0, 255, 1 | 2);
+ check(testNoColor(ns, 0xff));
+
+ns.noise(203, 0, 255, 1 | 4);
+ check(testNoColor(ns, 0xff00));
+
+// Noise on green and blue from 25 to 150
+ns.noise(203, 25, 150, 2 | 4);
+ check(testNoColor(ns, 0xff0000));
+ // Green should be from 25 to 150
+ check(testColorRange(ns, 0xff00, 25, 150));
+ check(testColorRange(ns, 0xff, 25, 150));
+
+// Noise on green from 200 to 201
+ns.noise(203, 200, 201, 2);
+ check(testColorRange(ns, 0xff00, 200, 201));
+
+// Noise on blue from 200 to 200
+ns.noise(203, 200, 200, 4);
+ check(testColorRange(ns, 0xff, 200, 200));
+
+// Noise on all from 70 to 80
+ns.noise(203, 70, 80);
+ check(testColorRange(ns, 0xff, 70, 80));
+ check(testColorRange(ns, 0xff00, 70, 80));
+ check(testColorRange(ns, 0xff0000, 70, 80));
+
+// Equal noise on all from 70 to 80
+ns.noise(203, 70, 80, 0, true);
+ check(testGreys(ns, 70, 80));
+
+// Equal noise on all from 0, 200
+ns.noise(203, 0, 200, 0, true);
+ check(testGreys(ns, 0, 200));
+
+// Swapped values
+ns.noise(203, 60, 50, 0, true);
+ check(testGreys(ns, 60, 60));
+
+// Negative values
+ns.noise(203, -10, 0, 0, true);
+ check(testGreys(ns, 0, 0));
+
 // clone();
 
 orig = new flash.display.BitmapData(10, 10, false, 0x00ff10);
@@ -869,6 +967,6 @@ flash.display.BitmapData.prototype = e;
 // END OF TEST
 //-------------------------------------------------------------
 
-totals(326);
+totals(340);
 
 #endif // OUTPUT_VERSION >= 8

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

Summary of changes:
 libcore/asobj/flash/display/BitmapData_as.cpp |  102 ++++++++++++++++++++++++-
 testsuite/actionscript.all/BitmapData.as      |  100 ++++++++++++++++++++++++-
 2 files changed, 198 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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