[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 |
---|
| 4 | * granted under this license. |
---|
| 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" |
---|
| 45 | |
---|
| 46 | //! \ingroup TLibCommon |
---|
| 47 | //! \{ |
---|
| 48 | |
---|
| 49 | // ==================================================================================================================== |
---|
| 50 | // Class definition |
---|
| 51 | // ==================================================================================================================== |
---|
| 52 | |
---|
| 53 | /// general YUV buffer class |
---|
| 54 | class TComYuv |
---|
| 55 | { |
---|
| 56 | private: |
---|
| 57 | |
---|
| 58 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 59 | // YUV buffer |
---|
| 60 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 61 | |
---|
| 62 | Pel* m_apiBufY; |
---|
| 63 | Pel* m_apiBufU; |
---|
| 64 | Pel* m_apiBufV; |
---|
| 65 | |
---|
| 66 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 67 | // Parameter for general YUV buffer usage |
---|
| 68 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 69 | |
---|
| 70 | UInt m_iWidth; |
---|
| 71 | UInt m_iHeight; |
---|
| 72 | UInt m_iCWidth; |
---|
| 73 | UInt m_iCHeight; |
---|
| 74 | |
---|
| 75 | static Int getAddrOffset( UInt uiPartUnitIdx, UInt width ) |
---|
| 76 | { |
---|
| 77 | Int blkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartUnitIdx ] ]; |
---|
| 78 | Int blkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartUnitIdx ] ]; |
---|
| 79 | |
---|
| 80 | return blkX + blkY * width; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | static Int getAddrOffset( UInt iTransUnitIdx, UInt iBlkSize, UInt width ) |
---|
| 84 | { |
---|
| 85 | Int blkX = ( iTransUnitIdx * iBlkSize ) & ( width - 1 ); |
---|
| 86 | Int blkY = ( iTransUnitIdx * iBlkSize ) &~ ( width - 1 ); |
---|
| 87 | |
---|
| 88 | return blkX + blkY * iBlkSize; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | public: |
---|
| 92 | |
---|
| 93 | TComYuv(); |
---|
| 94 | virtual ~TComYuv(); |
---|
| 95 | |
---|
| 96 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 97 | // Memory management |
---|
| 98 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 99 | |
---|
| 100 | Void create ( UInt iWidth, UInt iHeight ); ///< Create YUV buffer |
---|
| 101 | Void destroy (); ///< Destroy YUV buffer |
---|
| 102 | Void clear (); ///< clear YUV buffer |
---|
| 103 | |
---|
| 104 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 105 | // Copy, load, store YUV buffer |
---|
| 106 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 107 | |
---|
| 108 | // Copy YUV buffer to picture buffer |
---|
| 109 | Void copyToPicYuv ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 ); |
---|
| 110 | Void copyToPicLuma ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 ); |
---|
| 111 | Void copyToPicChroma ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 ); |
---|
| 112 | |
---|
| 113 | // Copy YUV buffer from picture buffer |
---|
| 114 | Void copyFromPicYuv ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ); |
---|
| 115 | Void copyFromPicLuma ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ); |
---|
| 116 | Void copyFromPicChroma ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx ); |
---|
| 117 | |
---|
| 118 | // Copy Small YUV buffer to the part of other Big YUV buffer |
---|
| 119 | Void copyToPartYuv ( TComYuv* pcYuvDst, UInt uiDstPartIdx ); |
---|
| 120 | Void copyToPartLuma ( TComYuv* pcYuvDst, UInt uiDstPartIdx ); |
---|
| 121 | Void copyToPartChroma ( TComYuv* pcYuvDst, UInt uiDstPartIdx ); |
---|
| 122 | |
---|
| 123 | // Copy the part of Big YUV buffer to other Small YUV buffer |
---|
| 124 | Void copyPartToYuv ( TComYuv* pcYuvDst, UInt uiSrcPartIdx ); |
---|
| 125 | Void copyPartToLuma ( TComYuv* pcYuvDst, UInt uiSrcPartIdx ); |
---|
| 126 | Void copyPartToChroma ( TComYuv* pcYuvDst, UInt uiSrcPartIdx ); |
---|
| 127 | |
---|
| 128 | // Copy YUV partition buffer to other YUV partition buffer |
---|
| 129 | Void copyPartToPartYuv ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight ); |
---|
| 130 | Void copyPartToPartLuma ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight ); |
---|
| 131 | Void copyPartToPartChroma ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt uiWidth, UInt uiHeight ); |
---|
| 132 | |
---|
| 133 | Void copyPartToPartChroma ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight, UInt chromaId); |
---|
| 134 | |
---|
| 135 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 136 | // Algebraic operation for YUV buffer |
---|
| 137 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 138 | |
---|
| 139 | // Clip(pcYuvSrc0 + pcYuvSrc1) -> m_apiBuf |
---|
| 140 | Void addClip ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
| 141 | Void addClipLuma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
| 142 | Void addClipChroma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
| 143 | |
---|
| 144 | // pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf |
---|
| 145 | Void subtract ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
| 146 | Void subtractLuma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
| 147 | Void subtractChroma ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); |
---|
| 148 | |
---|
| 149 | // (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition |
---|
| 150 | Void addAvg ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight ); |
---|
| 151 | |
---|
| 152 | // Remove High frequency |
---|
| 153 | Void removeHighFreq ( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ); |
---|
| 154 | |
---|
| 155 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 156 | // Access function for YUV buffer |
---|
| 157 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 158 | |
---|
| 159 | // Access starting position of YUV buffer |
---|
| 160 | Pel* getLumaAddr () { return m_apiBufY; } |
---|
| 161 | Pel* getCbAddr () { return m_apiBufU; } |
---|
| 162 | Pel* getCrAddr () { return m_apiBufV; } |
---|
| 163 | |
---|
| 164 | // Access starting position of YUV partition unit buffer |
---|
| 165 | Pel* getLumaAddr( UInt iPartUnitIdx ) { return m_apiBufY + getAddrOffset( iPartUnitIdx, m_iWidth ) ; } |
---|
| 166 | Pel* getCbAddr ( UInt iPartUnitIdx ) { return m_apiBufU + ( getAddrOffset( iPartUnitIdx, m_iCWidth ) >> 1 ); } |
---|
| 167 | Pel* getCrAddr ( UInt iPartUnitIdx ) { return m_apiBufV + ( getAddrOffset( iPartUnitIdx, m_iCWidth ) >> 1 ); } |
---|
| 168 | |
---|
| 169 | // Access starting position of YUV transform unit buffer |
---|
| 170 | Pel* getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufY + getAddrOffset( iTransUnitIdx, iBlkSize, m_iWidth ); } |
---|
| 171 | Pel* getCbAddr ( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufU + getAddrOffset( iTransUnitIdx, iBlkSize, m_iCWidth ); } |
---|
| 172 | Pel* getCrAddr ( UInt iTransUnitIdx, UInt iBlkSize ) { return m_apiBufV + getAddrOffset( iTransUnitIdx, iBlkSize, m_iCWidth ); } |
---|
| 173 | |
---|
| 174 | // Get stride value of YUV buffer |
---|
| 175 | UInt getStride () { return m_iWidth; } |
---|
| 176 | UInt getCStride () { return m_iCWidth; } |
---|
| 177 | UInt getHeight () { return m_iHeight; } |
---|
| 178 | |
---|
| 179 | UInt getWidth () { return m_iWidth; } |
---|
| 180 | UInt getCHeight () { return m_iCHeight; } |
---|
| 181 | UInt getCWidth () { return m_iCWidth; } |
---|
| 182 | };// END CLASS DEFINITION TComYuv |
---|
| 183 | |
---|
| 184 | //! \} |
---|
| 185 | |
---|
| 186 | #endif // __TCOMYUV__ |
---|