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

📄 bmpi_decoder.c

📁 bmp图像文件解码器的arm版本的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
* 
* FUNCTION NAME:
*   BMPI_DecodeBitmap()
*
* FUNCTION DESCRIPTION:
*   This function decodes all types of BMP images.
*
* INPUTS:
*   pu8InputBuffer  : pointer to input buffer
*   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_DecodeBitmap
(
    OP_UINT8                    *pu8InputBuffer,
    BMP_IMAGE_INFO              sImageInfo,
    OP_BOOLEAN                  func(OP_UINT16 x, OP_UINT16 y),
    IMAGE_DECODER_OUTPUT_TYPE   *psOutputBuffer
)
{

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

    OP_UINT8        u8Failed;                         /* to indicate decoding failure */
    OP_UINT32       u32OffsetToBitmap;                /* offset to bitmap data */
    PALETTE_TYPE    *psPalette;                       /* pointer to palette */

    /* -- Initialize local variable -- */    
    u32OffsetToBitmap = BMPI_ReadLittleEndianU32(pu8InputBuffer+0x0000000a);
    psPalette = (PALETTE_TYPE *)(pu8InputBuffer+0x00000036);


    /*-----------------------------------------------------------------------*/
    /* SELECT RIGHT DECODER AND THEN DECODE                                  */
    /*-----------------------------------------------------------------------*/

    switch(sImageInfo.u32Compression) 
    {
        
        /* -- No compression -- */
        case BI_RGB:
            switch(sImageInfo.u16BitsPerPixel) 
            {
                /* 2colors - 1 bit */
                case 1:
                    u8Failed = BMPI_DecodeRGB1(
                                     pu8InputBuffer+u32OffsetToBitmap,
                                     psPalette,                                     
                                     sImageInfo,
                                     func,
                                     psOutputBuffer);
                    break;
                /* 16 colors - 4 bits */
                case 4:
                    u8Failed = BMPI_DecodeRGB4(
                                     pu8InputBuffer+u32OffsetToBitmap,
                                     psPalette,                                     
                                     sImageInfo,
                                     func,
                                     psOutputBuffer);
                    break;
                /* 256 colors - 8 bits */
                case 8:
                    u8Failed = BMPI_DecodeRGB8(
                                     pu8InputBuffer+u32OffsetToBitmap,
                                     psPalette,                                     
                                     sImageInfo,
                                     func,
                                     psOutputBuffer);
                    break;
                /* 65K colors - 16 bits */
                case 16:
                    u8Failed = BMPI_Decode16Bits(
                                     pu8InputBuffer+u32OffsetToBitmap,
                                     pu8InputBuffer+0x00000036,                                     
                                     sImageInfo,
                                     func,
                                     psOutputBuffer);
                    break;
                /* 16M colors - 24 bits */
                case 24:
                    u8Failed = BMPI_DecodeRGB24(
                                     pu8InputBuffer+u32OffsetToBitmap, 
                                     sImageInfo,
                                     func,
                                     psOutputBuffer);
                    break;
                /* 16M colors - 32 bits */
                case 32:
                    u8Failed = BMPI_Decode32Bits(
                                     pu8InputBuffer+u32OffsetToBitmap,
                                     pu8InputBuffer+0x00000036,                                     
                                     sImageInfo,
                                     func,
                                     psOutputBuffer);                    
                    break;
                /* wrong configuration */
                default:
                    return(1);
            }
            break;

        /* RLE compression - 16 colors - 4 bits */
        case BI_RLE4:
            u8Failed = BMPI_DecodeRLE4(pu8InputBuffer+u32OffsetToBitmap,
                                       psPalette,                                     
                                       sImageInfo,
                                       func,
                                       psOutputBuffer);
            break;      
        /* RLE compression - 256 colors - 8 bits */
        case BI_RLE8:
            u8Failed = BMPI_DecodeRLE8(pu8InputBuffer+u32OffsetToBitmap,
                                       psPalette,                                     
                                       sImageInfo,
                                       func,
                                       psOutputBuffer);
            break;
        /* non-conventional bit masking */    
        case BI_BITFIELD:
            if(sImageInfo.u16BitsPerPixel == 16)                  /* 16 bits */
            {
                u8Failed = BMPI_Decode16Bits(pu8InputBuffer+u32OffsetToBitmap,
                                             pu8InputBuffer+0x00000036,                                     
                                             sImageInfo,
                                             func,
                                             psOutputBuffer);
            }
            else if(sImageInfo.u16BitsPerPixel == 32)             /* 32 bits */
            {
                u8Failed = BMPI_Decode32Bits(pu8InputBuffer+u32OffsetToBitmap,
                                             pu8InputBuffer+0x00000036,                                     
                                             sImageInfo,
                                             func,
                                             psOutputBuffer);
            }
            else
            {
                /* wrong configuration */
                return(1);
            }
            break;
        /* wrong configuration */
        default:            
            return(1);
    }

    /*-----------------------------------------------------------------------*/
    /* FLIP OUTPUT BUFFER                                                    */
    /*-----------------------------------------------------------------------*/

    BMPI_FlipBuffer((OP_UINT8 *)psOutputBuffer, sImageInfo);


    /*-----------------------------------------------------------------------*/
    /* CHECK IF DECODING WAS SUCCESSFUL                                      */
    /*-----------------------------------------------------------------------*/
    
    if(u8Failed)
    {
        return(1);
    }
    else
    {
        return(0);
    }

}



