Commit 959b290a authored by fbarchard@google.com's avatar fbarchard@google.com

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
parent dd499580
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 949
Version: 950
License: BSD
License File: LICENSE
......
......@@ -98,6 +98,10 @@ typedef signed char int8;
#endif // __GNUC__
#endif // LIBYUV_API
#define LIBYUV_BOOL int
#define LIBYUV_FALSE 0
#define LIBYUV_TRUE 1
// Visual C x86 or GCC little endian.
#if defined(__x86_64__) || defined(_M_X64) || \
defined(__i386__) || defined(_M_IX86) || \
......
......@@ -20,7 +20,7 @@ extern "C" {
// TODO(fbarchard): Consider overlapping bits for different architectures.
// Internal flag to indicate cpuid requires initialization.
static const int kCpuInit = 0x1;
#define kCpuInit 0x1
// These flags are only valid on ARM processors.
static const int kCpuHasARM = 0x2;
......
......@@ -11,10 +11,9 @@
#ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_ // NOLINT
#define INCLUDE_LIBYUV_MJPEG_DECODER_H_
#ifdef __cplusplus
#include "libyuv/basic_types.h"
#ifdef __cplusplus
// NOTE: For a simplified public API use convert.h MJPGToI420().
struct jpeg_common_struct;
......@@ -23,7 +22,15 @@ struct jpeg_source_mgr;
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;
......
......@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 949
#define LIBYUV_VERSION 950
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
......@@ -48,7 +48,7 @@ LIBYUV_API
void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
#if defined(_MSC_VER)
#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)
__asm {
mov eax, info_eax
......@@ -62,7 +62,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
}
#else
if (info_ecx == 0) {
__cpuid(reinterpret_cast<int*>(cpu_info), info_eax);
__cpuid((int*)(cpu_info), info_eax);
} else {
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() {
uint32 xcr0 = 0u;
#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)
__asm {
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.
#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);
if (var) {
if (var[0] != '0') {
return true;
return LIBYUV_TRUE;
}
}
return false;
return LIBYUV_FALSE;
}
#else // nacl does not support getenv().
static bool TestEnv(const char*) {
return false;
static LIBYUV_BOOL TestEnv(const char*) {
return LIBYUV_FALSE;
}
#endif
......
......@@ -10,32 +10,38 @@
#include "libyuv/mjpeg_decoder.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {
#endif
// Helper function to validate the jpeg appears intact.
// 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) {
// ERROR: Invalid jpeg size: sample_size
return false;
return LIBYUV_FALSE;
}
if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image
// 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] == 0xff && sample[i + 1] == 0xd9) { // End Of Image
return true;
return LIBYUV_TRUE; // Success: Valid jpeg.
}
--i;
}
--i;
}
// ERROR: Invalid jpeg end code not found. Size sample_size
return false;
return LIBYUV_FALSE;
}
#ifdef __cplusplus
} // extern "C"
} // namespace libyuv
#endif
......@@ -16,14 +16,14 @@ namespace libyuv {
extern "C" {
#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 {
uint32 alias;
uint32 canonical;
};
static const FourCCAliasEntry kFourCCAliases[] = {
static const struct FourCCAliasEntry kFourCCAliases[] = {
{FOURCC_IYUV, FOURCC_I420},
{FOURCC_YU16, FOURCC_I422},
{FOURCC_YU24, FOURCC_I444},
......@@ -47,7 +47,8 @@ static const FourCCAliasEntry kFourCCAliases[] = {
LIBYUV_API
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) {
return kFourCCAliases[i].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