[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TComYuv.h |
---|
| 35 | \brief general YUV buffer class (header) |
---|
| 36 | \todo this should be merged with TComPicYuv \n |
---|
| 37 | check usage of removeHighFreq function |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #ifndef __TCOMYUV__ |
---|
| 41 | #define __TCOMYUV__ |
---|
| 42 | #include "CommonDef.h" |
---|
| 43 | #include "TComPicYuv.h" |
---|
[1029] | 44 | #include "TComRectangle.h" |
---|
[313] | 45 | |
---|
| 46 | //! \ingroup TLibCommon |
---|
| 47 | //! \{ |
---|
| 48 | |
---|
| 49 | // ==================================================================================================================== |
---|
| 50 | // Class definition |
---|
| 51 | // ==================================================================================================================== |
---|
| 52 | |
---|
| 53 | /// general YUV buffer class |
---|
| 54 | class TComYuv |
---|
| 55 | { |
---|
| 56 | private: |
---|
[1029] | 57 | |
---|
[313] | 58 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 59 | // YUV buffer |
---|
| 60 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 61 | |
---|
| 62 | Pel* m_apiBuf[MAX_NUM_COMPONENT]; |
---|
| 63 | |
---|
[313] | 64 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 65 | // Parameter for general YUV buffer usage |
---|
| 66 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 67 | |
---|
[313] | 68 | UInt m_iWidth; |
---|
| 69 | UInt m_iHeight; |
---|
[1029] | 70 | ChromaFormat m_chromaFormatIDC; ////< Chroma Format |
---|
[313] | 71 | |
---|
[1029] | 72 | // dims 16x16 |
---|
| 73 | // blkSize=4x4 |
---|
| 74 | |
---|
| 75 | // these functions assume a square CU, of size width*width, split into square TUs each of size blkSize*blkSize. |
---|
| 76 | // iTransUnitIdx is the raster-scanned index of the sub-block (TU) in question. |
---|
| 77 | // eg for a 16x16 CU, with 4x4 TUs: |
---|
| 78 | // 0 1 2 3 |
---|
| 79 | // 4 5 6 7 |
---|
| 80 | // 8 9 10 11 |
---|
| 81 | // 12 13 14 15 |
---|
| 82 | |
---|
| 83 | // So, for iTransUnitIdx=14, 14*4 & 15 =8=X offset. |
---|
| 84 | // 14*4 / 16 =3=Y block offset |
---|
| 85 | // 3*4*16 = Y offset within buffer |
---|
| 86 | |
---|
| 87 | |
---|
[313] | 88 | public: |
---|
[1029] | 89 | |
---|
| 90 | TComYuv (); |
---|
| 91 | virtual ~TComYuv (); |
---|
| 92 | |
---|
[313] | 93 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 94 | // Memory management |
---|
| 95 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 96 | |
---|
| 97 | Void create ( const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC ); ///< Create YUV buffer |
---|
| 98 | Void destroy (); ///< Destroy YUV buffer |
---|
| 99 | Void clear (); ///< clear YUV buffer |
---|
| 100 | |
---|
[313] | 101 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 102 | // Copy, load, store YUV buffer |
---|
| 103 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 104 | |
---|
[313] | 105 | // Copy YUV buffer to picture buffer |
---|
[1029] | 106 | Void copyToPicYuv ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth = 0, const UInt uiPartIdx = 0 ) const ; |
---|
| 107 | Void copyToPicComponent ( const ComponentID id, TComPicYuv* pcPicYuvDst, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth = 0, const UInt uiPartIdx = 0 ) const ; |
---|
| 108 | |
---|
[313] | 109 | // Copy YUV buffer from picture buffer |
---|
[1029] | 110 | Void copyFromPicYuv ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx ); |
---|
| 111 | Void copyFromPicComponent ( const ComponentID id, const TComPicYuv* pcPicYuvSrc, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx ); |
---|
| 112 | |
---|
[313] | 113 | // Copy Small YUV buffer to the part of other Big YUV buffer |
---|
[1029] | 114 | Void copyToPartYuv ( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const ; |
---|
| 115 | Void copyToPartComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const ; |
---|
| 116 | |
---|
[313] | 117 | // Copy the part of Big YUV buffer to other Small YUV buffer |
---|
[1029] | 118 | Void copyPartToYuv ( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const; |
---|
| 119 | Void copyPartToComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const; |
---|
| 120 | |
---|
[313] | 121 | // Copy YUV partition buffer to other YUV partition buffer |
---|
[1029] | 122 | Void copyPartToPartYuv ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight ) const; |
---|
| 123 | Void copyPartToPartComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt uiWidthComponent, const UInt uiHeightComponent ) const; |
---|
[313] | 124 | |
---|
[1029] | 125 | // Copy YUV partition buffer to other YUV partition buffer for non-square blocks |
---|
| 126 | Void copyPartToPartComponentMxN ( const ComponentID id, TComYuv* pcYuvDst, const TComRectangle &rect ) const; |
---|
| 127 | |
---|
[313] | 128 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 129 | // Algebraic operation for YUV buffer |
---|
| 130 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 131 | |
---|
[313] | 132 | // Clip(pcYuvSrc0 + pcYuvSrc1) -> m_apiBuf |
---|
[1287] | 133 | Void addClip ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize, const BitDepths &clipBitDepths ); |
---|
[1029] | 134 | |
---|
[313] | 135 | // pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf |
---|
[1029] | 136 | Void subtract ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ); |
---|
| 137 | |
---|
[313] | 138 | // (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition |
---|
[1287] | 139 | Void addAvg ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight, const BitDepths &clipBitDepths ); |
---|
[313] | 140 | |
---|
[1313] | 141 | Void removeHighFreq ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight |
---|
[1324] | 142 | , const Int bitDepths[MAX_NUM_CHANNEL_TYPE], const Bool bClipToBitDepths |
---|
[1313] | 143 | ); |
---|
[1029] | 144 | |
---|
[313] | 145 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 146 | // Access function for YUV buffer |
---|
| 147 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 148 | |
---|
[313] | 149 | // Access starting position of YUV buffer |
---|
[1029] | 150 | Pel* getAddr (const ComponentID id) { return m_apiBuf[id]; } |
---|
| 151 | const Pel* getAddr (const ComponentID id) const { return m_apiBuf[id]; } |
---|
| 152 | |
---|
[313] | 153 | // Access starting position of YUV partition unit buffer |
---|
[1029] | 154 | Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) |
---|
| 155 | { |
---|
| 156 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id); |
---|
| 157 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id); |
---|
| 158 | assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 159 | return m_apiBuf[id] + blkX + blkY * getStride(id); |
---|
| 160 | } |
---|
| 161 | const Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) const |
---|
| 162 | { |
---|
| 163 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id); |
---|
| 164 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id); |
---|
| 165 | assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 166 | return m_apiBuf[id] + blkX + blkY * getStride(id); |
---|
| 167 | } |
---|
| 168 | |
---|
[313] | 169 | // Access starting position of YUV transform unit buffer |
---|
[1029] | 170 | Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) |
---|
| 171 | { |
---|
| 172 | UInt width=getWidth(id); |
---|
| 173 | Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 ); |
---|
| 174 | Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 ); |
---|
[1246] | 175 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) |
---|
| 176 | { |
---|
| 177 | blkY<<=1; |
---|
| 178 | } |
---|
[1029] | 179 | return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent; |
---|
| 180 | } |
---|
[313] | 181 | |
---|
[1029] | 182 | const Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const |
---|
| 183 | { |
---|
| 184 | UInt width=getWidth(id); |
---|
| 185 | Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 ); |
---|
| 186 | Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 ); |
---|
[1246] | 187 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) |
---|
| 188 | { |
---|
| 189 | blkY<<=1; |
---|
| 190 | } |
---|
[1029] | 191 | return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent; |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | // Access starting position of YUV transform unit buffer by pix offset for square & non-square blocks |
---|
| 195 | Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; } |
---|
| 196 | const Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) const { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; } |
---|
| 197 | |
---|
[313] | 198 | // Get stride value of YUV buffer |
---|
[1029] | 199 | UInt getStride (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); } |
---|
| 200 | UInt getHeight (const ComponentID id) const { return m_iHeight >> getComponentScaleY(id); } |
---|
| 201 | UInt getWidth (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); } |
---|
| 202 | ChromaFormat getChromaFormat () const { return m_chromaFormatIDC; } |
---|
| 203 | UInt getNumberValidComponents () const { return ::getNumberValidComponents(m_chromaFormatIDC); } |
---|
| 204 | UInt getComponentScaleX (const ComponentID id) const { return ::getComponentScaleX(id, m_chromaFormatIDC); } |
---|
| 205 | UInt getComponentScaleY (const ComponentID id) const { return ::getComponentScaleY(id, m_chromaFormatIDC); } |
---|
| 206 | |
---|
[313] | 207 | };// END CLASS DEFINITION TComYuv |
---|
| 208 | |
---|
| 209 | //! \} |
---|
| 210 | |
---|
| 211 | #endif // __TCOMYUV__ |
---|