gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10917: Implement some things in Bit


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10917: Implement some things in BitmapData.
Date: Mon, 25 May 2009 16:15:06 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 10917
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2009-05-25 16:15:06 +0200
message:
  Implement some things in BitmapData.
modified:
  libcore/asobj/flash/display/BitmapData_as.cpp
  libcore/asobj/flash/display/BitmapData_as.h
  testsuite/actionscript.all/BitmapData.as
    ------------------------------------------------------------
    revno: 10914.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2009-05-25 15:46:33 +0200
    message:
      Test and implement setPixel and setPixel32.
    modified:
      libcore/asobj/flash/display/BitmapData_as.cpp
      libcore/asobj/flash/display/BitmapData_as.h
      testsuite/actionscript.all/BitmapData.as
=== modified file 'libcore/asobj/flash/display/BitmapData_as.cpp'
--- a/libcore/asobj/flash/display/BitmapData_as.cpp     2009-05-25 09:01:28 
+0000
+++ b/libcore/asobj/flash/display/BitmapData_as.cpp     2009-05-25 13:46:33 
+0000
@@ -527,8 +527,23 @@
 {
        boost::intrusive_ptr<BitmapData_as> ptr =
         ensureType<BitmapData_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+    if (fn.nargs < 3) {
+        return as_value();
+    }
+
+    double x = fn.arg(0).to_number();
+    double y = fn.arg(1).to_number();
+    if (x < 0 || y < 0) return as_value();
+    if (x >= ptr->getWidth() || y >= ptr->getHeight()) {
+        return as_value();
+    }
+
+    // Ignore any transparency here.
+    boost::uint32_t color = fn.arg(2).to_int() & 0xffffff;
+
+    ptr->setPixel(x, y, color);
+
        return as_value();
 }
 
@@ -537,15 +552,31 @@
 {
        boost::intrusive_ptr<BitmapData_as> ptr =
         ensureType<BitmapData_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+    if (fn.nargs < 3) {
+        return as_value();
+    }
+
+    double x = fn.arg(0).to_number();
+    double y = fn.arg(1).to_number();
+    if (x < 0 || y < 0) return as_value();
+    if (x >= ptr->getWidth() || y >= ptr->getHeight()) {
+        return as_value();
+    }
+
+    // TODO: multiply.
+    boost::uint32_t color = fn.arg(2).to_int();
+
+    ptr->setPixel32(x, y, color);
+
        return as_value();
 }
 
 as_value
 BitmapData_threshold(const fn_call& fn)
 {
-       boost::intrusive_ptr<BitmapData_as> ptr = 
ensureType<BitmapData_as>(fn.this_ptr);
+       boost::intrusive_ptr<BitmapData_as> ptr =
+        ensureType<BitmapData_as>(fn.this_ptr);
        UNUSED(ptr);
        LOG_ONCE( log_unimpl (__FUNCTION__) );
        return as_value();

=== modified file 'libcore/asobj/flash/display/BitmapData_as.h'
--- a/libcore/asobj/flash/display/BitmapData_as.h       2009-02-25 22:33:03 
+0000
+++ b/libcore/asobj/flash/display/BitmapData_as.h       2009-05-25 13:46:33 
+0000
@@ -55,9 +55,27 @@
     {
         return _bitmapData;
     }
-    
-    // Returns an unsigned int representation of the pixel
-    // at (x, y) either with or without transparency.
+ 
+    /// Set a specified pixel to the specified color.
+    //
+    /// Callers must make sure the pixel is in range. Retains transparency
+    /// (which is opaque, for non-transparent BitmapData objects).
+    void setPixel(int x, int y, boost::uint32_t color) {
+        const BitmapArray::size_type index = x * _width + y;
+        _bitmapData[index] = (_bitmapData[index] & 0xff000000) | color;
+    }
+
+    /// Set a specified pixel to the specified color.
+    //
+    /// Callers must make sure the pixel is in range. Set to opaque for
+    /// non-transparent BitmapData objects
+    void setPixel32(int x, int y, boost::uint32_t color) {
+        _bitmapData[x * _width + y] = _transparent ? color : color | 
0xff000000;
+    }
+
+
+    /// Returns an unsigned int representation of the pixel
+    /// at (x, y) either with or without transparency.
     boost::int32_t getPixel(int x, int y, bool transparency) const;
 
     void update(const boost::uint8_t* data);

=== modified file 'testsuite/actionscript.all/BitmapData.as'
--- a/testsuite/actionscript.all/BitmapData.as  2009-05-25 12:34:53 +0000
+++ b/testsuite/actionscript.all/BitmapData.as  2009-05-25 13:46:33 +0000
@@ -155,6 +155,7 @@
 tr = new Bitmap(30, 30, true);
 ntr = new Bitmap(30, 30, false);
 
+// Premultiplication?
 tr.setPixel32(2, 2, 0x44);
 xcheck_equals(tr.getPixel(2, 2), 0x00);
 xcheck_equals(tr.getPixel32(2, 2), 0);
@@ -165,34 +166,39 @@
 xcheck_equals(tr.getPixel32(2, 2), 0x220000ac);
 
 tr.setPixel32(2, 2, 0xff0000aa);
-xcheck_equals(tr.getPixel(2, 2), 0xaa);
-xcheck_equals(tr.getPixel32(2, 2), -16777046);
+check_equals(tr.getPixel(2, 2), 0xaa);
+check_equals(tr.getPixel32(2, 2), -16777046);
 
 tr.setPixel(3, 3, 0xff);
-xcheck_equals(tr.getPixel(3, 3), 0xff);
-xcheck_equals(tr.getPixel32(3, 3), -16776961);
+check_equals(tr.getPixel(3, 3), 0xff);
+check_equals(tr.getPixel32(3, 3), -16776961);
 
+// Premultiplication?
 tr.setPixel32(4, 4, 0x44444444);
 xcheck_equals(tr.getPixel(4, 4), 0x434343);
 xcheck_equals(tr.getPixel32(4, 4), 0x44434343);
 
 tr.setPixel32(4, 4, 0x10101010);
-xcheck_equals(tr.getPixel(4, 4), 0x101010);
-xcheck_equals(tr.getPixel32(4, 4), 0x10101010);
+check_equals(tr.getPixel(4, 4), 0x101010);
+check_equals(tr.getPixel32(4, 4), 0x10101010);
 
+// Premultiplication?
 tr.setPixel32(4, 4, 0x43434343);
 xcheck_equals(tr.getPixel(4, 4), 0x444444);
 xcheck_equals(tr.getPixel32(4, 4), 0x43444444);
 
 ntr.setPixel(5, 5, 0xff);
-xcheck_equals(ntr.getPixel(5, 5), 0xff);
-xcheck_equals(ntr.getPixel32(5, 5), -16776961);
+check_equals(ntr.getPixel(5, 5), 0xff);
+check_equals(ntr.getPixel32(5, 5), -16776961);
 
 ntr.setPixel32(6, 6, 0x44444444);
-xcheck_equals(ntr.getPixel(6, 6), 0x444444);
-xcheck_equals(ntr.getPixel32(6, 6), -12303292);
+check_equals(ntr.getPixel(6, 6), 0x444444);
+check_equals(ntr.getPixel32(6, 6), -12303292);
 
+// ---------
 // floodFill
+// ---------
+
 bmp = new Bitmap(20, 20, false);
 bmp.floodFill(10, 10, 0x0000ff00);
 


reply via email to

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