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

📄 image.cpp

📁 从FFMPEG转换而来的H264解码程序,VC下编译..
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                     uint8_t *y_ptr,stride_t y_stride,
                                     uint8_t *u_ptr,uint8_t *v_ptr,stride_t uv_stride,
                                     int [4],int [4],int [4],
                                     bool full=true)
    {
     uint32_t r, g, b, r0, g0, b0;
     r0 = g0 = b0 = 0;
     READ_RGB16_Y <0>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB16_Y <1>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB16_UV<0,0>(u_ptr,v_ptr,uv_stride,r,g,b,r0,g0,b0);
    }
  };

 struct RGB16I_TO_YV12
  {
   static __forceinline void ROW(int r[4],int g[4],int b[4])
    {
    }
   static __forceinline void PROCESS(uint8_t *x_ptr,stride_t x_stride,
                                     uint8_t *y_ptr,stride_t y_stride,
                                     uint8_t *u_ptr,uint8_t *v_ptr,stride_t uv_stride,
                                     int [4],int [4],int [4],
                                     bool full=true)
    {
     uint32_t r, g, b, r0, g0, b0, r1, g1, b1;
     r0 = g0 = b0 = r1 = g1 = b1 = 0;
     READ_RGB16_Y<0>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB16_Y<1>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r1,g1,b1);
     READ_RGB16_Y<2>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB16_Y<3>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r1,g1,b1);
     READ_RGB16_UV<0, 0>(u_ptr,v_ptr,uv_stride,r,g,b,r0,g0,b0);
     READ_RGB16_UV<1, 1>(u_ptr,v_ptr,uv_stride,r,g,b,r0,g0,b0);
    }
  };

 struct RGB_TO_YV12
  {
   static __forceinline void ROW(int r[4],int g[4],int b[4])
    {
    }
   static __forceinline void PROCESS(uint8_t *x_ptr,stride_t x_stride,
                                     uint8_t *y_ptr,stride_t y_stride,
                                     uint8_t *u_ptr,uint8_t *v_ptr,stride_t uv_stride,
                                     int [4],int [4],int [4],
                                     bool full=true)
    {
     uint32_t r, g, b, r0, g0, b0;
     r0 = g0 = b0 = 0;
     READ_RGB_Y<0>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB_Y<1>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB_UV<0,0>(u_ptr,v_ptr,uv_stride,r,g,b,r0,g0,b0);
    }
  };

 struct RGBI_TO_YV12
  {
   static __forceinline void ROW(int r[4],int g[4],int b[4])
    {
    }
   static __forceinline void PROCESS(uint8_t *x_ptr,stride_t x_stride,
                                     uint8_t *y_ptr,stride_t y_stride,
                                     uint8_t *u_ptr,uint8_t *v_ptr,stride_t uv_stride,
                                     int [4],int [4],int [4],
                                     bool full=true)
    {
     uint32_t r, g, b, r0, g0, b0, r1, g1, b1;
     r0 = g0 = b0 = r1 = g1 = b1 = 0;
     READ_RGB_Y<0>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB_Y<1>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r1,g1,b1);
     READ_RGB_Y<2>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r0,g0,b0);
     READ_RGB_Y<3>(x_ptr,x_stride,y_ptr,y_stride,r,g,b,r1,g1,b1);
     READ_RGB_UV<0, 0>(u_ptr,v_ptr,uv_stride,r,g,b,r0,g0,b0);
     READ_RGB_UV<1, 1>(u_ptr,v_ptr,uv_stride,r,g,b,r0,g0,b0);
    }
  };

 template<class TFUNC> static __forceinline void MAKE_COLORSPACE(uint8_t * x_ptr, stride_t x_stride,
                                   uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr,
                                   stride_t y_stride, stride_t uv_stride,
                                   int width, int height,const TFUNC &FUNC)
  {
        int fixed_width = (width + 1) & ~1;
        stride_t x_dif = x_stride - (SIZE)*fixed_width;
        stride_t y_dif = y_stride - fixed_width;
        stride_t uv_dif = uv_stride - (fixed_width / 2);
        for (int y = 0; y < height; y+=(VPIXELS)) {
                int r[4], g[4], b[4];
                FUNC.ROW(r,g,b);
                for (int x = 0; x < fixed_width; x+=(PIXELS)) {
                        FUNC.PROCESS(x_ptr,x_stride,y_ptr,y_stride,u_ptr,v_ptr,uv_stride,r,g,b,y+VPIXELS<=height);
                        x_ptr += (PIXELS)*(SIZE);
                        y_ptr += (PIXELS);
                        u_ptr += (PIXELS)/2;
                        v_ptr += (PIXELS)/2;
                }
                x_ptr += x_dif + (VPIXELS-1)*x_stride;
                y_ptr += y_dif + (VPIXELS-1)*y_stride;
                u_ptr += uv_dif + ((VPIXELS/2)-1)*uv_stride;
                v_ptr += uv_dif + ((VPIXELS/2)-1)*uv_stride;
        }
  }
};

