ManaPlus
Functions
dyemain.cpp File Reference

(986a3bf)

#include "logger.h"
#include "graphicsmanager.h"
#include "maingui.h"
#include "sdlshared.h"
#include "fs/virtfs/fs.h"
#include "resources/dye/dyepalette.h"
#include "resources/image/image.h"
#include "resources/loaders/imageloader.h"
#include "resources/resourcemanager/resourcemanager.h"
#include "utils/cpu.h"
#include "utils/gettext.h"
#include "utils/pnglib.h"
#include "utils/sdlhelper.h"
#include <iostream>
#include "resources/sdlimagehelper.h"
#include <SDL.h>
#include "debug.h"

Go to the source code of this file.

Functions

static void printHelp ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

< Allow any video depth/pixel-format

Definition at line 70 of file dyemain.cpp.

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
static void printHelp()
Definition: dyemain.cpp:60
ImageHelper * imageHelper
Definition: imagehelper.cpp:44
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

References Append_false, ResourceManager::cleanOrphans(), ImageHelper::convertTo32Bit(), GraphicsManager::createWindow(), VirtFs::deinit(), Cpu::detect(), Loader::getImage(), imageHelper, VirtFs::init(), DyePalette::initFunctions(), SDL::initLogger(), logger, mainGui(), VirtFs::mountDir(), printHelp(), VirtFs::setWriteDir(), SurfaceImageHelper, and PngLib::writePNG().

◆ printHelp()

static void printHelp ( )
static

Definition at line 60 of file dyemain.cpp.

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 }
#define _(s)
Definition: gettext.h:35

References _.

Referenced by main().