void RGBto422 (unsigned char *rgb, unsigned char *yuv, int width, int
height)
{
int r, g, b, Y1, Cb1, Cr1, Y2, Cb2, Cr2, x, y;
for(y = 0; y<height; y++)
for(x = 0; x < width; x += 2) {
r = *rgb++;
g = *rgb++;
b = *rgb++;
Y1 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb1 = (b - Y1) / (2. - 2. * 0.1145);
Cr1 = (r - Y1) / (2. - 2. * 0.2989);
r = *rgb++;
g = *rgb++;
b = *rgb++;
Y2 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb2 = (b - Y2) / (2. - 2. * 0.1145);
Cr2 = (r - Y2) / (2. - 2. * 0.2989);
*yuv++ = (unsigned char) (128 + (Cb1 + Cb2) / 2) * 224./255.+ 16;
*yuv++ = (unsigned char) Y1 * 219./255/ + 16;
*yuv++ = (unsigned char) (128 + (Cr1 + Cr2) / 2) * 224./255.+ 16;
*yuv++ = (unsigned char) Y2 * 219./255/ + 16;
}
}
//a nd for completeness 411:
void RGBto420 (unsigned char *rgb, unsigned char *yuv, int width, int
height)
{
int r, g, b, Y1, Cb1, Cr1, Y2, Cb2, Cr2, Y3, Cb3, Cr3, Y4, Cb4, Cr4,
x, y;
for(y = 0; y<height; y += 2)
for(x = 0; x < width; x += 2) {
r = *rgb;
g = *(rgb+1);
b = *(rgb+2);
Y1 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb1 = (b - Y1) / (2. - 2. * 0.1145);
Cr1 = (r - Y1) / (2. - 2. * 0.2989);
r = *(rgb+3);
g = *(rgb+4);
b = *(rgb+5);
Y2 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb2 = (b - Y2) / (2. - 2. * 0.1145);
Cr2 = (r - Y2) / (2. - 2. * 0.2989);
r = *(rgb+3*width);
g = *(rgb+3*width+1);
b = *(rgb+3*width+2);
Y3 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb3 = (b - Y3) / (2. - 2. * 0.1145);
Cr3 = (r - Y3) / (2. - 2. * 0.2989);
r = *(rgb+3*width+3);
g = *(rgb+3*width+4);
b = *(rgb+3*width+5);
Y4 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb4 = (b - Y4) / (2. - 2. * 0.1145);
Cr4 = (r - Y4) / (2. - 2. * 0.2989);
*yuv++ = (unsigned char) Y1 * 219./255/ + 16;
*yuv++ = (unsigned char) Y2 * 219./255/ + 16;
*yuv++ = (unsigned char) Y3 * 219./255/ + 16;
*yuv++ = (unsigned char) Y4 * 219./255/ + 16;
*yuv++ = (unsigned char) (128 + (Cb1 + Cb2 + Cb3 + Cb4) / 4) * 224./255. + 16;
*yuv++ = (unsigned char) (128 + (Cr1 + Cr2 + Cr3 + Cr4) / 4) * 224./255. + 16;
rgb += 6;
}
}
void RGBto411 (unsigned char *rgb, unsigned char *yuv, int width, int
height)
{
int r, g, b, Y1, Cb1, Cr1, Y2, Cb2, Cr2, Y3, Cb3, Cr3, Y4, Cb4, Cr4,
x, y;
for(y = 0; y<height; y++)
for(x = 0; x < width; x += 4) {
r = *rgb++;
g = *rgb++;
b = *rgb++;
Y1 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb1 = (b - Y1) / (2. - 2. * 0.1145);
Cr1 = (r - Y1) / (2. - 2. * 0.2989);
r = *rgb++;
g = *rgb++;
b = *rgb++;
Y2 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb2 = (b - Y2) / (2. - 2. * 0.1145);
Cr2 = (r - Y2) / (2. - 2. * 0.2989);
r = *rgb++;
g = *rgb++;
b = *rgb++;
Y3 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb3 = (b - Y3) / (2. - 2. * 0.1145);
Cr3 = (r - Y3) / (2. - 2. * 0.2989);
r = *rgb++;
g = *rgb++;
b = *rgb++;
Y4 = 0.2989 * r + 0.5866 * g + 0.1145 * b;
Cb4 = (b - Y4) / (2. - 2. * 0.1145);
Cr4 = (r - Y4) / (2. - 2. * 0.2989);
*yuv++ = (unsigned char) Y1 * 219./255/ + 16;
*yuv++ = (unsigned char) Y2 * 219./255/ + 16;
*yuv++ = (unsigned char) Y3 * 219./255/ + 16;
*yuv++ = (unsigned char) Y4 * 219./255/ + 16;
*yuv++ = (unsigned char) (128 + (Cb1 + Cb2 + Cb3 + Cb4) / 4) * 224./255. + 16;
*yuv++ = (unsigned char) (128 + (Cr1 + Cr2 + Cr3 + Cr4) / 4) * 224./255. + 16;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jpg_function.rar_BLUE
共2个文件
txt:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 158 浏览量
2022-09-19
14:14:08
上传
评论
收藏 883B RAR 举报
温馨提示
// RGB -> YCbCr // Y = Coef. for red*Red+Coef. for green*Green+Coef. for blue*Blue // Cb = (Blue-Y)/(2-2*Coef. for blue) // Cr = (Red-Y)/(2-2*Coef. for red) // YCbCr -> RGB // Red = Cr*(2-2*Coef. for red)+Y // Green = (Y-Coef. for blue*Blue-Coef. for red*Red)/Coef. for green // Blue = Cb*(2-2*Coef. for blue)+Y
资源详情
资源评论
资源推荐
收起资源包目录
jpg_function.rar (2个子文件)
jpg function.txt 4KB
www.pudn.com.txt 218B
共 2 条
- 1
刘良运
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0