From 33d34eaad81ca9b3e05055f5a669c7ec3cd3fe61 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Fri, 22 Mar 2013 08:40:40 +0000 Subject: [PATCH] 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 --- README.chromium | 2 +- include/libyuv/convert.h | 2 +- include/libyuv/convert_argb.h | 2 +- include/libyuv/mjpeg_decoder.h | 3 ++ include/libyuv/rotate.h | 4 +- include/libyuv/rotate_argb.h | 2 +- include/libyuv/scale.h | 6 ++- include/libyuv/scale_argb.h | 2 +- include/libyuv/version.h | 2 +- include/libyuv/video_common.h | 6 +++ libyuv_test.gyp | 11 +++++ util/cpuid.c | 86 ++++++++++++++++++++++++++++++++++ util/psnr.cc | 28 ++++++----- util/psnr.h | 11 +++++ util/ssim.cc | 9 ++++ util/ssim.h | 11 +++++ 16 files changed, 166 insertions(+), 21 deletions(-) create mode 100644 util/cpuid.c diff --git a/README.chromium b/README.chromium index 4949db590..480e5dd21 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 616 +Version: 617 License: BSD License File: LICENSE diff --git a/include/libyuv/convert.h b/include/libyuv/convert.h index 90b7f222d..dd71cf5bb 100644 --- a/include/libyuv/convert.h +++ b/include/libyuv/convert.h @@ -243,7 +243,7 @@ int ConvertToI420(const uint8* src_frame, size_t src_size, int crop_x, int crop_y, int src_width, int src_height, int dst_width, int dst_height, - RotationMode rotation, + enum RotationMode rotation, uint32 format); #ifdef __cplusplus diff --git a/include/libyuv/convert_argb.h b/include/libyuv/convert_argb.h index 13e9561e1..3f029dc41 100644 --- a/include/libyuv/convert_argb.h +++ b/include/libyuv/convert_argb.h @@ -214,7 +214,7 @@ int ConvertToARGB(const uint8* src_frame, size_t src_size, int crop_x, int crop_y, int src_width, int src_height, int dst_width, int dst_height, - RotationMode rotation, + enum RotationMode rotation, uint32 format); #ifdef __cplusplus diff --git a/include/libyuv/mjpeg_decoder.h b/include/libyuv/mjpeg_decoder.h index 6089b783a..4c09abbe3 100644 --- a/include/libyuv/mjpeg_decoder.h +++ b/include/libyuv/mjpeg_decoder.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_ // NOLINT #define INCLUDE_LIBYUV_MJPEG_DECODER_H_ +#ifdef __cplusplus + #include "libyuv/basic_types.h" // NOTE: For a simplified public API use convert.h MJPGToI420(). @@ -185,4 +187,5 @@ class MJpegDecoder { } // namespace libyuv +#endif // __cplusplus #endif // INCLUDE_LIBYUV_MJPEG_DECODER_H_ NOLINT diff --git a/include/libyuv/rotate.h b/include/libyuv/rotate.h index 0fbe91db8..0b81da086 100644 --- a/include/libyuv/rotate.h +++ b/include/libyuv/rotate.h @@ -39,7 +39,7 @@ int I420Rotate(const uint8* src_y, int src_stride_y, uint8* dst_y, int dst_stride_y, uint8* dst_u, int dst_stride_u, 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. LIBYUV_API @@ -48,7 +48,7 @@ int NV12ToI420Rotate(const uint8* src_y, int src_stride_y, uint8* dst_y, int dst_stride_y, uint8* dst_u, int dst_stride_u, 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 LIBYUV_API diff --git a/include/libyuv/rotate_argb.h b/include/libyuv/rotate_argb.h index 0aa2a2138..660ff5573 100644 --- a/include/libyuv/rotate_argb.h +++ b/include/libyuv/rotate_argb.h @@ -23,7 +23,7 @@ extern "C" { LIBYUV_API int ARGBRotate(const uint8* src_argb, int src_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 } // extern "C" diff --git a/include/libyuv/scale.h b/include/libyuv/scale.h index a1f778f43..b1efc95d2 100644 --- a/include/libyuv/scale.h +++ b/include/libyuv/scale.h @@ -31,7 +31,7 @@ void ScalePlane(const uint8* src, int src_stride, int src_width, int src_height, uint8* dst, int dst_stride, 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 // dst width and height. @@ -52,8 +52,9 @@ int I420Scale(const uint8* src_y, int src_stride_y, uint8* dst_u, int dst_stride_u, uint8* dst_v, int dst_stride_v, int dst_width, int dst_height, - FilterMode filtering); + enum FilterMode filtering); +#ifdef __cplusplus // Legacy API. Deprecated. LIBYUV_API 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, // For testing, allow disabling of specialized scalers. LIBYUV_API void SetUseReferenceImpl(bool use); +#endif // __cplusplus #ifdef __cplusplus } // extern "C" diff --git a/include/libyuv/scale_argb.h b/include/libyuv/scale_argb.h index 1c86f27ce..cd58198b6 100644 --- a/include/libyuv/scale_argb.h +++ b/include/libyuv/scale_argb.h @@ -24,7 +24,7 @@ int ARGBScale(const uint8* src_argb, int src_stride_argb, int src_width, int src_height, uint8* dst_argb, int dst_stride_argb, int dst_width, int dst_height, - FilterMode filtering); + enum FilterMode filtering); #ifdef __cplusplus } // extern "C" diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 65e89b653..a3708ac55 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 616 +#define LIBYUV_VERSION 617 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/include/libyuv/video_common.h b/include/libyuv/video_common.h index 08d89d704..bfb53f935 100644 --- a/include/libyuv/video_common.h +++ b/include/libyuv/video_common.h @@ -27,9 +27,15 @@ extern "C" { // Convert four characters to a FourCC code. // Needs to be a macro otherwise the OS X compiler complains when the kFormat* // constants are used in a switch. +#ifdef __cplusplus #define FOURCC(a, b, c, d) ( \ (static_cast(a)) | (static_cast(b) << 8) | \ (static_cast(c) << 16) | (static_cast(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: // http://www.fourcc.org/yuv.php diff --git a/libyuv_test.gyp b/libyuv_test.gyp index 45c184786..5789ecb29 100644 --- a/libyuv_test.gyp +++ b/libyuv_test.gyp @@ -82,6 +82,17 @@ 'util/ssim.cc', ], }, + { + 'target_name': 'cpuid', + 'type': 'executable', + 'sources': [ + # sources + 'util/cpuid.c', + ], + 'dependencies': [ + 'libyuv.gyp:libyuv', + ], + }, ], # targets } diff --git a/util/cpuid.c b/util/cpuid.c new file mode 100644 index 000000000..be40a17e8 --- /dev/null +++ b/util/cpuid.c @@ -0,0 +1,86 @@ +/* + * 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 +#include +#include + +#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; +} + diff --git a/util/psnr.cc b/util/psnr.cc index a7f6c741b..01b61fc80 100644 --- a/util/psnr.cc +++ b/util/psnr.cc @@ -19,6 +19,10 @@ #include // For __cpuid() #endif +#ifdef __cplusplus +extern "C" { +#endif + typedef unsigned int uint32; // NOLINT #ifdef _MSC_VER typedef unsigned __int64 uint64; @@ -43,7 +47,7 @@ double ComputePSNR(double sse, double size) { static uint32 SumSquareError_NEON(const uint8* src_a, const uint8* src_b, int count) { volatile uint32 sse; - asm volatile ( + asm volatile ( // NOLINT "vmov.u8 q7, #0 \n" "vmov.u8 q9, #0 \n" "vmov.u8 q8, #0 \n" @@ -72,8 +76,7 @@ static uint32 SumSquareError_NEON(const uint8* src_a, "+r"(count), "=r"(sse) : - : "memory", "cc", "q0", "q1", "q2", "q3", "q7", "q8", "q9", "q10" - ); + : "memory", "cc", "q0", "q1", "q2", "q3", "q7", "q8", "q9", "q10"); return sse; } #elif !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) @@ -120,7 +123,7 @@ static uint32 SumSquareError_SSE2(const uint8* /*src_a*/, static uint32 SumSquareError_SSE2(const uint8* src_a, const uint8* src_b, int count) { uint32 sse; - asm volatile ( + asm volatile ( // NOLINT "pxor %%xmm0,%%xmm0 \n" "pxor %%xmm5,%%xmm5 \n" "sub %0,%1 \n" @@ -158,7 +161,7 @@ static uint32 SumSquareError_SSE2(const uint8* src_a, #if defined(__SSE2__) , "xmm0", "xmm1", "xmm2", "xmm5" #endif - ); + ); // NOLINT return sse; } #endif // LIBYUV_DISABLE_X86 etc @@ -166,21 +169,19 @@ static uint32 SumSquareError_SSE2(const uint8* src_a, #if defined(HAS_SUMSQUAREERROR_SSE2) #if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__) static __inline void __cpuid(int cpu_info[4], int info_type) { - asm volatile ( + asm volatile ( // NOLINT "mov %%ebx, %%edi \n" "cpuid \n" "xchg %%edi, %%ebx \n" : "=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__) static __inline void __cpuid(int cpu_info[4], int info_type) { - asm volatile ( + asm volatile ( // NOLINT "cpuid \n" : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) - : "a"(info_type) - ); + : "a"(info_type)); } #endif @@ -240,3 +241,8 @@ double ComputeSumSquareError(const uint8* src_a, } return static_cast(sse); } + +#ifdef __cplusplus +} // extern "C" +#endif + diff --git a/util/psnr.h b/util/psnr.h index 5e6c2b8e5..2cd0b1457 100644 --- a/util/psnr.h +++ b/util/psnr.h @@ -13,7 +13,14 @@ #ifndef 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; +#define UINT8_TYPE_DEFINED +#endif static const double kMaxPSNR = 128.0; @@ -25,4 +32,8 @@ double ComputePSNR(double sse, double size); // Pass this to ComputePSNR for final result. double ComputeSumSquareError(const uint8* org, const uint8* rec, int size); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // UTIL_PSNR_H_ diff --git a/util/ssim.cc b/util/ssim.cc index 9ebbdab43..2131b886b 100644 --- a/util/ssim.cc +++ b/util/ssim.cc @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef unsigned int uint32; // NOLINT typedef unsigned short uint16; // NOLINT @@ -325,3 +329,8 @@ double CalcSSIM(const uint8 *org, const uint8 *rec, double CalcLSSIM(double ssim) { return -10.0 * log10(1.0 - ssim); } + +#ifdef __cplusplus +} // extern "C" +#endif + diff --git a/util/ssim.h b/util/ssim.h index baec20c4f..0689276ad 100644 --- a/util/ssim.h +++ b/util/ssim.h @@ -13,7 +13,14 @@ #ifndef 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; +#define UINT8_TYPE_DEFINED +#endif double CalcSSIM(const uint8* org, const uint8* rec, const int image_width, const int image_height); @@ -21,4 +28,8 @@ double CalcSSIM(const uint8* org, const uint8* rec, // does -10.0 * log10(1.0 - ssim) double CalcLSSIM(double ssim); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // UTIL_SSIM_H_