⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wbmpi_decoder.c

📁 wbmp图像文件解码器的arm版本源代码
💻 C
字号:
/*
*******************************************************************************
*
* FILE NAME:            
*   wbmpi_decoder.c
*
* DESCRIPTION:
*   Source code of all internal functions of the WBMP decoder.
*
* MODULE: 
*   WBMP (Wireless BitMaP) decoder.
* 
*  
*******************************************************************************
*/

/*
*******************************************************************************
* Include files
*******************************************************************************
*/

#include "wbmpi_decoder.h"



/*
*******************************************************************************
* 
* FUNCTION NAME:
*   WBMPI_ReadMultiByteInteger()
*
* FUNCTION DESCRIPTION:
*   This function reads a multi-byte integer as defined in
*   "Wireless Application Environment Defined Media Type specification",
*   WAAP-237-WAEMT-20010515-a, Version 15, May 2001.
*   
*
* INPUTS:
*   pu8InputBuffer  : pointer to input buffer.
*
* OUTPUTS:
*   pu8InputBuffer  : pointer to input buffer.
*   
* RETURN:
*   u32Integer      : decoded unsigned 32-bit integer.
*
* GLOBALS ACCESSED/MODIFIED:
*   < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
OP_UINT32 WBMPI_ReadMultiByteInteger
(
    OP_UINT8    **pu8InputBuffer
)
{

    /*-----------------------------------------------------------------------*/
    /* DECLARE LOCAL VARIABLES                                               */
    /*-----------------------------------------------------------------------*/

    OP_UINT8    u8Temp;                        /* 8-bit temporary variable */
    OP_UINT32   u32Integer;                    /* decoded unsigned 32-bit integer */ 


    /*-----------------------------------------------------------------------*/
    /* DECODE UNSIGNED 32-BIT INTEGER                                        */
    /*-----------------------------------------------------------------------*/

    u32Integer = 0;
    do
    {
        u8Temp = **pu8InputBuffer;
        (*pu8InputBuffer)++;
        u32Integer = (u32Integer << 7) | (u8Temp & 0x7f);
    }while(u8Temp & 0x80);

    return(u32Integer);

}



/*
*******************************************************************************
* 
* FUNCTION NAME:
*   WBMPI_ReadHeader()
*
* FUNCTION DESCRIPTION:
*   This function reads the header of a WBMP buffer and retrieves the
*   following information: WBMP type, image width and height.
*   
*
* INPUTS:
*   pu8InputBuffer  : pointer to input buffer.
*
* OUTPUTS:
*   pu8InputBuffer  : pointer to input buffer.
*   u16WbmpType     : WBMP image type
*   u16ImageWidth   : image width
*   pu16ImageHeight : image height
*   
* RETURN:
*   '0' if successful or '1' if failed.
*
* GLOBALS ACCESSED/MODIFIED:
*   < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*   ONLY FOR WBMP IMAGE WITH TYPE '0'
*
*******************************************************************************
*/
OP_UINT8 WBMPI_ReadHeader
(
    OP_UINT8        **pu8InputBuffer,
    OP_UINT16       *pu16WbmpType,
    OP_UINT16       *pu16ImageWidth,
    OP_UINT16       *pu16ImageHeight)
{

    /*-----------------------------------------------------------------------*/
    /* DECLARE LOCAL VARIABLES                                               */
    /*-----------------------------------------------------------------------*/

    /* -- Declare local variables -- */
    OP_UINT8    u8Temp;                          /* 8-bit temporary variable */


    /*-----------------------------------------------------------------------*/
    /* READ WBMP TYPE                                                        */
    /*-----------------------------------------------------------------------*/

    /* -- Read type from input buffer -- */
    *pu16WbmpType = (OP_UINT16)WBMPI_ReadMultiByteInteger(pu8InputBuffer);

    /* -- Return an error if type is not '0' (only supported type) -- */
    if(*pu16WbmpType != 0) 
    {
        return(1);
    }


    /*-----------------------------------------------------------------------*/
    /* READ FIXED HEADER AND EXTENSION FIELDS                                */
    /*-----------------------------------------------------------------------*/

    /* -- Read fixed-header field -- */
    u8Temp = **pu8InputBuffer;
    (*pu8InputBuffer)++;

    /* -- Return an error if extension field is present (for type '0') -- */
    if(u8Temp & 0x80) 
    {
        return(1);
    }


    /*-----------------------------------------------------------------------*/
    /* READ IMAGE WIDTH AND HEIGHT                                           */
    /*-----------------------------------------------------------------------*/

    *pu16ImageWidth  = (OP_UINT16)WBMPI_ReadMultiByteInteger(pu8InputBuffer);
    *pu16ImageHeight = (OP_UINT16)WBMPI_ReadMultiByteInteger(pu8InputBuffer);


    /*-----------------------------------------------------------------------*/
    /* HEADER WAS READ SUCCESSFULLY                                          */
    /*-----------------------------------------------------------------------*/

    return(0);

}



