Commit 283eb139 authored by mikhal@webrtc.org's avatar mikhal@webrtc.org

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
parent 24fba05d
......@@ -18,99 +18,19 @@
#pragma warning(disable:4355)
#endif
//////////////////////////////////////////////////////////////////////
// General Utilities
//////////////////////////////////////////////////////////////////////
#ifndef UNUSED
#define UNUSED(x) Unused(static_cast<const void *>(&x))
#define UNUSED2(x,y) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y))
#define UNUSED3(x,y,z) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z))
#define UNUSED4(x,y,z,a) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z)); Unused(static_cast<const void *>(&a))
#define UNUSED5(x,y,z,a,b) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z)); Unused(static_cast<const void *>(&a)); Unused(static_cast<const void *>(&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 <windows.h>.
#define stdmax(x,y) std::max(x,y)
#else
#define stdmax(x,y) libyuv::_max(x,y)
#endif
#define ARRAY_SIZE(x) (static_cast<int>((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))
......
/*
* 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_
......
......@@ -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
}
......
......@@ -11,6 +11,8 @@
#include "format_conversion.h"
#include <assert.h>
#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);
......
......@@ -10,8 +10,8 @@
#include "scale.h"
#include <assert.h>
#include <string.h>
#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)) {
......
......@@ -17,6 +17,8 @@
namespace libyuv {
#define ARRAY_SIZE(x) (static_cast<int>((sizeof(x)/sizeof(x[0]))))
struct FourCCAliasEntry {
uint32 alias;
uint32 canonical;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment