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

📄 ijglwrap.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                               m_ulChromaKeyTol,                                               m_ulChromaKeyOpacity);                }            }            if (m_cDecompress.output_scanline >= m_cDecompress.output_height)            {                m_ulState = kStateReadingCompleted;            }        }        else if (m_ulState == kStateReadingCompleted)        {            /* Finish the decompression */            bRet = jpeg_finish_decompress(&m_cDecompress);            if (bRet == TRUE)            {                /* We had enough data */                m_bSuspended = FALSE;                /* Set the new state */                m_ulState = kStateFinished;            }            else            {                /* We suspended */                m_bSuspended = TRUE;            }        }    }    while (m_bSuspended == FALSE && m_ulState != kStateFinished);    return HXR_OK;}void /*_cdecl*/ CIJGLibraryWrapper::ErrorExit(j_common_ptr cinfo){    /* Check for input error conditions */    if (cinfo->err == NULL)    {        return;    }    if (cinfo->err->output_message == NULL)    {        return;    }    /* Call our output message function */    (*cinfo->err->output_message)(cinfo);    /* Get a pointer to a WrapperErrorMgr */    WrapperErrorMgr *pMgr = (WrapperErrorMgr *) cinfo->err;    /* Return control to the setjmp point */    longjmp(pMgr->m_cSetJmpBuf, 1);};void /*_cdecl*/ CIJGLibraryWrapper::OutputMessage(j_common_ptr cinfo){    /* Check for input error conditions */    if (cinfo->err == NULL)    {        return;    }    if (cinfo->err->format_message == NULL)    {        return;    }    /* Get a pointer to a WrapperErrorMgr */    WrapperErrorMgr *pMgr = (WrapperErrorMgr *) cinfo->err;    /* Create the message */    (*cinfo->err->format_message)(cinfo, (char *) pMgr->m_cErrStr.c_str());}UINT32 CIJGLibraryWrapper::GetMemorySum(){    /* Run through our current buffer list and add up the sizes */    UINT32 ulSum = 0;    for (GListIterator itr  = m_cSrcMgr.m_cBufferList.Begin();                       itr != m_cSrcMgr.m_cBufferList.End(); itr++)    {        /* Get the pointer from the iterator */        IHXBuffer *pBuffer = (IHXBuffer *) *itr;        /* Add the buffer size */        ulSum += pBuffer->GetSize();    }    return ulSum;}void /*_cdecl*/ CIJGLibraryWrapper::InitSource(j_decompress_ptr cinfo){    /* No work to do here */}boolean /*_cdecl*/ CIJGLibraryWrapper::FillInputBuffer(j_decompress_ptr cinfo){    /* Check for input error conditions */    if (cinfo->src == NULL)    {        ERREXIT(cinfo, JERR_INPUT_EMPTY);    }    /* Get a pointer to a BufferListSrcMgr */    BufferListSrcMgr *pMgr = (BufferListSrcMgr *) cinfo->src;    /* Check to see if there are more buffers in the list */    if (pMgr->m_lCurrentIndex + 1 >= (INT32) pMgr->m_cBufferList.Size())    {        /* We don't have any more buffers in our list, so suspend. */        return FALSE;    }    /* We do have more buffers, so increment the index and get the MyBuffer pointer */    pMgr->m_lCurrentIndex++;    IHXBuffer *pBuffer = (IHXBuffer *) pMgr->m_cBufferList[pMgr->m_lCurrentIndex];    if (pBuffer == NULL)    {        ERREXIT(cinfo, JERR_INPUT_EMPTY);    }    /* Save the current public source manager state variables */    UINT32 ulOldBytesInBuffer = pMgr->m_cPubSrcMgr.bytes_in_buffer;    BYTE  *pOldNextInputByte  = (BYTE *) pMgr->m_cPubSrcMgr.next_input_byte;    // There might be some header bytes at the beginning of each buffer,    // so we must offset by this amount    pMgr->m_cPubSrcMgr.bytes_in_buffer = pBuffer->GetSize()   - pMgr->m_ulBufferOffset;    pMgr->m_cPubSrcMgr.next_input_byte = pBuffer->GetBuffer() + pMgr->m_ulBufferOffset;    /*     * If this is the first successful fill we've done, then     * don't try to remove any buffers from the list.     */    if (pMgr->m_bFirstFill == TRUE)    {        pMgr->m_bFirstFill = FALSE;        return TRUE;    }        /*     * Determine which buffers we can release. The restart point is     * defined by the next_input_byte pointer. All buffers which are     * before the buffer which contains the restart point can be deleted.     */    while (pMgr->m_cBufferList.Size() > 0)    {        /* Get the buffer at the front of the list */        IHXBuffer *pListBuffer = (IHXBuffer *) pMgr->m_cBufferList.First();        /* Check to see if the old restart point is within this buffer */        if (pOldNextInputByte >= pListBuffer->GetBuffer() &&            pOldNextInputByte <= pListBuffer->GetBuffer() + pListBuffer->GetSize())        {            /*             * The old restart marker is within this buffer, so             * we can't delete it. This is because the jpeg library             * may have to back up into this buffer             */            break;        }        /* Remove this buffer from the front of the list */        pMgr->m_cBufferList.PopFront();        /*         * Decrement the current index since there's now one         * less buffer at the beginning of the list         */        pMgr->m_lCurrentIndex--;        /* Release the IHXBuffer object */        HX_RELEASE(pListBuffer);    }    return TRUE;}void /*_cdecl*/ CIJGLibraryWrapper::SkipInputData(j_decompress_ptr cinfo, long num_bytes){    /* Check for input error conditions */    if (cinfo->src == NULL)    {        ERREXIT(cinfo, JERR_INPUT_EMPTY);    }    /* Get a pointer to a BufferListSrcMgr */    BufferListSrcMgr *pMgr = (BufferListSrcMgr *) cinfo->src;    /* If we don't currently have any data, then we're finished */    if (pMgr->m_cBufferList.Size() == 0)    {        return;    }    /*     * All we're going to do for now is skip if we can within the     * data we have in the current buffer.     */    INT32 lLeftOverBytes = pMgr->m_cPubSrcMgr.bytes_in_buffer - num_bytes;    if (lLeftOverBytes >= 0)    {        /* We've got enough in the current buffer */        pMgr->m_cPubSrcMgr.bytes_in_buffer -= num_bytes;        pMgr->m_cPubSrcMgr.next_input_byte += num_bytes;    }}void /*_cdecl*/ CIJGLibraryWrapper::TermSource(j_decompress_ptr cinfo){    /* No work to do here */}HX_RESULT CIJGLibraryWrapper::TranscodeToRestartInterval(IHXBuffer *      pInputImage,                                                         UINT32            ulRestartInterval,                                                         REF(IHXBuffer *) rpOutputImage){    // Initialize the decompression error manager    WrapperErrorMgr               cErrMgr;    struct jpeg_decompress_struct cSrcInfo;    cSrcInfo.err = (struct jpeg_error_mgr *) &cErrMgr;    // Set up the default methods we won't override    jpeg_std_error(&cErrMgr.m_cPubErrMgr);    // Set the fields in the public manager we want to override    cErrMgr.m_cPubErrMgr.error_exit     = ErrorExit;    cErrMgr.m_cPubErrMgr.output_message = OutputMessage;    // Give the string enough to hold the biggest error string    if (cErrMgr.m_cErrStr.reserve(JMSG_LENGTH_MAX))    {        return HXR_OUTOFMEMORY;    }    // Forward declare some local variables    struct jpeg_compress_struct cDstInfo;    BYTE *                      pDstBuf = NULL;    // Here's the error return point    if (setjmp(cErrMgr.m_cSetJmpBuf))    {        // If we get here, the JPEG library has signaled a fatal error.        jpeg_destroy_compress(&cDstInfo);        jpeg_destroy_decompress(&cSrcInfo);        HX_VECTOR_DELETE(pDstBuf);        return HXR_FAIL;    }    // Initialize the JPEG decompression object with our error handling    jpeg_create_decompress(&cSrcInfo);    // Specify data source for decompression    jpeg_buffer_src(&cSrcInfo, pInputImage->GetBuffer(), pInputImage->GetSize());    // Read input file header    (void) jpeg_read_header(&cSrcInfo, TRUE);    // Read the DCT coefficients out of the input file    jvirt_barray_ptr *src_coef_arrays = jpeg_read_coefficients(&cSrcInfo);    // Create an output buffer the size of the uncompressed image - that    // will surely be enough    UINT32 ulDstBufSize = cSrcInfo.image_width * cSrcInfo.image_height * cSrcInfo.num_components;    pDstBuf             = new BYTE [ulDstBufSize];    if (!pDstBuf)    {        jpeg_destroy_compress(&cDstInfo);        jpeg_destroy_decompress(&cSrcInfo);        HX_VECTOR_DELETE(pDstBuf);        return HXR_OUTOFMEMORY;    }    // Initialize the compression error manager    cDstInfo.err = (struct jpeg_error_mgr *) &cErrMgr;    // Initialize the JPEG compression object with our error handling.    jpeg_create_compress(&cDstInfo);    // Initialize destination compression parameters from source values    jpeg_copy_critical_parameters(&cSrcInfo, &cDstInfo);    // Output DCT arrays will be same as input DCT arrays    jvirt_barray_ptr *dst_coef_arrays = src_coef_arrays;    // Specify data destination for compression    jpeg_buffer_dst(&cDstInfo, pDstBuf, ulDstBufSize);    // Set restart interval    cDstInfo.restart_interval = ulRestartInterval;    cDstInfo.restart_in_rows  = 0;    // Start compressor (note no image data is actually written here)    jpeg_write_coefficients(&cDstInfo, dst_coef_arrays);    // Finish compression    jpeg_finish_compress(&cDstInfo);    // Compute the output file size    UINT32 ulOutSize = ulDstBufSize - cDstInfo.dest->free_in_buffer;    // Destroy the compression object    jpeg_destroy_compress(&cDstInfo);    // Finish decompression    (void) jpeg_finish_decompress(&cSrcInfo);    // Destroy the decompression object    jpeg_destroy_decompress(&cSrcInfo);    // Create an output IHXBuffer    IHXBuffer *pBuffer = new CHXBuffer();    if (!pBuffer)    {        HX_VECTOR_DELETE(pDstBuf);        return HXR_OUTOFMEMORY;    }    pBuffer->AddRef();    // Set the output IHXBuffer to the output data    HX_RESULT retVal = pBuffer->Set(pDstBuf, ulOutSize);    if (retVal != HXR_OK)    {        HX_VECTOR_DELETE(pDstBuf);        HX_RELEASE(pBuffer);        return retVal;    }    // Now we're done with the intermediate buffer    HX_VECTOR_DELETE(pDstBuf);    // Set the outgoing buffer    rpOutputImage = pBuffer;    return HXR_OK;}HX_RESULT CIJGLibraryWrapper::GetLastOpaqueBuffer(REF(IHXBuffer*) rpOpaque){    HX_RESULT retVal = HXR_FAIL;    if (m_pLastOpaque)    {        HX_RELEASE(rpOpaque);        rpOpaque = m_pLastOpaque;        rpOpaque->AddRef();        retVal   = HXR_OK;    }    return retVal;}void CIJGLibraryWrapper::SetLastOpaqueBuffer(IHXBuffer* pOpaque){    if (pOpaque)    {        HX_RELEASE(m_pLastOpaque);        m_pLastOpaque = pOpaque;        m_pLastOpaque->AddRef();    }}void CIJGLibraryWrapper::SetChromaKeyInfo(UINT32 ulKey, UINT32 ulTol, UINT32 ulOp){    m_ulChromaKey         = ulKey;    m_ulChromaKeyTol      = ulTol;    m_ulChromaKeyOpacity  = ulOp;    m_bChromaKeySpecified = TRUE;}void CIJGLibraryWrapper::ExpandGrayToRGB(BYTE*  pBuf,                                         UINT32 ulWidth,                                         BOOL   bBigEndian){    if (pBuf)    {        BYTE*   pGray = pBuf + ulWidth - 1;        UINT32* pRGB  = ((UINT32*) pBuf) + ulWidth - 1;        while (ulWidth--)        {            *pRGB = ((*pGray) << 16) | ((*pGray) << 8) | (*pGray);            pRGB--;            pGray--;        }    }}void CIJGLibraryWrapper::ProcessOpacityAndChromaKey(BYTE*  pBuf,                                                    UINT32 ulWidth,                                                    UINT32 ulOpacity,                                                    BOOL   bChromaKey,                                                    UINT32 ulChromaKey,                                                    UINT32 ulChromaKeyTol,                                                    UINT32 ulChromaKeyOpacity){    if (pBuf)    {        // Clip the opacities        if (ulOpacity > 255) ulOpacity = 255;        if (ulChromaKeyOpacity > 255) ulChromaKeyOpacity = 255;        // Compute alphas (go ahead and pre-shift)        UINT32 ulAlpha       = (255 - ulOpacity) << 24;        UINT32 ulChromaAlpha = (255 - ulChromaKeyOpacity) << 24;        // Determine whether we need to process opacity,        // chroma key, or both        if (ulOpacity < 255 && !bChromaKey)        {            // Process opacity but not chroma key            UINT32* pPix = (UINT32*) pBuf;            while (ulWidth--)            {                *pPix = (*pPix & 0x00FFFFFF) | ulAlpha;                pPix++;            }        }        else if (ulOpacity >= 255 && bChromaKey)        {            // Process chroma key but not opacity            UINT32* pPix = (UINT32*) pBuf;            while (ulWidth--)            {                if (DoesChromaKeyMatch(*pPix, ulChromaKey, ulChromaKeyTol))                {                    *pPix = (*pPix & 0x00FFFFFF) | ulChromaAlpha;                }                pPix++;            }        }        else if (ulOpacity < 255 && bChromaKey)        {            // Compute new chroma alpha            UINT32 ulNewChromaKeyOpacity = ulChromaKeyOpacity * ulOpacity / 255;            UINT32 ulNewChromaAlpha      = (255 - ulNewChromaKeyOpacity) << 24;            // Process both opacity and chroma key            UINT32* pPix = (UINT32*) pBuf;            while (ulWidth--)            {                if (DoesChromaKeyMatch(*pPix, ulChromaKey, ulChromaKeyTol))                {                    *pPix = (*pPix & 0x00FFFFFF) | ulNewChromaAlpha;                }                else                {                    *pPix = (*pPix & 0x00FFFFFF) | ulAlpha;                }                pPix++;            }        }    }}

⌨️ 快捷键说明

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