ManaPlus
dyemain.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2018 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 
30 
31 #include "resources/image/image.h"
32 
33 #ifdef USE_SDL2
35 #endif // USE_SDL2
36 
38 
40 
41 #include "utils/cpu.h"
42 #include "utils/gettext.h"
43 #include "utils/pnglib.h"
44 #include "utils/sdlhelper.h"
45 
46 #include <iostream>
47 
48 #ifndef USE_SDL2
50 #endif // USE_SDL2
51 
52 PRAGMA48(GCC diagnostic push)
53 PRAGMA48(GCC diagnostic ignored "-Wshadow")
54 #include <SDL.h>
55 PRAGMA48(GCC diagnostic pop)
56 
57 #include "debug.h"
58 
59 static void printHelp()
60 {
61  // TRANSLATORS: command line help
62  std::cout << _("dyecmd srcfile dyestring dstfile") << std::endl;
63  // TRANSLATORS: command line help
64  std::cout << _("or") << std::endl;
65  // TRANSLATORS: command line help
66  std::cout << _("dyecmd srcdyestring dstfile") << std::endl;
67 }
68 
69 int main(int argc, char **argv)
70 {
71  if (argc == 2 && (strcmp(argv[1], "--help") != 0))
72  {
73  return mainGui(argc, argv);
74  }
75  if (argc < 3 || argc > 4)
76  {
77  printHelp();
78  return 1;
79  }
80 
81  logger = new Logger;
83 
84  VirtFs::init(argv[0]);
85  SDL_Init(SDL_INIT_VIDEO);
86 
87  Cpu::detect();
89 
90  graphicsManager.createWindow(10, 10, 0, SDL_ANYFORMAT);
91 
92 #ifdef USE_SDL2
94 #else // USE_SDL2
95 
97 #endif // USE_SDL2
98 
102  std::string src = argv[1];
103  std::string dst;
104  if (argc == 4)
105  {
106  src.append("|").append(argv[2]);
107  dst = argv[3];
108  }
109  else
110  {
111  dst = argv[2];
112  }
113 
114  Image *image = Loader::getImage(src);
115  if (image == nullptr)
116  {
117  printf("Error loading image\n");
118  VirtFs::deinit();
119  return 1;
120  }
121  SDL_Surface *const surface = ImageHelper::convertTo32Bit(
122  image->getSDLSurface());
123  PngLib::writePNG(surface, dst);
124  SDL_FreeSurface(surface);
125  image->decRef();
127  VirtFs::deinit();
128  return 0;
129 }
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 void initFunctions()
Definition: dyepalette.cpp:252
static SDL_Surface * convertTo32Bit(SDL_Surface *const tmpImage)
#define SurfaceImageHelper
Definition: sdlshared.h:61
Logger * logger
Definition: logger.cpp:88
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:59
#define PRAGMA48(str)
Definition: localconsts.h:198
const bool Append_false
Definition: append.h:29
bool setWriteDir(const std::string &newDir)
Definition: fs.cpp:330
void initLogger()
Definition: sdlhelper.cpp:186
void detect()
Definition: cpu.cpp:45
Definition: image.h:61
bool cleanOrphans(const bool always)
void init(const std::string &name)
Definition: fs.cpp:57
GraphicsManager graphicsManager
void decRef()
Definition: image.cpp:522
int main(int argc, char **argv)
Definition: dyemain.cpp:69