I420转RGB

 

http://blog.csdn.net/huiguixian/article/details/17288909

 

  1. public class YuvToRGB {  
  2.     private static int R = 0;  
  3.     private static int G = 1;  
  4.     private static int B = 2;  
  5.     public static int[] I420ToRGB(byte[] src, int width, int height){  
  6.         int numOfPixel = width * height;  
  7.         int positionOfV = numOfPixel;  
  8.         int positionOfU = numOfPixel/4 + numOfPixel;  
  9.         int[] rgb = new int[numOfPixel*3];  
  10.   
  11.         for(int i=0; i<height; i++){  
  12.             int startY = i*width;  
  13.             int step = (i/2)*(width/2);  
  14.             int startV = positionOfV + step;  
  15.             int startU = positionOfU + step;  
  16.             for(int j = 0; j < width; j++){  
  17.                 int Y = startY + j;  
  18.                 int V = startV + j/2;  
  19.                 int U = startU + j/2;  
  20.                 int index = Y*3;          
  21.                 rgb[index+B] = (int)((src[Y]&0xff) + 1.4075 * ((src[V]&0xff)-128));  
  22.                 rgb[index+G] = (int)((src[Y]&0xff) - 0.3455 * ((src[U]&0xff)-128) - 0.7169*((src[V]&0xff)-128));  
  23.                 rgb[index+R] = (int)((src[Y]&0xff) + 1.779 * ((src[U]&0xff)-128));  
  24.             }  
  25.         }  
  26.           
  27.         return rgb;  
  28.     }  
  29. }  

posted on 2017-09-27 19:47  蚂蚁flow  阅读(1091)  评论(0编辑  收藏  举报

导航