Commit 33d34eaa authored by fbarchard@google.com's avatar fbarchard@google.com

C header compatible

BUG=207
TEST=created .c file that includes libyuv.h
Review URL: https://webrtc-codereview.appspot.com/1228004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@617 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 597900a7
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 616 Version: 617
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -243,7 +243,7 @@ int ConvertToI420(const uint8* src_frame, size_t src_size, ...@@ -243,7 +243,7 @@ int ConvertToI420(const uint8* src_frame, size_t src_size,
int crop_x, int crop_y, int crop_x, int crop_y,
int src_width, int src_height, int src_width, int src_height,
int dst_width, int dst_height, int dst_width, int dst_height,
RotationMode rotation, enum RotationMode rotation,
uint32 format); uint32 format);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -214,7 +214,7 @@ int ConvertToARGB(const uint8* src_frame, size_t src_size, ...@@ -214,7 +214,7 @@ int ConvertToARGB(const uint8* src_frame, size_t src_size,
int crop_x, int crop_y, int crop_x, int crop_y,
int src_width, int src_height, int src_width, int src_height,
int dst_width, int dst_height, int dst_width, int dst_height,
RotationMode rotation, enum RotationMode rotation,
uint32 format); uint32 format);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#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"
// NOTE: For a simplified public API use convert.h MJPGToI420(). // NOTE: For a simplified public API use convert.h MJPGToI420().
...@@ -185,4 +187,5 @@ class MJpegDecoder { ...@@ -185,4 +187,5 @@ class MJpegDecoder {
} // namespace libyuv } // namespace libyuv
#endif // __cplusplus
#endif // INCLUDE_LIBYUV_MJPEG_DECODER_H_ NOLINT #endif // INCLUDE_LIBYUV_MJPEG_DECODER_H_ NOLINT
...@@ -39,7 +39,7 @@ int I420Rotate(const uint8* src_y, int src_stride_y, ...@@ -39,7 +39,7 @@ int I420Rotate(const uint8* src_y, int src_stride_y,
uint8* dst_y, int dst_stride_y, uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u, uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v, uint8* dst_v, int dst_stride_v,
int src_width, int src_height, RotationMode mode); int src_width, int src_height, enum RotationMode mode);
// Rotate NV12 input and store in I420. // Rotate NV12 input and store in I420.
LIBYUV_API LIBYUV_API
...@@ -48,7 +48,7 @@ int NV12ToI420Rotate(const uint8* src_y, int src_stride_y, ...@@ -48,7 +48,7 @@ int NV12ToI420Rotate(const uint8* src_y, int src_stride_y,
uint8* dst_y, int dst_stride_y, uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u, uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v, uint8* dst_v, int dst_stride_v,
int src_width, int src_height, RotationMode mode); int src_width, int src_height, enum RotationMode mode);
// Rotate planes by 90, 180, 270 // Rotate planes by 90, 180, 270
LIBYUV_API LIBYUV_API
......
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
LIBYUV_API LIBYUV_API
int ARGBRotate(const uint8* src_argb, int src_stride_argb, int ARGBRotate(const uint8* src_argb, int src_stride_argb,
uint8* dst_argb, int dst_stride_argb, uint8* dst_argb, int dst_stride_argb,
int src_width, int src_height, RotationMode mode); int src_width, int src_height, enum RotationMode mode);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -31,7 +31,7 @@ void ScalePlane(const uint8* src, int src_stride, ...@@ -31,7 +31,7 @@ void ScalePlane(const uint8* src, int src_stride,
int src_width, int src_height, int src_width, int src_height,
uint8* dst, int dst_stride, uint8* dst, int dst_stride,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering); enum FilterMode filtering);
// Scales a YUV 4:2:0 image from the src width and height to the // Scales a YUV 4:2:0 image from the src width and height to the
// dst width and height. // dst width and height.
...@@ -52,8 +52,9 @@ int I420Scale(const uint8* src_y, int src_stride_y, ...@@ -52,8 +52,9 @@ int I420Scale(const uint8* src_y, int src_stride_y,
uint8* dst_u, int dst_stride_u, uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v, uint8* dst_v, int dst_stride_v,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering); enum FilterMode filtering);
#ifdef __cplusplus
// Legacy API. Deprecated. // Legacy API. Deprecated.
LIBYUV_API LIBYUV_API
int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v, int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v,
...@@ -73,6 +74,7 @@ int ScaleOffset(const uint8* src_i420, int src_width, int src_height, ...@@ -73,6 +74,7 @@ int ScaleOffset(const uint8* src_i420, int src_width, int src_height,
// For testing, allow disabling of specialized scalers. // For testing, allow disabling of specialized scalers.
LIBYUV_API LIBYUV_API
void SetUseReferenceImpl(bool use); void SetUseReferenceImpl(bool use);
#endif // __cplusplus
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -24,7 +24,7 @@ int ARGBScale(const uint8* src_argb, int src_stride_argb, ...@@ -24,7 +24,7 @@ int ARGBScale(const uint8* src_argb, int src_stride_argb,
int src_width, int src_height, int src_width, int src_height,
uint8* dst_argb, int dst_stride_argb, uint8* dst_argb, int dst_stride_argb,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering); enum FilterMode filtering);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -11,6 +11,6 @@ ...@@ -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 616 #define LIBYUV_VERSION 617
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -27,9 +27,15 @@ extern "C" { ...@@ -27,9 +27,15 @@ extern "C" {
// Convert four characters to a FourCC code. // Convert four characters to a FourCC code.
// Needs to be a macro otherwise the OS X compiler complains when the kFormat* // Needs to be a macro otherwise the OS X compiler complains when the kFormat*
// constants are used in a switch. // constants are used in a switch.
#ifdef __cplusplus
#define FOURCC(a, b, c, d) ( \ #define FOURCC(a, b, c, d) ( \
(static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ (static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
(static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
#else
#define FOURCC(a, b, c, d) ( \
((uint32)(a)) | ((uint32)(b) << 8) | /* NOLINT */ \
((uint32)(c) << 16) | ((uint32)(d) << 24)) /* NOLINT */
#endif
// Some pages discussing FourCC codes: // Some pages discussing FourCC codes:
// http://www.fourcc.org/yuv.php // http://www.fourcc.org/yuv.php
......
...@@ -82,6 +82,17 @@ ...@@ -82,6 +82,17 @@
'util/ssim.cc', 'util/ssim.cc',
], ],
}, },
{
'target_name': 'cpuid',
'type': 'executable',
'sources': [
# sources
'util/cpuid.c',
],
'dependencies': [
'libyuv.gyp:libyuv',
],
},
], # targets ], # targets
} }
......
/*
* Copyright 2012 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INCLUDE_LIBYUV_COMPARE_H_
#include "libyuv.h"
#include "./psnr.h"
#include "./ssim.h"
int main(int argc, const char* argv[]) {
int cpu_flags = TestCpuFlag(-1);
int has_arm = TestCpuFlag(kCpuHasARM);
int has_avx = TestCpuFlag(kCpuHasAVX);
int has_avx2 = TestCpuFlag(kCpuHasAVX2);
int has_mips = TestCpuFlag(kCpuHasMIPS);
int has_mips_dsp = TestCpuFlag(kCpuHasMIPS_DSP);
int has_mips_dspr2 = TestCpuFlag(kCpuHasMIPS_DSPR2);
int has_movbe = TestCpuFlag(kCpuHasMOVBE);
int has_neon = TestCpuFlag(kCpuHasNEON);
int has_sse2 = TestCpuFlag(kCpuHasSSE2);
int has_sse41 = TestCpuFlag(kCpuHasSSE41);
int has_sse42 = TestCpuFlag(kCpuHasSSE42);
int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
int has_x86 = TestCpuFlag(kCpuHasX86);
#if defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64)
if (has_x86) {
int family, model, cpu_info[4];
// Vendor ID:
// AuthenticAMD AMD processor
// CentaurHauls Centaur processor
// CyrixInstead Cyrix processor
// GenuineIntel Intel processor
// GenuineTMx86 Transmeta processor
// Geode by NSC National Semiconductor processor
// NexGenDriven NexGen processor
// RiseRiseRise Rise Technology processor
// SiS SiS SiS SiS processor
// UMC UMC UMC UMC processor
CpuId(cpu_info, 0);
cpu_info[0] = cpu_info[1]; // Reorder output
cpu_info[1] = cpu_info[3];
cpu_info[3] = 0;
printf("Cpu Vendor: %s\n", (char*)(&cpu_info[0]));
// CPU Family and Model
// 3:0 - Stepping
// 7:4 - Model
// 11:8 - Family
// 13:12 - Processor Type
// 19:16 - Extended Model
// 27:20 - Extended Family
CpuId(cpu_info, 1);
family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family,
model, model);
}
#endif
printf("Cpu Flags %x\n", cpu_flags);
printf("Has ARM %x\n", has_arm);
printf("Has AVX %x\n", has_avx);
printf("Has AVX2 %x\n", has_avx2);
printf("Has MIPS %x\n", has_mips);
printf("Has MIPS DSP %x\n", has_mips_dsp);
printf("Has MIPS DSPR2 %x\n", has_mips_dspr2);
printf("Has MOVBE %x\n", has_movbe);
printf("Has NEON %x\n", has_neon);
printf("Has SSE2 %x\n", has_sse2);
printf("Has SSE4.1 %x\n", has_sse41);
printf("Has SSE4.2 %x\n", has_sse42);
printf("Has SSSE3 %x\n", has_ssse3);
printf("Has X86 %x\n", has_x86);
return 0;
}
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include <intrin.h> // For __cpuid() #include <intrin.h> // For __cpuid()
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int uint32; // NOLINT typedef unsigned int uint32; // NOLINT
#ifdef _MSC_VER #ifdef _MSC_VER
typedef unsigned __int64 uint64; typedef unsigned __int64 uint64;
...@@ -43,7 +47,7 @@ double ComputePSNR(double sse, double size) { ...@@ -43,7 +47,7 @@ double ComputePSNR(double sse, double size) {
static uint32 SumSquareError_NEON(const uint8* src_a, static uint32 SumSquareError_NEON(const uint8* src_a,
const uint8* src_b, int count) { const uint8* src_b, int count) {
volatile uint32 sse; volatile uint32 sse;
asm volatile ( asm volatile ( // NOLINT
"vmov.u8 q7, #0 \n" "vmov.u8 q7, #0 \n"
"vmov.u8 q9, #0 \n" "vmov.u8 q9, #0 \n"
"vmov.u8 q8, #0 \n" "vmov.u8 q8, #0 \n"
...@@ -72,8 +76,7 @@ static uint32 SumSquareError_NEON(const uint8* src_a, ...@@ -72,8 +76,7 @@ static uint32 SumSquareError_NEON(const uint8* src_a,
"+r"(count), "+r"(count),
"=r"(sse) "=r"(sse)
: :
: "memory", "cc", "q0", "q1", "q2", "q3", "q7", "q8", "q9", "q10" : "memory", "cc", "q0", "q1", "q2", "q3", "q7", "q8", "q9", "q10");
);
return sse; return sse;
} }
#elif !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) #elif !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86)
...@@ -120,7 +123,7 @@ static uint32 SumSquareError_SSE2(const uint8* /*src_a*/, ...@@ -120,7 +123,7 @@ static uint32 SumSquareError_SSE2(const uint8* /*src_a*/,
static uint32 SumSquareError_SSE2(const uint8* src_a, static uint32 SumSquareError_SSE2(const uint8* src_a,
const uint8* src_b, int count) { const uint8* src_b, int count) {
uint32 sse; uint32 sse;
asm volatile ( asm volatile ( // NOLINT
"pxor %%xmm0,%%xmm0 \n" "pxor %%xmm0,%%xmm0 \n"
"pxor %%xmm5,%%xmm5 \n" "pxor %%xmm5,%%xmm5 \n"
"sub %0,%1 \n" "sub %0,%1 \n"
...@@ -158,7 +161,7 @@ static uint32 SumSquareError_SSE2(const uint8* src_a, ...@@ -158,7 +161,7 @@ static uint32 SumSquareError_SSE2(const uint8* src_a,
#if defined(__SSE2__) #if defined(__SSE2__)
, "xmm0", "xmm1", "xmm2", "xmm5" , "xmm0", "xmm1", "xmm2", "xmm5"
#endif #endif
); ); // NOLINT
return sse; return sse;
} }
#endif // LIBYUV_DISABLE_X86 etc #endif // LIBYUV_DISABLE_X86 etc
...@@ -166,21 +169,19 @@ static uint32 SumSquareError_SSE2(const uint8* src_a, ...@@ -166,21 +169,19 @@ static uint32 SumSquareError_SSE2(const uint8* src_a,
#if defined(HAS_SUMSQUAREERROR_SSE2) #if defined(HAS_SUMSQUAREERROR_SSE2)
#if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__) #if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__)
static __inline void __cpuid(int cpu_info[4], int info_type) { static __inline void __cpuid(int cpu_info[4], int info_type) {
asm volatile ( asm volatile ( // NOLINT
"mov %%ebx, %%edi \n" "mov %%ebx, %%edi \n"
"cpuid \n" "cpuid \n"
"xchg %%edi, %%ebx \n" "xchg %%edi, %%ebx \n"
: "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type) : "a"(info_type));
);
} }
#elif defined(__i386__) || defined(__x86_64__) #elif defined(__i386__) || defined(__x86_64__)
static __inline void __cpuid(int cpu_info[4], int info_type) { static __inline void __cpuid(int cpu_info[4], int info_type) {
asm volatile ( asm volatile ( // NOLINT
"cpuid \n" "cpuid \n"
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type) : "a"(info_type));
);
} }
#endif #endif
...@@ -240,3 +241,8 @@ double ComputeSumSquareError(const uint8* src_a, ...@@ -240,3 +241,8 @@ double ComputeSumSquareError(const uint8* src_a,
} }
return static_cast<double>(sse); return static_cast<double>(sse);
} }
#ifdef __cplusplus
} // extern "C"
#endif
...@@ -13,7 +13,14 @@ ...@@ -13,7 +13,14 @@
#ifndef UTIL_PSNR_H_ #ifndef UTIL_PSNR_H_
#define UTIL_PSNR_H_ #define UTIL_PSNR_H_
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(INT_TYPES_DEFINED) && !defined(UINT8_TYPE_DEFINED)
typedef unsigned char uint8; typedef unsigned char uint8;
#define UINT8_TYPE_DEFINED
#endif
static const double kMaxPSNR = 128.0; static const double kMaxPSNR = 128.0;
...@@ -25,4 +32,8 @@ double ComputePSNR(double sse, double size); ...@@ -25,4 +32,8 @@ double ComputePSNR(double sse, double size);
// Pass this to ComputePSNR for final result. // Pass this to ComputePSNR for final result.
double ComputeSumSquareError(const uint8* org, const uint8* rec, int size); double ComputeSumSquareError(const uint8* org, const uint8* rec, int size);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // UTIL_PSNR_H_ #endif // UTIL_PSNR_H_
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int uint32; // NOLINT typedef unsigned int uint32; // NOLINT
typedef unsigned short uint16; // NOLINT typedef unsigned short uint16; // NOLINT
...@@ -325,3 +329,8 @@ double CalcSSIM(const uint8 *org, const uint8 *rec, ...@@ -325,3 +329,8 @@ double CalcSSIM(const uint8 *org, const uint8 *rec,
double CalcLSSIM(double ssim) { double CalcLSSIM(double ssim) {
return -10.0 * log10(1.0 - ssim); return -10.0 * log10(1.0 - ssim);
} }
#ifdef __cplusplus
} // extern "C"
#endif
...@@ -13,7 +13,14 @@ ...@@ -13,7 +13,14 @@
#ifndef UTIL_SSIM_H_ #ifndef UTIL_SSIM_H_
#define UTIL_SSIM_H_ #define UTIL_SSIM_H_
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(INT_TYPES_DEFINED) && !defined(UINT8_TYPE_DEFINED)
typedef unsigned char uint8; typedef unsigned char uint8;
#define UINT8_TYPE_DEFINED
#endif
double CalcSSIM(const uint8* org, const uint8* rec, double CalcSSIM(const uint8* org, const uint8* rec,
const int image_width, const int image_height); const int image_width, const int image_height);
...@@ -21,4 +28,8 @@ double CalcSSIM(const uint8* org, const uint8* rec, ...@@ -21,4 +28,8 @@ double CalcSSIM(const uint8* org, const uint8* rec,
// does -10.0 * log10(1.0 - ssim) // does -10.0 * log10(1.0 - ssim)
double CalcLSSIM(double ssim); double CalcLSSIM(double ssim);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // UTIL_SSIM_H_ #endif // UTIL_SSIM_H_
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