欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

YUV420数据格式详解,以图文形式揭示 - 提示:加强阅读理解,配合图片观看更加易懂

最编程 2024-08-15 16:30:18
...

                         

 

有了上边的理论,我们可以对​​Android​​摄像头采集的YUV420sp数据做很多的转换,下面我写一个旋转90度的​​算法​​。

代码如下:

 




[java] ​​view plain​​ ​​copy​

 


  1. public static void rotateYUV240SP(byte[] src,byte[] des,int width,int height)  
  2.     {  
  3.          
  4.         int wh = width * height;  
  5.         //旋转Y  
  6.         int k = 0;  
  7.         for(int i=0;i<width;i++) {  
  8.             for(int j=0;j<height;j++)   
  9.             {  
  10.                   des[k] = src[width*j + i];              
  11.                   k++;  
  12.             }  
  13.         }  
  14.           
  15.         for(int i=0;i<width;i+=2) {  
  16.             for(int j=0;j<height/2;j++)   
  17.             {     
  18.                   des[k] = src[wh+ width*j + i];      
  19.                   des[k+1]=src[wh + width*j + i+1];  
  20.                   k+=2;  
  21.             }  
  22.         }  
  23.           
  24.           
  25.     }  




[java] view plain copy

 


  1. public static void rotateYUV240SP(byte[] src,byte[] des,int width,int height)  
  2.     {  
  3.          
  4.         int wh = width * height;  
  5.         //旋转Y  
  6.         int k = 0;  
  7.         for(int i=0;i<width;i++) {  
  8.             for(int j=0;j<height;j++)   
  9.             {  
  10.                   des[k] = src[width*j + i];              
  11.                   k++;  
  12.             }  
  13.         }  
  14.           
  15.         for(int i=0;i<width;i+=2) {  
  16.             for(int j=0;j<height/2;j++)   
  17.             {     
  18.                   des[k] = src[wh+ width*j + i];      
  19.                   des[k+1]=src[wh + width*j + i+1];  
  20.                   k+=2;  
  21.             }  
  22.         }  
  23.           
  24.           
  25.     }