1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // yuv_row internal functions to handle YUV conversion and scaling to RGB. 6 // These functions are used from both yuv_convert.cc and yuv_scale.cc. 7 8 // TODO(fbarchard): Write function that can handle rotation and scaling. 9 10 #ifndef MEDIA_BASE_YUV_ROW_H_ 11 #define MEDIA_BASE_YUV_ROW_H_ 12 13 #include "chromium_types.h" 14 15 extern "C" { 16 // Can only do 1x. 17 // This is the second fastest of the scalers. 18 void FastConvertYUVToRGB32Row(const uint8* y_buf, 19 const uint8* u_buf, 20 const uint8* v_buf, 21 uint8* rgb_buf, 22 int width); 23 24 void FastConvertYUVToRGB32Row_C(const uint8* y_buf, 25 const uint8* u_buf, 26 const uint8* v_buf, 27 uint8* rgb_buf, 28 int width, 29 unsigned int x_shift); 30 31 void FastConvertYUVToRGB32Row(const uint8* y_buf, 32 const uint8* u_buf, 33 const uint8* v_buf, 34 uint8* rgb_buf, 35 int width); 36 37 // Can do 1x, half size or any scale down by an integer amount. 38 // Step can be negative (mirroring, rotate 180). 39 // This is the third fastest of the scalers. 40 // Only defined on Windows x86-32. 41 void ConvertYUVToRGB32Row_SSE(const uint8* y_buf, 42 const uint8* u_buf, 43 const uint8* v_buf, 44 uint8* rgb_buf, 45 int width, 46 int step); 47 48 // Rotate is like Convert, but applies different step to Y versus U and V. 49 // This allows rotation by 90 or 270, by stepping by stride. 50 // This is the forth fastest of the scalers. 51 // Only defined on Windows x86-32. 52 void RotateConvertYUVToRGB32Row_SSE(const uint8* y_buf, 53 const uint8* u_buf, 54 const uint8* v_buf, 55 uint8* rgb_buf, 56 int width, 57 int ystep, 58 int uvstep); 59 60 // Doubler does 4 pixels at a time. Each pixel is replicated. 61 // This is the fastest of the scalers. 62 // Only defined on Windows x86-32. 63 void DoubleYUVToRGB32Row_SSE(const uint8* y_buf, 64 const uint8* u_buf, 65 const uint8* v_buf, 66 uint8* rgb_buf, 67 int width); 68 69 // Handles arbitrary scaling up or down. 70 // Mirroring is supported, but not 90 or 270 degree rotation. 71 // Chroma is under sampled every 2 pixels for performance. 72 void ScaleYUVToRGB32Row(const uint8* y_buf, 73 const uint8* u_buf, 74 const uint8* v_buf, 75 uint8* rgb_buf, 76 int width, 77 int source_dx); 78 79 void ScaleYUVToRGB32Row(const uint8* y_buf, 80 const uint8* u_buf, 81 const uint8* v_buf, 82 uint8* rgb_buf, 83 int width, 84 int source_dx); 85 86 void ScaleYUVToRGB32Row_C(const uint8* y_buf, 87 const uint8* u_buf, 88 const uint8* v_buf, 89 uint8* rgb_buf, 90 int width, 91 int source_dx); 92 93 // Handles arbitrary scaling up or down with bilinear filtering. 94 // Mirroring is supported, but not 90 or 270 degree rotation. 95 // Chroma is under sampled every 2 pixels for performance. 96 // This is the slowest of the scalers. 97 void LinearScaleYUVToRGB32Row(const uint8* y_buf, 98 const uint8* u_buf, 99 const uint8* v_buf, 100 uint8* rgb_buf, 101 int width, 102 int source_dx); 103 104 void LinearScaleYUVToRGB32Row(const uint8* y_buf, 105 const uint8* u_buf, 106 const uint8* v_buf, 107 uint8* rgb_buf, 108 int width, 109 int source_dx); 110 111 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf, 112 const uint8* u_buf, 113 const uint8* v_buf, 114 uint8* rgb_buf, 115 int width, 116 int source_dx); 117 118 119 #if defined(_MSC_VER) && !defined(__CLR_VER) && !defined(__clang__) 120 #if defined(VISUALC_HAS_AVX2) 121 #define SIMD_ALIGNED(var) __declspec(align(32)) var 122 #else 123 #define SIMD_ALIGNED(var) __declspec(align(16)) var 124 #endif 125 #elif defined(__GNUC__) || defined(__clang__) 126 // Caveat GCC 4.2 to 4.7 have a known issue using vectors with const. 127 #if defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2) 128 #define SIMD_ALIGNED(var) var __attribute__((aligned(32))) 129 #else 130 #define SIMD_ALIGNED(var) var __attribute__((aligned(16))) 131 #endif 132 #else 133 #define SIMD_ALIGNED(var) var 134 #endif 135 136 extern SIMD_ALIGNED(const int16 kCoefficientsRgbY[768][4]); 137 138 // x64 uses MMX2 (SSE) so emms is not required. 139 // Warning C4799: function has no EMMS instruction. 140 // EMMS() is slow and should be called by the calling function once per image. 141 #if defined(ARCH_CPU_X86) && !defined(ARCH_CPU_X86_64) 142 #if defined(_MSC_VER) 143 #define EMMS() __asm emms 144 #pragma warning(disable: 4799) 145 #else 146 #define EMMS() asm("emms") 147 #endif 148 #else 149 #define EMMS() ((void)0) 150 #endif 151 152 } // extern "C" 153 154 #endif // MEDIA_BASE_YUV_ROW_H_ 155