From b744e3734ae6f6138f57fd012bc3e20f41b2ec7a Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Thu, 10 Nov 2011 18:44:37 +0000 Subject: [PATCH] libyuv: Updating general functions: 1. Deleting Crop and CropPad functions 2. Moving I420Mirror to planar functions 3. deleting general.h and general.cc Review URL: http://webrtc-codereview.appspot.com/269008 git-svn-id: http://libyuv.googlecode.com/svn/trunk@67 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- include/libyuv.h | 1 - include/libyuv/general.h | 47 ----- include/libyuv/planar_functions.h | 9 + libyuv.gyp | 2 - source/general.cc | 286 ------------------------------ source/planar_functions.cc | 57 ++++++ 6 files changed, 66 insertions(+), 336 deletions(-) delete mode 100644 include/libyuv/general.h delete mode 100644 source/general.cc diff --git a/include/libyuv.h b/include/libyuv.h index 5a30e2d05..9b2fa80ac 100644 --- a/include/libyuv.h +++ b/include/libyuv.h @@ -16,7 +16,6 @@ #include "libyuv/convert.h" #include "libyuv/cpu_id.h" #include "libyuv/format_conversion.h" -#include "libyuv/general.h" #include "libyuv/planar_functions.h" #include "libyuv/rotate.h" #include "libyuv/scale.h" diff --git a/include/libyuv/general.h b/include/libyuv/general.h deleted file mode 100644 index 58943c866..000000000 --- a/include/libyuv/general.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 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. - */ - - -/* - * General operations on YUV images. - */ - -#ifndef INCLUDE_LIBYUV_GENERAL_H_ -#define INCLUDE_LIBYUV_GENERAL_H_ - -#include "libyuv/basic_types.h" - -namespace libyuv { - -// I420 mirror -int -I420Mirror(const uint8* src_yplane, int src_ystride, - const uint8* src_uplane, int src_ustride, - const uint8* src_vplane, int src_vstride, - uint8* dst_yplane, int dst_ystride, - uint8* dst_uplane, int dst_ustride, - uint8* dst_vplane, int dst_vstride, - int width, int height); - -// Crop/Pad I420 frame to match required dimensions. -int -I420CropPad(const uint8* src_frame, int src_width, - int src_height, uint8* dst_frame, - int dst_width, int dst_height); - -// I420 Crop - crop a rectangle from image -int -I420Crop(uint8* frame, - int src_width, int src_height, - int dst_width, int dst_height); - -} // namespace libyuv - -#endif // INCLUDE_LIBYUV_GENERAL_H_ diff --git a/include/libyuv/planar_functions.h b/include/libyuv/planar_functions.h index 9c0a10a33..73bdf8c42 100644 --- a/include/libyuv/planar_functions.h +++ b/include/libyuv/planar_functions.h @@ -25,6 +25,15 @@ int I420Copy(const uint8* src_y, int src_stride_y, uint8* dst_v, int dst_stride_v, int width, int height); +// I420 mirror +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); + // Draw a rectangle into I420 int I420Rect(uint8* dst_y, int dst_stride_y, uint8* dst_u, int dst_stride_u, diff --git a/libyuv.gyp b/libyuv.gyp index c6b674962..93d3eef87 100644 --- a/libyuv.gyp +++ b/libyuv.gyp @@ -25,7 +25,6 @@ # includes 'include/libyuv/basic_types.h', 'include/libyuv/convert.h', - 'include/libyuv/general.h', 'include/libyuv/scale.h', 'include/libyuv/planar_functions.h', @@ -41,7 +40,6 @@ 'source/convert.cc', 'source/cpu_id.cc', 'source/format_conversion.cc', - 'source/general.cc', 'source/planar_functions.cc', 'source/rotate.cc', 'source/row_table.cc', diff --git a/source/general.cc b/source/general.cc deleted file mode 100644 index 162a0259a..000000000 --- a/source/general.cc +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 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 "libyuv/general.h" - -#include // memcpy(), memset() - -#include "libyuv/planar_functions.h" - -namespace libyuv { - -int I420Mirror(const uint8* src_yplane, int src_ystride, - const uint8* src_uplane, int src_ustride, - const uint8* src_vplane, int src_vstride, - uint8* dst_yplane, int dst_ystride, - uint8* dst_uplane, int dst_ustride, - uint8* dst_vplane, int dst_vstride, - int width, int height) { - if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL || - dst_yplane == NULL || dst_uplane == NULL || dst_vplane == NULL) - return -1; - - // Only accepts positive dimensions - if (height < 0 || width < 0 || dst_ystride < 0 || dst_ustride < 0 || - dst_vstride < 0) - return -1; - - int indO = 0; - int indS = 0; - int wind, hind; - uint8 tmp_val; - // Will swap two values per iteration - const int half_width = (width + 1) >> 1; - - // Y - for (wind = 0; wind < half_width; ++wind) { - for (hind = 0; hind < height; ++hind) { - indO = hind * src_ystride + wind; - indS = hind * dst_ystride + (width - wind - 1); - tmp_val = src_yplane[indO]; - dst_yplane[indO] = src_yplane[indS]; - dst_yplane[indS] = tmp_val; - } - } - - const int half_height = (height + 1) >> 1; - const int half_uv_width = (width + 1) >> 1; - - for (wind = 0; wind < half_uv_width; ++wind) { - for (hind = 0; hind < half_height; ++hind) { - // U - indO = hind * dst_ustride + wind; - indS = hind * dst_ustride + (half_uv_width - wind - 1); - tmp_val = src_uplane[indO]; - dst_uplane[indO] = src_uplane[indS]; - dst_uplane[indS] = tmp_val; - // V - indO = hind * dst_vstride + wind; - indS = hind * dst_vstride + (half_uv_width - wind - 1); - tmp_val = src_vplane[indO]; - dst_vplane[indO] = src_vplane[indS]; - dst_vplane[indS] = tmp_val; - } - } - return 0; -} - -// Make a center cut -int I420Crop(uint8* frame, - int src_width, int src_height, - int dst_width, int dst_height) -{ - if (frame == NULL) - return -1; - - if (src_width == dst_width && src_height == dst_height) { - // Nothing to do - return 0; - } - if (dst_width > src_width || dst_height > src_height) { - // error - return -1; - } - int i = 0; - int m = 0; - int loop = 0; - int half_dst_width = dst_width / 2; - int halfdst_height = dst_height / 2; - int halfsrc_width = src_width / 2; - int half_dst_height= src_height / 2; - int crop_height = ( src_height - dst_height ) / 2; - int crop_width = ( src_width - dst_width ) / 2; - - for (i = src_width * crop_height + crop_width; loop < dst_height ; - loop++, i += src_width) { - memcpy(&frame[m],&frame[i],dst_width); - m += dst_width; - } - i = src_width * src_height; // ilum - loop = 0; - for ( i += (halfsrc_width * crop_height / 2 + crop_width / 2); - loop < halfdst_height; loop++,i += halfsrc_width) { - memcpy(&frame[m],&frame[i],half_dst_width); - m += half_dst_width; - } - loop = 0; - i = src_width * src_height + half_dst_height * halfsrc_width; // ilum + Cr - for ( i += (halfsrc_width * crop_height / 2 + crop_width / 2); - loop < halfdst_height; loop++, i += halfsrc_width) { - memcpy(&frame[m],&frame[i],half_dst_width); - m += half_dst_width; - } - return 0; -} - - -int I420CropPad(const uint8* src_frame, int src_width, - int src_height, uint8* dst_frame, - int dst_width, int dst_height) -{ - if (src_width < 1 || dst_width < 1 || src_height < 1 || dst_height < 1) { - return -1; - } - if (src_width == dst_width && src_height == dst_height) { - memcpy(dst_frame, src_frame, 3 * dst_width * (dst_height >> 1)); - } else { - if (src_height < dst_height) { - // pad height - int pad_height = dst_height - src_height; - int i = 0; - int pad_width = 0; - int crop_width = 0; - int width = src_width; - if (src_width < dst_width) { - // pad width - pad_width = dst_width - src_width; - } else { - // cut width - crop_width = src_width - dst_width; - width = dst_width; - } - if (pad_height) { - memset(dst_frame, 0, dst_width * (pad_height >> 1)); - dst_frame += dst_width * (pad_height >> 1); - } - for (i = 0; i < src_height;i++) { - if (pad_width) { - memset(dst_frame, 0, pad_width / 2); - dst_frame += pad_width / 2; - } - src_frame += crop_width >> 1; // in case we have a cut - memcpy(dst_frame,src_frame ,width); - src_frame += crop_width >> 1; - dst_frame += width; - src_frame += width; - if (pad_width) { - memset(dst_frame, 0, pad_width / 2); - dst_frame += pad_width / 2; - } - } - if (pad_height) { - memset(dst_frame, 0, dst_width * (pad_height >> 1)); - dst_frame += dst_width * (pad_height >> 1); - } - if (pad_height) { - memset(dst_frame, 127, (dst_width >> 2) * (pad_height >> 1)); - dst_frame += (dst_width >> 2) * (pad_height >> 1); - } - for (i = 0; i < (src_height >> 1); i++) { - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - src_frame += crop_width >> 2; // in case we have a cut - memcpy(dst_frame, src_frame,width >> 1); - src_frame += crop_width >> 2; - dst_frame += width >> 1; - src_frame += width >> 1; - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - } - if (pad_height) { - memset(dst_frame, 127, (dst_width >> 1) * (pad_height >> 1)); - dst_frame += (dst_width >> 1) * (pad_height >> 1); - } - for (i = 0; i < (src_height >> 1); i++) { - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - src_frame += crop_width >> 2; // in case we have a cut - memcpy(dst_frame, src_frame,width >> 1); - src_frame += crop_width >> 2; - dst_frame += width >> 1; - src_frame += width >> 1; - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - } - if (pad_height) { - memset(dst_frame, 127, (dst_width >> 2) * (pad_height >> 1)); - dst_frame += (dst_width >> 2) * (pad_height >> 1); - } - } else { - // cut height - int i = 0; - int pad_width = 0; - int crop_width = 0; - int width = src_width; - - if (src_width < dst_width) { - // pad width - pad_width = dst_width - src_width; - } else { - // cut width - crop_width = src_width - dst_width; - width = dst_width; - } - int diff_height = src_height - dst_height; - src_frame += src_width * (diff_height >> 1); // skip top I - - for (i = 0; i < dst_height; i++) { - if (pad_width) { - memset(dst_frame, 0, pad_width / 2); - dst_frame += pad_width / 2; - } - src_frame += crop_width >> 1; // in case we have a cut - memcpy(dst_frame,src_frame ,width); - src_frame += crop_width >> 1; - dst_frame += width; - src_frame += width; - if (pad_width) { - memset(dst_frame, 0, pad_width / 2); - dst_frame += pad_width / 2; - } - } - src_frame += src_width * (diff_height >> 1); // skip end I - src_frame += (src_width >> 2) * (diff_height >> 1); // skip top of Cr - for (i = 0; i < (dst_height >> 1); i++) { - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - src_frame += crop_width >> 2; // in case we have a cut - memcpy(dst_frame, src_frame,width >> 1); - src_frame += crop_width >> 2; - dst_frame += width >> 1; - src_frame += width >> 1; - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - } - src_frame += (src_width >> 2) * (diff_height >> 1); // skip end of Cr - src_frame += (src_width >> 2) * (diff_height >> 1); // skip top of Cb - for (i = 0; i < (dst_height >> 1); i++) { - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - src_frame += crop_width >> 2; // in case we have a cut - memcpy(dst_frame, src_frame, width >> 1); - src_frame += crop_width >> 2; - dst_frame += width >> 1; - src_frame += width >> 1; - if (pad_width) { - memset(dst_frame, 127, pad_width >> 2); - dst_frame += pad_width >> 2; - } - } - } - } - return 0; -} - -} // namespace libyuv diff --git a/source/planar_functions.cc b/source/planar_functions.cc index b5cc8b36a..cd2e19f01 100644 --- a/source/planar_functions.cc +++ b/source/planar_functions.cc @@ -182,6 +182,63 @@ int I420Copy(const uint8* src_y, int src_stride_y, return 0; } +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) { + if (src_y == NULL || src_u == NULL || src_v == NULL || + dst_y == NULL || dst_u == NULL || dst_v == NULL) + return -1; + + // Only accepts positive dimensions + if (height < 0 || width < 0 || src_stride_y < 0 || src_stride_u < 0 || + src_stride_v < 0 || dst_stride_y < 0 || dst_stride_u < 0 || + dst_stride_v < 0) + return -1; + + int indO = 0; + int indS = 0; + int wind, hind; + uint8 tmp_val; + // Will swap two values per iteration + const int half_width = (width + 1) >> 1; + + // Y + for (wind = 0; wind < half_width; ++wind) { + for (hind = 0; hind < height; ++hind) { + indO = hind * src_stride_y + wind; + indS = hind * dst_stride_y + (width - wind - 1); + tmp_val = src_y[indO]; + dst_y[indO] = src_y[indS]; + dst_y[indS] = tmp_val; + } + } + + const int half_height = (height + 1) >> 1; + const int half_uv_width = (width + 1) >> 1; + + for (wind = 0; wind < half_uv_width; ++wind) { + for (hind = 0; hind < half_height; ++hind) { + // U + indO = hind * dst_stride_u + wind; + indS = hind * dst_stride_u + (half_uv_width - wind - 1); + tmp_val = src_u[indO]; + dst_u[indO] = src_u[indS]; + dst_u[indS] = tmp_val; + // V + indO = hind * dst_stride_v + wind; + indS = hind * dst_stride_v + (half_uv_width - wind - 1); + tmp_val = src_v[indO]; + dst_v[indO] = src_v[indS]; + dst_v[indS] = tmp_val; + } + } + return 0; +} + // SetRows32 writes 'count' bytes using a 32 bit value repeated #if defined(__ARM_NEON__) && !defined(COVERAGE_ENABLED)