⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tspuimage.cpp

📁 从FFMPEG转换而来的H264解码程序,VC下编译..
💻 CPP
📖 第 1 页 / 共 2 页
字号:
     tmp = left * top * (srca[base + (unsigned int) unscaled_x]);
     alpha += tmp;
     color += tmp * srci[base + (unsigned int) unscaled_x];
     /* 2: top center part */
     if (width > 0) {
       unsigned int walkx;
       for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {
         base = srcStride * (unsigned int) unscaled_y + walkx;
         tmp = /* 1.0 * */ top * (srca[base]);
         alpha += tmp;
         color += tmp * srci[base];
       }
     }
     /* 3: top right part */
     if (right > 0.0) {
       base = srcStride * (unsigned int) unscaled_y + (unsigned int) unscaled_x_right;
       tmp = right * top * (srca[base]);
       alpha += tmp;
       color += tmp * srci[base];
     }
     /* 4: center left part */
     if (height > 0) {
       unsigned int walky;
       for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {
         base = srcStride * walky + (unsigned int) unscaled_x;
         tmp = left /* * 1.0 */ * (srca[base]);
         alpha += tmp;
         color += tmp * srci[base];
       }
     }
     /* 5: center part */
     if (width > 0 && height > 0) {
       unsigned int walky;
       for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {
         unsigned int walkx;
         base = srcStride * walky;
         for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {
           tmp = /* 1.0 * 1.0 * */ (srca[base + walkx]);
           alpha += tmp;
           color += tmp * srci[base + walkx];
         }
       }
     }
     /* 6: center right part */
     if (right > 0.0 && height > 0) {
       unsigned int walky;
       for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {
         base = srcStride * walky + (unsigned int) unscaled_x_right;
         tmp = right /* * 1.0 */ * (srca[base]);
         alpha += tmp;
         color += tmp * srci[base];
       }
     }
     /* 7: bottom left part */
     if (bottom > 0.0) {
       base = srcStride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x;
       tmp = left * bottom * (srca[base]);
       alpha += tmp;
       color += tmp * srci[base];
     }
     /* 8: bottom center part */
     if (width > 0 && bottom > 0.0) {
       unsigned int walkx;
       base = srcStride * (unsigned int) unscaled_y_bottom;
       for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {
         tmp = /* 1.0 * */ bottom * (srca[base + walkx]);
         alpha += tmp;
         color += tmp * srci[base + walkx];
       }
     }
     /* 9: bottom right part */
     if (right > 0.0 && bottom > 0.0) {
       base = srcStride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x_right;
       tmp = right * bottom * (srca[base]);
       alpha += tmp;
       color += tmp * srci[base];
     }
     /* Finally mix these transparency and brightness information suitably */
     *dstiLn = (unsigned char)(alpha > 0 ? color / alpha : 0);
     *dstaLn = (unsigned char)(alpha * scalex * scaley / 0x10000);
    }
  }
}

//============================================ TspuImage::TscalerBilin =============================================
TspuImage::TscalerBilin::TscalerBilin(const TrenderedSubtitleLines::TprintPrefs &prefs,int srcdx,int srcdy,int dstdx,int dstdy):Tscaler(srcdx,srcdy,dstdx,dstdy)
{
 table_x=(scale_pixel*)calloc(dstdx,sizeof(scale_pixel));
 table_y=(scale_pixel*)calloc(dstdy,sizeof(scale_pixel));
 scale_table(0,0,srcdx-1,dstdx-1,table_x);
 scale_table(0,0,srcdy-1,dstdy-1,table_y);
}
TspuImage::TscalerBilin::~TscalerBilin()
{
 free(table_x);
 free(table_y);
}
void TspuImage::TscalerBilin::scale_table(unsigned int start_src, unsigned int start_tar, unsigned int end_src, unsigned int end_tar, scale_pixel *table)
{
 unsigned int delta_src=end_src-start_src;
 unsigned int delta_tar=end_tar-start_tar;
 if (delta_src==0 || delta_tar==0)
  return;
 int src=0,src_step=(delta_src<<16)/delta_tar >>1;
 for (unsigned int t=0;t<=delta_tar;src+=(src_step<<1),t++)
  {
   table[t].position=std::min((unsigned int)(src>>16),end_src-1);
   table[t].right_down=src&0xffff;
   table[t].left_up=0x10000-table[t].right_down;
  }
}

void TspuImage::TscalerBilin::scale(const unsigned char *srci,const unsigned char *srca,stride_t srcStride,unsigned char *dsti,unsigned char *dsta,stride_t dstStride)
{
 for (int y=0;y<dstdy;y++,dsti+=dstStride,dsta+=dstStride)
  {
   unsigned char *dstiLn=dsti,*dstaLn=dsta;
   for (int x=0;x<dstdx;x++,dstiLn++,dstaLn++)
    {
     stride_t base=table_y[y].position*srcStride+table_x[x].position;
     int alpha[4];
     alpha[0]=canon_alpha(srca[base]);
     alpha[1]=canon_alpha(srca[base+1]);
     alpha[2]=canon_alpha(srca[base+srcStride]);
     alpha[3]=canon_alpha(srca[base+srcStride+1]);
     int color[4];
     color[0]=srci[base];
     color[1]=srci[base+1];
     color[2]=srci[base+srcStride];
     color[3]=srci[base+srcStride+1];
     unsigned int scale[4];
     scale[0]=(table_x[x].left_up*table_y[y].left_up>>16)*alpha[0];
     scale[1]=(table_x[x].right_down*table_y[y].left_up>>16)*alpha[1];
     scale[2]=(table_x[x].left_up*table_y[y].right_down>>16)*alpha[2];
     scale[3]=(table_x[x].right_down*table_y[y].right_down>>16)*alpha[3];
     *dstiLn=(unsigned char)((color[0] * scale[0] + color[1] * scale[1] + color[2] * scale[2] + color[3] * scale[3])>>24);
     *dstaLn=(unsigned char)((scale[0] + scale[1] + scale[2] + scale[3]) >> 20);
    }
  }
}

