[517] | 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 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 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 | #ifndef _DOWN_CONVERT_ |
---|
| 35 | #define _DOWN_CONVERT_ |
---|
| 36 | |
---|
| 37 | #define ZERO_PHASE 1 |
---|
| 38 | |
---|
| 39 | #define ESS_NONE 0 |
---|
| 40 | |
---|
| 41 | #include <cassert> |
---|
| 42 | #include "../../Lib/TLibCommon/TypeDef.h" |
---|
| 43 | |
---|
| 44 | #ifndef gMax |
---|
| 45 | #define gMax(x,y) ((x)>(y)?(x):(y)) |
---|
| 46 | #define gMin(x,y) ((x)<(y)?(x):(y)) |
---|
| 47 | |
---|
| 48 | #define ROFRS( exp, retVal ) \ |
---|
| 49 | { \ |
---|
| 50 | if( !( exp ) ) \ |
---|
| 51 | { \ |
---|
| 52 | return retVal; \ |
---|
| 53 | } \ |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | #define ROTRS( exp, retVal ) \ |
---|
| 57 | { \ |
---|
| 58 | if( ( exp ) ) \ |
---|
| 59 | { \ |
---|
| 60 | return retVal; \ |
---|
| 61 | } \ |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | #endif |
---|
| 65 | |
---|
| 66 | class ResizeParameters |
---|
| 67 | { |
---|
| 68 | public: |
---|
| 69 | ResizeParameters() |
---|
| 70 | : m_iExtendedSpatialScalability ( ESS_NONE ) |
---|
| 71 | , m_iLevelIdc ( 0 ) |
---|
| 72 | , m_bFrameMbsOnlyFlag ( true ) |
---|
| 73 | , m_bFieldPicFlag ( false ) |
---|
| 74 | , m_bBotFieldFlag ( false ) |
---|
| 75 | , m_bIsMbAffFrame ( false ) |
---|
| 76 | , m_iFrameWidth ( 0 ) |
---|
| 77 | , m_iFrameHeight ( 0 ) |
---|
| 78 | , m_iWidthInSamples ( 0 ) |
---|
| 79 | , m_iHeightInSamples ( 0 ) |
---|
| 80 | , m_iChromaPhaseX ( 0 ) |
---|
| 81 | , m_iChromaPhaseY ( 0 ) |
---|
| 82 | , m_iScaledRefFrmWidth ( 0 ) |
---|
| 83 | , m_iScaledRefFrmHeight ( 0 ) |
---|
| 84 | , m_iLeftFrmOffset ( 0 ) |
---|
| 85 | , m_iTopFrmOffset ( 0 ) |
---|
| 86 | , m_iRefLayerChromaPhaseX ( 0 ) |
---|
| 87 | , m_iRefLayerChromaPhaseY ( 0 ) |
---|
| 88 | , m_bRefLayerFrameMbsOnlyFlag ( true ) |
---|
| 89 | , m_bRefLayerFieldPicFlag ( false ) |
---|
| 90 | , m_bRefLayerBotFieldFlag ( false ) |
---|
| 91 | , m_bRefLayerIsMbAffFrame ( false ) |
---|
| 92 | , m_iRefLayerFrmWidth ( 0 ) |
---|
| 93 | , m_iRefLayerFrmHeight ( 0 ) |
---|
| 94 | , m_iRefLayerWidthInSamples ( 0 ) |
---|
| 95 | , m_iRefLayerHeightInSamples ( 0 ) |
---|
| 96 | { |
---|
| 97 | }; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | public: |
---|
| 102 | //===== parameters of current layer ===== |
---|
| 103 | Int m_iExtendedSpatialScalability; |
---|
| 104 | Int m_iLevelIdc; |
---|
| 105 | Bool m_bFrameMbsOnlyFlag; |
---|
| 106 | Bool m_bFieldPicFlag; |
---|
| 107 | Bool m_bBotFieldFlag; |
---|
| 108 | Bool m_bIsMbAffFrame; |
---|
| 109 | Int m_iFrameWidth; |
---|
| 110 | Int m_iFrameHeight; |
---|
| 111 | Int m_iWidthInSamples; |
---|
| 112 | Int m_iHeightInSamples; |
---|
| 113 | Int m_iChromaPhaseX; |
---|
| 114 | Int m_iChromaPhaseY; |
---|
| 115 | Int m_iScaledRefFrmWidth; // also in PictureParameters |
---|
| 116 | Int m_iScaledRefFrmHeight; // also in PictureParameters |
---|
| 117 | Int m_iLeftFrmOffset; // also in PictureParameters |
---|
| 118 | Int m_iTopFrmOffset; // also in PictureParameters |
---|
| 119 | Int m_iRefLayerChromaPhaseX; // also in PictureParameters |
---|
| 120 | Int m_iRefLayerChromaPhaseY; // also in PictureParameters |
---|
| 121 | |
---|
| 122 | //===== parameters for base layer ===== |
---|
| 123 | Bool m_bRefLayerFrameMbsOnlyFlag; |
---|
| 124 | Bool m_bRefLayerFieldPicFlag; |
---|
| 125 | Bool m_bRefLayerBotFieldFlag; |
---|
| 126 | Bool m_bRefLayerIsMbAffFrame; |
---|
| 127 | Int m_iRefLayerFrmWidth; |
---|
| 128 | Int m_iRefLayerFrmHeight; |
---|
| 129 | Int m_iRefLayerWidthInSamples; |
---|
| 130 | Int m_iRefLayerHeightInSamples; |
---|
| 131 | }; |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | class DownConvert |
---|
| 135 | { |
---|
| 136 | public: |
---|
| 137 | //======================== |
---|
| 138 | // general main functions |
---|
| 139 | //======================== |
---|
| 140 | DownConvert (); |
---|
| 141 | ~DownConvert (); |
---|
| 142 | bool init ( int iMaxWidth, int iMaxHeight, int iMaxMargin = 0 ); |
---|
| 143 | void destroy (); |
---|
| 144 | |
---|
| 145 | //===================================== |
---|
| 146 | // main functions for DownConvert Tool |
---|
| 147 | //===================================== |
---|
| 148 | void downsamplingSVC ( unsigned char* pucBufferY, int iStrideY, |
---|
| 149 | unsigned char* pucBufferU, int iStrideU, |
---|
| 150 | unsigned char* pucBufferV, int iStrideV, |
---|
| 151 | ResizeParameters* pcParameters, bool bBotCoincided = false ); |
---|
| 152 | |
---|
| 153 | //========================== |
---|
| 154 | // general helper functions |
---|
| 155 | //========================== |
---|
| 156 | //--- delete buffers --- |
---|
| 157 | void xDestroy (); |
---|
| 158 | //--- general clipping --- |
---|
| 159 | int xClip ( int iValue, |
---|
| 160 | int imin, |
---|
| 161 | int imax ); |
---|
| 162 | //======================================= |
---|
| 163 | // helper functions for DownConvert Tool |
---|
| 164 | //======================================= |
---|
| 165 | //--- place to and get from image buffer --- |
---|
| 166 | void xCopyToImageBuffer ( unsigned char* pucSrc, |
---|
| 167 | int iWidth, |
---|
| 168 | int iHeight, |
---|
| 169 | int iStride ); |
---|
| 170 | void xCopyFromImageBuffer ( unsigned char* pucDes, |
---|
| 171 | int iWidth, |
---|
| 172 | int iHeight, |
---|
| 173 | int iStride ); |
---|
| 174 | //--- SVC non-normative downsampling --- |
---|
| 175 | void xCompDownsampling ( ResizeParameters* pcParameters, |
---|
| 176 | bool bChroma, |
---|
| 177 | bool bBotFlag, |
---|
| 178 | bool bVerticalDownsampling ); |
---|
| 179 | void xVertDownsampling ( int iBaseW, |
---|
| 180 | int iBaseH, |
---|
| 181 | bool bBotFlag ); |
---|
| 182 | void xBasicDownsampling ( int iBaseW, int iBaseH, int iCurrW, int iCurrH, |
---|
| 183 | int iLOffset, int iTOffset, int iROffset, int iBOffset, |
---|
| 184 | int iShiftX, int iShiftY, int iScaleX, int iScaleY, |
---|
| 185 | int iAddX, int iAddY, int iDeltaX, int iDeltaY ); |
---|
| 186 | private: |
---|
| 187 | //===== member variables ===== |
---|
| 188 | int m_iImageStride; |
---|
| 189 | int* m_paiImageBuffer; |
---|
| 190 | int* m_paiTmp1dBuffer; |
---|
| 191 | }; |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | __inline Int CeilLog2( Int i ) |
---|
| 195 | { |
---|
| 196 | Int s = 0; i--; |
---|
| 197 | while( i > 0 ) |
---|
| 198 | { |
---|
| 199 | s++; |
---|
| 200 | i >>= 1; |
---|
| 201 | } |
---|
| 202 | return s; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | #endif // _DOWN_CONVERT_ |
---|
| 207 | |
---|
| 208 | |
---|