00001 #include "FCam/FCam.h"
00002 #include <stdio.h>
00003 #include <math.h>
00004
00005 using namespace FCam;
00006
00007 Shot _shot;
00008
00009 float _colorMatrix[12] = {
00010 1, 0, 0, 0,
00011 0, 1, 0, 0,
00012 0, 0, 1, 0};
00013
00014 const std::string _string = "Test";
00015
00016 class TestFrame : public _Frame {
00017 public:
00018 const FCam::Shot &baseShot() const {return _shot;}
00019 FCam::BayerPattern bayerPattern() const {return FCam::GRBG;}
00020 unsigned short maxRawValue() const {return 1023;}
00021 void rawToRGBColorMatrix(int, float *m) const {
00022 for (int i = 0; i < 12; i++) m[i] = _colorMatrix[i];
00023 }
00024 const std::string &manufacturer() const {return _string;}
00025 const std::string &model() const {return _string;}
00026 };
00027
00028 int main(int argc, const char **argv) {
00029
00030 TestFrame *_f = new TestFrame;
00031 Frame f(_f);
00032
00033 printf("Testing demosaic results on a white jaggy circle\n");
00034 Image circle(128, 128, RAW);
00035 short *data = (short *)circle(0,0);
00036 for (int y = 0; y < 128; y++) {
00037 for (int x = 0; x < 128; x++) {
00038 bool in = ((x-64)*(x-64) + (y-64)*(y-64)) < 2500;
00039 *data++ = in ? 1023 : 0;
00040 }
00041 }
00042
00043 _f->image = circle;
00044 FCAM_IMAGE_DEBUG(f.image());
00045 saveDump(demosaic(f), "circle.tmp");
00046
00047 printf("Testing demosaic results on a white anti-aliased circle\n");
00048 data = (short *)circle(0,0);
00049 for (int y = 0; y < 128; y++) {
00050 for (int x = 0; x < 128; x++) {
00051 float d = sqrtf(((x-64)*(x-64) + (y-64)*(y-64)));
00052 *data++ = (d > 50 ? 0 : (d < 49 ? 1023 : (50 - d)*1023));
00053 }
00054 }
00055
00056 saveDump(circle, "circle_in.tmp");
00057 saveDump(demosaic(f), "circle_out.tmp");
00058
00059 printf("Testing demosaic on a subimage\n");
00060 Image canvas(200,200, RAW);
00061 for (int y=0; y < 200; y++) {
00062 for (int x=0; x < 200; x+=2) {
00063 ((short*)canvas(x,y))[0] = 0;
00064 ((short*)canvas(x,y))[1] = 1023;
00065 }
00066 }
00067 Image subCanvas = canvas.subImage(36,36,Size(128,128));
00068 subCanvas.copyFrom(circle);
00069 FCAM_IMAGE_DEBUG(canvas);
00070 FCAM_IMAGE_DEBUG(subCanvas);
00071 saveDump(canvas, "circle_canvas_in.tmp");
00072 saveDump(subCanvas, "circle_sub_in.tmp");
00073 saveDump(demosaic(f), "circle_sub.tmp");
00074
00075 printf("Testing demosaic speed\n");
00076
00077 Image in(64*40, 48*40, RAW);
00078
00079 _f->image = in;
00080
00081 Time t1 = Time::now();
00082
00083 for (int i = 0; i < 4; i++) {
00084 demosaic(f);
00085 }
00086
00087 printf("%d\n", (Time::now() - t1)/4000);
00088
00089 printf("Testing basic thumbnail generation \n");
00090
00091 Image in2(2592,1968, RAW);
00092 for (unsigned int y=0; y < in2.height()-1; y+=2) {
00093 for (unsigned int x=0; x < in2.width()-1; x+=2) {
00094 *((short*)in2(x,y)) = 500 * ((x / 50) % 2) * ((y / 50) % 2);
00095 *((short*)in2(x+1,y)) = 500 * ((x / 25) % 2) * ((y / 25) % 2);
00096 *((short*)in2(x,y+1)) = 500 * ((x / 100) % 2) * ((y / 100) % 2);
00097 *((short*)in2(x+1,y+1)) = 500 * ((x / 50) % 2) * ((y / 50) % 2);
00098 }
00099 }
00100 saveDump(in2, "thumb_in.tmp");
00101 _f->image = in2;
00102 saveDump(makeThumbnail(f), "thumb_out.tmp");
00103
00104 #ifdef FCAM_ARCH_ARM
00105 printf("Testing thumbnail speed, N900-asm 2592x1968 GRBG -> 640x480 \n");
00106
00107 _f->image = in2;
00108 Time t3 = Time::now();
00109 for (int i=0; i<10; i++) {
00110 makeThumbnail(f);
00111 }
00112 printf("%d\n", (Time::now() - t3)/10000);
00113 #endif
00114
00115 printf("Testing thumbnail speed, generic 2591x1967 GRBG -> 640x480 \n");
00116 Image in3(2591,1967, RAW);
00117 _f->image = in3;
00118 Time t2 = Time::now();
00119 for (int i=0; i<10; i++) {
00120 makeThumbnail(f);
00121 }
00122 printf("%d\n", (Time::now() - t2)/10000);
00123
00124
00125 return 0;
00126 };