?? bmpi_32bit_decoder.c
字號:
/*
*******************************************************************************
*
* FILE NAME:
* bmp_32bit_decoder.c
*
* DESCRIPTION:
* source code for BMP decoder with 32-bit.
*
* MODULE:
* BMP (BitMaP) decoder.
*
*
*******************************************************************************
*/
/*
*******************************************************************************
* Include files
*******************************************************************************
*/
/* -- Include for BMP ressources -- */
#include "bmp_decoder_api.h"
#include "bmpi_decoder.h"
/*
*******************************************************************************
*
* FUNCTION NAME:
* BMPI_Decode32Bits()
*
* FUNCTION DESCRIPTION:
* This function decodes a BMP image with 16-bit color.
*
* INPUTS:
* pu8InputBuffer : pointer to input buffer
* pu8Mask : pointer to color mask in palette
* 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_Decode32Bits
(
OP_UINT8 *pu8InputBuffer,
OP_UINT8 *pu8Mask,
BMP_IMAGE_INFO sImageInfo,
OP_BOOLEAN func(OP_UINT16 x, OP_UINT16 y),
IMAGE_DECODER_OUTPUT_TYPE *psOutputBuffer)
{
/*-----------------------------------------------------------------------*/
/* DECLARE LOCAL VARIABLES */
/*-----------------------------------------------------------------------*/
OP_UINT16 u8RedMask; /* mask for red color */
OP_UINT16 u8GreenMask; /* mask for green color */
OP_UINT16 u8BlueMask; /* mask for blue color */
OP_UINT32 u32XinvCnt; /* inverse counter on X-axis */
OP_UINT32 u32YinvCnt; /* inverse counter on Y-axis */
OP_UINT32 u32Temp; /* 32-bit temporary variable */
/*-----------------------------------------------------------------------*/
/* DECODE 32-BIT COLORS */
/*-----------------------------------------------------------------------*/
/* determine bit masks for each color plane */
if(sImageInfo.u32Compression == BI_RGB) /* no bit masking */
{
u8RedMask = 0xff;
u8GreenMask = 0xff;
u8BlueMask = 0xff;
}
else /* with specific bit masking */
{
u32Temp = BMPI_ReadLittleEndianU32(pu8Mask);
pu8Mask+=4;
u8RedMask = BMPI_RetrieveBitMask32Bits(u32Temp);
u32Temp = BMPI_ReadLittleEndianU32(pu8Mask);
pu8Mask+=4;
u8GreenMask = BMPI_RetrieveBitMask32Bits(u32Temp);
u32Temp = BMPI_ReadLittleEndianU32(pu8Mask);
u8BlueMask = BMPI_RetrieveBitMask32Bits(u32Temp);
}
/* -- Extract data in bitmap pixel by pixel -- */
/* vertical loop */
u32YinvCnt = sImageInfo.u32ImageHeight;
while(u32YinvCnt--)
{
/* horizontal loop */
u32XinvCnt = sImageInfo.u32ImageWidth;
while(u32XinvCnt--)
{
psOutputBuffer->u8Blue = (*pu8InputBuffer++) & u8BlueMask;
psOutputBuffer->u8Green = (*pu8InputBuffer++) & u8GreenMask;
psOutputBuffer->u8Red = (*pu8InputBuffer++) & u8RedMask;
pu8InputBuffer++; /* every 4th bytes are ignored */
psOutputBuffer->u8Alpha = 0xff; /* set to opaque as default */
psOutputBuffer++; /* move pointer to next pixel */
}
}
/*-----------------------------------------------------------------------*/
/* DECODED SUCCESSFULLY */
/*-----------------------------------------------------------------------*/
return(0);
}
/*
*******************************************************************************
*
* FUNCTION NAME:
* BMPI_RetrieveBitMask32Bits()
*
* FUNCTION DESCRIPTION:
* This function retrieves the bit mask of one color from a 32-bit data
* in palette.
*
* INPUTS:
* u32BitField : bit field from palette where mask is included.
*
* OUTPUTS:
* None.
*
* RETURN:
* u8Mask : bit mask for one color.
*
* GLOBALS ACCESSED/MODIFIED:
* < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
OP_UINT8 BMPI_RetrieveBitMask32Bits
(
OP_UINT32 u32BitField
)
{
/*-----------------------------------------------------------------------*/
/* INITIALIZE RETURNED PARAMETERS */
/*-----------------------------------------------------------------------*/
OP_UINT8 u8Mask;
OP_UINT32 u32LoopCounter; /* loop counter */
OP_UINT32 u32Temp; /* 32-bit temporary variable */
/*-----------------------------------------------------------------------*/
/* DETERMINE 8-bit MASK */
/*-----------------------------------------------------------------------*/
u32LoopCounter = 0;
u32Temp = u32BitField & 0x00000001;
while( (!u32Temp) && (u32LoopCounter < 32) )
{
u32BitField = (u32BitField >> 1) & 0x7fffffff;
u32Temp = u32BitField & 0x00000001;
u32LoopCounter++;
}
if(u32LoopCounter != 32)
{
u8Mask = (OP_UINT8)u32BitField;
}
else
{
u8Mask = 0x00;
}
return(u8Mask);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -