Feature: flip yuv data of front Camera

pull/221/head
xufuji456 2 years ago
parent f2f3bd5bb8
commit 4c9d1aa0fa
  1. 2
      Live/src/main/java/com/frank/live/camera/Camera2Helper.java
  2. 32
      Live/src/main/java/com/frank/live/util/YUVUtil.java

@ -595,7 +595,7 @@ public class Camera2Helper {
}
// front camera need to flip
if (CAMERA_ID_FRONT.equals(mCameraId)) {
YUVUtil.flipYUV(dstData, width, height, rotation == 90, rotation == 180);
YUVUtil.flipYUV(dstData, yuvData, width, height);
}
if (camera2Listener != null) {
camera2Listener.onPreviewFrame(dstData);

@ -126,27 +126,29 @@ public class YUVUtil {
}
}
private static void swap(byte[] a, int i, int j) {
byte temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void flipYUV(byte[] dst, int width, int height, boolean flipX, boolean flipY) {
public static void flipYUV(byte[] dst, byte[] src, int width, int height) {
if (dst == null || width <= 0 || height <= 0)
return;
if (flipY) {
for (int i=0; i<height; i++) {
for (int j=0; j<width/2; j++) {
swap(dst, j, width - j - 1);
int idx = 0;
// Y
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
dst[idx++] = src[width - i + (height - j) * width];
}
}
// U
int offset = width * height;
for (int i = 0; i < width / 2; i++) {
for (int j = 0; j < height / 2; j++) {
dst[idx++] = src[offset + width - i + (height / 2 - j) * width / 2];
}
if (flipX) {
for (int i=0; i<width; i++) {
for (int j=0; j<height/2; j++) {
swap(dst, j, height - j - 1);
}
// V
offset += width * height / 4;
for (int i = 0; i < width / 2; i++) {
for (int j = 0; j < height / 2; j++) {
dst[idx++] = src[offset + width - i + (height / 2 - j) * width / 2];
}
}
}

Loading…
Cancel
Save