The takePicture rawCallback returns a null pointer. The getPictureFormat only allows for .jpg. While the jpeg can be improved with getParameters() setJpegQuality(100) setPar
//Ugly code to convert bayer to rgb
//test__1604x1206_10_2b.raw
//test__1284x966_10_3.raw
#include
unsigned short int bayerImage[2500][3500]; //times 3 allows for forming an RGB image for debugging
unsigned char bmpImage[30000000]; //times 3 allows for forming an RGB image for debugging
#include
#include
#include "bayer2rgb.h"
#include
#include
/*****************************************************************************
**
*/
int DumpImage( char* pszFilename, BYTE* pImage, int bmpWidth, int bmpHeight,int bmpBits,int bmpFormat)
{
FILE *bayerFile;
FILE *rgbFile;
int x,y;
unsigned char lowOrder,highOrder;
unsigned char bmpchar;
unsigned short bayerVal;
unsigned char bmpheader[62];
char FullFilename[MY_MAX_PATH];
unsigned int bmrgbFilesize;
unsigned int minPixel=100000;
unsigned int maxPixel=0;
static unsigned int rgbValues[4][1024];
/*expecting 10 bit bayer */
if(bmpBits!=10)
{
printf("invalid bit specification\n");
return(-1);
}
if(bmpHeight >= 0)
{
bmrgbFilesize = (((bmpWidth*24+31)/32)*4)*bmpHeight;
}
else
{
bmrgbFilesize = (((bmpWidth*24+31)/32)*4)*(-bmpHeight);
}
#ifdef LINUX
strcpy( FullFilename, pszFilename );
rgbFile = fopen( FullFilename, "w+b" );
if( rgbFile )
#else
strcpy_s( FullFilename, sizeof(FullFilename), pszFilename );
errno_t errno;
errno = fopen_s( &bayerFile, FullFilename, "r+b" );
if(errno == 0)
{
printf("size %d", strlen(FullFilename)-4);
memcpy(&FullFilename[strlen(FullFilename)-4],".bmp",4);
errno = fopen_s( &rgbFile, FullFilename, "w+b" );
}
if ( errno == 0 )
#endif
{
/* 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 */
/* 0 R G R G R G 0 G R G R G R 0 B G B G B G */
/* 1 G B G B G B 1 B G B G B G 1 G R G R G R */
/* 2 R G R G R G 2 G R G R G R 2 B G B G B G */
/* 3 G B G B G B 3 B G B G B G 3 G R G R G R */
memset(bmpImage,255,sizeof(bmpImage));
switch(bmpFormat)
{
case 2:
// 0 1 2 3 4 5
// 0 G R G R G R
// 1 B G B G B G
// 2 G R G R G R
// 3 B G B G B G
for(y=0;ymaxPixel)
{
maxPixel=bayerVal;
}
if(y%2==0)
{
if(x%2==0)
{
//green
bayerImage[y][x]=bayerVal/2;
//if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.65;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[0][bayerVal]++;
}
else
{
//red
bayerImage[y][x]=bayerVal/2;
//if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.85;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[1][bayerVal]++;
}
}
else
{
if(x%2==0)
{
//blue
bayerImage[y][x]=bayerVal/2;
//if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.85;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[2][bayerVal]++;
}
else
{
//green
bayerImage[y][x]=bayerVal/2;
//if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.65;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[3][bayerVal]++;
}
}
}
}
for(y=1;ymaxPixel)
{
maxPixel=bayerVal;
}
if(y%2==0)
{
if(x%2==0)
{
//red
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.85;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[1][bayerVal]++;
}
else
{
//green
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
bayerImage[y][x]*=.65;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[0][bayerVal]++;
}
}
else
{
if(x%2==0)
{
//green
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
bayerImage[y][x]*=.65;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[3][bayerVal]++;
}
else
{
//blue
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.85;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[2][bayerVal]++;
}
}
}
}
for(y=1;ymaxPixel)
{
maxPixel=bayerVal;
}
if(y%2==0)
{
if(x%2==0)
{
//green
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
bayerImage[y][x]*=.65;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[0][bayerVal]++;
}
else
{
//red
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.85;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[1][bayerVal]++;
}
}
else
{
if(x%2==0)
{
//blue
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
//bayerImage[y][x]*=.85;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[2][bayerVal]++;
}
else
{
//green
bayerImage[y][x]=bayerVal;
if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
bayerImage[y][x]*=.65;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[3][bayerVal]++;
}
}
}
}
for(y=1;ymaxPixel)
{
maxPixel=bayerVal;
}
if(y%2==0)
{
if(x%2==0)
{
//green
bayerImage[y][x]=bayerVal;
//if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
bayerImage[y][x]/=256;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[0][bayerVal]++;
}
else
{
//red
bayerImage[y][x]=bayerVal;
//if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
bayerImage[y][x]/=256;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[1][bayerVal]++;
}
}
else
{
if(x%2==0)
{
//blue
bayerImage[y][x]=bayerVal;
//if (bayerImage[y][x] >= 10) bayerImage[y][x]-=10; else bayerImage[y][x]=0;
bayerImage[y][x]/=256;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[2][bayerVal]++;
}
else
{
//green
bayerImage[y][x]=bayerVal;
//if (bayerImage[y][x] >= 20) bayerImage[y][x]-=20; else bayerImage[y][x]=0;
bayerImage[y][x]/=256;
if(bayerImage[y][x]>255)
bayerImage[y][x]=255;
rgbValues[3][bayerVal]++;
}
}
}
}
for(y=1;y