首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

RGB 转 YUV 展示不对

2013-01-08 
RGB 转 YUV 显示不对?我通过LIBJPG获取得到RGB分量了,现在将其存储为YUV420格式,但是不知道为什么显示不对

RGB 转 YUV 显示不对?
我通过LIBJPG获取得到RGB分量了,现在将其存储为YUV420格式,但是不知道为什么显示不对啊,求解 啊~~下面是主要的代码,看看哪里出错了?

tmp = output_buffer + row_width * (cinfo->output_height - 1);
        for (rows = 0; rows < cinfo->output_height; rows++) {
                   jumper = 0;
                for (cols = 0; cols < row_width; cols += 3) {
                        pdata[cols + 2] = (299*tmp[cols + 0]+587*tmp[cols + 1]+114*tmp[cols + 2]);//Red          y
                        Y_DATA[len1++] = pdata[cols + 2];
                        pdata[cols + 1] = (0-147*tmp[cols + 0]-289*tmp[cols + 1]+436*tmp[cols + 2]);//Green ;0       u
                        pdata[cols + 0] = (615*tmp[cols + 0]-515*tmp[cols + 1]-100*tmp[cols + 2]);//Blue ;0   v
                        if((jumper%4)==0){
                         U_DATA[len2++]=pdata[cols + 1];
                         V_DATA[len3++]=pdata[cols + 0];
                         }
                        jumper++;
                      }
                tmp -= row_width;
               // fwrite(pdata, 1, step, output_file);
        }
        fwrite(Y_DATA, len,1,output_file);
        fwrite(U_DATA, len/4,1,output_file);
        fwrite(V_DATA, len/4,1,output_file);

[解决办法]
y对了,u,v是上下2行取平均数,不是一行4个像素取1个。

热点排行
Bad Request.