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