📄 bmp_decoder_api.c
字号:
/*
*******************************************************************************
*
* FILE NAME:
* bmp_decoder_api.c
*
* DESCRIPTION:
* Contain all function definitions for BMP decoder API.
*
* MODULE:
* BMP (BitMaP) decoder.
*
*
*******************************************************************************
*/
/*
*******************************************************************************
* Include files
*******************************************************************************
*/
/* -- Include for BMP ressources -- */
#include "bmp_decoder_api.h"
#include "bmpi_decoder.h"
/*
*******************************************************************************
* Macros
*******************************************************************************
*/
/*
*******************************************************************************
* Global variables
*******************************************************************************
*/
/* -- Input buffer pointer -- */
static OP_UINT8 *bmpInputBuffer;
/* -- output buffer pointer -- */
static OP_UINT8 *bmpOutputBuffer;
/* -- input buffer size -- */
static OP_UINT32 bmpInputBufferSize;
/* -- Image information -- */
static BMP_IMAGE_INFO bmpImageInfo;
/* -- Decoder state -- */
static BMP_DECODER_STATE bmpDecoderState = BMP_DECODER_STATE_UNINITIALIZED;
/*
*******************************************************************************
*
* FUNCTION NAME:
* bmpDecoderInitialize()
*
* FUNCTION DESCRIPTION:
* This function initializes the BMP decoder and sets the image
* decoding configurations to default values.
*
* INPUTS:
* None
*
* OUTPUTS:
* None
*
* RETURN:
* None
*
* GLOBALS ACCESSED/MODIFIED:
* bmpInputBuffer, bmpOutputBuffer, bmpInputBufferSize, bmpImageInfo,
* bmpDecoderState
*
* SPECIAL NOTES:
*
*
*******************************************************************************
*/
void bmpDecoderInitialize
(
void
)
{
/* -- Clear input and output buffer pointers -- */
bmpInputBuffer = OP_NULL;
bmpOutputBuffer = OP_NULL;
bmpInputBufferSize = 0;
/* -- Clear image info structure -- */
bmpImageInfo.u32ImageHeight = 0;
bmpImageInfo.u32ImageWidth = 0;
bmpImageInfo.u16ImageType = 0;
bmpImageInfo.u16NumberOfPlanes = 0;
bmpImageInfo.u16BitsPerPixel = 0;
bmpImageInfo.u32Compression = 0;
bmpImageInfo.u32BitmapDataSize = 0;
bmpImageInfo.u32HorizontalResolution = 0;
bmpImageInfo.u32VerticalResolution = 0;
bmpImageInfo.u32NumberOfColors = 0;
bmpImageInfo.u32ImportantColors = 0;
/* -- Update decoder state -- */
bmpDecoderState = BMP_DECODER_STATE_INITIALIZED;
}
/*
*******************************************************************************
*
* FUNCTION NAME:
* bmpSetInputBuffer()
*
* FUNCTION DESCRIPTION:
* This function allows the Decoder Controller to pass the decoder
* the input buffer pointer and the input buffer size.
* bmpInputBuffer and bmpInputBufferSize are initialized to the input
* parameters of this function.
*
* INPUTS:
* pu8InputBuffer : input buffer pointer (from decoder controller)
* u32InputBufferSize : input buffer size (from decoder controller)
*
* OUTPUTS:
* None
*
* RETURN:
* None
*
* GLOBALS ACCESSED/MODIFIED:
* bmpInputBuffer, bmpInputBufferSize, bmpDecoderState
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
void bmpSetInputBuffer
(
OP_UINT8 *pu8InputBuffer,
OP_UINT32 u32InputBufferSize
)
{
/* -- Declare local variable -- */
char cTemp1; /* temporary char */
char cTemp2; /* temporary char */
OP_UINT32 u32FileSize; /* file size as given in file header */
if(bmpDecoderState == BMP_DECODER_STATE_INITIALIZED)
{
/* -- Store input buffer info -- */
bmpInputBuffer = pu8InputBuffer;
bmpInputBufferSize = u32InputBufferSize;
/* -- Read file header -- */
BMPI_ExtractInfoFromFileHeader(bmpInputBuffer,
&bmpImageInfo,
&u32FileSize);
/* -- Check that FileSize is equal to true file size -- */
if(u32FileSize != u32InputBufferSize)
{
return;
}
/* -- Check that image type is 'BM' (Windows identifier) -- */
cTemp1 = (char)((bmpImageInfo.u16ImageType>>8) & 0x00ff);
cTemp2 = (char)(bmpImageInfo.u16ImageType & 0x00ff);
if( (cTemp1 != 'B') || (cTemp2 != 'M') )
{
return;
}
/* -- Read information header without the palette -- */
BMPI_ExtractInfoFromInfoHeader(bmpInputBuffer,
&bmpImageInfo);
/* -- Check that input image size is limited to 16-bit range --*/
if( (bmpImageInfo.u32ImageHeight > 0x0000ffff) || (bmpImageInfo.u32ImageWidth > 0x0000ffff) )
{
return;
}
/* -- Check that number of planes is limited to one -- */
if (bmpImageInfo.u16NumberOfPlanes > 1)
{
return;
}
/* -- Update decoder state -- */
bmpDecoderState = BMP_DECODER_STATE_READY;
}
}
/*
*******************************************************************************
*
* FUNCTION NAME:
* bmpGetImageInfo()
*
* FUNCTION DESCRIPTION:
* This function returns image information to Image Decoder
* Controller.
*
* INPUTS:
* None.
*
* OUTPUTS:
* psInfo : pointer to BMP image info structure
*
* RETURN:
* BMP_DECODER_ERR_NONE if successful, an error code otherwise.
*
* GLOBALS ACCESSED/MODIFIED:
* bmpImageInfo, bmpDecoderState
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
BMP_DECODER_ERR bmpGetImageInfo(BMP_IMAGE_INFO *psInfo)
{
if(bmpDecoderState == BMP_DECODER_STATE_READY)
{
/* -- copy image info -- */
psInfo->u16ImageType = bmpImageInfo.u16ImageType;
psInfo->u32ImageWidth = bmpImageInfo.u32ImageWidth;
psInfo->u32ImageHeight = bmpImageInfo.u32ImageHeight;
psInfo->u16NumberOfPlanes = bmpImageInfo.u16NumberOfPlanes;
psInfo->u16BitsPerPixel = bmpImageInfo.u16BitsPerPixel;
psInfo->u32Compression = bmpImageInfo.u32Compression;
psInfo->u32BitmapDataSize = bmpImageInfo.u32BitmapDataSize;
psInfo->u32HorizontalResolution = bmpImageInfo.u32HorizontalResolution;
psInfo->u32VerticalResolution = bmpImageInfo.u32VerticalResolution;
psInfo->u32NumberOfColors = bmpImageInfo.u32NumberOfColors;
psInfo->u32ImportantColors = bmpImageInfo.u32ImportantColors;
return(BMP_DECODER_ERR_NONE);
}
else
{
return(BMP_DECODER_ERR_INVALID_STATE);
}
bmpDecoderState = BMP_DECODER_STATE_INITIALIZED;
}
/*
*******************************************************************************
*
* FUNCTION NAME:
* bmpDecodeImage()
*
* FUNCTION DESCRIPTION:
* This function decodes the BMP image.
*
* INPUTS:
* pu8OutputBuffer : pointer to output buffer
* func : pointer to callback function
*
* OUTPUTS:
* pu8OutputBuffer : pointer to output buffer
*
* RETURN:
* BMP_DECODER_ERR_NONE if successful, an error code otherwise.
*
* GLOBALS ACCESSED/MODIFIED:
* bmpInputBuffer, bmpInputBufferSize, bmpDecoderState, bmpImageInfo
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
BMP_DECODER_ERR bmpDecodeImage
(
OP_UINT8 *pu8OutputBuffer,
OP_BOOLEAN func(OP_UINT16 x, OP_UINT16 y)
)
{
/* -- Check if we are in the right state -- */
if(bmpDecoderState == BMP_DECODER_STATE_READY)
{
/* -- Save output buffer pointer -- */
bmpOutputBuffer = pu8OutputBuffer;
/* -- Update decoder state -- */
bmpDecoderState = BMP_DECODER_STATE_ACTIVE;
/* -- Decode BMP image -- */
BMPI_DecodeBitmap(bmpInputBuffer,
bmpImageInfo,
func,
(IMAGE_DECODER_OUTPUT_TYPE *)pu8OutputBuffer);
return(BMP_DECODER_ERR_NONE);
}
/* -- Decoder is not in a right state -- */
else
{
return(BMP_DECODER_ERR_INVALID_STATE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -