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

📄 rgb.c

📁 mpeg2 decoder filter过滤服务端
💻 C
📖 第 1 页 / 共 2 页
字号:
									\	    pu += 8;							\	    pv += 8;							\	    py += 8;							\	    dst += 8 * num;						\	} while (--j);							\	py += id->base.y_increm;				   	\	pu += id->base.y_increm;				   	\	pv += id->base.y_increm;				   	\	dst = (type *)((char *)dst + id->base.rgb_increm);		\	DITHER(dithpos += id->base.dither_stride;)			\    } while (--i);							\}DECLARE_444 (rgb_c_32_444, uint32_t, 1, DST, SKIP)DECLARE_444 (rgb_c_24_rgb_444, uint8_t, 3, DSTRGB, SKIP)DECLARE_444 (rgb_c_24_bgr_444, uint8_t, 3, DSTBGR, SKIP)DECLARE_444 (rgb_c_16_444, uint16_t, 1, DST, SKIP)DECLARE_444 (rgb_c_8_444, uint8_t, 1, DSTDITHER, DO)static void rgb_start (void * _id, const mpeg2_fbuf_t * fbuf,		       const mpeg2_picture_t * picture,		       const mpeg2_gop_t * gop){    convert_rgb_t * id = (convert_rgb_t *) _id;    int uv_stride = id->uv_stride_frame;    id->y_stride = id->y_stride_frame;    id->rgb_ptr = fbuf->buf[0];    id->rgb_stride = id->rgb_stride_frame;    id->dither_stride = 32;    id->dither_offset = dither_temporal[picture->temporal_reference & 63];    if (picture->nb_fields == 1) {	uv_stride <<= 1;	id->y_stride <<= 1;	id->rgb_stride <<= 1;	id->dither_stride <<= 1;	id->dither_offset += 16;	if (!(picture->flags & PIC_FLAG_TOP_FIELD_FIRST)) {	    id->rgb_ptr += id->rgb_stride_frame;	    id->dither_offset += 32;	}    }    id->y_increm = (id->y_stride << id->convert420) - id->y_stride_frame;    id->uv_increm = uv_stride - id->uv_stride_frame;    id->rgb_increm = (id->rgb_stride << id->convert420) - id->rgb_stride_min;    id->dither_stride <<= id->convert420;}static inline int div_round (int dividend, int divisor){    if (dividend > 0)	return (dividend + (divisor>>1)) / divisor;    else	return -((-dividend + (divisor>>1)) / divisor);}static unsigned int rgb_c_init (convert_rgb_c_t * id,				mpeg2convert_rgb_order_t order,				unsigned int bpp){    int i;    uint8_t table_Y[1024];    uint32_t * table_32 = 0;    uint16_t * table_16 = 0;    uint8_t * table_8 = 0;    uint8_t * table_332 = 0;    int entry_size = 0;    void * table_r = 0;    void * table_g = 0;    void * table_b = 0;    int crv = Inverse_Table_6_9[matrix_coefficients][0];    int cbu = Inverse_Table_6_9[matrix_coefficients][1];    int cgu = -Inverse_Table_6_9[matrix_coefficients][2];    int cgv = -Inverse_Table_6_9[matrix_coefficients][3];    for (i = 0; i < 1024; i++) {	int j;	j = (76309 * (i - 384 - 16) + 32768) >> 16;	table_Y[i] = (j < 0) ? 0 : ((j > 255) ? 255 : j);    }    switch (bpp) {    case 32:	if (!id)	    return (197 + 2*682 + 256 + 132) * sizeof (uint32_t);	table_32 = (uint32_t *) (id + 1);	entry_size = sizeof (uint32_t);	table_r = table_32 + 197;	table_b = table_32 + 197 + 685;	table_g = table_32 + 197 + 2*682;	for (i = -197; i < 256+197; i++)	    ((uint32_t *) table_r)[i] =		table_Y[i+384] << ((order == MPEG2CONVERT_RGB) ? 16 : 0);	for (i = -132; i < 256+132; i++)	    ((uint32_t *) table_g)[i] = table_Y[i+384] << 8;	for (i = -232; i < 256+232; i++)	    ((uint32_t *) table_b)[i] =		table_Y[i+384] << ((order == MPEG2CONVERT_RGB) ? 0 : 16);	break;    case 24:	if (!id)	    return (256 + 2*232) * sizeof (uint8_t);	table_8 = (uint8_t *) (id + 1);	entry_size = sizeof (uint8_t);	table_r = table_g = table_b = table_8 + 232;	for (i = -232; i < 256+232; i++)	    ((uint8_t * )table_b)[i] = table_Y[i+384];	break;    case 15:    case 16:	if (!id)	    return (197 + 2*682 + 256 + 132) * sizeof (uint16_t);	table_16 = (uint16_t *) (id + 1);	entry_size = sizeof (uint16_t);	table_r = table_16 + 197;	table_b = table_16 + 197 + 685;	table_g = table_16 + 197 + 2*682;	for (i = -197; i < 256+197; i++) {	    int j = table_Y[i+384] >> 3;	    if (order == MPEG2CONVERT_RGB)		j <<= ((bpp==16) ? 11 : 10);	    ((uint16_t *)table_r)[i] = j;	}	for (i = -132; i < 256+132; i++) {	    int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);	    ((uint16_t *)table_g)[i] = j << 5;	}	for (i = -232; i < 256+232; i++) {	    int j = table_Y[i+384] >> 3;	    if (order == MPEG2CONVERT_BGR)		j <<= ((bpp==16) ? 11 : 10);	    ((uint16_t *)table_b)[i] = j;	}	break;    case 8:	if (!id)	    return (197 + 2*682 + 256 + 232 + 71) * sizeof (uint8_t);	table_332 = (uint8_t *) (id + 1);	entry_size = sizeof (uint8_t);	table_r = table_332 + 197;	table_g = table_332 + 197 + 682 + 30;	table_b = table_332 + 197 + 2*682;	for (i = -197; i < 256+197+30; i++)	    ((uint8_t *)table_r)[i] = ((table_Y[i+384] * 7 / 255) <<				       (order == MPEG2CONVERT_RGB ? 5 : 0));	for (i = -132; i < 256+132+30; i++)	    ((uint8_t *)table_g)[i-30] = ((table_Y[i+384] * 7 / 255) <<					  (order == MPEG2CONVERT_RGB ? 2 : 3));	for (i = -232; i < 256+232+71; i++)	    ((uint8_t *)table_b)[i] = ((table_Y[i+384] / 85) <<				       (order == MPEG2CONVERT_RGB ? 0 : 6));	break;    }    for (i = 0; i < 256; i++) {	id->table_rV[i] = (((uint8_t *)table_r) +			   entry_size * div_round (crv * (i-128), 76309));	id->table_gU[i] = (((uint8_t *)table_g) +			   entry_size * div_round (cgu * (i-128), 76309));	id->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);	id->table_bU[i] = (((uint8_t *)table_b) +			   entry_size * div_round (cbu * (i-128), 76309));    }    return 0;}static int rgb_internal (mpeg2convert_rgb_order_t order, unsigned int bpp,			 int stage, void * _id, const mpeg2_sequence_t * seq,			 int stride, uint32_t accel, void * arg,			 mpeg2_convert_init_t * result){    convert_rgb_t * id = (convert_rgb_t *) _id;    mpeg2convert_copy_t * copy = (mpeg2convert_copy_t *) 0;    unsigned int id_size = sizeof (convert_rgb_t);    int chroma420 = (seq->chroma_height < seq->height);    int convert420 = 0;    int rgb_stride_min = ((bpp + 7) >> 3) * seq->width;    //noerror;
	//ARCH_X86 is faster than ARCH_X86_
	//#ifdef ARCH_X86_#ifdef ARCH_X86_    if (!copy && (accel & MPEG2_ACCEL_X86_MMXEXT)) {	convert420 = 0;	copy = mpeg2convert_rgb_mmxext (order, bpp, seq);    }    if (!copy && (accel & MPEG2_ACCEL_X86_MMX)) {	convert420 = 0;	copy = mpeg2convert_rgb_mmx (order, bpp, seq);    }#endif#ifdef ARCH_SPARC    if (!copy && (accel & MPEG2_ACCEL_SPARC_VIS)) {	convert420 = chroma420;	copy = mpeg2convert_rgb_vis (order, bpp, seq);    }noerror;#endif    if (!copy) {	int src, dest;	static void (* rgb_c[3][5]) (void *, uint8_t * const *,				     unsigned int) =	    {{rgb_c_24_bgr_420, rgb_c_8_420, rgb_c_16_420,	      rgb_c_24_rgb_420, rgb_c_32_420},	     {rgb_c_24_bgr_422, rgb_c_8_422, rgb_c_16_422,	      rgb_c_24_rgb_422, rgb_c_32_422},	     {rgb_c_24_bgr_444, rgb_c_8_444, rgb_c_16_444,	      rgb_c_24_rgb_444, rgb_c_32_444}};	convert420 = chroma420;	id_size = (sizeof (convert_rgb_c_t) +		   rgb_c_init ((convert_rgb_c_t *) id, order, bpp));	src = ((seq->chroma_width == seq->width) +	       (seq->chroma_height == seq->height));	dest = ((bpp == 24 && order == MPEG2CONVERT_BGR) ? 0 : (bpp + 7) >> 3);	copy = rgb_c[src][dest];    }    result->id_size = id_size;    if (stride < rgb_stride_min)	stride = rgb_stride_min;    if (stage == MPEG2_CONVERT_STRIDE)	return stride;    else if (stage == MPEG2_CONVERT_START) {	id->width = seq->width >> 3;	id->y_stride_frame = seq->width;	id->uv_stride_frame = seq->chroma_width;	id->rgb_stride_frame = stride;	id->rgb_stride_min = rgb_stride_min;	id->chroma420 = chroma420;	id->convert420 = convert420;	result->buf_size[0] = stride * seq->height;	result->buf_size[1] = result->buf_size[2] = 0;	result->start = rgb_start;	result->copy = copy;    }    return 0;}#define DECLARE(func,order,bpp)						\int func (int stage, void * id,						\	  const mpeg2_sequence_t * sequence, int stride,		\	  uint32_t accel, void * arg, mpeg2_convert_init_t * result)	\{									\    return rgb_internal (order, bpp, stage, id, sequence, stride,	\			 accel, arg, result);				\}DECLARE (mpeg2convert_rgb32, MPEG2CONVERT_RGB, 32)DECLARE (mpeg2convert_rgb24, MPEG2CONVERT_RGB, 24)DECLARE (mpeg2convert_rgb16, MPEG2CONVERT_RGB, 16)DECLARE (mpeg2convert_rgb15, MPEG2CONVERT_RGB, 15)DECLARE (mpeg2convert_rgb8, MPEG2CONVERT_RGB, 8)DECLARE (mpeg2convert_bgr32, MPEG2CONVERT_BGR, 32)DECLARE (mpeg2convert_bgr24, MPEG2CONVERT_BGR, 24)DECLARE (mpeg2convert_bgr16, MPEG2CONVERT_BGR, 16)DECLARE (mpeg2convert_bgr15, MPEG2CONVERT_BGR, 15)DECLARE (mpeg2convert_bgr8, MPEG2CONVERT_BGR, 8)mpeg2_convert_t * mpeg2convert_rgb (mpeg2convert_rgb_order_t order,				    unsigned int bpp){    static mpeg2_convert_t * table[5][2] =	{{mpeg2convert_rgb15, mpeg2convert_bgr15},	 {mpeg2convert_rgb8, mpeg2convert_bgr8},	 {mpeg2convert_rgb16, mpeg2convert_bgr16},	 {mpeg2convert_rgb24, mpeg2convert_bgr24},	 {mpeg2convert_rgb32, mpeg2convert_bgr32}};    if (order == MPEG2CONVERT_RGB || order == MPEG2CONVERT_BGR) {	if (bpp == 15)	    return table[0][order == MPEG2CONVERT_BGR];	else if (bpp >= 8 && bpp <= 32 && (bpp & 7) == 0)	    return table[bpp >> 3][order == MPEG2CONVERT_BGR];    }    return (mpeg2_convert_t *) 0;}

⌨️ 快捷键说明

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