-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
59 lines (49 loc) · 1.42 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
// Convert an image input to ascii art
#include <iostream>
#include "display.hpp"
#include "codecs/image.hpp"
int main(int argc, char * argv[])
{
auto args = parse_args(argc, argv);
if(!args)
return EXIT_FAILURE;
try
{
auto img = get_image_data(*args);
if(args->get_image_count)
{
std::cout<<img->num_images()<<'\n';
return 0;
}
if(args->get_frame_count)
{
std::cout<<img->num_frames()<<'\n';
return 0;
}
if(!img->supports_multiple_images() && args->image_no > 0)
throw std::runtime_error{args->help_text + "\nImage type doesn't support multiple images"};
if(!img->supports_animation() && args->animate)
throw std::runtime_error{args->help_text + "\nImage type doesn't support animation"};
if(args->display)
display_image(*img, *args);
if(args->convert_filename)
{
if(args->frame_no)
img->get_frame(*args->frame_no).convert(*args);
else if(args->image_no)
img->get_image(*args->image_no).convert(*args);
else
img->convert(*args);
}
}
catch(Early_exit & e)
{
return EXIT_SUCCESS;
}
catch(const std::runtime_error & e)
{
std::cerr<<e.what()<<'\n';
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}