mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-07 01:06:46 +08:00
Port a few functions to C
BUG=303 TESTED=try bots R=johannkoenig@google.com, tpsiaki@google.com Review URL: https://webrtc-codereview.appspot.com/6599005 git-svn-id: http://libyuv.googlecode.com/svn/trunk@950 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
dd49958058
commit
959b290a96
@ -1,6 +1,6 @@
|
|||||||
Name: libyuv
|
Name: libyuv
|
||||||
URL: http://code.google.com/p/libyuv/
|
URL: http://code.google.com/p/libyuv/
|
||||||
Version: 949
|
Version: 950
|
||||||
License: BSD
|
License: BSD
|
||||||
License File: LICENSE
|
License File: LICENSE
|
||||||
|
|
||||||
|
|||||||
@ -98,6 +98,10 @@ typedef signed char int8;
|
|||||||
#endif // __GNUC__
|
#endif // __GNUC__
|
||||||
#endif // LIBYUV_API
|
#endif // LIBYUV_API
|
||||||
|
|
||||||
|
#define LIBYUV_BOOL int
|
||||||
|
#define LIBYUV_FALSE 0
|
||||||
|
#define LIBYUV_TRUE 1
|
||||||
|
|
||||||
// Visual C x86 or GCC little endian.
|
// Visual C x86 or GCC little endian.
|
||||||
#if defined(__x86_64__) || defined(_M_X64) || \
|
#if defined(__x86_64__) || defined(_M_X64) || \
|
||||||
defined(__i386__) || defined(_M_IX86) || \
|
defined(__i386__) || defined(_M_IX86) || \
|
||||||
|
|||||||
@ -20,7 +20,7 @@ extern "C" {
|
|||||||
|
|
||||||
// TODO(fbarchard): Consider overlapping bits for different architectures.
|
// TODO(fbarchard): Consider overlapping bits for different architectures.
|
||||||
// Internal flag to indicate cpuid requires initialization.
|
// Internal flag to indicate cpuid requires initialization.
|
||||||
static const int kCpuInit = 0x1;
|
#define kCpuInit 0x1
|
||||||
|
|
||||||
// These flags are only valid on ARM processors.
|
// These flags are only valid on ARM processors.
|
||||||
static const int kCpuHasARM = 0x2;
|
static const int kCpuHasARM = 0x2;
|
||||||
|
|||||||
@ -11,10 +11,9 @@
|
|||||||
#ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_ // NOLINT
|
#ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_ // NOLINT
|
||||||
#define INCLUDE_LIBYUV_MJPEG_DECODER_H_
|
#define INCLUDE_LIBYUV_MJPEG_DECODER_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
|
|
||||||
#include "libyuv/basic_types.h"
|
#include "libyuv/basic_types.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
// NOTE: For a simplified public API use convert.h MJPGToI420().
|
// NOTE: For a simplified public API use convert.h MJPGToI420().
|
||||||
|
|
||||||
struct jpeg_common_struct;
|
struct jpeg_common_struct;
|
||||||
@ -23,7 +22,15 @@ struct jpeg_source_mgr;
|
|||||||
|
|
||||||
namespace libyuv {
|
namespace libyuv {
|
||||||
|
|
||||||
bool ValidateJpeg(const uint8* sample, size_t sample_size);
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
static const uint32 kUnknownDataSize = 0xFFFFFFFF;
|
static const uint32 kUnknownDataSize = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,6 @@
|
|||||||
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
|
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
|
||||||
#define INCLUDE_LIBYUV_VERSION_H_
|
#define INCLUDE_LIBYUV_VERSION_H_
|
||||||
|
|
||||||
#define LIBYUV_VERSION 949
|
#define LIBYUV_VERSION 950
|
||||||
|
|
||||||
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
|
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
|
||||||
|
|||||||
@ -48,7 +48,7 @@ LIBYUV_API
|
|||||||
void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
|
void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#if (_MSC_FULL_VER >= 160040219)
|
#if (_MSC_FULL_VER >= 160040219)
|
||||||
__cpuidex(reinterpret_cast<int*>(cpu_info), info_eax, info_ecx);
|
__cpuidex((int*)(cpu_info), info_eax, info_ecx);
|
||||||
#elif defined(_M_IX86)
|
#elif defined(_M_IX86)
|
||||||
__asm {
|
__asm {
|
||||||
mov eax, info_eax
|
mov eax, info_eax
|
||||||
@ -62,7 +62,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (info_ecx == 0) {
|
if (info_ecx == 0) {
|
||||||
__cpuid(reinterpret_cast<int*>(cpu_info), info_eax);
|
__cpuid((int*)(cpu_info), info_eax);
|
||||||
} else {
|
} else {
|
||||||
cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0;
|
cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0;
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
|
|||||||
int TestOsSaveYmm() {
|
int TestOsSaveYmm() {
|
||||||
uint32 xcr0 = 0u;
|
uint32 xcr0 = 0u;
|
||||||
#if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
|
#if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
|
||||||
xcr0 = static_cast<uint32>(_xgetbv(0)); // VS2010 SP1 required.
|
xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required.
|
||||||
#elif defined(_M_IX86)
|
#elif defined(_M_IX86)
|
||||||
__asm {
|
__asm {
|
||||||
xor ecx, ecx // xcr 0
|
xor ecx, ecx // xcr 0
|
||||||
@ -162,18 +162,18 @@ int cpu_info_ = kCpuInit; // cpu_info is not initialized yet.
|
|||||||
// to disable. Zero ignored to make it easy to set the variable on/off.
|
// to disable. Zero ignored to make it easy to set the variable on/off.
|
||||||
#if !defined(__native_client__) && !defined(_M_ARM)
|
#if !defined(__native_client__) && !defined(_M_ARM)
|
||||||
|
|
||||||
static bool TestEnv(const char* name) {
|
static LIBYUV_BOOL TestEnv(const char* name) {
|
||||||
const char* var = getenv(name);
|
const char* var = getenv(name);
|
||||||
if (var) {
|
if (var) {
|
||||||
if (var[0] != '0') {
|
if (var[0] != '0') {
|
||||||
return true;
|
return LIBYUV_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return LIBYUV_FALSE;
|
||||||
}
|
}
|
||||||
#else // nacl does not support getenv().
|
#else // nacl does not support getenv().
|
||||||
static bool TestEnv(const char*) {
|
static LIBYUV_BOOL TestEnv(const char*) {
|
||||||
return false;
|
return LIBYUV_FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -10,32 +10,38 @@
|
|||||||
|
|
||||||
#include "libyuv/mjpeg_decoder.h"
|
#include "libyuv/mjpeg_decoder.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
namespace libyuv {
|
namespace libyuv {
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// Helper function to validate the jpeg appears intact.
|
// Helper function to validate the jpeg appears intact.
|
||||||
// TODO(fbarchard): Optimize case where SOI is found but EOI is not.
|
// TODO(fbarchard): Optimize case where SOI is found but EOI is not.
|
||||||
bool ValidateJpeg(const uint8* sample, size_t sample_size) {
|
LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size) {
|
||||||
|
size_t i;
|
||||||
if (sample_size < 64) {
|
if (sample_size < 64) {
|
||||||
// ERROR: Invalid jpeg size: sample_size
|
// ERROR: Invalid jpeg size: sample_size
|
||||||
return false;
|
return LIBYUV_FALSE;
|
||||||
}
|
}
|
||||||
if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image
|
if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image
|
||||||
// ERROR: Invalid jpeg initial start code
|
// ERROR: Invalid jpeg initial start code
|
||||||
return false;
|
return LIBYUV_FALSE;
|
||||||
}
|
}
|
||||||
for (int i = static_cast<int>(sample_size) - 2; i > 1;) {
|
for (i = sample_size - 2; i > 1;) {
|
||||||
if (sample[i] != 0xd9) {
|
if (sample[i] != 0xd9) {
|
||||||
if (sample[i] == 0xff && sample[i + 1] == 0xd9) { // End Of Image
|
if (sample[i] == 0xff && sample[i + 1] == 0xd9) { // End Of Image
|
||||||
return true;
|
return LIBYUV_TRUE; // Success: Valid jpeg.
|
||||||
}
|
}
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
// ERROR: Invalid jpeg end code not found. Size sample_size
|
// ERROR: Invalid jpeg end code not found. Size sample_size
|
||||||
return false;
|
return LIBYUV_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
} // namespace libyuv
|
} // namespace libyuv
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -16,14 +16,14 @@ namespace libyuv {
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (static_cast<int>((sizeof(x) / sizeof(x[0]))))
|
#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof(x[0]))
|
||||||
|
|
||||||
struct FourCCAliasEntry {
|
struct FourCCAliasEntry {
|
||||||
uint32 alias;
|
uint32 alias;
|
||||||
uint32 canonical;
|
uint32 canonical;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const FourCCAliasEntry kFourCCAliases[] = {
|
static const struct FourCCAliasEntry kFourCCAliases[] = {
|
||||||
{FOURCC_IYUV, FOURCC_I420},
|
{FOURCC_IYUV, FOURCC_I420},
|
||||||
{FOURCC_YU16, FOURCC_I422},
|
{FOURCC_YU16, FOURCC_I422},
|
||||||
{FOURCC_YU24, FOURCC_I444},
|
{FOURCC_YU24, FOURCC_I444},
|
||||||
@ -47,7 +47,8 @@ static const FourCCAliasEntry kFourCCAliases[] = {
|
|||||||
|
|
||||||
LIBYUV_API
|
LIBYUV_API
|
||||||
uint32 CanonicalFourCC(uint32 fourcc) {
|
uint32 CanonicalFourCC(uint32 fourcc) {
|
||||||
for (int i = 0; i < ARRAY_SIZE(kFourCCAliases); ++i) {
|
int i;
|
||||||
|
for (i = 0; i < ARRAY_SIZE(kFourCCAliases); ++i) {
|
||||||
if (kFourCCAliases[i].alias == fourcc) {
|
if (kFourCCAliases[i].alias == fourcc) {
|
||||||
return kFourCCAliases[i].canonical;
|
return kFourCCAliases[i].canonical;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user