| 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" | 15 #include "libyuv/row.h" |
| 16 #include "../unit_test/unit_test.h" | 16 #include "../unit_test/unit_test.h" |
| 17 | 17 |
| 18 namespace libyuv { | 18 namespace libyuv { |
| 19 | 19 |
| 20 static void I420TestRotate(int src_width, int src_height, | 20 static void I420TestRotate(int src_width, int src_height, |
| 21 int dst_width, int dst_height, | 21 int dst_width, int dst_height, |
| 22 libyuv::RotationMode mode, | 22 libyuv::RotationMode mode, |
| 23 int benchmark_iterations, int disable_cpu_flags) { | 23 int benchmark_iterations, |
| 24 int disable_cpu_flags, int benchmark_cpu_info) { |
| 24 if (src_width < 1) { | 25 if (src_width < 1) { |
| 25 src_width = 1; | 26 src_width = 1; |
| 26 } | 27 } |
| 27 if (src_height == 0) { | 28 if (src_height == 0) { |
| 28 src_height = 1; | 29 src_height = 1; |
| 29 } | 30 } |
| 30 if (dst_width < 1) { | 31 if (dst_width < 1) { |
| 31 dst_width = 1; | 32 dst_width = 1; |
| 32 } | 33 } |
| 33 if (dst_height < 1) { | 34 if (dst_height < 1) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 53 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 53 I420Rotate(src_i420, src_width, | 54 I420Rotate(src_i420, src_width, |
| 54 src_i420 + src_i420_y_size, (src_width + 1) / 2, | 55 src_i420 + src_i420_y_size, (src_width + 1) / 2, |
| 55 src_i420 + src_i420_y_size + src_i420_uv_size, (src_width + 1) / 2, | 56 src_i420 + src_i420_y_size + src_i420_uv_size, (src_width + 1) / 2, |
| 56 dst_i420_c, dst_width, | 57 dst_i420_c, dst_width, |
| 57 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, | 58 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, |
| 58 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, | 59 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, |
| 59 (dst_width + 1) / 2, | 60 (dst_width + 1) / 2, |
| 60 src_width, src_height, mode); | 61 src_width, src_height, mode); |
| 61 | 62 |
| 62 MaskCpuFlags(-1); // Enable all CPU optimization. | 63 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 63 for (int i = 0; i < benchmark_iterations; ++i) { | 64 for (int i = 0; i < benchmark_iterations; ++i) { |
| 64 I420Rotate(src_i420, src_width, | 65 I420Rotate(src_i420, src_width, |
| 65 src_i420 + src_i420_y_size, (src_width + 1) / 2, | 66 src_i420 + src_i420_y_size, (src_width + 1) / 2, |
| 66 src_i420 + src_i420_y_size + src_i420_uv_size, | 67 src_i420 + src_i420_y_size + src_i420_uv_size, |
| 67 (src_width + 1) / 2, | 68 (src_width + 1) / 2, |
| 68 dst_i420_opt, dst_width, | 69 dst_i420_opt, dst_width, |
| 69 dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, | 70 dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, |
| 70 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, | 71 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, |
| 71 (dst_width + 1) / 2, | 72 (dst_width + 1) / 2, |
| 72 src_width, src_height, mode); | 73 src_width, src_height, mode); |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Rotation should be exact. | 76 // Rotation should be exact. |
| 76 for (int i = 0; i < dst_i420_size; ++i) { | 77 for (int i = 0; i < dst_i420_size; ++i) { |
| 77 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); | 78 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); |
| 78 } | 79 } |
| 79 | 80 |
| 80 free_aligned_buffer_64(dst_i420_c); | 81 free_aligned_buffer_64(dst_i420_c); |
| 81 free_aligned_buffer_64(dst_i420_opt); | 82 free_aligned_buffer_64(dst_i420_opt); |
| 82 free_aligned_buffer_64(src_i420); | 83 free_aligned_buffer_64(src_i420); |
| 83 } | 84 } |
| 84 | 85 |
| 85 TEST_F(LibYUVRotateTest, I420Rotate0) { | 86 TEST_F(LibYUVRotateTest, I420Rotate0) { |
| 86 I420TestRotate(benchmark_width_, benchmark_height_, | 87 I420TestRotate(benchmark_width_, benchmark_height_, |
| 87 benchmark_width_, benchmark_height_, | 88 benchmark_width_, benchmark_height_, |
| 88 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 89 kRotate0, benchmark_iterations_, |
| 90 disable_cpu_flags_, benchmark_cpu_info_); |
| 89 } | 91 } |
| 90 | 92 |
| 91 TEST_F(LibYUVRotateTest, I420Rotate90) { | 93 TEST_F(LibYUVRotateTest, I420Rotate90) { |
| 92 I420TestRotate(benchmark_width_, benchmark_height_, | 94 I420TestRotate(benchmark_width_, benchmark_height_, |
| 93 benchmark_height_, benchmark_width_, | 95 benchmark_height_, benchmark_width_, |
| 94 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 96 kRotate90, benchmark_iterations_, |
| 97 disable_cpu_flags_, benchmark_cpu_info_); |
| 95 } | 98 } |
| 96 | 99 |
| 97 TEST_F(LibYUVRotateTest, I420Rotate180) { | 100 TEST_F(LibYUVRotateTest, I420Rotate180) { |
| 98 I420TestRotate(benchmark_width_, benchmark_height_, | 101 I420TestRotate(benchmark_width_, benchmark_height_, |
| 99 benchmark_width_, benchmark_height_, | 102 benchmark_width_, benchmark_height_, |
| 100 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 103 kRotate180, benchmark_iterations_, |
| 104 disable_cpu_flags_, benchmark_cpu_info_); |
| 101 } | 105 } |
| 102 | 106 |
| 103 TEST_F(LibYUVRotateTest, I420Rotate270) { | 107 TEST_F(LibYUVRotateTest, I420Rotate270) { |
| 104 I420TestRotate(benchmark_width_, benchmark_height_, | 108 I420TestRotate(benchmark_width_, benchmark_height_, |
| 105 benchmark_height_, benchmark_width_, | 109 benchmark_height_, benchmark_width_, |
| 106 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 110 kRotate270, benchmark_iterations_, |
| 111 disable_cpu_flags_, benchmark_cpu_info_); |
| 107 } | 112 } |
| 108 | 113 |
| 109 TEST_F(LibYUVRotateTest, I420Rotate0_Odd) { | 114 TEST_F(LibYUVRotateTest, I420Rotate0_Odd) { |
| 110 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 115 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 111 benchmark_width_ - 3, benchmark_height_ - 1, | 116 benchmark_width_ - 3, benchmark_height_ - 1, |
| 112 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 117 kRotate0, benchmark_iterations_, |
| 118 disable_cpu_flags_, benchmark_cpu_info_); |
| 113 } | 119 } |
| 114 | 120 |
| 115 TEST_F(LibYUVRotateTest, I420Rotate90_Odd) { | 121 TEST_F(LibYUVRotateTest, I420Rotate90_Odd) { |
| 116 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 122 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 117 benchmark_height_ - 1, benchmark_width_ - 3, | 123 benchmark_height_ - 1, benchmark_width_ - 3, |
| 118 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 124 kRotate90, benchmark_iterations_, |
| 125 disable_cpu_flags_, benchmark_cpu_info_); |
| 119 } | 126 } |
| 120 | 127 |
| 121 TEST_F(LibYUVRotateTest, I420Rotate180_Odd) { | 128 TEST_F(LibYUVRotateTest, I420Rotate180_Odd) { |
| 122 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 129 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 123 benchmark_width_ - 3, benchmark_height_ - 1, | 130 benchmark_width_ - 3, benchmark_height_ - 1, |
| 124 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 131 kRotate180, benchmark_iterations_, |
| 132 disable_cpu_flags_, benchmark_cpu_info_); |
| 125 } | 133 } |
| 126 | 134 |
| 127 TEST_F(LibYUVRotateTest, I420Rotate270_Odd) { | 135 TEST_F(LibYUVRotateTest, I420Rotate270_Odd) { |
| 128 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 136 I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 129 benchmark_height_ - 1, benchmark_width_ - 3, | 137 benchmark_height_ - 1, benchmark_width_ - 3, |
| 130 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 138 kRotate270, benchmark_iterations_, |
| 139 disable_cpu_flags_, benchmark_cpu_info_); |
| 131 } | 140 } |
| 132 | 141 |
| 133 static void NV12TestRotate(int src_width, int src_height, | 142 static void NV12TestRotate(int src_width, int src_height, |
| 134 int dst_width, int dst_height, | 143 int dst_width, int dst_height, |
| 135 libyuv::RotationMode mode, | 144 libyuv::RotationMode mode, |
| 136 int benchmark_iterations, int disable_cpu_flags) { | 145 int benchmark_iterations, |
| 146 int disable_cpu_flags, int benchmark_cpu_info) { |
| 137 if (src_width < 1) { | 147 if (src_width < 1) { |
| 138 src_width = 1; | 148 src_width = 1; |
| 139 } | 149 } |
| 140 if (src_height == 0) { // allow negative for inversion test. | 150 if (src_height == 0) { // allow negative for inversion test. |
| 141 src_height = 1; | 151 src_height = 1; |
| 142 } | 152 } |
| 143 if (dst_width < 1) { | 153 if (dst_width < 1) { |
| 144 dst_width = 1; | 154 dst_width = 1; |
| 145 } | 155 } |
| 146 if (dst_height < 1) { | 156 if (dst_height < 1) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 | 175 |
| 166 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 176 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 167 NV12ToI420Rotate(src_nv12, src_width, | 177 NV12ToI420Rotate(src_nv12, src_width, |
| 168 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, | 178 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, |
| 169 dst_i420_c, dst_width, | 179 dst_i420_c, dst_width, |
| 170 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, | 180 dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, |
| 171 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, | 181 dst_i420_c + dst_i420_y_size + dst_i420_uv_size, |
| 172 (dst_width + 1) / 2, | 182 (dst_width + 1) / 2, |
| 173 src_width, src_height, mode); | 183 src_width, src_height, mode); |
| 174 | 184 |
| 175 MaskCpuFlags(-1); // Enable all CPU optimization. | 185 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 176 for (int i = 0; i < benchmark_iterations; ++i) { | 186 for (int i = 0; i < benchmark_iterations; ++i) { |
| 177 NV12ToI420Rotate(src_nv12, src_width, | 187 NV12ToI420Rotate(src_nv12, src_width, |
| 178 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, | 188 src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, |
| 179 dst_i420_opt, dst_width, | 189 dst_i420_opt, dst_width, |
| 180 dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, | 190 dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, |
| 181 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, | 191 dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, |
| 182 (dst_width + 1) / 2, | 192 (dst_width + 1) / 2, |
| 183 src_width, src_height, mode); | 193 src_width, src_height, mode); |
| 184 } | 194 } |
| 185 | 195 |
| 186 // Rotation should be exact. | 196 // Rotation should be exact. |
| 187 for (int i = 0; i < dst_i420_size; ++i) { | 197 for (int i = 0; i < dst_i420_size; ++i) { |
| 188 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); | 198 EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); |
| 189 } | 199 } |
| 190 | 200 |
| 191 free_aligned_buffer_64(dst_i420_c); | 201 free_aligned_buffer_64(dst_i420_c); |
| 192 free_aligned_buffer_64(dst_i420_opt); | 202 free_aligned_buffer_64(dst_i420_opt); |
| 193 free_aligned_buffer_64(src_nv12); | 203 free_aligned_buffer_64(src_nv12); |
| 194 } | 204 } |
| 195 | 205 |
| 196 TEST_F(LibYUVRotateTest, NV12Rotate0) { | 206 TEST_F(LibYUVRotateTest, NV12Rotate0) { |
| 197 NV12TestRotate(benchmark_width_, benchmark_height_, | 207 NV12TestRotate(benchmark_width_, benchmark_height_, |
| 198 benchmark_width_, benchmark_height_, | 208 benchmark_width_, benchmark_height_, |
| 199 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 209 kRotate0, benchmark_iterations_, |
| 210 disable_cpu_flags_, benchmark_cpu_info_); |
| 200 } | 211 } |
| 201 | 212 |
| 202 TEST_F(LibYUVRotateTest, NV12Rotate90) { | 213 TEST_F(LibYUVRotateTest, NV12Rotate90) { |
| 203 NV12TestRotate(benchmark_width_, benchmark_height_, | 214 NV12TestRotate(benchmark_width_, benchmark_height_, |
| 204 benchmark_height_, benchmark_width_, | 215 benchmark_height_, benchmark_width_, |
| 205 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 216 kRotate90, benchmark_iterations_, |
| 217 disable_cpu_flags_, benchmark_cpu_info_); |
| 206 } | 218 } |
| 207 | 219 |
| 208 TEST_F(LibYUVRotateTest, NV12Rotate180) { | 220 TEST_F(LibYUVRotateTest, NV12Rotate180) { |
| 209 NV12TestRotate(benchmark_width_, benchmark_height_, | 221 NV12TestRotate(benchmark_width_, benchmark_height_, |
| 210 benchmark_width_, benchmark_height_, | 222 benchmark_width_, benchmark_height_, |
| 211 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 223 kRotate180, benchmark_iterations_, |
| 224 disable_cpu_flags_, benchmark_cpu_info_); |
| 212 } | 225 } |
| 213 | 226 |
| 214 TEST_F(LibYUVRotateTest, NV12Rotate270) { | 227 TEST_F(LibYUVRotateTest, NV12Rotate270) { |
| 215 NV12TestRotate(benchmark_width_, benchmark_height_, | 228 NV12TestRotate(benchmark_width_, benchmark_height_, |
| 216 benchmark_height_, benchmark_width_, | 229 benchmark_height_, benchmark_width_, |
| 217 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 230 kRotate270, benchmark_iterations_, |
| 231 disable_cpu_flags_, benchmark_cpu_info_); |
| 218 } | 232 } |
| 219 | 233 |
| 220 TEST_F(LibYUVRotateTest, NV12Rotate0_Odd) { | 234 TEST_F(LibYUVRotateTest, NV12Rotate0_Odd) { |
| 221 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 235 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 222 benchmark_width_ - 3, benchmark_height_ - 1, | 236 benchmark_width_ - 3, benchmark_height_ - 1, |
| 223 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 237 kRotate0, benchmark_iterations_, |
| 238 disable_cpu_flags_, benchmark_cpu_info_); |
| 224 } | 239 } |
| 225 | 240 |
| 226 TEST_F(LibYUVRotateTest, NV12Rotate90_Odd) { | 241 TEST_F(LibYUVRotateTest, NV12Rotate90_Odd) { |
| 227 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 242 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 228 benchmark_height_ - 1, benchmark_width_ - 3, | 243 benchmark_height_ - 1, benchmark_width_ - 3, |
| 229 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 244 kRotate90, benchmark_iterations_, |
| 245 disable_cpu_flags_, benchmark_cpu_info_); |
| 230 } | 246 } |
| 231 | 247 |
| 232 TEST_F(LibYUVRotateTest, NV12Rotate180_Odd) { | 248 TEST_F(LibYUVRotateTest, NV12Rotate180_Odd) { |
| 233 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 249 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 234 benchmark_width_ - 3, benchmark_height_ - 1, | 250 benchmark_width_ - 3, benchmark_height_ - 1, |
| 235 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 251 kRotate180, benchmark_iterations_, |
| 252 disable_cpu_flags_, benchmark_cpu_info_); |
| 236 } | 253 } |
| 237 | 254 |
| 238 TEST_F(LibYUVRotateTest, NV12Rotate270_Odd) { | 255 TEST_F(LibYUVRotateTest, NV12Rotate270_Odd) { |
| 239 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 256 NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 240 benchmark_height_ - 1, benchmark_width_ - 3, | 257 benchmark_height_ - 1, benchmark_width_ - 3, |
| 241 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 258 kRotate270, benchmark_iterations_, |
| 259 disable_cpu_flags_, benchmark_cpu_info_); |
| 242 } | 260 } |
| 243 | 261 |
| 244 TEST_F(LibYUVRotateTest, NV12Rotate0_Inverted) { | 262 TEST_F(LibYUVRotateTest, NV12Rotate0_Inverted) { |
| 245 NV12TestRotate(benchmark_width_, -benchmark_height_, | 263 NV12TestRotate(benchmark_width_, -benchmark_height_, |
| 246 benchmark_width_, benchmark_height_, | 264 benchmark_width_, benchmark_height_, |
| 247 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 265 kRotate0, benchmark_iterations_, |
| 266 disable_cpu_flags_, benchmark_cpu_info_); |
| 248 } | 267 } |
| 249 | 268 |
| 250 TEST_F(LibYUVRotateTest, NV12Rotate90_Inverted) { | 269 TEST_F(LibYUVRotateTest, NV12Rotate90_Inverted) { |
| 251 NV12TestRotate(benchmark_width_, -benchmark_height_, | 270 NV12TestRotate(benchmark_width_, -benchmark_height_, |
| 252 benchmark_height_, benchmark_width_, | 271 benchmark_height_, benchmark_width_, |
| 253 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 272 kRotate90, benchmark_iterations_, |
| 273 disable_cpu_flags_, benchmark_cpu_info_); |
| 254 } | 274 } |
| 255 | 275 |
| 256 TEST_F(LibYUVRotateTest, NV12Rotate180_Inverted) { | 276 TEST_F(LibYUVRotateTest, NV12Rotate180_Inverted) { |
| 257 NV12TestRotate(benchmark_width_, -benchmark_height_, | 277 NV12TestRotate(benchmark_width_, -benchmark_height_, |
| 258 benchmark_width_, benchmark_height_, | 278 benchmark_width_, benchmark_height_, |
| 259 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 279 kRotate180, benchmark_iterations_, |
| 280 disable_cpu_flags_, benchmark_cpu_info_); |
| 260 } | 281 } |
| 261 | 282 |
| 262 TEST_F(LibYUVRotateTest, NV12Rotate270_Inverted) { | 283 TEST_F(LibYUVRotateTest, NV12Rotate270_Inverted) { |
| 263 NV12TestRotate(benchmark_width_, -benchmark_height_, | 284 NV12TestRotate(benchmark_width_, -benchmark_height_, |
| 264 benchmark_height_, benchmark_width_, | 285 benchmark_height_, benchmark_width_, |
| 265 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 286 kRotate270, benchmark_iterations_, |
| 287 disable_cpu_flags_, benchmark_cpu_info_); |
| 266 } | 288 } |
| 267 | 289 |
| 268 | 290 |
| 269 | 291 |
| 270 | 292 |
| 271 | 293 |
| 272 } // namespace libyuv | 294 } // namespace libyuv |
| OLD | NEW |