1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libyuv/unit_test/rotate_test.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,244 @@ 1.4 +/* 1.5 + * Copyright 2012 The LibYuv Project Authors. All rights reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#include <stdlib.h> 1.15 +#include <time.h> 1.16 + 1.17 +#include "libyuv/cpu_id.h" 1.18 +#include "libyuv/rotate.h" 1.19 +#include "libyuv/row.h" 1.20 +#include "../unit_test/unit_test.h" 1.21 + 1.22 +namespace libyuv { 1.23 + 1.24 +static void I420TestRotate(int src_width, int src_height, 1.25 + int dst_width, int dst_height, 1.26 + libyuv::RotationMode mode, 1.27 + int benchmark_iterations) { 1.28 + if (src_width < 1) { 1.29 + src_width = 1; 1.30 + } 1.31 + if (src_height < 1) { 1.32 + src_height = 1; 1.33 + } 1.34 + if (dst_width < 1) { 1.35 + dst_width = 1; 1.36 + } 1.37 + if (dst_height < 1) { 1.38 + dst_height = 1; 1.39 + } 1.40 + int src_i420_y_size = src_width * src_height; 1.41 + int src_i420_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2); 1.42 + int src_i420_size = src_i420_y_size + src_i420_uv_size * 2; 1.43 + align_buffer_64(src_i420, src_i420_size); 1.44 + for (int i = 0; i < src_i420_size; ++i) { 1.45 + src_i420[i] = random() & 0xff; 1.46 + } 1.47 + 1.48 + int dst_i420_y_size = dst_width * dst_height; 1.49 + int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); 1.50 + int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; 1.51 + align_buffer_64(dst_i420_c, dst_i420_size); 1.52 + align_buffer_64(dst_i420_opt, dst_i420_size); 1.53 + memset(dst_i420_c, 2, dst_i420_size); 1.54 + memset(dst_i420_opt, 3, dst_i420_size); 1.55 + 1.56 + MaskCpuFlags(0); // Disable all CPU optimization. 1.57 + I420Rotate(src_i420, src_width, 1.58 + src_i420 + src_i420_y_size, (src_width + 1) / 2, 1.59 + src_i420 + src_i420_y_size + src_i420_uv_size, (src_width + 1) / 2, 1.60 + dst_i420_c, dst_width, 1.61 + dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, 1.62 + dst_i420_c + dst_i420_y_size + dst_i420_uv_size, 1.63 + (dst_width + 1) / 2, 1.64 + src_width, src_height, mode); 1.65 + 1.66 + MaskCpuFlags(-1); // Enable all CPU optimization. 1.67 + for (int i = 0; i < benchmark_iterations; ++i) { 1.68 + I420Rotate(src_i420, src_width, 1.69 + src_i420 + src_i420_y_size, (src_width + 1) / 2, 1.70 + src_i420 + src_i420_y_size + src_i420_uv_size, 1.71 + (src_width + 1) / 2, 1.72 + dst_i420_opt, dst_width, 1.73 + dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, 1.74 + dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, 1.75 + (dst_width + 1) / 2, 1.76 + src_width, src_height, mode); 1.77 + } 1.78 + 1.79 + // Rotation should be exact. 1.80 + for (int i = 0; i < dst_i420_size; ++i) { 1.81 + EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); 1.82 + } 1.83 + 1.84 + free_aligned_buffer_64(dst_i420_c); 1.85 + free_aligned_buffer_64(dst_i420_opt); 1.86 + free_aligned_buffer_64(src_i420); 1.87 +} 1.88 + 1.89 +TEST_F(libyuvTest, I420Rotate0) { 1.90 + I420TestRotate(benchmark_width_, benchmark_height_, 1.91 + benchmark_width_, benchmark_height_, 1.92 + kRotate0, benchmark_iterations_); 1.93 +} 1.94 + 1.95 +TEST_F(libyuvTest, I420Rotate90) { 1.96 + I420TestRotate(benchmark_width_, benchmark_height_, 1.97 + benchmark_height_, benchmark_width_, 1.98 + kRotate90, benchmark_iterations_); 1.99 +} 1.100 + 1.101 +TEST_F(libyuvTest, I420Rotate180) { 1.102 + I420TestRotate(benchmark_width_, benchmark_height_, 1.103 + benchmark_width_, benchmark_height_, 1.104 + kRotate180, benchmark_iterations_); 1.105 +} 1.106 + 1.107 +TEST_F(libyuvTest, I420Rotate270) { 1.108 + I420TestRotate(benchmark_width_, benchmark_height_, 1.109 + benchmark_height_, benchmark_width_, 1.110 + kRotate270, benchmark_iterations_); 1.111 +} 1.112 + 1.113 +TEST_F(libyuvTest, I420Rotate0_Odd) { 1.114 + I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.115 + benchmark_width_ - 3, benchmark_height_ - 1, 1.116 + kRotate0, benchmark_iterations_); 1.117 +} 1.118 + 1.119 +TEST_F(libyuvTest, I420Rotate90_Odd) { 1.120 + I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.121 + benchmark_height_ - 1, benchmark_width_ - 3, 1.122 + kRotate90, benchmark_iterations_); 1.123 +} 1.124 + 1.125 +TEST_F(libyuvTest, I420Rotate180_Odd) { 1.126 + I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.127 + benchmark_width_ - 3, benchmark_height_ - 1, 1.128 + kRotate180, benchmark_iterations_); 1.129 +} 1.130 + 1.131 +TEST_F(libyuvTest, I420Rotate270_Odd) { 1.132 + I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.133 + benchmark_height_ - 1, benchmark_width_ - 3, 1.134 + kRotate270, benchmark_iterations_); 1.135 +} 1.136 + 1.137 +static void NV12TestRotate(int src_width, int src_height, 1.138 + int dst_width, int dst_height, 1.139 + libyuv::RotationMode mode, 1.140 + int benchmark_iterations) { 1.141 + if (src_width < 1) { 1.142 + src_width = 1; 1.143 + } 1.144 + if (src_height < 1) { 1.145 + src_height = 1; 1.146 + } 1.147 + if (dst_width < 1) { 1.148 + dst_width = 1; 1.149 + } 1.150 + if (dst_height < 1) { 1.151 + dst_height = 1; 1.152 + } 1.153 + int src_nv12_y_size = src_width * src_height; 1.154 + int src_nv12_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2) * 2; 1.155 + int src_nv12_size = src_nv12_y_size + src_nv12_uv_size; 1.156 + align_buffer_64(src_nv12, src_nv12_size); 1.157 + for (int i = 0; i < src_nv12_size; ++i) { 1.158 + src_nv12[i] = random() & 0xff; 1.159 + } 1.160 + 1.161 + int dst_i420_y_size = dst_width * dst_height; 1.162 + int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); 1.163 + int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; 1.164 + align_buffer_64(dst_i420_c, dst_i420_size); 1.165 + align_buffer_64(dst_i420_opt, dst_i420_size); 1.166 + memset(dst_i420_c, 2, dst_i420_size); 1.167 + memset(dst_i420_opt, 3, dst_i420_size); 1.168 + 1.169 + MaskCpuFlags(0); // Disable all CPU optimization. 1.170 + NV12ToI420Rotate(src_nv12, src_width, 1.171 + src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, 1.172 + dst_i420_c, dst_width, 1.173 + dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, 1.174 + dst_i420_c + dst_i420_y_size + dst_i420_uv_size, 1.175 + (dst_width + 1) / 2, 1.176 + src_width, src_height, mode); 1.177 + 1.178 + MaskCpuFlags(-1); // Enable all CPU optimization. 1.179 + for (int i = 0; i < benchmark_iterations; ++i) { 1.180 + NV12ToI420Rotate(src_nv12, src_width, 1.181 + src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, 1.182 + dst_i420_opt, dst_width, 1.183 + dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, 1.184 + dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, 1.185 + (dst_width + 1) / 2, 1.186 + src_width, src_height, mode); 1.187 + } 1.188 + 1.189 + // Rotation should be exact. 1.190 + for (int i = 0; i < dst_i420_size; ++i) { 1.191 + EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); 1.192 + } 1.193 + 1.194 + free_aligned_buffer_64(dst_i420_c); 1.195 + free_aligned_buffer_64(dst_i420_opt); 1.196 + free_aligned_buffer_64(src_nv12); 1.197 +} 1.198 + 1.199 +TEST_F(libyuvTest, NV12Rotate0) { 1.200 + NV12TestRotate(benchmark_width_, benchmark_height_, 1.201 + benchmark_width_, benchmark_height_, 1.202 + kRotate0, benchmark_iterations_); 1.203 +} 1.204 + 1.205 +TEST_F(libyuvTest, NV12Rotate90) { 1.206 + NV12TestRotate(benchmark_width_, benchmark_height_, 1.207 + benchmark_height_, benchmark_width_, 1.208 + kRotate90, benchmark_iterations_); 1.209 +} 1.210 + 1.211 +TEST_F(libyuvTest, NV12Rotate180) { 1.212 + NV12TestRotate(benchmark_width_, benchmark_height_, 1.213 + benchmark_width_, benchmark_height_, 1.214 + kRotate180, benchmark_iterations_); 1.215 +} 1.216 + 1.217 +TEST_F(libyuvTest, NV12Rotate270) { 1.218 + NV12TestRotate(benchmark_width_, benchmark_height_, 1.219 + benchmark_height_, benchmark_width_, 1.220 + kRotate270, benchmark_iterations_); 1.221 +} 1.222 + 1.223 +TEST_F(libyuvTest, NV12Rotate0_Odd) { 1.224 + NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.225 + benchmark_width_ - 3, benchmark_height_ - 1, 1.226 + kRotate0, benchmark_iterations_); 1.227 +} 1.228 + 1.229 +TEST_F(libyuvTest, NV12Rotate90_Odd) { 1.230 + NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.231 + benchmark_height_ - 1, benchmark_width_ - 3, 1.232 + kRotate90, benchmark_iterations_); 1.233 +} 1.234 + 1.235 +TEST_F(libyuvTest, NV12Rotate180_Odd) { 1.236 + NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.237 + benchmark_width_ - 3, benchmark_height_ - 1, 1.238 + kRotate180, benchmark_iterations_); 1.239 +} 1.240 + 1.241 +TEST_F(libyuvTest, NV12Rotate270_Odd) { 1.242 + NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, 1.243 + benchmark_height_ - 1, benchmark_width_ - 3, 1.244 + kRotate270, benchmark_iterations_); 1.245 +} 1.246 + 1.247 +} // namespace libyuv