c - 如何通过 libyuv::I420Scale 为 android 前置摄像头实现 Mirror?

标签 c android-camera webrtc front-camera libyuv

以下文字来自libyuv#rotation

Mirror - Horizontal Flip Mirror functions for horizontally flipping an image, which can be useful for 'self view' of a webcam.

int I420Mirror(const uint8* src_y, int src_stride_y,
           const uint8* src_u, int src_stride_u,
           const uint8* src_v, int src_stride_v,
           uint8* dst_y, int dst_stride_y,
           uint8* dst_u, int dst_stride_u,
           uint8* dst_v, int dst_stride_v,
           int width, int height);

Mirror functionality can also be achieved with the I420Scale and ARGBScale functions by passing negative width and/or height.

但是,我看到了 I420Scale 的实现像这样:

LIBYUV_API
int I420Scale(const uint8* src_y, int src_stride_y,
          const uint8* src_u, int src_stride_u,
          const uint8* src_v, int src_stride_v,
          int src_width, int src_height,
          uint8* dst_y, int dst_stride_y,
          uint8* dst_u, int dst_stride_u,
          uint8* dst_v, int dst_stride_v,
          int dst_width, int dst_height,
          enum FilterMode filtering) {
  int src_halfwidth = SUBSAMPLE(src_width, 1, 1);
  int src_halfheight = SUBSAMPLE(src_height, 1, 1);
  int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1);
  int dst_halfheight = SUBSAMPLE(dst_height, 1, 1);
  if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || 
  src_width > 32768 || src_height > 32768 ||
  !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { 
    return -1;
  }

  ScalePlane(src_y, src_stride_y, src_width, src_height,
         dst_y, dst_stride_y, dst_width, dst_height,
         filtering);
  ScalePlane(src_u, src_stride_u, src_halfwidth, src_halfheight,
         dst_u, dst_stride_u, dst_halfwidth, dst_halfheight,
         filtering);
  ScalePlane(src_v, src_stride_v, src_halfwidth, src_halfheight,
         dst_v, dst_stride_v, dst_halfwidth, dst_halfheight,
         filtering);
  return 0;
}

如果dst_width <= 0 || dst_height <= 0 , 然后 return -1 ;

这是关于 Mirror functionality can also be achieved with the I420Scale by passing negative width and/or height 的笑话吗? ?

I420Scale如何实现镜像功能?

最佳答案

在我按照以下方式完成后,它对我来说工作正常:

if (facing == 1) {
    // front camera should be mirror
    src_w = - src_w;
}
if ((ret = I420Scale(
            pTempY, src_stride_y,
            pTempU, src_stride_u,
            pTempV, src_stride_v,
            src_w, src_h,
            pDstY, dst_width,
            pDstU, (dst_width + 1) >> 1,
            pDstV, (dst_width + 1) >> 1,
            dst_w, dst_h,
            kFilterNone
        ))) {}

关于c - 如何通过 libyuv::I420Scale 为 android 前置摄像头实现 Mirror?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33342214/

相关文章:

C:避免链表中的垃圾值

webrtc - WebRTC App 的带宽和质量控制

Android:无法获取相机拍摄的原始照片(只能读取压缩照片)

Android——使用sanselan手动更新图片Exif数据

使用 OpenGL 处理 Android 相机帧

android - Android 中的 WebRTC

swift - 类 RTCCVPixelBuffer 在两者中都实现,将使用两者之一。哪个是未定义的

java - registerNatives() 方法有什么作用?

c - 如何清理使用 read() 填充的缓冲区并继续读取同一缓冲区?

c++ - C 或 C++ 中的边界检查是否昂贵?