cleanup yuv for consistency. stride, return int, negative heights, inplace conversions, lower case names, filter enum, uint, planarfunction updates, remove common.h, remove common/ folder, cpuid header public, move headers into libyuv/, add libyuv.h, fixed header guards, remove internal timing from scale, tweaks for llvm build, videocommon simplified

BUG=none
TEST=Talk builds on all platforms against libyuv.
Review URL: http://webrtc-codereview.appspot.com/226003

git-svn-id: http://libyuv.googlecode.com/svn/trunk@31 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
fbarchard@google.com 2011-10-14 17:50:12 +00:00
parent ec9d86cab3
commit a1280730c2
26 changed files with 2013 additions and 2000 deletions

View File

@ -1,41 +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.
*/
#ifndef LIBYUV_SOURCE_COMMON_H_
#define LIBYUV_SOURCE_COMMON_H_
#if defined(_MSC_VER)
// warning C4355: 'this' : used in base member initializer list
#pragma warning(disable:4355)
#endif
#ifndef ENABLE_DEBUG
#define ENABLE_DEBUG _DEBUG
#endif // !defined(ENABLE_DEBUG)
#if ENABLE_DEBUG
#if defined(_MSC_VER) && _MSC_VER < 1300
#define __FUNCTION__ ""
#endif
#else // !ENABLE_DEBUG
#endif // !ENABLE_DEBUG
// Forces compiler to inline, even against its better judgement. Use wisely.
#if defined(__GNUC__)
#define FORCE_INLINE __attribute__((always_inline))
#elif defined(WIN32)
#define FORCE_INLINE __forceinline
#else
#define FORCE_INLINE
#endif
#endif // LIBYUV_SOURCE_COMMON_H_

View File

