Feature: flip yuv when it is front camera

pull/221/head
xufuji456 2 years ago
parent 02b0b963c1
commit cf677ae1bd
  1. 4
      Live/src/main/java/com/frank/live/camera/Camera2Helper.java
  2. 25
      Live/src/main/java/com/frank/live/util/YUVUtil.java
  3. 2
      app/src/main/cpp/yuv/yuv_converter.cpp
  4. 2
      app/src/main/cpp/yuv/yuv_converter.h
  5. BIN
      picture/ffmpeg_group.png

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

@ -126,4 +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) {
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);
}
}
}
if (flipX) {
for (int i=0; i<width; i++) {
for (int j=0; j<height/2; j++) {
swap(dst, j, height - j - 1);
}
}
}
}
} }

@ -28,7 +28,7 @@
// U = (-38 * R - 74 * G + 112 * B) >> 8 + 128 // U = (-38 * R - 74 * G + 112 * B) >> 8 + 128
// V = (112 * R - 94 * G - 18 * B) >> 8 + 128 // V = (112 * R - 94 * G - 18 * B) >> 8 + 128
static void rgba_to_yuv420p(int *argb, int8_t *yuv, int width, int height) { static void rgba_to_yuv420p(const int *argb, int8_t *yuv, int width, int height) {
int frameSize = width * height; int frameSize = width * height;
int index = 0; int index = 0;
int yIndex = 0; int yIndex = 0;

@ -7,7 +7,7 @@
#include <cstdint> #include <cstdint>
static void rgba_to_yuv420p(int *argb, int8_t *yuv, int width, int height); static void rgba_to_yuv420p(const int *argb, int8_t *yuv, int width, int height);
static void yuv420p_to_argb(const int8_t *yuv, int *argb, int width, int height); static void yuv420p_to_argb(const int8_t *yuv, int *argb, int width, int height);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 150 KiB

Loading…
Cancel
Save