media/libyuv/unit_test/rotate_argb_test.cc

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
     3  *
     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
     6  *  tree. An additional intellectual property rights grant can be found
     7  *  in the file PATENTS. All contributing project authors may
     8  *  be found in the AUTHORS file in the root of the source tree.
     9  */
    11 #include <stdlib.h>
    12 #include <time.h>
    14 #include "libyuv/cpu_id.h"
    15 #include "libyuv/rotate_argb.h"
    16 #include "libyuv/row.h"
    17 #include "../unit_test/unit_test.h"
    19 namespace libyuv {
    21 void TestRotateBpp(int src_width, int src_height,
    22                    int dst_width, int dst_height,
    23                    libyuv::RotationMode mode,
    24                    int benchmark_iterations,
    25                    const int kBpp) {
    26   if (src_width < 1) {
    27     src_width = 1;
    28   }
    29   if (src_height < 1) {
    30     src_height = 1;
    31   }
    32   if (dst_width < 1) {
    33     dst_width = 1;
    34   }
    35   if (dst_height < 1) {
    36     dst_height = 1;
    37   }
    38   int src_stride_argb = src_width * kBpp;
    39   int src_argb_plane_size = src_stride_argb * src_height;
    40   align_buffer_64(src_argb, src_argb_plane_size);
    41   for (int i = 0; i < src_argb_plane_size; ++i) {
    42     src_argb[i] = random() & 0xff;
    43   }
    45   int dst_stride_argb = dst_width * kBpp;
    46   int dst_argb_plane_size = dst_stride_argb * dst_height;
    47   align_buffer_64(dst_argb_c, dst_argb_plane_size);
    48   align_buffer_64(dst_argb_opt, dst_argb_plane_size);
    49   memset(dst_argb_c, 2, dst_argb_plane_size);
    50   memset(dst_argb_opt, 3, dst_argb_plane_size);
    52   if (kBpp == 1) {
    53     MaskCpuFlags(0);  // Disable all CPU optimization.
    54     RotatePlane(src_argb, src_stride_argb,
    55                 dst_argb_c, dst_stride_argb,
    56                 src_width, src_height, mode);
    58     MaskCpuFlags(-1);  // Enable all CPU optimization.
    59     for (int i = 0; i < benchmark_iterations; ++i) {
    60       RotatePlane(src_argb, src_stride_argb,
    61                   dst_argb_opt, dst_stride_argb,
    62                   src_width, src_height, mode);
    63     }
    64   } else if (kBpp == 4) {
    65     MaskCpuFlags(0);  // Disable all CPU optimization.
    66     ARGBRotate(src_argb, src_stride_argb,
    67                dst_argb_c, dst_stride_argb,
    68                src_width, src_height, mode);
    70     MaskCpuFlags(-1);  // Enable all CPU optimization.
    71     for (int i = 0; i < benchmark_iterations; ++i) {
    72       ARGBRotate(src_argb, src_stride_argb,
    73                  dst_argb_opt, dst_stride_argb,
    74                  src_width, src_height, mode);
    75     }
    76   }
    78   // Rotation should be exact.
    79   for (int i = 0; i < dst_argb_plane_size; ++i) {
    80     EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
    81   }
    83   free_aligned_buffer_64(dst_argb_c);
    84   free_aligned_buffer_64(dst_argb_opt);
    85   free_aligned_buffer_64(src_argb);
    86 }
    88 static void ARGBTestRotate(int src_width, int src_height,
    89                            int dst_width, int dst_height,
    90                            libyuv::RotationMode mode,
    91                            int benchmark_iterations) {
    92   TestRotateBpp(src_width, src_height,
    93                 dst_width, dst_height,
    94                 mode, benchmark_iterations, 4);
    95 }
    97 TEST_F(libyuvTest, ARGBRotate0) {
    98   ARGBTestRotate(benchmark_width_, benchmark_height_,
    99                  benchmark_width_, benchmark_height_,
   100                  kRotate0, benchmark_iterations_);
   101 }
   103 TEST_F(libyuvTest, ARGBRotate90) {
   104   ARGBTestRotate(benchmark_width_, benchmark_height_,
   105                  benchmark_height_, benchmark_width_,
   106                  kRotate90, benchmark_iterations_);
   107 }
   109 TEST_F(libyuvTest, ARGBRotate180) {
   110   ARGBTestRotate(benchmark_width_, benchmark_height_,
   111                  benchmark_width_, benchmark_height_,
   112                  kRotate180, benchmark_iterations_);
   113 }
   115 TEST_F(libyuvTest, ARGBRotate270) {
   116   ARGBTestRotate(benchmark_width_, benchmark_height_,
   117                  benchmark_height_, benchmark_width_,
   118                  kRotate270, benchmark_iterations_);
   119 }
   121 TEST_F(libyuvTest, ARGBRotate0_Odd) {
   122   ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   123                  benchmark_width_ - 3, benchmark_height_ - 1,
   124                  kRotate0, benchmark_iterations_);
   125 }
   127 TEST_F(libyuvTest, ARGBRotate90_Odd) {
   128   ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   129                  benchmark_height_ - 1, benchmark_width_ - 3,
   130                  kRotate90, benchmark_iterations_);
   131 }
   133 TEST_F(libyuvTest, ARGBRotate180_Odd) {
   134   ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   135                  benchmark_width_ - 3, benchmark_height_ - 1,
   136                  kRotate180, benchmark_iterations_);
   137 }
   139 TEST_F(libyuvTest, ARGBRotate270_Odd) {
   140   ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
   141                  benchmark_height_ - 1, benchmark_width_ - 3,
   142                  kRotate270, benchmark_iterations_);
   143 }
   145 static void TestRotatePlane(int src_width, int src_height,
   146                             int dst_width, int dst_height,
   147                             libyuv::RotationMode mode,
   148                             int benchmark_iterations) {
   149   TestRotateBpp(src_width, src_height,
   150                 dst_width, dst_height,
   151                 mode, benchmark_iterations, 1);
   152 }
   154 TEST_F(libyuvTest, RotatePlane0) {
   155   TestRotatePlane(benchmark_width_, benchmark_height_,
   156                   benchmark_width_, benchmark_height_,
   157                   kRotate0, benchmark_iterations_);
   158 }
   160 TEST_F(libyuvTest, RotatePlane90) {
   161   TestRotatePlane(benchmark_width_, benchmark_height_,
   162                   benchmark_height_, benchmark_width_,
   163                   kRotate90, benchmark_iterations_);
   164 }
   166 TEST_F(libyuvTest, RotatePlane180) {
   167   TestRotatePlane(benchmark_width_, benchmark_height_,
   168                   benchmark_width_, benchmark_height_,
   169                   kRotate180, benchmark_iterations_);
   170 }
   172 TEST_F(libyuvTest, RotatePlane270) {
   173   TestRotatePlane(benchmark_width_, benchmark_height_,
   174                   benchmark_height_, benchmark_width_,
   175                   kRotate270, benchmark_iterations_);
   176 }
   178 TEST_F(libyuvTest, RotatePlane0_Odd) {
   179   TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   180                   benchmark_width_ - 3, benchmark_height_ - 1,
   181                   kRotate0, benchmark_iterations_);
   182 }
   184 TEST_F(libyuvTest, RotatePlane90_Odd) {
   185   TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   186                   benchmark_height_ - 1, benchmark_width_ - 3,
   187                   kRotate90, benchmark_iterations_);
   188 }
   190 TEST_F(libyuvTest, RotatePlane180_Odd) {
   191   TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   192                   benchmark_width_ - 3, benchmark_height_ - 1,
   193                   kRotate180, benchmark_iterations_);
   194 }
   196 TEST_F(libyuvTest, RotatePlane270_Odd) {
   197   TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
   198                   benchmark_height_ - 1, benchmark_width_ - 3,
   199                   kRotate270, benchmark_iterations_);
   200 }
   202 }  // namespace libyuv

mercurial