[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 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, 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 <assert.h> |
---|
| 43 | #include "CommonDef.h" |
---|
| 44 | #include "TComPicYuv.h" |
---|
[1029] | 45 | #include "TComRectangle.h" |
---|
[313] | 46 | |
---|
| 47 | //! \ingroup TLibCommon |
---|
| 48 | //! \{ |
---|
| 49 | |
---|
| 50 | // ==================================================================================================================== |
---|
| 51 | // Class definition |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | |
---|
| 54 | /// general YUV buffer class |
---|
| 55 | class TComYuv |
---|
| 56 | { |
---|
| 57 | private: |
---|
[1029] | 58 | |
---|
[313] | 59 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 60 | // YUV buffer |
---|
| 61 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 62 | |
---|
| 63 | Pel* m_apiBuf[MAX_NUM_COMPONENT]; |
---|
| 64 | |
---|
[313] | 65 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 66 | // Parameter for general YUV buffer usage |
---|
| 67 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 68 | |
---|
[313] | 69 | UInt m_iWidth; |
---|
| 70 | UInt m_iHeight; |
---|
[1029] | 71 | ChromaFormat m_chromaFormatIDC; ////< Chroma Format |
---|
[313] | 72 | |
---|
[1029] | 73 | // dims 16x16 |
---|
| 74 | // blkSize=4x4 |
---|
| 75 | |
---|
| 76 | // these functions assume a square CU, of size width*width, split into square TUs each of size blkSize*blkSize. |
---|
| 77 | // iTransUnitIdx is the raster-scanned index of the sub-block (TU) in question. |
---|
| 78 | // eg for a 16x16 CU, with 4x4 TUs: |
---|
| 79 | // 0 1 2 3 |
---|
| 80 | // 4 5 6 7 |
---|
| 81 | // 8 9 10 11 |
---|
| 82 | // 12 13 14 15 |
---|
| 83 | |
---|
| 84 | // So, for iTransUnitIdx=14, 14*4 & 15 =8=X offset. |
---|
| 85 | // 14*4 / 16 =3=Y block offset |
---|
| 86 | // 3*4*16 = Y offset within buffer |
---|
| 87 | |
---|
| 88 | |
---|
[313] | 89 | public: |
---|
[1029] | 90 | |
---|
| 91 | TComYuv (); |
---|
| 92 | virtual ~TComYuv (); |
---|
| 93 | |
---|
[313] | 94 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 95 | // Memory management |
---|
| 96 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 97 | |
---|
| 98 | Void create ( const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC ); ///< Create YUV buffer |
---|
| 99 | Void destroy (); ///< Destroy YUV buffer |
---|
| 100 | Void clear (); ///< clear YUV buffer |
---|
| 101 | |
---|
[313] | 102 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 103 | // Copy, load, store YUV buffer |
---|
| 104 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 105 | |
---|
[313] | 106 | // Copy YUV buffer to picture buffer |
---|
[1029] | 107 | Void copyToPicYuv ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth = 0, const UInt uiPartIdx = 0 ) const ; |
---|
| 108 | Void copyToPicComponent ( const ComponentID id, TComPicYuv* pcPicYuvDst, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth = 0, const UInt uiPartIdx = 0 ) const ; |
---|
| 109 | |
---|
[313] | 110 | // Copy YUV buffer from picture buffer |
---|
[1029] | 111 | Void copyFromPicYuv ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx ); |
---|
| 112 | Void copyFromPicComponent ( const ComponentID id, const TComPicYuv* pcPicYuvSrc, const UInt iCtuRsAddr, const UInt uiAbsZorderIdx ); |
---|
| 113 | |
---|
[313] | 114 | // Copy Small YUV buffer to the part of other Big YUV buffer |
---|
[1029] | 115 | Void copyToPartYuv ( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const ; |
---|
| 116 | Void copyToPartComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const ; |
---|
| 117 | |
---|
[313] | 118 | // Copy the part of Big YUV buffer to other Small YUV buffer |
---|
[1029] | 119 | Void copyPartToYuv ( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const; |
---|
| 120 | Void copyPartToComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const; |
---|
| 121 | |
---|
[313] | 122 | // Copy YUV partition buffer to other YUV partition buffer |
---|
[1029] | 123 | Void copyPartToPartYuv ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight ) const; |
---|
| 124 | Void copyPartToPartComponent ( const ComponentID id, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt uiWidthComponent, const UInt uiHeightComponent ) const; |
---|
[313] | 125 | |
---|
[1029] | 126 | // Copy YUV partition buffer to other YUV partition buffer for non-square blocks |
---|
| 127 | Void copyPartToPartComponentMxN ( const ComponentID id, TComYuv* pcYuvDst, const TComRectangle &rect ) const; |
---|
| 128 | |
---|
[313] | 129 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 130 | // Algebraic operation for YUV buffer |
---|
| 131 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 132 | |
---|
[313] | 133 | // Clip(pcYuvSrc0 + pcYuvSrc1) -> m_apiBuf |
---|
[1029] | 134 | Void addClip ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ); |
---|
| 135 | |
---|
[313] | 136 | // pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf |
---|
[1029] | 137 | Void subtract ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize ); |
---|
| 138 | |
---|
[313] | 139 | // (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition |
---|
[1029] | 140 | Void addAvg ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight ); |
---|
[313] | 141 | |
---|
[1029] | 142 | Void removeHighFreq ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight ); |
---|
| 143 | |
---|
[313] | 144 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 145 | // Access function for YUV buffer |
---|
| 146 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[1029] | 147 | |
---|
[313] | 148 | // Access starting position of YUV buffer |
---|
[1029] | 149 | Pel* getAddr (const ComponentID id) { return m_apiBuf[id]; } |
---|
| 150 | const Pel* getAddr (const ComponentID id) const { return m_apiBuf[id]; } |
---|
| 151 | |
---|
[313] | 152 | // Access starting position of YUV partition unit buffer |
---|
[1029] | 153 | Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) |
---|
| 154 | { |
---|
| 155 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id); |
---|
| 156 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id); |
---|
| 157 | assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 158 | return m_apiBuf[id] + blkX + blkY * getStride(id); |
---|
| 159 | } |
---|
| 160 | const Pel* getAddr (const ComponentID id, const UInt uiPartUnitIdx) const |
---|
| 161 | { |
---|
| 162 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleX(id); |
---|
| 163 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ] >> getComponentScaleY(id); |
---|
| 164 | assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 165 | return m_apiBuf[id] + blkX + blkY * getStride(id); |
---|
| 166 | } |
---|
| 167 | |
---|
[313] | 168 | // Access starting position of YUV transform unit buffer |
---|
[1029] | 169 | Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) |
---|
| 170 | { |
---|
| 171 | UInt width=getWidth(id); |
---|
| 172 | Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 ); |
---|
| 173 | Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 ); |
---|
| 174 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) blkY<<=1; |
---|
| 175 | // assert((blkX<getWidth(id) && blkY<getHeight(id))); |
---|
| 176 | return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent; |
---|
| 177 | } |
---|
[313] | 178 | |
---|
[1029] | 179 | const Pel* getAddr (const ComponentID id, const UInt iTransUnitIdx, const UInt iBlkSizeForComponent) const |
---|
| 180 | { |
---|
| 181 | UInt width=getWidth(id); |
---|
| 182 | Int blkX = ( iTransUnitIdx * iBlkSizeForComponent ) & ( width - 1 ); |
---|
| 183 | Int blkY = ( iTransUnitIdx * iBlkSizeForComponent ) &~ ( width - 1 ); |
---|
| 184 | if (m_chromaFormatIDC==CHROMA_422 && id!=COMPONENT_Y) blkY<<=1; |
---|
| 185 | // UInt w=getWidth(id), h=getHeight(id); |
---|
| 186 | // assert((blkX<w && blkY<h)); |
---|
| 187 | return m_apiBuf[id] + blkX + blkY * iBlkSizeForComponent; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | // Access starting position of YUV transform unit buffer by pix offset for square & non-square blocks |
---|
| 191 | Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; } |
---|
| 192 | const Pel* getAddrPix (const ComponentID id, const UInt iPixX, const UInt iPixY ) const { return m_apiBuf[id] + iPixY * getStride(id) + iPixX; } |
---|
| 193 | |
---|
[313] | 194 | // Get stride value of YUV buffer |
---|
[1029] | 195 | UInt getStride (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); } |
---|
| 196 | UInt getHeight (const ComponentID id) const { return m_iHeight >> getComponentScaleY(id); } |
---|
| 197 | UInt getWidth (const ComponentID id) const { return m_iWidth >> getComponentScaleX(id); } |
---|
| 198 | ChromaFormat getChromaFormat () const { return m_chromaFormatIDC; } |
---|
| 199 | UInt getNumberValidComponents () const { return ::getNumberValidComponents(m_chromaFormatIDC); } |
---|
| 200 | UInt getComponentScaleX (const ComponentID id) const { return ::getComponentScaleX(id, m_chromaFormatIDC); } |
---|
| 201 | UInt getComponentScaleY (const ComponentID id) const { return ::getComponentScaleY(id, m_chromaFormatIDC); } |
---|
| 202 | |
---|
[313] | 203 | };// END CLASS DEFINITION TComYuv |
---|
| 204 | |
---|
| 205 | //! \} |
---|
| 206 | |
---|
| 207 | #endif // __TCOMYUV__ |
---|