gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog testsuite/MovieTester.cpp tests...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog testsuite/MovieTester.cpp tests...
Date: Wed, 18 Apr 2007 17:28:13 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/04/18 17:28:13

Modified files:
        .              : ChangeLog 
        testsuite      : MovieTester.cpp MovieTester.h 

Log message:
                * testsuite/MovieTester.{cpp,h}:
                  Added interfaces for testing pixel values.
                  Next step would be actually initializing
                  a renderer during testing (if requested, maybe?)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2916&r2=1.2917
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/MovieTester.cpp?cvsroot=gnash&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/MovieTester.h?cvsroot=gnash&r1=1.12&r2=1.13

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2916
retrieving revision 1.2917
diff -u -b -r1.2916 -r1.2917
--- ChangeLog   18 Apr 2007 17:04:56 -0000      1.2916
+++ ChangeLog   18 Apr 2007 17:28:13 -0000      1.2917
@@ -1,3 +1,10 @@
+2007-04-18 Sandro Santilli <address@hidden>
+
+       * testsuite/MovieTester.{cpp,h}:
+         Added interfaces for testing pixel values.
+         Next step would be actually initializing
+         a renderer during testing (if requested, maybe?)
+
 2007-04-18 Udo Giacomozzi <address@hidden>
 
        * backend/render_handler.h: renamed get_pixel() to getPixel() and

Index: testsuite/MovieTester.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/MovieTester.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- testsuite/MovieTester.cpp   2 Apr 2007 15:45:22 -0000       1.24
+++ testsuite/MovieTester.cpp   18 Apr 2007 17:28:13 -0000      1.25
@@ -29,6 +29,8 @@
 #include "gnash.h" // for create_movie and create_library_movie and for 
gnash::key namespace
 #include "VM.h" // for initialization
 #include "sound_handler_test.h" // for creating the "test" sound handler
+#include "render.h" // for get_render_handler
+#include "types.h" // for rgba class
 
 #include <cstdio>
 #include <string>
@@ -139,9 +141,24 @@
 void
 MovieTester::movePointerTo(int x, int y)
 {
+       _x = x;
+       _y = y;
        _movie_root->notify_mouse_moved(x, y);
 }
 
+FuzzyPixel
+MovieTester::getAveragePixel(unsigned radius, int tolerance) const
+{
+       render_handler* rend = get_render_handler();
+       assert(rend);
+       rgba color;
+       if ( ! rend->getAveragePixel(color, _x, _y, radius) )
+       {
+               return FuzzyPixel();
+       }
+       return FuzzyPixel(color, tolerance);
+}
+
 void
 MovieTester::pressMouseButton()
 {
@@ -209,4 +226,24 @@
        return _sound_handler.get()->test_times_stopped_all();
 }
 
+bool
+FuzzyPixel::operator==(const FuzzyPixel& o) const
+{
+       // Intolerant FuzzyPixels never succeed in comparison
+       if ( _tol < 0 || o._tol < 0 ) return false;
+
+       int tol=std::max(_tol, o._tol);
+       if ( ! fuzzyEqual(_col.m_r, o._col.m_r, tol) ) return false;
+       if ( ! fuzzyEqual(_col.m_g, o._col.m_g, tol) ) return false;
+       if ( ! fuzzyEqual(_col.m_b, o._col.m_b, tol) ) return false;
+       if ( ! fuzzyEqual(_col.m_a, o._col.m_a, tol) ) return false;
+       return true;
+}
+
+std::ostream&
+operator<< (std::ostream& o, const FuzzyPixel& p)
+{
+       return o << "FuzzyPixel(" << p._col.toString() << ") [tol:" << p._tol 
<< "]";
+}
+
 } // namespace gnash

Index: testsuite/MovieTester.h
===================================================================
RCS file: /sources/gnash/gnash/testsuite/MovieTester.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- testsuite/MovieTester.h     18 Apr 2007 15:26:39 -0000      1.12
+++ testsuite/MovieTester.h     18 Apr 2007 17:28:13 -0000      1.13
@@ -23,6 +23,7 @@
 #include "Range2d.h"
 #include "gnash.h" // for namespace key
 #include "sound_handler_test.h" // for creating the "test" sound handler
+#include "types.h" // for rgba class
 
 #include <memory> // for auto_ptr
 #include <string> // for auto_ptr
@@ -37,6 +38,93 @@
 
 namespace gnash {
 
+/// An utility class used to compare rgba values with a given tolerance
+class FuzzyPixel
+{
+
+public:
+
+       friend std::ostream& operator<< (std::ostream& o, const FuzzyPixel& p);
+
+       /// Construct a black, alpha 0 FuzzyPixel with NO tolerance.
+       //
+       /// No tolerance means that any comparison will fail
+       ///
+       FuzzyPixel()
+               :
+               _col(0,0,0,0),
+               _tol(0)
+       {
+       }
+
+       /// Construct a FuzzyPixel with given color and tolerance
+       //
+       /// @param color
+       ///     The color value
+       ///
+       /// @param tolerance
+       ///     The tolerance to use in comparisons
+       ///
+       FuzzyPixel(rgba& color, int tolerance=0)
+               :
+               _col(color),
+               _tol(tolerance)
+       {
+       }
+
+       /// Construct a FuzzyPixel with given values
+       //
+       /// @param r
+       ///     The red value.
+       ///
+       /// @param g
+       ///     The green value.
+       ///
+       /// @param b
+       ///     The blue value.
+       ///
+       /// @param a
+       ///     The alpha value.
+       ///
+       FuzzyPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
+               :
+               _col(r, g, b, a),
+               _tol(0)
+       {
+       }
+
+       /// Set the tolerance to use in comparisons
+       //
+       /// @param tol
+       ///     The tolerance to use in comparisons
+       ///
+       void setTolerance(int tol)
+       {
+               _tol = tol;
+       }
+
+       /// Compare two FuzzyPixel using the tolerance of the most tolerant of 
the two
+       //
+       /// Note that if any of the two operands has 0 tolerance, any equality
+       /// comparison will fail.
+       ///
+       bool operator==(const FuzzyPixel& other) const;
+
+       // Return true if a and b are below a given tolerance
+       static bool fuzzyEqual(int a, int b, int tol)
+       {
+               return abs(a-b) <= tol;
+       }
+
+private:
+
+       rgba _col;
+
+       // tolerance value
+       int _tol;
+
+};
+
 /// An utility class for testing movie playback
 //
 /// This is a just born implementation and doesn't
@@ -88,6 +176,21 @@
        ///
        void movePointerTo(int x, int y);
 
+       /// Get the average pixel under the mouse pointer
+       //
+       /// @param radius
+       ///     Radius defining the average zone used.
+       ///     1 means a single pixel.
+       ///     Behaviour of passing 0 is undefined.
+       ///
+       /// @param tolerance
+       ///     The tolerance value to use for the returned FuzzyPixel.
+       ///
+       /// Note that if current pointer is outside of the rendered region
+       /// an intollerant FuzzyPixel is returned.
+       ///
+       FuzzyPixel getAveragePixel(unsigned radius, int tolerance) const;
+
        /// Notify mouse button was pressed
        void pressMouseButton();
 
@@ -133,6 +236,10 @@
        gnash::sprite_instance* _movie;
 
        std::auto_ptr<TEST_sound_handler> _sound_handler;
+
+       int _x;
+
+       int _y;
 };
 
 } // namespace gnash




reply via email to

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