• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

tests/testDNG.cpp

00001 #include <FCam/Dummy.h>
00002 #include <stdio.h>
00003 
00004 int main(int argc, char **argv) {
00005 
00006     FCam::Dummy::Sensor sensor;
00007 
00008     FCam::Dummy::Shot shot;
00009     shot.testPattern = FCam::Dummy::CHECKERBOARD;
00010     shot.exposure = 5000;
00011     shot.gain = 1.0f;
00012     shot.image = FCam::Image(sensor.maxImageSize(), FCam::RAW);
00013     shot.histogram.enabled = true;
00014     shot.histogram.region = FCam::Rect(0,0,sensor.maxImageSize().width, sensor.maxImageSize().height);
00015     shot.sharpness.enabled = false;
00016 
00017     sensor.capture(shot);
00018     FCam::Dummy::Frame frame = sensor.getFrame();
00019 
00020     FCam::Event e;
00021     bool errors = false;
00022     if (FCam::getNextEvent(&e, FCam::Event::Error)) {
00023         do {
00024             if (e.type == FCam::Event::Error) {
00025                 errors = true;
00026                 printf("** FCam error [%d] %d at %s: %s\n", e.type, e.data, e.time.toString().c_str(), e.description.c_str());
00027             }
00028         } while (FCam::getNextEvent(&e, FCam::Event::Error));
00029         if (errors) {
00030             printf ("Error capturing a frame\n");
00031             return 1;
00032         }
00033     }
00034 
00035     frame["lens.aperture"] = 1.8f;
00036     frame["testInt"] = 1;
00037     frame["testFloat"] = 3.14159;
00038     frame["testTime"] = FCam::Time::now();
00039     std::vector<std::string> testStrings;
00040     testStrings.push_back("string1");
00041     testStrings.push_back("string2");
00042     testStrings.push_back("string3");
00043     testStrings.push_back("string4");
00044     frame["testStrings"] = testStrings;
00045 
00046 
00047     std::string test1DNGName("testDNG_1.dng");
00048     std::string test1DumpName("testDump_1.tmp");
00049     std::string test2DNGName("testDNG_2.dng");
00050     std::string test2DumpName("testDump_2.tmp");
00051     std::string test2DumpThumbName("testDumpThumb_2.tmp");
00052 
00053     FCAM_FRAME_DEBUG(frame);
00054 
00055     printf("Saving test frame dump as %s\n", test1DumpName.c_str());
00056     FCam::saveDump(frame, test1DumpName);
00057 
00058     printf("Saving test frame DNG as %s\n", test1DNGName.c_str());
00059 
00060     FCam::saveDNG(frame, test1DNGName);
00061     if (FCam::getNextEvent(&e, FCam::Event::Error)) {
00062         do {
00063             if (e.type == FCam::Event::Error) {
00064                 errors = true;
00065                 printf("** FCam error [%d] %d at %s: %s\n", e.type, e.data, e.time.toString().c_str(), e.description.c_str());
00066             }
00067         } while(FCam::getNextEvent(&e, FCam::Event::Error));
00068         if (errors) {
00069             printf("Error saving DNG, exiting.\n");
00070             return 1;
00071         }
00072     }
00073 
00074     printf("Loading back DNG\n");
00075     FCam::DNGFrame fLoaded = FCam::loadDNG(test1DNGName);
00076 
00077     FCAM_FRAME_DEBUG(fLoaded);
00078 
00079     if (!fLoaded.valid()) {
00080         printf("Error loading test DNG file. Listing all errors:\n");
00081 
00082         while (FCam::getNextEvent(&e, FCam::Event::Error)) {
00083             printf("** FCam error [%d] %d at %s: %s\n", e.type, e.data, e.time.toString().c_str(), e.description.c_str());
00084         }
00085         return 1;
00086     }
00087 
00088     printf("Saving loaded DNG as %s\n", test2DumpName.c_str());
00089     FCam::saveDump(fLoaded, test2DumpName);
00090     if (FCam::getNextEvent(&e, FCam::Event::Error)) {
00091         do {
00092             if (e.type == FCam::Event::Error) {
00093                 errors = true;
00094                 printf("** FCam error [%d] %d at %s: %s\n", e.type, e.data, e.time.toString().c_str(), e.description.c_str());
00095             }
00096         } while (FCam::getNextEvent(&e, FCam::Event::Error));
00097         if (errors) {
00098             printf ("Error saving JPEG.\n");
00099             return 1;
00100         }
00101     }
00102 
00103     printf("Saving loaded DNG thumbnail as %s\n", test2DumpThumbName.c_str());
00104     FCam::saveDump(fLoaded.thumbnail(), test2DumpThumbName);
00105     if (FCam::getNextEvent(&e, FCam::Event::Error)) {
00106         do {
00107             if (e.type == FCam::Event::Error) {
00108                 errors = true;
00109                 printf("** FCam error [%d] %d at %s: %s\n", e.type, e.data, e.time.toString().c_str(), e.description.c_str());
00110             }
00111         } while (FCam::getNextEvent(&e, FCam::Event::Error));
00112         if (errors) {
00113             printf ("Error saving JPEG.\n");
00114             return 1;
00115         }
00116     }
00117 
00118     printf("Saving loaded DNG as %s\n", test2DNGName.c_str());
00119     FCam::saveDNG(fLoaded, test2DNGName);
00120     if (FCam::getNextEvent(&e, FCam::Event::Error)) {
00121 
00122         do {
00123             if (e.type == FCam::Event::Error) {
00124                 errors = true;
00125                 printf("** FCam error [%d] %d at %s: %s\n", e.type, e.data, e.time.toString().c_str(), e.description.c_str());
00126             }
00127         } while (FCam::getNextEvent(&e, FCam::Event::Error));
00128         if (errors) {
00129             printf ("Error saving DNG again.\n");
00130             return 1;
00131         }
00132     }
00133 
00134     printf("Done with test. Compare two DNGs for equality.\n");
00135 
00136     return 0;
00137 }

Generated on Fri Sep 24 2010 15:53:00 for FCam by  doxygen 1.7.1