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 // front camera need to flip
if (CAMERA_ID_FRONT.equals(mCameraId)) { if (CAMERA_ID_FRONT.equals(mCameraId)) {
YUVUtil.flipYUV(dstData, width, height, rotation == 90, rotation == 180); YUVUtil.flipYUV(dstData, yuvData, width, height);
} }
if (camera2Listener != null) { if (camera2Listener != null) {
camera2Listener.onPreviewFrame(dstData); camera2Listener.onPreviewFrame(dstData);

@ -126,28 +126,30 @@ public class YUVUtil {
} }
} }
private static void swap(byte[] a, int i, int j) { public static void flipYUV(byte[] dst, byte[] src, int width, int height) {
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) {
if (dst == null || width <= 0 || height <= 0) if (dst == null || width <= 0 || height <= 0)
return; return;
if (flipY) {
for (int i=0; i<height; i++) { int idx = 0;
for (int j=0; j<width/2; j++) { // Y
swap(dst, j, width - j - 1); for (int i = 0; i < width; i++) {
} for (int j = 0; j < height; j++) {
dst[idx++] = src[width - i + (height - j) * width];
} }
} }
if (flipX) { // U
for (int i=0; i<width; i++) { int offset = width * height;
for (int i = 0; i < width / 2; i++) {
for (int j = 0; j < height / 2; j++) { for (int j = 0; j < height / 2; j++) {
swap(dst, j, height - j - 1); dst[idx++] = src[offset + width - i + (height / 2 - j) * width / 2];
} }
} }
// 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