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

📄 rgb2yuv.c

📁 linux下的一款播放器
💻 C
📖 第 1 页 / 共 3 页
字号:
        src_width  <= 0 || src_height  <= 0 ||    /* rectangles: */        dest_x < 0 || dest_y < 0 || dest_dx <= 0 || dest_dy <= 0 ||        src_x  < 0 || src_y  < 0 || src_dx  <= 0 || src_dy  <= 0 ||    /* overlaps: */        dest_width < dest_x + dest_dx || dest_height < dest_y + dest_dy ||        src_width  < src_x  + src_dx  || src_height  < src_y  + src_dy)        goto fail;    /* scale factors: */    if (dest_dx == src_dx)          *p_scale_x = 1;    else if (dest_dx == 2 * src_dx) *p_scale_x = 2;    else goto fail;    if (dest_dy == src_dy)          *p_scale_y = 1;    else if (dest_dy == 2 * src_dy) *p_scale_y = 2;    else goto fail;    /* success: */    return 1;    /* failure: */fail:    return 0;}static int adjust_range (int *z1, int *dz1, int *z2, int *dz2, int inc2){    /* skip odd start pixel: */    if (*z1 & 1) {        *z1 += 1;        *dz1 -= 1;        *z2 += inc2;        *dz2 -= inc2;    }    /* clip the range: */    if (*dz1 & 1) {        *dz1 -= 1;        *dz2 -= inc2;    }    return (*dz1 > 0 && *dz2 > 0);}//////////////////////////////////////////////////////////	ARGBtoYUVA////	Note: YUVA is identical to I420 but has an additional//	  planar field at the end the contains "alpha" info.//	  This "alpha" field is the size of the Y component////////////////////////////////////////////////////////int ARGBtoYUVA (unsigned char *dest_ptr, int dest_width, int dest_height,    int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,    unsigned char *src_ptr, int src_width, int src_height, int src_pitch,    int src_x, int src_y, int src_dx, int src_dy){    /* scale factors: */    int scale_x, scale_y;    /* check arguments: */    if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,        dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,        src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))        return -1;    /* align destination rectangle: */    if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x) ||        !adjust_range (&dest_y, &dest_dy, &src_y, &src_dy, scale_y))        return 0;    /* check if bottom-up bitmaps: */    if (src_pitch < 0)  src_ptr -= (src_height-1) * src_pitch;    if (dest_pitch <= 0) return -1;     /* not supported *//* *  if (!is_dest_alpha && !is_dest_beta && !is_dest_gamma && !is_dest_kappa) */    {        /* just move data in, no color adjustments: */        unsigned char *s1, *s2, *d1, *d2, *dv, *du, *d3, *d4;        register int i, j;        /* get pointers: */        s1 = src_ptr + src_x * BPP(RGB32) + src_y * src_pitch; /* 3 bytes/pixel */        s2 = s1 + src_pitch;        d1 = dest_ptr + dest_x + dest_y * dest_pitch;    /* luma offsets  */        d2 = d1 + dest_pitch;        du = dest_ptr + dest_height * dest_pitch + (dest_x/2 + dest_y/2 * dest_pitch/2); /* chroma offset */        dv = du + dest_height * dest_pitch/4;        d3 = dv + dest_height * dest_pitch/4;        d4 = d3 + dest_pitch;        switch (chroma_resampling_mode)        {            case CRM_00_11:                /* the main loop (processes 2 lines a time): */                for (i = 0; i < dest_dy/2; i ++) {                    /* convert 2x2 block: */                    for (j = 0; j < dest_dx/2; j ++) {                        int r2, b2, y2;                        /* process lumas: */                        {                            PIXEL(RGB32,x);                            register unsigned int r, b, y;                            LOAD(RGB32,s1,x);               /* [0,0] */                            r = GET_R(RGB32,x);                            b = GET_B(RGB32,x);                            y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b];                            d1[0] = yytab [y];							d3[0] = GET_A(RGB32,x);                            LOAD(RGB32,s1+BPP(RGB32),x);    /* [0,1] */                            r = GET_R(RGB32,x);                            b = GET_B(RGB32,x);                            y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b];                            d1[1] = yytab [y];							d3[1] = GET_A(RGB32,x);                            LOAD(RGB32,s2,x);               /* [1,0] */                            r2 = (r = GET_R(RGB32,x));                            b2 = (b = GET_B(RGB32,x));                            y2 = (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d2[0] = yytab [y];							d4[0] = GET_A(RGB32,x);                            LOAD(RGB32,s2+BPP(RGB32),x);    /* [1,1] */                            r2 += (r = GET_R(RGB32,x));                            b2 += (b = GET_B(RGB32,x));                            y2 += (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d2[1] = yytab [y];							d4[1] = GET_A(RGB32,x);                        }                        /* average chromas: */                        dv[0] = vrytab [VMIN+(r2-y2)/2];                        du[0] = ubytab [UMIN+(b2-y2)/2];                        /* go to the next block: */                        s1 += 2 * BPP(RGB32); s2 += 2 * BPP(RGB32);                        d1 += 2; d2 += 2;                        d3 += 2; d4 += 2;                        du += 1; dv += 1;                    }                    /* switch to the next two lines: */                    s1 += src_pitch * 2 - dest_dx * BPP(RGB32);                    s2 += src_pitch * 2 - dest_dx * BPP(RGB32);                    d1 += dest_pitch * 2 - dest_dx;                    d2 += dest_pitch * 2 - dest_dx;                    d3 += dest_pitch * 2 - dest_dx;                    d4 += dest_pitch * 2 - dest_dx;                    du += (dest_pitch - dest_dx)/2;                    dv += (dest_pitch - dest_dx)/2;                }                break;            case CRM_11_00:                /* the main loop (processes 2 lines a time): */                for (i = 0; i < dest_dy/2; i ++) {                    /* convert 2x2 block: */                    for (j = 0; j < dest_dx/2; j ++) {                        int r2, b2, y2;                        /* process lumas: */                        {                            PIXEL(RGB32,x);                            register unsigned int r, b, y;                            LOAD(RGB32,s1,x);               /* [0,0] */                            r2 = (r = GET_R(RGB32,x));                            b2 = (b = GET_B(RGB32,x));                            y2 = (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d1[0] = yytab [y];							d3[0] = GET_A(RGB32,x);                            LOAD(RGB32,s1+BPP(RGB32),x);    /* [0,1] */                            r2 += (r = GET_R(RGB32,x));                            b2 += (b = GET_B(RGB32,x));                            y2 += (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d1[1] = yytab [y];							d3[1] = GET_A(RGB32,x);                            LOAD(RGB32,s2,x);               /* [1,0] */                            r = GET_R(RGB32,x);                            b = GET_B(RGB32,x);                            y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b];                            d2[0] = yytab [y];							d4[0] = GET_A(RGB32,x);                            LOAD(RGB32,s2+BPP(RGB32),x);    /* [1,1] */                            r = GET_R(RGB32,x);                            b = GET_B(RGB32,x);                            y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b];                            d2[1] = yytab [y]; 							d4[1] = GET_A(RGB32,x);                       }                        /* average chromas: */                        dv[0] = vrytab [VMIN+(r2-y2)/2];                        du[0] = ubytab [UMIN+(b2-y2)/2];                        /* go to the next block: */                        s1 += 2 * BPP(RGB32); s2 += 2 * BPP(RGB32);                        d1 += 2; d2 += 2;                        d3 += 2; d4 += 2;                        du += 1; dv += 1;                    }                    /* switch to the next two lines: */                    s1 += src_pitch * 2 - dest_dx * BPP(RGB32);                    s2 += src_pitch * 2 - dest_dx * BPP(RGB32);                    d1 += dest_pitch * 2 - dest_dx;                    d2 += dest_pitch * 2 - dest_dx;                    d3 += dest_pitch * 2 - dest_dx;                    d4 += dest_pitch * 2 - dest_dx;                    du += (dest_pitch - dest_dx)/2;                    dv += (dest_pitch - dest_dx)/2;                }                break;            case CRM_11_11:            default:                /* the main loop (processes 2 lines a time): */                for (i = 0; i < dest_dy/2; i ++) {                    /* convert 2x2 block: */                    for (j = 0; j < dest_dx/2; j ++) {                        int r4, b4, y4;                        /* process lumas: */                        {                            PIXEL(RGB32,x);                            register unsigned int r, b, y;                            LOAD(RGB32,s1,x);               /* [0,0] */                            r4 = (r = GET_R(RGB32,x));                            b4 = (b = GET_B(RGB32,x));                            y4 = (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d1[0] = yytab [y];							d3[0] = GET_A(RGB32,x);                            LOAD(RGB32,s1+BPP(RGB32),x);    /* [0,1] */                            r4 += (r = GET_R(RGB32,x));                            b4 += (b = GET_B(RGB32,x));                            y4 += (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d1[1] = yytab [y];							d3[1] = GET_A(RGB32,x);                            LOAD(RGB32,s2,x);               /* [1,0] */                            r4 += (r = GET_R(RGB32,x));                            b4 += (b = GET_B(RGB32,x));                            y4 += (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d2[0] = yytab [y];							d4[0] = GET_A(RGB32,x);                            LOAD(RGB32,s2+BPP(RGB32),x);    /* [1,1] */                            r4 += (r = GET_R(RGB32,x));                            b4 += (b = GET_B(RGB32,x));                            y4 += (y = yrtab [r] + ygtab [GET_G(RGB32,x)] + ybtab [b]);                            d2[1] = yytab [y];							d4[1] = GET_A(RGB32,x);                        }                        /* average chromas: */                        dv[0] = vrytab [VMIN+(r4-y4)/4];                        du[0] = ubytab [UMIN+(b4-y4)/4];                        /* go to the next block: */                        s1 += 2 * BPP(RGB32); s2 += 2 * BPP(RGB32);                        d1 += 2; d2 += 2;                        d3 += 2; d4 += 2;                        du += 1; dv += 1;                    }                    /* switch to the next two lines: */                    s1 += src_pitch * 2 - dest_dx * BPP(RGB32);                    s2 += src_pitch * 2 - dest_dx * BPP(RGB32);                    d1 += dest_pitch * 2 - dest_dx;                    d2 += dest_pitch * 2 - dest_dx;                    d3 += dest_pitch * 2 - dest_dx;                    d4 += dest_pitch * 2 - dest_dx;                    du += (dest_pitch - dest_dx)/2;                    dv += (dest_pitch - dest_dx)/2;                }        }    }/* *  else { *      put all the color-dependent stuff here ... *  } */    return 0;}/* rgb2yuv.c -- end of file */

⌨️ 快捷键说明

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