?? bmpi_16bit_decoder.c
字號:
/*
*******************************************************************************
*
* FILE NAME:
* bmp_16bit_decoder.c
*
* DESCRIPTION:
* source code for BMP decoder with 16-bit.
*
* MODULE:
* BMP (BitMaP) decoder.
*
*
*******************************************************************************
*/
/*
*******************************************************************************
* Include files
*******************************************************************************
*/
/* -- Include for BMP ressources -- */
#include "bmp_decoder_api.h"
#include "bmpi_decoder.h"
/*
*******************************************************************************
*
* FUNCTION NAME:
* BMPI_Decode16Bits()
*
* 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_Decode16Bits
(
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 u16RedMask; /* mask for red color */
OP_UINT16 u16GreenMask; /* mask for green color */
OP_UINT16 u16BlueMask; /* mask for blue color */
OP_UINT16 u16RedShift; /* shift value used in decoding red color */
OP_UINT16 u16GreenShift; /* shift value used in decoding green color */
OP_UINT16 u16BlueShift; /* shift value used in decoding blue color */
OP_UINT16 u16RedScaling; /* scaling value used in decoding red color */
OP_UINT16 u16GreenScaling; /* scaling value used in decoding green color */
OP_UINT16 u16BlueScaling; /* scaling value used in decoding blue color */
OP_UINT16 u16Temp; /* 16-bit temporary variable */
OP_UINT32 u32NumExtraByte; /* number of extra bytes in a line */
OP_UINT32 u32XinvCnt; /* inverse counter on X-axis */
OP_UINT32 u32YinvCnt; /* inverse counter on Y-axis */
OP_UINT32 u32Temp; /* 32-bit temporary variable */
/*-----------------------------------------------------------------------*/
/* DECODE 16-BIT COLORS */
/*-----------------------------------------------------------------------*/
/* determine bit masks for each color plane */
if(sImageInfo.u32Compression == BI_RGB) /* with conventional bit masking */
{
u16RedMask = 0x7c00;
u16GreenMask = 0x03e0;
u16BlueMask = 0x001f;
u16RedShift = 10;
u16GreenShift = 5;
u16BlueShift = 0;
u16RedScaling = 8;
u16GreenScaling = 8;
u16BlueScaling = 8;
}
else /* with specific bit masking */
{
u16RedMask = (OP_UINT16)BMPI_ReadLittleEndianU32(pu8Mask);
pu8Mask+=4;
u16GreenMask = (OP_UINT16)BMPI_ReadLittleEndianU32(pu8Mask);
pu8Mask+=4;
u16BlueMask = (OP_UINT16)BMPI_ReadLittleEndianU32(pu8Mask);
BMPI_DetermineShiftScaling(u16RedMask,
&u16RedShift,
&u16RedScaling);
BMPI_DetermineShiftScaling(u16GreenMask,
&u16GreenShift,
&u16GreenScaling);
BMPI_DetermineShiftScaling(u16BlueMask,
&u16BlueShift,
&u16BlueScaling);
}
/* -- Calculate number of extra bytes in a line -- */
u32Temp = (sImageInfo.u32ImageWidth*2) & 0x00000003;
if ( u32Temp != 0 )
{
u32NumExtraByte = 4-u32Temp;
}
else
{
u32NumExtraByte = 0;
}
/* -- Extract 16-bit data in bitmap -- */
/* vertical loop */
u32YinvCnt = sImageInfo.u32ImageHeight;
while(u32YinvCnt--)
{
/* horizontal loop */
u32XinvCnt = sImageInfo.u32ImageWidth;
while(u32XinvCnt--) /* releavant 16-bit data */
{
u16Temp = BMPI_ReadLittleEndianU16(pu8InputBuffer);
pu8InputBuffer+=2; /* move to next 16-bit data */
psOutputBuffer->u8Blue = (OP_UINT8)((u16Temp & u16BlueMask)
>> u16BlueShift)*u16BlueScaling;
psOutputBuffer->u8Green = (OP_UINT8)((u16Temp & u16GreenMask)
>> u16GreenShift)*u16GreenScaling;
psOutputBuffer->u8Red = (OP_UINT8)((u16Temp & u16RedMask)
>> u16RedShift)*u16RedScaling;
psOutputBuffer->u8Alpha = 0xff; /* set to opaque as default */
psOutputBuffer++; /* move to next pixel */
}
pu8InputBuffer+=u32NumExtraByte; /* dummy bytes are ignored */
}
/*-----------------------------------------------------------------------*/
/* DECODED SUCCESSFULLY */
/*-----------------------------------------------------------------------*/
return(0);
}
/*
*******************************************************************************
*
* FUNCTION NAME:
* BMPI_DetermineShiftScaling()
*
* FUNCTION DESCRIPTION:
* This function determines the shifting and scaling values used in
* calculating the color intensity. The shifting and scaling values
* are derived from the input bit mask.
*
* INPUTS:
* u16Mask : input bit mask.
*
* OUTPUTS:
* u16Shift : shift value derived from the input bit mask
* u16Scaling : scaling value derived from input bit mask
*
* RETURN:
* None.
*
* GLOBALS ACCESSED/MODIFIED:
* < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
void BMPI_DetermineShiftScaling
(
OP_UINT16 u16Mask,
OP_UINT16 *u16Shift,
OP_UINT16 *u16Scaling
)
{
/*-----------------------------------------------------------------------*/
/* DECLARE LOCAL VARIABLES */
/*-----------------------------------------------------------------------*/
OP_UINT16 u16Temp; /* 16-bit temporary variable */
/*-----------------------------------------------------------------------*/
/* INITIALIZE RETURNED PARAMETERS */
/*-----------------------------------------------------------------------*/
*u16Shift = 0;
*u16Scaling = 0x0080;
/*-----------------------------------------------------------------------*/
/* DETERMINE SHIFTING VALUE */
/*-----------------------------------------------------------------------*/
u16Temp = u16Mask & 0x0001;
while( (!u16Temp) && (*u16Shift<16) )
{
u16Mask = (u16Mask >> 1) & 0x7fff;
u16Temp = u16Mask & 0x0001;
(*u16Shift)++;
}
/*-----------------------------------------------------------------------*/
/* DETERMINE SCALING VALUE */
/*-----------------------------------------------------------------------*/
if(*u16Shift == 16)
{
*u16Scaling = 0;
}
else
{
u16Mask = u16Mask >> 1;
while(u16Mask)
{
*u16Scaling = *u16Scaling >> 1;
u16Mask = u16Mask >> 1;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -