| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/cpu.h" |
| 5 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 6 #include "media/base/cpu_features.h" | |
| 7 #include "media/base/simd/convert_rgb_to_yuv.h" | 7 #include "media/base/simd/convert_rgb_to_yuv.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 // Reference code that converts RGB pixels to YUV pixels. | 12 // Reference code that converts RGB pixels to YUV pixels. |
| 13 int ConvertRGBToY(const uint8* rgb) { | 13 int ConvertRGBToY(const uint8* rgb) { |
| 14 int y = 25 * rgb[0] + 129 * rgb[1] + 66 * rgb[2]; | 14 int y = 25 * rgb[0] + 129 * rgb[1] + 66 * rgb[2]; |
| 15 y = ((y + 128) >> 8) + 16; | 15 y = ((y + 128) >> 8) + 16; |
| 16 return std::max(0, std::min(255, y)); | 16 return std::max(0, std::min(255, y)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 // A side-by-side test that verifies our ASM functions that convert RGB pixels | 47 // A side-by-side test that verifies our ASM functions that convert RGB pixels |
| 48 // to YUV pixels can output the expected results. This test converts RGB pixels | 48 // to YUV pixels can output the expected results. This test converts RGB pixels |
| 49 // to YUV pixels with our ASM functions (which use SSE, SSE2, SSE3, and SSSE3) | 49 // to YUV pixels with our ASM functions (which use SSE, SSE2, SSE3, and SSSE3) |
| 50 // and compare the output YUV pixels with the ones calculated with out reference | 50 // and compare the output YUV pixels with the ones calculated with out reference |
| 51 // functions implemented in C++. | 51 // functions implemented in C++. |
| 52 TEST(YUVConvertTest, SideBySideRGB) { | 52 TEST(YUVConvertTest, SideBySideRGB) { |
| 53 // We skip this test on PCs which does not support SSE3 because this test | 53 // We skip this test on PCs which does not support SSE3 because this test |
| 54 // needs it. | 54 // needs it. |
| 55 if (!media::hasSSSE3()) | 55 base::CPU cpu; |
| 56 if (!cpu.has_ssse3()) |
| 56 return; | 57 return; |
| 57 | 58 |
| 58 // This test checks a subset of all RGB values so this test does not take so | 59 // This test checks a subset of all RGB values so this test does not take so |
| 59 // long time. | 60 // long time. |
| 60 const int kStep = 8; | 61 const int kStep = 8; |
| 61 const int kWidth = 256 / kStep; | 62 const int kWidth = 256 / kStep; |
| 62 | 63 |
| 63 #ifdef ENABLE_SUBSAMPLING | 64 #ifdef ENABLE_SUBSAMPLING |
| 64 const bool kSubsampling = true; | 65 const bool kSubsampling = true; |
| 65 #else | 66 #else |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 const uint8* p = &rgb[i * 2 * size]; | 118 const uint8* p = &rgb[i * 2 * size]; |
| 118 int error = ConvertRGBToV(p, size, kSubsampling) - v[i]; | 119 int error = ConvertRGBToV(p, size, kSubsampling) - v[i]; |
| 119 total_error += error > 0 ? error : -error; | 120 total_error += error > 0 ? error : -error; |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 EXPECT_EQ(0, total_error); | 125 EXPECT_EQ(0, total_error); |
| 125 } | 126 } |
| 126 } | 127 } |
| OLD | NEW |