mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
5b18a38cd7
--HG-- rename : media/webrtc/trunk/third_party/libyuv/AUTHORS => media/libyuv/AUTHORS rename : media/webrtc/trunk/third_party/libyuv/Android.mk => media/libyuv/Android.mk rename : media/webrtc/trunk/third_party/libyuv/DEPS => media/libyuv/DEPS rename : media/webrtc/trunk/third_party/libyuv/LICENSE => media/libyuv/LICENSE rename : media/webrtc/trunk/third_party/libyuv/LICENSE_THIRD_PARTY => media/libyuv/LICENSE_THIRD_PARTY rename : media/webrtc/trunk/third_party/libyuv/OWNERS => media/libyuv/OWNERS rename : media/webrtc/trunk/third_party/libyuv/PATENTS => media/libyuv/PATENTS rename : media/webrtc/trunk/third_party/libyuv/README.chromium => media/libyuv/README.chromium rename : media/webrtc/trunk/third_party/libyuv/all.gyp => media/libyuv/all.gyp rename : media/webrtc/trunk/third_party/libyuv/codereview.settings => media/libyuv/codereview.settings rename : media/webrtc/trunk/third_party/libyuv/include/libyuv.h => media/libyuv/include/libyuv.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/basic_types.h => media/libyuv/include/libyuv/basic_types.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/compare.h => media/libyuv/include/libyuv/compare.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/convert.h => media/libyuv/include/libyuv/convert.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/convert_argb.h => media/libyuv/include/libyuv/convert_argb.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/convert_from.h => media/libyuv/include/libyuv/convert_from.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/convert_from_argb.h => media/libyuv/include/libyuv/convert_from_argb.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/cpu_id.h => media/libyuv/include/libyuv/cpu_id.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/format_conversion.h => media/libyuv/include/libyuv/format_conversion.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/mjpeg_decoder.h => media/libyuv/include/libyuv/mjpeg_decoder.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/planar_functions.h => media/libyuv/include/libyuv/planar_functions.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/rotate.h => media/libyuv/include/libyuv/rotate.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/rotate_argb.h => media/libyuv/include/libyuv/rotate_argb.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/row.h => media/libyuv/include/libyuv/row.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/scale.h => media/libyuv/include/libyuv/scale.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/scale_argb.h => media/libyuv/include/libyuv/scale_argb.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/scale_row.h => media/libyuv/include/libyuv/scale_row.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/version.h => media/libyuv/include/libyuv/version.h rename : media/webrtc/trunk/third_party/libyuv/include/libyuv/video_common.h => media/libyuv/include/libyuv/video_common.h rename : media/webrtc/trunk/third_party/libyuv/libyuv.gyp => media/libyuv/libyuv.gyp rename : media/webrtc/trunk/third_party/libyuv/libyuv.gypi => media/libyuv/libyuv.gypi rename : media/webrtc/trunk/third_party/libyuv/libyuv_nacl.gyp => media/libyuv/libyuv_nacl.gyp rename : media/webrtc/trunk/third_party/libyuv/libyuv_test.gyp => media/libyuv/libyuv_test.gyp rename : media/webrtc/trunk/third_party/libyuv/linux.mk => media/libyuv/linux.mk rename : media/webrtc/trunk/third_party/libyuv/public.mk => media/libyuv/public.mk rename : media/webrtc/trunk/third_party/libyuv/source/compare.cc => media/libyuv/source/compare.cc rename : media/webrtc/trunk/third_party/libyuv/source/compare_common.cc => media/libyuv/source/compare_common.cc rename : media/webrtc/trunk/third_party/libyuv/source/compare_neon.cc => media/libyuv/source/compare_neon.cc rename : media/webrtc/trunk/third_party/libyuv/source/compare_posix.cc => media/libyuv/source/compare_posix.cc rename : media/webrtc/trunk/third_party/libyuv/source/compare_win.cc => media/libyuv/source/compare_win.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert.cc => media/libyuv/source/convert.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert_argb.cc => media/libyuv/source/convert_argb.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert_from.cc => media/libyuv/source/convert_from.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert_from_argb.cc => media/libyuv/source/convert_from_argb.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert_jpeg.cc => media/libyuv/source/convert_jpeg.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert_to_argb.cc => media/libyuv/source/convert_to_argb.cc rename : media/webrtc/trunk/third_party/libyuv/source/convert_to_i420.cc => media/libyuv/source/convert_to_i420.cc rename : media/webrtc/trunk/third_party/libyuv/source/cpu_id.cc => media/libyuv/source/cpu_id.cc rename : media/webrtc/trunk/third_party/libyuv/source/format_conversion.cc => media/libyuv/source/format_conversion.cc rename : media/webrtc/trunk/third_party/libyuv/source/mjpeg_decoder.cc => media/libyuv/source/mjpeg_decoder.cc rename : media/webrtc/trunk/third_party/libyuv/source/mjpeg_validate.cc => media/libyuv/source/mjpeg_validate.cc rename : media/webrtc/trunk/third_party/libyuv/source/planar_functions.cc => media/libyuv/source/planar_functions.cc rename : media/webrtc/trunk/third_party/libyuv/source/rotate.cc => media/libyuv/source/rotate.cc rename : media/webrtc/trunk/third_party/libyuv/source/rotate_argb.cc => media/libyuv/source/rotate_argb.cc rename : media/webrtc/trunk/third_party/libyuv/source/rotate_mips.cc => media/libyuv/source/rotate_mips.cc rename : media/webrtc/trunk/third_party/libyuv/source/rotate_neon.cc => media/libyuv/source/rotate_neon.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_any.cc => media/libyuv/source/row_any.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_common.cc => media/libyuv/source/row_common.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_mips.cc => media/libyuv/source/row_mips.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_neon.cc => media/libyuv/source/row_neon.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_posix.cc => media/libyuv/source/row_posix.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_win.cc => media/libyuv/source/row_win.cc rename : media/webrtc/trunk/third_party/libyuv/source/row_x86.asm => media/libyuv/source/row_x86.asm rename : media/webrtc/trunk/third_party/libyuv/source/scale.cc => media/libyuv/source/scale.cc rename : media/webrtc/trunk/third_party/libyuv/source/scale_argb.cc => media/libyuv/source/scale_argb.cc rename : media/webrtc/trunk/third_party/libyuv/source/scale_common.cc => media/libyuv/source/scale_common.cc rename : media/webrtc/trunk/third_party/libyuv/source/scale_mips.cc => media/libyuv/source/scale_mips.cc rename : media/webrtc/trunk/third_party/libyuv/source/scale_neon.cc => media/libyuv/source/scale_neon.cc rename : media/webrtc/trunk/third_party/libyuv/source/scale_posix.cc => media/libyuv/source/scale_posix.cc rename : media/webrtc/trunk/third_party/libyuv/source/scale_win.cc => media/libyuv/source/scale_win.cc rename : media/webrtc/trunk/third_party/libyuv/source/video_common.cc => media/libyuv/source/video_common.cc rename : media/webrtc/trunk/third_party/libyuv/source/x86inc.asm => media/libyuv/source/x86inc.asm rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/libyuv_tests.bat => media/libyuv/tools/valgrind-libyuv/libyuv_tests.bat rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/libyuv_tests.py => media/libyuv/tools/valgrind-libyuv/libyuv_tests.py rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/libyuv_tests.sh => media/libyuv/tools/valgrind-libyuv/libyuv_tests.sh rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/memcheck/OWNERS => media/libyuv/tools/valgrind-libyuv/memcheck/OWNERS rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/memcheck/PRESUBMIT.py => media/libyuv/tools/valgrind-libyuv/memcheck/PRESUBMIT.py rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/memcheck/suppressions.txt => media/libyuv/tools/valgrind-libyuv/memcheck/suppressions.txt rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/memcheck/suppressions_mac.txt => media/libyuv/tools/valgrind-libyuv/memcheck/suppressions_mac.txt rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/memcheck/suppressions_win32.txt => media/libyuv/tools/valgrind-libyuv/memcheck/suppressions_win32.txt rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/tsan/OWNERS => media/libyuv/tools/valgrind-libyuv/tsan/OWNERS rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/tsan/PRESUBMIT.py => media/libyuv/tools/valgrind-libyuv/tsan/PRESUBMIT.py rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/tsan/suppressions.txt => media/libyuv/tools/valgrind-libyuv/tsan/suppressions.txt rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/tsan/suppressions_mac.txt => media/libyuv/tools/valgrind-libyuv/tsan/suppressions_mac.txt rename : media/webrtc/trunk/third_party/libyuv/tools/valgrind-libyuv/tsan/suppressions_win32.txt => media/libyuv/tools/valgrind-libyuv/tsan/suppressions_win32.txt rename : media/webrtc/trunk/third_party/libyuv/unit_test/basictypes_test.cc => media/libyuv/unit_test/basictypes_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/compare_test.cc => media/libyuv/unit_test/compare_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/convert_test.cc => media/libyuv/unit_test/convert_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/cpu_test.cc => media/libyuv/unit_test/cpu_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/math_test.cc => media/libyuv/unit_test/math_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/planar_test.cc => media/libyuv/unit_test/planar_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/rotate_argb_test.cc => media/libyuv/unit_test/rotate_argb_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/rotate_test.cc => media/libyuv/unit_test/rotate_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/scale_argb_test.cc => media/libyuv/unit_test/scale_argb_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/scale_test.cc => media/libyuv/unit_test/scale_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/testdata/arm_v7.txt => media/libyuv/unit_test/testdata/arm_v7.txt rename : media/webrtc/trunk/third_party/libyuv/unit_test/testdata/tegra3.txt => media/libyuv/unit_test/testdata/tegra3.txt rename : media/webrtc/trunk/third_party/libyuv/unit_test/unit_test.cc => media/libyuv/unit_test/unit_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/unit_test.h => media/libyuv/unit_test/unit_test.h rename : media/webrtc/trunk/third_party/libyuv/unit_test/version_test.cc => media/libyuv/unit_test/version_test.cc rename : media/webrtc/trunk/third_party/libyuv/unit_test/video_common_test.cc => media/libyuv/unit_test/video_common_test.cc rename : media/webrtc/trunk/third_party/libyuv/util/Makefile => media/libyuv/util/Makefile rename : media/webrtc/trunk/third_party/libyuv/util/compare.cc => media/libyuv/util/compare.cc rename : media/webrtc/trunk/third_party/libyuv/util/convert.cc => media/libyuv/util/convert.cc rename : media/webrtc/trunk/third_party/libyuv/util/cpuid.c => media/libyuv/util/cpuid.c rename : media/webrtc/trunk/third_party/libyuv/util/psnr.cc => media/libyuv/util/psnr.cc rename : media/webrtc/trunk/third_party/libyuv/util/psnr.h => media/libyuv/util/psnr.h rename : media/webrtc/trunk/third_party/libyuv/util/psnr_main.cc => media/libyuv/util/psnr_main.cc rename : media/webrtc/trunk/third_party/libyuv/util/ssim.cc => media/libyuv/util/ssim.cc rename : media/webrtc/trunk/third_party/libyuv/util/ssim.h => media/libyuv/util/ssim.h rename : media/webrtc/trunk/third_party/libyuv/winarm.mk => media/libyuv/winarm.mk
384 lines
14 KiB
C++
384 lines
14 KiB
C++
/*
|
|
* Copyright 2011 The LibYuv Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "libyuv/convert.h"
|
|
|
|
#include "libyuv/format_conversion.h"
|
|
#include "libyuv/video_common.h"
|
|
|
|
#ifdef __cplusplus
|
|
namespace libyuv {
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Convert camera sample to I420 with cropping, rotation and vertical flip.
|
|
// src_width is used for source stride computation
|
|
// src_height is used to compute location of planes, and indicate inversion
|
|
// sample_size is measured in bytes and is the size of the frame.
|
|
// With MJPEG it is the compressed size of the frame.
|
|
LIBYUV_API
|
|
int ConvertToI420(const uint8* sample,
|
|
size_t sample_size,
|
|
uint8* y, int y_stride,
|
|
uint8* u, int u_stride,
|
|
uint8* v, int v_stride,
|
|
int crop_x, int crop_y,
|
|
int src_width, int src_height,
|
|
int crop_width, int crop_height,
|
|
enum RotationMode rotation,
|
|
uint32 fourcc) {
|
|
uint32 format = CanonicalFourCC(fourcc);
|
|
int aligned_src_width = (src_width + 1) & ~1;
|
|
const uint8* src;
|
|
const uint8* src_uv;
|
|
int abs_src_height = (src_height < 0) ? -src_height : src_height;
|
|
int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height;
|
|
int r = 0;
|
|
LIBYUV_BOOL need_buf = (rotation && format != FOURCC_I420 &&
|
|
format != FOURCC_NV12 && format != FOURCC_NV21 &&
|
|
format != FOURCC_YU12 && format != FOURCC_YV12) || y == sample;
|
|
uint8* tmp_y = y;
|
|
uint8* tmp_u = u;
|
|
uint8* tmp_v = v;
|
|
int tmp_y_stride = y_stride;
|
|
int tmp_u_stride = u_stride;
|
|
int tmp_v_stride = v_stride;
|
|
uint8* rotate_buffer = NULL;
|
|
int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height;
|
|
|
|
if (!y || !u || !v || !sample ||
|
|
src_width <= 0 || crop_width <= 0 ||
|
|
src_height == 0 || crop_height == 0) {
|
|
return -1;
|
|
}
|
|
if (src_height < 0) {
|
|
inv_crop_height = -inv_crop_height;
|
|
}
|
|
|
|
// One pass rotation is available for some formats. For the rest, convert
|
|
// to I420 (with optional vertical flipping) into a temporary I420 buffer,
|
|
// and then rotate the I420 to the final destination buffer.
|
|
// For in-place conversion, if destination y is same as source sample,
|
|
// also enable temporary buffer.
|
|
if (need_buf) {
|
|
int y_size = crop_width * abs_crop_height;
|
|
int uv_size = ((crop_width + 1) / 2) * ((abs_crop_height + 1) / 2);
|
|
rotate_buffer = (uint8*)malloc(y_size + uv_size * 2);
|
|
if (!rotate_buffer) {
|
|
return 1; // Out of memory runtime error.
|
|
}
|
|
y = rotate_buffer;
|
|
u = y + y_size;
|
|
v = u + uv_size;
|
|
y_stride = crop_width;
|
|
u_stride = v_stride = ((crop_width + 1) / 2);
|
|
}
|
|
|
|
switch (format) {
|
|
// Single plane formats
|
|
case FOURCC_YUY2:
|
|
src = sample + (aligned_src_width * crop_y + crop_x) * 2;
|
|
r = YUY2ToI420(src, aligned_src_width * 2,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_UYVY:
|
|
src = sample + (aligned_src_width * crop_y + crop_x) * 2;
|
|
r = UYVYToI420(src, aligned_src_width * 2,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_RGBP:
|
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
|
r = RGB565ToI420(src, src_width * 2,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_RGBO:
|
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
|
r = ARGB1555ToI420(src, src_width * 2,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_R444:
|
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
|
r = ARGB4444ToI420(src, src_width * 2,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_24BG:
|
|
src = sample + (src_width * crop_y + crop_x) * 3;
|
|
r = RGB24ToI420(src, src_width * 3,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_RAW:
|
|
src = sample + (src_width * crop_y + crop_x) * 3;
|
|
r = RAWToI420(src, src_width * 3,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_ARGB:
|
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
|
r = ARGBToI420(src, src_width * 4,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_BGRA:
|
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
|
r = BGRAToI420(src, src_width * 4,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_ABGR:
|
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
|
r = ABGRToI420(src, src_width * 4,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_RGBA:
|
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
|
r = RGBAToI420(src, src_width * 4,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
// TODO(fbarchard): Support cropping Bayer by odd numbers
|
|
// by adjusting fourcc.
|
|
case FOURCC_BGGR:
|
|
src = sample + (src_width * crop_y + crop_x);
|
|
r = BayerBGGRToI420(src, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_GBRG:
|
|
src = sample + (src_width * crop_y + crop_x);
|
|
r = BayerGBRGToI420(src, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_GRBG:
|
|
src = sample + (src_width * crop_y + crop_x);
|
|
r = BayerGRBGToI420(src, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_RGGB:
|
|
src = sample + (src_width * crop_y + crop_x);
|
|
r = BayerRGGBToI420(src, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_I400:
|
|
src = sample + src_width * crop_y + crop_x;
|
|
r = I400ToI420(src, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
// Biplanar formats
|
|
case FOURCC_NV12:
|
|
src = sample + (src_width * crop_y + crop_x);
|
|
src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x;
|
|
r = NV12ToI420Rotate(src, src_width,
|
|
src_uv, aligned_src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height, rotation);
|
|
break;
|
|
case FOURCC_NV21:
|
|
src = sample + (src_width * crop_y + crop_x);
|
|
src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x;
|
|
// Call NV12 but with u and v parameters swapped.
|
|
r = NV12ToI420Rotate(src, src_width,
|
|
src_uv, aligned_src_width,
|
|
y, y_stride,
|
|
v, v_stride,
|
|
u, u_stride,
|
|
crop_width, inv_crop_height, rotation);
|
|
break;
|
|
case FOURCC_M420:
|
|
src = sample + (src_width * crop_y) * 12 / 8 + crop_x;
|
|
r = M420ToI420(src, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
case FOURCC_Q420:
|
|
src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
|
|
src_uv = sample + (src_width + aligned_src_width * 2) * crop_y +
|
|
src_width + crop_x * 2;
|
|
r = Q420ToI420(src, src_width * 3,
|
|
src_uv, src_width * 3,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
// Triplanar formats
|
|
case FOURCC_I420:
|
|
case FOURCC_YU12:
|
|
case FOURCC_YV12: {
|
|
const uint8* src_y = sample + (src_width * crop_y + crop_x);
|
|
const uint8* src_u;
|
|
const uint8* src_v;
|
|
int halfwidth = (src_width + 1) / 2;
|
|
int halfheight = (abs_src_height + 1) / 2;
|
|
if (format == FOURCC_YV12) {
|
|
src_v = sample + src_width * abs_src_height +
|
|
(halfwidth * crop_y + crop_x) / 2;
|
|
src_u = sample + src_width * abs_src_height +
|
|
halfwidth * (halfheight + crop_y / 2) + crop_x / 2;
|
|
} else {
|
|
src_u = sample + src_width * abs_src_height +
|
|
(halfwidth * crop_y + crop_x) / 2;
|
|
src_v = sample + src_width * abs_src_height +
|
|
halfwidth * (halfheight + crop_y / 2) + crop_x / 2;
|
|
}
|
|
r = I420Rotate(src_y, src_width,
|
|
src_u, halfwidth,
|
|
src_v, halfwidth,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height, rotation);
|
|
break;
|
|
}
|
|
case FOURCC_I422:
|
|
case FOURCC_YV16: {
|
|
const uint8* src_y = sample + src_width * crop_y + crop_x;
|
|
const uint8* src_u;
|
|
const uint8* src_v;
|
|
int halfwidth = (src_width + 1) / 2;
|
|
if (format == FOURCC_YV16) {
|
|
src_v = sample + src_width * abs_src_height +
|
|
halfwidth * crop_y + crop_x / 2;
|
|
src_u = sample + src_width * abs_src_height +
|
|
halfwidth * (abs_src_height + crop_y) + crop_x / 2;
|
|
} else {
|
|
src_u = sample + src_width * abs_src_height +
|
|
halfwidth * crop_y + crop_x / 2;
|
|
src_v = sample + src_width * abs_src_height +
|
|
halfwidth * (abs_src_height + crop_y) + crop_x / 2;
|
|
}
|
|
r = I422ToI420(src_y, src_width,
|
|
src_u, halfwidth,
|
|
src_v, halfwidth,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
}
|
|
case FOURCC_I444:
|
|
case FOURCC_YV24: {
|
|
const uint8* src_y = sample + src_width * crop_y + crop_x;
|
|
const uint8* src_u;
|
|
const uint8* src_v;
|
|
if (format == FOURCC_YV24) {
|
|
src_v = sample + src_width * (abs_src_height + crop_y) + crop_x;
|
|
src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x;
|
|
} else {
|
|
src_u = sample + src_width * (abs_src_height + crop_y) + crop_x;
|
|
src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x;
|
|
}
|
|
r = I444ToI420(src_y, src_width,
|
|
src_u, src_width,
|
|
src_v, src_width,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
}
|
|
case FOURCC_I411: {
|
|
int quarterwidth = (src_width + 3) / 4;
|
|
const uint8* src_y = sample + src_width * crop_y + crop_x;
|
|
const uint8* src_u = sample + src_width * abs_src_height +
|
|
quarterwidth * crop_y + crop_x / 4;
|
|
const uint8* src_v = sample + src_width * abs_src_height +
|
|
quarterwidth * (abs_src_height + crop_y) + crop_x / 4;
|
|
r = I411ToI420(src_y, src_width,
|
|
src_u, quarterwidth,
|
|
src_v, quarterwidth,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
crop_width, inv_crop_height);
|
|
break;
|
|
}
|
|
#ifdef HAVE_JPEG
|
|
case FOURCC_MJPG:
|
|
r = MJPGToI420(sample, sample_size,
|
|
y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
src_width, abs_src_height, crop_width, inv_crop_height);
|
|
break;
|
|
#endif
|
|
default:
|
|
r = -1; // unknown fourcc - return failure code.
|
|
}
|
|
|
|
if (need_buf) {
|
|
if (!r) {
|
|
r = I420Rotate(y, y_stride,
|
|
u, u_stride,
|
|
v, v_stride,
|
|
tmp_y, tmp_y_stride,
|
|
tmp_u, tmp_u_stride,
|
|
tmp_v, tmp_v_stride,
|
|
crop_width, abs_crop_height, rotation);
|
|
}
|
|
free(rotate_buffer);
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
} // namespace libyuv
|
|
#endif
|