Changeset 1200 in 3DVCSoftware for branches/HTM-14.1-update-dev0/source/Lib/TLibCommon/TComInterpolationFilter.cpp
- Timestamp:
- 4 May 2015, 18:38:08 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-14.1-update-dev0/source/Lib/TLibCommon/TComInterpolationFilter.cpp
r1179 r1200 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 }, … … 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 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 349 363 #if H_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 370 filterCopy(bitDepth, src, srcStride, dst, dstStride, width, height, true, isLast ); 371 } 372 else if (isLuma(compID)) 361 373 { 362 374 #if H_3D_ARP … … 368 380 { 369 381 #endif 370 filterHor<NTAPS_LUMA>(g_bitDepthY, src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilter[frac]); 371 #if H_3D_ARP 372 } 373 #endif 374 } 375 } 376 377 /** 378 * \brief Filter a block of luma samples (vertical) 379 * 382 383 assert(frac >= 0 && frac < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 384 filterHor<NTAPS_LUMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isLast, m_lumaFilter[frac]); 385 #if H_3D_ARP 386 } 387 #endif 388 389 } 390 else 391 { 392 const UInt csx = getComponentScaleX(compID, fmt); 393 assert(frac >=0 && csx<2 && (frac<<(1-csx)) < CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 394 filterHor<NTAPS_CHROMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isLast, m_chromaFilter[frac<<(1-csx)]); 395 } 396 } 397 398 399 /** 400 * \brief Filter a block of Luma/Chroma samples (vertical) 401 * 402 * \param compID Colour component ID 380 403 * \param src Pointer to source samples 381 404 * \param srcStride Stride of source samples … … 387 410 * \param isFirst Flag indicating whether it is the first filtering operation 388 411 * \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 412 * \param fmt Chroma format 413 * \param bitDepth Bit depth 414 */ 415 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 391 416 #if H_3D_ARP 392 417 , Bool filterType 393 418 #endif 394 ) 395 { 396 assert(frac >= 0 && frac < 4); 397 419 ) 420 { 398 421 if ( frac == 0 ) 399 422 { 400 filterCopy( g_bitDepthY, src, srcStride, dst, dstStride, width, height, isFirst, isLast );401 } 402 else 423 filterCopy(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast ); 424 } 425 else if (isLuma(compID)) 403 426 { 404 427 #if H_3D_ARP … … 410 433 { 411 434 #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 435 assert(frac >= 0 && frac < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 436 filterVer<NTAPS_LUMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_lumaFilter[frac]); 437 #if H_3D_ARP 438 } 439 #endif 440 441 } 442 else 443 { 444 const UInt csy = getComponentScaleY(compID, fmt); 445 assert(frac >=0 && csy<2 && (frac<<(1-csy)) < CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS); 446 filterVer<NTAPS_CHROMA>(bitDepth, src, srcStride, dst, dstStride, width, height, isFirst, isLast, m_chromaFilter[frac<<(1-csy)]); 447 } 448 } 449 432 450 #if H_3D_ARP 433 451 , Bool filterType 434 452 #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 { 453 445 454 #if H_3D_ARP 446 455 if(filterType) … … 451 460 { 452 461 #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 462 #if H_3D_ARP 463 } 464 #endif 474 465 #if H_3D_ARP 475 466 , Bool filterType 476 467 #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 else486 {487 468 #if H_3D_ARP 488 469 if(filterType) … … 493 474 { 494 475 #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 } 476 #if H_3D_ARP 477 } 478 #endif 479 480 501 481 502 482 //! \}
Note: See TracChangeset for help on using the changeset viewer.