这是预览的画面。。。预览没什么问题。
这是用OV9650拍照得来的画面。。。
我很纳闷的是:为什么从同一个地址取数据,放到LCD的内存就正常,放到16位bmp颜色就成这个样子?。。。
在6.0系统下:
拍照相关的驱动是:
CIS_IOControl下:
case IOCTL_CAM_COPY :
Copy_Cam_Preview_Image(pBufOut,dwLenOut) ;
RETAILMSG(MSG_EN_1,( TEXT("CAMERA:IOCTL_CAM_COPY(dwLenIn:%x)\r\n"), dwLenIn));
break;
void Copy_Cam_Preview_Image(U8 *pBufOut,DWORD dwLenOut)
{
int temp;
U8 *buffer_rgb;
U8 *pImage;
pImage=pBufOut;
temp = (s2440CAM->CIPRSTATUS>>26)&3;
temp = (temp + 2) % 4;
RETAILMSG(MSG_EN_1,(_T("Copy_preview_index = %d, size %d/r/n"), temp, image_size));
switch (temp) {
case 0: buffer_rgb = (U8*)s2440CAM->CIPRCLRSA1; break;
case 1: buffer_rgb = (U8*)s2440CAM->CIPRCLRSA2; break;
case 2: buffer_rgb = (U8*)s2440CAM->CIPRCLRSA3; break;
case 3: buffer_rgb = (U8*)s2440CAM->CIPRCLRSA4; break;
default : buffer_rgb = (U8*)s2440CAM->CIPRCLRSA1; break;
}
RETAILMSG(MSG_EN_1,(_T("buffer_rgb[PHY] = 0x%x/r/n"), buffer_rgb));
buffer_rgb += VIRTUAL_ADDR_OFFSET;
#if 1
RETAILMSG(MSG_EN_1,(_T("buffer_rgb = 0x%x/r/n"), buffer_rgb));
#endif
memcpy(pImage,buffer_rgb,dwLenOut);
RETAILMSG(MSG_EN_1,(_T("Data Bytes = 0x%x/r/n"), dwLenOut));
}//
应用程序:
pImgRgbBuffer=new unsigned char[width*height*2];
DeviceIoControl(hCam,IOCTL_CAM_COPY,NULL,NULL,pImgRgbBuffer,width*height*2,NULL,NULL);
BITMAPINFO RGB16BitsBITMAPINFO;
ZeroMemory(&RGB16BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB16BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB16BitsBITMAPINFO.bmiHeader.biWidth = width;
RGB16BitsBITMAPINFO.bmiHeader.biHeight = height;
RGB16BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB16BitsBITMAPINFO.bmiHeader.biCompression = BI_RGB;
RGB16BitsBITMAPINFO.bmiHeader.biBitCount = 16;
RGB16BitsBITMAPINFO.bmiHeader.biClrImportant = 0;
BITMAPFILEHEADER bmBITMAPFILEHEADER;
ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));
bmBITMAPFILEHEADER.bfType = 0x4d42; //bmp
bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + ((width*height)*2); ///3=(24 / 8)
char file_name[MAX_PATH] = {0};
GetLocalTime(&st);
GetModulePath(szPath, NULL);
sprintf(file_name, "%s%04d-%02d-%02d_%02d%02d%02d.BMP",
szPath,
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
FILE *mStream = NULL;
if((mStream = fopen(file_name,"wb")))
{
fwrite(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER), 1, mStream);
fwrite(&(RGB16BitsBITMAPINFO.bmiHeader), sizeof(BITMAPINFOHEADER), 1, mStream);
fwrite(pImgRgbBuffer,width*height*2, 1, mStream);
fclose(mStream);
}
delete[]pImgRgbBuffer;
请熟悉的大侠支个招吧!好几天了,找不出原因。
------解决方案--------------------
BPP16位的BITMAPINFO结构数据构造存在问题
1、biCompression要求设置为BI_BITFIELDS
2、需要包含RGBQUAD,数据结构定义如下:
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[3];
} BITMAPINFO, FAR *LPBITMAPINFO, *PBITMAPINFO;
3、参照(2),bmiColors的设置如下:
bmiColors[0] = 0xF800;
bmiColors[1] = 0x07E0;
bmiColors[2] = 0x001F;