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

📄 bmpi_rgb1_decoder.c

📁 bmp图像文件解码器的arm版本的源代码
💻 C
字号:
/*
*******************************************************************************
*
* FILE NAME:            
*   bmp_rgb1_decoder.c
*
* DESCRIPTION:
*   source code for BMP decoder with 1-bit and no compression (RGB1)
*
* MODULE: 
*   BMP (BitMaP) decoder.
* 
*  
*******************************************************************************
*/

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

/* -- Include for BMP ressources -- */
#include "bmp_decoder_api.h"
#include "bmpi_decoder.h"



/*
*******************************************************************************
* 
* FUNCTION NAME:
*   BMPI_DecodeRGB1()
*
* FUNCTION DESCRIPTION:
*   This function decodes a BMP image with 1-bit color and no compression.
*
* INPUTS:
*   pu8Bitmap  : pointer to bitmap data 
*   psPalette  : pointer to palette (structure)
*   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_DecodeRGB1
(
    OP_UINT8                    *pu8Bitmap,
    PALETTE_TYPE                *psPalette,
    BMP_IMAGE_INFO              sImageInfo,
    OP_BOOLEAN                  func(OP_UINT16 x, OP_UINT16 y),
    IMAGE_DECODER_OUTPUT_TYPE   *psOutputBuffer)
{


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

    OP_UINT8    u8PaletteIndex;         /* palette index to retrieve RGB color */
    OP_UINT32   u32NumExtraByte;        /* number of extra bytes append at end of a line */
    OP_UINT32   u32WidthDividedBy8;     /* image width divided by 8 (and rounded) */ 
    OP_UINT32   u32XinvCnt;             /* inverse counter on X-axis */
    OP_UINT32   u32YinvCnt;             /* inverse counter on Y-axis */
    OP_UINT32   u32BitIndex;            /* index for bits in a byte */
    OP_UINT32   u32RemainingBits;       /* remaining bits to be processed in a byte */


    /*-----------------------------------------------------------------------*/
    /* DECODE 4-BIT COLORS & NO COMPRESSION FORMAT                           */
    /*-----------------------------------------------------------------------*/

    /* -- Calculate number of extra of bytes in a line -- */
    u32WidthDividedBy8 = sImageInfo.u32ImageWidth >> 3;
    u32NumExtraByte = ((sImageInfo.u32ImageWidth+7) >> 3) & 0x00000003;
    if ( u32NumExtraByte != 0 ) 
    {
        u32NumExtraByte = 4-u32NumExtraByte;
    }
    else
    {
        u32NumExtraByte = 0;
    }

    /* -- Extract bitmap data byte by byte -- */
    /* vertical loop */
    u32YinvCnt = sImageInfo.u32ImageHeight;
    while(u32YinvCnt--)
    {

        /* horizontal loop */
        u32XinvCnt = u32WidthDividedBy8;
        while(u32XinvCnt--)                                  /* 'true' bytes */
        {
            /* extract bits in a byte */
            u32BitIndex = 8;
            while(u32BitIndex--)
            {
                u8PaletteIndex = ( (*pu8Bitmap) >> u32BitIndex ) & 0x01;
                psOutputBuffer->u8Blue  = (psPalette+u8PaletteIndex)->u8Blue;
                psOutputBuffer->u8Green = (psPalette+u8PaletteIndex)->u8Green;
                psOutputBuffer->u8Red   = (psPalette+u8PaletteIndex)->u8Red;
                psOutputBuffer->u8Alpha = 0xff;  /* set to opaque as default */
                psOutputBuffer++;              /* move pointer to next pixel */              
            }
            pu8Bitmap++;                                /* move to next byte */
        }
        u32RemainingBits = sImageInfo.u32ImageWidth-u32WidthDividedBy8*8;
        u32BitIndex = 7;
        while(u32RemainingBits--)
        {
            u8PaletteIndex = ( (*pu8Bitmap) >> u32BitIndex ) & 0x01;
            psOutputBuffer->u8Blue  = (psPalette+u8PaletteIndex)->u8Blue;
            psOutputBuffer->u8Green = (psPalette+u8PaletteIndex)->u8Green;
            psOutputBuffer->u8Red   = (psPalette+u8PaletteIndex)->u8Red;
            psOutputBuffer->u8Alpha = 0xff;      /* set to opaque as default */
            psOutputBuffer++;                  /* move pointer to next pixel */
            u32BitIndex--;
        }
        pu8Bitmap++;                                    /* move to next byte */
        pu8Bitmap+=u32NumExtraByte;               /* dummy bytes are ignored */

    }

    /*-----------------------------------------------------------------------*/
    /* DECODED SUCCESSFULLY                                                  */
    /*-----------------------------------------------------------------------*/

    return(0);
}



⌨️ 快捷键说明

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