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

📄 jpegmcudec.c

📁 jpeg图像文件软件解码器的arm版本的源代码程序
💻 C
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  JPEGMCUDec.c
//
//  DESCRIPTION
//       Handle the image data related structures.    This decoder does not 
//       handle multiple scans in a frame.
//
//
///////////////////////////////////////////////////////////////////////////////


#include "JPEGMCUDec.h"
#include "JPEGHuffmanDec.h"
#include "JPEGIDCT.h"

/////////////////////////////////////////////////////////////////////////////
// NAME  
//            JPEGMCUConstruct
//
// DESCRIPTION
//            Construct a JPEGMCU object.
//
// INPUTS   
//            jpegMCU - pointer to a JPEGMCU structure
// 
// OUTPUTS  
//            jpegMCU - initialized fields in this structure        
//
// RETURN VALUE
//          none.    
//           
/////////////////////////////////////////////////////////////////////////////
void JPEGMCUConstruct
(
    JPEGMCU     *jpegMCU
)
{
    // initialize all internal variables
    jpegMCU->numComponents = 0;

    jpegMCU->imageMCUBufSize = 0;

    jpegMCU->bitsBuf = 0;
    jpegMCU->bitsBufPtr = 32;        // empty
}


/////////////////////////////////////////////////////////////////////////////
// NAME  
//            JPEGMCUConfig
//
// DESCRIPTION
//            Configure the JPEGMCU object.
//
// INPUTS   
//            jpegSegments - pointer to JPEG segments structure
//            jpegMCU - pointer to a JPEGMCU structure
// 
// OUTPUTS  
//            jpegMCU - setup fields in this structure        
//
// RETURN VALUE
//          Always returns JPEG_OK    
//           
/////////////////////////////////////////////////////////////////////////////
int JPEGMCUConfig
(
    JPEGSegments    *jpegSegments, 
    JPEGMCU         *jpegMCU
)
{
    int                 compIdx;
    int                    tableIdx;
    OP_UINT8            numBlocks;
    JPEGFrameHeader     *frameHeader;
    JPEGScanHeader      *scanHeader;
    JPEGMCUCompInfo     *mcuCompInfo;

    // set the variables according to the information in jpegSegments
    frameHeader = &(jpegSegments->frameHeader);
    scanHeader  = &(jpegSegments->scanHeader);

    jpegMCU->numComponents = frameHeader->numComponents;

    numBlocks = 0;

    // setup the decoding information for each component properly
    for (compIdx = 0; compIdx < scanHeader->numComponents; compIdx ++)
    {
        int             sampFactor;
        int             entropyTableIDs;
        int             quantTableID;
        int             dcHuffTableID;
        int             acHuffTableID;
        JPEGQuantTable  *quantTable;
        JPEGHuffTable   *huffTable;

        mcuCompInfo = jpegMCU->compInfo + compIdx;

        sampFactor = frameHeader->frameCompBlocks[compIdx].sampFactor;
        entropyTableIDs = scanHeader->scanCompBlocks[compIdx].entropyTableIDs;

        // calculate from horizontal and vertical sampling factors
        mcuCompInfo->numCompBlocks = ((sampFactor >> 4) & 0x0F) * (sampFactor & 0x0F);
        numBlocks += mcuCompInfo->numCompBlocks;

        // select the quantization table
        quantTableID = frameHeader->frameCompBlocks[compIdx].quantTableID;

        for (tableIdx = 0; tableIdx < jpegSegments->numQuantTables; tableIdx ++)
        {
            quantTable = &(jpegSegments->quantTables[tableIdx]);
            if (quantTableID == (quantTable->tableSpec & 0x0F))
            {
                mcuCompInfo->quantTable = quantTable->table;
                break;
            }
        }

        // select the Huff tables for this component
        dcHuffTableID = entropyTableIDs >> 4;
        acHuffTableID = entropyTableIDs & 0x0F;

        for (tableIdx = 0; tableIdx < jpegSegments->numHuffTables; tableIdx ++)
        {
            huffTable = &(jpegSegments->huffTables[tableIdx]);

            if ((huffTable->tableSpec >> 4) & 0x0F)
            {
                // AC Huffman TABLE
                if (acHuffTableID == (huffTable->tableSpec & 0x0F))
                {
                    mcuCompInfo->acHuffTable = huffTable;
                }
            }
            else
            {
                // DC Huffman TABLE
                if (dcHuffTableID == (huffTable->tableSpec & 0x0F))
                {
                    mcuCompInfo->dcHuffTable = huffTable;
                }
            }
        }
    }

    // allocate the buffers needed
    jpegMCU->imageMCUBufSize = BLOCK_AREA * numBlocks;

    return JPEG_OK;
}

/////////////////////////////////////////////////////////////////////////////
// NAME  
//            JPEGMCUInitialize
//
// DESCRIPTION
//            Initialize the JPEGMCU structure before the decoding process begins.
//
// INPUTS   
//            jpegMCU - pointer to a JPEGMCU structure
// 
// OUTPUTS  
//            jpegMCU - initializes fields in this structure        
//
// RETURN VALUE
//          none.    
//           
/////////////////////////////////////////////////////////////////////////////
void JPEGMCUInitialize
(
    JPEGMCU     *jpegMCU
)
{
    int                 i; 
    int                 compIdx;
    JPEGMCUCompInfo     *thisCompInfo;

    thisCompInfo = jpegMCU->compInfo;
    for (compIdx = jpegMCU->numComponents; compIdx > 0; compIdx --)
    {
        thisCompInfo->prevDCValue = 0;
        thisCompInfo ++;
    }

    for(i = 0; i < BLOCK_AREA; i++) 
    {
        jpegMCU->coeffMCUBuf[i] = 0;
    }

    jpegMCU->bitsBuf = 0;
    jpegMCU->bitsBufPtr = 32;
}

⌨️ 快捷键说明

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