?? bmpi_decoder.c
字號:
*
* FUNCTION NAME:
* BMPI_DecodeBitmap()
*
* FUNCTION DESCRIPTION:
* This function decodes all types of BMP images.
*
* INPUTS:
* pu8InputBuffer : pointer to input buffer
* sImageInfo : image information structure
* func : pointer to callback function
*
* OUTPUTS:
* psOutputBuffer : pointer to output buffer (structure)
*
* RETURN:
* '0' if successful or '1' if failed.
*
* GLOBALS ACCESSED/MODIFIED:
* < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
OP_UINT8 BMPI_DecodeBitmap
(
OP_UINT8 *pu8InputBuffer,
BMP_IMAGE_INFO sImageInfo,
OP_BOOLEAN func(OP_UINT16 x, OP_UINT16 y),
IMAGE_DECODER_OUTPUT_TYPE *psOutputBuffer
)
{
/*-----------------------------------------------------------------------*/
/* DECLARE LOCAL VARIABLES */
/*-----------------------------------------------------------------------*/
OP_UINT8 u8Failed; /* to indicate decoding failure */
OP_UINT32 u32OffsetToBitmap; /* offset to bitmap data */
PALETTE_TYPE *psPalette; /* pointer to palette */
/* -- Initialize local variable -- */
u32OffsetToBitmap = BMPI_ReadLittleEndianU32(pu8InputBuffer+0x0000000a);
psPalette = (PALETTE_TYPE *)(pu8InputBuffer+0x00000036);
/*-----------------------------------------------------------------------*/
/* SELECT RIGHT DECODER AND THEN DECODE */
/*-----------------------------------------------------------------------*/
switch(sImageInfo.u32Compression)
{
/* -- No compression -- */
case BI_RGB:
switch(sImageInfo.u16BitsPerPixel)
{
/* 2colors - 1 bit */
case 1:
u8Failed = BMPI_DecodeRGB1(
pu8InputBuffer+u32OffsetToBitmap,
psPalette,
sImageInfo,
func,
psOutputBuffer);
break;
/* 16 colors - 4 bits */
case 4:
u8Failed = BMPI_DecodeRGB4(
pu8InputBuffer+u32OffsetToBitmap,
psPalette,
sImageInfo,
func,
psOutputBuffer);
break;
/* 256 colors - 8 bits */
case 8:
u8Failed = BMPI_DecodeRGB8(
pu8InputBuffer+u32OffsetToBitmap,
psPalette,
sImageInfo,
func,
psOutputBuffer);
break;
/* 65K colors - 16 bits */
case 16:
u8Failed = BMPI_Decode16Bits(
pu8InputBuffer+u32OffsetToBitmap,
pu8InputBuffer+0x00000036,
sImageInfo,
func,
psOutputBuffer);
break;
/* 16M colors - 24 bits */
case 24:
u8Failed = BMPI_DecodeRGB24(
pu8InputBuffer+u32OffsetToBitmap,
sImageInfo,
func,
psOutputBuffer);
break;
/* 16M colors - 32 bits */
case 32:
u8Failed = BMPI_Decode32Bits(
pu8InputBuffer+u32OffsetToBitmap,
pu8InputBuffer+0x00000036,
sImageInfo,
func,
psOutputBuffer);
break;
/* wrong configuration */
default:
return(1);
}
break;
/* RLE compression - 16 colors - 4 bits */
case BI_RLE4:
u8Failed = BMPI_DecodeRLE4(pu8InputBuffer+u32OffsetToBitmap,
psPalette,
sImageInfo,
func,
psOutputBuffer);
break;
/* RLE compression - 256 colors - 8 bits */
case BI_RLE8:
u8Failed = BMPI_DecodeRLE8(pu8InputBuffer+u32OffsetToBitmap,
psPalette,
sImageInfo,
func,
psOutputBuffer);
break;
/* non-conventional bit masking */
case BI_BITFIELD:
if(sImageInfo.u16BitsPerPixel == 16) /* 16 bits */
{
u8Failed = BMPI_Decode16Bits(pu8InputBuffer+u32OffsetToBitmap,
pu8InputBuffer+0x00000036,
sImageInfo,
func,
psOutputBuffer);
}
else if(sImageInfo.u16BitsPerPixel == 32) /* 32 bits */
{
u8Failed = BMPI_Decode32Bits(pu8InputBuffer+u32OffsetToBitmap,
pu8InputBuffer+0x00000036,
sImageInfo,
func,
psOutputBuffer);
}
else
{
/* wrong configuration */
return(1);
}
break;
/* wrong configuration */
default:
return(1);
}
/*-----------------------------------------------------------------------*/
/* FLIP OUTPUT BUFFER */
/*-----------------------------------------------------------------------*/
BMPI_FlipBuffer((OP_UINT8 *)psOutputBuffer, sImageInfo);
/*-----------------------------------------------------------------------*/
/* CHECK IF DECODING WAS SUCCESSFUL */
/*-----------------------------------------------------------------------*/
if(u8Failed)
{
return(1);
}
else
{
return(0);
}
}
/*
*******************************************************************************
*
* FUNCTION NAME:
* BMPIFlipBuffer()
*
* FUNCTION DESCRIPTION:
* This function flips vertically a BMP buffer.
* At input, the buffer contains scan lines from bottom to top.
* At output, the buffer contains scan lines from top to bottom.
*
* INPUTS:
* pu8Buffer : pointer to buffer
* sImageInfo : image information structure
*
* pu8Buffer : pointer to buffer
* RETURN:
* '0' if successful or '1' if failed.
*
* GLOBALS ACCESSED/MODIFIED:
* < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
void BMPI_FlipBuffer
(
OP_UINT8 *pu8Buffer,
BMP_IMAGE_INFO sImageInfo
)
{
/*-----------------------------------------------------------------------*/
/* DECLARE LOCAL VARIABLES */
/*-----------------------------------------------------------------------*/
char u8Byte;
OP_UINT32 u32HalfHeight; /* half of buffer height */
OP_UINT32 u32BufferWidth; /* buffer width */
OP_UINT32 u32Xindex, u32Yindex; /* indexes for buffer */
OP_UINT32 u32FirstByteIndex, u32SecondByteIndex; /* indexes for the two */
/* bytes to be inter-changed */
/*-----------------------------------------------------------------------*/
/* FLIP VERTICALLY BUFFER */
/*-----------------------------------------------------------------------*/
/* -- Vertical loop -- */
u32HalfHeight = (sImageInfo.u32ImageHeight >> 1) & 0x7fffffff;
for (u32Yindex = 0; u32Yindex < u32HalfHeight; u32Yindex++)
{
/* -- Horizontal loop -- */
u32BufferWidth = sImageInfo.u32ImageWidth * 4;
for (u32Xindex = 0; u32Xindex < u32BufferWidth; u32Xindex++)
{
u32FirstByteIndex = u32Yindex*u32BufferWidth+u32Xindex;
u32SecondByteIndex = (sImageInfo.u32ImageHeight-u32Yindex-1)*u32BufferWidth+u32Xindex;
u8Byte = *(pu8Buffer+u32FirstByteIndex);
*(pu8Buffer+u32FirstByteIndex) = *(pu8Buffer+u32SecondByteIndex);
*(pu8Buffer+u32SecondByteIndex) = u8Byte;
} /* end of horizontal loop */
} /* end of horizontal loop */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -