Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
    5  *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     4 * granted under this license.
     5 *
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4545#include <assert.h>
    4646
     47#include "TComChromaFormat.h"
     48
    4749
    4850//! \ingroup TLibCommon
     
    5355// ====================================================================================================================
    5456
    55 const Short TComInterpolationFilter::m_lumaFilter[4][NTAPS_LUMA] =
     57const TFilterCoeff TComInterpolationFilter::m_lumaFilter[LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS][NTAPS_LUMA] =
    5658{
    5759  {  0, 0,   0, 64,  0,   0, 0,  0 },
     
    6163};
    6264
    63 const Short TComInterpolationFilter::m_chromaFilter[8][NTAPS_CHROMA] =
     65const TFilterCoeff TComInterpolationFilter::m_chromaFilter[CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS][NTAPS_CHROMA] =
    6466{
    6567  {  0, 64,  0,  0 },
     
    7375};
    7476
    75 #if H_3D_ARP
     77#if NH_3D_ARP
    7678const Short TComInterpolationFilter::m_lumaFilterARP[4][NTAPS_LUMA_ARP] =
    7779{
     
    111113 * \param isLast     Flag indicating whether it is the last filtering operation
    112114 */
    113 Void TComInterpolationFilter::filterCopy(Int bitDepth, const Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast)
     115Void TComInterpolationFilter::filterCopy(Int bitDepth, const Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast)
    114116{
    115117  Int row, col;
    116  
     118
    117119  if ( isFirst == isLast )
    118120  {
     
    123125        dst[col] = src[col];
    124126      }
    125      
     127
    126128      src += srcStride;
    127129      dst += dstStride;
    128     }             
     130    }
    129131  }
    130132  else if ( isFirst )
    131133  {
    132     Int shift = IF_INTERNAL_PREC - bitDepth;
    133    
     134    const Int shift = std::max<Int>(2, (IF_INTERNAL_PREC - bitDepth));
     135
    134136    for (row = 0; row < height; row++)
    135137    {
    136138      for (col = 0; col < width; col++)
    137139      {
    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
    142144      src += srcStride;
    143145      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;
    153154    for (row = 0; row < height; row++)
    154155    {
    155156      for (col = 0; col < width; col++)
    156157      {
    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        }
    161168        dst[col] = val;
    162169      }
    163      
     170
    164171      src += srcStride;
    165172      dst += dstStride;
    166     }             
     173    }
    167174  }
    168175}
     
    185192 */
    186193template<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, Short const *coeff)
     194Void TComInterpolationFilter::filter(Int bitDepth, Pel const *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, TFilterCoeff const *coeff)
    188195{
    189196  Int row, col;
    190  
    191   Short c[8];
     197
     198  Pel c[8];
    192199  c[0] = coeff[0];
    193200  c[1] = coeff[1];
     
    207214    c[7] = coeff[7];
    208215  }
    209  
     216
    210217  Int cStride = ( isVertical ) ? srcStride : 1;
    211218  src -= ( N/2 - 1 ) * cStride;
    212219
    213220  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
    217228  if ( isLast )
    218229  {
     
    228239    maxVal = 0;
    229240  }
    230  
     241
    231242  for (row = 0; row < height; row++)
    232243  {
     
    234245    {
    235246      Int sum;
    236      
     247
    237248      sum  = src[ col + 0 * cStride] * c[0];
    238249      sum += src[ col + 1 * cStride] * c[1];
     
    250261      {
    251262        sum += src[ col + 6 * cStride] * c[6];
    252         sum += src[ col + 7 * cStride] * c[7];       
    253       }
    254      
    255       Short val = ( sum + offset ) >> shift;
     263        sum += src[ col + 7 * cStride] * c[7];
     264      }
     265
     266      Pel val = ( sum + offset ) >> shift;
    256267      if ( isLast )
    257268      {
    258269        val = ( val < 0 ) ? 0 : val;
    259         val = ( val > maxVal ) ? maxVal : val;       
     270        val = ( val > maxVal ) ? maxVal : val;
    260271      }
    261272      dst[col] = val;
    262273    }
    263    
     274
    264275    src += srcStride;
    265276    dst += dstStride;
    266   }   
     277  }
    267278}
    268279
     
    282293 */
    283294template<Int N>
    284 Void TComInterpolationFilter::filterHor(Int bitDepth, Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Bool isLast, Short const *coeff)
     295Void TComInterpolationFilter::filterHor(Int bitDepth, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isLast, TFilterCoeff const *coeff)
    285296{
    286297  if ( isLast )
     
    298309 *
    299310 * \tparam N          Number of taps
    300  * \param  bitDpeth   Sample bit depth
     311 * \param  bitDepth   Bit depth
    301312 * \param  src        Pointer to source samples
    302313 * \param  srcStride  Stride of source samples
     
    310321 */
    311322template<Int N>
    312 Void TComInterpolationFilter::filterVer(Int bitDepth, Pel *src, Int srcStride, Short *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast, Short const *coeff)
     323Void TComInterpolationFilter::filterVer(Int bitDepth, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast, TFilterCoeff const *coeff)
    313324{
    314325  if ( isFirst && isLast )
     
    327338  {
    328339    filter<N, true, false, false>(bitDepth, src, srcStride, dst, dstStride, width, height, coeff);
    329   }     
     340  }
    330341}
    331342
     
    335346
    336347/**
    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
    339351 * \param  src        Pointer to source samples
    340352 * \param  srcStride  Stride of source samples
     
    345357 * \param  frac       Fractional sample offset
    346358 * \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 */
     362Void 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
    350364    , Bool filterType
    351365#endif
    352   )
    353 {
    354   assert(frac >= 0 && frac < 4);
    355  
     366)
     367{
    356368  if ( frac == 0 )
    357369  {
    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
    363376    if(filterType)
    364377    {
    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]);
    366379    }
    367380    else
    368381    {
    369382#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
    372403    }
    373404#endif
     
    375406}
    376407
    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
    380413 * \param  src        Pointer to source samples
    381414 * \param  srcStride  Stride of source samples
     
    387420 * \param  isFirst    Flag indicating whether it is the first filtering operation
    388421 * \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 */
     425Void 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
    392427    , Bool filterType
    393428#endif
    394   )
    395 {
    396   assert(frac >= 0 && frac < 4);
    397  
     429)
     430{
    398431  if ( frac == 0 )
    399432  {
    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
    405439    if(filterType)
    406440    {
    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]);   
    408442    }
    409443    else
    410444    {
    411445#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
    446457    if(filterType)
    447458    {
    448       filterHor<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]);   
    449460    }
    450461    else
    451462    {
    452463#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    }
    502470//! \}
Note: See TracChangeset for help on using the changeset viewer.