void ProcessImage(Image<Tout>& img_out, const Image<Tin>& img_in, bayer_method_t method, color_filter_t tile) { if(method == BAYER_METHOD_NONE) { PitchedImageCopy(img_out, img_in.template UnsafeReinterpret<Tout>() ); }else if(method == BAYER_METHOD_DOWNSAMPLE_MONO) { if( sizeof(Tout) == 1) { DownsampleToMono<int,Tout, Tin>(img_out, img_in); }else{ DownsampleToMono<double,Tout, Tin>(img_out, img_in); } }else if(method == BAYER_METHOD_DOWNSAMPLE) { DownsampleDebayer(img_out, img_in, tile); }else{ #ifdef HAVE_DC1394 if(sizeof(Tout) == 1) { dc1394_bayer_decoding_8bit( (uint8_t*)img_in.ptr, (uint8_t*)img_out.ptr, img_in.w, img_in.h, (dc1394color_filter_t)tile, (dc1394bayer_method_t)method ); }else if(sizeof(Tout) == 2) { dc1394_bayer_decoding_16bit( (uint16_t*)img_in.ptr, (uint16_t*)img_out.ptr, img_in.w, img_in.h, (dc1394color_filter_t)tile, (dc1394bayer_method_t)method, 16 ); } #endif } }
int main( int argc, char ** argv ) { uint32_t in_size=0, out_size=0, width=0, height=0, bpp=0; dc1394color_filter_t first_color = DC1394_COLOR_FILTER_RGGB; int tiff = 0; dc1394bayer_method_t method = DC1394_BAYER_METHOD_BILINEAR; char *infile=NULL, *outfile=NULL; int input_fd = 0; int output_fd = 0; void * bayer = NULL; void * rgb = NULL, *rgb_start = NULL; char c; int optidx = 0; int swap = 0; struct option longopt[] = { {"input",1,NULL,'i'}, {"output",1,NULL,'o'}, {"width",1,NULL,'w'}, {"height",1,NULL,'v'}, {"help",0,NULL,'h'}, {"bpp",1,NULL,'b'}, {"first",1,NULL,'f'}, {"method",1,NULL,'m'}, {"tiff",0,NULL,'t'}, {"swap",0,NULL,'s'}, {0,0,0,0} }; while ((c=getopt_long(argc,argv,"i:o:w:v:b:f:m:ths",longopt,&optidx)) != -1) { switch ( c ) { case 'i': infile = strdup( optarg ); break; case 'o': outfile = strdup( optarg ); break; case 'w': width = strtol( optarg, NULL, 10 ); break; case 'v': height = strtol( optarg, NULL, 10 ); break; case 'b': bpp = strtol( optarg, NULL, 10 ); break; case 'f': first_color = getFirstColor( optarg ); break; case 'm': method = getMethod( optarg ); break; case 's': swap = 1; break; case 't': tiff = TIFF_HDR_SIZE; break; case 'h': usage(argv[0]); return 0; break; default: printf("bad arg\n"); usage(argv[0]); return 1; } } // arguments: infile outfile width height bpp first_color if( infile == NULL || outfile == NULL || bpp == 0 || width == 0 || height == 0 ) { printf("Bad parameter\n"); usage(argv[0]); return 1; } input_fd = open(infile, O_RDONLY); if(input_fd < 0) { printf("Problem opening input: %s\n", infile); return 1; } output_fd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); if(output_fd < 0) { printf("Problem opening output: %s\n", outfile); return 1; } in_size = lseek(input_fd, 0, SEEK_END ); lseek(input_fd, 0, 0); out_size = width * height * (bpp / 8) * 3 + tiff; ftruncate(output_fd, out_size ); bayer = mmap(NULL, in_size, PROT_READ | PROT_WRITE, MAP_PRIVATE /*| MAP_POPULATE*/, input_fd, 0); if( bayer == MAP_FAILED ) { perror("Faild mmaping input"); return 1; } rgb_start = rgb = mmap(NULL, out_size, PROT_READ | PROT_WRITE, MAP_SHARED /*| MAP_POPULATE*/, output_fd, 0); if( rgb == MAP_FAILED ) { perror("Faild mmaping output"); return 1; } #ifdef DEBUG printf("%p -> %p\n", bayer, rgb); printf("%s: %s(%d) %s(%d) %d %d %d, %d %d\n", argv[0], infile, in_size, outfile, out_size, width, height, bpp, first_color, method ); //memset(rgb, 0xff, out_size);//return 1; #endif if(tiff) { rgb_start = put_tiff((uint8_t*)rgb, width, height, bpp); } #if 1 switch(bpp) { case 8: dc1394_bayer_decoding_8bit((const uint8_t*)bayer, (uint8_t*)rgb_start, width, height, first_color, method); break; case 16: dc1394_bayer_decoding_16bit((const uint16_t*)bayer, (uint16_t*)rgb_start, width, height, first_color, method, bpp); break; default: { uint8_t tmp=0; uint32_t i=0; for(i=0;i<in_size;i+=2){ tmp = *(((uint8_t*)bayer)+i); *(((uint8_t*)bayer)+i) = *(((uint8_t*)bayer)+i+1); *(((uint8_t*)bayer)+i+1) = tmp; } } dc1394_bayer_decoding_16bit((const uint16_t*)bayer, (uint16_t*)rgb_start, width, height, first_color, method, bpp); break; } #endif #if DEBUG printf("Last few In: %x %x %x %x\n", ((uint32_t*)bayer)[0], ((uint32_t*)bayer)[1], ((uint32_t*)bayer)[2], ((uint32_t*)bayer)[3]); // ((int*)rgb)[2] = 0xadadadad; printf("Last few Out: %x %x %x %x\n", ((uint32_t*)rgb)[0], ((uint32_t*)rgb)[1], ((uint32_t*)rgb)[2], ((uint32_t*)rgb)[3]); #endif munmap(bayer,in_size); close(input_fd); if( msync(rgb, out_size, MS_INVALIDATE|MS_SYNC) != 0 ) perror("Problem msyncing"); munmap(rgb,out_size); if( fsync(output_fd) != 0 ) perror("Problem fsyncing"); close(output_fd); return 0; }