Author: mordante
Date: Sat Mar 31 21:18:07 2012
New Revision: 53735

URL: http://svn.gna.org/viewcvs/wesnoth?rev=53735&view=rev
Log:
Add a count parameter to wesmage.

This lets the filter be applied to count surfaces. Not really practical
but nice for timing changes in an algorithm.

Modified:
    trunk/src/wesmage/options.cpp
    trunk/src/wesmage/options.hpp
    trunk/src/wesmage/wesmage.cpp

Modified: trunk/src/wesmage/options.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/options.cpp?rev=53735&r1=53734&r2=53735&view=diff
==============================================================================
--- trunk/src/wesmage/options.cpp (original)
+++ trunk/src/wesmage/options.cpp Sat Mar 31 21:18:07 2012
@@ -29,6 +29,7 @@
        , output_filename()
        , filters()
        , time(false)
+       , count(1)
 {
 }
 
@@ -118,6 +119,9 @@
 "-n, --dry-run           No output is written.\n"
 "-t, --time              Show the time it took to apply the filters.\n"
 "                        The resolution of the time depends on the platform.\n"
+"-c, --count COUNT       The number of times the filter needs to be applied.\n"
+"                        This feature is mainly for timing an algorithm and\n"
+"                        is applied on a new image every iteration.\n"
 "-f, --filter FILTER     Filters to be applied to the image. See FILTERS.\n"
 "-h, --help              Show this help and terminate the programme.\n"
 "\n"
@@ -169,6 +173,27 @@
                        dry_run = true;
                } else if(option == "-t" || option == "--time") {
                        result.time = true;
+               } else if(option == "-c" || option == "--count") {
+                       ++i;
+                       VALIDATE_NOT_PAST_END;
+
+                       char* end;
+                       result.count = strtol(argv[i], &end, 10);
+                       if(*end || result.count <= 0) {
+                               std::cerr << "Error: Parameter of count »"
+                                               << argv[i]
+                                               << "« should be a positive 
number.\n";
+                               print_help(EXIT_FAILURE);
+                       }
+               } else if(option.substr(0, 2) == "-c") {
+                       char* end;
+                       result.count = strtol(option.substr(2).c_str(), &end, 
10);
+                       if(*end || result.count <= 0) {
+                               std::cerr << "Error: Parameter of count »"
+                                               << option.substr(2).c_str()
+                                               << "« should be a positive 
number.\n";
+                               print_help(EXIT_FAILURE);
+                       }
                } else if(option == "-o" || option == "--output") {
                        ++i;
                        VALIDATE_NOT_PAST_END;

Modified: trunk/src/wesmage/options.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/options.hpp?rev=53735&r1=53734&r2=53735&view=diff
==============================================================================
--- trunk/src/wesmage/options.hpp (original)
+++ trunk/src/wesmage/options.hpp Sat Mar 31 21:18:07 2012
@@ -72,6 +72,13 @@
        /** Display the time that applying the filters took. */
        bool time;
 
+       /**
+        * The number of times the filter has to be applied.
+        *
+        * This feature is for performance testing only.
+        */
+       int count;
+
 private:
 
        /**

Modified: trunk/src/wesmage/wesmage.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/wesmage.cpp?rev=53735&r1=53734&r2=53735&view=diff
==============================================================================
--- trunk/src/wesmage/wesmage.cpp (original)
+++ trunk/src/wesmage/wesmage.cpp Sat Mar 31 21:18:07 2012
@@ -46,6 +46,15 @@
                        return EXIT_FAILURE;
                }
 
+               std::vector<surface> surfaces;
+               if(options.count != 1) {
+                       for(int i = 1; i < options.count; ++i) {
+                               // make_neutral_surface make a deep-copy of the 
image.
+                               surfaces.push_back(make_neutral_surface(surf));
+                       }
+               }
+               surfaces.push_back(surf);
+
                clock_t begin = std::clock();
                clock_t end = std::clock();
                if(options.time) {
@@ -61,8 +70,10 @@
                        begin = std::clock();
                }
 
-               BOOST_FOREACH(const std::string& filter, options.filters) {
-                       filter_apply(surf, filter);
+               for(int i = 0; i < options.count; ++i) {
+                       BOOST_FOREACH(const std::string& filter, 
options.filters) {
+                               filter_apply(surfaces[i], filter);
+                       }
                }
 
                end = std::clock();
@@ -75,7 +86,7 @@
                }
 
                if(!options.output_filename.empty()) {
-                       save_image(surf, options.output_filename);
+                       save_image(surfaces[0], options.output_filename);
                }
 
        } catch(const texit& exit) {


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to