Go to the documentation of this file.00001
00002
00003
00004
00005 #include <FCam/FCam.h>
00006 #include <stdio.h>
00007
00008 void usage() {
00009 printf("updateDNG\n"
00010 " A simply utility to update DNGs saved by programs using\n"
00011 " the FCam API to the latest metadata available.\n\n"
00012
00013 "Usage: updateDNG [FLAGS] INPUT [OUTPUT].\n"
00014 " With no output name given, adds .up. before the .dng extension to\n"
00015 " the input to create the output name.\n"
00016 "Flags:\n"
00017 " -i Dump out information about the DNG contents\n"
00018 " -n Don't actually write output (useful with -i)\n"
00019 "\n");
00020 exit(1);
00021 }
00022
00023 int main(int argc, char **argv) {
00024 if (argc < 2) {
00025 usage();
00026 }
00027 bool dumpFrame = false;
00028 bool writeOutput = true;
00029
00030 bool doneWithFlags = false;
00031 int argIndex=1;
00032 for (; argIndex < argc; argIndex++) {
00033 if (argv[argIndex][0] == '-') {
00034 switch (argv[argIndex][1]) {
00035 case 'i':
00036 dumpFrame = true;
00037 break;
00038 case 'n':
00039 writeOutput = false;
00040 break;
00041 default:
00042 doneWithFlags = true;
00043 break;
00044 }
00045 } else {
00046 doneWithFlags = true;
00047 }
00048
00049 if (doneWithFlags) break;
00050 }
00051
00052 if (argIndex == argc) {
00053 printf("Error: No input file given!\n");
00054 usage();
00055 }
00056
00057 std::string inputFile(argv[argIndex]);
00058
00059 std::string outputFile;
00060 if (argIndex < argc -1 ) {
00061 outputFile = std::string(argv[argIndex+1]);
00062 } else {
00063 outputFile = inputFile.substr(0,inputFile.rfind(".dng"));
00064 outputFile.append(".up.dng");
00065 }
00066
00067 FCam::Event e;
00068
00069 printf("Reading input DNG %s\n", inputFile.c_str());
00070
00071 FCam::DNGFrame f = FCam::loadDNG(inputFile);
00072
00073 if (FCam::_eventQueue.size() > 0) {
00074 printf("Events reported while loading DNG:\n");
00075 while (getNextEvent(&e)) {
00076 switch (e.type) {
00077 case FCam::Event::Error:
00078 printf(" Error code: %d. Description: %s\n", e.data, e.description.c_str());
00079 break;
00080 case FCam::Event::Warning:
00081 printf(" Warning code: %d. Description: %s\n", e.data, e.description.c_str());
00082 break;
00083 default:
00084 printf(" Event type %d, code: %d. Description: %s\n", e.type, e.data, e.description.c_str());
00085 break;
00086 }
00087 }
00088 }
00089
00090 if (!f.valid()) {
00091 printf("Fatal Error: Unable to read input file %s\n", inputFile.c_str());
00092 exit(1);
00093 }
00094
00095 if (dumpFrame) {
00096 f.debug(inputFile.c_str());
00097 }
00098
00099 if (writeOutput) {
00100 printf("Writing output to %s\n", outputFile.c_str());
00101 FCam::saveDNG(f, outputFile);
00102
00103 if (FCam::_eventQueue.size() > 0) {
00104 printf("Events reported while saving to %s:\n", outputFile.c_str());
00105 while (getNextEvent(&e)) {
00106 switch (e.type) {
00107 case FCam::Event::Error:
00108 printf(" Error code: %d. Description: %s\n", e.data, e.description.c_str());
00109 break;
00110 case FCam::Event::Warning:
00111 printf(" Warning code: %d. Description: %s\n", e.data, e.description.c_str());
00112 break;
00113 default:
00114 printf(" Event type %d, code: %d. Description: %s\n", e.type, e.data, e.description.c_str());
00115 break;
00116 }
00117 }
00118 }
00119 }
00120 return 0;
00121 }