From 283eb139df3479cf6a6c9d13a5b0ab41cbff3bc0 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Tue, 11 Oct 2011 18:22:34 +0000 Subject: [PATCH] LibYuv: General updates Review URL: http://webrtc-codereview.appspot.com/220004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@17 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- common/common.h | 80 ------------------------------------- include/scale.h | 10 ++++- libyuv.gyp | 16 ++++---- source/format_conversion.cc | 14 ++++--- source/scale.cc | 52 ++++++++++++------------ source/video_common.cc | 2 + 6 files changed, 53 insertions(+), 121 deletions(-) diff --git a/common/common.h b/common/common.h index a4163de15..a81ab6ac6 100644 --- a/common/common.h +++ b/common/common.h @@ -18,99 +18,19 @@ #pragma warning(disable:4355) #endif -////////////////////////////////////////////////////////////////////// -// General Utilities -////////////////////////////////////////////////////////////////////// - -#ifndef UNUSED -#define UNUSED(x) Unused(static_cast(&x)) -#define UNUSED2(x,y) Unused(static_cast(&x)); Unused(static_cast(&y)) -#define UNUSED3(x,y,z) Unused(static_cast(&x)); Unused(static_cast(&y)); Unused(static_cast(&z)) -#define UNUSED4(x,y,z,a) Unused(static_cast(&x)); Unused(static_cast(&y)); Unused(static_cast(&z)); Unused(static_cast(&a)) -#define UNUSED5(x,y,z,a,b) Unused(static_cast(&x)); Unused(static_cast(&y)); Unused(static_cast(&z)); Unused(static_cast(&a)); Unused(static_cast(&b)) -inline void Unused(const void *) { } -#endif // UNUSED - -#ifndef WIN32 -#define strnicmp(x,y,n) strncasecmp(x,y,n) -#define stricmp(x,y) strcasecmp(x,y) - -// TODO(sergeyu): Remove this. std::max should be used everywhere in the code. -// NOMINMAX must be defined where we include . -#define stdmax(x,y) std::max(x,y) -#else -#define stdmax(x,y) libyuv::_max(x,y) -#endif - - -#define ARRAY_SIZE(x) (static_cast((sizeof(x)/sizeof(x[0])))) - -///////////////////////////////////////////////////////////////////////////// -// Assertions -///////////////////////////////////////////////////////////////////////////// - #ifndef ENABLE_DEBUG #define ENABLE_DEBUG _DEBUG #endif // !defined(ENABLE_DEBUG) #if ENABLE_DEBUG -namespace libyuv { - -// Break causes the debugger to stop executing, or the program to abort -void Break(); - -// LogAssert writes information about an assertion to the log -void LogAssert(const char * function, const char * file, int line, - const char * expression); - -inline bool Assert(bool result, const char * function, const char * file, - int line, const char * expression) { - if (!result) { - LogAssert(function, file, line, expression); - Break(); - return false; - } - return true; -} - -} // namespace libyuv - #if defined(_MSC_VER) && _MSC_VER < 1300 #define __FUNCTION__ "" #endif - -#ifndef ASSERT -#define ASSERT(x) (void)libyuv::Assert((x),__FUNCTION__,__FILE__,__LINE__,#x) -#endif - -#ifndef VERIFY -#define VERIFY(x) libyuv::Assert((x),__FUNCTION__,__FILE__,__LINE__,#x) -#endif - #else // !ENABLE_DEBUG -namespace libyuv { - -inline bool libyuv(bool result) { return result; } - -} // namespace libyuv - -#ifndef ASSERT -#define ASSERT(x) (void)0 -#endif - -#ifndef VERIFY -#define VERIFY(x) libyuv::ImplicitCastToBool(x) -#endif - #endif // !ENABLE_DEBUG -#define COMPILE_TIME_ASSERT(expr) char CTA_UNIQUE_NAME[expr] -#define CTA_UNIQUE_NAME CTA_MAKE_NAME(__LINE__) -#define CTA_MAKE_NAME(line) CTA_MAKE_NAME2(line) -#define CTA_MAKE_NAME2(line) constraint_ ## line - #ifdef __GNUC__ // Forces compiler to inline, even against its better judgement. Use wisely. #define FORCE_INLINE __attribute__((always_inline)) diff --git a/include/scale.h b/include/scale.h index c795ff731..57b2c18b9 100644 --- a/include/scale.h +++ b/include/scale.h @@ -1,4 +1,12 @@ - +/* + * 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. + */ #ifndef LIBYUV_INCLUDE_SCALE_H_ diff --git a/libyuv.gyp b/libyuv.gyp index 44a6e116d..dd31c0159 100644 --- a/libyuv.gyp +++ b/libyuv.gyp @@ -46,17 +46,17 @@ 'source/scale.cc', 'source/video_common.cc', ], - 'conditions': [ - ['OS=="win"', { - 'sources': [ - 'source/row_win.cc', - ], - },{ # else + 'conditions': [ + ['OS=="win"', { + 'sources': [ + 'source/row_win.cc', + ], + },{ # else 'sources': [ 'source/row_posix.cc', ], - }], - ] + }], + ] }, ], # targets } diff --git a/source/format_conversion.cc b/source/format_conversion.cc index 7cd352647..a7e1f3c60 100644 --- a/source/format_conversion.cc +++ b/source/format_conversion.cc @@ -11,6 +11,8 @@ #include "format_conversion.h" +#include + #include "common.h" #include "cpu_id.h" #include "video_common.h" @@ -72,7 +74,7 @@ static FORCE_INLINE uint32 FourCcToBayerPixelColourMap(uint32 fourcc) { // four pixels in each 2x2 grid, in left-to-right and top-to-bottom order. switch (fourcc) { default: - ASSERT(false); + assert(false); case FOURCC_RGGB: return FOURCC(RED, GREEN_BETWEEN_RED, GREEN_BETWEEN_BLUE, BLUE); case FOURCC_BGGR: @@ -278,8 +280,8 @@ void BayerRGBToI420(const uint8* src, int src_pitch, uint32 src_fourcc, uint8* u, int u_pitch, uint8* v, int v_pitch, int width, int height) { - ASSERT(width % 2 == 0); - ASSERT(height % 2 == 0); + assert(width % 2 == 0); + assert(height % 2 == 0); uint32 colour_map = FourCcToBayerPixelColourMap(src_fourcc); @@ -434,7 +436,7 @@ void RGB32ToBayerRGB(const uint8* src_rgb, int src_pitch_rgb, uint8* dst_bayer, int dst_pitch_bayer, uint32 dst_fourcc_bayer, int width, int height) { - ASSERT(width % 2 == 0); + assert(width % 2 == 0); void (*ARGBToBayerRow)(const uint8* src_argb, uint8* dst_bayer, uint32 selector, int pix); #if defined(HAS_ARGBTOBAYERROW_SSSE3) @@ -449,7 +451,7 @@ void RGB32ToBayerRGB(const uint8* src_rgb, int src_pitch_rgb, ARGBToBayerRow = ARGBToBayerRow_C; } - ASSERT(src_fourcc_rgb == FOURCC_ARGB); + assert(src_fourcc_rgb == FOURCC_ARGB); int blue_index = 0; int green_index = 1; int red_index = 2; @@ -459,7 +461,7 @@ void RGB32ToBayerRGB(const uint8* src_rgb, int src_pitch_rgb, uint32 index_map[2]; switch (dst_fourcc_bayer) { default: - ASSERT(false); + assert(false); case FOURCC_RGGB: index_map[0] = GenerateSelector(red_index, green_index); index_map[1] = GenerateSelector(green_index, blue_index); diff --git a/source/scale.cc b/source/scale.cc index da4a9c6cc..c7948606f 100644 --- a/source/scale.cc +++ b/source/scale.cc @@ -10,8 +10,8 @@ #include "scale.h" +#include #include -#include "common.h" #include "cpu_id.h" @@ -1923,7 +1923,7 @@ static void ScaleRowDown8_C(const uint8* iptr, int32, static void ScaleRowDown8Int_C(const uint8* iptr, int32 istride, uint8* dst, int32 owidth) { ALIGN16(uint8 irow[kMaxRow12 * 2]); - ASSERT(owidth <= kMaxOutputWidth); + assert(owidth <= kMaxOutputWidth); ScaleRowDown4Int_C(iptr, istride, irow, owidth * 2); ScaleRowDown4Int_C(iptr + istride * 4, istride, irow + kMaxOutputWidth, owidth * 2); @@ -1932,7 +1932,7 @@ static void ScaleRowDown8Int_C(const uint8* iptr, int32 istride, static void ScaleRowDown34_C(const uint8* iptr, int32, uint8* dst, int32 owidth) { - ASSERT((owidth % 3 == 0) && (owidth > 0)); + assert((owidth % 3 == 0) && (owidth > 0)); uint8* dend = dst + owidth; do { dst[0] = iptr[0]; @@ -1946,7 +1946,7 @@ static void ScaleRowDown34_C(const uint8* iptr, int32, // Filter rows 0 and 1 together, 3 : 1 static void ScaleRowDown34_0_Int_C(const uint8* iptr, int32 istride, uint8* d, int32 owidth) { - ASSERT((owidth % 3 == 0) && (owidth > 0)); + assert((owidth % 3 == 0) && (owidth > 0)); uint8* dend = d + owidth; const uint8* s = iptr; const uint8* t = iptr + istride; @@ -1969,7 +1969,7 @@ static void ScaleRowDown34_0_Int_C(const uint8* iptr, int32 istride, // Filter rows 1 and 2 together, 1 : 1 static void ScaleRowDown34_1_Int_C(const uint8* iptr, int32 istride, uint8* d, int32 owidth) { - ASSERT((owidth % 3 == 0) && (owidth > 0)); + assert((owidth % 3 == 0) && (owidth > 0)); uint8* dend = d + owidth; const uint8* s = iptr; const uint8* t = iptr + istride; @@ -2069,7 +2069,7 @@ static void ScaleRowDown34_1_Int_SSE2(const uint8* iptr, int32 istride, static void ScaleRowDown38_C(const uint8* iptr, int32, uint8* dst, int32 owidth) { - ASSERT(owidth % 3 == 0); + assert(owidth % 3 == 0); for (int x = 0; x < owidth; x += 3) { dst[0] = iptr[0]; dst[1] = iptr[3]; @@ -2082,7 +2082,7 @@ static void ScaleRowDown38_C(const uint8* iptr, int32, // 8x3 -> 3x1 static void ScaleRowDown38_3_Int_C(const uint8* iptr, int32 istride, uint8* optr, int32 owidth) { - ASSERT((owidth % 3 == 0) && (owidth > 0)); + assert((owidth % 3 == 0) && (owidth > 0)); for (int i = 0; i < owidth; i+=3) { optr[0] = (iptr[0] + iptr[1] + iptr[2] + iptr[istride + 0] + iptr[istride + 1] + iptr[istride + 2] + @@ -2104,7 +2104,7 @@ static void ScaleRowDown38_3_Int_C(const uint8* iptr, int32 istride, // 8x2 -> 3x1 static void ScaleRowDown38_2_Int_C(const uint8* iptr, int32 istride, uint8* optr, int32 owidth) { - ASSERT((owidth % 3 == 0) && (owidth > 0)); + assert((owidth % 3 == 0) && (owidth > 0)); for (int i = 0; i < owidth; i+=3) { optr[0] = (iptr[0] + iptr[1] + iptr[2] + iptr[istride + 0] + iptr[istride + 1] + iptr[istride + 2]) * @@ -2124,7 +2124,7 @@ static void ScaleRowDown38_2_Int_C(const uint8* iptr, int32 istride, static void ScaleFilterRows_C(uint8* optr, const uint8* iptr0, int32 istride, int owidth, int source_y_fraction) { - ASSERT(owidth > 0); + assert(owidth > 0); int y1_fraction = source_y_fraction; int y0_fraction = 256 - y1_fraction; const uint8* iptr1 = iptr0 + istride; @@ -2147,8 +2147,8 @@ static void ScaleFilterRows_C(uint8* optr, void ScaleAddRows_C(const uint8* iptr, int32 istride, uint16* orow, int32 iwidth, int32 iheight) { - ASSERT(iwidth > 0); - ASSERT(iheight > 0); + assert(iwidth > 0); + assert(iheight > 0); for (int x = 0; x < iwidth; ++x) { const uint8* s = iptr + x; int sum = 0; @@ -2172,8 +2172,8 @@ static void ScalePlaneDown2(int32 iwidth, int32 iheight, int32 istride, int32 ostride, const uint8 *iptr, uint8 *optr, bool interpolate) { - ASSERT(iwidth % 2 == 0); - ASSERT(iheight % 2 == 0); + assert(iwidth % 2 == 0); + assert(iheight % 2 == 0); void (*ScaleRowDown2)(const uint8* iptr, int32 istride, uint8* orow, int32 owidth); @@ -2212,8 +2212,8 @@ static void ScalePlaneDown4(int32 iwidth, int32 iheight, int32 istride, int32 ostride, const uint8 *iptr, uint8 *optr, bool interpolate) { - ASSERT(iwidth % 4 == 0); - ASSERT(iheight % 4 == 0); + assert(iwidth % 4 == 0); + assert(iheight % 4 == 0); void (*ScaleRowDown4)(const uint8* iptr, int32 istride, uint8* orow, int32 owidth); @@ -2247,8 +2247,8 @@ static void ScalePlaneDown8(int32 iwidth, int32 iheight, int32 istride, int32 ostride, const uint8 *iptr, uint8 *optr, bool interpolate) { - ASSERT(iwidth % 8 == 0); - ASSERT(iheight % 8 == 0); + assert(iwidth % 8 == 0); + assert(iheight % 8 == 0); void (*ScaleRowDown8)(const uint8* iptr, int32 istride, uint8* orow, int32 owidth); #if defined(HAS_SCALEROWDOWN8_SSE2) @@ -2281,7 +2281,7 @@ static void ScalePlaneDown34(int32 iwidth, int32 iheight, int32 istride, int32 ostride, const uint8* iptr, uint8* optr, bool interpolate) { - ASSERT(owidth % 3 == 0); + assert(owidth % 3 == 0); void (*ScaleRowDown34_0)(const uint8* iptr, int32 istride, uint8* orow, int32 owidth); void (*ScaleRowDown34_1)(const uint8* iptr, int32 istride, @@ -2362,7 +2362,7 @@ static void ScalePlaneDown38(int32 iwidth, int32 iheight, int32 istride, int32 ostride, const uint8* iptr, uint8* optr, bool interpolate) { - ASSERT(owidth % 3 == 0); + assert(owidth % 3 == 0); void (*ScaleRowDown38_3)(const uint8* iptr, int32 istride, uint8* orow, int32 owidth); void (*ScaleRowDown38_2)(const uint8* iptr, int32 istride, @@ -2411,8 +2411,8 @@ static void ScalePlaneDown38(int32 iwidth, int32 iheight, inline static uint32 SumBox(int32 iboxwidth, int32 iboxheight, int32 istride, const uint8 *iptr) { - ASSERT(iboxwidth > 0); - ASSERT(iboxheight > 0); + assert(iboxwidth > 0); + assert(iboxheight > 0); uint32 sum = 0u; for (int y = 0; y < iboxheight; ++y) { for (int x = 0; x < iboxwidth; ++x) { @@ -2437,7 +2437,7 @@ static void ScalePlaneBoxRow(int32 owidth, int32 boxheight, } inline static uint32 SumPixels(int32 iboxwidth, const uint16 *iptr) { - ASSERT(iboxwidth > 0); + assert(iboxwidth > 0); uint32 sum = 0u; for (int x = 0; x < iboxwidth; ++x) { sum += iptr[x]; @@ -2485,8 +2485,8 @@ static void ScalePlaneBox(int32 iwidth, int32 iheight, int32 owidth, int32 oheight, int32 istride, int32 ostride, const uint8 *iptr, uint8 *optr) { - ASSERT(owidth > 0); - ASSERT(oheight > 0); + assert(owidth > 0); + assert(oheight > 0); int dy = (iheight << 16) / oheight; int dx = (iwidth << 16) / owidth; if ((iwidth % 16 != 0) || (iwidth > kMaxInputWidth) || @@ -2592,8 +2592,8 @@ static void ScalePlaneBilinear(int32 iwidth, int32 iheight, int32 owidth, int32 oheight, int32 istride, int32 ostride, const uint8 *iptr, uint8 *optr) { - ASSERT(owidth > 0); - ASSERT(oheight > 0); + assert(owidth > 0); + assert(oheight > 0); int dy = (iheight << 16) / oheight; int dx = (iwidth << 16) / owidth; if ((iwidth % 8 != 0) || (iwidth > kMaxInputWidth)) { diff --git a/source/video_common.cc b/source/video_common.cc index 5152781e1..8242316df 100644 --- a/source/video_common.cc +++ b/source/video_common.cc @@ -17,6 +17,8 @@ namespace libyuv { +#define ARRAY_SIZE(x) (static_cast((sizeof(x)/sizeof(x[0])))) + struct FourCCAliasEntry { uint32 alias; uint32 canonical;