Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJXR/image/decode/strPredQuantDec.c view on Meta::CPAN
//*@@@+++@@@@******************************************************************
//
// Copyright © Microsoft Corp.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//*@@@---@@@@******************************************************************
#include "strcodec.h"
#define DEQUANT(iRaw, iQP) ((iRaw) * (iQP))
Void dequantizeBlock4x4(PixelI * pRec, Int * pOrg, const Int * pIndex, Int iQPLP)
{
Int i;
for(i = 1; i < 16; i ++)
pRec[pIndex[i]] = DEQUANT(pOrg[i], iQPLP);
}
Void dequantizeBlock2x2(PixelI * pRec, Int * pOrg, Int iQPLP)
{
pRec[32] = DEQUANT(pOrg[1], iQPLP);
pRec[16] = DEQUANT(pOrg[2], iQPLP);
pRec[48] = DEQUANT(pOrg[3], iQPLP);
}
Void dequantizeBlock4x2(PixelI * pRec, Int * pOrg, Int iQPLP)
{
pRec[ 64] = DEQUANT(pOrg[1], iQPLP);
pRec[ 16] = DEQUANT(pOrg[2], iQPLP);
pRec[ 80] = DEQUANT(pOrg[3], iQPLP);
pRec[ 32] = DEQUANT(pOrg[4], iQPLP);
pRec[ 96] = DEQUANT(pOrg[5], iQPLP);
pRec[ 48] = DEQUANT(pOrg[6], iQPLP);
pRec[112] = DEQUANT(pOrg[7], iQPLP);
}
Int dequantizeMacroblock(CWMImageStrCodec * pSC)
{
const COLORFORMAT cf = pSC->m_param.cfColorFormat;
CWMIMBInfo *pMBInfo = &pSC->MBInfo;
CWMITile * pTile = pSC->pTile + pSC->cTileColumn;
const size_t iChannels = pSC->m_param.cNumChannels;
size_t i;
for(i = 0; i < iChannels; i ++){
//dequantize DC
pSC->p1MBbuffer[i][0] = DEQUANT(pMBInfo->iBlockDC[i][0], pTile->pQuantizerDC[i]->iQP);
// dequantize LP
if(pSC->WMISCP.sbSubband != SB_DC_ONLY)
if(i == 0 || (cf != YUV_422 && cf != YUV_420))
dequantizeBlock4x4(pSC->p1MBbuffer[i] , pMBInfo->iBlockDC[i], dctIndex[2], pTile->pQuantizerLP[i][pMBInfo->iQIndexLP].iQP);
else if(cf == YUV_422)
dequantizeBlock4x2(pSC->p1MBbuffer[i], pMBInfo->iBlockDC[i], pTile->pQuantizerLP[i][pMBInfo->iQIndexLP].iQP);
else // 420
dequantizeBlock2x2(pSC->p1MBbuffer[i], pMBInfo->iBlockDC[i], pTile->pQuantizerLP[i][pMBInfo->iQIndexLP].iQP);
}
return ICERR_OK;
}
/* frequency domain inverse DCAC prediction */
Void predDCACDec(CWMImageStrCodec * pSC)
{
const COLORFORMAT cf = pSC->m_param.cfColorFormat;
const Int iChannels = (cf == YUV_420 || cf == YUV_422) ? 1 : (Int) pSC->m_param.cNumChannels;
CWMIMBInfo *pMBInfo = &(pSC->MBInfo);
size_t mbX = pSC->cColumn;// mbY = pSC->cRow;
Int iDCACPredMode = getDCACPredMode(pSC, mbX);
Int iDCPredMode = (iDCACPredMode & 0x3);
Int iADPredMode = (iDCACPredMode & 0xC);
PixelI * pOrg, * pRef;
Int ii;
for(ii = 0; ii < iChannels; ii ++){
pOrg = pMBInfo->iBlockDC[ii];//[dcBlkIdx + (i >> 4)]; // current DC block
/* DC prediction */
if(iDCPredMode == 1){ // predict DC from top
pOrg[0] += pSC->PredInfoPrevRow[ii][mbX].iDC;
}
else if(iDCPredMode == 0){ // predict DC from left
pOrg[0] += (pSC->PredInfo[ii] + mbX - 1)->iDC;
}
else if(iDCPredMode == 2){// predict DC from top&left
pOrg[0] += ((pSC->PredInfo[ii] + mbX - 1)->iDC + (pSC->PredInfoPrevRow[ii] + mbX)->iDC) >> 1;
}
/* AD prediction */
if(iADPredMode == 4){// predict AD from top
pRef = (pSC->PredInfoPrevRow[ii] + mbX)->piAD;
pOrg[4] += pRef[3], pOrg[8] += pRef[4], pOrg[12] += pRef[5];
}
else if(iADPredMode == 0){// predict AD from left
pRef = (pSC->PredInfo[ii] + mbX - 1)->piAD;
pOrg[1] += pRef[0], pOrg[2] += pRef[1], pOrg[3] += pRef[2];
}
( run in 0.350 second using v1.01-cache-2.11-cpan-71847e10f99 )