@ -1,41 +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.
*/
#ifndef LIBYUV_INCLUDE_FORMATCONVERSION_H_
#define LIBYUV_INCLUDE_FORMATCONVERSION_H_
#include "basic_types.h"
namespace libyuv {
// Converts any Bayer RGB format to I420.
void BayerRGBToI420(const uint8* src_bayer, int src_pitch_bayer,
uint32 src_fourcc_bayer,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Converts any Bayer RGB format to ARGB.
void BayerRGBToARGB(const uint8* src_bayer, int src_pitch_bayer,
uint32 src_fourcc_bayer,
uint8* dst_rgb, int dst_pitch_rgb,
int width, int height);
// Converts ARGB to any Bayer RGB format.
void ARGBToBayerRGB(const uint8* src_rgb, int src_pitch_rgb,
uint8* dst_bayer, int dst_pitch_bayer,
uint32 dst_fourcc_bayer,
int width, int height);
} // namespace libyuv
#endif // LIBYUV_INCLUDE_FORMATCONVERSION_H_

23
include/libyuv.h Normal file
View File

@ -0,0 +1,23 @@
/*
* 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_LIBYUV_H_
#define LIBYUV_INCLUDE_LIBYUV_H_
#include "libyuv/basic_types.h"
#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/scale.h"
#endif // LIBYUV_INCLUDE_LIBYUV_H_

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef LIBYUV_COMMON_BASIC_TYPES_H_
#define LIBYUV_COMMON_BASIC_TYPES_H_
#ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_
#define INCLUDE_LIBYUV_BASIC_TYPES_H_
#include <stddef.h> // for NULL, size_t
@ -17,11 +17,6 @@
#include <stdint.h> // for uintptr_t
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef INT_TYPES_DEFINED
#define INT_TYPES_DEFINED
#ifdef COMPILER_MSVC
@ -59,48 +54,15 @@ typedef unsigned short uint16;
typedef unsigned char uint8;
#endif // INT_TYPES_DEFINED
#ifdef WIN32
typedef int socklen_t;
#endif
namespace libyuv {
template<class T> inline T _min(T a, T b) { return (a > b) ? b : a; }
template<class T> inline T _max(T a, T b) { return (a < b) ? b : a; }
// For wait functions that take a number of milliseconds, kForever indicates
// unlimited time.
const int kForever = -1;
}
// Detect compiler is for x86 or x64.
#if defined(__x86_64__) || defined(_M_X64) || \
defined(__i386__) || defined(_M_IX86)
#define CPU_X86 1
#endif
#ifdef WIN32
#define alignof(t) __alignof(t)
#else // !WIN32
#define alignof(t) __alignof__(t)
#endif // !WIN32
#define IS_ALIGNED(p, a) (0==(reinterpret_cast<uintptr_t>(p) & ((a)-1)))
#define ALIGNP(p, t) \
(reinterpret_cast<uint8*>(((reinterpret_cast<uintptr_t>(p) + \
((t)-1)) & ~((t)-1))))
#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
#if defined(__GNUC__)
#define GCC_ATTR(x) __attribute__ ((x))
#else // !__GNUC__
#define GCC_ATTR(x)
#endif // !__GNUC__
#endif // LIBYUV_COMMON_BASIC_TYPES_H_
#endif // INCLUDE_LIBYUV_BASIC_TYPES_H_

View File

@ -9,10 +9,10 @@
*/
#ifndef LIBYUV_INCLUDE_CONVERT_H_
#define LIBYUV_INCLUDE_CONVERT_H_
#ifndef INCLUDE_LIBYUV_CONVERT_H_
#define INCLUDE_LIBYUV_CONVERT_H_
#include "basic_types.h"
#include "libyuv/basic_types.h"
namespace libyuv {
@ -106,4 +106,4 @@ NV12ToRGB565(const uint8* src_yplane, int src_ystride,
} // namespace libyuv
#endif // LIBYUV_INCLUDE_CONVERT_H_
#endif // INCLUDE_LIBYUV_CONVERT_H_

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef LIBYUV_SOURCE_CPU_ID_H_
#define LIBYUV_SOURCE_CPU_ID_H_
#ifndef INCLUDE_LIBYUV_CPU_ID_H_
#define INCLUDE_LIBYUV_CPU_ID_H_
namespace libyuv {
@ -28,4 +28,4 @@ void MaskCpuFlagsForTest(int enable_flags);
} // namespace libyuv
#endif // LIBYUV_SOURCE_CPU_ID_H_
#endif // INCLUDE_LIBYUV_CPU_ID_H_

View File

@ -0,0 +1,41 @@
/*
* 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 INCLUDE_LIBYUV_FORMATCONVERSION_H_
#define INCLUDE_LIBYUV_FORMATCONVERSION_H_
#include "libyuv/basic_types.h"
namespace libyuv {
// Converts any Bayer RGB format to I420.
int BayerRGBToI420(const uint8* src_bayer, int src_stride_bayer,
uint32 src_fourcc_bayer,
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);
// Converts any Bayer RGB format to ARGB.
int BayerRGBToARGB(const uint8* src_bayer, int src_stride_bayer,
uint32 src_fourcc_bayer,
uint8* dst_rgb, int dst_stride_rgb,
int width, int height);
// Converts ARGB to any Bayer RGB format.
int ARGBToBayerRGB(const uint8* src_rgb, int src_stride_rgb,
uint8* dst_bayer, int dst_stride_bayer,
uint32 dst_fourcc_bayer,
int width, int height);
} // namespace libyuv
#endif // INCLUDE_LIBYUV_FORMATCONVERSION_H_

View File

@ -13,23 +13,22 @@
* General operations on YUV images.
*/
#ifndef LIBYUV_INCLUDE_GENERAL_H_
#define LIBYUV_INCLUDE_GENERAL_H_
#ifndef INCLUDE_LIBYUV_GENERAL_H_
#define INCLUDE_LIBYUV_GENERAL_H_
#include "basic_types.h"
#include "libyuv/basic_types.h"
namespace libyuv {
// Supported rotation
enum RotationMode
{
enum RotationMode {
kRotateNone = 0,
kRotateClockwise = 90,
kRotateCounterClockwise = 270,
kRotate180 = 180,
};
// I420 mirror
// I420 mirror
int
I420Mirror(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride,
@ -45,7 +44,7 @@ I420CropPad(const uint8* src_frame, int src_width,
int src_height, uint8* dst_frame,
int dst_width, int dst_height);
// I420 Crop - make a center cut
// I420 Crop - crop a rectangle from image
int
I420Crop(uint8* frame,
int src_width, int src_height,
@ -62,8 +61,6 @@ I420Rotate(const uint8* src_yplane, int src_ystride,
int width, int height,
RotationMode mode);
} // namespace libyuv
#endif // LIBYUV_INCLUDE_GENERAL_H_
#endif // INCLUDE_LIBYUV_GENERAL_H_

View File

@ -0,0 +1,141 @@
/*
* 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 INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_
#define INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_
#include "libyuv/basic_types.h"
namespace libyuv {
// Copy I420 to I420.
int I420Copy(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);
// Convert I422 to I420. Used by MJPG.
int I422ToI420(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);
// Convert M420 to I420.
int M420ToI420(const uint8* src_m420, int src_stride_m420,
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);
// Convert Q420 to I420.
int Q420ToI420(const uint8* src_y, int src_stride_y,
const uint8* src_yuy2, int src_stride_yuy2,
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);
// Convert NV12 to I420. Also used for NV21.
int NV12ToI420(const uint8* src_y,
const uint8* src_uv, int src_stride,
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);
// Convert YUY2 to I420.
int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2,
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);
// Convert UYVY to I420.
int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy,
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);
// Convert I420 to ARGB.
int I420ToARGB(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_argb, int dst_stride_argb,
int width, int height);
// Convert I420 to BGRA.
int I420ToBGRA(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_argb, int dst_stride_argb,
int width, int height);
// Convert I420 to ABGR.
int I420ToABGR(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_argb, int dst_stride_argb,
int width, int height);
// Convert I422 to ARGB.
int I422ToARGB(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_argb, int dst_stride_argb,
int width, int height);
// Convert I444 to ARGB.
int I444ToARGB(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_argb, int dst_stride_argb,
int width, int height);
// Convert I400 to ARGB.
int I400ToARGB(const uint8* src_y, int src_stride_y,
uint8* dst_argb, int dst_stride_argb,
int width, int height);
// Convert I400 to ARGB.
int I400ToARGB_Reference(const uint8* src_y, int src_stride_y,
uint8* dst_argb, int dst_stride_argb,
int width, int height);
// Convert RAW to ARGB.
int RAWToARGB(const uint8* src_raw, int src_stride_raw,
uint8* dst_argb, int dst_stride_argb,
int width, int height);
// Convert BG24 to ARGB.
int BG24ToARGB(const uint8* src_bg24, int src_stride_bg24,
uint8* dst_argb, int dst_stride_argb,
int width, int height);
// Convert ABGR to ARGB.
int ABGRToARGB(const uint8* src_abgr, int src_stride_abgr,
uint8* dst_argb, int dst_stride_argb,
int width, int height);
// Convert BGRA to ARGB.
int BGRAToARGB(const uint8* src_bgra, int src_stride_bgra,
uint8* dst_argb, int dst_stride_argb,
int width, int height);
} // namespace libyuv
#endif // INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_

67
include/libyuv/scale.h Normal file
View File

@ -0,0 +1,67 @@
/*
* 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 INCLUDE_LIBYUV_SCALE_H_
#define INCLUDE_LIBYUV_SCALE_H_
#include "libyuv/basic_types.h"
namespace libyuv {
// Supported filtering
enum FilterMode {
kFilterNone = 0, // Point sample; Fastest
kFilterBilinear = 1, // Faster than box, but lower quality scaling down.
kFilterBox = 2 // Highest quality
};
// Scales a YUV 4:2:0 image from the src width and height to the
// dst width and height.
// If filtering is kFilterNone, a simple nearest-neighbor algorithm is
// used. This produces basic (blocky) quality at the fastest speed.
// If filtering is kFilterBilinear, interpolation is used to produce a better
// quality image, at the expense of speed.
// If filtering is kFilterBox, averaging is used to produce ever better
// quality image, at further expense of speed.
// Returns 0 if successful.
int I420Scale(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
int src_width, int src_height,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v,
int dst_width, int dst_height,
FilterMode filtering);
// Legacy API
// If dst_height_offset is non-zero, the image is offset by that many pixels
// and stretched to (dst_height - dst_height_offset * 2) pixels high,
// instead of dst_height.
int Scale(const uint8* src, int src_width, int src_height,
uint8* dst, int dst_width, int dst_height, int dst_height_offset,
bool interpolate);
// Same, but specified src terms of each plane location and stride.
int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v,
int src_stride_y, int src_stride_u, int src_stride_v,
int src_width, int src_height,
uint8* dst_y, uint8* dst_u, uint8* dst_v,
int dst_stride_y, int dst_stride_u, int dst_stride_v,
int dst_width, int dst_height,
bool interpolate);
// For testing, allow disabling of optimizations.
void SetUseReferenceImpl(bool use);
} // namespace libyuv
#endif // INCLUDE_LIBYUV_SCALE_H_

View File

@ -1,136 +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.
*/
#ifndef LIBYUV_INCLUDE_PLANAR_FUNCTIONS_H_
#define LIBYUV_INCLUDE_PLANAR_FUNCTIONS_H_
#include "basic_types.h"
namespace libyuv {
// Copy I420 to I420.
void I420Copy(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert I422 to I420. Used by MJPG.
void I422ToI420(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert M420 to I420.
void M420ToI420(const uint8* src_m420, int src_pitch_m420,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert Q420 to I420.
void Q420ToI420(const uint8* src_y, int src_pitch_y,
const uint8* src_yuy2, int src_pitch_yuy2,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert NV12 to I420. Also used for NV21.
void NV12ToI420(const uint8* src_y,
const uint8* src_uv, int src_pitch,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert YUY2 to I420.
void YUY2ToI420(const uint8* src_yuy2, int src_pitch_yuy2,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert UYVY to I420.
void UYVYToI420(const uint8* src_uyvy, int src_pitch_uyvy,
uint8* dst_y, int dst_pitch_y,
uint8* dst_u, int dst_pitch_u,
uint8* dst_v, int dst_pitch_v,
int width, int height);
// Convert I420 to ARGB.
void I420ToARGB(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert I420 to BGRA.
void I420ToBGRA(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert I420 to ABGR.
void I420ToABGR(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert I422 to ARGB.
void I422ToARGB(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert I444 to ARGB.
void I444ToARGB(const uint8* src_y, int src_pitch_y,
const uint8* src_u, int src_pitch_u,
const uint8* src_v, int src_pitch_v,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert I400 to ARGB.
void I400ToARGB(const uint8* src_y, int src_pitch_y,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert I400 to ARGB.
void I400ToARGB_Reference(const uint8* src_y, int src_pitch_y,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert RAW to ARGB.
void RAWToARGB(const uint8* src_raw, int src_pitch_raw,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert BG24 to ARGB.
void BG24ToARGB(const uint8* src_bg24, int src_pitch_bg24,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
// Convert ABGR to ARGB.
void ABGRToARGB(const uint8* src_abgr, int src_pitch_abgr,
uint8* dst_argb, int dst_pitch_argb,
int width, int height);
} // namespace libyuv
#endif // LIBYUV_INCLUDE_PLANAR_FUNCTIONS_H_

View File

@ -1,52 +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.
*/
#ifndef LIBYUV_INCLUDE_SCALE_H_
#define LIBYUV_INCLUDE_SCALE_H_
#include "basic_types.h"
#if defined(_MSC_VER)
#define ALIGN16(var) __declspec(align(16)) var
#else
#define ALIGN16(var) var __attribute__((aligned(16)))
#endif
namespace libyuv {
// Scales a YUV 4:2:0 image from the input width and height to the
// output width and height. If outh_offset is nonzero, the image is
// offset by that many pixels and stretched to (outh - outh_offset * 2)
// pixels high, instead of outh.
// If interpolate is not set, a simple nearest-neighbor algorithm is
// used. This produces basic (blocky) quality at the fastest speed.
// If interpolate is set, interpolation is used to produce a better
// quality image, at the expense of speed.
// Returns true if successful.
bool Scale(const uint8 *in, int32 inw, int32 inh,
uint8 *out, int32 outw, int32 outh, int32 outh_offset,
bool interpolate);
// Same, but specified in terms of each plane location and stride.
bool Scale(const uint8 *inY, const uint8 *inU, const uint8 *inV,
int32 istrideY, int32 istrideU, int32 istrideV,
int32 iwidth, int32 iheight,
uint8 *outY, uint8 *outU, uint8 *outV,
int32 ostrideY, int32 ostrideU, int32 ostrideV,
int32 owidth, int32 oheight,
bool interpolate);
// For testing, allow disabling of optimizations.
void SetUseReferenceImpl(bool use);
} // namespace libyuv
#endif // LIBYUV_INCLUDE_SCALE_H_

View File

@ -15,11 +15,11 @@
*
***************************************************************/
#ifndef WEBRTC_COMMON_VIDEO_VPLIB_CONVERSION_TABLES
#define WEBRTC_COMMON_VIDEO_VPLIB_CONVERSION_TABLES
#ifndef LIBYUV_SOURCE_CONVERSION_TABLES_H_
#define LIBYUV_SOURCE_CONVERSION_TABLES_H_
namespace libyuv {
namespace libyuv
{
/******************************************************************************
* YUV TO RGB approximation
*
@ -97,7 +97,6 @@ namespace libyuv
Ucg(244),Ucg(245),Ucg(246),Ucg(247),Ucg(248),Ucg(249),Ucg(250),Ucg(251),
Ucg(252),Ucg(253),Ucg(254),Ucg(255)};
static const int mapUcb[256] = {
Ucb(0),Ucb(1),Ucb(2),Ucb(3),Ucb(4),Ucb(5),Ucb(6),Ucb(7),Ucb(8),Ucb(9),
Ucb(10),Ucb(11),Ucb(12),Ucb(13),Ucb(14),Ucb(15),Ucb(16),Ucb(17),Ucb(18),
@ -199,5 +198,6 @@ namespace libyuv
Vcg(252),Vcg(253),Vcg(254),Vcg(255)};
} // namespace libyuv
#endif

View File

@ -8,13 +8,10 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "libyuv/convert.h"
#include "convert.h"
#include "basic_types.h"
#include <string.h> // memcpy(), memset()
#include <assert.h>
#include <stdlib.h> // abs
#include "libyuv/basic_types.h"
#include "conversion_tables.h"
//#define SCALEOPT //Currently for windows only. June 2010
@ -22,20 +19,16 @@
#include <emmintrin.h>
#endif
#include "conversion_tables.h"
namespace libyuv
{
// Clip value to [0,255]
inline uint8 Clip(int32 val);
#ifdef SCALEOPT
void *memcpy_16(void * dest, const void * src, size_t n);
void *memcpy_8(void * dest, const void * src, size_t n);
#endif
namespace libyuv {
static inline uint8 Clip(int32 val) {
if (val < 0) {
return (uint8) 0;
} else if (val > 255){
return (uint8) 255;
}
return (uint8) val;
}
int
I420ToRGB24(const uint8* src_yplane, int src_ystride,
@ -344,8 +337,8 @@ I420ToYUY2(const uint8* src_yplane, int src_ystride,
const uint8* in1 = src_yplane;
const uint8* in2 = src_yplane + src_ystride ;
const uint8* inU = src_uplane;
const uint8* inV = src_vplane;
const uint8* src_u = src_uplane;
const uint8* src_v = src_vplane;
uint8* out1 = dst_frame;
uint8* out2 = dst_frame + 2 * dst_stride;
@ -356,25 +349,25 @@ I420ToYUY2(const uint8* src_yplane, int src_ystride,
for (int i = 0; i < ((src_height + 1) >> 1); i++){
for (int j = 0; j < ((src_width + 1) >> 1); j++){
out1[0] = in1[0];
out1[1] = *inU;
out1[1] = *src_u;
out1[2] = in1[1];
out1[3] = *inV;
out1[3] = *src_v;
out2[0] = in2[0];
out2[1] = *inU;
out2[1] = *src_u;
out2[2] = in2[1];
out2[3] = *inV;
out2[3] = *src_v;
out1 += 4;
out2 += 4;
inU++;
inV++;
src_u++;
src_v++;
in1 += 2;
in2 += 2;
}
in1 += 2 * src_ystride - src_width;
in2 += 2 * src_ystride - src_width;
inU += src_ustride - ((src_width + 1) >> 1);
inV += src_vstride - ((src_width + 1) >> 1);
src_u += src_ustride - ((src_width + 1) >> 1);
src_v += src_vstride - ((src_width + 1) >> 1);
out1 += 2 * dst_stride + 2 * (dst_stride - src_width);
out2 += 2 * dst_stride + 2 * (dst_stride - src_width);
}
@ -387,34 +380,34 @@ I420ToYUY2(const uint8* src_yplane, int src_ystride,
;pusha
mov eax, DWORD PTR [in1] ;1939.33
mov ecx, DWORD PTR [in2] ;1939.33
mov ebx, DWORD PTR [inU] ;1939.33
mov edx, DWORD PTR [inV] ;1939.33
mov ebx, DWORD PTR [src_u] ;1939.33
mov edx, DWORD PTR [src_v] ;1939.33
loop0:
movq xmm6, QWORD PTR [ebx] ;inU
movq xmm0, QWORD PTR [edx] ;inV
punpcklbw xmm6, xmm0 ;inU, inV mix
movq xmm6, QWORD PTR [ebx] ;src_u
movq xmm0, QWORD PTR [edx] ;src_v
punpcklbw xmm6, xmm0 ;src_u, src_v mix
;movdqa xmm1, xmm6
;movdqa xmm2, xmm6
;movdqa xmm4, xmm6
movdqu xmm3, XMMWORD PTR [eax] ;in1
movdqa xmm1, xmm3
punpcklbw xmm1, xmm6 ;in1, inU, in1, inV
punpcklbw xmm1, xmm6 ;in1, src_u, in1, src_v
mov esi, DWORD PTR [out1]
movdqu XMMWORD PTR [esi], xmm1 ;write to out1
movdqu xmm5, XMMWORD PTR [ecx] ;in2
movdqa xmm2, xmm5
punpcklbw xmm2, xmm6 ;in2, inU, in2, inV
punpcklbw xmm2, xmm6 ;in2, src_u, in2, src_v
mov edi, DWORD PTR [out2]
movdqu XMMWORD PTR [edi], xmm2 ;write to out2
punpckhbw xmm3, xmm6 ;in1, inU, in1, inV again
punpckhbw xmm3, xmm6 ;in1, src_u, in1, src_v again
movdqu XMMWORD PTR [esi+16], xmm3 ;write to out1 again
add esi, 32
mov DWORD PTR [out1], esi
punpckhbw xmm5, xmm6 ;inU, in2, inV again
punpckhbw xmm5, xmm6 ;src_u, in2, src_v again
movdqu XMMWORD PTR [edi+16], xmm5 ;write to out2 again
add edi, 32
mov DWORD PTR [out2], edi
@ -431,8 +424,8 @@ I420ToYUY2(const uint8* src_yplane, int src_ystride,
mov DWORD PTR [in1], eax ;1939.33
mov DWORD PTR [in2], ecx ;1939.33
mov DWORD PTR [inU], ebx ;1939.33
mov DWORD PTR [inV], edx ;1939.33
mov DWORD PTR [src_u], ebx ;1939.33
mov DWORD PTR [src_v], edx ;1939.33
;popa
emms
@ -504,32 +497,32 @@ I420ToUYVY(const uint8* src_yplane, int src_ystride,
;pusha
mov eax, DWORD PTR [in1] ;1939.33
mov ecx, DWORD PTR [in2] ;1939.33
mov ebx, DWORD PTR [inU] ;1939.33
mov edx, DWORD PTR [inV] ;1939.33
mov ebx, DWORD PTR [src_u] ;1939.33
mov edx, DWORD PTR [src_v] ;1939.33
loop0:
movq xmm6, QWORD PTR [ebx] ;inU
movq xmm0, QWORD PTR [edx] ;inV
punpcklbw xmm6, xmm0 ;inU, inV mix
movq xmm6, QWORD PTR [ebx] ;src_u
movq xmm0, QWORD PTR [edx] ;src_v
punpcklbw xmm6, xmm0 ;src_u, src_v mix
movdqa xmm1, xmm6
movdqa xmm2, xmm6
movdqa xmm4, xmm6
movdqu xmm3, XMMWORD PTR [eax] ;in1
punpcklbw xmm1, xmm3 ;inU, in1, inV
punpcklbw xmm1, xmm3 ;src_u, in1, src_v
mov esi, DWORD PTR [out1]
movdqu XMMWORD PTR [esi], xmm1 ;write to out1
movdqu xmm5, XMMWORD PTR [ecx] ;in2
punpcklbw xmm2, xmm5 ;inU, in2, inV
punpcklbw xmm2, xmm5 ;src_u, in2, src_v
mov edi, DWORD PTR [out2]
movdqu XMMWORD PTR [edi], xmm2 ;write to out2
punpckhbw xmm4, xmm3 ;inU, in1, inV again
punpckhbw xmm4, xmm3 ;src_u, in1, src_v again
movdqu XMMWORD PTR [esi+16], xmm4 ;write to out1 again
add esi, 32
mov DWORD PTR [out1], esi
punpckhbw xmm6, xmm5 ;inU, in2, inV again
punpckhbw xmm6, xmm5 ;src_u, in2, src_v again
movdqu XMMWORD PTR [edi+16], xmm6 ;write to out2 again
add edi, 32
mov DWORD PTR [out2], edi
@ -546,8 +539,8 @@ loop0:
mov DWORD PTR [in1], eax ;1939.33
mov DWORD PTR [in2], ecx ;1939.33
mov DWORD PTR [inU], ebx ;1939.33
mov DWORD PTR [inV], edx ;1939.33
mov DWORD PTR [src_u], ebx ;1939.33
mov DWORD PTR [src_v], edx ;1939.33
;popa
emms
@ -848,62 +841,4 @@ RAWToI420(const uint8* src_frame, int src_stride,
src_width, src_height, RAWToI420Row_C);
}
inline
uint8 Clip(int32 val)
{
if (val < 0){
return (uint8)0;
} else if (val > 255){
return (uint8)255;
}
return (uint8)val;
}
#ifdef SCALEOPT
//memcpy_16 assumes that width is an integer multiple of 16!
void
*memcpy_16(void * dest, const void * src, size_t n)
{
_asm
{
mov eax, dword ptr [src]
mov ebx, dword ptr [dest]
mov ecx, dword ptr [n]
loop0:
movdqu xmm0, XMMWORD PTR [eax]
movdqu XMMWORD PTR [ebx], xmm0
add eax, 16
add ebx, 16
sub ecx, 16
jg loop0
}
}
// memcpy_8 assumes that width is an integer multiple of 8!
void
*memcpy_8(void * dest, const void * src, size_t n)
{
_asm
{
mov eax, dword ptr [src]
mov ebx, dword ptr [dest]
mov ecx, dword ptr [n]
loop0:
movq mm0, QWORD PTR [eax]
movq QWORD PTR [ebx], mm0
add eax, 8
add ebx, 8
sub ecx, 8
jg loop0
emms
}
}
#endif
} // namespace libyuv

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "cpu_id.h"
#include "basic_types.h" // for CPU_X86
#include "libyuv/cpu_id.h"
#include "libyuv/basic_types.h" // for CPU_X86
#ifdef _MSC_VER
#include <intrin.h>

View File

@ -10,8 +10,7 @@
#include <assert.h>
#include "common.h"
#include "cpu_id.h"
#include "libyuv/cpu_id.h"
#include "video_common.h"
namespace libyuv {
@ -19,6 +18,15 @@ namespace libyuv {
// Most code in here is inspired by the material at
// http://www.siliconimaging.com/RGB%20Bayer.htm
// Forces compiler to inline, even against its better judgement. Use wisely.
#if defined(__GNUC__)
#define FORCE_INLINE __attribute__((always_inline))
#elif defined(WIN32)
#define FORCE_INLINE __forceinline
#else
#define FORCE_INLINE
#endif
enum {
RED = 0,
BLUE = 1,
@ -98,7 +106,7 @@ static FORCE_INLINE void InterpolateBayerRGBCorner(uint8* r,
uint8* g,
uint8* b,
const uint8* src,
int src_pitch,
int src_stride,
Position pos,
uint8 colour) {
@ -108,20 +116,20 @@ static FORCE_INLINE void InterpolateBayerRGBCorner(uint8* r,
int adjacent_column;
switch (pos) {
case TOP_LEFT:
adjacent_row = src_pitch;
adjacent_row = src_stride;
adjacent_column = 1;
break;
case TOP_RIGHT:
adjacent_row = src_pitch;
adjacent_row = src_stride;
adjacent_column = -1;
break;
case BOTTOM_LEFT:
adjacent_row = -src_pitch;
adjacent_row = -src_stride;
adjacent_column = 1;
break;
case BOTTOM_RIGHT:
default:
adjacent_row = -src_pitch;
adjacent_row = -src_stride;
adjacent_column = -1;
break;
}
@ -161,7 +169,7 @@ static FORCE_INLINE void InterpolateBayerRGBEdge(uint8* r,
uint8* g,
uint8* b,
const uint8* src,
int src_pitch,
int src_stride,
Position pos,
uint8 colour) {
@ -176,21 +184,21 @@ static FORCE_INLINE void InterpolateBayerRGBEdge(uint8* r,
switch (pos) {
case TOP_EDGE:
inner = src_pitch;
inner = src_stride;
side = 1;
break;
case RIGHT_EDGE:
inner = -1;
side = src_pitch;
side = src_stride;
break;
case BOTTOM_EDGE:
inner = -src_pitch;
inner = -src_stride;
side = 1;
break;
case LEFT_EDGE:
default:
inner = 1;
side = src_pitch;
side = src_stride;
break;
}
@ -234,7 +242,7 @@ static FORCE_INLINE void InterpolateBayerRGBCenter(uint8* r,
uint8* g,
uint8* b,
const uint8* src,
int src_pitch,
int src_stride,
uint8 colour) {
if (IsRedBlue(colour)) {
@ -245,12 +253,12 @@ static FORCE_INLINE void InterpolateBayerRGBCenter(uint8* r,
// quality here by using only two of the green pixels based on the
// correlation to the nearby red/blue pixels, but that is slower and would
// result in more edge cases.
*g = (src[1] + src[-1] + src[src_pitch] + src[-src_pitch]) / 4;
*g = (src[1] + src[-1] + src[src_stride] + src[-src_stride]) / 4;
// Average of the oppositely-coloured corner pixels (there's four).
uint8 corner_average = (src[src_pitch + 1] +
src[src_pitch - 1] +
src[-src_pitch + 1] +
src[-src_pitch - 1]) / 4;
uint8 corner_average = (src[src_stride + 1] +
src[src_stride - 1] +
src[-src_stride + 1] +
src[-src_stride - 1]) / 4;
if (colour == RED) {
*r = current_pixel;
*b = corner_average;
@ -263,7 +271,7 @@ static FORCE_INLINE void InterpolateBayerRGBCenter(uint8* r,
// Average of the adjacent same-row pixels (there's two).
uint8 row_adjacent = (src[1] + src[-1]) / 2;
// Average of the adjacent same-column pixels (there's two).
uint8 column_adjacent = (src[src_pitch] + src[-src_pitch]) / 2;
uint8 column_adjacent = (src[src_stride] + src[-src_stride]) / 2;
if (colour == GREEN_BETWEEN_RED) {
*r = row_adjacent;
*b = column_adjacent;
@ -275,15 +283,15 @@ static FORCE_INLINE void InterpolateBayerRGBCenter(uint8* r,
}
// Converts any Bayer RGB format to ARGB.
void BayerRGBToARGB(const uint8* src, int src_pitch, uint32 src_fourcc,
uint8* dst, int dst_pitch,
int width, int height) {
int BayerRGBToARGB(const uint8* src, int src_stride, uint32 src_fourcc,
uint8* dst, int dst_stride,
int width, int height) {
assert(width % 2 == 0);
assert(height % 2 == 0);
uint32 colour_map = FourCcToBayerPixelColourMap(src_fourcc);
int src_row_inc = src_pitch * 2 - width;
int dst_row_inc = dst_pitch * 2 - width * 4;
int src_row_inc = src_stride * 2 - width;
int dst_row_inc = dst_stride * 2 - width * 4;
// Iterate over the 2x2 grids.
for (int y1 = 0; y1 < height; y1 += 2) {
@ -297,24 +305,24 @@ void BayerRGBToARGB(const uint8* src, int src_pitch, uint32 src_fourcc,
uint8 current_colour = static_cast<uint8>(colours);
colours >>= 8;
Position pos = GetPosition(x1 + x2, y1 + y2, width, height);
const uint8* src_pixel = &src[y2 * src_pitch + x2];
uint8* dst_pixel = &dst[y2 * dst_pitch + x2 * 4];
const uint8* src_pixel = &src[y2 * src_stride + x2];
uint8* dst_pixel = &dst[y2 * dst_stride + x2 * 4];
// Convert from Bayer RGB to regular RGB.
if (pos == MIDDLE) {
// 99% of the image is the middle.
InterpolateBayerRGBCenter(&r, &g, &b,
src_pixel, src_pitch,
src_pixel, src_stride,
current_colour);
} else if (pos >= LEFT_EDGE) {
// Next most frequent is edges.
InterpolateBayerRGBEdge(&r, &g, &b,
src_pixel, src_pitch, pos,
src_pixel, src_stride, pos,
current_colour);
} else {
// Last is the corners. There are only 4.
InterpolateBayerRGBCorner(&r, &g, &b,
src_pixel, src_pitch, pos,
src_pixel, src_stride, pos,
current_colour);
}
@ -331,23 +339,24 @@ void BayerRGBToARGB(const uint8* src, int src_pitch, uint32 src_fourcc,
src += src_row_inc;
dst += dst_row_inc;
}
return 0;
}
// Converts any Bayer RGB format to I420.
void BayerRGBToI420(const uint8* src, int src_pitch, uint32 src_fourcc,
uint8* y, int y_pitch,
uint8* u, int u_pitch,
uint8* v, int v_pitch,
int width, int height) {
int BayerRGBToI420(const uint8* src, int src_stride, uint32 src_fourcc,
uint8* y, int y_stride,
uint8* u, int u_stride,
uint8* v, int v_stride,
int width, int height) {
assert(width % 2 == 0);
assert(height % 2 == 0);
uint32 colour_map = FourCcToBayerPixelColourMap(src_fourcc);
int src_row_inc = src_pitch * 2 - width;
int y_row_inc = y_pitch * 2 - width;
int u_row_inc = u_pitch - width / 2;
int v_row_inc = v_pitch - width / 2;
int src_row_inc = src_stride * 2 - width;
int y_row_inc = y_stride * 2 - width;
int u_row_inc = u_stride - width / 2;
int v_row_inc = v_stride - width / 2;
// Iterate over the 2x2 grids.
for (int y1 = 0; y1 < height; y1 += 2) {
@ -363,25 +372,25 @@ void BayerRGBToI420(const uint8* src, int src_pitch, uint32 src_fourcc,
uint8 current_colour = static_cast<uint8>(colours);
colours >>= 8;
Position pos = GetPosition(x1 + x2, y1 + y2, width, height);
const uint8* src_pixel = &src[y2 * src_pitch + x2];
uint8* y_pixel = &y[y2 * y_pitch + x2];
const uint8* src_pixel = &src[y2 * src_stride + x2];
uint8* y_pixel = &y[y2 * y_stride + x2];
// Convert from Bayer RGB to regular RGB.
if (pos == MIDDLE) {
// 99% of the image is the middle.
InterpolateBayerRGBCenter(&r, &g, &b,
src_pixel, src_pitch,
src_pixel, src_stride,
current_colour);
} else if (pos >= LEFT_EDGE) {
// Next most frequent is edges.
InterpolateBayerRGBEdge(&r, &g, &b,
src_pixel, src_pitch, pos,
src_pixel, src_stride, pos,
current_colour);
} else {
// Last is the corners. There are only 4.
InterpolateBayerRGBCorner(&r, &g, &b,
src_pixel, src_pitch, pos,
src_pixel, src_stride, pos,
current_colour);
}
@ -405,6 +414,7 @@ void BayerRGBToI420(const uint8* src, int src_pitch, uint32 src_fourcc,
u += u_row_inc;
v += v_row_inc;
}
return 0;
}
// Note: to do this with Neon vld4.8 would load ARGB values into 4 registers
@ -490,18 +500,18 @@ static uint32 GenerateSelector(int select0, int select1) {
}
// Converts 32 bit ARGB to any Bayer RGB format.
void ARGBToBayerRGB(const uint8* src_rgb, int src_pitch_rgb,
uint8* dst_bayer, int dst_pitch_bayer,
uint32 dst_fourcc_bayer,
int width, int height) {
int ARGBToBayerRGB(const uint8* src_rgb, int src_stride_rgb,
uint8* dst_bayer, int dst_stride_bayer,
uint32 dst_fourcc_bayer,
int width, int height) {
assert(width % 2 == 0);
void (*ARGBToBayerRow)(const uint8* src_argb,
uint8* dst_bayer, uint32 selector, int pix);
#if defined(HAS_ARGBTOBAYERROW_SSSE3)
if (libyuv::TestCpuFlag(libyuv::kCpuHasSSSE3) &&
(width % 4 == 0) &&
IS_ALIGNED(src_rgb, 16) && (src_pitch_rgb % 16 == 0) &&
IS_ALIGNED(dst_bayer, 4) && (dst_pitch_bayer % 4 == 0)) {
IS_ALIGNED(src_rgb, 16) && (src_stride_rgb % 16 == 0) &&
IS_ALIGNED(dst_bayer, 4) && (dst_stride_bayer % 4 == 0)) {
ARGBToBayerRow = ARGBToBayerRow_SSSE3;
} else
#endif
@ -540,9 +550,10 @@ void ARGBToBayerRGB(const uint8* src_rgb, int src_pitch_rgb,
// Now convert.
for (int y = 0; y < height; ++y) {
ARGBToBayerRow(src_rgb, dst_bayer, index_map[y & 1], width);
src_rgb += src_pitch_rgb;
dst_bayer += dst_pitch_bayer;
src_rgb += src_stride_rgb;
dst_bayer += dst_stride_bayer;
}
return 0;
}
} // namespace libyuv

View File

@ -8,14 +8,13 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "general.h"
#include "libyuv/general.h"
#include <string.h> // memcpy(), memset()
#include "planar_functions.h"
#include "libyuv/planar_functions.h"
#include "rotate.h"
namespace libyuv {
int
@ -25,11 +24,11 @@ I420Mirror(const uint8* src_yplane, int src_ystride,
uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride,
int width, int height)
{
int width, int height) {
if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
dst_yplane == NULL || dst_uplane == NULL || dst_vplane == NULL)
dst_yplane == NULL || dst_uplane == NULL || dst_vplane == NULL) {
return -1;
}
int indO = 0;
int indS = 0;
@ -39,8 +38,8 @@ I420Mirror(const uint8* src_yplane, int src_ystride,
const int halfWidth = (width + 1) >> 1;
// Y
for (wind = 0; wind < halfWidth; wind++){
for (hind = 0; hind < height; hind++){
for (wind = 0; wind < halfWidth; wind++) {
for (hind = 0; hind < height; hind++) {
indO = hind * src_ystride + wind;
indS = hind * dst_ystride + (width - wind - 1);
tmpVal = src_yplane[indO];
@ -53,8 +52,8 @@ I420Mirror(const uint8* src_yplane, int src_ystride,
const int halfSrcuvStride = (height + 1) >> 1;
const int halfuvWidth = (width + 1) >> 2;
for (wind = 0; wind < halfuvWidth; wind++){
for (hind = 0; hind < halfHeight; hind++){
for (wind = 0; wind < halfuvWidth; wind++) {
for (hind = 0; hind < halfHeight; hind++) {
indO = hind * halfSrcuvStride + wind;
indS = hind * halfSrcuvStride + (halfuvWidth - wind - 1);
// U
@ -79,11 +78,11 @@ I420Crop(uint8* frame,
if (frame == NULL)
return -1;
if (src_width == dst_width && src_height == dst_height){
if (src_width == dst_width && src_height == dst_height) {
// Nothing to do
return 3 * dst_height * dst_width / 2;
}
if (dst_width > src_width || dst_height > src_height){
if (dst_width > src_width || dst_height > src_height) {
// error
return -1;
}
@ -98,21 +97,21 @@ I420Crop(uint8* frame,
int crop_width = ( src_width - dst_width ) / 2;
for (i = src_width * crop_height + crop_width; loop < dst_height ;
loop++, i += src_width){
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){
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){
loop < halfdst_height; loop++, i += halfsrc_width) {
memcpy(&frame[m],&frame[i],half_dst_width);
m += half_dst_width;
}
@ -122,66 +121,59 @@ I420Crop(uint8* frame,
int
I420CropPad(const uint8* src_frame, int src_width,
int src_height, uint8* dst_frame,
int dst_width, int dst_height)
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 )
if (src_width < 1 || dst_width < 1 || src_height < 1 || dst_height < 1) {
return -1;
if (src_width == dst_width && src_height == dst_height)
}
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){
} 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){
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;
} else {
// cut width
crop_width = src_width - dst_width;
width = dst_width;
}
if (pad_height){
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)
{
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, 0, dst_width * (pad_height >> 1));
dst_frame += dst_width * (pad_height >> 1);
}
if (pad_height)
{
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)
{
for (i = 0; i < (src_height >> 1); i++) {
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
@ -190,21 +182,17 @@ I420CropPad(const uint8* src_frame, int src_width,
src_frame += crop_width >> 2;
dst_frame += width >> 1;
src_frame += width >> 1;
if (pad_width)
{
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
}
if (pad_height)
{
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)
{
for (i = 0; i < (src_height >> 1); i++) {
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
@ -213,32 +201,26 @@ I420CropPad(const uint8* src_frame, int src_width,
src_frame += crop_width >> 2;
dst_frame += width >> 1;
src_frame += width >> 1;
if (pad_width)
{
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
}
if (pad_height)
{
if (pad_height) {
memset(dst_frame, 127, (dst_width >> 2) * (pad_height >> 1));
dst_frame += (dst_width >> 2) * (pad_height >> 1);
}
}
else
{
} else {
// cut height
int i = 0;
int pad_width = 0;
int crop_width = 0;
int width = src_width;
if (src_width < dst_width)
{
if (src_width < dst_width) {
// pad width
pad_width = dst_width - src_width;
} else
{
} else {
// cut width
crop_width = src_width - dst_width;
width = dst_width;
@ -246,10 +228,8 @@ I420CropPad(const uint8* src_frame, int src_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)
{
for (i = 0; i < dst_height; i++) {
if (pad_width) {
memset(dst_frame, 0, pad_width / 2);
dst_frame += pad_width / 2;
}
@ -258,18 +238,15 @@ I420CropPad(const uint8* src_frame, int src_width,
src_frame += crop_width >> 1;
dst_frame += width;
src_frame += width;
if (pad_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)
{
for (i = 0; i < (dst_height >> 1); i++) {
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
@ -278,18 +255,15 @@ I420CropPad(const uint8* src_frame, int src_width,
src_frame += crop_width >> 2;
dst_frame += width >> 1;
src_frame += width >> 1;
if (pad_width)
{
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)
{
for (i = 0; i < (dst_height >> 1); i++) {
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
@ -298,8 +272,7 @@ I420CropPad(const uint8* src_frame, int src_width,
src_frame += crop_width >> 2;
dst_frame += width >> 1;
src_frame += width >> 1;
if (pad_width)
{
if (pad_width) {
memset(dst_frame, 127, pad_width >> 2);
dst_frame += pad_width >> 2;
}
@ -317,20 +290,17 @@ I420Rotate(const uint8* src_yplane, int src_ystride,
uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride,
int width, int height,
RotationMode mode)
{
switch (mode){
// TODO: should return int
RotationMode mode) {
switch (mode) {
case kRotateNone:
// copy frame
I420Copy(src_yplane, src_ystride,
src_uplane, src_ustride,
src_vplane, src_vstride,
dst_yplane, dst_ystride,
dst_uplane, dst_ustride,
dst_vplane, dst_vstride,
width, height);
return 0;
return I420Copy(src_yplane, src_ystride,
src_uplane, src_ustride,
src_vplane, src_vstride,
dst_yplane, dst_ystride,
dst_uplane, dst_ustride,
dst_vplane, dst_vstride,
width, height);
break;
case kRotateClockwise:
Rotate90(src_yplane, src_ystride,
@ -374,4 +344,4 @@ I420Rotate(const uint8* src_yplane, int src_ystride,
}
}
} // nmaespace libyuv
} // namespace libyuv

File diff suppressed because it is too large Load Diff

View File

@ -19,31 +19,31 @@ typedef void (*rotate_wxhfunc)(const uint8*, int, uint8*, int, int, int);
#ifdef __ARM_NEON__
extern "C" {
void ReverseLine_NEON(const uint8* src, uint8* dst, int width);
void Transpose_wx8_NEON(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch, int width);
void Transpose_wx8_NEON(const uint8* src, int src_stride,
uint8* dst, int dst_stride, int width);
} // extern "C"
#endif
static void Transpose_wx8_C(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
static void Transpose_wx8_C(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int w) {
int i, j;
for (i = 0; i < w; ++i)
for (j = 0; j < 8; ++j)
dst[i * dst_pitch + j] = src[j * src_pitch + i];
dst[i * dst_stride + j] = src[j * src_stride + i];
}
static void Transpose_wxh_C(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
static void Transpose_wxh_C(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
int i, j;
for (i = 0; i < width; ++i)
for (j = 0; j < height; ++j)
dst[i * dst_pitch + j] = src[j * src_pitch + i];
dst[i * dst_stride + j] = src[j * src_stride + i];
}
void Transpose(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Transpose(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
int i = height;
rotate_wx8func Transpose_wx8;
@ -60,33 +60,33 @@ void Transpose(const uint8* src, int src_pitch,
// work across the source in 8x8 tiles
do {
Transpose_wx8(src, src_pitch, dst, dst_pitch, width);
Transpose_wx8(src, src_stride, dst, dst_stride, width);
src += 8 * src_pitch;
src += 8 * src_stride;
dst += 8;
i -= 8;
} while (i >= 8);
// TODO(frkoenig): Have wx4 and maybe wx2
Transpose_wxh(src, src_pitch, dst, dst_pitch, width, i);
Transpose_wxh(src, src_stride, dst, dst_stride, width, i);
}
void Rotate90(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Rotate90(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
src += src_pitch*(height-1);
src_pitch = -src_pitch;
src += src_stride*(height-1);
src_stride = -src_stride;
Transpose(src, src_pitch, dst, dst_pitch, width, height);
Transpose(src, src_stride, dst, dst_stride, width, height);
}
void Rotate270(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Rotate270(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
dst += dst_pitch*(width-1);
dst_pitch = -dst_pitch;
dst += dst_stride*(width-1);
dst_stride = -dst_stride;
Transpose(src, src_pitch, dst, dst_pitch, width, height);
Transpose(src, src_stride, dst, dst_stride, width, height);
}
void ReverseLine_C(const uint8* src, uint8* dst, int width) {
@ -95,8 +95,8 @@ void ReverseLine_C(const uint8* src, uint8* dst, int width) {
dst[width-1 - i] = src[i];
}
void Rotate180(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Rotate180(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
int i;
reverse_func ReverseLine;
@ -108,13 +108,13 @@ void Rotate180(const uint8* src, int src_pitch,
ReverseLine = ReverseLine_C;
#endif
dst += dst_pitch*(height-1);
dst += dst_stride*(height-1);
for (i = 0; i < height; ++i) {
ReverseLine(src, dst, width);
src += src_pitch;
dst -= dst_pitch;
src += src_stride;
dst -= dst_stride;
}
}

View File

@ -11,34 +11,35 @@
#ifndef LIBYUV_SOURCE_ROTATE_H_
#define LIBYUV_SOURCE_ROTATE_H_
#include "basic_types.h"
#include "libyuv/basic_types.h"
namespace libyuv {
void Rotate90(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Rotate90(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height);
void Rotate180(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Rotate180(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height);
void Rotate270(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Rotate270(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height);
void Rotate90_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Rotate90_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height);
void Rotate180_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Rotate180_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height);
void Rotate270_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Rotate270_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height);
void Transpose(const uint8* src, int src_pitch,
uint8* dst, int dst_pitch,
void Transpose(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height);
} // namespace libyuv

View File

@ -27,40 +27,40 @@ void ReverseLine_di_NEON(const uint8* src,
uint8* dst_a, uint8* dst_b,
int width);
void SaveRegisters_NEON(unsigned long long *store);
void Transpose_di_wx8_NEON(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Transpose_di_wx8_NEON(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width);
} // extern "C"
#endif
static void Transpose_di_wx8_C(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
static void Transpose_di_wx8_C(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int w) {
int i, j;
for (i = 0; i < w*2; i += 2)
for (j = 0; j < 8; ++j) {
dst_a[j + (i>>1)*dst_pitch_a] = src[i + j*src_pitch];
dst_b[j + (i>>1)*dst_pitch_b] = src[i + j*src_pitch + 1];
dst_a[j + (i>>1)*dst_stride_a] = src[i + j*src_stride];
dst_b[j + (i>>1)*dst_stride_b] = src[i + j*src_stride + 1];
}
}
static void Transpose_di_wxh_C(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
static void Transpose_di_wxh_C(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int w, int h) {
int i, j;
for (i = 0; i < w*2; i += 2)
for (j = 0; j < h; ++j) {
dst_a[j + (i>>1)*dst_pitch_a] = src[i + j*src_pitch];
dst_b[j + (i>>1)*dst_pitch_b] = src[i + j*src_pitch + 1];
dst_a[j + (i>>1)*dst_stride_a] = src[i + j*src_stride];
dst_b[j + (i>>1)*dst_stride_b] = src[i + j*src_stride + 1];
}
}
void Transpose_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Transpose_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height) {
int i = height;
rotate_wx8func Transpose_wx8;
@ -81,20 +81,20 @@ void Transpose_deinterleave(const uint8* src, int src_pitch,
// work across the source in 8x8 tiles
do {
Transpose_wx8(src, src_pitch,
dst_a, dst_pitch_a,
dst_b, dst_pitch_b,
Transpose_wx8(src, src_stride,
dst_a, dst_stride_a,
dst_b, dst_stride_b,
width);
src += 8 * src_pitch;
src += 8 * src_stride;
dst_a += 8;
dst_b += 8;
i -= 8;
} while (i >= 8);
Transpose_wxh(src, src_pitch,
dst_a, dst_pitch_a,
dst_b, dst_pitch_b,
Transpose_wxh(src, src_stride,
dst_a, dst_stride_a,
dst_b, dst_stride_b,
width, i);
#ifdef __ARM_NEON__
@ -102,31 +102,31 @@ void Transpose_deinterleave(const uint8* src, int src_pitch,
#endif
}
void Rotate90_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Rotate90_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height) {
src += src_pitch*(height-1);
src_pitch = -src_pitch;
src += src_stride*(height-1);
src_stride = -src_stride;
Transpose_deinterleave(src, src_pitch,
dst_a, dst_pitch_a,
dst_b, dst_pitch_b,
Transpose_deinterleave(src, src_stride,
dst_a, dst_stride_a,
dst_b, dst_stride_b,
width, height);
}
void Rotate270_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Rotate270_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height) {
dst_a += dst_pitch_a*((width>>1)-1);
dst_b += dst_pitch_b*((width>>1)-1);
dst_pitch_a = -dst_pitch_a;
dst_pitch_b = -dst_pitch_b;
dst_a += dst_stride_a*((width>>1)-1);
dst_b += dst_stride_b*((width>>1)-1);
dst_stride_a = -dst_stride_a;
dst_stride_b = -dst_stride_b;
Transpose_deinterleave(src, src_pitch,
dst_a, dst_pitch_a,
dst_b, dst_pitch_b,
Transpose_deinterleave(src, src_stride,
dst_a, dst_stride_a,
dst_b, dst_stride_b,
width, height);
}
@ -140,9 +140,9 @@ static void ReverseLine_di_C(const uint8* src,
}
}
void Rotate180_deinterleave(const uint8* src, int src_pitch,
uint8* dst_a, int dst_pitch_a,
uint8* dst_b, int dst_pitch_b,
void Rotate180_deinterleave(const uint8* src, int src_stride,
uint8* dst_a, int dst_stride_a,
uint8* dst_b, int dst_stride_b,
int width, int height) {
int i;
reverse_func ReverseLine;
@ -154,17 +154,17 @@ void Rotate180_deinterleave(const uint8* src, int src_pitch,
ReverseLine = ReverseLine_di_C;
#endif
dst_a += dst_pitch_a*(height-1);
dst_b += dst_pitch_b*(height-1);
dst_a += dst_stride_a*(height-1);
dst_b += dst_stride_b*(height-1);
width >>= 1;
for (i = 0; i < height; ++i) {
ReverseLine(src, dst_a, dst_b, width);
src += src_pitch;
dst_a -= dst_pitch_a;
dst_b -= dst_pitch_b;
src += src_stride;
dst_a -= dst_stride_a;
dst_b -= dst_stride_b;
}
}

View File

@ -11,7 +11,7 @@
#ifndef LIBYUV_SOURCE_ROW_H_
#define LIBYUV_SOURCE_ROW_H_
#include "basic_types.h"
#include "libyuv/basic_types.h"
extern "C" {
void FastConvertYUVToRGB32Row(const uint8* y_buf,

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,6 @@
#include <sstream>
#include "common.h"
namespace libyuv {
#define ARRAY_SIZE(x) (static_cast<int>((sizeof(x)/sizeof(x[0]))))
@ -47,20 +45,4 @@ uint32 CanonicalFourCC(uint32 fourcc) {
return fourcc;
}
std::string VideoFormat::ToString() const {
std::string fourcc_name = GetFourccName(fourcc) + " ";
for (std::string::const_iterator i = fourcc_name.begin();
i < fourcc_name.end(); ++i) {
// Test character is printable; Avoid isprint() which asserts on negatives
if (*i < 32 || *i >= 127) {
fourcc_name = "";
break;
}
}
std::ostringstream ss;
ss << fourcc_name << width << "x" << height << "x" << IntervalToFps(interval);
return ss.str();
}
} // namespace libyuv

View File

@ -18,7 +18,7 @@
#include <string>
#include "basic_types.h"
#include "libyuv/basic_types.h"
namespace libyuv {
@ -32,16 +32,6 @@ namespace libyuv {
(static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
(static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
// Get the name, that is, string with four characters, of a fourcc code.
inline std::string GetFourccName(uint32 fourcc) {
std::string name;
name.push_back(static_cast<char>(fourcc & 0xFF));
name.push_back(static_cast<char>((fourcc >> 8) & 0xFF));
name.push_back(static_cast<char>((fourcc >> 16) & 0xFF));
name.push_back(static_cast<char>((fourcc >> 24) & 0xFF));
return name;
}
// Some good pages discussing FourCC codes:
// http://developer.apple.com/quicktime/icefloe/dispatch020.html
// http://www.fourcc.org/yuv.php
@ -87,88 +77,6 @@ enum FourCC {
// Converts fourcc aliases into canonical ones.
uint32 CanonicalFourCC(uint32 fourcc);
//////////////////////////////////////////////////////////////////////////////
// Definition of VideoFormat.
//////////////////////////////////////////////////////////////////////////////
static const int64 kNumNanosecsPerSec = 1000000000;
struct VideoFormat {
static const int64 kMinimumInterval = kNumNanosecsPerSec / 10000; // 10k fps
VideoFormat() : width(0), height(0), interval(0), fourcc(0) {}
VideoFormat(int w, int h, int64 interval_ns, uint32 cc)
: width(w),
height(h),
interval(interval_ns),
fourcc(cc) {
}
VideoFormat(const VideoFormat& format)
: width(format.width),
height(format.height),
interval(format.interval),
fourcc(format.fourcc) {
}
static int64 FpsToInterval(int fps) {
return fps ? kNumNanosecsPerSec / fps : kMinimumInterval;
}
static int IntervalToFps(int64 interval) {
// Normalize the interval first.
interval = libyuv::_max(interval, kMinimumInterval);
return static_cast<int>(kNumNanosecsPerSec / interval);
}
bool operator==(const VideoFormat& format) const {
return width == format.width && height == format.height &&
interval == format.interval && fourcc == format.fourcc;
}
bool operator!=(const VideoFormat& format) const {
return !(*this == format);
}
bool operator<(const VideoFormat& format) const {
return (fourcc < format.fourcc) ||
(fourcc == format.fourcc && width < format.width) ||
(fourcc == format.fourcc && width == format.width &&
height < format.height) ||
(fourcc == format.fourcc && width == format.width &&
height == format.height && interval > format.interval);
}
int framerate() const { return IntervalToFps(interval); }
// Check if both width and height are 0.
bool IsSize0x0() const { return 0 == width && 0 == height; }
// Check if this format is less than another one by comparing the resolution
// and frame rate.
bool IsPixelRateLess(const VideoFormat& format) const {
return width * height * framerate() <
format.width * format.height * format.framerate();
}
// Get a string presentation in the form of "fourcc width x height x fps"
std::string ToString() const;
int width; // in number of pixels
int height; // in number of pixels
int64 interval; // in nanoseconds
uint32 fourcc; // color space. FOURCC_ANY means that any color space is OK.
};
// Result of video capturer start.
enum CaptureResult {
CR_SUCCESS, // The capturer starts successfully.
CR_PENDING, // The capturer is pending to start the capture device.
CR_FAILURE, // The capturer fails to start.
CR_NO_DEVICE, // The capturer has no device and fails to start.
};
} // namespace libyuv
#endif // LIBYUV_SOURCE_VIDEO_COMMON_H_

View File

@ -22,8 +22,7 @@ class libyuvEnvironment : public ::testing::Environment {
libyuvTest::libyuvTest() :
_rotate_max_w(128),
_rotate_max_h(128)
{
_rotate_max_h(128) {
}
void libyuvTest::SetUp() {