/*
*******************************************************************************
* 
* FUNCTION NAME:
*   WBMPI_DecodeBitmap()
*
* FUNCTION DESCRIPTION:
*   This function decodes WBMP image data with type '0'.
*   
*
* INPUTS:
*   pu8InputBuffer  : pointer to input buffer
*   u16ImageWidth   : image width
*   pu16ImageHeight : image height
*   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:
*   ONLY FOR WBMP IMAGE WITH TYPE '0'
*
*******************************************************************************
*/
OP_UINT8 WBMPI_DecodeBitmap
(
    OP_UINT8                    *pu8InputBuffer,
    OP_UINT16                   u16ImageWidth,
    OP_UINT16                   u16ImageHeight,
    OP_BOOLEAN                  func(OP_UINT16 x, OP_UINT16 y),
    IMAGE_DECODER_OUTPUT_TYPE   *psOutputBuffer)
{


    /*-----------------------------------------------------------------------*/
    /* DECLARE LOCAL VARIABLES                                               */
    /*-----------------------------------------------------------------------*/

    /* -- Declare local variables -- */
    OP_UINT8    u8NewByte;                  /* byte from input buffer */
    OP_UINT8    u8Pixel;                    /* pixel value */
    OP_UINT16   u16ColumnIndex;             /* column index */
    OP_UINT16   u16RowIndex;                /* row indexes */
    OP_UINT16   u16NumberOfByteForRow;      /* number of bytes for a row */
    OP_UINT16   u16NumberOfPixelsInByte;    /* number of pixels to decode in a byte */


    /*-----------------------------------------------------------------------*/
    /* READ IMAGE DATA ROW BY ROW                                            */
    /*-----------------------------------------------------------------------*/

    /* -- For each row */
    u16RowIndex = u16ImageHeight;
    while(u16RowIndex--)
    {

        /* -- For each column of a row -- */
        u16ColumnIndex = u16ImageWidth;

        if ( u16ImageWidth % 8 )
        {
            u16NumberOfByteForRow = (u16ImageWidth>>3) + 1;
        }
        else
        {
            u16NumberOfByteForRow = (u16ImageWidth>>3);
        }
        
        while (u16NumberOfByteForRow--)
        {
            /* read a new byte in the input buffer */
            u8NewByte = *pu8InputBuffer;
            pu8InputBuffer++;

            /* extract 8 pixels in current byte */
            if (u16ColumnIndex > 8)
            {
                u16NumberOfPixelsInByte = 8;
            }
            else
            {
                u16NumberOfPixelsInByte = u16ColumnIndex;
            }
            while (u16NumberOfPixelsInByte--)
            {
                u8Pixel = u8NewByte & 0x80;
                /* 'white' pixel --> (R,G,B,A) = (0xff, 0xff, 0xff, 0xff) */
                if(u8Pixel != 0)
                {
                    psOutputBuffer->u8Red   = 0xff;
                    psOutputBuffer->u8Green = 0xff;
                    psOutputBuffer->u8Blue  = 0xff;
                }
                /* 'black' pixel --> (R,G,B,A) = (0x00, 0x00, 0x00, 0xff)*/
                else
                {
                    psOutputBuffer->u8Red   = 0x00;
                    psOutputBuffer->u8Green = 0x00;
                    psOutputBuffer->u8Blue  = 0x00;
                }
                psOutputBuffer->u8Alpha = 0xff;
                psOutputBuffer++;
                u16ColumnIndex--;
                u8NewByte = u8NewByte << 1;
            }

        } /* end of loop on column */

    } /* end of loop on row */


    /*-----------------------------------------------------------------------*/
    /* BITMAP WAS DECODED SUCCESSFULLY                                       */
    /*-----------------------------------------------------------------------*/
    
    if ( (u16ImageWidth > 0) && (u16ImageHeight > 0) )
    {
        func((OP_UINT16)(u16ImageWidth-1),(OP_UINT16)(u16ImageHeight-1));
    }
    else
    {
        func(0,0);
    }
    return(0);

}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -