media/libyuv/unit_test/rotate_argb_test.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libyuv/unit_test/rotate_argb_test.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,202 @@
     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_argb.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 +void TestRotateBpp(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 +                   const int kBpp) {
    1.29 +  if (src_width < 1) {
    1.30 +    src_width = 1;
    1.31 +  }
    1.32 +  if (src_height < 1) {
    1.33 +    src_height = 1;
    1.34 +  }
    1.35 +  if (dst_width < 1) {
    1.36 +    dst_width = 1;
    1.37 +  }
    1.38 +  if (dst_height < 1) {
    1.39 +    dst_height = 1;
    1.40 +  }
    1.41 +  int src_stride_argb = src_width * kBpp;
    1.42 +  int src_argb_plane_size = src_stride_argb * src_height;
    1.43 +  align_buffer_64(src_argb, src_argb_plane_size);
    1.44 +  for (int i = 0; i < src_argb_plane_size; ++i) {
    1.45 +    src_argb[i] = random() & 0xff;
    1.46 +  }
    1.47 +
    1.48 +  int dst_stride_argb = dst_width * kBpp;
    1.49 +  int dst_argb_plane_size = dst_stride_argb * dst_height;
    1.50 +  align_buffer_64(dst_argb_c, dst_argb_plane_size);
    1.51 +  align_buffer_64(dst_argb_opt, dst_argb_plane_size);
    1.52 +  memset(dst_argb_c, 2, dst_argb_plane_size);
    1.53 +  memset(dst_argb_opt, 3, dst_argb_plane_size);
    1.54 +
    1.55 +  if (kBpp == 1) {
    1.56 +    MaskCpuFlags(0);  // Disable all CPU optimization.
    1.57 +    RotatePlane(src_argb, src_stride_argb,
    1.58 +                dst_argb_c, dst_stride_argb,
    1.59 +                src_width, src_height, mode);
    1.60 +
    1.61 +    MaskCpuFlags(-1);  // Enable all CPU optimization.
    1.62 +    for (int i = 0; i < benchmark_iterations; ++i) {
    1.63 +      RotatePlane(src_argb, src_stride_argb,
    1.64 +                  dst_argb_opt, dst_stride_argb,
    1.65 +                  src_width, src_height, mode);
    1.66 +    }
    1.67 +  } else if (kBpp == 4) {
    1.68 +    MaskCpuFlags(0);  // Disable all CPU optimization.
    1.69 +    ARGBRotate(src_argb, src_stride_argb,
    1.70 +               dst_argb_c, dst_stride_argb,
    1.71 +               src_width, src_height, mode);
    1.72 +
    1.73 +    MaskCpuFlags(-1);  // Enable all CPU optimization.
    1.74 +    for (int i = 0; i < benchmark_iterations; ++i) {
    1.75 +      ARGBRotate(src_argb, src_stride_argb,
    1.76 +                 dst_argb_opt, dst_stride_argb,
    1.77 +                 src_width, src_height, mode);
    1.78 +    }
    1.79 +  }
    1.80 +
    1.81 +  // Rotation should be exact.
    1.82 +  for (int i = 0; i < dst_argb_plane_size; ++i) {
    1.83 +    EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
    1.84 +  }
    1.85 +
    1.86 +  free_aligned_buffer_64(dst_argb_c);
    1.87 +  free_aligned_buffer_64(dst_argb_opt);
    1.88 +  free_aligned_buffer_64(src_argb);
    1.89 +}
    1.90 +
    1.91 +static void ARGBTestRotate(int src_width, int src_height,
    1.92 +                           int dst_width, int dst_height,
    1.93 +                           libyuv::RotationMode mode,
    1.94 +                           int benchmark_iterations) {
    1.95 +  TestRotateBpp(src_width, src_height,
    1.96 +                dst_width, dst_height,
    1.97 +                mode, benchmark_iterations, 4);
    1.98 +}
    1.99 +
   1.100 +TEST_F(libyuvTest, ARGBRotate0) {
   1.101 +  ARGBTestRotate(benchmark_width_, benchmark_height_,
   1.102 +                 benchmark_width_, benchmark_height_,
   1.103 +                 kRotate0, benchmark_iterations_);
   1.104 +}
   1.105 +
   1.106 +TEST_F(libyuvTest, ARGBRotate90) {
   1.107 +  ARGBTestRotate(benchmark_width_, benchmark_height_,
   1.108 +                 benchmark_height_, benchmark_width_,
   1.109 +                 kRotate90, benchmark_iterations_);
   1.110 +}
   1.111 +
   1.112 +TEST_F(libyuvTest, ARGBRotate180) {
   1.113 +  ARGBTestRotate(benchmark_width_, benchmark_height_,
   1.114 +                 benchmark_width_, benchmark_height_,
   1.115 +                 kRotate180, benchmark_iterations_);
   1.116 +}
   1.117 +
   1.118 +TEST_F(libyuvTest, ARGBRotate270) {
   1.119 +  ARGBTestRotate(benchmark_width_, benchmark_height_,
   1.120 +                 benchmark_height_, benchmark_width_,
   1.121 +                 kRotate270, benchmark_iterations_);
   1.122 +}
   1.123 +
   1.124 +TEST_F(libyuvTest, ARGBRotate0_Odd) {
   1.125 +  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   1.126 +                 benchmark_width_ - 3, benchmark_height_ - 1,
   1.127 +                 kRotate0, benchmark_iterations_);
   1.128 +}
   1.129 +
   1.130 +TEST_F(libyuvTest, ARGBRotate90_Odd) {
   1.131 +  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   1.132 +                 benchmark_height_ - 1, benchmark_width_ - 3,
   1.133 +                 kRotate90, benchmark_iterations_);
   1.134 +}
   1.135 +
   1.136 +TEST_F(libyuvTest, ARGBRotate180_Odd) {
   1.137 +  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   1.138 +                 benchmark_width_ - 3, benchmark_height_ - 1,
   1.139 +                 kRotate180, benchmark_iterations_);
   1.140 +}
   1.141 +
   1.142 +TEST_F(libyuvTest, ARGBRotate270_Odd) {
   1.143 +  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   1.144 +                 benchmark_height_ - 1, benchmark_width_ - 3,
   1.145 +                 kRotate270, benchmark_iterations_);
   1.146 +}
   1.147 +
   1.148 +static void TestRotatePlane(int src_width, int src_height,
   1.149 +                            int dst_width, int dst_height,
   1.150 +                            libyuv::RotationMode mode,
   1.151 +                            int benchmark_iterations) {
   1.152 +  TestRotateBpp(src_width, src_height,
   1.153 +                dst_width, dst_height,
   1.154 +                mode, benchmark_iterations, 1);
   1.155 +}
   1.156 +
   1.157 +TEST_F(libyuvTest, RotatePlane0) {
   1.158 +  TestRotatePlane(benchmark_width_, benchmark_height_,
   1.159 +                  benchmark_width_, benchmark_height_,
   1.160 +                  kRotate0, benchmark_iterations_);
   1.161 +}
   1.162 +
   1.163 +TEST_F(libyuvTest, RotatePlane90) {
   1.164 +  TestRotatePlane(benchmark_width_, benchmark_height_,
   1.165 +                  benchmark_height_, benchmark_width_,
   1.166 +                  kRotate90, benchmark_iterations_);
   1.167 +}
   1.168 +
   1.169 +TEST_F(libyuvTest, RotatePlane180) {
   1.170 +  TestRotatePlane(benchmark_width_, benchmark_height_,
   1.171 +                  benchmark_width_, benchmark_height_,
   1.172 +                  kRotate180, benchmark_iterations_);
   1.173 +}
   1.174 +
   1.175 +TEST_F(libyuvTest, RotatePlane270) {
   1.176 +  TestRotatePlane(benchmark_width_, benchmark_height_,
   1.177 +                  benchmark_height_, benchmark_width_,
   1.178 +                  kRotate270, benchmark_iterations_);
   1.179 +}
   1.180 +
   1.181 +TEST_F(libyuvTest, RotatePlane0_Odd) {
   1.182 +  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   1.183 +                  benchmark_width_ - 3, benchmark_height_ - 1,
   1.184 +                  kRotate0, benchmark_iterations_);
   1.185 +}
   1.186 +
   1.187 +TEST_F(libyuvTest, RotatePlane90_Odd) {
   1.188 +  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   1.189 +                  benchmark_height_ - 1, benchmark_width_ - 3,
   1.190 +                  kRotate90, benchmark_iterations_);
   1.191 +}
   1.192 +
   1.193 +TEST_F(libyuvTest, RotatePlane180_Odd) {
   1.194 +  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   1.195 +                  benchmark_width_ - 3, benchmark_height_ - 1,
   1.196 +                  kRotate180, benchmark_iterations_);
   1.197 +}
   1.198 +
   1.199 +TEST_F(libyuvTest, RotatePlane270_Odd) {
   1.200 +  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   1.201 +                  benchmark_height_ - 1, benchmark_width_ - 3,
   1.202 +                  kRotate270, benchmark_iterations_);
   1.203 +}
   1.204 +
   1.205 +}  // namespace libyuv

mercurial