#undef FIX_IN

//===================================== YUY2 ============================
//MAKE_COLORSPACE(yv12_to_yuyv_c,    2,2,2, YV12_TO_YUYV,   0,1,2,3,CCIR)
static void yv12_to_yuyv_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,2, intToVal<0>, 1,2,3,CCIR> TMAKE_COLORSPACE_yv12_to_yuyv_c;
 TMAKE_COLORSPACE_yv12_to_yuyv_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_yv12_to_yuyv_c::YV12_TO_YUYV());
}
//MAKE_COLORSPACE(yv12_to_uyvy_c,    2,2,2, YV12_TO_YUYV,   1,0,3,2,CCIR)
static void yv12_to_uyvy_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,2, intToVal<1>, 0,3,2,CCIR> TMAKE_COLORSPACE_yv12_to_uyvy_c;
 TMAKE_COLORSPACE_yv12_to_uyvy_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_yv12_to_uyvy_c::YV12_TO_YUYV());
}
//MAKE_COLORSPACE(yv12_to_yuyvi_c,   2,2,4, YV12_TO_YUYVI,  0,1,2,3,CCIR)
static void yv12_to_yuyvi_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,4, intToVal<0>, 1,2,3,CCIR> TMAKE_COLORSPACE_yv12_to_yuyvi_c;
 TMAKE_COLORSPACE_yv12_to_yuyvi_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_yv12_to_yuyvi_c::YV12_TO_YUYVI());
}
//MAKE_COLORSPACE(yv12_to_uyvyi_c,   2,2,4, YV12_TO_YUYVI,  1,0,3,2,CCIR)
static void yv12_to_uyvyi_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,4, intToVal<1>, 0,3,2,CCIR> TMAKE_COLORSPACE_yv12_to_uyvyi_c;
 TMAKE_COLORSPACE_yv12_to_uyvyi_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_yv12_to_uyvyi_c::YV12_TO_YUYVI());
}

//---------------------------------------------
//MAKE_COLORSPACE(yuyv_to_yv12_c,    2,2,2, YUYV_TO_YV12,   0,1,2,3,CCIR)
static void yuyv_to_yv12_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,2, intToVal<0>, 1,2,3,CCIR> TMAKE_COLORSPACE_yuyv_to_yv12_c;
 TMAKE_COLORSPACE_yuyv_to_yv12_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_yuyv_to_yv12_c::YUYV_TO_YV12());
}
//MAKE_COLORSPACE(uyvy_to_yv12_c,    2,2,2, YUYV_TO_YV12,   1,0,3,2,CCIR)
static void uyvy_to_yv12_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,2, intToVal<1>, 0,3,2,CCIR> TMAKE_COLORSPACE_uyvy_to_yv12_c;
 TMAKE_COLORSPACE_uyvy_to_yv12_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_uyvy_to_yv12_c::YUYV_TO_YV12());
}
//MAKE_COLORSPACE(yuyvi_to_yv12_c,   2,2,4, YUYVI_TO_YV12,  0,1,2,3,CCIR)
static void yuyvi_to_yv12_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,4, intToVal<0>, 1,2,3,CCIR> TMAKE_COLORSPACE_yuyvi_to_yv12_c;
 TMAKE_COLORSPACE_yuyvi_to_yv12_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_yuyvi_to_yv12_c::YUYVI_TO_YV12());
}
//MAKE_COLORSPACE(uyvyi_to_yv12_c,    2,2,2, YUYV_TO_YV12,   1,0,3,2,CCIR)
static void uyvyi_to_yv12_c(uint8_t * x_ptr,stride_t x_stride,uint8_t * y_ptr,uint8_t * u_ptr,uint8_t * v_ptr,stride_t y_stride,stride_t uv_stride,int width,int height)
{
 typedef TMAKE_COLORSPACE<2,2,4, intToVal<1>, 0,3,2,CCIR> TMAKE_COLORSPACE_uyvyi_to_yv12_c;
 TMAKE_COLORSPACE_uyvyi_to_yv12_c::MAKE_COLORSPACE(x_ptr,x_stride,y_ptr,u_ptr,v_ptr,y_stride,uv_stride,width,height,TMAKE_COLORSPACE_uyvyi_to_yv12_c::YUYVI_TO_YV12());
}

