#define MICSIZE 10
#if 1
FILE* fpbmp;
FILE* fpout;
unsigned char* pu8FileBuffer = NULL;
fpbmp = fopen("xxx.rgba", "rb");
if (fpbmp == NULL)
{
printf("Open bmp failed!!!\n");
}
else
{
printf("Open bmp success!!!\n");
}
fpout = fopen("1111.argb1555", "wb+");
if (fpout == NULL)
{
printf("Open out.bmp failed!!!\n");
}
else
{
printf("Open out.bmp success!!!\n");
}
fseek(fpbmp, 0, SEEK_SET); //定位原图 偏移位置
fseek(fpout, 0, SEEK_SET); //定位新图 偏移位置
unsigned char u8bitAlphaChannel = 0;
unsigned char u8bitRedChannel = 0;
unsigned char u8bitGreenChannel = 0;
unsigned char u8bitBlueChannel = 0;
unsigned int alpha = 0;
unsigned int red = 0;
unsigned int green = 0;
unsigned int blue = 0;
unsigned short ARGB1555pixel= 0;
pu8FileBuffer = (unsigned char*)malloc(MICSIZE * MICSIZE *4);
if (pu8FileBuffer == NULL)
{
printf("malloc failed fileSize=%d\n", fpbmp);
fclose(fpbmp);
}
memset(pu8FileBuffer, 0, MICSIZE * MICSIZE *4);
//fseek(pFile, 54, SEEK_SET);
fread(pu8FileBuffer, 1, MICSIZE * MICSIZE *4, fpbmp);
fclose(fpbmp);
unsigned short* pBmpBufOut = NULL;
pBmpBufOut = (unsigned short*)malloc(MICSIZE * MICSIZE * 2);
memset(pBmpBufOut, 0, MICSIZE * MICSIZE * 2);
for (int i = 0; i < MICSIZE * MICSIZE * 4; i+=4)
{
u8bitAlphaChannel = *(pu8FileBuffer + i + 3);
u8bitRedChannel = *(pu8FileBuffer + i + 0);
u8bitGreenChannel = *(pu8FileBuffer + i + 1);
u8bitBlueChannel = *(pu8FileBuffer + i + 2);
alpha = (u8bitAlphaChannel + 127) / 255;
red = (u8bitRedChannel * 31 + 127) / 255;
green = (u8bitGreenChannel * 31 + 127) / 255;
blue = (u8bitBlueChannel * 31 + 127) / 255;
ARGB1555pixel = (alpha << 15) | (red << 10) | (green << 5) | blue;
*(pBmpBufOut + i / 4) = ARGB1555pixel;
}
fwrite(pBmpBufOut, MICSIZE * MICSIZE, sizeof(unsigned short), fpout);
fclose(fpout);
#endif
|