cutter.cpp

Go to the documentation of this file.
00001 /* $Id: cutter.cpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2004 - 2008 by Philippe Plantier <ayin@anathas.org>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file tools/cutter.cpp
00016 //! Standalone-Utility for images / tiles
00017 
00018 #include "../sdl_utils.hpp"
00019 #include "../game_config.hpp"
00020 #include "exploder_utils.hpp"
00021 #include "exploder_composer.hpp"
00022 
00023 #include "SDL_image.h"
00024 
00025 namespace {
00026 
00027     void print_usage(std::string name)
00028     {
00029         std::cerr << "usage: " << name << " [source] [dest_directory]\n";
00030     }
00031 }
00032 
00033 int main(int argc, char* argv[])
00034 {
00035     std::string src;
00036     std::string dest_dir;
00037     cutter cut;
00038 
00039     // Parse arguments that shouldn't require a display device
00040     int arg;
00041     for(arg = 1; arg != argc; ++arg) {
00042         const std::string val(argv[arg]);
00043         if(val.empty()) {
00044             continue;
00045         }
00046 
00047         if(val == "--help" || val == "-h") {
00048             print_usage(argv[0]);
00049             return 0;
00050         } else if(val == "--verbose" || val == "-v") {
00051             cut.set_verbose(true);
00052         } else if(val == "--directory" || val == "-d" ) {
00053             game_config::path = argv[++arg];
00054         } else {
00055             if(src.empty()) {
00056                 src = val;
00057             } else if(dest_dir.empty()) {
00058                 dest_dir = val;
00059             } else {
00060                 print_usage(argv[0]);
00061                 return 1;
00062             }
00063         }
00064     }
00065 
00066     if(src.empty() || dest_dir.empty()) {
00067         print_usage(argv[0]);
00068         return 1;
00069     }
00070 
00071     try {
00072         const config conf = cut.load_config(src);
00073         cut.load_masks(conf);
00074 
00075         const surface src_surface(make_neutral_surface(IMG_Load(src.c_str())));
00076         if(src_surface == NULL)
00077             throw exploder_failure("Unable to load the source image " + src);
00078 
00079         const cutter::surface_map surfaces = cut.cut_surface(src_surface, conf);
00080 
00081         for(cutter::surface_map::const_iterator itor = surfaces.begin();
00082                 itor != surfaces.end(); ++itor) {
00083             const cutter::mask &mask = itor->second.mask;
00084 
00085             surface surf = surface(
00086                     create_compatible_surface(itor->second.image,
00087                     mask.cut.w, mask.cut.h));
00088 
00089             masked_overwrite_surface(surf, itor->second.image, mask.image,
00090                     mask.cut.x - mask.shift.x, mask.cut.y - mask.shift.y);
00091 
00092             save_image(surf, dest_dir + "/" + mask.name + ".png");
00093         }
00094 
00095     } catch(exploder_failure err) {
00096         std::cerr << "Failed: " << err.message << "\n";
00097     }
00098 }
00099 
00100 

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs