YUV数据 nv21转nv12 以及YUV数据顺时针旋转90度工具函数

有关YUV

YUV420一共有四种,有时候数据之间需要转换,用到最多的就是nv21转nv12。编码时候相机获取到的数据需要顺时针旋转90度,从而宽长变成长宽。

具体函数实现

nv21转nv12:

static byte[] nv12;

public static byte[] nv21toNV12(byte[] nv21){
    
    
    int size=nv21.length;
    nv12=new byte[size];
    int len=size*2/3;
    System.arraycopy(nv21,0,nv12,0,len);
    int i=len;
  
     while(i<size-1){
    
    
         nv12[i]=nv21[i+1];
         nv12[i+1]=nv21[i];
         i+=2;
     }
   
   return nv12;
}

YUV数据顺时针旋转90度函数:

public static void portraitData2Raw(byte[] data,byte[] output,int width,int height){
    
    
     int y_len=width*height;
     int uvHeight=height>>1;
     int k=0;

     for(int j=0;j<width;j++){
    
    
          for(int i=height-1;i>=0;i--){
    
    
             output[k++]=data[y_len+width*i+j];
             output[k++]=data[y_len+width*i+j+1];
          }
     }
}

写在最后的话

直到现在还是很喜欢宫崎骏笔下的夏天:

蓝天白云, 随风恣意摇摆的红花绿草,还有飘动的裙摆
在这里插入图片描述
翠绿的树木,炫目的阳光,还有叫个不停的知了,彰显着夏天的热烈和活力
在这里插入图片描述

消暑的西瓜,切着熟透了的西瓜超级治愈
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43911199/article/details/127136678