|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
package com.frank.live.util; |
|
|
|
|
|
|
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Tool of transforming YUV format |
|
|
|
|
* Created by frank on 2018/7/1. |
|
|
|
@ -43,25 +45,53 @@ public class YUVUtil { |
|
|
|
|
return yuv420sp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void YUV420pRotate90(byte[] dstData, byte[] data, int width, int height) { |
|
|
|
|
public static void YUV420pRotate90(byte[] dst, byte[] src, int width, int height) { |
|
|
|
|
int n = 0; |
|
|
|
|
int wh = width * height; |
|
|
|
|
//y
|
|
|
|
|
int halfWidth = width / 2; |
|
|
|
|
int halfHeight = height / 2; |
|
|
|
|
// y
|
|
|
|
|
for (int j = 0; j < width; j++) { |
|
|
|
|
for(int i = height - 1; i >= 0; i--) { |
|
|
|
|
dstData[n++] = data[width * i + j]; |
|
|
|
|
for (int i = height - 1; i >= 0; i--) { |
|
|
|
|
dst[n++] = src[width * i + j]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// u
|
|
|
|
|
for (int i = 0; i < halfWidth; i++) { |
|
|
|
|
for (int j = 1; j <= halfHeight; j++) { |
|
|
|
|
dst[n++] = src[wh + ((halfHeight - j) * halfWidth + i)]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// v
|
|
|
|
|
for (int i = 0; i < halfWidth; i++) { |
|
|
|
|
for (int j = 1; j <= halfHeight; j++) { |
|
|
|
|
dst[n++] = src[wh + wh / 4 + ((halfHeight - j) * halfWidth + i)]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void YUV420pRotate180(byte[] dst, byte[] src, int width, int height) { |
|
|
|
|
int n = 0; |
|
|
|
|
int halfWidth = width / 2; |
|
|
|
|
int halfHeight = height / 2; |
|
|
|
|
// y
|
|
|
|
|
for (int j = height - 1; j >= 0; j--) { |
|
|
|
|
for (int i = width; i > 0; i--) { |
|
|
|
|
dst[n++] = src[width * j + i - 1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//u
|
|
|
|
|
for (int i = 0; i < width / 2; i++) { |
|
|
|
|
for (int j = 1; j <= height / 2; j++) { |
|
|
|
|
dstData[n++] = data[wh + ((height/2 - j) * (width / 2) + i)]; |
|
|
|
|
// u
|
|
|
|
|
int offset = width * height; |
|
|
|
|
for (int j = halfHeight - 1; j >= 0; j--) { |
|
|
|
|
for (int i = halfWidth; i > 0; i--) { |
|
|
|
|
dst[n++] = src[offset + halfWidth * j + i - 1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//v
|
|
|
|
|
for(int i = 0; i < width / 2; i++) { |
|
|
|
|
for(int j = 1; j <= height / 2; j++) { |
|
|
|
|
dstData[n++] = data[wh + wh / 4 + ((height / 2 - j) * (width / 2) + i)]; |
|
|
|
|
// v
|
|
|
|
|
offset += halfWidth * halfHeight; |
|
|
|
|
for (int j = halfHeight - 1; j >= 0; j--) { |
|
|
|
|
for (int i = halfWidth; i > 0; i--) { |
|
|
|
|
dst[n++] = src[offset + halfWidth * j + i - 1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|