Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include <stdlib.h> |
michael@0 | 12 | #include <time.h> |
michael@0 | 13 | |
michael@0 | 14 | #include "libyuv/cpu_id.h" |
michael@0 | 15 | #include "libyuv/rotate.h" |
michael@0 | 16 | #include "libyuv/row.h" |
michael@0 | 17 | #include "../unit_test/unit_test.h" |
michael@0 | 18 | |
michael@0 | 19 | namespace libyuv { |
michael@0 | 20 | |
michael@0 | 21 | static void I420TestRotate(int src_width, int src_height, |
michael@0 | 22 | int dst_width, int dst_height, |
michael@0 | 23 | libyuv::RotationMode mode, |
michael@0 | 24 | int benchmark_iterations) { |
michael@0 | 25 | if (src_width < 1) { |
michael@0 | 26 | src_width = 1; |
michael@0 | 27 | } |
michael@0 | 28 | if (src_height < 1) { |
michael@0 | 29 | src_height = 1; |
michael@0 | 30 | } |
michael@0 | 31 | if (dst_width < 1) { |
michael@0 | 32 | dst_width = 1; |
michael@0 | 33 | } |
michael@0 | 34 | if (dst_height < 1) { |
michael@0 | 35 | dst_height = 1; |
michael@0 | 36 | } |
michael@0 | 37 | int src_i420_y_size = src_width * src_height; |
michael@0 | 38 | int src_i420_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2); |
michael@0 | 39 | int src_i420_size = src_i420_y_size + src_i420_uv_size * 2; |
michael@0 | 40 | align_buffer_64(src_i420, src_i420_size); |
michael@0 | 41 | for (int i = 0; i < src_i420_size; ++i) { |
michael@0 | 42 | src_i420[i] = random() & 0xff; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | int dst_i420_y_size = dst_width * dst_height; |
michael@0 | 46 | int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); |
michael@0 | 47 | int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; |
michael@0 | 48 | align_buffer_64(dst_i420_c, dst_i420_size); |
michael@0 | 49 | align_buffer_64(dst_i420_opt, dst_i420_size); |
michael@0 | 50 | memset(dst_i420_c, 2, dst_i420_size); |
michael@0 | 51 | memset(dst_i420_opt, 3, dst_i420_size); |
michael@0 | 52 | |
michael@0 | 53 | MaskCpuFlags(0); // Disable all CPU optimization. |
michael@0 | 54 | I420Rotate(src_i420, src_width, |
michael@0 | 55 | src_i420 + src_i420_y_size, (src_width + 1) / 2, |
michael@0 | 56 | src_i420 + src_i420_y_size + src_i420_uv_size, (src_width + 1) / 2, |
michael@0 | 57 | dst_i420_c, dst_width, |
michael@0 | 58 | dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, |
michael@0 | 59 | dst_i420_c + dst_i420_y_size + dst_i420_uv_size, |
michael@0 | 60 | (dst_width + 1) / 2, |
michael@0 | 61 | src_width, src_height, mode); |
michael@0 | 62 | |
michael@0 | 63 | MaskCpuFlags(-1); // Enable all CPU optimization. |
michael@0 | 64 | for (int i = 0; i < benchmark_iterations; ++i) { |
michael@0 | 65 | I420Rotate(src_i420, src_width, |
michael@0 | 66 | src_i420 + src_i420_y_size, (src_width + 1) / 2, |
michael@0 | 67 | src_i420 + src_i420_y_size + src_i420_uv_size, |
michael@0 | 68 | (src_width + 1) / 2, |
michael@0 | 69 | dst_i420_opt, dst_width, |
michael@0 | 70 | dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, |
michael@0 | 71 | dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, |
michael@0 | 72 | (dst_width + 1) / 2, |
michael@0 | 73 | src_width, src_height, mode); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | // Rotation should be exact. |
michael@0 | 77 | for (int i = 0; i < dst_i420_size; ++i) { |
michael@0 | 78 | EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | free_aligned_buffer_64(dst_i420_c); |
michael@0 | 82 | free_aligned_buffer_64(dst_i420_opt); |
michael@0 | 83 | free_aligned_buffer_64(src_i420); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | TEST_F(libyuvTest, I420Rotate0) { |
michael@0 | 87 | I420TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 88 | benchmark_width_, benchmark_height_, |
michael@0 | 89 | kRotate0, benchmark_iterations_); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | TEST_F(libyuvTest, I420Rotate90) { |
michael@0 | 93 | I420TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 94 | benchmark_height_, benchmark_width_, |
michael@0 | 95 | kRotate90, benchmark_iterations_); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | TEST_F(libyuvTest, I420Rotate180) { |
michael@0 | 99 | I420TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 100 | benchmark_width_, benchmark_height_, |
michael@0 | 101 | kRotate180, benchmark_iterations_); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | TEST_F(libyuvTest, I420Rotate270) { |
michael@0 | 105 | I420TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 106 | benchmark_height_, benchmark_width_, |
michael@0 | 107 | kRotate270, benchmark_iterations_); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | TEST_F(libyuvTest, I420Rotate0_Odd) { |
michael@0 | 111 | I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 112 | benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 113 | kRotate0, benchmark_iterations_); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | TEST_F(libyuvTest, I420Rotate90_Odd) { |
michael@0 | 117 | I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 118 | benchmark_height_ - 1, benchmark_width_ - 3, |
michael@0 | 119 | kRotate90, benchmark_iterations_); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | TEST_F(libyuvTest, I420Rotate180_Odd) { |
michael@0 | 123 | I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 124 | benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 125 | kRotate180, benchmark_iterations_); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | TEST_F(libyuvTest, I420Rotate270_Odd) { |
michael@0 | 129 | I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 130 | benchmark_height_ - 1, benchmark_width_ - 3, |
michael@0 | 131 | kRotate270, benchmark_iterations_); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | static void NV12TestRotate(int src_width, int src_height, |
michael@0 | 135 | int dst_width, int dst_height, |
michael@0 | 136 | libyuv::RotationMode mode, |
michael@0 | 137 | int benchmark_iterations) { |
michael@0 | 138 | if (src_width < 1) { |
michael@0 | 139 | src_width = 1; |
michael@0 | 140 | } |
michael@0 | 141 | if (src_height < 1) { |
michael@0 | 142 | src_height = 1; |
michael@0 | 143 | } |
michael@0 | 144 | if (dst_width < 1) { |
michael@0 | 145 | dst_width = 1; |
michael@0 | 146 | } |
michael@0 | 147 | if (dst_height < 1) { |
michael@0 | 148 | dst_height = 1; |
michael@0 | 149 | } |
michael@0 | 150 | int src_nv12_y_size = src_width * src_height; |
michael@0 | 151 | int src_nv12_uv_size = ((src_width + 1) / 2) * ((src_height + 1) / 2) * 2; |
michael@0 | 152 | int src_nv12_size = src_nv12_y_size + src_nv12_uv_size; |
michael@0 | 153 | align_buffer_64(src_nv12, src_nv12_size); |
michael@0 | 154 | for (int i = 0; i < src_nv12_size; ++i) { |
michael@0 | 155 | src_nv12[i] = random() & 0xff; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | int dst_i420_y_size = dst_width * dst_height; |
michael@0 | 159 | int dst_i420_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); |
michael@0 | 160 | int dst_i420_size = dst_i420_y_size + dst_i420_uv_size * 2; |
michael@0 | 161 | align_buffer_64(dst_i420_c, dst_i420_size); |
michael@0 | 162 | align_buffer_64(dst_i420_opt, dst_i420_size); |
michael@0 | 163 | memset(dst_i420_c, 2, dst_i420_size); |
michael@0 | 164 | memset(dst_i420_opt, 3, dst_i420_size); |
michael@0 | 165 | |
michael@0 | 166 | MaskCpuFlags(0); // Disable all CPU optimization. |
michael@0 | 167 | NV12ToI420Rotate(src_nv12, src_width, |
michael@0 | 168 | src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, |
michael@0 | 169 | dst_i420_c, dst_width, |
michael@0 | 170 | dst_i420_c + dst_i420_y_size, (dst_width + 1) / 2, |
michael@0 | 171 | dst_i420_c + dst_i420_y_size + dst_i420_uv_size, |
michael@0 | 172 | (dst_width + 1) / 2, |
michael@0 | 173 | src_width, src_height, mode); |
michael@0 | 174 | |
michael@0 | 175 | MaskCpuFlags(-1); // Enable all CPU optimization. |
michael@0 | 176 | for (int i = 0; i < benchmark_iterations; ++i) { |
michael@0 | 177 | NV12ToI420Rotate(src_nv12, src_width, |
michael@0 | 178 | src_nv12 + src_nv12_y_size, (src_width + 1) & ~1, |
michael@0 | 179 | dst_i420_opt, dst_width, |
michael@0 | 180 | dst_i420_opt + dst_i420_y_size, (dst_width + 1) / 2, |
michael@0 | 181 | dst_i420_opt + dst_i420_y_size + dst_i420_uv_size, |
michael@0 | 182 | (dst_width + 1) / 2, |
michael@0 | 183 | src_width, src_height, mode); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | // Rotation should be exact. |
michael@0 | 187 | for (int i = 0; i < dst_i420_size; ++i) { |
michael@0 | 188 | EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | free_aligned_buffer_64(dst_i420_c); |
michael@0 | 192 | free_aligned_buffer_64(dst_i420_opt); |
michael@0 | 193 | free_aligned_buffer_64(src_nv12); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | TEST_F(libyuvTest, NV12Rotate0) { |
michael@0 | 197 | NV12TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 198 | benchmark_width_, benchmark_height_, |
michael@0 | 199 | kRotate0, benchmark_iterations_); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | TEST_F(libyuvTest, NV12Rotate90) { |
michael@0 | 203 | NV12TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 204 | benchmark_height_, benchmark_width_, |
michael@0 | 205 | kRotate90, benchmark_iterations_); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | TEST_F(libyuvTest, NV12Rotate180) { |
michael@0 | 209 | NV12TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 210 | benchmark_width_, benchmark_height_, |
michael@0 | 211 | kRotate180, benchmark_iterations_); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | TEST_F(libyuvTest, NV12Rotate270) { |
michael@0 | 215 | NV12TestRotate(benchmark_width_, benchmark_height_, |
michael@0 | 216 | benchmark_height_, benchmark_width_, |
michael@0 | 217 | kRotate270, benchmark_iterations_); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | TEST_F(libyuvTest, NV12Rotate0_Odd) { |
michael@0 | 221 | NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 222 | benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 223 | kRotate0, benchmark_iterations_); |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | TEST_F(libyuvTest, NV12Rotate90_Odd) { |
michael@0 | 227 | NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 228 | benchmark_height_ - 1, benchmark_width_ - 3, |
michael@0 | 229 | kRotate90, benchmark_iterations_); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | TEST_F(libyuvTest, NV12Rotate180_Odd) { |
michael@0 | 233 | NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 234 | benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 235 | kRotate180, benchmark_iterations_); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | TEST_F(libyuvTest, NV12Rotate270_Odd) { |
michael@0 | 239 | NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
michael@0 | 240 | benchmark_height_ - 1, benchmark_width_ - 3, |
michael@0 | 241 | kRotate270, benchmark_iterations_); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | } // namespace libyuv |