ManaPlus
Functions
dyemain.cpp File Reference

(dc3c359)

#include "logger.h"
#include "graphicsmanager.h"
#include "maingui.h"
#include "sdlshared.h"
#include "fs/virtfs/fs.h"
#include "resources/image/image.h"
#include "resources/loaders/imageloader.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 64 of file dyemain.cpp.

References Append_false, ImageHelper::convertTo32Bit(), GraphicsManager::createWindow(), VirtFs::deinit(), Loader::getImage(), Image::getSDLSurface(), graphicsManager, imageHelper, VirtFs::init(), SDL::initLogger(), logger, mainGui(), VirtFs::mountDir(), printHelp(), VirtFs::setWriteDir(), SurfaceImageHelper, and PngLib::writePNG().

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
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
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

◆ printHelp()

static void printHelp ( )
static

Definition at line 54 of file dyemain.cpp.

References _.

Referenced by main().

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