/*
*******************************************************************************
* 
* FUNCTION NAME:
*   BMPIFlipBuffer()
*
* FUNCTION DESCRIPTION:
*   This function flips vertically a BMP buffer.
*   At input, the buffer contains scan lines from bottom to top.
*   At output, the buffer contains scan lines from top to bottom. 
*
* INPUTS:
*   pu8Buffer   : pointer to buffer
*   sImageInfo  : image information structure 
*
* OUTPUTS:
*   pu8Buffer   : pointer to buffer
*   
* RETURN:
*   '0' if successful or '1' if failed.
*
* GLOBALS ACCESSED/MODIFIED:
*   < List all global variables this function accesses and/or modifies >
*
* SPECIAL NOTES:
*
*******************************************************************************
*/
void BMPI_FlipBuffer
(
    OP_UINT8            *pu8Buffer,
    BMP_IMAGE_INFO      sImageInfo
)
{

    /*-----------------------------------------------------------------------*/
    /* DECLARE LOCAL VARIABLES                                                 */
    /*-----------------------------------------------------------------------*/
 
    char        u8Byte;
    OP_UINT32   u32HalfHeight;                          /* half of buffer height */
    OP_UINT32   u32BufferWidth;                         /* buffer width */
    OP_UINT32   u32Xindex, u32Yindex;                   /* indexes for buffer */
    OP_UINT32   u32FirstByteIndex, u32SecondByteIndex;  /* indexes for the two */
                                                        /* bytes to be inter-changed */
        
    /*-----------------------------------------------------------------------*/
    /* FLIP VERTICALLY BUFFER                                                 */
    /*-----------------------------------------------------------------------*/
      
    /* -- Vertical loop -- */
    u32HalfHeight = (sImageInfo.u32ImageHeight >> 1) & 0x7fffffff;
    for (u32Yindex = 0; u32Yindex < u32HalfHeight; u32Yindex++)
    {

        /* -- Horizontal loop -- */
        u32BufferWidth = sImageInfo.u32ImageWidth * 4;
        for (u32Xindex = 0; u32Xindex < u32BufferWidth; u32Xindex++) 
        {
            u32FirstByteIndex = u32Yindex*u32BufferWidth+u32Xindex;
            u32SecondByteIndex = (sImageInfo.u32ImageHeight-u32Yindex-1)*u32BufferWidth+u32Xindex;
            u8Byte = *(pu8Buffer+u32FirstByteIndex);
            *(pu8Buffer+u32FirstByteIndex) = *(pu8Buffer+u32SecondByteIndex);
            *(pu8Buffer+u32SecondByteIndex) = u8Byte;
        } /* end of horizontal loop */

    } /* end of horizontal loop */
}

⌨️ 快捷键说明

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