| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2012 The LibYuv 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 <stdlib.h> | 11 #include <stdlib.h> |
| 12 | 12 |
| 13 #include "libyuv/cpu_id.h" | 13 #include "libyuv/cpu_id.h" |
| 14 #include "libyuv/rotate.h" | 14 #include "libyuv/rotate.h" |
| 15 #include "libyuv/row.h" | |
| 16 #include "../unit_test/unit_test.h" | 15 #include "../unit_test/unit_test.h" |
| 17 | 16 |
| 18 namespace libyuv { | 17 namespace libyuv { |
| 19 | 18 |
| 20 static void I420TestRotate(int src_width, int src_height, | 19 static void I420TestRotate(int src_width, int src_height, |
| 21 int dst_width, int dst_height, | 20 int dst_width, int dst_height, |
| 22 libyuv::RotationMode mode, | 21 libyuv::RotationMode mode, |
| 23 int benchmark_iterations, | 22 int benchmark_iterations, |
| 24 int disable_cpu_flags, int benchmark_cpu_info) { | 23 int disable_cpu_flags, int benchmark_cpu_info) { |
| 25 if (src_width < 1) { | 24 if (src_width < 1) { |
| 26 src_width = 1; | 25 src_width = 1; |
| 27 } | 26 } |
| 28 if (src_height == 0) { | 27 if (src_height == 0) { |
| 29 src_height = 1; | 28 src_height = 1; |
| 30 } | 29 } |
| 31 if (dst_width < 1) { | 30 if (dst_width < 1) { |
| 32 dst_width = 1; | 31 dst_width = 1; |
| 33 } | 32 } |
| 34 if (dst_height < 1) { | 33 if (dst_height < 1) { |
| 35 dst_height = 1; | 34 dst_height = 1; |
| 36 } | 35 } |
| 37 int src_i420_y_size = src_width * Abs(src_height); | 36 int src_i420_y_size = src_width * Abs(src_height); |
| 38 int src_i420_uv_size = ((src_width + 1) / 2) * ((Abs(src_height) + 1) / 2); | 37 int src_i420_uv_size = ((src_width + 1) / 2) * ((Abs(src_height) + 1) / 2); |
| 39 int src_i420_size = src_i420_y_size + src_i420_uv_size * 2; | 38 int src_i420_size = src_i420_y_size + src_i420_uv_size * 2; |
| 40 align_buffer_64(src_i420, src_i420_size); | 39 align_buffer_page_end(src_i420, src_i420_size); |
| 41 for (int i = 0; i < src_i420_size; ++i) { | 40 for (int i = 0; i < src_i420_size; ++i) { |
| 42 src_i420[i] = fastrand() & 0xff; | 41 src_i420[i] = fastrand() & 0xff; |
| 43 } | 42 } |
| 44 | 43 |
| 45 int dst_i420_y_size = dst_width * dst_height; | 44 int dst_i420_y_size = dst_width * dst_height; |
| 46 int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); | 45 int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); |
| 47 int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; | 46 int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; |
| 48 align_buffer_64(dst_i420_c, dst_i420_size); | 47 align_buffer_page_end(dst_i420_c, dst_i420_size); |
| 49 align_buffer_64(dst_i420_opt, dst_i420_size); | 48 align_buffer_page_end(dst_i420_opt, dst_i420_size); |
| 50 memset(dst_i420_c, 2, dst_i420_size); | 49 memset(dst_i420_c, 2, dst_i420_size); |
| 51 memset(dst_i420_opt, 3, dst_i420_size); | 50 memset(dst_i420_opt, 3, dst_i420_size); |
| 52 | 51 |
| 53 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 52 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 54 I420Rotate(src_i420, src_width, | 53 I420Rotate(src_i420, src_width, |
| 55 src_i420 + src_i420_y_size, (src_width + 1) / 2, | 54 src_i420 + src_i420_y_size, (src_width + 1) / 2, |
| 56 src_i420 + src_i420_y_size + src_i420_uv_size, (src_width + 1) / 2, | 55 src_i420 + src_i420_y_size + src_i420_uv_size, (src_width + 1) / 2, |
| 57 dst_i420_c, dst_width, | 56 dst_i420_c, dst_width, |
| 58 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, | 57 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, |
| 59 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, | 58 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, | 70 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, |
| 72 (dst_width + 1) / 2, | 71 (dst_width + 1) / 2, |
| 73 src_width, src_height, mode); | 72 src_width, src_height, mode); |
| 74 } | 73 } |
| 75 | 74 |
| 76 // Rotation should be exact. | 75 // Rotation should be exact. |
| 77 for (int i = 0; i < dst_i420_size; ++i) { | 76 for (int i = 0; i < dst_i420_size; ++i) { |
| 78 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); | 77 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); |
| 79 } | 78 } |
| 80 | 79 |
| 81 free_aligned_buffer_64(dst_i420_c); | 80 free_aligned_buffer_page_end(dst_i420_c); |
| 82 free_aligned_buffer_64(dst_i420_opt); | 81 free_aligned_buffer_page_end(dst_i420_opt); |
| 83 free_aligned_buffer_64(src_i420); | 82 free_aligned_buffer_page_end(src_i420); |
| 84 } | 83 } |
| 85 | 84 |
| 86 TEST_F(LibYUVRotateTest, I420Rotate0_Opt) { | 85 TEST_F(LibYUVRotateTest, I420Rotate0_Opt) { |
| 87 I420TestRotate(benchmark_width_, benchmark_height_, | 86 I420TestRotate(benchmark_width_, benchmark_height_, |
| 88 benchmark_width_, benchmark_height_, | 87 benchmark_width_, benchmark_height_, |
| 89 kRotate0, benchmark_iterations_, | 88 kRotate0, benchmark_iterations_, |
| 90 disable_cpu_flags_, benchmark_cpu_info_); | 89 disable_cpu_flags_, benchmark_cpu_info_); |
| 91 } | 90 } |
| 92 | 91 |
| 93 TEST_F(LibYUVRotateTest, I420Rotate90_Opt) { | 92 TEST_F(LibYUVRotateTest, I420Rotate90_Opt) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (dst_width < 1) { | 155 if (dst_width < 1) { |
| 157 dst_width = 1; | 156 dst_width = 1; |
| 158 } | 157 } |
| 159 if (dst_height < 1) { | 158 if (dst_height < 1) { |
| 160 dst_height = 1; | 159 dst_height = 1; |
| 161 } | 160 } |
| 162 int src_nv12_y_size = src_width * Abs(src_height); | 161 int src_nv12_y_size = src_width * Abs(src_height); |
| 163 int src_nv12_uv_size = | 162 int src_nv12_uv_size = |
| 164 ((src_width + 1) / 2) * ((Abs(src_height) + 1) / 2) * 2; | 163 ((src_width + 1) / 2) * ((Abs(src_height) + 1) / 2) * 2; |
| 165 int src_nv12_size = src_nv12_y_size + src_nv12_uv_size; | 164 int src_nv12_size = src_nv12_y_size + src_nv12_uv_size; |
| 166 align_buffer_64(src_nv12, src_nv12_size); | 165 align_buffer_page_end(src_nv12, src_nv12_size); |
| 167 for (int i = 0; i < src_nv12_size; ++i) { | 166 for (int i = 0; i < src_nv12_size; ++i) { |
| 168 src_nv12[i] = fastrand() & 0xff; | 167 src_nv12[i] = fastrand() & 0xff; |
| 169 } | 168 } |
| 170 | 169 |
| 171 int dst_i420_y_size = dst_width * dst_height; | 170 int dst_i420_y_size = dst_width * dst_height; |
| 172 int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); | 171 int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); |
| 173 int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; | 172 int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; |
| 174 align_buffer_64(dst_i420_c, dst_i420_size); | 173 align_buffer_page_end(dst_i420_c, dst_i420_size); |
| 175 align_buffer_64(dst_i420_opt, dst_i420_size); | 174 align_buffer_page_end(dst_i420_opt, dst_i420_size); |
| 176 memset(dst_i420_c, 2, dst_i420_size); | 175 memset(dst_i420_c, 2, dst_i420_size); |
| 177 memset(dst_i420_opt, 3, dst_i420_size); | 176 memset(dst_i420_opt, 3, dst_i420_size); |
| 178 | 177 |
| 179 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 178 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 180 NV12ToI420Rotate(src_nv12, src_width, | 179 NV12ToI420Rotate(src_nv12, src_width, |
| 181 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, | 180 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, |
| 182 dst_i420_c, dst_width, | 181 dst_i420_c, dst_width, |
| 183 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, | 182 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, |
| 184 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, | 183 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, |
| 185 (dst_width + 1) / 2, | 184 (dst_width + 1) / 2, |
| 186 src_width, src_height, mode); | 185 src_width, src_height, mode); |
| 187 | 186 |
| 188 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. | 187 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 189 for (int i = 0; i < benchmark_iterations; ++i) { | 188 for (int i = 0; i < benchmark_iterations; ++i) { |
| 190 NV12ToI420Rotate(src_nv12, src_width, | 189 NV12ToI420Rotate(src_nv12, src_width, |
| 191 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, | 190 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, |
| 192 dst_i420_opt, dst_width, | 191 dst_i420_opt, dst_width, |
| 193 dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, | 192 dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, |
| 194 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, | 193 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, |
| 195 (dst_width + 1) / 2, | 194 (dst_width + 1) / 2, |
| 196 src_width, src_height, mode); | 195 src_width, src_height, mode); |
| 197 } | 196 } |
| 198 | 197 |
| 199 // Rotation should be exact. | 198 // Rotation should be exact. |
| 200 for (int i = 0; i < dst_i420_size; ++i) { | 199 for (int i = 0; i < dst_i420_size; ++i) { |
| 201 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); | 200 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); |
| 202 } | 201 } |
| 203 | 202 |
| 204 free_aligned_buffer_64(dst_i420_c); | 203 free_aligned_buffer_page_end(dst_i420_c); |
| 205 free_aligned_buffer_64(dst_i420_opt); | 204 free_aligned_buffer_page_end(dst_i420_opt); |
| 206 free_aligned_buffer_64(src_nv12); | 205 free_aligned_buffer_page_end(src_nv12); |
| 207 } | 206 } |
| 208 | 207 |
| 209 TEST_F(LibYUVRotateTest, NV12Rotate0_Opt) { | 208 TEST_F(LibYUVRotateTest, NV12Rotate0_Opt) { |
| 210 NV12TestRotate(benchmark_width_, benchmark_height_, | 209 NV12TestRotate(benchmark_width_, benchmark_height_, |
| 211 benchmark_width_, benchmark_height_, | 210 benchmark_width_, benchmark_height_, |
| 212 kRotate0, benchmark_iterations_, | 211 kRotate0, benchmark_iterations_, |
| 213 disable_cpu_flags_, benchmark_cpu_info_); | 212 disable_cpu_flags_, benchmark_cpu_info_); |
| 214 } | 213 } |
| 215 | 214 |
| 216 TEST_F(LibYUVRotateTest, NV12Rotate90_Opt) { | 215 TEST_F(LibYUVRotateTest, NV12Rotate90_Opt) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 benchmark_height_, benchmark_width_, | 287 benchmark_height_, benchmark_width_, |
| 289 kRotate270, benchmark_iterations_, | 288 kRotate270, benchmark_iterations_, |
| 290 disable_cpu_flags_, benchmark_cpu_info_); | 289 disable_cpu_flags_, benchmark_cpu_info_); |
| 291 } | 290 } |
| 292 | 291 |
| 293 | 292 |
| 294 | 293 |
| 295 | 294 |
| 296 | 295 |
| 297 } // namespace libyuv | 296 } // namespace libyuv |
| OLD | NEW |