/* 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-2011, 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 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. */ #include "TRenImage.h" #include "TRenImagePlane.h" #include "TRenFilter.h" #include "assert.h" template TRenImage::TRenImage( TRenImage& rcIn ) { allocatePlanes( rcIn.getPlane(0)->getWidth(), rcIn.getPlane(0)->getHeight(), rcIn.getNumberOfFullPlanes(), rcIn.getNumberOfQuaterPlanes() ) ; assign(&rcIn); } template TRenImage::TRenImage( UInt uiWidth, UInt uiHeight, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes ) { allocatePlanes( uiWidth, uiHeight, uiNumberOfFullPlanes, uiNumberOfQuaterPlanes ); } template TRenImage::TRenImage() : m_uiNumberOfFullPlanes(0), m_uiNumberOfQuaterPlanes(0), m_uiNumberOfPlanes(0), m_apcPlanes(0) { } template<> TRenImage::TRenImage( TComPicYuv* pcPicYuv, Bool bFirstPlaneOnly ) { if (bFirstPlaneOnly) //400 { m_uiNumberOfPlanes = 1; m_uiNumberOfFullPlanes = 1; m_uiNumberOfQuaterPlanes = 0; m_apcPlanes = new TRenImagePlane*[ m_uiNumberOfPlanes ]; m_apcPlanes[0] = new TRenImagePlane( pcPicYuv->getBufY(), pcPicYuv->getWidth() + (REN_LUMA_MARGIN << 1), pcPicYuv->getHeight()+ (REN_LUMA_MARGIN << 1), pcPicYuv->getStride (), REN_LUMA_MARGIN ); } else //420 { m_uiNumberOfPlanes = 3; m_uiNumberOfFullPlanes = 1; m_uiNumberOfQuaterPlanes = 2; m_apcPlanes = new TRenImagePlane*[ m_uiNumberOfPlanes ]; m_apcPlanes[0] = new TRenImagePlane( pcPicYuv->getBufY(), pcPicYuv->getWidth() + (REN_LUMA_MARGIN << 1), pcPicYuv->getHeight() + (REN_LUMA_MARGIN << 1), pcPicYuv->getStride (), REN_LUMA_MARGIN ); m_apcPlanes[1] = new TRenImagePlane( pcPicYuv->getBufU(), (pcPicYuv->getWidth()>>1)+ REN_LUMA_MARGIN , (pcPicYuv->getHeight()>>1) + REN_LUMA_MARGIN , pcPicYuv->getCStride(), REN_LUMA_MARGIN >> 1 ); m_apcPlanes[2] = new TRenImagePlane( pcPicYuv->getBufV(), (pcPicYuv->getWidth()>>1)+ REN_LUMA_MARGIN , (pcPicYuv->getHeight()>>1) + REN_LUMA_MARGIN , pcPicYuv->getCStride(), REN_LUMA_MARGIN >> 1 ); } } template TRenImage* TRenImage::create() { return new TRenImage( m_apcPlanes[0]->getWidth(), m_apcPlanes[0]->getHeight(), m_uiNumberOfFullPlanes, m_uiNumberOfQuaterPlanes ); } template TRenImage::TRenImage( TComPicYuv* pcPicYuv, Bool bFirstPlaneOnly ) { assert(0); } template TRenImagePlane* TRenImage::getPlane(UInt uiPlaneNumber) const { return m_apcPlanes[uiPlaneNumber]; } template TRenImagePlane** TRenImage::getPlanes() const { return m_apcPlanes; } template Void TRenImage::getDataAndStrides( T** pptData, Int* piStrides ) { for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++ ) { piStrides[uiCurPlane] = m_apcPlanes[uiCurPlane]->getStride (); pptData [uiCurPlane] = m_apcPlanes[uiCurPlane]->getPlaneData(); } } template Void TRenImage::getWidthAndHeight( Int* ppiWidths, Int* ppiHeights ) { for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++ ) { ppiWidths [uiCurPlane] = m_apcPlanes[uiCurPlane]->getWidth (); ppiHeights[uiCurPlane] = m_apcPlanes[uiCurPlane]->getHeight(); } } template Void TRenImage::allocatePlanes( UInt uiWidth, UInt uiHeight, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes ) { assert( uiNumberOfFullPlanes + uiNumberOfQuaterPlanes); UInt uiHalfWidth = uiWidth / 2; UInt uiHalfHeight = uiHeight / 2; uiHalfWidth = (uiHalfWidth == 0) ? 1 : uiHalfWidth ; uiHalfHeight = (uiHalfHeight == 0) ? 1 : uiHalfHeight; m_uiNumberOfPlanes = uiNumberOfFullPlanes + uiNumberOfQuaterPlanes; ; m_uiNumberOfFullPlanes = uiNumberOfFullPlanes; m_uiNumberOfQuaterPlanes = uiNumberOfQuaterPlanes; this->m_apcPlanes = new TRenImagePlane*[m_uiNumberOfPlanes]; for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfFullPlanes; uiCurPlane++) { this->m_apcPlanes[uiCurPlane] = new TRenImagePlane(uiWidth, uiHeight, REN_LUMA_MARGIN); }; for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfQuaterPlanes; uiCurPlane++) { this->m_apcPlanes[uiCurPlane+uiNumberOfFullPlanes] = new TRenImagePlane(uiHalfWidth, uiHalfHeight, REN_LUMA_MARGIN >> 1); }; } template Void TRenImage::assign(Int iVal) { for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) { m_apcPlanes[uiCurPlane]->assign( iVal); } } template Void TRenImage::devide( Double dDevisor ) { for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) { m_apcPlanes[uiCurPlane]->devide(dDevisor); } } template template Void TRenImage::assign( TRenImage* pcSrcImage ) { if (pcSrcImage->getNumberOfPlanes() != m_uiNumberOfPlanes ) { assert(0); } for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) { m_apcPlanes[uiCurPlane]->assign(pcSrcImage->getPlane(uiCurPlane)->getPlaneDataOrg(),pcSrcImage->getPlane(uiCurPlane)->getStride()); } } template Void TRenImage::setData( TRenImage* pcInputImage, Bool bClean ) { for (UInt uiPlane = 0; uiPlane < m_uiNumberOfPlanes; uiPlane++) { m_apcPlanes[uiPlane]->setData( pcInputImage->getPlane( uiPlane ), bClean ); } } template Void TRenImage::extendMargin() { for (UInt uiPlane = 0; uiPlane < m_uiNumberOfPlanes; uiPlane++) { m_apcPlanes[uiPlane]->extendMargin(); } } template Void TRenImage::xDeletePlanes() { for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) { if ( m_apcPlanes[uiCurPlane]) { delete m_apcPlanes[uiCurPlane]; } m_apcPlanes[uiCurPlane] = 0; } } template Void TRenImage::init() { // YUV-init m_apcPlanes[0]->assign((Pel) 0 ); for (UInt uiCurPlane = 1; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++) { m_apcPlanes[uiCurPlane]->assign( (Pel) ((g_uiIBDI_MAX+1) >> 1) ); } } template TRenImage::~TRenImage() { xDeletePlanes(); delete[] m_apcPlanes; } template UInt TRenImage::getNumberOfPlanes() const { return m_uiNumberOfPlanes; } template UInt TRenImage::getNumberOfQuaterPlanes() const { return m_uiNumberOfQuaterPlanes; } template UInt TRenImage::getNumberOfFullPlanes() const { return m_uiNumberOfFullPlanes; } template class TRenImage; template class TRenImage; template class TRenImage; template class TRenImage; template Void TRenImage::assign (TRenImage* );