/* 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-2014, 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; igetConformanceWindow(); } #endif #endif #if LAYER_CTB m_iMarginX = uiMaxCUWidth + 16; // for 16-byte alignment m_iMarginY = uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding #else m_iMarginX = g_uiMaxCUWidth + 16; // for 16-byte alignment m_iMarginY = g_uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding #endif m_bIsBorderExtended = false; // assign the picture arrays and set up the ptr to the top left of the original picture { Int chan=0; for(; chan> getComponentScaleY(ch)) * getStride(ch) + (m_iMarginX >> getComponentScaleX(ch)); } for(;chan>getComponentScaleY(ch); const Int ctuWidth=uiMaxCUWidth>>getComponentScaleX(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 * uiMaxCUDepth)]; const Int numSubBlockPartitions=(1<> uiMaxCUDepth); const Int minSubBlockWidth =(ctuWidth >> uiMaxCUDepth); for (Int buRow = 0; buRow < numSubBlockPartitions; buRow++) for (Int buCol = 0; buCol < numSubBlockPartitions; buCol++) m_subCuOffsetInBuffer[chan][(buRow << uiMaxCUDepth) + buCol] = stride * buRow * minSubBlockHeight + buCol * minSubBlockWidth; } return; } Void TComPicYuv::destroy() { for(Int chan=0; changetWidth(COMPONENT_Y) ); assert( m_iPicHeight == pcPicYuvDst->getHeight(COMPONENT_Y) ); assert( m_chromaFormatIDC == pcPicYuvDst->getChromaFormat() ); for(Int chan=0; changetBuf(ch), m_apiPicBuf[ch], sizeof (Pel) * getStride(ch) * getTotalHeight(ch)); } return; } Void TComPicYuv::extendPicBorder () { if ( m_bIsBorderExtended ) return; for(Int chan=0; chan0)?(1<<(shift-1)):0; const Pel *pi = getAddr(ch); const Int stride = getStride(ch); const Int height = getHeight(ch); const Int width = getWidth(ch); 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); } Void TComPicYuv::dump( Char* pFileName, Bool bAdd, Int bitDepth ) { FILE* pFile; if (!bAdd) { pFile = fopen (pFileName, "wb"); } else { pFile = fopen (pFileName, "ab"); } if( bitDepth == 8 ) { dump( pFileName, bAdd ); return; } for(Int chan = 0; chan < getNumberValidComponents(); chan++) { const ComponentID ch = ComponentID(chan); const Pel *pi = getAddr(ch); const Int stride = getStride(ch); const Int height = getHeight(ch); const Int width = getWidth(ch); for (Int y = 0; y < height; y++ ) { for (Int x = 0; x < width; x++ ) { Pel pix = pi[x]; UChar uc = pix & 0xff; fwrite( &uc, sizeof(UChar), 1, pFile ); uc = (pix >> 8) & 0xff; fwrite( &uc, sizeof(UChar), 1, pFile ); } pi += stride; } } fclose(pFile); } #if AUXILIARY_PICTURES Void TComPicYuv::convertToMonochrome() { Pel grayVal = (1 << (g_bitDepth[CHANNEL_TYPE_CHROMA] - 1)); for( UInt comp = 1; comp < getNumberValidComponents(); comp++ ) { const ComponentID ch=ComponentID(comp); for( UInt i = 0; i < getStride(ch) * getTotalHeight(ch); i++ ) { m_apiPicBuf[ch][i] = grayVal; } } } #endif //! \}