ManaPlus
src
progs
dyecmd
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
30
#include "
resources/dye/dyepalette.h
"
31
32
#include "
resources/image/image.h
"
33
34
#ifdef USE_SDL2
35
#include "
resources/surfaceimagehelper.h
"
36
#endif
// USE_SDL2
37
38
#include "
resources/loaders/imageloader.h
"
39
40
#include "
resources/resourcemanager/resourcemanager.h
"
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
50
#include "
resources/sdlimagehelper.h
"
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
;
83
SDL::initLogger
();
84
85
VirtFs::init
(argv[0]);
86
SDL_Init(SDL_INIT_VIDEO);
87
88
Cpu::detect
();
89
DyePalette::initFunctions
();
90
91
GraphicsManager::createWindow
(10, 10, 0, SDL_ANYFORMAT);
92
93
#ifdef USE_SDL2
94
imageHelper
=
new
SurfaceImageHelper
;
95
#else
// USE_SDL2
96
97
imageHelper
=
new
SDLImageHelper
;
98
#endif
// USE_SDL2
99
100
VirtFs::setWriteDir
(
"."
);
101
VirtFs::mountDir
(
"."
,
Append_false
);
102
VirtFs::mountDir
(
"/"
,
Append_false
);
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();
127
ResourceManager::cleanOrphans
(
true
);
128
VirtFs::deinit
();
129
return
0;
130
}
Append_false
const bool Append_false
Definition:
append.h:30
DyePalette::initFunctions
static void initFunctions()
Definition:
dyepalette.cpp:253
GraphicsManager::createWindow
static SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
Definition:
graphicsmanager.cpp:640
ImageHelper::convertTo32Bit
static SDL_Surface * convertTo32Bit(SDL_Surface *const tmpImage)
Definition:
imagehelper.cpp:134
Image
Logger
Definition:
logger.h:69
SDLImageHelper
Definition:
sdlimagehelper.h:44
cpu.h
main
int main(int argc, char **argv)
Definition:
dyemain.cpp:70
printHelp
static void printHelp()
Definition:
dyemain.cpp:60
dyepalette.h
fs.h
gettext.h
_
#define _(s)
Definition:
gettext.h:35
graphicsmanager.h
image.h
imageHelper
ImageHelper * imageHelper
Definition:
imagehelper.cpp:44
imageloader.h
PRAGMA48
#define PRAGMA48(str)
Definition:
localconsts.h:199
logger
Logger * logger
Definition:
logger.cpp:89
logger.h
mainGui
int mainGui(int argc, char *argv[])
Definition:
maingui.cpp:142
maingui.h
Cpu::detect
void detect()
Definition:
cpu.cpp:46
Loader::getImage
Image * getImage(const std::string &idPath)
Definition:
imageloader.cpp:86
PngLib::writePNG
bool writePNG(SDL_Surface *const surface, const std::string &filename)
Definition:
pnglib.cpp:37
ResourceManager::cleanOrphans
bool cleanOrphans(const bool always)
Definition:
resourcemanager.cpp:227
SDL::initLogger
void initLogger()
Definition:
sdlhelper.cpp:187
VirtFs::deinit
bool deinit()
Definition:
fs.cpp:785
VirtFs::init
void init(const std::string &name)
Definition:
fs.cpp:58
VirtFs::setWriteDir
bool setWriteDir(const std::string &newDir)
Definition:
fs.cpp:331
VirtFs::mountDir
bool mountDir(std::string newDir, const Append append)
Definition:
fs.cpp:393
pnglib.h
resourcemanager.h
sdlhelper.h
sdlimagehelper.h
sdlshared.h
SurfaceImageHelper
#define SurfaceImageHelper
Definition:
sdlshared.h:62
surfaceimagehelper.h
Generated on Wed Mar 17 2021 19:19:09 for ManaPlus by
1.9.1