tools/cutter.cpp

Go to the documentation of this file.
00001 /* $Id: cutter.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2004 - 2012 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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * @file
00018  * Standalone-Utility for images / tiles
00019  */
00020 
00021 #include "../game_config.hpp"
00022 #include "exploder_composer.hpp"
00023 
00024 #include "SDL_image.h"
00025 
00026 #include <iostream>
00027 
00028 namespace {
00029 
00030     void print_usage(std::string name)
00031     {
00032         std::cerr << "usage: " << name << " [source] [dest_directory]\n";
00033     }
00034 }
00035 
00036 int main(int argc, char* argv[])
00037 {
00038     std::string src;
00039     std::string dest_dir;
00040     cutter cut;
00041 
00042     // Parse arguments that shouldn't require a display device
00043     int arg;
00044     for(arg = 1; arg != argc; ++arg) {
00045         const std::string val(argv[arg]);
00046         if(val.empty()) {
00047             continue;
00048         }
00049 
00050         if(val == "--help" || val == "-h") {
00051             print_usage(argv[0]);
00052             return 0;
00053         } else if(val == "--verbose" || val == "-v") {
00054             cut.set_verbose(true);
00055         } else if(val == "--directory" || val == "-d" ) {
00056             game_config::path = argv[++arg];
00057         } else {
00058             if(src.empty()) {
00059                 src = val;
00060             } else if(dest_dir.empty()) {
00061                 dest_dir = val;
00062             } else {
00063                 print_usage(argv[0]);
00064                 return 1;
00065             }
00066         }
00067     }
00068 
00069     if(src.empty() || dest_dir.empty()) {
00070         print_usage(argv[0]);
00071         return 1;
00072     }
00073 
00074     try {
00075         const config conf = cut.load_config(src);
00076         cut.load_masks(conf);
00077 
00078         const surface src_surface(make_neutral_surface(IMG_Load(src.c_str())));
00079         if(src_surface == NULL)
00080             throw exploder_failure("Unable to load the source image " + src);
00081 
00082         const cutter::surface_map surfaces = cut.cut_surface(src_surface, conf);
00083 
00084         for(cutter::surface_map::const_iterator itor = surfaces.begin();
00085                 itor != surfaces.end(); ++itor) {
00086             const cutter::mask &mask = itor->second.mask;
00087 
00088             surface surf = surface(
00089                     create_compatible_surface(itor->second.image,
00090                     mask.cut.w, mask.cut.h));
00091 
00092             masked_overwrite_surface(surf, itor->second.image, mask.image,
00093                     mask.cut.x - mask.shift.x, mask.cut.y - mask.shift.y);
00094 
00095             save_image(surf, dest_dir + "/" + mask.name + ".png");
00096         }
00097 
00098     } catch(exploder_failure& err) {
00099         std::cerr << "Failed: " << err.message << "\n";
00100         return 1;
00101     }
00102 
00103     return 0;
00104 }
00105 
00106 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:54 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs