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

📄 i420_rgb.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
static void Deactivate( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;#if defined (MODULE_NAME_IS_i420_rgb)    free( p_vout->chroma.p_sys->p_base );#endif    free( p_vout->chroma.p_sys->p_offset );    free( p_vout->chroma.p_sys->p_buffer );    free( p_vout->chroma.p_sys );}#if defined (MODULE_NAME_IS_i420_rgb)/***************************************************************************** * SetGammaTable: return intensity table transformed by gamma curve. ***************************************************************************** * pi_table is a table of 256 entries from 0 to 255. *****************************************************************************/static void SetGammaTable( int *pi_table, double f_gamma ){    int i_y;                                               /* base intensity */    /* Use exp(gamma) instead of gamma */    f_gamma = exp( f_gamma );    /* Build gamma table */    for( i_y = 0; i_y < 256; i_y++ )    {        pi_table[ i_y ] = (int)( pow( (double)i_y / 256, f_gamma ) * 256 );    }}/***************************************************************************** * SetYUV: compute tables and set function pointers *****************************************************************************/static void SetYUV( vout_thread_t *p_vout ){    int          pi_gamma[256];                               /* gamma table */    volatile int i_index;                                 /* index in tables */                   /* We use volatile here to work around a strange gcc-3.3.4                    * optimization bug */    /* Build gamma table */    SetGammaTable( pi_gamma, p_vout->f_gamma );    /*     * Set pointers and build YUV tables     */    /* Color: build red, green and blue tables */    switch( p_vout->output.i_chroma )    {    case VLC_FOURCC('R','G','B','2'):        p_vout->chroma.p_sys->p_rgb8 = (uint8_t *)p_vout->chroma.p_sys->p_base;        Set8bppPalette( p_vout, p_vout->chroma.p_sys->p_rgb8 );        break;    case VLC_FOURCC('R','V','1','5'):    case VLC_FOURCC('R','V','1','6'):        p_vout->chroma.p_sys->p_rgb16 = (uint16_t *)p_vout->chroma.p_sys->p_base;        for( i_index = 0; i_index < RED_MARGIN; i_index++ )        {            p_vout->chroma.p_sys->p_rgb16[RED_OFFSET - RED_MARGIN + i_index] = RGB2PIXEL( p_vout, pi_gamma[0], 0, 0 );            p_vout->chroma.p_sys->p_rgb16[RED_OFFSET + 256 + i_index] =        RGB2PIXEL( p_vout, pi_gamma[255], 0, 0 );        }        for( i_index = 0; i_index < GREEN_MARGIN; i_index++ )        {            p_vout->chroma.p_sys->p_rgb16[GREEN_OFFSET - GREEN_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[0], 0 );            p_vout->chroma.p_sys->p_rgb16[GREEN_OFFSET + 256 + i_index] =          RGB2PIXEL( p_vout, 0, pi_gamma[255], 0 );        }        for( i_index = 0; i_index < BLUE_MARGIN; i_index++ )        {            p_vout->chroma.p_sys->p_rgb16[BLUE_OFFSET - BLUE_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[0] );            p_vout->chroma.p_sys->p_rgb16[BLUE_OFFSET + BLUE_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[255] );        }        for( i_index = 0; i_index < 256; i_index++ )        {            p_vout->chroma.p_sys->p_rgb16[RED_OFFSET + i_index] =   RGB2PIXEL( p_vout, pi_gamma[ i_index ], 0, 0 );            p_vout->chroma.p_sys->p_rgb16[GREEN_OFFSET + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[ i_index ], 0 );            p_vout->chroma.p_sys->p_rgb16[BLUE_OFFSET + i_index] =  RGB2PIXEL( p_vout, 0, 0, pi_gamma[ i_index ] );        }        break;    case VLC_FOURCC('R','V','2','4'):    case VLC_FOURCC('R','V','3','2'):        p_vout->chroma.p_sys->p_rgb32 = (uint32_t *)p_vout->chroma.p_sys->p_base;        for( i_index = 0; i_index < RED_MARGIN; i_index++ )        {            p_vout->chroma.p_sys->p_rgb32[RED_OFFSET - RED_MARGIN + i_index] = RGB2PIXEL( p_vout, pi_gamma[0], 0, 0 );            p_vout->chroma.p_sys->p_rgb32[RED_OFFSET + 256 + i_index] =        RGB2PIXEL( p_vout, pi_gamma[255], 0, 0 );        }        for( i_index = 0; i_index < GREEN_MARGIN; i_index++ )        {            p_vout->chroma.p_sys->p_rgb32[GREEN_OFFSET - GREEN_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[0], 0 );            p_vout->chroma.p_sys->p_rgb32[GREEN_OFFSET + 256 + i_index] =          RGB2PIXEL( p_vout, 0, pi_gamma[255], 0 );        }        for( i_index = 0; i_index < BLUE_MARGIN; i_index++ )        {            p_vout->chroma.p_sys->p_rgb32[BLUE_OFFSET - BLUE_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[0] );            p_vout->chroma.p_sys->p_rgb32[BLUE_OFFSET + BLUE_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[255] );        }        for( i_index = 0; i_index < 256; i_index++ )        {            p_vout->chroma.p_sys->p_rgb32[RED_OFFSET + i_index] =   RGB2PIXEL( p_vout, pi_gamma[ i_index ], 0, 0 );            p_vout->chroma.p_sys->p_rgb32[GREEN_OFFSET + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[ i_index ], 0 );            p_vout->chroma.p_sys->p_rgb32[BLUE_OFFSET + i_index] =  RGB2PIXEL( p_vout, 0, 0, pi_gamma[ i_index ] );        }        break;    }}static void Set8bppPalette( vout_thread_t *p_vout, uint8_t *p_rgb8 ){    #define CLIP( x ) ( ((x < 0) ? 0 : (x > 255) ? 255 : x) << 8 )    int y,u,v;    int r,g,b;    int i = 0, j = 0;    uint16_t *p_cmap_r=p_vout->chroma.p_sys->p_rgb_r;    uint16_t *p_cmap_g=p_vout->chroma.p_sys->p_rgb_g;    uint16_t *p_cmap_b=p_vout->chroma.p_sys->p_rgb_b;    unsigned char p_lookup[PALETTE_TABLE_SIZE];    /* This loop calculates the intersection of an YUV box and the RGB cube. */    for ( y = 0; y <= 256; y += 16, i += 128 - 81 )    {        for ( u = 0; u <= 256; u += 32 )        {            for ( v = 0; v <= 256; v += 32 )            {                r = y + ( (V_RED_COEF*(v-128)) >> SHIFT );                g = y + ( (U_GREEN_COEF*(u-128)                         + V_GREEN_COEF*(v-128)) >> SHIFT );                b = y + ( (U_BLUE_COEF*(u-128)) >> SHIFT );                if( r >= 0x00 && g >= 0x00 && b >= 0x00                        && r <= 0xff && g <= 0xff && b <= 0xff )                {                    /* This one should never happen unless someone                     * fscked up my code */                    if( j == 256 )                    {                        msg_Err( p_vout, "no colors left in palette" );                        break;                    }                    /* Clip the colors */                    p_cmap_r[ j ] = CLIP( r );                    p_cmap_g[ j ] = CLIP( g );                    p_cmap_b[ j ] = CLIP( b );#if 0		    printf("+++Alloc RGB cmap %d (%d, %d, %d)\n", j,			   p_cmap_r[ j ] >>8, p_cmap_g[ j ] >>8, 			   p_cmap_b[ j ] >>8);#endif                    /* Allocate color */                    p_lookup[ i ] = 1;                    p_rgb8[ i++ ] = j;                    j++;                }                else                {                    p_lookup[ i ] = 0;                    p_rgb8[ i++ ] = 0;                }            }        }    }    /* The colors have been allocated, we can set the palette */    p_vout->output.pf_setpalette( p_vout, p_cmap_r, p_cmap_g, p_cmap_b );#if 0    /* There will eventually be a way to know which colors     * couldn't be allocated and try to find a replacement */    p_vout->i_white_pixel = 0xff;    p_vout->i_black_pixel = 0x00;    p_vout->i_gray_pixel = 0x44;    p_vout->i_blue_pixel = 0x3b;#endif    /* This loop allocates colors that got outside the RGB cube */    for ( i = 0, y = 0; y <= 256; y += 16, i += 128 - 81 )    {        for ( u = 0; u <= 256; u += 32 )        {            for ( v = 0; v <= 256; v += 32, i++ )            {                int u2, v2, dist, mindist = 100000000;                if( p_lookup[ i ] || y == 0 )                {                    continue;                }                /* Heavy. yeah. */                for( u2 = 0; u2 <= 256; u2 += 32 )                {                    for( v2 = 0; v2 <= 256; v2 += 32 )                    {                        j = ((y>>4)<<7) + (u2>>5)*9 + (v2>>5);                        dist = (u-u2)*(u-u2) + (v-v2)*(v-v2);                        /* Find the nearest color */                        if( p_lookup[ j ] && dist < mindist )                        {                            p_rgb8[ i ] = p_rgb8[ j ];                            mindist = dist;                        }                        j -= 128;                        /* Find the nearest color */                        if( p_lookup[ j ] && dist + 128 < mindist )                        {                            p_rgb8[ i ] = p_rgb8[ j ];                            mindist = dist + 128;                        }                    }                }            }        }    }}#endif

⌨️ 快捷键说明

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