| 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 #include "media/base/simd/convert_rgb_to_yuv.h" |
| 6 |
| 5 #include <stdint.h> | 7 #include <stdint.h> |
| 6 | 8 |
| 9 #include <memory> |
| 10 |
| 7 #include "base/cpu.h" | 11 #include "base/cpu.h" |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "media/base/simd/convert_rgb_to_yuv.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 // Reference code that converts RGB pixels to YUV pixels. | 16 // Reference code that converts RGB pixels to YUV pixels. |
| 15 int ConvertRGBToY(const uint8_t* rgb) { | 17 int ConvertRGBToY(const uint8_t* rgb) { |
| 16 int y = 25 * rgb[0] + 129 * rgb[1] + 66 * rgb[2]; | 18 int y = 25 * rgb[0] + 129 * rgb[1] + 66 * rgb[2]; |
| 17 y = ((y + 128) >> 8) + 16; | 19 y = ((y + 128) >> 8) + 16; |
| 18 return std::max(0, std::min(255, y)); | 20 return std::max(0, std::min(255, y)); |
| 19 } | 21 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 if (!cpu.has_ssse3()) | 53 if (!cpu.has_ssse3()) |
| 52 return; | 54 return; |
| 53 | 55 |
| 54 // This test checks a subset of all RGB values so this test does not take so | 56 // This test checks a subset of all RGB values so this test does not take so |
| 55 // long time. | 57 // long time. |
| 56 const int kStep = 8; | 58 const int kStep = 8; |
| 57 const int kWidth = 256 / kStep; | 59 const int kWidth = 256 / kStep; |
| 58 | 60 |
| 59 for (int size = 3; size <= 4; ++size) { | 61 for (int size = 3; size <= 4; ++size) { |
| 60 // Create the output buffers. | 62 // Create the output buffers. |
| 61 scoped_ptr<uint8_t[]> rgb(new uint8_t[kWidth * size]); | 63 std::unique_ptr<uint8_t[]> rgb(new uint8_t[kWidth * size]); |
| 62 scoped_ptr<uint8_t[]> y(new uint8_t[kWidth]); | 64 std::unique_ptr<uint8_t[]> y(new uint8_t[kWidth]); |
| 63 scoped_ptr<uint8_t[]> u(new uint8_t[kWidth / 2]); | 65 std::unique_ptr<uint8_t[]> u(new uint8_t[kWidth / 2]); |
| 64 scoped_ptr<uint8_t[]> v(new uint8_t[kWidth / 2]); | 66 std::unique_ptr<uint8_t[]> v(new uint8_t[kWidth / 2]); |
| 65 | 67 |
| 66 // Choose the function that converts from RGB pixels to YUV ones. | 68 // Choose the function that converts from RGB pixels to YUV ones. |
| 67 void (*convert)(const uint8_t*, uint8_t*, uint8_t*, uint8_t*, int, int, int, | 69 void (*convert)(const uint8_t*, uint8_t*, uint8_t*, uint8_t*, int, int, int, |
| 68 int, int) = NULL; | 70 int, int) = NULL; |
| 69 if (size == 3) | 71 if (size == 3) |
| 70 convert = media::ConvertRGB24ToYUV_SSSE3; | 72 convert = media::ConvertRGB24ToYUV_SSSE3; |
| 71 else | 73 else |
| 72 convert = media::ConvertRGB32ToYUV_SSSE3; | 74 convert = media::ConvertRGB32ToYUV_SSSE3; |
| 73 | 75 |
| 74 int total_error = 0; | 76 int total_error = 0; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 const uint8_t* p = &rgb[i * 2 * size]; | 109 const uint8_t* p = &rgb[i * 2 * size]; |
| 108 int error = ConvertRGBToV(p, size) - v[i]; | 110 int error = ConvertRGBToV(p, size) - v[i]; |
| 109 total_error += error > 0 ? error : -error; | 111 total_error += error > 0 ? error : -error; |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 } | 114 } |
| 113 | 115 |
| 114 EXPECT_EQ(0, total_error); | 116 EXPECT_EQ(0, total_error); |
| 115 } | 117 } |
| 116 } | 118 } |
| OLD | NEW |