From 6d82347dda1b90d7b2c4ee8c110089c78777c738 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Mon, 13 Jan 2014 18:32:37 +0000 Subject: [PATCH] Conversion functions ported to C89 / Visual C. BUG=303 TESTED=cl /c /TC /Iinclude source/convert_to_argb.cc R=tpsiaki@google.com Review URL: https://webrtc-codereview.appspot.com/6969004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@964 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- source/convert_to_argb.cc | 18 ++++++++++-------- source/convert_to_i420.cc | 29 +++++++++++++++-------------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/README.chromium b/README.chromium index 694bae662..746621e7b 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 962 +Version: 964 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 94eb21f9d..b8916d1f2 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 962 +#define LIBYUV_VERSION 964 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/source/convert_to_argb.cc b/source/convert_to_argb.cc index 210b67c5a..1b228a7b4 100644 --- a/source/convert_to_argb.cc +++ b/source/convert_to_argb.cc @@ -38,19 +38,11 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, enum RotationMode rotation, uint32 fourcc) { uint32 format = CanonicalFourCC(fourcc); - if (crop_argb == NULL || sample == NULL || - src_width <= 0 || crop_width <= 0 || - src_height == 0 || crop_height == 0) { - return -1; - } 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; - if (src_height < 0) { - inv_crop_height = -inv_crop_height; - } int r = 0; // One pass rotation is available for some formats. For the rest, convert @@ -64,6 +56,16 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, int tmp_argb_stride = argb_stride; uint8* rotate_buffer = NULL; int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; + + if (crop_argb == NULL || sample == NULL || + src_width <= 0 || crop_width <= 0 || + src_height == 0 || crop_height == 0) { + return -1; + } + if (src_height < 0) { + inv_crop_height = -inv_crop_height; + } + if (need_buf) { int argb_size = crop_width * abs_crop_height * 4; rotate_buffer = (uint8*)malloc(argb_size); diff --git a/source/convert_to_i420.cc b/source/convert_to_i420.cc index 3420c9dc3..7b194fff7 100644 --- a/source/convert_to_i420.cc +++ b/source/convert_to_i420.cc @@ -37,26 +37,12 @@ int ConvertToI420(const uint8* sample, enum RotationMode rotation, uint32 fourcc) { uint32 format = CanonicalFourCC(fourcc); - if (!y || !u || !v || !sample || - src_width <= 0 || crop_width <= 0 || - src_height == 0 || crop_height == 0) { - return -1; - } 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; - if (src_height < 0) { - inv_crop_height = -inv_crop_height; - } int r = 0; - - // 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. LIBYUV_BOOL need_buf = (rotation && format != FOURCC_I420 && format != FOURCC_NV12 && format != FOURCC_NV21 && format != FOURCC_YU12 && format != FOURCC_YV12) || y == sample; @@ -68,6 +54,21 @@ int ConvertToI420(const uint8* sample, 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);