media/libyuv/unit_test/rotate_argb_test.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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_argb.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 void TestRotateBpp(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 const int kBpp) {
michael@0 26 if (src_width < 1) {
michael@0 27 src_width = 1;
michael@0 28 }
michael@0 29 if (src_height < 1) {
michael@0 30 src_height = 1;
michael@0 31 }
michael@0 32 if (dst_width < 1) {
michael@0 33 dst_width = 1;
michael@0 34 }
michael@0 35 if (dst_height < 1) {
michael@0 36 dst_height = 1;
michael@0 37 }
michael@0 38 int src_stride_argb = src_width * kBpp;
michael@0 39 int src_argb_plane_size = src_stride_argb * src_height;
michael@0 40 align_buffer_64(src_argb, src_argb_plane_size);
michael@0 41 for (int i = 0; i < src_argb_plane_size; ++i) {
michael@0 42 src_argb[i] = random() & 0xff;
michael@0 43 }
michael@0 44
michael@0 45 int dst_stride_argb = dst_width * kBpp;
michael@0 46 int dst_argb_plane_size = dst_stride_argb * dst_height;
michael@0 47 align_buffer_64(dst_argb_c, dst_argb_plane_size);
michael@0 48 align_buffer_64(dst_argb_opt, dst_argb_plane_size);
michael@0 49 memset(dst_argb_c, 2, dst_argb_plane_size);
michael@0 50 memset(dst_argb_opt, 3, dst_argb_plane_size);
michael@0 51
michael@0 52 if (kBpp == 1) {
michael@0 53 MaskCpuFlags(0); // Disable all CPU optimization.
michael@0 54 RotatePlane(src_argb, src_stride_argb,
michael@0 55 dst_argb_c, dst_stride_argb,
michael@0 56 src_width, src_height, mode);
michael@0 57
michael@0 58 MaskCpuFlags(-1); // Enable all CPU optimization.
michael@0 59 for (int i = 0; i < benchmark_iterations; ++i) {
michael@0 60 RotatePlane(src_argb, src_stride_argb,
michael@0 61 dst_argb_opt, dst_stride_argb,
michael@0 62 src_width, src_height, mode);
michael@0 63 }
michael@0 64 } else if (kBpp == 4) {
michael@0 65 MaskCpuFlags(0); // Disable all CPU optimization.
michael@0 66 ARGBRotate(src_argb, src_stride_argb,
michael@0 67 dst_argb_c, dst_stride_argb,
michael@0 68 src_width, src_height, mode);
michael@0 69
michael@0 70 MaskCpuFlags(-1); // Enable all CPU optimization.
michael@0 71 for (int i = 0; i < benchmark_iterations; ++i) {
michael@0 72 ARGBRotate(src_argb, src_stride_argb,
michael@0 73 dst_argb_opt, dst_stride_argb,
michael@0 74 src_width, src_height, mode);
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 // Rotation should be exact.
michael@0 79 for (int i = 0; i < dst_argb_plane_size; ++i) {
michael@0 80 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
michael@0 81 }
michael@0 82
michael@0 83 free_aligned_buffer_64(dst_argb_c);
michael@0 84 free_aligned_buffer_64(dst_argb_opt);
michael@0 85 free_aligned_buffer_64(src_argb);
michael@0 86 }
michael@0 87
michael@0 88 static void ARGBTestRotate(int src_width, int src_height,
michael@0 89 int dst_width, int dst_height,
michael@0 90 libyuv::RotationMode mode,
michael@0 91 int benchmark_iterations) {
michael@0 92 TestRotateBpp(src_width, src_height,
michael@0 93 dst_width, dst_height,
michael@0 94 mode, benchmark_iterations, 4);
michael@0 95 }
michael@0 96
michael@0 97 TEST_F(libyuvTest, ARGBRotate0) {
michael@0 98 ARGBTestRotate(benchmark_width_, benchmark_height_,
michael@0 99 benchmark_width_, benchmark_height_,
michael@0 100 kRotate0, benchmark_iterations_);
michael@0 101 }
michael@0 102
michael@0 103 TEST_F(libyuvTest, ARGBRotate90) {
michael@0 104 ARGBTestRotate(benchmark_width_, benchmark_height_,
michael@0 105 benchmark_height_, benchmark_width_,
michael@0 106 kRotate90, benchmark_iterations_);
michael@0 107 }
michael@0 108
michael@0 109 TEST_F(libyuvTest, ARGBRotate180) {
michael@0 110 ARGBTestRotate(benchmark_width_, benchmark_height_,
michael@0 111 benchmark_width_, benchmark_height_,
michael@0 112 kRotate180, benchmark_iterations_);
michael@0 113 }
michael@0 114
michael@0 115 TEST_F(libyuvTest, ARGBRotate270) {
michael@0 116 ARGBTestRotate(benchmark_width_, benchmark_height_,
michael@0 117 benchmark_height_, benchmark_width_,
michael@0 118 kRotate270, benchmark_iterations_);
michael@0 119 }
michael@0 120
michael@0 121 TEST_F(libyuvTest, ARGBRotate0_Odd) {
michael@0 122 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 123 benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 124 kRotate0, benchmark_iterations_);
michael@0 125 }
michael@0 126
michael@0 127 TEST_F(libyuvTest, ARGBRotate90_Odd) {
michael@0 128 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 129 benchmark_height_ - 1, benchmark_width_ - 3,
michael@0 130 kRotate90, benchmark_iterations_);
michael@0 131 }
michael@0 132
michael@0 133 TEST_F(libyuvTest, ARGBRotate180_Odd) {
michael@0 134 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 135 benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 136 kRotate180, benchmark_iterations_);
michael@0 137 }
michael@0 138
michael@0 139 TEST_F(libyuvTest, ARGBRotate270_Odd) {
michael@0 140 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 141 benchmark_height_ - 1, benchmark_width_ - 3,
michael@0 142 kRotate270, benchmark_iterations_);
michael@0 143 }
michael@0 144
michael@0 145 static void TestRotatePlane(int src_width, int src_height,
michael@0 146 int dst_width, int dst_height,
michael@0 147 libyuv::RotationMode mode,
michael@0 148 int benchmark_iterations) {
michael@0 149 TestRotateBpp(src_width, src_height,
michael@0 150 dst_width, dst_height,
michael@0 151 mode, benchmark_iterations, 1);
michael@0 152 }
michael@0 153
michael@0 154 TEST_F(libyuvTest, RotatePlane0) {
michael@0 155 TestRotatePlane(benchmark_width_, benchmark_height_,
michael@0 156 benchmark_width_, benchmark_height_,
michael@0 157 kRotate0, benchmark_iterations_);
michael@0 158 }
michael@0 159
michael@0 160 TEST_F(libyuvTest, RotatePlane90) {
michael@0 161 TestRotatePlane(benchmark_width_, benchmark_height_,
michael@0 162 benchmark_height_, benchmark_width_,
michael@0 163 kRotate90, benchmark_iterations_);
michael@0 164 }
michael@0 165
michael@0 166 TEST_F(libyuvTest, RotatePlane180) {
michael@0 167 TestRotatePlane(benchmark_width_, benchmark_height_,
michael@0 168 benchmark_width_, benchmark_height_,
michael@0 169 kRotate180, benchmark_iterations_);
michael@0 170 }
michael@0 171
michael@0 172 TEST_F(libyuvTest, RotatePlane270) {
michael@0 173 TestRotatePlane(benchmark_width_, benchmark_height_,
michael@0 174 benchmark_height_, benchmark_width_,
michael@0 175 kRotate270, benchmark_iterations_);
michael@0 176 }
michael@0 177
michael@0 178 TEST_F(libyuvTest, RotatePlane0_Odd) {
michael@0 179 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 180 benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 181 kRotate0, benchmark_iterations_);
michael@0 182 }
michael@0 183
michael@0 184 TEST_F(libyuvTest, RotatePlane90_Odd) {
michael@0 185 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 186 benchmark_height_ - 1, benchmark_width_ - 3,
michael@0 187 kRotate90, benchmark_iterations_);
michael@0 188 }
michael@0 189
michael@0 190 TEST_F(libyuvTest, RotatePlane180_Odd) {
michael@0 191 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 192 benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 193 kRotate180, benchmark_iterations_);
michael@0 194 }
michael@0 195
michael@0 196 TEST_F(libyuvTest, RotatePlane270_Odd) {
michael@0 197 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
michael@0 198 benchmark_height_ - 1, benchmark_width_ - 3,
michael@0 199 kRotate270, benchmark_iterations_);
michael@0 200 }
michael@0 201
michael@0 202 } // namespace libyuv

mercurial