blob: 2c425e097fbcc0102cf950fbf28c0e84cf1a8fdd (
plain)
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
|
#include "common.hh"
#include "args.hh"
#include "image.hh"
#include <iostream>
#include <string>
#include <vector>
namespace {
std::ostream& operator<<(std::ostream& out, Location const& loc) {
if (loc.empty()) {
return out << "none";
}
return out << loc.lat << ' ' << loc.lng;
}
std::ostream& operator<<(std::ostream& out, Rotation const& rot) {
switch (rot) {
case Rotation::UNKNOWN:
break;
case Rotation::NONE:
return out << "None";
case Rotation::MIRRORED:
return out << "Mirrored";
case Rotation::ROTATED_180:
return out << "Rotated 180";
case Rotation::ROTATED_180_MIRRORED:
return out << "Rotated 180 Mirrored";
case Rotation::ROTATED_90:
return out << "Rotated 90";
case Rotation::ROTATED_90_MIRRORED:
return out << "Rotated 90 Mirrored";
case Rotation::ROTATED_270:
return out << "Rotated 270";
case Rotation::ROTATED_270_MIRRORED:
return out << "Rotated 270 Mirrored";
}
return out << "Unknown";
}
std::ostream& operator<<(std::ostream& out, Date const& date) {
if (date.empty())
return out << "none";
return out << date.to_format("%Y-%m-%d %H:%M");
}
constexpr const char kTryMessage[] = "Try `dump-image --help` for usage.";
} // namespace
int main(int argc, char** argv) {
auto args = Args::create();
auto* help_arg = args->add_option('h', "help", "display this text and exit.");
std::vector<std::string> arguments;
if (!args->run(argc, argv, "dump-image", std::cerr, &arguments)) {
std::cerr << kTryMessage << std::endl;
return EXIT_FAILURE;
}
if (help_arg->is_set()) {
std::cout << "Usage: `dump-image FILE...'\n"
<< "Dump image information about FILE.\n"
<< "\n"
<< "Options:\n";
args->print_descriptions(std::cout, 80);
return EXIT_SUCCESS;
}
bool good = true;
for (auto const& arg : arguments) {
if (arguments.size() > 1)
std::cout << arg << std::endl;
auto image = Image::load(arg);
if (image) {
std::cout << "Width: " << image->width() << std::endl;
std::cout << "Height: " << image->height() << std::endl;
std::cout << "Location: " << image->location() << std::endl;
std::cout << "Rotation: " << image->rotation() << std::endl;
std::cout << "Date: " << image->date() << std::endl;
} else {
std::cerr << "Failed to load " << arg << std::endl;
good = false;
}
}
return good ? EXIT_SUCCESS : EXIT_FAILURE;
}
|