-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_loader.cc
156 lines (131 loc) · 5.26 KB
/
test_loader.cc
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define TINY_DNG_LOADER_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define TINY_DNG_NO_EXCEPTION
#include "tiny_dng_loader.h"
static char get_colorname(int c) {
switch (c) {
case 0:
return 'R';
case 1:
return 'G';
case 2:
return 'B';
case 3:
return 'C';
case 4:
return 'M';
case 5:
return 'Y';
case 6:
return 'W';
default:
return '?';
}
}
int main(int argc, char **argv) {
std::string input_filename = "colorchart.dng";
if (argc > 1) {
input_filename = std::string(argv[1]);
}
std::string warn, err;
std::vector<tinydng::DNGImage> images;
std::vector<tinydng::FieldInfo> custom_fields;
bool ret = tinydng::LoadDNG(input_filename.c_str(), custom_fields, &images, &warn, &err);
if (!warn.empty()) {
std::cout << "WARN: " << warn << std::endl;
}
if (!err.empty()) {
std::cout << "ERR: " << err;
}
if (ret) {
for (size_t i = 0; i < images.size(); i++) {
const tinydng::DNGImage &image = images[i];
;
std::cout << "width = " << image.width << std::endl;
std::cout << "height = " << image.height << std::endl;
std::cout << "bits per pixel = " << image.bits_per_sample << std::endl;
std::cout << "bits per pixel(original) = " << image.bits_per_sample_original << std::endl;
std::cout << "samples per piexl = " << image.samples_per_pixel << std::endl;
std::cout << "sample format = " << image.sample_format << std::endl;
std::cout << "version = " << image.version << std::endl;
for (int s = 0; s < image.samples_per_pixel; s++) {
std::cout << "white_level[" << s << "] = " << image.white_level[s] << std::endl;
std::cout << "black_level[" << s << "] = " << image.black_level[s] << std::endl;
}
std::cout << "tile_width = " << image.tile_width << std::endl;
std::cout << "tile_length = " << image.tile_length << std::endl;
std::cout << "cfa_layout = " << image.cfa_layout << std::endl;
std::cout << "cfa_plane_color = "
<< get_colorname(image.cfa_plane_color[0])
<< get_colorname(image.cfa_plane_color[1])
<< get_colorname(image.cfa_plane_color[2])
<< get_colorname(image.cfa_plane_color[3]) << std::endl;
std::cout << "cfa_pattern[2][2] = " << std::endl
<< image.cfa_pattern[0][0] << ", "
<< image.cfa_pattern[0][1] << std::endl
<< image.cfa_pattern[1][0] << ", "
<< image.cfa_pattern[1][1] << std::endl;
std::cout << "active_area = " << image.active_area[0] << ", "
<< image.active_area[1] << ", " << image.active_area[2]
<< ", " << image.active_area[3] << std::endl;
std::cout << "calibration_illuminant1 = "
<< image.calibration_illuminant1 << std::endl;
std::cout << "calibration_illuminant2 = "
<< image.calibration_illuminant2 << std::endl;
std::cout << "color_matrix1 = " << std::endl;
for (size_t k = 0; k < 3; k++) {
std::cout << image.color_matrix1[k][0] << " , "
<< image.color_matrix1[k][1] << " , "
<< image.color_matrix1[k][2] << std::endl;
}
std::cout << "color_matrix2 = " << std::endl;
for (size_t k = 0; k < 3; k++) {
std::cout << image.color_matrix2[k][0] << " , "
<< image.color_matrix2[k][1] << " , "
<< image.color_matrix2[k][2] << std::endl;
}
std::cout << "forward_matrix1 = " << std::endl;
for (size_t k = 0; k < 3; k++) {
std::cout << image.forward_matrix1[k][0] << " , "
<< image.forward_matrix1[k][1] << " , "
<< image.forward_matrix1[k][2] << std::endl;
}
std::cout << "forward_matrix2 = " << std::endl;
for (size_t k = 0; k < 3; k++) {
std::cout << image.forward_matrix2[k][0] << " , "
<< image.forward_matrix2[k][1] << " , "
<< image.forward_matrix2[k][2] << std::endl;
}
std::cout << "camera_calibration1 = " << std::endl;
for (size_t k = 0; k < 3; k++) {
std::cout << image.camera_calibration1[k][0] << " , "
<< image.camera_calibration1[k][1] << " , "
<< image.camera_calibration1[k][2] << std::endl;
}
std::cout << "camera_calibration2 = " << std::endl;
for (size_t k = 0; k < 3; k++) {
std::cout << image.camera_calibration2[k][0] << " , "
<< image.camera_calibration2[k][1] << " , "
<< image.camera_calibration2[k][2] << std::endl;
}
if (image.has_analog_balance) {
std::cout << "analog_balance = "
<< image.analog_balance[0] << " , "
<< image.analog_balance[1] << " , "
<< image.analog_balance[2] << std::endl;
}
if (image.has_as_shot_neutral) {
std::cout << "as_shot_neutral = "
<< image.as_shot_neutral[0] << " , "
<< image.as_shot_neutral[1] << " , "
<< image.as_shot_neutral[2] << std::endl;
}
}
} else {
std::cout << "Fail to load DNG " << input_filename << std::endl;
}
return EXIT_SUCCESS;
}