|
2440 lcd 24bpp显示就照我说的做。
关于BMP图片转转成16bpp/24bpp直接显示数据,看代码:
#include
#include
#include
/***********************************************
Data types
************************************************/
#define dgNULL 0L
#define dgTRUE 1
#define dgFALSE 0
typedef short int dgBOOL;
typedef signed char S8;
typedef signed short int S16;
typedef signed int S32;
typedef unsigned char U8;
typedef unsigned short int U16;
typedef unsigned int U32;
#define BI_RGB 0L
typedef struct tag_dgImage_BITMAPFILEHEADER {
U32 bfSize;
U16 bfReserved1;
U16 bfReserved2;
U32 bfOffBits;
} _dgImage_BITMAPFILEHEADER;
typedef struct tag_dgImage_BITMAPINFOHEADER{
U32 biSize;
S32 biWidth;
S32 biHeight;
U16 biPlanes;
U16 biBitCount;
U32 biCompression;
U32 biSizeImage;
S32 biXPelsPerMeter;
S32 biYPelsPerMeter;
U32 biClrUsed;
U32 biClrImportant;
} _dgImage_BITMAPINFOHEADER;
#define RGB_16BIT 0
#define RGB_24BIT 1
dgBOOL BMP2DMP( const char *const srcname, const char *const dstname, char rgbdata)
{
U16 BMP_ID;
_dgImage_BITMAPFILEHEADER bmpfh;
_dgImage_BITMAPINFOHEADER bmpinfo;
FILE *fp1, *fp2;
/* load windows BMP file */
fp1 = fopen( srcname, "rb" );
if( !fp1 ) goto error;
fp2 = fopen( dstname, "wb" );
if( !fp2 ) goto error;
fread((void *)(&BMP_ID),2, 1, fp1 );
//if (BMP_ID != *((U16*) "BM")) goto error;
fread((void *)(&bmpfh),sizeof(_dgImage_BITMAPFILEHEADER), 1, fp1 );
fread((void *)(&bmpinfo),sizeof(_dgImage_BITMAPINFOHEADER), 1, fp1 );
printf( "Width : %d, Height : %d\n", bmpinfo.biWidth, bmpinfo.biHeight );
//printf( "Data Position = 0x%08X\n", bmpfh.bfOffBits );
{
int i, j;
unsigned short int rgb565;
unsigned char bgr[3];
fseek( fp1, bmpfh.bfOffBits,SEEK_SET );
for( i=(bmpinfo.biHeight)-1 ; i>=0 ; i-- )
{
for( j=0 ; j<(bmpinfo.biWidth) ; j++ )
{
if(rgbdata == 0)
{
fread( bgr, 3, 1, fp1 );
rgb565 = ((((U16)bgr[2])&0xF8)<<8) | ((((U16)bgr[1])&0xFC)<<3) | ((((U16)bgr[0])&0xF8)>>3);
//printf(" (%3d, %3d) = (%3d, %3d, %3d) = 0x%04X\n", j, i, bgr[0], bgr[1], bgr[2], rgb565 );
fseek( fp2, (i*bmpinfo.biWidth + j)*2, SEEK_SET );
fwrite( &rgb565, 2, 1, fp2 );
}
else if(rgbdata == 1)
{
fread( bgr, 3, 1, fp1 );
fseek( fp2, (i*bmpinfo.biWidth + j)*3, SEEK_SET );
fwrite( bgr, 3, 1, fp2);
}
else
{
goto error;
}
}
// 4 byte aline per every line.
if( (bmpinfo.biWidth*3) % 4 )
{
fread( bgr, (bmpinfo.biWidth*3) % 4, 1, fp1 );
}
}
}
switch(rgbdata)
{
case 0:
printf( "16BIT RGBDATA\n" );
break;
case 1:
printf( "24BIT RGBDATA\n" );
break;
default:
break;
}
// printf( "saved\n" );
if( fp1 ) fclose( fp1 );
if( fp2 ) fclose( fp2 );
return dgTRUE;
error:
printf( "error\n" );
if( fp1 ) fclose( fp1 );
if( fp2 ) fclose( fp2 );
return dgFALSE;
}
int main( int argc, char *argv[] )
{
if( argc != 4 )
{
printf( "Usage : bmp2dmp.exe srcfilename dstfilename RGB_DATA\n" );
printf( "<>\n" );
printf( "0 : 24Bit BMP File --> 16Bit RGB DATA\n" );
printf( "1 : 24Bit BMP File --> 24Bit RGB DATA\n" );
return -1;
}
// if( BMP2DMP( (const char *const)argv[1], (const char *const)argv[2] ) )
if( BMP2DMP( (const char *const)argv[1], (const char *const)argv[2] , (atoi(argv[3]))))
return 0;
return -1;
}
|
|