ManaPlus
Functions
dyemain.cpp File Reference

(501c48e)

#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 69 of file dyemain.cpp.

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

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

◆ printHelp()

static void printHelp ( )
static

Definition at line 59 of file dyemain.cpp.

References _.

Referenced by main().

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