//============================================ MMX =============================================
template<class Tsimd> static void yv12_to_yv12_simd(uint8_t * y_dst, uint8_t * u_dst, uint8_t * v_dst,
 				      stride_t y_dst_stride, stride_t uv_dst_stride,
 				      const uint8_t * y_src, const uint8_t * u_src, const uint8_t * v_src,
 				      stride_t y_src_stride, stride_t uv_src_stride,
 				      int width, int height)
{
 struct TplaneCopy
  {
   static __forceinline void PLANE_COPY(uint8_t *DST,stride_t DST_DIF,const uint8_t *SRC,stride_t SRC_DIF,int WIDTH,int HEIGHT)
    {
        int eax= WIDTH  ;
        int ebp= HEIGHT ;// $ebp$ = height
        int ecx;//=0;
        const unsigned char *esi= SRC;
        unsigned char *edi= DST;

        int ebx= eax;
        eax>>=6;//                      ; $eax$ = width / 64
        ebx&=63;//; remainder = width % 64
        int edx= ebx;
        ebx>>=4 ;//               ; $ebx$ = remainder / 16
        edx&= 15;//                     ; $edx$ = remainder % 16
        __m64 mm0,mm1,mm2,mm3,mm4,mm5,mm6,mm7;
loop64_start:
        if (eax==0)
         goto loop16_start;
        ecx= eax;//            ; width64
loop64:
        Tsimd::prefetchnta (esi + 64);//  ; non temporal prefetch
        Tsimd::prefetchnta (esi + 96);

        movq (mm1, esi);//         ; read from src
        movq (mm2, esi + 8);
        movq (mm3, esi + 16);
        movq (mm4, esi + 24 );
        movq (mm5, esi + 32);
        movq (mm6, esi + 40);
        movq (mm7, esi + 48);
        movq (mm0, esi + 56);

        Tsimd::movntq (edi, mm1);//               ; write to y_out
        Tsimd::movntq (edi + 8, mm2 );
        Tsimd::movntq (edi + 16, mm3 );
        Tsimd::movntq (edi + 24, mm4 );
        Tsimd::movntq (edi + 32, mm5 );
        Tsimd::movntq (edi + 40, mm6 );
        Tsimd::movntq (edi + 48, mm7 );
        Tsimd::movntq (edi + 56, mm0 );

        esi+= 64;
        edi+= 64;
        ecx--;
        if (ecx)
         goto loop64;


loop16_start:
        if (ebx==0)
         goto loop1_start;
        ecx= ebx;//            ; width16
loop16:
        movq (mm1, esi);
        movq (mm2, esi + 8);
        Tsimd::movntq (edi, mm1);
        Tsimd::movntq (edi + 8, mm2 );

        esi+= 16;
        edi+= 16 ;
        ecx--;
        if (ecx)
         goto loop16;


loop1_start:
        ecx=edx;
        while (ecx)
         {
          *edi++=*esi++;
          ecx--;
         }
        //memcpy(edi,esi,edx);
        //mov ecx, edx
        //rep movsb

        esi+= SRC_DIF;
        edi+= DST_DIF;
        ebp--;
        if (ebp)
         goto loop64_start;
    }
  };
 int  width2	=width>>1;
 int  height2	=height>>1;
 stride_t  y_src_dif	=y_src_stride-width;;
 stride_t  y_dst_dif	=y_dst_stride-width;
 stride_t uv_src_dif	=uv_src_stride-width2;
 stride_t uv_dst_dif	=uv_dst_stride-width2;

 TplaneCopy::PLANE_COPY     ( y_dst, y_dst_dif,  y_src, y_src_dif,  width,  height);
 TplaneCopy::PLANE_COPY     ( u_dst, uv_dst_dif, u_src, uv_src_dif, width2, height2);
 TplaneCopy::PLANE_COPY     ( v_dst, uv_dst_dif, v_src, uv_src_dif, width2, height2);
}

template<class Tsimd,int BYTES,int PIXELS,int VPIXELS,int ARG1,int ARG2,int CCIR> struct TMAKE_COLORSPACE_SIMD
{
 struct YUYV_TO_YV12
  {
   static __forceinline void INIT(__m64 &mm7)
    {
     static const __int64 yuyv_mask=0x00ff00ff00ff00ffLL;
     movq (mm7, yuyv_mask);
    }
   static __forceinline void PROCESS(__m64 &mm7,unsigned char *edi,stride_t edx,unsigned char *ebx,unsigned char *ecx,unsigned char *esi,stride_t eax,stride_t uv_stride)
    {
     static const __int64 mmx_one=0x0001000100010001LL;//    dw 1, 1, 1, 1

     __m64 mm0,mm1,mm2,mm3,mm4,mm5,mm6;
     movq (mm0, edi);                               // x_ptr[0]
     movq (mm1, edi + 8);                   // x_ptr[8]
     movq (mm2, edi + edx);         // x_ptr[x_stride + 0]
     movq (mm3, edi + edx + 8);     // x_ptr[x_stride + 8]

            // average uv-components
    //---[ plain mmx ]----------------------------------------------------
    if (ARG2==0)           // if (ARG2 eq "0")
     {
                    movq (mm4, mm0);

⌨️ 快捷键说明

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