Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp
r1179 r1313 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. 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC4 * granted under this license. 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 45 45 #include <assert.h> 46 46 47 #include "TComChromaFormat.h" 48 47 49 48 50 //! \ingroup TLibCommon … … 53 55 // ==================================================================================================================== 54 56 55 const Short TComInterpolationFilter::m_lumaFilter[4][NTAPS_LUMA] =57 const TFilterCoeff TComInterpolationFilter::m_lumaFilter[LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS][NTAPS_LUMA] = 56 58 { 57 59 { 0, 0, 0, 64, 0, 0, 0, 0 }, … … 61 63 }; 62 64 63 const Short TComInterpolationFilter::m_chromaFilter[8][NTAPS_CHROMA] =65 const TFilterCoeff TComInterpolationFilter::m_chromaFilter[CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS][NTAPS_CHROMA] = 64 66 { 65 67 { 0, 64, 0, 0 }, … … 73 75 }; 74 76 75 #if H_3D_ARP77 #if NH_3D_ARP 76 78 const Short TComInterpolationFilter::m_lumaFilterARP[4][NTAPS_LUMA_ARP] = 77 79 { … … 111 113 * \param isLast Flag indicating whether it is the last filtering operation 112 114 */ 113 Void TComInterpolationFilter::filterCopy(Int bitDepth, const Pel *src, Int srcStride, Short*dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast)115 Void TComInterpolationFilter::filterCopy(Int bitDepth, const Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast) 114 116 { 115 117 Int row, col; 116 118 117 119 if ( isFirst == isLast ) 118 120 { … … 123 125 dst[col] = src[col]; 124 126 } 125 127 126 128 src += srcStride; 127 129 dst += dstStride; 128 } 130 } 129 131 } 130 132 else if ( isFirst ) 131 133 { 132 Int shift = IF_INTERNAL_PREC - bitDepth;133 134 const Int shift = std::max<Int>(2, (IF_INTERNAL_PREC - bitDepth)); 135 134 136 for (row = 0; row < height; row++) 135 137 { 136 138 for (col = 0; col < width; col++) 137 139 { 138 Short val = src[col] << shift;139 dst[col] = val - ( Short)IF_INTERNAL_OFFS;140 } 141 140 Pel val = leftShift_round(src[col], shift); 141 dst[col] = val - (Pel)IF_INTERNAL_OFFS; 142 } 143 142 144 src += srcStride; 143 145 dst += dstStride; 144 } 145 } 146 else 147 { 148 Int shift = IF_INTERNAL_PREC - bitDepth; 149 Short offset = IF_INTERNAL_OFFS; 150 offset += shift?(1 << (shift - 1)):0; 151 Short maxVal = (1 << bitDepth) - 1; 152 Short minVal = 0; 146 } 147 } 148 else 149 { 150 const Int shift = std::max<Int>(2, (IF_INTERNAL_PREC - bitDepth)); 151 152 Pel maxVal = (1 << bitDepth) - 1; 153 Pel minVal = 0; 153 154 for (row = 0; row < height; row++) 154 155 { 155 156 for (col = 0; col < width; col++) 156 157 { 157 Short val = src[ col ]; 158 val = ( val + offset ) >> shift; 159 if (val < minVal) val = minVal; 160 if (val > maxVal) val = maxVal; 158 Pel val = src[ col ]; 159 val = rightShift_round((val + IF_INTERNAL_OFFS), shift); 160 if (val < minVal) 161 { 162 val = minVal; 163 } 164 if (val > maxVal) 165 { 166 val = maxVal; 167 } 161 168 dst[col] = val; 162 169 } 163 170 164 171 src += srcStride; 165 172 dst += dstStride; 166 } 173 } 167 174 } 168 175 } … … 185 192 */ 186 193 template<Int N, Bool isVertical, Bool isFirst, Bool isLast> 187 Void TComInterpolationFilter::filter(Int bitDepth, Short const *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Shortconst *coeff)194 Void TComInterpolationFilter::filter(Int bitDepth, Pel const *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, TFilterCoeff const *coeff) 188 195 { 189 196 Int row, col; 190 191 Shortc[8];197 198 Pel c[8]; 192 199 c[0] = coeff[0]; 193 200 c[1] = coeff[1]; … … 207 214 c[7] = coeff[7]; 208 215 } 209 216 210 217 Int cStride = ( isVertical ) ? srcStride : 1; 211 218 src -= ( N/2 - 1 ) * cStride; 212 219 213 220 Int offset; 214 Short maxVal; 215 Int headRoom = IF_INTERNAL_PREC - bitDepth; 216 Int shift = IF_FILTER_PREC; 221 Pel maxVal; 222 Int headRoom = std::max<Int>(2, (IF_INTERNAL_PREC - bitDepth)); 223 Int shift = IF_FILTER_PREC; 224 // with the current settings (IF_INTERNAL_PREC = 14 and IF_FILTER_PREC = 6), though headroom can be 225 // negative for bit depths greater than 14, shift will remain non-negative for bit depths of 8->20 226 assert(shift >= 0); 227 217 228 if ( isLast ) 218 229 { … … 228 239 maxVal = 0; 229 240 } 230 241 231 242 for (row = 0; row < height; row++) 232 243 { … … 234 245 { 235 246 Int sum; 236 247 237 248 sum = src[ col + 0 * cStride] * c[0]; 238 249 sum += src[ col + 1 * cStride] * c[1]; … … 250 261 { 251 262 sum += src[ col + 6 * cStride] * c[6]; 252 sum += src[ col + 7 * cStride] * c[7]; 253 } 254 255 Shortval = ( sum + offset ) >> shift;263 sum += src[ col + 7 * cStride] * c[7]; 264 } 265 266 Pel val = ( sum + offset ) >> shift; 256 267 if ( isLast ) 257 268 { 258 269 val = ( val < 0 ) ? 0 : val; 259 val = ( val > maxVal ) ? maxVal : val; 270 val = ( val > maxVal ) ? maxVal : val; 260 271 } 261 272 dst[col] = val; 262 273 } 263 274 264 275 src += srcStride; 265 276 dst += dstStride; 266 } 277 } 267 278 } 268 279 … … 282 293 */ 283 294 template<Int N> 284 Void TComInterpolationFilter::filterHor(Int bitDepth, Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Bool isLast, Shortconst *coeff)295 Void TComInterpolationFilter::filterHor(Int bitDepth, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isLast, TFilterCoeff const *coeff) 285 296 { 286 297 if ( isLast ) … … 298 309 * 299 310 * \tparam N Number of taps 300 * \param bitD peth Sample bit depth311 * \param bitDepth Bit depth 301 312 * \param src Pointer to source samples 302 313 * \param srcStride Stride of source samples … … 310 321 */ 311 322 template<Int N> 312 Void TComInterpolationFilter::filterVer(Int bitDepth, Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast, Shortconst *coeff)323 Void TComInterpolationFilter::filterVer(Int bitDepth, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast, TFilterCoeff const *coeff) 313 324 { 314 325 if ( isFirst && isLast ) … … 327 338 { 328 339 filter<N, true, false, false>(bitDepth, src, srcStride, dst, dstStride, width, height, coeff); 329 } 340 } 330 341 } 331 342 … … 335 346 336 347 /** 337 * \brief Filter a block of luma samples (horizontal) 338 * 348 * \brief Filter a block of Luma/Chroma samples (horizontal) 349 * 350 * \param compID Chroma component ID 339 351 * \param src Pointer to source samples 340 352 * \param srcStride Stride of source samples … … 345 357 * \param frac Fractional sample offset 346 358 * \param isLast Flag indicating whether it is the last filtering operation 347 */ 348 Void TComInterpolationFilter::filterHorLuma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast 349 #if H_3D_ARP 359 * \param fmt Chroma format 360 * \param bitDepth Bit depth 361 */ 362 Void TComInterpolationFilter::filterHor(const ComponentID compID, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast, const ChromaFormat fmt, const Int bitDepth 363 #if NH_3D_ARP 350 364 , Bool filterType 351 365 #endif 352 ) 353 { 354 assert(frac >= 0 && frac < 4); 355 366 ) 367 { 356 368 if ( frac == 0 ) 357 369 { 358 filterCopy(g_bitDepthY, src, srcStride, dst, dstStride, width, height, true, isLast ); 359 } 360 else 361 { 362 #if H_3D_ARP 370 filterCopy(bitDepth, src, srcStride, dst, dstStride, width, height, true, isLast ); 371 } 372 else if (isLuma(compID)) 373 { 374 assert(frac >= 0 && frac < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 375 #if NH_3D_ARP 363 376 if(filterType) 364 377 { 365 filterHor<NTAPS_LUMA_ARP>( g_bitDepthY, src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilterARP[frac]);378 filterHor<NTAPS_LUMA_ARP>(bitDepth, src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilterARP[frac]); 366 379 } 367 380 else 368 381 { 369 382 #endif 370 filterHor<NTAPS_LUMA>(g_bitDepthY, src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilter[frac]); 371 #if H_3D_ARP 383 filterHor<NTAPS_LUMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilter[frac]); 384 #if NH_3D_ARP 385 } 386 #endif 387 388 } 389 else 390 { 391 const UInt csx = getComponentScaleX(compID, fmt); 392 assert(frac >=0 && csx<2 && (frac<<(1-csx)) < CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 393 #if NH_3D_ARP 394 if(filterType) 395 { 396 filterHor<NTAPS_CHROMA_ARP>(bitDepth, src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilterARP[frac]); 397 } 398 else 399 { 400 #endif 401 filterHor<NTAPS_CHROMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilter[frac<<(1-csx)]); 402 #if NH_3D_ARP 372 403 } 373 404 #endif … … 375 406 } 376 407 377 /** 378 * \brief Filter a block of luma samples (vertical) 379 * 408 409 /** 410 * \brief Filter a block of Luma/Chroma samples (vertical) 411 * 412 * \param compID Colour component ID 380 413 * \param src Pointer to source samples 381 414 * \param srcStride Stride of source samples … … 387 420 * \param isFirst Flag indicating whether it is the first filtering operation 388 421 * \param isLast Flag indicating whether it is the last filtering operation 389 */ 390 Void TComInterpolationFilter::filterVerLuma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast 391 #if H_3D_ARP 422 * \param fmt Chroma format 423 * \param bitDepth Bit depth 424 */ 425 Void TComInterpolationFilter::filterVer(const ComponentID compID, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast, const ChromaFormat fmt, const Int bitDepth 426 #if NH_3D_ARP 392 427 , Bool filterType 393 428 #endif 394 ) 395 { 396 assert(frac >= 0 && frac < 4); 397 429 ) 430 { 398 431 if ( frac == 0 ) 399 432 { 400 filterCopy(g_bitDepthY, src, srcStride, dst, dstStride, width, height, isFirst, isLast ); 401 } 402 else 403 { 404 #if H_3D_ARP 433 filterCopy(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast ); 434 } 435 else if (isLuma(compID)) 436 { 437 assert(frac >= 0 && frac < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 438 #if NH_3D_ARP 405 439 if(filterType) 406 440 { 407 filterVer<NTAPS_LUMA_ARP>( g_bitDepthY, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilterARP[frac]);441 filterVer<NTAPS_LUMA_ARP>(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilterARP[frac]); 408 442 } 409 443 else 410 444 { 411 445 #endif 412 filterVer<NTAPS_LUMA>(g_bitDepthY, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilter[frac]); 413 #if H_3D_ARP 414 } 415 #endif 416 } 417 } 418 419 /** 420 * \brief Filter a block of chroma samples (horizontal) 421 * 422 * \param src Pointer to source samples 423 * \param srcStride Stride of source samples 424 * \param dst Pointer to destination samples 425 * \param dstStride Stride of destination samples 426 * \param width Width of block 427 * \param height Height of block 428 * \param frac Fractional sample offset 429 * \param isLast Flag indicating whether it is the last filtering operation 430 */ 431 Void TComInterpolationFilter::filterHorChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isLast 432 #if H_3D_ARP 433 , Bool filterType 434 #endif 435 ) 436 { 437 assert(frac >= 0 && frac < 8); 438 439 if ( frac == 0 ) 440 { 441 filterCopy(g_bitDepthC, src, srcStride, dst, dstStride, width, height, true, isLast ); 442 } 443 else 444 { 445 #if H_3D_ARP 446 filterVer<NTAPS_LUMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilter[frac]); 447 #if NH_3D_ARP 448 } 449 #endif 450 451 } 452 else 453 { 454 const UInt csy = getComponentScaleY(compID, fmt); 455 assert(frac >=0 && csy<2 && (frac<<(1-csy)) < CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 456 #if NH_3D_ARP 446 457 if(filterType) 447 458 { 448 filter Hor<NTAPS_CHROMA_ARP>(g_bitDepthC, src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilterARP[frac]);459 filterVer<NTAPS_CHROMA_ARP>(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilterARP[frac]); 449 460 } 450 461 else 451 462 { 452 463 #endif 453 filterHor<NTAPS_CHROMA>(g_bitDepthC, src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilter[frac]); 454 #if H_3D_ARP 455 } 456 #endif 457 } 458 } 459 460 /** 461 * \brief Filter a block of chroma samples (vertical) 462 * 463 * \param src Pointer to source samples 464 * \param srcStride Stride of source samples 465 * \param dst Pointer to destination samples 466 * \param dstStride Stride of destination samples 467 * \param width Width of block 468 * \param height Height of block 469 * \param frac Fractional sample offset 470 * \param isFirst Flag indicating whether it is the first filtering operation 471 * \param isLast Flag indicating whether it is the last filtering operation 472 */ 473 Void TComInterpolationFilter::filterVerChroma(Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Int frac, Bool isFirst, Bool isLast 474 #if H_3D_ARP 475 , Bool filterType 476 #endif 477 ) 478 { 479 assert(frac >= 0 && frac < 8); 480 481 if ( frac == 0 ) 482 { 483 filterCopy(g_bitDepthC, src, srcStride, dst, dstStride, width, height, isFirst, isLast ); 484 } 485 else 486 { 487 #if H_3D_ARP 488 if(filterType) 489 { 490 filterVer<NTAPS_CHROMA_ARP>(g_bitDepthC, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilterARP[frac]); 491 } 492 else 493 { 494 #endif 495 filterVer<NTAPS_CHROMA>(g_bitDepthC, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilter[frac]); 496 #if H_3D_ARP 497 } 498 #endif 499 } 500 } 501 464 filterVer<NTAPS_CHROMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilter[frac<<(1-csy)]); 465 #if NH_3D_ARP 466 } 467 #endif 468 } 469 } 502 470 //! \}
Note: See TracChangeset for help on using the changeset viewer.