-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.cpp
124 lines (108 loc) · 2.6 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <SDL.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <stdlib.h>
#include "ImageConverter.h"
#include "HelperFunctions.h"
using namespace std;
#ifdef main
#undef main
#endif
int main(int argc, char * argv[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
cout << "SDL initialization failed. SDL Error: " << SDL_GetError() << endl;
}
atexit(SDL_Quit);
string filename;
bool isProgramToBeClosed = false;
while (!isProgramToBeClosed)
{
validateFilename(filename);
ImageConverter converter(filename.c_str());
SDL_Color ** inputImage = create_two_dimensional_SDL_array(converter.imageWidth, converter.imageHeight);
copyCurrentSDLWindow(converter, inputImage, converter.imageWidth, converter.imageHeight);
char paletteChoice;
choosePalette(paletteChoice);
switch (paletteChoice)
{
case '1':
cout << "- Converting to imposed palette..." << endl << endl;
converter.predefinedTransform();
break;
case '2':
cout << "- Converting to dedicated palette..." << endl << endl;
converter.dedicatedTransform();
break;
case '3':
cout << "- Converting to grayscale palette..." << endl << endl;
converter.grayScaleTransform();
break;
default:
cout << "- Incorrect choice." << endl << endl;
break;
}
bool isDitheringChosen = false;
chooseDithering(isDitheringChosen);
if (isDitheringChosen)
{
cout << "- Processing dithering..." << endl << endl;
converter.dithering(inputImage, paletteChoice);
}
char saveOptionChoice;
bool isAveragePredictorChosen = false;
chooseSaveOption(saveOptionChoice, isAveragePredictorChosen);
switch (saveOptionChoice)
{
case '1':
cout << "- Saving to .bmp file. [result.bmp]" << endl << endl;
converter.saveToBmp("result.bmp");
break;
case '2':
cout << "- Saving to .karol file." << endl << endl;
break;
default:
cout << "- Image won't be saved." << endl << endl;
break;
}
displayFurtherInstructions();
// message processing loop
SDL_Event event;
bool isEventFired = false;
while (!isEventFired)
{
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
{
isEventFired = true;
isProgramToBeClosed = true;
break;
}
// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
{
isEventFired = true;
isProgramToBeClosed = true;
}
else if (event.key.keysym.sym == SDLK_n)
{
isEventFired = true;
}
break;
}
}
}
}
}
return 0;
}