/* The copyright in this software is being made available under the BSD * License, included below. This software may be subject to other third party * and contributor rights, including patent rights, and no such rights are * granted under this license. * * Copyright (c) 2010-2015, ITU/ISO/IEC * 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. * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * 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. */ /** \file TComPicYuv.cpp \brief picture YUV buffer class */ #include #include #include #ifdef __APPLE__ #include #else #include #endif #include "TComPicYuv.h" #include "TLibVideoIO/TVideoIOYuv.h" //! \ingroup TLibCommon //! \{ TComPicYuv::TComPicYuv() { for(UInt i=0; i> getComponentScaleY(ch)) * getStride(ch) + (m_marginX >> getComponentScaleX(ch)); } // initialize pointers for unused components to NULL for(UInt comp=getNumberValidComponents();comp> maxCUDepth; m_iBaseUnitHeight = maxCUHeight >> maxCUDepth; #endif const Int numCuInWidth = m_picWidth / maxCUWidth + (m_picWidth % maxCUWidth != 0); const Int numCuInHeight = m_picHeight / maxCUHeight + (m_picHeight % maxCUHeight != 0); for(Int chan=0; chan>getChannelTypeScaleY(ch); const Int ctuWidth = maxCUWidth>>getChannelTypeScaleX(ch); const Int stride = getStride(ch); m_ctuOffsetInBuffer[chan] = new Int[numCuInWidth * numCuInHeight]; for (Int cuRow = 0; cuRow < numCuInHeight; cuRow++) { for (Int cuCol = 0; cuCol < numCuInWidth; cuCol++) { m_ctuOffsetInBuffer[chan][cuRow * numCuInWidth + cuCol] = stride * cuRow * ctuHeight + cuCol * ctuWidth; } } m_subCuOffsetInBuffer[chan] = new Int[(size_t)1 << (2 * maxCUDepth)]; const Int numSubBlockPartitions=(1<> maxCUDepth); const Int minSubBlockWidth =(ctuWidth >> maxCUDepth); for (Int buRow = 0; buRow < numSubBlockPartitions; buRow++) { for (Int buCol = 0; buCol < numSubBlockPartitions; buCol++) { m_subCuOffsetInBuffer[chan][(buRow << maxCUDepth) + buCol] = stride * buRow * minSubBlockHeight + buCol * minSubBlockWidth; } } } } Void TComPicYuv::destroy() { for(Int comp=0; compgetChromaFormat() ); for(Int comp=0; compgetWidth(compId) == width); assert(pcPicYuvDst->getHeight(compId) == height); if (strideSrc==pcPicYuvDst->getStride(compId)) { ::memcpy ( pcPicYuvDst->getBuf(compId), getBuf(compId), sizeof(Pel)*strideSrc*getTotalHeight(compId)); } else { const Pel *pSrc = getAddr(compId); Pel *pDest = pcPicYuvDst->getAddr(compId); const UInt strideDest = pcPicYuvDst->getStride(compId); for(Int y=0; y8) { is16bit=true; } } for(Int comp = 0; comp < getNumberValidComponents(); comp++) { const ComponentID compId = ComponentID(comp); const Pel *pi = getAddr(compId); const Int stride = getStride(compId); const Int height = getHeight(compId); const Int width = getWidth(compId); if (is16bit) { for (Int y = 0; y < height; y++ ) { for (Int x = 0; x < width; x++ ) { UChar uc = (UChar)((pi[x]>>0) & 0xff); fwrite( &uc, sizeof(UChar), 1, pFile ); uc = (UChar)((pi[x]>>8) & 0xff); fwrite( &uc, sizeof(UChar), 1, pFile ); } pi += stride; } } else { const Int shift = bitDepths.recon[toChannelType(compId)] - 8; const Int offset = (shift>0)?(1<<(shift-1)):0; for (Int y = 0; y < height; y++ ) { for (Int x = 0; x < width; x++ ) { UChar uc = (UChar)Clip3(0, 255, (pi[x]+offset)>>shift); fwrite( &uc, sizeof(UChar), 1, pFile ); } pi += stride; } } } fclose(pFile); } #if NH_3D_IV_MERGE Void TComPicYuv::getTopLeftSamplePos( Int iCuAddr, Int iAbsZorderIdx, Int& riX, Int& riY ) { Int iRastPartIdx = g_auiZscanToRaster[iAbsZorderIdx]; Int iCuSizeInBases = m_iCuWidth / m_iBaseUnitWidth; Int iCuX = iCuAddr % m_iNumCuInWidth; Int iCuY = iCuAddr / m_iNumCuInWidth; Int iBaseX = iRastPartIdx % iCuSizeInBases; Int iBaseY = iRastPartIdx / iCuSizeInBases; riX = iCuX * m_iCuWidth + iBaseX * m_iBaseUnitWidth; riY = iCuY * m_iCuHeight + iBaseY * m_iBaseUnitHeight; } Void TComPicYuv::getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx ) { Int iCuX = iX / m_iCuWidth; Int iCuY = iY / m_iCuHeight; Int iBaseX = ( iX - iCuX * m_iCuWidth ) / m_iBaseUnitWidth; Int iBaseY = ( iY - iCuY * m_iCuHeight ) / m_iBaseUnitHeight; Int iCuSizeInBases = m_iCuWidth / m_iBaseUnitWidth; riCuAddr = iCuY * m_iNumCuInWidth + iCuX; Int iRastPartIdx = iBaseY * iCuSizeInBases + iBaseX; riAbsZorderIdx = g_auiRasterToZscan[ iRastPartIdx ]; } #endif #if NH_3D_VSO Void TComPicYuv::setChromaTo( Pel pVal ) { xSetPels( getAddr( COMPONENT_Cb ), getStride( COMPONENT_Cb ), getWidth( COMPONENT_Cb), getHeight( COMPONENT_Cb ), pVal ); xSetPels( getAddr( COMPONENT_Cr ), getStride( COMPONENT_Cr ), getWidth( COMPONENT_Cr), getHeight( COMPONENT_Cr ), pVal ); } Void TComPicYuv::xSetPels( Pel* piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Pel iVal ) { for (Int iYPos = 0; iYPos < iHeight; iYPos++) { for (Int iXPos = 0; iXPos < iWidth; iXPos++) { piPelSource[iXPos] = iVal; } piPelSource += iSourceStride; } } #endif //! \}