ManaPlus
dyemain.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2017 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "logger.h"
22 
23 #include "graphicsmanager.h"
24 #include "maingui.h"
25 #include "sdlshared.h"
26 
27 #include "fs/virtfs/fs.h"
28 
29 #include "resources/image/image.h"
30 
31 #ifdef USE_SDL2
33 #endif // USE_SDL2
34 
36 
37 #include "utils/gettext.h"
38 #include "utils/pnglib.h"
39 #include "utils/sdlhelper.h"
40 
41 #include <iostream>
42 
43 #ifndef USE_SDL2
45 #endif // USE_SDL2
46 
47 PRAGMA48(GCC diagnostic push)
48 PRAGMA48(GCC diagnostic ignored "-Wshadow")
49 #include <SDL.h>
50 PRAGMA48(GCC diagnostic pop)
51 
52 #include "debug.h"
53 
54 static void printHelp()
55 {
56  // TRANSLATORS: command line help
57  std::cout << _("dyecmd srcfile dyestring dstfile") << std::endl;
58  // TRANSLATORS: command line help
59  std::cout << _("or") << std::endl;
60  // TRANSLATORS: command line help
61  std::cout << _("dyecmd srcdyestring dstfile") << std::endl;
62 }
63 
64 int main(int argc, char **argv)
65 {
66  if (argc == 2 && (strcmp(argv[1], "--help") != 0))
67  {
68  return mainGui(argc, argv);
69  }
70  if (argc < 3 || argc > 4)
71  {
72  printHelp();
73  return 1;
74  }
75 
76  logger = new Logger;
78 
79  VirtFs::init(argv[0]);
80  SDL_Init(SDL_INIT_VIDEO);
81 
82  graphicsManager.createWindow(10, 10, 0, SDL_ANYFORMAT);
83 
84 #ifdef USE_SDL2
86 #else // USE_SDL2
87 
89 #endif // USE_SDL2
90 
94  std::string src = argv[1];
95  std::string dst;
96  if (argc == 4)
97  {
98  src.append("|").append(argv[2]);
99  dst = argv[3];
100  }
101  else
102  {
103  dst = argv[2];
104  }
105 
106  Image *image = Loader::getImage(src);
107  if (image == nullptr)
108  {
109  printf("Error loading image\n");
110  VirtFs::deinit();
111  return 1;
112  }
113  SDL_Surface *const surface = ImageHelper::convertTo32Bit(
114  image->getSDLSurface());
115  PngLib::writePNG(surface, dst);
116  SDL_FreeSurface(surface);
117  VirtFs::deinit();
118  return 0;
119 }
Definition: logger.h:67
bool deinit()
Definition: fs.cpp:784
#define _(s)
Definition: gettext.h:34
SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
int mainGui(int argc, char *argv[])
Definition: maingui.cpp:107
bool mountDir(std::string newDir, const Append append)
Definition: fs.cpp:392
static SDL_Surface * convertTo32Bit(SDL_Surface *const tmpImage)
#define SurfaceImageHelper
Definition: sdlshared.h:61
Logger * logger
Definition: logger.cpp:95
SDL_Surface * getSDLSurface()
Definition: image.h:202
bool writePNG(SDL_Surface *const surface, const std::string &filename)
Definition: pnglib.cpp:36
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
static void printHelp()
Definition: dyemain.cpp:54
#define PRAGMA48(str)
Definition: localconsts.h:214
const bool Append_false
Definition: append.h:29
bool setWriteDir(const std::string &newDir)
Definition: fs.cpp:330
void initLogger()
Definition: sdlhelper.cpp:186
Definition: image.h:61
void init(const std::string &name)
Definition: fs.cpp:57
GraphicsManager graphicsManager
int main(int argc, char **argv)
Definition: dyemain.cpp:64