HRESULT TimgFilterTomsMoComp::process(TfilterQueue::iterator it, TffPict &pict, const TfilterSettingsVideo *cfg0)
{
    if (is(pict, cfg0)) {
        const TdeinterlaceSettings *cfg = (const TdeinterlaceSettings*)cfg0;
        if (((pict.fieldtype & FIELD_TYPE::PROGRESSIVE_FRAME) || pict.film) && !cfg->deinterlaceAlways) {
            return parent->processSample(++it, pict);
        }
        init(pict, cfg->full, cfg->half);
        const unsigned char *src[4];
        bool cspChanged = getCur(FF_CSP_420P | FF_CSP_YUY2, pict, cfg->full, src);
        unsigned char *dst[4];
        cspChanged |= getNext(csp1, pict, cfg->full, dst);

        if (cspChanged || se != cfg->tomsmocompSE || vf != cfg->tomsmocompVF || oldstride10 != stride1[0]) {
            oldstride10 = stride1[0];
            se = cfg->tomsmocompSE;
            vf = cfg->tomsmocompVF;
            done();
        }

        if (!t) {
            //pstride[0]=(dxY/16+2)*16;pstride[1]=pstride[2]=pstride[0]/2;
            for (unsigned int i = 0; i < pict.cspInfo.numPlanes; i++) {
                pstride[i] = stride1[i];
                psrc[i] = (unsigned char*)aligned_calloc(pstride[i], dy1[i]);
            }
            twidth = dx1[0];
            theight = dy1[0];
            t = createI();
            inited = t->create((Tconfig::cpu_flags & FF_CPU_SSE) != 0, (Tconfig::cpu_flags & FF_CPU_MMXEXT) != 0, (Tconfig::cpu_flags & FF_CPU_3DNOW) != 0, csp1 & FF_CSP_YUY2 ? true : false,
                               -1, se, vf != 0,
                               twidth, theight, stride1, stride2);
            frameNum = 0;
        }

        if (inited) {
            t->GetFrame(frameNum, 1, src, dst, (const unsigned char**)psrc);
            pict.fieldtype = (pict.fieldtype & ~(FIELD_TYPE::MASK_INT_PROG)) | FIELD_TYPE::PROGRESSIVE_FRAME;
            pict.csp &= ~FF_CSP_FLAGS_INTERLACED;
            for (unsigned int i = 0; i < pict.cspInfo.numPlanes; i++) {
                TffPict::copy(psrc[i], pstride[i], src[i], stride1[i], dx2[i], dy2[i]);
            }
            frameNum++;
        }
    }

    if (pict.rectClip != pict.rectFull) {
        parent->dirtyBorder = 1;
    }

    return parent->processSample(++it, pict);
}
Beispiel #2
0
HRESULT TimgFilterAwarpsharp::process(TfilterQueue::iterator it, TffPict &pict, const TfilterSettingsVideo *cfg0)
{
#if !defined(__GNUC__) && !defined(WIN64)
    if (is(pict, cfg0)) {
        const TwarpsharpSettings *cfg = (const TwarpsharpSettings*)cfg0;
        init(pict, cfg->full, cfg->half);
        getCur(FF_CSP_420P | FF_CSP_FLAGS_YUV_ADJ, pict, cfg->full, (const unsigned char**)&aws.src.yplane.ptr, (const unsigned char**)&aws.src.uplane.ptr, (const unsigned char**)&aws.src.vplane.ptr, NULL);
        getNext(csp1 | FF_CSP_FLAGS_YUV_ADJ, pict, cfg->full, &aws.dst.yplane.ptr, &aws.dst.uplane.ptr, &aws.dst.vplane.ptr, NULL);
        if (!aws.work.yplane.ptr) {
            aws.work.yplane.width = aws.work.yplane.pitch = dx1[0];
            aws.work.yplane.height = dy1[0];
            aws.work.yplane.ptr = (unsigned char*)aligned_calloc(dx1[0] * dy1[0] * pict.cspInfo.bpp / 8, 1);
            aws.work.uplane.width = aws.work.uplane.pitch = dx1[1];
            aws.work.uplane.height = dy1[1];
            aws.work.uplane.ptr = aws.work.yplane.ptr + dx1[0] * dy1[0];
            aws.work.vplane.width = aws.work.vplane.pitch = dx1[2];
            aws.work.vplane.height = dy1[2];
            aws.work.vplane.ptr = aws.work.uplane.ptr + dx1[1] * dy1[1];
            pict.clear(cfg->full);
        }
        aws.blurlevel = cfg->awarpsharpBlur;
        aws.cm = cfg->awarpsharpCM;
        aws.bm = cfg->awarpsharpBM;
        aws.depth = (int)((cfg->awarpsharpDepth / 100.0) * 512 * aws.blurlevel / 4.0 + 0.5);
        aws.thresh = (int)((cfg->awarpsharpThresh / 100.0) * 256 + 0.5);
        aws.src.yplane.width = dx1[0];
        aws.src.yplane.height = dy1[0];
        aws.src.uplane.width = dx1[1];
        aws.src.uplane.height = dy1[1];
        aws.src.vplane.width = dx1[2];
        aws.src.vplane.height = dy1[2];
        aws.src.yplane.pitch = stride1[0];
        aws.src.uplane.pitch = stride1[1];
        aws.src.vplane.pitch = stride1[2];
        aws.dst.yplane.width = dx1[0];
        aws.dst.yplane.height = dy1[0];
        aws.dst.uplane.width = dx1[1];
        aws.dst.uplane.height = dy1[1];
        aws.dst.vplane.width = dx1[2];
        aws.dst.vplane.height = dy1[2];
        aws.dst.yplane.pitch = stride2[0];
        aws.dst.uplane.pitch = stride2[1];
        aws.dst.vplane.pitch = stride2[2];
        aws_run(&aws);
        _mm_empty();
    }
#endif
    return parent->processSample(++it, pict);
}
Beispiel #3
0
/* Design FIR filter using the Window method

   n     filter length must be odd for HP and BS filters
   w     buffer for the filter taps (must be n long)
   fc    cutoff frequencies (1 for LP and HP, 2 for BP and BS)
         0 < fc < 1 where 1 <=> Fs/2
   flags window and filter type as defined in filter.h
         variables are ored together: i.e. LP|HAMMING will give a
         low pass filter designed using a hamming window
   opt   beta constant used only when designing using kaiser windows

   returns 0 if OK, -1 if fail
*/
TfirFilter::_ftype_t* TfirFilter::design_fir(unsigned int *n, _ftype_t* fc, int type, int window, _ftype_t opt)
{
  unsigned int  o   = *n & 1;            // Indicator for odd filter length
  unsigned int  end = ((*n + 1) >> 1) - o;       // Loop end
  unsigned int  i;                      // Loop index

  _ftype_t k1 = 2 * _ftype_t(M_PI);             // 2*pi*fc1
  _ftype_t k2 = 0.5f * (_ftype_t)(1 - o);// Constant used if the filter has even length
  _ftype_t k3;                           // 2*pi*fc2 Constant used in BP and BS design
  _ftype_t g  = 0.0f;                    // Gain
  _ftype_t t1,t2,t3;                     // Temporary variables
  _ftype_t fc1,fc2;                      // Cutoff frequencies

  // Sanity check
  if(*n==0) return NULL;
  fc[0]=limit(fc[0],_ftype_t(0.001),_ftype_t(1));

  if (!o && (type==TfirSettings::BANDSTOP || type==TfirSettings::HIGHPASS))
   (*n)++;
  _ftype_t *w=(_ftype_t*)aligned_calloc(sizeof(_ftype_t),*n);

  // Get window coefficients
  switch(window){
  case(TfirSettings::WINDOW_BOX):
    boxcar(*n,w); break;
  case(TfirSettings::WINDOW_TRIANGLE):
    triang(*n,w); break;
  case(TfirSettings::WINDOW_HAMMING):
    hamming(*n,w); break;
  case(TfirSettings::WINDOW_HANNING):
    hanning(*n,w); break;
  case(TfirSettings::WINDOW_BLACKMAN):
    blackman(*n,w); break;
  case(TfirSettings::WINDOW_FLATTOP):
    flattop(*n,w); break;
  case(TfirSettings::WINDOW_KAISER):
    kaiser(*n,w,opt); break;
  default:
   {
    delete []w;
    return NULL;
   }
  }

  if(type==TfirSettings::LOWPASS || type==TfirSettings::HIGHPASS){
    fc1=*fc;
    // Cutoff frequency must be < 0.5 where 0.5 <=> Fs/2
    fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25f;
    k1 *= fc1;

    if(type==TfirSettings::LOWPASS){ // Low pass filter

      // If the filter length is odd, there is one point which is exactly
      // in the middle. The value at this point is 2*fCutoff*sin(x)/x,
      // where x is zero. To make sure nothing strange happens, we set this
      // value separately.
      if (o){
        w[end] = fc1 * w[end] * 2.0f;
        g=w[end];
      }

      // Create filter
      for (i=0 ; i<end ; i++){
        t1 = (_ftype_t)(i+1) - k2;
        w[end-i-1] = w[*n-end+i] = _ftype_t(w[end-i-1] * sin(k1 * t1)/(M_PI * t1)); // Sinc
        g += 2*w[end-i-1]; // Total gain in filter
      }
    }
    else{ // High pass filter
      //if (!o) // High pass filters must have odd length
      // return -1;
      w[end] = _ftype_t(1.0 - (fc1 * w[end] * 2.0));
      g= w[end];

      // Create filter
      for (i=0 ; i<end ; i++){
        t1 = (_ftype_t)(i+1);
        w[end-i-1] = w[*n-end+i] = _ftype_t(-1 * w[end-i-1] * sin(k1 * t1)/(M_PI * t1)); // Sinc
        g += ((i&1) ? (2*w[end-i-1]) : (-2*w[end-i-1])); // Total gain in filter
      }
    }
  }

  if(type==TfirSettings::BANDPASS || type==TfirSettings::BANDSTOP){
    fc1=fc[0];
    fc2=limit(fc[1],_ftype_t(0.001),_ftype_t(1));
    // Cutoff frequencies must be < 1.0 where 1.0 <=> Fs/2
    fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25f;
    fc2 = ((fc2 <= 1.0) && (fc2 > 0.0)) ? fc2/2 : 0.25f;
    k3  = k1 * fc2; // 2*pi*fc2
    k1 *= fc1;      // 2*pi*fc1

    if(type==TfirSettings::BANDPASS){ // Band pass
      // Calculate center tap
      if (o){
        g=w[end]*(fc1+fc2);
        w[end] = (fc2 - fc1) * w[end] * 2.0f;
      }

      // Create filter
      for (i=0 ; i<end ; i++){
        t1 = (_ftype_t)(i+1) - k2;
        t2 = _ftype_t(sin(k3 * t1)/(M_PI * t1)); // Sinc fc2
        t3 = _ftype_t(sin(k1 * t1)/(M_PI * t1)); // Sinc fc1
        g += w[end-i-1] * (t3 + t2);   // Total gain in filter
        w[end-i-1] = w[*n-end+i] = w[end-i-1] * (t2 - t3);
      }
    }
    else{ // Band stop
      //if (!o) // Band stop filters must have odd length
      //  return -1;
      w[end] = _ftype_t(1.0 - (fc2 - fc1) * w[end] * 2.0);
      g= w[end];

      // Create filter
      for (i=0 ; i<end ; i++){
        t1 = (_ftype_t)(i+1);
        t2 = _ftype_t(sin(k1 * t1)/(M_PI * t1)); // Sinc fc1
        t3 = _ftype_t(sin(k3 * t1)/(M_PI * t1)); // Sinc fc2
        w[end-i-1] = w[*n-end+i] = w[end-i-1] * (t2 - t3);
        g += 2*w[end-i-1]; // Total gain in filter
      }
    }
  }

  // Normalize gain
  g=1/g;
  for (i=0; i<*n; i++)
    w[i] *= g;

  return w;
}