The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
exploder_composer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004 - 2016 by Philippe Plantier <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "exploder_composer.hpp"
16 #include <SDL_image.h>
17 
18 #include <iostream>
19 
20 composer::composer() : interactive_(false), verbose_(false)
21 {
22 }
23 
24 
26 {
27  cutter cut;
28  cut.set_verbose(verbose_);
29 
30  const config src_conf = cut.load_config(src);
31  const config dest_conf = cut.load_config(dest);
32 
33  if(verbose_) {
34  std::cerr << "Loading masks...\n";
35  }
36  cut.load_masks(src_conf);
37  cut.load_masks(dest_conf);
38 
39  if(verbose_) {
40  std::cerr << "Loading images...\n";
41  }
42  const surface src_surface(make_neutral_surface(IMG_Load(src.c_str())));
43  if(src_surface == nullptr)
44  throw exploder_failure("Unable to load the source image " + src);
45 
46  const surface dest_surface(make_neutral_surface(IMG_Load(dest.c_str())));
47  if(dest_surface == nullptr)
48  throw exploder_failure("Unable to load the destination image " + dest);
49 
50  if(verbose_) {
51  std::cerr << "Cutting images...\n";
52  }
53  const cutter::surface_map src_surfaces = cut.cut_surface(src_surface, src_conf);
54  const cutter::surface_map dest_surfaces = cut.cut_surface(dest_surface, dest_conf);
55 
56  for(cutter::surface_map::const_iterator itor = dest_surfaces.begin();
57  itor != dest_surfaces.end(); ++itor) {
58 
59  const std::string& name = itor->second.name;
60 
61  if(src_surfaces.find(name) == src_surfaces.end())
62  continue;
63 
64  const cutter::positioned_surface& src_ps = src_surfaces.find(name)->second;
65  const cutter::positioned_surface& dest_ps = itor->second;
66 
67  if(!image_empty(dest_ps.image)) {
68  if(interactive_) {
69  //TODO: make "interactive" mode work
70  } else {
71  std::cerr << "Warning: element " << name << " not empty on destination image\n";
72  }
73  }
74  if(verbose_) {
75  std::cerr << "Inserting image " << name
76  << " on position (" << dest_ps.pos.x
77  << ", " << dest_ps.pos.y << ")\n";
78  }
79  masked_overwrite_surface(dest_surface, src_ps.image,
80  src_ps.mask.image,
81  dest_ps.pos.x, dest_ps.pos.y);
82  }
83 
84  return dest_surface;
85 }
86 
88 {
90 }
91 
93 {
94  verbose_ = value;
95 }
96 
void set_verbose(bool value)
surface compose(const std::string &src, const std::string &dest)
surface_map cut_surface(surface surf, const config &conf)
std::multimap< std::string, positioned_surface > surface_map
GLenum src
Definition: glew.h:2392
const config load_config(const std::string &filename)
void set_interactive(bool value)
void set_verbose(bool value)
void masked_overwrite_surface(surface dest, surface src, surface mask, int x, int y)
GLsizei const GLfloat * value
Definition: glew.h:1817
std::map< std::string, tfilter >::iterator itor
Definition: filter.cpp:199
GLuint const GLchar * name
Definition: glew.h:1782
surface make_neutral_surface(const surface &surf)
Definition: utils.cpp:135
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool image_empty(surface surf)
void load_masks(const config &conf)