-
Notifications
You must be signed in to change notification settings - Fork 0
/
invert.cpp
79 lines (66 loc) · 2.18 KB
/
invert.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
#include "image.h"
#include <iostream>
void printTemplateForCorrectRequest()
{
std::cout << "Please, specify the correct request parameters shown below\n"
<< "[name of original jpeg file] [name of output jpeg file] [quality number - integer number between 0 and 100]" << std::endl;
}
int main( int argc, char* argv[] )
{
int QualityNumber = 50; // default
std::string nameOfOrig;
std::string nameOfSavedImg;
if (argc != 4)
{
printTemplateForCorrectRequest();
return 1;
}
else
{
std::vector<std::string> allArgs(argv + 1, argv + 4);
nameOfOrig = allArgs[0];
nameOfSavedImg = allArgs[1];
try
{
QualityNumber = std::stoi( allArgs[2] );
}
catch(std::invalid_argument& e){
// if no conversion could be performed
std::cout << "No conversion could be performed. No correct quality number specified\n";
printTemplateForCorrectRequest();
return 1;
}
catch(std::out_of_range& e){
// if the converted value would fall out of the range of the result type
std::cout << "The converted value fall out of the range of the result type. No correct quality number specified\n";
printTemplateForCorrectRequest();
return 1;
}
}
try
{
// Constructor expects a filename to load:
jpegImage::Image imgOriginal(nameOfOrig);
// for time tests
//jpegImage::Image copyOfOrig(imgOriginal);
// for time tests
//jpegImage::Image copyOfOrigForStdInvert(imgOriginal);
// Print some image info
imgOriginal.printImageProperties();
// image invert
imgOriginal.parallelInvert();
// for time tests
//copyOfOrig.invert();
// for time tests
//copyOfOrigForStdInvert.stdInvert();
// Save the image with new quality number
imgOriginal.save(nameOfSavedImg, QualityNumber);
return 0;
}
catch(const std::runtime_error& re)
{
std::cout << "runtime Main() error handler: ";
std::cout << re.what() << std::endl;
return 1;
}
}