OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This webpage shows layout of YV12 and other YUV formats | 5 // This webpage shows layout of YV12 and other YUV formats |
6 // http://www.fourcc.org/yuv.php | 6 // http://www.fourcc.org/yuv.php |
7 // The actual conversion is best described here | 7 // The actual conversion is best described here |
8 // http://en.wikipedia.org/wiki/YUV | 8 // http://en.wikipedia.org/wiki/YUV |
9 // An article on optimizing YUV conversion using tables instead of multiplies | 9 // An article on optimizing YUV conversion using tables instead of multiplies |
10 // http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf | 10 // http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf |
11 // | 11 // |
12 // YV12 is a full plane of Y and a half height, half width chroma planes | 12 // YV12 is a full plane of Y and a half height, half width chroma planes |
13 // YV16 is a full plane of Y and a full height, half width chroma planes | 13 // YV16 is a full plane of Y and a full height, half width chroma planes |
14 // | 14 // |
15 // ARGB pixel format is output, which on little endian is stored as BGRA. | 15 // ARGB pixel format is output, which on little endian is stored as BGRA. |
16 // The alpha is set to 255, allowing the application to use RGBA or RGB32. | 16 // The alpha is set to 255, allowing the application to use RGBA or RGB32. |
17 | 17 |
18 #include "media/base/yuv_convert.h" | 18 #include "media/base/yuv_convert.h" |
19 | 19 |
20 #include "base/cpu.h" | 20 #include "base/cpu.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "media/base/simd/convert_rgb_to_yuv.h" | 24 #include "media/base/simd/convert_rgb_to_yuv.h" |
25 #include "media/base/simd/convert_yuv_to_rgb.h" | 25 #include "media/base/simd/convert_yuv_to_rgb.h" |
| 26 #include "media/base/simd/empty_register_state.h" |
26 #include "media/base/simd/filter_yuv.h" | 27 #include "media/base/simd/filter_yuv.h" |
27 | 28 |
28 #if defined(ARCH_CPU_X86_FAMILY) | 29 #if defined(ARCH_CPU_X86_FAMILY) |
29 #if defined(COMPILER_MSVC) | 30 #if defined(COMPILER_MSVC) |
30 #include <intrin.h> | 31 #include <intrin.h> |
31 #else | 32 #else |
32 #include <mmintrin.h> | 33 #include <mmintrin.h> |
33 #endif | 34 #endif |
34 #endif | 35 #endif |
35 | 36 |
36 namespace media { | 37 namespace media { |
37 | 38 |
38 static FilterYUVRowsProc ChooseFilterYUVRowsProc() { | 39 static FilterYUVRowsProc ChooseFilterYUVRowsProc() { |
39 #if defined(ARCH_CPU_X86_FAMILY) | 40 #if defined(ARCH_CPU_X86_FAMILY) |
40 base::CPU cpu; | 41 base::CPU cpu; |
41 if (cpu.has_sse2()) | 42 if (cpu.has_sse2()) |
42 return &FilterYUVRows_SSE2; | 43 return &FilterYUVRows_SSE2; |
| 44 |
| 45 #if !defined(MEDIA_DO_NOT_USE_MMX_INTRINSICS) |
43 if (cpu.has_mmx()) | 46 if (cpu.has_mmx()) |
44 return &FilterYUVRows_MMX; | 47 return &FilterYUVRows_MMX; |
45 #endif | 48 #endif // !defined(MEDIA_DO_NOT_USE_MMX_INTRINSICS) |
| 49 #endif // defined(ARCH_CPU_X86_FAMILY) |
46 return &FilterYUVRows_C; | 50 return &FilterYUVRows_C; |
47 } | 51 } |
48 | 52 |
49 static ConvertYUVToRGB32RowProc ChooseConvertYUVToRGB32RowProc() { | 53 static ConvertYUVToRGB32RowProc ChooseConvertYUVToRGB32RowProc() { |
50 #if defined(ARCH_CPU_X86_FAMILY) | 54 #if defined(ARCH_CPU_X86_FAMILY) |
51 base::CPU cpu; | 55 base::CPU cpu; |
52 if (cpu.has_sse()) | 56 if (cpu.has_sse()) |
53 return &ConvertYUVToRGB32Row_SSE; | 57 return &ConvertYUVToRGB32Row_SSE; |
54 if (cpu.has_mmx()) | 58 if (cpu.has_mmx()) |
55 return &ConvertYUVToRGB32Row_MMX; | 59 return &ConvertYUVToRGB32Row_MMX; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Empty SIMD registers state after using them. | 94 // Empty SIMD registers state after using them. |
91 void EmptyRegisterState() { | 95 void EmptyRegisterState() { |
92 #if defined(ARCH_CPU_X86_FAMILY) | 96 #if defined(ARCH_CPU_X86_FAMILY) |
93 static bool checked = false; | 97 static bool checked = false; |
94 static bool has_mmx = false; | 98 static bool has_mmx = false; |
95 if (!checked) { | 99 if (!checked) { |
96 base::CPU cpu; | 100 base::CPU cpu; |
97 has_mmx = cpu.has_mmx(); | 101 has_mmx = cpu.has_mmx(); |
98 checked = true; | 102 checked = true; |
99 } | 103 } |
100 if (has_mmx) | 104 |
| 105 if (has_mmx) { |
| 106 #if defined(MEDIA_DO_NOT_USE_MMX_INTRINSICS) |
| 107 EmptyRegisterState_MMX(); |
| 108 #else |
101 _mm_empty(); | 109 _mm_empty(); |
102 #endif | 110 #endif // defined(MEDIA_DO_NOT_USE_MMX_INTRINSICS) |
| 111 } |
| 112 |
| 113 #endif // defined(ARCH_CPU_X86_FAMILY) |
103 } | 114 } |
104 | 115 |
105 // 16.16 fixed point arithmetic | 116 // 16.16 fixed point arithmetic |
106 const int kFractionBits = 16; | 117 const int kFractionBits = 16; |
107 const int kFractionMax = 1 << kFractionBits; | 118 const int kFractionMax = 1 << kFractionBits; |
108 const int kFractionMask = ((1 << kFractionBits) - 1); | 119 const int kFractionMask = ((1 << kFractionBits) - 1); |
109 | 120 |
110 // Scale a frame of YUV to 32 bit ARGB. | 121 // Scale a frame of YUV to 32 bit ARGB. |
111 void ScaleYUVToRGB32(const uint8* y_buf, | 122 void ScaleYUVToRGB32(const uint8* y_buf, |
112 const uint8* u_buf, | 123 const uint8* u_buf, |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 else | 593 else |
583 convert_proc = &ConvertYUVToRGB32_C; | 594 convert_proc = &ConvertYUVToRGB32_C; |
584 } | 595 } |
585 | 596 |
586 convert_proc(yplane, uplane, vplane, rgbframe, | 597 convert_proc(yplane, uplane, vplane, rgbframe, |
587 width, height, ystride, uvstride, rgbstride, yuv_type); | 598 width, height, ystride, uvstride, rgbstride, yuv_type); |
588 #endif | 599 #endif |
589 } | 600 } |
590 | 601 |
591 } // namespace media | 602 } // namespace media |
OLD | NEW |