OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2010 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <sstream> | 11 #include <sstream> |
12 | 12 |
13 #include "libyuv/cpu_id.h" | 13 #include "libyuv/cpu_id.h" |
14 #include "libyuv/scale.h" | 14 #include "libyuv/scale.h" |
15 #include "webrtc/base/basictypes.h" | 15 #include "webrtc/base/basictypes.h" |
16 #include "webrtc/base/flags.h" | 16 #include "webrtc/base/flags.h" |
17 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
18 #include "webrtc/base/scoped_ptr.h" | |
19 #include "webrtc/media/base/testutils.h" | 18 #include "webrtc/media/base/testutils.h" |
20 | 19 |
21 #if defined(_MSC_VER) | 20 #if defined(_MSC_VER) |
22 #define ALIGN16(var) __declspec(align(16)) var | 21 #define ALIGN16(var) __declspec(align(16)) var |
23 #else | 22 #else |
24 #define ALIGN16(var) var __attribute__((aligned(16))) | 23 #define ALIGN16(var) var __attribute__((aligned(16))) |
25 #endif | 24 #endif |
26 | 25 |
27 using cricket::LoadPlanarYuvTestImage; | 26 using cricket::LoadPlanarYuvTestImage; |
28 using cricket::DumpPlanarYuvTestImage; | 27 using cricket::DumpPlanarYuvTestImage; |
29 using rtc::scoped_ptr; | |
30 | 28 |
31 DEFINE_bool(yuvscaler_dump, false, | 29 DEFINE_bool(yuvscaler_dump, false, |
32 "whether to write out scaled images for inspection"); | 30 "whether to write out scaled images for inspection"); |
33 DEFINE_int(yuvscaler_repeat, 1, | 31 DEFINE_int(yuvscaler_repeat, 1, |
34 "how many times to perform each scaling operation (for perf testing)"); | 32 "how many times to perform each scaling operation (for perf testing)"); |
35 | 33 |
36 static const int kAlignment = 16; | 34 static const int kAlignment = 16; |
37 | 35 |
38 // TEST_UNCACHED flushes cache to test real memory performance. | 36 // TEST_UNCACHED flushes cache to test real memory performance. |
39 // TEST_RSTSC uses cpu cycles for more accurate benchmark of the scale function. | 37 // TEST_RSTSC uses cpu cycles for more accurate benchmark of the scale function. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 75 |
78 // Scale an image and compare against a Lanczos-filtered test image. | 76 // Scale an image and compare against a Lanczos-filtered test image. |
79 // Lanczos is considered to be the "ideal" image resampling method, so we try | 77 // Lanczos is considered to be the "ideal" image resampling method, so we try |
80 // to get as close to that as possible, while being as fast as possible. | 78 // to get as close to that as possible, while being as fast as possible. |
81 bool TestScale(int iw, int ih, int ow, int oh, int offset, bool usefile, | 79 bool TestScale(int iw, int ih, int ow, int oh, int offset, bool usefile, |
82 bool optimize, int cpuflags, bool interpolate, | 80 bool optimize, int cpuflags, bool interpolate, |
83 int memoffset, double* error) { | 81 int memoffset, double* error) { |
84 *error = 0.; | 82 *error = 0.; |
85 size_t isize = I420_SIZE(iw, ih); | 83 size_t isize = I420_SIZE(iw, ih); |
86 size_t osize = I420_SIZE(ow, oh); | 84 size_t osize = I420_SIZE(ow, oh); |
87 scoped_ptr<uint8_t[]> ibuffer( | 85 std::unique_ptr<uint8_t[]> ibuffer( |
88 new uint8_t[isize + kAlignment + memoffset]()); | 86 new uint8_t[isize + kAlignment + memoffset]()); |
89 scoped_ptr<uint8_t[]> obuffer( | 87 std::unique_ptr<uint8_t[]> obuffer( |
90 new uint8_t[osize + kAlignment + memoffset]()); | 88 new uint8_t[osize + kAlignment + memoffset]()); |
91 scoped_ptr<uint8_t[]> xbuffer( | 89 std::unique_ptr<uint8_t[]> xbuffer( |
92 new uint8_t[osize + kAlignment + memoffset]()); | 90 new uint8_t[osize + kAlignment + memoffset]()); |
93 | 91 |
94 uint8_t* ibuf = ALIGNP(ibuffer.get(), kAlignment) + memoffset; | 92 uint8_t* ibuf = ALIGNP(ibuffer.get(), kAlignment) + memoffset; |
95 uint8_t* obuf = ALIGNP(obuffer.get(), kAlignment) + memoffset; | 93 uint8_t* obuf = ALIGNP(obuffer.get(), kAlignment) + memoffset; |
96 uint8_t* xbuf = ALIGNP(xbuffer.get(), kAlignment) + memoffset; | 94 uint8_t* xbuf = ALIGNP(xbuffer.get(), kAlignment) + memoffset; |
97 | 95 |
98 if (usefile) { | 96 if (usefile) { |
99 if (!LoadPlanarYuvTestImage("faces", iw, ih, ibuf) || | 97 if (!LoadPlanarYuvTestImage("faces", iw, ih, ibuf) || |
100 !LoadPlanarYuvTestImage("faces", ow, oh, xbuf)) { | 98 !LoadPlanarYuvTestImage("faces", ow, oh, xbuf)) { |
101 LOG(LS_ERROR) << "Failed to load image"; | 99 LOG(LS_ERROR) << "Failed to load image"; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 183 } |
186 if (dump_) DumpPlanarYuvTestImage("TestCopy", obuf, ow, oh); | 184 if (dump_) DumpPlanarYuvTestImage("TestCopy", obuf, ow, oh); |
187 EXPECT_EQ(-1, FindDiff(obuf, ibuf, sizeof(ibuf))); | 185 EXPECT_EQ(-1, FindDiff(obuf, ibuf, sizeof(ibuf))); |
188 } | 186 } |
189 | 187 |
190 // Tests copy from 4:3 to 16:9. | 188 // Tests copy from 4:3 to 16:9. |
191 TEST_F(YuvScalerTest, TestOffset16_10Copy) { | 189 TEST_F(YuvScalerTest, TestOffset16_10Copy) { |
192 const int iw = 640, ih = 360; | 190 const int iw = 640, ih = 360; |
193 const int ow = 640, oh = 480; | 191 const int ow = 640, oh = 480; |
194 const int offset = (480 - 360) / 2; | 192 const int offset = (480 - 360) / 2; |
195 scoped_ptr<uint8_t[]> ibuffer(new uint8_t[I420_SIZE(iw, ih) + kAlignment]); | 193 std::unique_ptr<uint8_t[]> ibuffer( |
196 scoped_ptr<uint8_t[]> obuffer(new uint8_t[I420_SIZE(ow, oh) + kAlignment]); | 194 new uint8_t[I420_SIZE(iw, ih) + kAlignment]); |
| 195 std::unique_ptr<uint8_t[]> obuffer( |
| 196 new uint8_t[I420_SIZE(ow, oh) + kAlignment]); |
197 | 197 |
198 uint8_t* ibuf = ALIGNP(ibuffer.get(), kAlignment); | 198 uint8_t* ibuf = ALIGNP(ibuffer.get(), kAlignment); |
199 uint8_t* obuf = ALIGNP(obuffer.get(), kAlignment); | 199 uint8_t* obuf = ALIGNP(obuffer.get(), kAlignment); |
200 | 200 |
201 // Load the frame, scale it, check it. | 201 // Load the frame, scale it, check it. |
202 ASSERT_TRUE(LoadPlanarYuvTestImage("faces", iw, ih, ibuf)); | 202 ASSERT_TRUE(LoadPlanarYuvTestImage("faces", iw, ih, ibuf)); |
203 | 203 |
204 // Clear to black, which is Y = 0 and U and V = 128 | 204 // Clear to black, which is Y = 0 and U and V = 128 |
205 memset(obuf, 0, ow * oh); | 205 memset(obuf, 0, ow * oh); |
206 memset(obuf + ow * oh, 128, ow * oh / 2); | 206 memset(obuf + ow * oh, 128, ow * oh / 2); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 TEST_H(TestScaleDown8xHDOptInt, 1280, 720, 1280 / 8, 720 / 8, true, ALLFLAGS, | 592 TEST_H(TestScaleDown8xHDOptInt, 1280, 720, 1280 / 8, 720 / 8, true, ALLFLAGS, |
593 true, 1) | 593 true, 1) |
594 | 594 |
595 // Tests interpolated 1/8x scale down, using optimized algorithm. | 595 // Tests interpolated 1/8x scale down, using optimized algorithm. |
596 TEST_H(TestScaleDown9xHDOptInt, 1280, 720, 1280 / 9, 720 / 9, true, ALLFLAGS, | 596 TEST_H(TestScaleDown9xHDOptInt, 1280, 720, 1280 / 9, 720 / 9, true, ALLFLAGS, |
597 true, 1) | 597 true, 1) |
598 | 598 |
599 // Tests interpolated 1/8x scale down, using optimized algorithm. | 599 // Tests interpolated 1/8x scale down, using optimized algorithm. |
600 TEST_H(TestScaleDown10xHDOptInt, 1280, 720, 1280 / 10, 720 / 10, true, ALLFLAGS, | 600 TEST_H(TestScaleDown10xHDOptInt, 1280, 720, 1280 / 10, 720 / 10, true, ALLFLAGS, |
601 true, 1) | 601 true, 1) |
OLD | NEW |