32 #include <boost/format.hpp>
33 #include <boost/lexical_cast.hpp>
35 #include <libopenraw/libopenraw.h>
37 #include "dumputils.hpp"
55 OrDiag(std::ostream & out,
const std::string & extract_thumbs,
bool dev_mode)
57 , m_extract_all_thumbs(false)
58 , m_dev_mode(dev_mode)
60 m_extract_all_thumbs = (extract_thumbs ==
"all");
61 if (!m_extract_all_thumbs) {
63 int size = boost::lexical_cast<int>(extract_thumbs);
64 m_thumb_sizes.insert(size);
80 const uint8_t* patternPattern
83 for(uint16_t i = 0; i < size; ++i) {
84 switch(patternPattern[i]) {
92 case OR_PATTERN_COLOUR_BLUE:
111 return "Non RGB 2x2";
113 case OR_CFA_PATTERN_RGGB:
116 case OR_CFA_PATTERN_GBRG:
119 case OR_CFA_PATTERN_BGGR:
122 case OR_CFA_PATTERN_GRBG:
128 return str(boost::format(
"Unknown %1%") % t);
134 case OR_DATA_TYPE_NONE:
138 return "8bits per channel RGB pixmap";
144 return "TIFF container";
147 return "PNG container";
153 return "Compressed RAW data";
155 case OR_DATA_TYPE_UNKNOWN:
156 return "Unknown type";
188 uint32_t dim = std::max(x, y);
189 std::string name(str(boost::format(
"thumb_%1%.%2%") % dim % ext));
190 f = fopen(name.c_str(),
"wb");
194 fprintf(f,
"%d %d\n", x, y);
195 fprintf(f,
"%d\n", 0xff);
200 std::cerr <<
"short write of " << s <<
" bytes\n";
213 m_out << boost::format(
"\tNumber of previews: %1%\n")
216 m_out <<
"\tAvailable previews:\n";
217 for(
size_t i = 0; i < size; i++) {
219 m_out << boost::format(
"\t\tSize %1%\n") % previews[i];
224 m_out << boost::format(
"\t\t\tError getting thumbnail %1%\n") % err;
227 m_out << boost::format(
"\t\t\tFormat %1%\n")
231 m_out << boost::format(
"\t\t\tDimensions: width = %1% height = %2%\n")
233 m_out << boost::format(
"\t\t\tByte size: %1%\n")
236 if (m_extract_all_thumbs
237 || m_thumb_sizes.find(previews[i]) != m_thumb_sizes.end()) {
241 m_out << boost::format(
"\t\t\tOutput as %1%\n") % name;
252 m_out <<
"\tRAW data\n";
254 m_out << boost::format(
"\t\tType: %1%")
255 % dataTypeToString(dataType);
257 m_out << boost::format(
" (compression = %1%)\n")
263 m_out << boost::format(
"\t\tByte size: %1%\n")
267 m_out << boost::format(
"\t\tDimensions: width = %1% height = %2%\n")
271 uint32_t aa_x, aa_y, aa_width, aa_height;
273 &aa_width, &aa_height);
275 boost::format(
"\t\tActive Area (x,y,w,h): %1% %2% %3% %4%\n")
276 % aa_x % aa_y % aa_width % aa_height;
283 m_out << boost::format(
"\t\tBayer Type: %1%\n")
284 % cfaPatternToString(patternType);
287 m_out << boost::format(
"\t\tPattern: %1%\n")
288 % cfaPatternToString(pattern);
291 m_out << boost::format(
"\t\tBits per channel: %1%\n")
293 uint16_t black, white;
295 m_out << boost::format(
296 "\t\tValues: black = %1% white = %2%\n") % black % white;
298 uint32_t matrix_size = 0;
301 m_out << boost::format(
"\t\tColour Matrix 1: ");
302 for (uint32_t i = 0; i < matrix_size; i++) {
312 m_out << boost::format(
"\tNo Raw Data found! (error = %1%)\n")
320 m_out <<
"\tMeta data\n";
321 m_out <<
"\t\tMakerNotes\n";
325 m_out <<
"\t\t\tNo MakerNote found!\n";
327 const char* makernote_id = or_ifd_get_makernote_id(mnote);
328 m_out << boost::format(
"\t\t\tType = %1%\n")
329 % (makernote_id ? makernote_id :
"(null)");
330 auto num_entries = or_ifd_count_tags(mnote);
331 m_out << boost::format(
"\t\t\tNum entries = %1%\n")
333 or_ifd_release(mnote);
336 m_out << boost::format(
"\t\tOrientation: %1%\n")
354 m_out << boost::format(
"\t\tColour Matrix Origin: %1%\n")
357 ExifLightsourceValue calIll;
359 m_out << boost::format(
"\t\tCalibration Illuminant 1: %1%\n")
360 %
static_cast<int>(calIll);
365 std::vector<int64_t> int_matrix;
366 std::transform(&matrix[0], &matrix[9], std::back_inserter(int_matrix),
367 [](
double v) -> int64_t {
return rintl(v * 10000.0); });
368 m_out << boost::format(
"\t\tColour Matrix 1: %1%, %2%, %3%, "
369 "%4%, %5%, %6%, %7%, %8%, %9%\n")
370 % int_matrix[0] % int_matrix[1] % int_matrix[2]
371 % int_matrix[3] % int_matrix[4] % int_matrix[5]
372 % int_matrix[6] % int_matrix[7] % int_matrix[8];
374 m_out << boost::format(
"\t\tColour Matrix 1: %1%, %2%, %3%, "
375 "%4%, %5%, %6%, %7%, %8%, %9%\n")
376 % matrix[0] % matrix[1] % matrix[2]
377 % matrix[3] % matrix[4] % matrix[5]
378 % matrix[6] % matrix[7] % matrix[8];
382 m_out <<
"\t\tNo Colour Matrix 1\n";
386 m_out << boost::format(
"\t\tCalibration Illuminant 2: %1%\n")
387 %
static_cast<int>(calIll);
393 std::vector<int64_t> int_matrix;
394 std::transform(&matrix[0], &matrix[9], std::back_inserter(int_matrix),
395 [](
double v) -> int64_t {
return rintl(v * 10000.0); });
396 m_out << boost::format(
"\t\tColour Matrix 2: %1%, %2%, %3%, "
397 "%4%, %5%, %6%, %7%, %8%, %9%\n")
398 % int_matrix[0] % int_matrix[1] % int_matrix[2]
399 % int_matrix[3] % int_matrix[4] % int_matrix[5]
400 % int_matrix[6] % int_matrix[7] % int_matrix[8];
403 m_out << boost::format(
"\t\tColour Matrix 2: %1%, %2%, %3%, "
404 "%4%, %5%, %6%, %7%, %8%, %9%\n")
405 % matrix[0] % matrix[1] % matrix[2]
406 % matrix[3] % matrix[4] % matrix[5]
407 % matrix[6] % matrix[7] % matrix[8];
411 m_out <<
"\t\tNo Colour Matrix 2\n";
414 void operator()(
const std::string &s)
416 m_out << boost::format(
"Dumping %1%\n") % s;
423 m_out <<
"unrecognized file\n";
435 std::ostream & m_out;
436 bool m_extract_all_thumbs;
438 std::set<int> m_thumb_sizes;
444 std::cerr <<
"ordiag [-v] [-h] [-t all|<size>] [-d 0-9] [files...]\n";
445 std::cerr <<
"Print libopenraw diagnostics\n";
446 std::cerr <<
"\t-h: show this help\n";
447 std::cerr <<
"\t-D: developer mode: display some data a format suited for development\n";
448 std::cerr <<
"\t-v: show version\n";
449 std::cerr <<
"\t-d level: set debug / verbosity to level\n";
450 std::cerr <<
"\t-t [all|<size>]: extract thumbnails. all or <size>.\n";
451 std::cerr <<
"\tfiles: the files to diagnose\n";
456 std::cerr <<
"ordiag version 0.1 - (c) 2007-2014 Hubert Figuiere\n";
461 int main(
int argc,
char **argv)
465 bool dev_mode =
false;
466 std::string extract_thumbs;
467 std::vector<std::string> files;
470 while((o = getopt(argc, argv,
"hvdDt:")) != -1) {
488 extract_thumbs = optarg;
504 for ( ; optind < argc; optind++) {
505 files.push_back(argv[optind]);
509 std::cerr <<
"missing file name.\n";
521 for_each(files.begin(), files.end(),
OrDiag(std::cout, extract_thumbs, dev_mode));
Dump a RawFile. (functor)
std::string extractThumb(ORThumbnailRef thumb)
Extract thumbnail to a file.
OrDiag(std::ostream &out, const std::string &extract_thumbs, bool dev_mode)
Constructor.
void dumpPreviews(ORRawFileRef rf)
Dump the previews of the raw file to the output stream.
API_EXPORT or_cfa_pattern or_mosaicinfo_get_type(ORMosaicInfoRef pattern)
Get the type of the mosaic.
const struct _MosaicInfo * ORMosaicInfoRef
A MosaicInfo object.
API_EXPORT const uint8_t * or_mosaicinfo_get_pattern(ORMosaicInfoRef pattern, uint16_t *count)
Get the pattern.
struct _RawData * ORRawDataRef
RawData reference.
or_cfa_pattern
CFA pattern types.
API_EXPORT void or_debug_set_level(debug_level lvl)
Set the debug level.
struct _RawFile * ORRawFileRef
RawFile reference.
struct _Thumbnail * ORThumbnailRef
Thumbnail reference.
or_error
Error codes returned by libopenraw.
@ OR_CFA_PATTERN_NON_RGB22
@ OR_DATA_TYPE_COMPRESSED_RAW
@ OR_DATA_TYPE_PIXMAP_8RGB
@ OR_PATTERN_COLOUR_GREEN
@ OR_RAWFILE_TYPE_UNKNOWN
@ OR_COLOUR_MATRIX_BUILTIN
@ OR_COLOUR_MATRIX_PROVIDED
API_EXPORT ORIfdDirRef or_rawfile_get_ifd(ORRawFileRef rawfile, or_ifd_dir_type ifd)
Get an IFD directory.
API_EXPORT or_error or_rawfile_release(ORRawFileRef rawfile)
Release the RawFile.
API_EXPORT or_colour_matrix_origin or_rawfile_get_colour_matrix_origin(ORRawFileRef rawfile)
Get the colour matrix origin for file.
API_EXPORT ExifLightsourceValue or_rawfile_get_calibration_illuminant2(ORRawFileRef rawfile)
Get calibration illuminant for the second colour matrix.
API_EXPORT ORRawFileRef or_rawfile_new(const char *filename, or_rawfile_type type)
Create a new RawFile object from a file.
API_EXPORT or_error or_rawfile_get_colourmatrix2(ORRawFileRef rawfile, double *matrix, uint32_t *size)
Get the second colour matrix.
API_EXPORT or_error or_rawfile_get_colourmatrix1(ORRawFileRef rawfile, double *matrix, uint32_t *size)
Get the first colour matrix.
API_EXPORT const uint32_t * or_rawfile_get_thumbnail_sizes(ORRawFileRef rawfile, size_t *size)
Get the the array of thumbnail sizes.
API_EXPORT or_error or_rawfile_get_thumbnail(ORRawFileRef rawfile, uint32_t _preferred_size, ORThumbnailRef thumb)
Get a thumbnail from a RawFile..
API_EXPORT int32_t or_rawfile_get_orientation(ORRawFileRef rawfile)
Get the orientation.
API_EXPORT or_error or_rawfile_get_rawdata(ORRawFileRef rawfile, ORRawDataRef rawdata, uint32_t options)
Get the RawData out of the RawFile.
API_EXPORT ExifLightsourceValue or_rawfile_get_calibration_illuminant1(ORRawFileRef rawfile)
Get calibration illuminant for the first colour matrix.
API_EXPORT void or_rawdata_dimensions(ORRawDataRef rawdata, uint32_t *width, uint32_t *height)
Get the RAW data dimensions in pixels.
API_EXPORT ORRawDataRef or_rawdata_new(void)
Allocate a new RawData.
API_EXPORT const double * or_rawdata_get_colour_matrix(ORRawDataRef rawdata, uint32_t index, uint32_t *size)
Get the colour matrix.
API_EXPORT or_error or_rawdata_get_levels(ORRawDataRef rawdata, uint16_t *black, uint16_t *white)
Return the levels values for the raw data.
API_EXPORT uint32_t or_rawdata_bpc(ORRawDataRef rawdata)
Return the bits per component.
API_EXPORT or_error or_rawdata_get_active_area(ORRawDataRef rawdata, uint32_t *x, uint32_t *y, uint32_t *width, uint32_t *height)
Get the active area for the raw data.
API_EXPORT size_t or_rawdata_data_size(ORRawDataRef rawdata)
Get the size of the RAW data in bytes.
API_EXPORT uint32_t or_rawdata_get_compression(ORRawDataRef rawdata)
Return the compression type for the RawData.
API_EXPORT ORMosaicInfoRef or_rawdata_get_mosaicinfo(ORRawDataRef rawdata)
Return the mosaic info.
API_EXPORT or_data_type or_rawdata_format(ORRawDataRef rawdata)
Get the format of the RAW data.
API_EXPORT or_error or_rawdata_release(ORRawDataRef rawdata)
Release the rawdata.
API_EXPORT ORThumbnailRef or_thumbnail_new(void)
Allocate a Thumbnail object.
API_EXPORT size_t or_thumbnail_data_size(ORThumbnailRef thumb)
Get the data size.
API_EXPORT void or_thumbnail_dimensions(ORThumbnailRef thumb, uint32_t *width, uint32_t *height)
Get the Thumbnail dimensions in pixels.
API_EXPORT or_data_type or_thumbnail_format(ORThumbnailRef thumb)
Get the thumbnail format.
API_EXPORT void * or_thumbnail_data(ORThumbnailRef thumb)
Get the pointer to the data.
API_EXPORT or_error or_thumbnail_release(ORThumbnailRef thumb)
Release a Thumbnail object.