Changeset 1029 in SHVCSoftware for branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp
- Timestamp:
- 26 Feb 2015, 00:21:54 (10 years ago)
- Location:
- branches/SHM-dev
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev
- Property svn:mergeinfo changed
-
branches/SHM-dev/source
- Property svn:mergeinfo changed
-
branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp
r869 r1029 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 6 * Copyright (c) 2010-2014, ITU/ISO/IEC … … 47 47 48 48 #include "TComPicYuv.h" 49 #include "TLibVideoIO/TVideoIOYuv.h" 49 50 50 51 //! \ingroup TLibCommon … … 53 54 TComPicYuv::TComPicYuv() 54 55 { 55 m_apiPicBufY = NULL; // Buffer (including margin) 56 m_apiPicBufU = NULL; 57 m_apiPicBufV = NULL; 58 59 m_piPicOrgY = NULL; // m_apiPicBufY + m_iMarginLuma*getStride() + m_iMarginLuma 60 m_piPicOrgU = NULL; 61 m_piPicOrgV = NULL; 62 56 for(UInt i=0; i<MAX_NUM_COMPONENT; i++) 57 { 58 m_apiPicBuf[i] = NULL; // Buffer (including margin) 59 m_piPicOrg[i] = NULL; // m_apiPicBufY + m_iMarginLuma*getStride() + m_iMarginLuma 60 } 61 62 for(UInt i=0; i<MAX_NUM_CHANNEL_TYPE; i++) 63 { 64 m_ctuOffsetInBuffer[i]=0; 65 m_subCuOffsetInBuffer[i]=0; 66 } 67 63 68 m_bIsBorderExtended = false; 64 69 } 70 71 72 65 73 66 74 TComPicYuv::~TComPicYuv() … … 70 78 #if SVC_EXTENSION 71 79 #if R0156_CONF_WINDOW_IN_REP_FORMAT 72 #if AUXILIARY_PICTURES 73 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, Window* conformanceWindow ) 74 #else 75 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, Window* conformanceWindow ) 76 #endif 77 #else // R0156_CONF_WINDOW_IN_REP_FORMAT 78 #if AUXILIARY_PICTURES 79 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps ) 80 #else 81 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps ) 82 #endif 83 #endif 84 #else 85 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth ) 86 #endif 87 { 88 m_iPicWidth = iPicWidth; 89 m_iPicHeight = iPicHeight; 80 Void TComPicYuv::create( const Int iPicWidth, const Int iPicHeight, const ChromaFormat chromaFormatIDC, const UInt uiMaxCUWidth, const UInt uiMaxCUHeight, const UInt uiMaxCUDepth, Window* conformanceWindow ) 81 #else 82 Void TComPicYuv::create( const Int iPicWidth, const Int iPicHeight, const ChromaFormat chromaFormatIDC, const UInt uiMaxCUWidth, const UInt uiMaxCUHeight, const UInt uiMaxCUDepth, TComSPS* pcSps ) 83 #endif 84 #else 85 Void TComPicYuv::create( const Int iPicWidth, const Int iPicHeight, const ChromaFormat chromaFormatIDC, 86 const UInt uiMaxCUWidth, const UInt uiMaxCUHeight, const UInt uiMaxCUDepth ) 87 #endif 88 { 89 m_iPicWidth = iPicWidth; 90 m_iPicHeight = iPicHeight; 91 m_chromaFormatIDC = chromaFormatIDC; 90 92 91 93 #if SVC_EXTENSION … … 102 104 #endif 103 105 #endif 104 105 // --> After config finished!106 m_iCuWidth = uiMaxCUWidth;107 m_iCuHeight = uiMaxCUHeight;108 #if AUXILIARY_PICTURES109 m_chromaFormatIDC = chromaFormatIDC;110 #endif111 112 Int numCuInWidth = m_iPicWidth / m_iCuWidth + (m_iPicWidth % m_iCuWidth != 0);113 Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0);114 106 115 107 #if LAYER_CTB 116 m_iLumaMarginX = uiMaxCUWidth + 16; // for 16-byte alignment 117 m_iLumaMarginY = uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding 118 #else 119 m_iLumaMarginX = g_uiMaxCUWidth + 16; // for 16-byte alignment 120 m_iLumaMarginY = g_uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding 121 #endif 122 123 m_iChromaMarginX = m_iLumaMarginX>>1; 124 m_iChromaMarginY = m_iLumaMarginY>>1; 125 126 m_apiPicBufY = (Pel*)xMalloc( Pel, ( m_iPicWidth + (m_iLumaMarginX <<1)) * ( m_iPicHeight + (m_iLumaMarginY <<1))); 127 m_apiPicBufU = (Pel*)xMalloc( Pel, ((m_iPicWidth >> 1) + (m_iChromaMarginX<<1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY<<1))); 128 m_apiPicBufV = (Pel*)xMalloc( Pel, ((m_iPicWidth >> 1) + (m_iChromaMarginX<<1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY<<1))); 129 130 m_piPicOrgY = m_apiPicBufY + m_iLumaMarginY * getStride() + m_iLumaMarginX; 131 m_piPicOrgU = m_apiPicBufU + m_iChromaMarginY * getCStride() + m_iChromaMarginX; 132 m_piPicOrgV = m_apiPicBufV + m_iChromaMarginY * getCStride() + m_iChromaMarginX; 108 m_iMarginX = uiMaxCUWidth + 16; // for 16-byte alignment 109 m_iMarginY = uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding 110 #else 111 m_iMarginX = g_uiMaxCUWidth + 16; // for 16-byte alignment 112 m_iMarginY = g_uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding 113 #endif 133 114 134 115 m_bIsBorderExtended = false; 116 117 // assign the picture arrays and set up the ptr to the top left of the original picture 118 { 119 Int chan=0; 120 for(; chan<getNumberValidComponents(); chan++) 121 { 122 const ComponentID ch=ComponentID(chan); 123 m_apiPicBuf[chan] = (Pel*)xMalloc( Pel, getStride(ch) * getTotalHeight(ch)); 124 m_piPicOrg[chan] = m_apiPicBuf[chan] + (m_iMarginY >> getComponentScaleY(ch)) * getStride(ch) + (m_iMarginX >> getComponentScaleX(ch)); 125 } 126 for(;chan<MAX_NUM_COMPONENT; chan++) 127 { 128 m_apiPicBuf[chan] = NULL; 129 m_piPicOrg[chan] = NULL; 130 } 131 } 132 133 134 const Int numCuInWidth = m_iPicWidth / uiMaxCUWidth + (m_iPicWidth % uiMaxCUWidth != 0); 135 const Int numCuInHeight = m_iPicHeight / uiMaxCUHeight + (m_iPicHeight % uiMaxCUHeight != 0); 136 for(Int chan=0; chan<2; chan++) 137 { 138 const ComponentID ch=ComponentID(chan); 139 const Int ctuHeight=uiMaxCUHeight>>getComponentScaleY(ch); 140 const Int ctuWidth=uiMaxCUWidth>>getComponentScaleX(ch); 141 const Int stride = getStride(ch); 142 143 m_ctuOffsetInBuffer[chan] = new Int[numCuInWidth * numCuInHeight]; 144 145 for (Int cuRow = 0; cuRow < numCuInHeight; cuRow++) 146 for (Int cuCol = 0; cuCol < numCuInWidth; cuCol++) 147 m_ctuOffsetInBuffer[chan][cuRow * numCuInWidth + cuCol] = stride * cuRow * ctuHeight + cuCol * ctuWidth; 148 149 m_subCuOffsetInBuffer[chan] = new Int[(size_t)1 << (2 * uiMaxCUDepth)]; 150 151 const Int numSubBlockPartitions=(1<<uiMaxCUDepth); 152 const Int minSubBlockHeight =(ctuHeight >> uiMaxCUDepth); 153 const Int minSubBlockWidth =(ctuWidth >> uiMaxCUDepth); 154 155 for (Int buRow = 0; buRow < numSubBlockPartitions; buRow++) 156 for (Int buCol = 0; buCol < numSubBlockPartitions; buCol++) 157 m_subCuOffsetInBuffer[chan][(buRow << uiMaxCUDepth) + buCol] = stride * buRow * minSubBlockHeight + buCol * minSubBlockWidth; 158 } 159 return; 160 } 161 162 163 164 Void TComPicYuv::destroy() 165 { 166 for(Int chan=0; chan<MAX_NUM_COMPONENT; chan++) 167 { 168 m_piPicOrg[chan] = NULL; 169 170 if( m_apiPicBuf[chan] ){ xFree( m_apiPicBuf[chan] ); m_apiPicBuf[chan] = NULL; } 171 } 172 173 for(UInt chan=0; chan<MAX_NUM_CHANNEL_TYPE; chan++) 174 { 175 if (m_ctuOffsetInBuffer[chan]) delete[] m_ctuOffsetInBuffer[chan]; m_ctuOffsetInBuffer[chan] = NULL; 176 if (m_subCuOffsetInBuffer[chan]) delete[] m_subCuOffsetInBuffer[chan]; m_subCuOffsetInBuffer[chan] = NULL; 177 } 178 } 179 180 181 182 Void TComPicYuv::copyToPic (TComPicYuv* pcPicYuvDst) const 183 { 184 assert( m_iPicWidth == pcPicYuvDst->getWidth(COMPONENT_Y) ); 185 assert( m_iPicHeight == pcPicYuvDst->getHeight(COMPONENT_Y) ); 186 assert( m_chromaFormatIDC == pcPicYuvDst->getChromaFormat() ); 187 188 for(Int chan=0; chan<getNumberValidComponents(); chan++) 189 { 190 const ComponentID ch=ComponentID(chan); 191 ::memcpy ( pcPicYuvDst->getBuf(ch), m_apiPicBuf[ch], sizeof (Pel) * getStride(ch) * getTotalHeight(ch)); 192 } 193 return; 194 } 195 196 197 Void TComPicYuv::extendPicBorder () 198 { 199 if ( m_bIsBorderExtended ) return; 200 201 for(Int chan=0; chan<getNumberValidComponents(); chan++) 202 { 203 const ComponentID ch=ComponentID(chan); 204 Pel *piTxt=getAddr(ch); // piTxt = point to (0,0) of image within bigger picture. 205 const Int iStride=getStride(ch); 206 const Int iWidth=getWidth(ch); 207 const Int iHeight=getHeight(ch); 208 const Int iMarginX=getMarginX(ch); 209 const Int iMarginY=getMarginY(ch); 210 211 Pel* pi = piTxt; 212 // do left and right margins 213 for (Int y = 0; y < iHeight; y++) 214 { 215 for (Int x = 0; x < iMarginX; x++ ) 216 { 217 pi[ -iMarginX + x ] = pi[0]; 218 pi[ iWidth + x ] = pi[iWidth-1]; 219 } 220 pi += iStride; 221 } 222 223 // pi is now the (0,height) (bottom left of image within bigger picture 224 pi -= (iStride + iMarginX); 225 // pi is now the (-marginX, height-1) 226 for (Int y = 0; y < iMarginY; y++ ) 227 { 228 ::memcpy( pi + (y+1)*iStride, pi, sizeof(Pel)*(iWidth + (iMarginX<<1)) ); 229 } 230 231 // pi is still (-marginX, height-1) 232 pi -= ((iHeight-1) * iStride); 233 // pi is now (-marginX, 0) 234 for (Int y = 0; y < iMarginY; y++ ) 235 { 236 ::memcpy( pi - (y+1)*iStride, pi, sizeof(Pel)*(iWidth + (iMarginX<<1)) ); 237 } 238 } 239 240 m_bIsBorderExtended = true; 241 } 242 243 244 245 // NOTE: This function is never called, but may be useful for developers. 246 Void TComPicYuv::dump (const Char* pFileName, Bool bAdd) const 247 { 248 FILE* pFile; 249 if (!bAdd) 250 { 251 pFile = fopen (pFileName, "wb"); 252 } 253 else 254 { 255 pFile = fopen (pFileName, "ab"); 256 } 257 258 259 for(Int chan = 0; chan < getNumberValidComponents(); chan++) 260 { 261 const ComponentID ch = ComponentID(chan); 262 const Int shift = g_bitDepth[toChannelType(ch)] - 8; 263 const Int offset = (shift>0)?(1<<(shift-1)):0; 264 const Pel *pi = getAddr(ch); 265 const Int stride = getStride(ch); 266 const Int height = getHeight(ch); 267 const Int width = getWidth(ch); 268 269 for (Int y = 0; y < height; y++ ) 270 { 271 for (Int x = 0; x < width; x++ ) 272 { 273 UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift); 274 fwrite( &uc, sizeof(UChar), 1, pFile ); 275 } 276 pi += stride; 277 } 278 } 279 280 fclose(pFile); 281 } 282 283 Void TComPicYuv::dump( Char* pFileName, Bool bAdd, Int bitDepth ) 284 { 285 FILE* pFile; 286 if (!bAdd) 287 { 288 pFile = fopen (pFileName, "wb"); 289 } 290 else 291 { 292 pFile = fopen (pFileName, "ab"); 293 } 294 295 if( bitDepth == 8 ) 296 { 297 dump( pFileName, bAdd ); 298 return; 299 } 300 301 for(Int chan = 0; chan < getNumberValidComponents(); chan++) 302 { 303 const ComponentID ch = ComponentID(chan); 304 const Int shift = g_bitDepth[toChannelType(ch)] - 8; 305 const Int offset = (shift>0)?(1<<(shift-1)):0; 306 const Pel *pi = getAddr(ch); 307 const Int stride = getStride(ch); 308 const Int height = getHeight(ch); 309 const Int width = getWidth(ch); 310 311 for (Int y = 0; y < height; y++ ) 312 { 313 for (Int x = 0; x < width; x++ ) 314 { 315 Pel pix = Clip3<Pel>(0, (1 << bitDepth)-1, (pi[x]+offset)>>shift); 316 317 UChar uc = pix & 0xff; 318 fwrite( &uc, sizeof(UChar), 1, pFile ); 319 uc = (pix >> 8) & 0xff; 320 fwrite( &uc, sizeof(UChar), 1, pFile ); 321 } 322 pi += stride; 323 } 324 } 135 325 136 m_cuOffsetY = new Int[numCuInWidth * numCuInHeight]; 137 m_cuOffsetC = new Int[numCuInWidth * numCuInHeight]; 138 for (Int cuRow = 0; cuRow < numCuInHeight; cuRow++) 139 { 140 for (Int cuCol = 0; cuCol < numCuInWidth; cuCol++) 141 { 142 m_cuOffsetY[cuRow * numCuInWidth + cuCol] = getStride() * cuRow * m_iCuHeight + cuCol * m_iCuWidth; 143 m_cuOffsetC[cuRow * numCuInWidth + cuCol] = getCStride() * cuRow * (m_iCuHeight / 2) + cuCol * (m_iCuWidth / 2); 144 } 145 } 146 147 m_buOffsetY = new Int[(size_t)1 << (2 * uiMaxCUDepth)]; 148 m_buOffsetC = new Int[(size_t)1 << (2 * uiMaxCUDepth)]; 149 for (Int buRow = 0; buRow < (1 << uiMaxCUDepth); buRow++) 150 { 151 for (Int buCol = 0; buCol < (1 << uiMaxCUDepth); buCol++) 152 { 153 m_buOffsetY[(buRow << uiMaxCUDepth) + buCol] = getStride() * buRow * (uiMaxCUHeight >> uiMaxCUDepth) + buCol * (uiMaxCUWidth >> uiMaxCUDepth); 154 m_buOffsetC[(buRow << uiMaxCUDepth) + buCol] = getCStride() * buRow * (uiMaxCUHeight / 2 >> uiMaxCUDepth) + buCol * (uiMaxCUWidth / 2 >> uiMaxCUDepth); 155 } 156 } 157 return; 158 } 159 160 Void TComPicYuv::destroy() 161 { 162 m_piPicOrgY = NULL; 163 m_piPicOrgU = NULL; 164 m_piPicOrgV = NULL; 165 166 if( m_apiPicBufY ){ xFree( m_apiPicBufY ); m_apiPicBufY = NULL; } 167 if( m_apiPicBufU ){ xFree( m_apiPicBufU ); m_apiPicBufU = NULL; } 168 if( m_apiPicBufV ){ xFree( m_apiPicBufV ); m_apiPicBufV = NULL; } 169 170 delete[] m_cuOffsetY; 171 delete[] m_cuOffsetC; 172 delete[] m_buOffsetY; 173 delete[] m_buOffsetC; 174 } 175 176 Void TComPicYuv::createLuma( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth ) 177 { 178 m_iPicWidth = iPicWidth; 179 m_iPicHeight = iPicHeight; 180 181 // --> After config finished! 182 m_iCuWidth = uiMaxCUWidth; 183 m_iCuHeight = uiMaxCUHeight; 184 185 Int numCuInWidth = m_iPicWidth / m_iCuWidth + (m_iPicWidth % m_iCuWidth != 0); 186 Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0); 187 188 #if LAYER_CTB 189 m_iLumaMarginX = uiMaxCUWidth + 16; // for 16-byte alignment 190 m_iLumaMarginY = uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding 191 #else 192 m_iLumaMarginX = g_uiMaxCUWidth + 16; // for 16-byte alignment 193 m_iLumaMarginY = g_uiMaxCUHeight + 16; // margin for 8-tap filter and infinite padding 194 #endif 195 196 m_apiPicBufY = (Pel*)xMalloc( Pel, ( m_iPicWidth + (m_iLumaMarginX <<1)) * ( m_iPicHeight + (m_iLumaMarginY <<1))); 197 m_piPicOrgY = m_apiPicBufY + m_iLumaMarginY * getStride() + m_iLumaMarginX; 198 199 m_cuOffsetY = new Int[numCuInWidth * numCuInHeight]; 200 m_cuOffsetC = NULL; 201 for (Int cuRow = 0; cuRow < numCuInHeight; cuRow++) 202 { 203 for (Int cuCol = 0; cuCol < numCuInWidth; cuCol++) 204 { 205 m_cuOffsetY[cuRow * numCuInWidth + cuCol] = getStride() * cuRow * m_iCuHeight + cuCol * m_iCuWidth; 206 } 207 } 208 209 m_buOffsetY = new Int[(size_t)1 << (2 * uiMaxCUDepth)]; 210 m_buOffsetC = NULL; 211 for (Int buRow = 0; buRow < (1 << uiMaxCUDepth); buRow++) 212 { 213 for (Int buCol = 0; buCol < (1 << uiMaxCUDepth); buCol++) 214 { 215 m_buOffsetY[(buRow << uiMaxCUDepth) + buCol] = getStride() * buRow * (uiMaxCUHeight >> uiMaxCUDepth) + buCol * (uiMaxCUWidth >> uiMaxCUDepth); 216 } 217 } 218 return; 219 } 220 221 Void TComPicYuv::destroyLuma() 222 { 223 m_piPicOrgY = NULL; 224 225 if( m_apiPicBufY ){ xFree( m_apiPicBufY ); m_apiPicBufY = NULL; } 226 227 delete[] m_cuOffsetY; 228 delete[] m_buOffsetY; 229 } 230 231 Void TComPicYuv::copyToPic (TComPicYuv* pcPicYuvDst) 232 { 233 assert( m_iPicWidth == pcPicYuvDst->getWidth() ); 234 assert( m_iPicHeight == pcPicYuvDst->getHeight() ); 235 236 ::memcpy ( pcPicYuvDst->getBufY(), m_apiPicBufY, sizeof (Pel) * ( m_iPicWidth + (m_iLumaMarginX << 1)) * ( m_iPicHeight + (m_iLumaMarginY << 1)) ); 237 ::memcpy ( pcPicYuvDst->getBufU(), m_apiPicBufU, sizeof (Pel) * ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1)) ); 238 ::memcpy ( pcPicYuvDst->getBufV(), m_apiPicBufV, sizeof (Pel) * ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1)) ); 239 return; 240 } 241 242 Void TComPicYuv::copyToPicLuma (TComPicYuv* pcPicYuvDst) 243 { 244 assert( m_iPicWidth == pcPicYuvDst->getWidth() ); 245 assert( m_iPicHeight == pcPicYuvDst->getHeight() ); 246 247 ::memcpy ( pcPicYuvDst->getBufY(), m_apiPicBufY, sizeof (Pel) * ( m_iPicWidth + (m_iLumaMarginX << 1)) * ( m_iPicHeight + (m_iLumaMarginY << 1)) ); 248 return; 249 } 250 251 Void TComPicYuv::copyToPicCb (TComPicYuv* pcPicYuvDst) 252 { 253 assert( m_iPicWidth == pcPicYuvDst->getWidth() ); 254 assert( m_iPicHeight == pcPicYuvDst->getHeight() ); 255 256 ::memcpy ( pcPicYuvDst->getBufU(), m_apiPicBufU, sizeof (Pel) * ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1)) ); 257 return; 258 } 259 260 Void TComPicYuv::copyToPicCr (TComPicYuv* pcPicYuvDst) 261 { 262 assert( m_iPicWidth == pcPicYuvDst->getWidth() ); 263 assert( m_iPicHeight == pcPicYuvDst->getHeight() ); 264 265 ::memcpy ( pcPicYuvDst->getBufV(), m_apiPicBufV, sizeof (Pel) * ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1)) ); 266 return; 326 fclose(pFile); 267 327 } 268 328 … … 270 330 Void TComPicYuv::convertToMonochrome() 271 331 { 272 Int numPix = ((m_iPicWidth >> 1) + (m_i ChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1));273 Pel grayVal = (1 << (g_bitDepth C- 1));332 Int numPix = ((m_iPicWidth >> 1) + (m_iMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iMarginY << 1)); 333 Pel grayVal = (1 << (g_bitDepth[CHANNEL_TYPE_CHROMA] - 1)); 274 334 275 335 for (UInt i = 0; i < numPix; i++) 276 336 { 277 m_apiPicBufU[i] = grayVal; 278 m_apiPicBufV[i] = grayVal; 279 } 280 } 281 #endif 282 283 Void TComPicYuv::extendPicBorder () 284 { 285 if ( m_bIsBorderExtended ) return; 286 287 xExtendPicCompBorder( getLumaAddr(), getStride(), getWidth(), getHeight(), m_iLumaMarginX, m_iLumaMarginY ); 288 xExtendPicCompBorder( getCbAddr() , getCStride(), getWidth() >> 1, getHeight() >> 1, m_iChromaMarginX, m_iChromaMarginY ); 289 xExtendPicCompBorder( getCrAddr() , getCStride(), getWidth() >> 1, getHeight() >> 1, m_iChromaMarginX, m_iChromaMarginY ); 290 291 m_bIsBorderExtended = true; 292 } 293 294 Void TComPicYuv::xExtendPicCompBorder (Pel* piTxt, Int iStride, Int iWidth, Int iHeight, Int iMarginX, Int iMarginY) 295 { 296 Int x, y; 297 Pel* pi; 298 299 pi = piTxt; 300 for ( y = 0; y < iHeight; y++) 301 { 302 for ( x = 0; x < iMarginX; x++ ) 303 { 304 pi[ -iMarginX + x ] = pi[0]; 305 pi[ iWidth + x ] = pi[iWidth-1]; 306 } 307 pi += iStride; 308 } 309 310 pi -= (iStride + iMarginX); 311 for ( y = 0; y < iMarginY; y++ ) 312 { 313 ::memcpy( pi + (y+1)*iStride, pi, sizeof(Pel)*(iWidth + (iMarginX<<1)) ); 314 } 315 316 pi -= ((iHeight-1) * iStride); 317 for ( y = 0; y < iMarginY; y++ ) 318 { 319 ::memcpy( pi - (y+1)*iStride, pi, sizeof(Pel)*(iWidth + (iMarginX<<1)) ); 320 } 321 } 322 323 324 Void TComPicYuv::dump (Char* pFileName, Bool bAdd) 325 { 326 FILE* pFile; 327 if (!bAdd) 328 { 329 pFile = fopen (pFileName, "wb"); 330 } 331 else 332 { 333 pFile = fopen (pFileName, "ab"); 334 } 335 336 Int shift = g_bitDepthY-8; 337 Int offset = (shift>0)?(1<<(shift-1)):0; 338 339 Int x, y; 340 UChar uc; 341 342 Pel* piY = getLumaAddr(); 343 Pel* piCb = getCbAddr(); 344 Pel* piCr = getCrAddr(); 345 346 for ( y = 0; y < m_iPicHeight; y++ ) 347 { 348 for ( x = 0; x < m_iPicWidth; x++ ) 349 { 350 uc = (UChar)Clip3<Pel>(0, 255, (piY[x]+offset)>>shift); 351 352 fwrite( &uc, sizeof(UChar), 1, pFile ); 353 } 354 piY += getStride(); 355 } 356 357 shift = g_bitDepthC-8; 358 offset = (shift>0)?(1<<(shift-1)):0; 359 360 for ( y = 0; y < m_iPicHeight >> 1; y++ ) 361 { 362 for ( x = 0; x < m_iPicWidth >> 1; x++ ) 363 { 364 uc = (UChar)Clip3<Pel>(0, 255, (piCb[x]+offset)>>shift); 365 fwrite( &uc, sizeof(UChar), 1, pFile ); 366 } 367 piCb += getCStride(); 368 } 369 370 for ( y = 0; y < m_iPicHeight >> 1; y++ ) 371 { 372 for ( x = 0; x < m_iPicWidth >> 1; x++ ) 373 { 374 uc = (UChar)Clip3<Pel>(0, 255, (piCr[x]+offset)>>shift); 375 fwrite( &uc, sizeof(UChar), 1, pFile ); 376 } 377 piCr += getCStride(); 378 } 379 380 fclose(pFile); 381 } 382 383 Void TComPicYuv::dump( Char* pFileName, Bool bAdd, Int bitDepth ) 384 { 385 FILE* pFile; 386 if (!bAdd) 387 { 388 pFile = fopen (pFileName, "wb"); 389 } 390 else 391 { 392 pFile = fopen (pFileName, "ab"); 393 } 394 395 if( bitDepth == 8 ) 396 { 397 dump( pFileName, bAdd ); 398 return; 399 } 400 401 Int x, y; 402 UChar uc; 403 404 Pel* piY = getLumaAddr(); 405 Pel* piCb = getCbAddr(); 406 Pel* piCr = getCrAddr(); 407 408 for ( y = 0; y < m_iPicHeight; y++ ) 409 { 410 for ( x = 0; x < m_iPicWidth; x++ ) 411 { 412 uc = piY[x] & 0xff; 413 fwrite( &uc, sizeof(UChar), 1, pFile ); 414 uc = (piY[x] >> 8) & 0xff; 415 fwrite( &uc, sizeof(UChar), 1, pFile ); 416 } 417 piY += getStride(); 418 } 419 420 for ( y = 0; y < m_iPicHeight >> 1; y++ ) 421 { 422 for ( x = 0; x < m_iPicWidth >> 1; x++ ) 423 { 424 uc = piCb[x] & 0xff; 425 fwrite( &uc, sizeof(UChar), 1, pFile ); 426 uc = (piCb[x] >> 8) & 0xff; 427 fwrite( &uc, sizeof(UChar), 1, pFile ); 428 } 429 piCb += getCStride(); 430 } 431 432 for ( y = 0; y < m_iPicHeight >> 1; y++ ) 433 { 434 for ( x = 0; x < m_iPicWidth >> 1; x++ ) 435 { 436 uc = piCr[x] & 0xff; 437 fwrite( &uc, sizeof(UChar), 1, pFile ); 438 uc = (piCr[x] >> 8) & 0xff; 439 fwrite( &uc, sizeof(UChar), 1, pFile ); 440 } 441 piCr += getCStride(); 442 } 443 444 fclose(pFile); 445 } 337 m_apiPicBuf[COMPONENT_Cb][i] = grayVal; 338 m_apiPicBuf[COMPONENT_Cr][i] = grayVal; 339 } 340 } 341 #endif 446 342 447 343 //! \}
Note: See TracChangeset for help on using the changeset viewer.