YUV转换为RGB

void yuv2rgb_nv21(const unsigned char *src, unsigned char *dst, int src_width, int src_height, int src_step, int dst_width, int dst_height, int dst_step) {
	typedef unsigned char uint8;
	const uint8* pY;
	const uint8* pU;
	const uint8* pV;
	int Y00, Y01, U, V;
	int Y10, Y11;
	int i, j;
	int ruv, guv, buv;
	int R, G, B;

#define SET_COLOR(out, index) \
    {                  \
        out[index++] = B;     \
        out[index++] = G;     \
        out[index++] = R;     \
    }

	int width = dst_width;
	int height = dst_height;
	pY = src;
	{
		pV = src + height*src_step;
		pU = src + (height + height / 4)*src_step;
	}
	for (i = 0; i < height; i += 2, pY += src_step * 2) {
		size_t index = 0;
		size_t index1 = 0;
		uint8* out = dst + i*dst_step;
		uint8* out1 = dst + (i + 1)*dst_step;
		int jV = 0;
		for (j = 0; j < width; j += 2) {
			Y00 = *((pY)+j);
			Y01 = *((pY)+j + 1);
			Y10 = *((pY)+src_step + j);
			Y11 = *((pY)+src_step + j + 1);
			{
				{
					V = *(pV + j);
					U = *(pV + j + 1);
				}
			}

			ruv = ((359 * (V - 128)) >> 8);
			guv = -1 * ((88 * (U - 128) + 183 * (V - 128)) >> 8);
			buv = ((454 * (U - 128)) >> 8);

			R = Y00 + ruv;
			G = Y00 + guv;
			B = Y00 + buv;
			R = (R > 255) ? 255 : ((R < 0) ? 0 : R);
			G = (G > 255) ? 255 : ((G < 0) ? 0 : G);
			B = (B > 255) ? 255 : ((B < 0) ? 0 : B);

			SET_COLOR(out, index)

				R = Y01 + ruv;
			G = Y01 + guv;
			B = Y01 + buv;
			R = (R > 255) ? 255 : ((R < 0) ? 0 : R);
			G = (G > 255) ? 255 : ((G < 0) ? 0 : G);
			B = (B > 255) ? 255 : ((B < 0) ? 0 : B);

			SET_COLOR(out, index)

				ruv = ((359 * (V - 128)) >> 8);
			guv = -1 * ((88 * (U - 128) + 183 * (V - 128)) >> 8);
			buv = ((454 * (U - 128)) >> 8);
			R = Y10 + ruv;
			G = Y10 + guv;
			B = Y10 + buv;
			R = (R > 255) ? 255 : ((R < 0) ? 0 : R);
			G = (G > 255) ? 255 : ((G < 0) ? 0 : G);
			B = (B > 255) ? 255 : ((B < 0) ? 0 : B);

			SET_COLOR(out1, index1)

				R = Y11 + ruv;
			G = Y11 + guv;
			B = Y11 + buv;
			R = (R > 255) ? 255 : ((R < 0) ? 0 : R);
			G = (G > 255) ? 255 : ((G < 0) ? 0 : G);
			B = (B > 255) ? 255 : ((B < 0) ? 0 : B);

			SET_COLOR(out1, index1)
		}
		{
			{
				pV += src_step;
			}
		}
	}
#undef SET_COLOR
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值