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

📄 omxicjp_encodehuffman8x8_direct_s16_u1_c1.c

📁 The OpenMAX DL (Development Layer) APIs contain a comprehensive set of audio, video, signal processi
💻 C
字号:
/** * *  * File Name:  omxICJP_EncodeHuffman8x8_Direct_S16_U1_C1.c * OpenMAX DL: v1.0.2 * Revision:   10586 * Date:       Wednesday, March 5, 2008 *  * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved. *  *  * * Description: Huffman encoding function. * */#include "omxtypes.h"#include "armOMX.h"#include "omxIC.h"#include "armCOMM.h"#include "armCOMM_Bitstream.h"#include "armIC.h"static OMXResult armICJP_FindDiffCategory(OMX_U16 value, OMX_U16 *pCategory);static OMXResult armICJP_WriteHuffmanCode(OMX_U8 **ppHuffDst, OMX_INT *pHuffBitOffset,                         const armICJP_EncHuffmanSpec *pARM_HuffTable, OMX_U32 value);       /** * Function:  omxICJP_EncodeHuffman8x8_Direct_S16_U1_C1   (5.1.3.4.3) * * Description: * Implements the Huffman encoder for baseline mode.  The input raster  * scanned source data block (8x8) is zigzag scanned , prior to encoding.  To  * match the transposed order of the input DCT, an implicit transpose of the  * source data block is integrated into the zigzag scan. The DC prediction  * coefficient (*pDCPred) should be initialized to zero and reset to zero  * after every restart interval.  Example 5-1 illustrates Huffman encoder  * buffer behavior.  * * Input Arguments: *    *   pSrc - pointer to the source data block (8x8), in transposed order; must  *            be aligned on a 32-byte boundary.  *   pDCHuffTable - pointer to the OMXICJPHuffmanEncodeSpec data structure  *            containing the DC Huffman encoder table; must be aligned on a  *            4-byte boundary.  *   pACHuffTable - pointer to the OMXICJPHuffmanEncodeSpec data structure  *            containing the AC Huffman encoder table; must be aligned on a  *            4-byte boundary.  *   pSrcDstBitsLen - pointer to the next available bit in the output buffer  *            (pDst); informs the Huffman encoder of where to start writing  *            the output bits for the current block.  To accommodate a  *            non-empty pDst buffer upon function entry, the parameter  *            pSrcDstBitsLen indicates the position of the current bit (output  *            start position) as an offset relative to pDst, or equivalently,  *            the buffer length upon entry in terms of bits.  The number of  *            bytes contained in the output buffer is given by  *            pSrcDstBitsLen>>3, the number of bits contained in the current  *            byte is given by pSrcDstBitsLen&0x7, and the number of bits free  *            in the current byte is given by 8 (pSrcDstBitsLen&0x7). There is  *            no restriction on buffer length. It is the responsibility of the  *            caller to maintain the buffer and limit its length as  *            appropriate for the target application or environment. The value  *            *pSrcDstBitsLen is updated upon return as described below under  *             Output Arguments .  The parameter pSrcDstBitsLen must be  *            aligned on a 4-byte boundary.  *   pDCPred - pointer to the DC prediction coefficient. Upon input should  *            contain the value of the quantized DC coefficient from the most  *            recently coded block.  Updated upon return as described below;  *            must be aligned on a 4-byte boundary.  * * Output Arguments: *    *   pDst - pointer to the to the first byte in the JPEG output bitstream  *            buffer both upon function entry and upon function return, i.e.,  *            the function does not modify the value of the pointer. The next  *            available bit in the buffer is indexed by the parameter  *            pSrcDstBitsLen, i.e., for a buffer of non zero length, the value  *            of the last bit written during the Huffman block encode  *            operation is given by (pDst[currentByte]>>currentBit)&0x1, where  *            currentByte=(pSrcDstBitsLen 1)>>3, and  *            currentBit=7-((pSrcDstBitsLen-1)&0x7). Within each byte, bits  *            are filled from most significant to least significant, and  *            buffer contents are formatted in accordance with CCITT T.81. The  *            pointer pDst must be aligned on a 4-byte boundary.  *   pSrcDstBitsLen - pointer to the next available bit position in the  *            output buffer (pDst) following the block Huffman encode  *            operation; informs the caller of where the Huffman encoder  *            stopped writing bits for the current block. The updated value  *            *pSrcDstBitsLen indexes the position following the last bit  *            written to the output buffer relative to pDst, or equivalently,  *            it indicates the updated number of bits contained in the output  *            buffer after block encoding has been completed. Usage guidelines  *            apply as described above under  Input Arguments.   *   pDCPred - pointer to the DC prediction coefficient. Updated upon return  *            to contain the DC coefficient from the current block; the  *            pointer must be aligned on a 4-byte boundary.  * * Return Value: *     *    OMX_Sts_NoErr - no error  *    OMX_Sts_BadArgErr - Bad arguments. Returned for any of the following  *              conditions: a pointer was NULL the start address of a pointer  *              was not 4-byte aligned.  *    -    *pDstBitsLen was less than 0.  * */OMXResult omxICJP_EncodeHuffman8x8_Direct_S16_U1_C1(        const OMX_S16 *pSrc,        OMX_U8  *pDst,        OMX_INT *pSrcDstBitsLen,        OMX_S16 *pDCPred,        const OMXICJPHuffmanEncodeSpec *pDCHuffTable,        const OMXICJPHuffmanEncodeSpec *pACHuffTable       ){    OMX_U8  *pHuffDst, *pHuffDstRef, **ppHuffDst;    OMX_INT huffBitOffset, numBytesWritten, numBitsWritten;    OMX_INT dcDiff, i, zeroRunLen = 0;    OMX_U16 diffCategory;    OMX_S16 curAcCoeff;    const armICJP_EncHuffmanSpec *pARM_DCHuffTable = (armICJP_EncHuffmanSpec *) pDCHuffTable;    const armICJP_EncHuffmanSpec *pARM_ACHuffTable = (armICJP_EncHuffmanSpec *) pACHuffTable;        armRetArgErrIf(!pSrc,         OMX_Sts_BadArgErr);    armRetArgErrIf(!pDst,         OMX_Sts_BadArgErr);    armRetArgErrIf(!pDCPred,      OMX_Sts_BadArgErr);    armRetArgErrIf(!pSrcDstBitsLen, OMX_Sts_BadArgErr);    armRetArgErrIf(!pDCHuffTable,   OMX_Sts_BadArgErr);    armRetArgErrIf(!pACHuffTable,   OMX_Sts_BadArgErr);    armRetArgErrIf(*pSrcDstBitsLen < 0, OMX_Sts_BadArgErr);    armRetArgErrIf(armNot4ByteAligned(pSrc),    OMX_Sts_BadArgErr);    armRetArgErrIf(armNot4ByteAligned(pDst),    OMX_Sts_BadArgErr);    armRetArgErrIf(armNot4ByteAligned(pDCPred), OMX_Sts_BadArgErr);    armRetArgErrIf(armNot4ByteAligned(pSrcDstBitsLen), OMX_Sts_BadArgErr);    armRetArgErrIf(armNot4ByteAligned(pDCHuffTable),   OMX_Sts_BadArgErr);    armRetArgErrIf(armNot4ByteAligned(pACHuffTable),   OMX_Sts_BadArgErr);        pHuffDst        = pDst + (*pSrcDstBitsLen)/8;    pHuffDstRef     = pDst + (*pSrcDstBitsLen)/8;    ppHuffDst       = &pHuffDst;    huffBitOffset   = *pSrcDstBitsLen % 8;        /*    -----------------------------------------------------------------------    DC Huffman Encoding is described in the JPEG Standard [ISO10918]     Annex F.1.2.1: Huffman encoding of DC coefficients.    -----------------------------------------------------------------------    */        dcDiff      = *pSrc - *pDCPred;    *pDCPred    = *pSrc;        armICJP_FindDiffCategory(armAbs(dcDiff), &diffCategory);    armICJP_WriteHuffmanCode(ppHuffDst, &huffBitOffset, pARM_DCHuffTable, diffCategory);        dcDiff = (dcDiff < 0) ? (dcDiff - 1) : dcDiff;    armPackBits(ppHuffDst, &huffBitOffset, dcDiff, diffCategory);        /*    -----------------------------------------------------------------------    AC Huffman Encoding is described in the JPEG Standard [ISO10918]     Annex F.1.2.2: Huffman encoding of AC coefficients.    -----------------------------------------------------------------------    */        for(i = 1; i < ARM_ICJP_BLOCKSIZE; i++)    {        curAcCoeff = pSrc[i];                if(curAcCoeff == 0)        {            if (i == ARM_ICJP_BLOCKSIZE - 1)            {                armICJP_WriteHuffmanCode(ppHuffDst, &huffBitOffset, pARM_ACHuffTable, 0);                break;            }            zeroRunLen++;        }        else        {            while(zeroRunLen > 15)            {                armICJP_WriteHuffmanCode(ppHuffDst, &huffBitOffset, pARM_ACHuffTable, (16 * 15 + 0));                zeroRunLen -= 16;            }                        armICJP_FindDiffCategory(armAbs(curAcCoeff), &diffCategory);            armICJP_WriteHuffmanCode(ppHuffDst, &huffBitOffset, pARM_ACHuffTable, (16 * zeroRunLen + diffCategory));            curAcCoeff = (curAcCoeff < 0) ? (curAcCoeff - 1) : curAcCoeff;            armPackBits(ppHuffDst, &huffBitOffset, curAcCoeff, diffCategory);                        zeroRunLen = 0;        }    }        /*    -----------------------------------------------------------------------    Update the in/out parameter <pSrcDstBitsLen> to reflect the Huffman codes    written into the stream.    -----------------------------------------------------------------------    */        numBytesWritten  = (OMX_INT)(pHuffDst - pHuffDstRef);    numBitsWritten   = (numBytesWritten * 8) + huffBitOffset - (*pSrcDstBitsLen % 8);    *pSrcDstBitsLen += numBitsWritten;        return OMX_Sts_NoErr;}/** * Function: armICJP_FindDiffCategory * * Description: * This function finds the difference category to which the input value belongs. * This function looks up the table armICJP_HuffmanCategoryTable[], for finding * the category. * * Parameters: * [in]  value      The difference value for which the category is to be found. * [out] pCategory  The difference category to which the current value belongs. * * Return Value: * Standard OMXResult result. See enumeration for possible result codes. * */static OMXResult armICJP_FindDiffCategory(        OMX_U16 value,        OMX_U16 *pCategory       ){    armRetArgErrIf(!pCategory, OMX_Sts_BadArgErr);        if (value < 256)    {        *pCategory  = armICJP_HuffmanCategoryTable[value];    }    else    {        value       = value >> 8;        *pCategory  = armICJP_HuffmanCategoryTable[value] + 8;    }    return OMX_Sts_NoErr;}/** * Function: armICJP_WriteHuffmanCode * * Description: * This function looks up the Huffman encoding table to find the Huffman code for the input * value; Then writes this into the destination buffer and updates the buffer pointer and  * the bit-offset of the current byte. * * Parameters: * [in]  ppHuffDst       Pointer to pointer to the stream, where Huffman code is to be written. * [in]  pHuffBitOffset  Pointer to the bit offset in the current byte pointed by ppHuffDst. * [in]  pARM_HuffTable  Pointer to the Huffman Table structure. * [in]  value           The value to be encoded using the Huffman codes. * [out] ppHuffDst       Updated pointer to pointer to the stream, where Huffman code was written. * [out] pHuffBitOffset  Updated pointer to the bit offset in the current byte pointed by ppHuffDst. * * Return Value: * Standard OMXResult result. See enumeration for possible result codes. * */static OMXResult armICJP_WriteHuffmanCode(        OMX_U8 **ppHuffDst,        OMX_INT *pHuffBitOffset,        const armICJP_EncHuffmanSpec *pARM_HuffTable,        OMX_U32 value       ){    OMX_U8  huffSize = pARM_HuffTable->pHuffStruct[value].codeLen;    OMX_U16 huffCode = pARM_HuffTable->pHuffStruct[value].codeWord;        if(huffSize)    {        armPackBits(ppHuffDst, pHuffBitOffset, huffCode, huffSize);        return OMX_Sts_NoErr;    }        return OMX_Sts_Err;}/* End of file */

⌨️ 快捷键说明

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