[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 |
---|
[1029] | 133 | Void addClip ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ); |
---|
| 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 |
---|
[1029] | 139 | Void addAvg ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight ); |
---|
[313] | 140 | |
---|
[1029] | 141 | Void removeHighFreq ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight ); |
---|
| 142 | |
---|
[313] | 143 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 144 | // Access function for YUV buffer |
---|
| 145 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 146 | |
---|
[313] | 147 | // Access starting position of YUV buffer |
---|
[1029] | 148 | Pel* getAddr (const ComponentID id) { return m_apiBuf[id]; } |
---|
| 149 | const Pel* getAddr (const ComponentID id) const { return m_apiBuf[id]; } |
---|
| 150 | |
---|
[313] | 151 | // Access starting position of YUV partition unit buffer |
---|
[1029] | 152 | Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) |
---|
| 153 | { |
---|
| 154 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id); |
---|
| 155 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id); |
---|
| 156 | assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 157 | return m_apiBuf[id] + blkX + blkY * getStride(id); |
---|
| 158 | } |
---|
| 159 | const Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) const |
---|
| 160 | { |
---|
| 161 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id); |
---|
| 162 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id); |
---|
| 163 | assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 164 | return m_apiBuf[id] + blkX + blkY * getStride(id); |
---|
| 165 | } |
---|
| 166 | |
---|
[313] | 167 | // Access starting position of YUV transform unit buffer |
---|
[1029] | 168 | Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) |
---|
| 169 | { |
---|
| 170 | UInt width=getWidth(id); |
---|
| 171 | Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 ); |
---|
| 172 | Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 ); |
---|
[1246] | 173 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) |
---|
| 174 | { |
---|
| 175 | blkY<<=1; |
---|
| 176 | } |
---|
[1029] | 177 | return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent; |
---|
| 178 | } |
---|
[313] | 179 | |
---|
[1029] | 180 | const Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const |
---|
| 181 | { |
---|
| 182 | UInt width=getWidth(id); |
---|
| 183 | Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 ); |
---|
| 184 | Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 ); |
---|
[1246] | 185 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) |
---|
| 186 | { |
---|
| 187 | blkY<<=1; |
---|
| 188 | } |
---|
[1029] | 189 | return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | // Access starting position of YUV transform unit buffer by pix offset for square & non-square blocks |
---|
| 193 | Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; } |
---|
| 194 | const Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) const { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; } |
---|
| 195 | |
---|
[313] | 196 | // Get stride value of YUV buffer |
---|
[1029] | 197 | UInt getStride (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); } |
---|
| 198 | UInt getHeight (const ComponentID id) const { return m_iHeight >> getComponentScaleY(id); } |
---|
| 199 | UInt getWidth (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); } |
---|
| 200 | ChromaFormat getChromaFormat () const { return m_chromaFormatIDC; } |
---|
| 201 | UInt getNumberValidComponents () const { return ::getNumberValidComponents(m_chromaFormatIDC); } |
---|
| 202 | UInt getComponentScaleX (const ComponentID id) const { return ::getComponentScaleX(id, m_chromaFormatIDC); } |
---|
| 203 | UInt getComponentScaleY (const ComponentID id) const { return ::getComponentScaleY(id, m_chromaFormatIDC); } |
---|
| 204 | |
---|
[313] | 205 | };// END CLASS DEFINITION TComYuv |
---|
| 206 | |
---|
| 207 | //! \} |
---|
| 208 | |
---|
| 209 | #endif // __TCOMYUV__ |
---|