//============================================== TspuImage::TscalerSw ==============================================
TspuImage::TscalerSw::TscalerSw(const TrenderedSubtitleLines::TprintPrefs &prefs,int srcdx,int srcdy,int dstdx,int dstdy):
 Tscaler(srcdx,srcdy,dstdx,dstdy),
 approx(prefs,srcdx,srcdy,dstdx,dstdy)
{
 prefs.deci->getPostproc(&libmplayer);
 filter.lumH=filter.lumV=filter.chrH=filter.chrV=libmplayer->sws_getGaussianVec(prefs.vobaagauss/1000.0, 3.0);
 libmplayer->sws_normalizeVec(filter.lumH,1.0);
 SwsParams params;Tlibmplayer::swsInitParams(&params,SWS_GAUSS);
 ctx=libmplayer->sws_getContext(srcdx,srcdy,IMGFMT_Y800,dstdx,dstdy,IMGFMT_Y800,&params,&filter,NULL);
}
TspuImage::TscalerSw::~TscalerSw()
{
 libmplayer->sws_freeVec(filter.lumH);
 if (ctx) libmplayer->sws_freeContext(ctx);
 libmplayer->Release();
}
void TspuImage::TscalerSw::scale(const unsigned char *srci,const unsigned char *srca,stride_t srcStride,unsigned char *dsti,unsigned char *dsta,stride_t dstStride)
{
 if (!ctx)
  approx.scale(srci,srca,srcStride,dsti,dsta,dstStride);
 else
  {
   libmplayer->sws_scale_ordered(ctx,&srci,&srcStride,0,srcdy,&dsti,&dstStride);
   libmplayer->sws_scale_ordered(ctx,&srca,&srcStride,0,srcdy,&dsta,&dstStride);
  }
}

//================================================= TspuImageSimd =================================================
template<class _mm> void TspuImageSimd<_mm>::print(unsigned int dx[3],unsigned char *dstLn[3],const stride_t stride[3],const unsigned char *bmp[3],const unsigned char *msk[3]) const
{
 if (!plane[0].stride || !plane[0].c || !plane[0].r) return;
 typename _mm::__m m0=_mm::setzero_si64();
 for (int i=0;i<3;i++)
  {
   unsigned char *dst=dstLn[i];
   const unsigned char *c=bmp[i],*r=msk[i];
   for (int y=rect[i].top;y<rect[i].bottom;y++,dst+=stride[i],c+=plane[i].stride,r+=plane[i].stride)
    {
     int x=0;
     for (;x<int(dx[i]-_mm::size/2+1);x+=_mm::size/2)
      {
       typename _mm::__m p8=_mm::unpacklo_pi8(_mm::load2(dst+x),m0);
       typename _mm::__m c8=_mm::unpacklo_pi8(_mm::load2(c+x),m0);
       typename _mm::__m r8=_mm::unpacklo_pi8(_mm::load2(r+x),m0);
       _mm::store2(dst+x,_mm::packs_pu16(_mm::sub_pi16(p8,_mm::srai_pi16(_mm::mullo_pi16(_mm::sub_pi16(p8,c8),r8),4)),m0));
      }
     for (;x<int(dx[i]);x++)
      dst[x]=(unsigned char)(dst[x]-((dst[x]-c[x])*r[x]>>4));
    }
  }
 _mm::empty();
}
template<class _mm> void TspuImageSimd<_mm>::ownprint(const TrenderedSubtitleLines::TprintPrefs &prefs)
{
 if (!plane[0].stride || !plane[0].c || !plane[0].r) return;
 typename _mm::__m m0=_mm::setzero_si64();
 unsigned int sizeDx=prefs.sizeDx?prefs.sizeDx:prefs.dx;
 for (int i=0;i<3;i++)
  {
   unsigned char *dst=prefs.dst[i]+rect[i].top*prefs.stride[i]+rect[i].left;
   const unsigned char *c=plane[i].c,*r=plane[i].r;
   for (int y=rect[i].top;y<rect[i].bottom;y++,dst+=prefs.stride[i],c+=plane[i].stride,r+=plane[i].stride)
    {
     int x=0,dx=rect[i].Width();if (rect[i].left+dx>(int)sizeDx>>prefs.shiftX[i]) dx=(sizeDx>>prefs.shiftX[i])-rect[i].left;
     for (;x<int(dx-_mm::size/2+1);x+=_mm::size/2)
      {
       typename _mm::__m p8=_mm::unpacklo_pi8(_mm::load2(dst+x),m0);
       typename _mm::__m c8=_mm::unpacklo_pi8(_mm::load2(c+x),m0);
       typename _mm::__m r8=_mm::unpacklo_pi8(_mm::load2(r+x),m0);
       _mm::store2(dst+x,_mm::packs_pu16(_mm::sub_pi16(p8,_mm::srai_pi16(_mm::mullo_pi16(_mm::sub_pi16(p8,c8),r8),4)),m0));
      }
     for (;x<dx;x++)
      dst[x]=(unsigned char)(dst[x]-((dst[x]-c[x])*r[x]>>4));
    }
  }
 _mm::empty();
}

template struct TspuImageSimd<Tmmx>;
#ifdef __SSE2__
 template struct TspuImageSimd<Tsse2>;
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -