|
楼主 |
发表于 2014-9-22 13:31:21
|
显示全部楼层
这是我转BMP的代码。把一张张RGB888的BMP转成连续的RGB565数据,并且转90度。这个代码写得比较粗糙。。。供参考
- // RGB24toRGB565.cpp
- //
- #include "stdafx.h"
- #include "windows.h"
- unsigned char SrcBMP[320 * 240 * 3];
- unsigned char DstBMP[240 * 320 * 2];
- #define RGB565(r, g, b) \
- ((((r) & 0x1f) << 11) | \
- (((g) & 0x3f) << 5) | \
- (((b) & 0x1f) ))
- int _tmain(int argc, _TCHAR* argv[])
- {
- HANDLE hSrcFile;
- HANDLE hDstFile;
- DWORD r,g,b;
- unsigned char * SrcPixel;
- DWORD dwBytesRead, dwBytesWritten, dwPos;
- unsigned short * DstPixel;
- TCHAR SrcFileName[MAX_PATH];
- hDstFile = CreateFile(TEXT("J:\\grab_bmp\\!output.img"), // open DST file
- GENERIC_WRITE, // open for writing
- 0, // do not share
- NULL, // no security
- OPEN_ALWAYS, // open or create
- FILE_ATTRIBUTE_NORMAL, // normal file
- NULL); // no attr. template
- for (int FileIndex = 484; FileIndex <= 6951; FileIndex++)
- {
- _stprintf (SrcFileName, TEXT("J:\\grab_bmp\\grab%05d.bmp"), FileIndex);
- hSrcFile = CreateFile(SrcFileName, // open SRC file
- GENERIC_READ, // open for reading
- 0, // do not share
- NULL, // no security
- OPEN_EXISTING, // existing file only
- FILE_ATTRIBUTE_NORMAL, // normal file
- NULL); // no attr. template
- if (hSrcFile == INVALID_HANDLE_VALUE)
- {
- printf("Could not open source file.");
- return 0;
- }
- SetFilePointer(hSrcFile, 0x1A, NULL, FILE_BEGIN);
- ReadFile(hSrcFile, SrcBMP, sizeof(SrcBMP), &dwBytesRead, NULL);
- if (dwBytesRead != sizeof(SrcBMP))
- {
- printf("Read file error.");
- return 0;
- }
- CloseHandle(hSrcFile);
- for( int x = 0; x < 240; x++)
- {
- for( int y = 0; y < 320; y++)
- {
- SrcPixel = SrcBMP + ((319 - y) * 3) + ((239 - x) * 320 * 3);
- b = SrcPixel[0];
- g = SrcPixel[1];
- r = SrcPixel[2];
- DstPixel = (unsigned short *)(DstBMP + x * 2 + y * 240 * 2);
- *DstPixel = RGB565(r >> 3, g >> 2, b >> 3);
- }
- }
- WriteFile(hDstFile, DstBMP, sizeof(DstBMP), &dwBytesWritten, NULL);
- }
- CloseHandle(hDstFile);
- return 0;
- }
复制代码 |
|