LCOV - code coverage report
Current view: top level - third_party/aom/av1/common - resize.c (source / functions) Hit Total Coverage
Test: output.info Lines: 0 456 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 26 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
       3             :  *
       4             :  * This source code is subject to the terms of the BSD 2 Clause License and
       5             :  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
       6             :  * was not distributed with this source code in the LICENSE file, you can
       7             :  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
       8             :  * Media Patent License 1.0 was not distributed with this source code in the
       9             :  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
      10             :  */
      11             : 
      12             : #include <assert.h>
      13             : #include <limits.h>
      14             : #include <math.h>
      15             : #include <stdio.h>
      16             : #include <stdlib.h>
      17             : #include <string.h>
      18             : 
      19             : #include "./aom_config.h"
      20             : #if CONFIG_HIGHBITDEPTH
      21             : #include "aom_dsp/aom_dsp_common.h"
      22             : #endif  // CONFIG_HIGHBITDEPTH
      23             : #include "aom_ports/mem.h"
      24             : #include "aom_scale/aom_scale.h"
      25             : #include "av1/common/common.h"
      26             : #include "av1/common/resize.h"
      27             : 
      28             : #include "./aom_scale_rtcd.h"
      29             : 
      30             : #define FILTER_BITS 7
      31             : 
      32             : #define INTERP_TAPS 8
      33             : #define SUBPEL_BITS_RS 5
      34             : #define SUBPEL_MASK_RS ((1 << SUBPEL_BITS_RS) - 1)
      35             : #define INTERP_PRECISION_BITS 32
      36             : 
      37             : typedef int16_t interp_kernel[INTERP_TAPS];
      38             : 
      39             : // Filters for interpolation (0.5-band) - note this also filters integer pels.
      40             : static const interp_kernel filteredinterp_filters500[(1 << SUBPEL_BITS_RS)] = {
      41             :   { -3, 0, 35, 64, 35, 0, -3, 0 },    { -3, -1, 34, 64, 36, 1, -3, 0 },
      42             :   { -3, -1, 32, 64, 38, 1, -3, 0 },   { -2, -2, 31, 63, 39, 2, -3, 0 },
      43             :   { -2, -2, 29, 63, 41, 2, -3, 0 },   { -2, -2, 28, 63, 42, 3, -4, 0 },
      44             :   { -2, -3, 27, 63, 43, 4, -4, 0 },   { -2, -3, 25, 62, 45, 5, -4, 0 },
      45             :   { -2, -3, 24, 62, 46, 5, -4, 0 },   { -2, -3, 23, 61, 47, 6, -4, 0 },
      46             :   { -2, -3, 21, 60, 49, 7, -4, 0 },   { -1, -4, 20, 60, 50, 8, -4, -1 },
      47             :   { -1, -4, 19, 59, 51, 9, -4, -1 },  { -1, -4, 17, 58, 52, 10, -4, 0 },
      48             :   { -1, -4, 16, 57, 53, 12, -4, -1 }, { -1, -4, 15, 56, 54, 13, -4, -1 },
      49             :   { -1, -4, 14, 55, 55, 14, -4, -1 }, { -1, -4, 13, 54, 56, 15, -4, -1 },
      50             :   { -1, -4, 12, 53, 57, 16, -4, -1 }, { 0, -4, 10, 52, 58, 17, -4, -1 },
      51             :   { -1, -4, 9, 51, 59, 19, -4, -1 },  { -1, -4, 8, 50, 60, 20, -4, -1 },
      52             :   { 0, -4, 7, 49, 60, 21, -3, -2 },   { 0, -4, 6, 47, 61, 23, -3, -2 },
      53             :   { 0, -4, 5, 46, 62, 24, -3, -2 },   { 0, -4, 5, 45, 62, 25, -3, -2 },
      54             :   { 0, -4, 4, 43, 63, 27, -3, -2 },   { 0, -4, 3, 42, 63, 28, -2, -2 },
      55             :   { 0, -3, 2, 41, 63, 29, -2, -2 },   { 0, -3, 2, 39, 63, 31, -2, -2 },
      56             :   { 0, -3, 1, 38, 64, 32, -1, -3 },   { 0, -3, 1, 36, 64, 34, -1, -3 }
      57             : };
      58             : 
      59             : // Filters for interpolation (0.625-band) - note this also filters integer pels.
      60             : static const interp_kernel filteredinterp_filters625[(1 << SUBPEL_BITS_RS)] = {
      61             :   { -1, -8, 33, 80, 33, -8, -1, 0 }, { -1, -8, 30, 80, 35, -8, -1, 1 },
      62             :   { -1, -8, 28, 80, 37, -7, -2, 1 }, { 0, -8, 26, 79, 39, -7, -2, 1 },
      63             :   { 0, -8, 24, 79, 41, -7, -2, 1 },  { 0, -8, 22, 78, 43, -6, -2, 1 },
      64             :   { 0, -8, 20, 78, 45, -5, -3, 1 },  { 0, -8, 18, 77, 48, -5, -3, 1 },
      65             :   { 0, -8, 16, 76, 50, -4, -3, 1 },  { 0, -8, 15, 75, 52, -3, -4, 1 },
      66             :   { 0, -7, 13, 74, 54, -3, -4, 1 },  { 0, -7, 11, 73, 56, -2, -4, 1 },
      67             :   { 0, -7, 10, 71, 58, -1, -4, 1 },  { 1, -7, 8, 70, 60, 0, -5, 1 },
      68             :   { 1, -6, 6, 68, 62, 1, -5, 1 },    { 1, -6, 5, 67, 63, 2, -5, 1 },
      69             :   { 1, -6, 4, 65, 65, 4, -6, 1 },    { 1, -5, 2, 63, 67, 5, -6, 1 },
      70             :   { 1, -5, 1, 62, 68, 6, -6, 1 },    { 1, -5, 0, 60, 70, 8, -7, 1 },
      71             :   { 1, -4, -1, 58, 71, 10, -7, 0 },  { 1, -4, -2, 56, 73, 11, -7, 0 },
      72             :   { 1, -4, -3, 54, 74, 13, -7, 0 },  { 1, -4, -3, 52, 75, 15, -8, 0 },
      73             :   { 1, -3, -4, 50, 76, 16, -8, 0 },  { 1, -3, -5, 48, 77, 18, -8, 0 },
      74             :   { 1, -3, -5, 45, 78, 20, -8, 0 },  { 1, -2, -6, 43, 78, 22, -8, 0 },
      75             :   { 1, -2, -7, 41, 79, 24, -8, 0 },  { 1, -2, -7, 39, 79, 26, -8, 0 },
      76             :   { 1, -2, -7, 37, 80, 28, -8, -1 }, { 1, -1, -8, 35, 80, 30, -8, -1 },
      77             : };
      78             : 
      79             : // Filters for interpolation (0.75-band) - note this also filters integer pels.
      80             : static const interp_kernel filteredinterp_filters750[(1 << SUBPEL_BITS_RS)] = {
      81             :   { 2, -11, 25, 96, 25, -11, 2, 0 }, { 2, -11, 22, 96, 28, -11, 2, 0 },
      82             :   { 2, -10, 19, 95, 31, -11, 2, 0 }, { 2, -10, 17, 95, 34, -12, 2, 0 },
      83             :   { 2, -9, 14, 94, 37, -12, 2, 0 },  { 2, -8, 12, 93, 40, -12, 1, 0 },
      84             :   { 2, -8, 9, 92, 43, -12, 1, 1 },   { 2, -7, 7, 91, 46, -12, 1, 0 },
      85             :   { 2, -7, 5, 90, 49, -12, 1, 0 },   { 2, -6, 3, 88, 52, -12, 0, 1 },
      86             :   { 2, -5, 1, 86, 55, -12, 0, 1 },   { 2, -5, -1, 84, 58, -11, 0, 1 },
      87             :   { 2, -4, -2, 82, 61, -11, -1, 1 }, { 2, -4, -4, 80, 64, -10, -1, 1 },
      88             :   { 1, -3, -5, 77, 67, -9, -1, 1 },  { 1, -3, -6, 75, 70, -8, -2, 1 },
      89             :   { 1, -2, -7, 72, 72, -7, -2, 1 },  { 1, -2, -8, 70, 75, -6, -3, 1 },
      90             :   { 1, -1, -9, 67, 77, -5, -3, 1 },  { 1, -1, -10, 64, 80, -4, -4, 2 },
      91             :   { 1, -1, -11, 61, 82, -2, -4, 2 }, { 1, 0, -11, 58, 84, -1, -5, 2 },
      92             :   { 1, 0, -12, 55, 86, 1, -5, 2 },   { 1, 0, -12, 52, 88, 3, -6, 2 },
      93             :   { 0, 1, -12, 49, 90, 5, -7, 2 },   { 0, 1, -12, 46, 91, 7, -7, 2 },
      94             :   { 1, 1, -12, 43, 92, 9, -8, 2 },   { 0, 1, -12, 40, 93, 12, -8, 2 },
      95             :   { 0, 2, -12, 37, 94, 14, -9, 2 },  { 0, 2, -12, 34, 95, 17, -10, 2 },
      96             :   { 0, 2, -11, 31, 95, 19, -10, 2 }, { 0, 2, -11, 28, 96, 22, -11, 2 }
      97             : };
      98             : 
      99             : // Filters for interpolation (0.875-band) - note this also filters integer pels.
     100             : static const interp_kernel filteredinterp_filters875[(1 << SUBPEL_BITS_RS)] = {
     101             :   { 3, -8, 13, 112, 13, -8, 3, 0 },   { 3, -7, 10, 112, 17, -9, 3, -1 },
     102             :   { 2, -6, 7, 111, 21, -9, 3, -1 },   { 2, -5, 4, 111, 24, -10, 3, -1 },
     103             :   { 2, -4, 1, 110, 28, -11, 3, -1 },  { 1, -3, -1, 108, 32, -12, 4, -1 },
     104             :   { 1, -2, -3, 106, 36, -13, 4, -1 }, { 1, -1, -6, 105, 40, -14, 4, -1 },
     105             :   { 1, -1, -7, 102, 44, -14, 4, -1 }, { 1, 0, -9, 100, 48, -15, 4, -1 },
     106             :   { 1, 1, -11, 97, 53, -16, 4, -1 },  { 0, 1, -12, 95, 57, -16, 4, -1 },
     107             :   { 0, 2, -13, 91, 61, -16, 4, -1 },  { 0, 2, -14, 88, 65, -16, 4, -1 },
     108             :   { 0, 3, -15, 84, 69, -17, 4, 0 },   { 0, 3, -16, 81, 73, -16, 3, 0 },
     109             :   { 0, 3, -16, 77, 77, -16, 3, 0 },   { 0, 3, -16, 73, 81, -16, 3, 0 },
     110             :   { 0, 4, -17, 69, 84, -15, 3, 0 },   { -1, 4, -16, 65, 88, -14, 2, 0 },
     111             :   { -1, 4, -16, 61, 91, -13, 2, 0 },  { -1, 4, -16, 57, 95, -12, 1, 0 },
     112             :   { -1, 4, -16, 53, 97, -11, 1, 1 },  { -1, 4, -15, 48, 100, -9, 0, 1 },
     113             :   { -1, 4, -14, 44, 102, -7, -1, 1 }, { -1, 4, -14, 40, 105, -6, -1, 1 },
     114             :   { -1, 4, -13, 36, 106, -3, -2, 1 }, { -1, 4, -12, 32, 108, -1, -3, 1 },
     115             :   { -1, 3, -11, 28, 110, 1, -4, 2 },  { -1, 3, -10, 24, 111, 4, -5, 2 },
     116             :   { -1, 3, -9, 21, 111, 7, -6, 2 },   { -1, 3, -9, 17, 112, 10, -7, 3 }
     117             : };
     118             : 
     119             : // Filters for interpolation (full-band) - no filtering for integer pixels
     120             : static const interp_kernel filteredinterp_filters1000[(1 << SUBPEL_BITS_RS)] = {
     121             :   { 0, 0, 0, 128, 0, 0, 0, 0 },        { 0, 1, -3, 128, 3, -1, 0, 0 },
     122             :   { -1, 2, -6, 127, 7, -2, 1, 0 },     { -1, 3, -9, 126, 12, -4, 1, 0 },
     123             :   { -1, 4, -12, 125, 16, -5, 1, 0 },   { -1, 4, -14, 123, 20, -6, 2, 0 },
     124             :   { -1, 5, -15, 120, 25, -8, 2, 0 },   { -1, 5, -17, 118, 30, -9, 3, -1 },
     125             :   { -1, 6, -18, 114, 35, -10, 3, -1 }, { -1, 6, -19, 111, 41, -12, 3, -1 },
     126             :   { -1, 6, -20, 107, 46, -13, 4, -1 }, { -1, 6, -21, 103, 52, -14, 4, -1 },
     127             :   { -1, 6, -21, 99, 57, -16, 5, -1 },  { -1, 6, -21, 94, 63, -17, 5, -1 },
     128             :   { -1, 6, -20, 89, 68, -18, 5, -1 },  { -1, 6, -20, 84, 73, -19, 6, -1 },
     129             :   { -1, 6, -20, 79, 79, -20, 6, -1 },  { -1, 6, -19, 73, 84, -20, 6, -1 },
     130             :   { -1, 5, -18, 68, 89, -20, 6, -1 },  { -1, 5, -17, 63, 94, -21, 6, -1 },
     131             :   { -1, 5, -16, 57, 99, -21, 6, -1 },  { -1, 4, -14, 52, 103, -21, 6, -1 },
     132             :   { -1, 4, -13, 46, 107, -20, 6, -1 }, { -1, 3, -12, 41, 111, -19, 6, -1 },
     133             :   { -1, 3, -10, 35, 114, -18, 6, -1 }, { -1, 3, -9, 30, 118, -17, 5, -1 },
     134             :   { 0, 2, -8, 25, 120, -15, 5, -1 },   { 0, 2, -6, 20, 123, -14, 4, -1 },
     135             :   { 0, 1, -5, 16, 125, -12, 4, -1 },   { 0, 1, -4, 12, 126, -9, 3, -1 },
     136             :   { 0, 1, -2, 7, 127, -6, 2, -1 },     { 0, 0, -1, 3, 128, -3, 1, 0 }
     137             : };
     138             : 
     139             : // Filters for factor of 2 downsampling.
     140             : static const int16_t av1_down2_symeven_half_filter[] = { 56, 12, -3, -1 };
     141             : static const int16_t av1_down2_symodd_half_filter[] = { 64, 35, 0, -3 };
     142             : 
     143           0 : static const interp_kernel *choose_interp_filter(int inlength, int outlength) {
     144           0 :   int outlength16 = outlength * 16;
     145           0 :   if (outlength16 >= inlength * 16)
     146           0 :     return filteredinterp_filters1000;
     147           0 :   else if (outlength16 >= inlength * 13)
     148           0 :     return filteredinterp_filters875;
     149           0 :   else if (outlength16 >= inlength * 11)
     150           0 :     return filteredinterp_filters750;
     151           0 :   else if (outlength16 >= inlength * 9)
     152           0 :     return filteredinterp_filters625;
     153             :   else
     154           0 :     return filteredinterp_filters500;
     155             : }
     156             : 
     157           0 : static void interpolate(const uint8_t *const input, int inlength,
     158             :                         uint8_t *output, int outlength) {
     159           0 :   const int64_t delta =
     160           0 :       (((uint64_t)inlength << 32) + outlength / 2) / outlength;
     161           0 :   const int64_t offset =
     162             :       inlength > outlength
     163           0 :           ? (((int64_t)(inlength - outlength) << 31) + outlength / 2) /
     164             :                 outlength
     165           0 :           : -(((int64_t)(outlength - inlength) << 31) + outlength / 2) /
     166             :                 outlength;
     167           0 :   uint8_t *optr = output;
     168             :   int x, x1, x2, sum, k, int_pel, sub_pel;
     169             :   int64_t y;
     170             : 
     171           0 :   const interp_kernel *interp_filters =
     172             :       choose_interp_filter(inlength, outlength);
     173             : 
     174           0 :   x = 0;
     175           0 :   y = offset;
     176           0 :   while ((y >> INTERP_PRECISION_BITS) < (INTERP_TAPS / 2 - 1)) {
     177           0 :     x++;
     178           0 :     y += delta;
     179             :   }
     180           0 :   x1 = x;
     181           0 :   x = outlength - 1;
     182           0 :   y = delta * x + offset;
     183           0 :   while ((y >> INTERP_PRECISION_BITS) + (int64_t)(INTERP_TAPS / 2) >=
     184             :          inlength) {
     185           0 :     x--;
     186           0 :     y -= delta;
     187             :   }
     188           0 :   x2 = x;
     189           0 :   if (x1 > x2) {
     190           0 :     for (x = 0, y = offset; x < outlength; ++x, y += delta) {
     191             :       const int16_t *filter;
     192           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     193           0 :       sub_pel =
     194           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     195           0 :       filter = interp_filters[sub_pel];
     196           0 :       sum = 0;
     197           0 :       for (k = 0; k < INTERP_TAPS; ++k) {
     198           0 :         const int pk = int_pel - INTERP_TAPS / 2 + 1 + k;
     199           0 :         sum += filter[k] * input[AOMMAX(AOMMIN(pk, inlength - 1), 0)];
     200             :       }
     201           0 :       *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
     202             :     }
     203             :   } else {
     204             :     // Initial part.
     205           0 :     for (x = 0, y = offset; x < x1; ++x, y += delta) {
     206             :       const int16_t *filter;
     207           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     208           0 :       sub_pel =
     209           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     210           0 :       filter = interp_filters[sub_pel];
     211           0 :       sum = 0;
     212           0 :       for (k = 0; k < INTERP_TAPS; ++k)
     213           0 :         sum += filter[k] * input[AOMMAX(int_pel - INTERP_TAPS / 2 + 1 + k, 0)];
     214           0 :       *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
     215             :     }
     216             :     // Middle part.
     217           0 :     for (; x <= x2; ++x, y += delta) {
     218             :       const int16_t *filter;
     219           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     220           0 :       sub_pel =
     221           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     222           0 :       filter = interp_filters[sub_pel];
     223           0 :       sum = 0;
     224           0 :       for (k = 0; k < INTERP_TAPS; ++k)
     225           0 :         sum += filter[k] * input[int_pel - INTERP_TAPS / 2 + 1 + k];
     226           0 :       *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
     227             :     }
     228             :     // End part.
     229           0 :     for (; x < outlength; ++x, y += delta) {
     230             :       const int16_t *filter;
     231           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     232           0 :       sub_pel =
     233           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     234           0 :       filter = interp_filters[sub_pel];
     235           0 :       sum = 0;
     236           0 :       for (k = 0; k < INTERP_TAPS; ++k)
     237           0 :         sum += filter[k] *
     238           0 :                input[AOMMIN(int_pel - INTERP_TAPS / 2 + 1 + k, inlength - 1)];
     239           0 :       *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
     240             :     }
     241             :   }
     242           0 : }
     243             : 
     244             : #ifndef __clang_analyzer__
     245           0 : static void down2_symeven(const uint8_t *const input, int length,
     246             :                           uint8_t *output) {
     247             :   // Actual filter len = 2 * filter_len_half.
     248           0 :   const int16_t *filter = av1_down2_symeven_half_filter;
     249           0 :   const int filter_len_half = sizeof(av1_down2_symeven_half_filter) / 2;
     250             :   int i, j;
     251           0 :   uint8_t *optr = output;
     252           0 :   int l1 = filter_len_half;
     253           0 :   int l2 = (length - filter_len_half);
     254           0 :   l1 += (l1 & 1);
     255           0 :   l2 += (l2 & 1);
     256           0 :   if (l1 > l2) {
     257             :     // Short input length.
     258           0 :     for (i = 0; i < length; i += 2) {
     259           0 :       int sum = (1 << (FILTER_BITS - 1));
     260           0 :       for (j = 0; j < filter_len_half; ++j) {
     261           0 :         sum +=
     262           0 :             (input[AOMMAX(i - j, 0)] + input[AOMMIN(i + 1 + j, length - 1)]) *
     263           0 :             filter[j];
     264             :       }
     265           0 :       sum >>= FILTER_BITS;
     266           0 :       *optr++ = clip_pixel(sum);
     267             :     }
     268             :   } else {
     269             :     // Initial part.
     270           0 :     for (i = 0; i < l1; i += 2) {
     271           0 :       int sum = (1 << (FILTER_BITS - 1));
     272           0 :       for (j = 0; j < filter_len_half; ++j) {
     273           0 :         sum += (input[AOMMAX(i - j, 0)] + input[i + 1 + j]) * filter[j];
     274             :       }
     275           0 :       sum >>= FILTER_BITS;
     276           0 :       *optr++ = clip_pixel(sum);
     277             :     }
     278             :     // Middle part.
     279           0 :     for (; i < l2; i += 2) {
     280           0 :       int sum = (1 << (FILTER_BITS - 1));
     281           0 :       for (j = 0; j < filter_len_half; ++j) {
     282           0 :         sum += (input[i - j] + input[i + 1 + j]) * filter[j];
     283             :       }
     284           0 :       sum >>= FILTER_BITS;
     285           0 :       *optr++ = clip_pixel(sum);
     286             :     }
     287             :     // End part.
     288           0 :     for (; i < length; i += 2) {
     289           0 :       int sum = (1 << (FILTER_BITS - 1));
     290           0 :       for (j = 0; j < filter_len_half; ++j) {
     291           0 :         sum +=
     292           0 :             (input[i - j] + input[AOMMIN(i + 1 + j, length - 1)]) * filter[j];
     293             :       }
     294           0 :       sum >>= FILTER_BITS;
     295           0 :       *optr++ = clip_pixel(sum);
     296             :     }
     297             :   }
     298           0 : }
     299             : #endif
     300             : 
     301           0 : static void down2_symodd(const uint8_t *const input, int length,
     302             :                          uint8_t *output) {
     303             :   // Actual filter len = 2 * filter_len_half - 1.
     304           0 :   const int16_t *filter = av1_down2_symodd_half_filter;
     305           0 :   const int filter_len_half = sizeof(av1_down2_symodd_half_filter) / 2;
     306             :   int i, j;
     307           0 :   uint8_t *optr = output;
     308           0 :   int l1 = filter_len_half - 1;
     309           0 :   int l2 = (length - filter_len_half + 1);
     310           0 :   l1 += (l1 & 1);
     311           0 :   l2 += (l2 & 1);
     312           0 :   if (l1 > l2) {
     313             :     // Short input length.
     314           0 :     for (i = 0; i < length; i += 2) {
     315           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     316           0 :       for (j = 1; j < filter_len_half; ++j) {
     317           0 :         sum += (input[(i - j < 0 ? 0 : i - j)] +
     318           0 :                 input[(i + j >= length ? length - 1 : i + j)]) *
     319           0 :                filter[j];
     320             :       }
     321           0 :       sum >>= FILTER_BITS;
     322           0 :       *optr++ = clip_pixel(sum);
     323             :     }
     324             :   } else {
     325             :     // Initial part.
     326           0 :     for (i = 0; i < l1; i += 2) {
     327           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     328           0 :       for (j = 1; j < filter_len_half; ++j) {
     329           0 :         sum += (input[(i - j < 0 ? 0 : i - j)] + input[i + j]) * filter[j];
     330             :       }
     331           0 :       sum >>= FILTER_BITS;
     332           0 :       *optr++ = clip_pixel(sum);
     333             :     }
     334             :     // Middle part.
     335           0 :     for (; i < l2; i += 2) {
     336           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     337           0 :       for (j = 1; j < filter_len_half; ++j) {
     338           0 :         sum += (input[i - j] + input[i + j]) * filter[j];
     339             :       }
     340           0 :       sum >>= FILTER_BITS;
     341           0 :       *optr++ = clip_pixel(sum);
     342             :     }
     343             :     // End part.
     344           0 :     for (; i < length; i += 2) {
     345           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     346           0 :       for (j = 1; j < filter_len_half; ++j) {
     347           0 :         sum += (input[i - j] + input[(i + j >= length ? length - 1 : i + j)]) *
     348           0 :                filter[j];
     349             :       }
     350           0 :       sum >>= FILTER_BITS;
     351           0 :       *optr++ = clip_pixel(sum);
     352             :     }
     353             :   }
     354           0 : }
     355             : 
     356           0 : static int get_down2_length(int length, int steps) {
     357             :   int s;
     358           0 :   for (s = 0; s < steps; ++s) length = (length + 1) >> 1;
     359           0 :   return length;
     360             : }
     361             : 
     362           0 : static int get_down2_steps(int in_length, int out_length) {
     363           0 :   int steps = 0;
     364             :   int proj_in_length;
     365           0 :   while ((proj_in_length = get_down2_length(in_length, 1)) >= out_length) {
     366           0 :     ++steps;
     367           0 :     in_length = proj_in_length;
     368             :   }
     369           0 :   return steps;
     370             : }
     371             : 
     372           0 : static void resize_multistep(const uint8_t *const input, int length,
     373             :                              uint8_t *output, int olength, uint8_t *otmp) {
     374           0 :   if (length == olength) {
     375           0 :     memcpy(output, input, sizeof(output[0]) * length);
     376           0 :     return;
     377             :   }
     378           0 :   const int steps = get_down2_steps(length, olength);
     379             : 
     380           0 :   if (steps > 0) {
     381           0 :     uint8_t *out = NULL;
     382           0 :     int filteredlength = length;
     383             : 
     384           0 :     assert(otmp != NULL);
     385           0 :     uint8_t *otmp2 = otmp + get_down2_length(length, 1);
     386           0 :     for (int s = 0; s < steps; ++s) {
     387           0 :       const int proj_filteredlength = get_down2_length(filteredlength, 1);
     388           0 :       const uint8_t *const in = (s == 0 ? input : out);
     389           0 :       if (s == steps - 1 && proj_filteredlength == olength)
     390           0 :         out = output;
     391             :       else
     392           0 :         out = (s & 1 ? otmp2 : otmp);
     393           0 :       if (filteredlength & 1)
     394           0 :         down2_symodd(in, filteredlength, out);
     395             :       else
     396           0 :         down2_symeven(in, filteredlength, out);
     397           0 :       filteredlength = proj_filteredlength;
     398             :     }
     399           0 :     if (filteredlength != olength) {
     400           0 :       interpolate(out, filteredlength, output, olength);
     401             :     }
     402             :   } else {
     403           0 :     interpolate(input, length, output, olength);
     404             :   }
     405             : }
     406             : 
     407           0 : static void fill_col_to_arr(uint8_t *img, int stride, int len, uint8_t *arr) {
     408             :   int i;
     409           0 :   uint8_t *iptr = img;
     410           0 :   uint8_t *aptr = arr;
     411           0 :   for (i = 0; i < len; ++i, iptr += stride) {
     412           0 :     *aptr++ = *iptr;
     413             :   }
     414           0 : }
     415             : 
     416           0 : static void fill_arr_to_col(uint8_t *img, int stride, int len, uint8_t *arr) {
     417             :   int i;
     418           0 :   uint8_t *iptr = img;
     419           0 :   uint8_t *aptr = arr;
     420           0 :   for (i = 0; i < len; ++i, iptr += stride) {
     421           0 :     *iptr = *aptr++;
     422             :   }
     423           0 : }
     424             : 
     425           0 : void av1_resize_plane(const uint8_t *const input, int height, int width,
     426             :                       int in_stride, uint8_t *output, int height2, int width2,
     427             :                       int out_stride) {
     428             :   int i;
     429           0 :   uint8_t *intbuf = (uint8_t *)malloc(sizeof(uint8_t) * width2 * height);
     430           0 :   uint8_t *tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) * AOMMAX(width, height));
     431           0 :   uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * height);
     432           0 :   uint8_t *arrbuf2 = (uint8_t *)malloc(sizeof(uint8_t) * height2);
     433           0 :   if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL || arrbuf2 == NULL)
     434             :     goto Error;
     435           0 :   assert(width > 0);
     436           0 :   assert(height > 0);
     437           0 :   assert(width2 > 0);
     438           0 :   assert(height2 > 0);
     439           0 :   for (i = 0; i < height; ++i)
     440           0 :     resize_multistep(input + in_stride * i, width, intbuf + width2 * i, width2,
     441             :                      tmpbuf);
     442           0 :   for (i = 0; i < width2; ++i) {
     443           0 :     fill_col_to_arr(intbuf + i, width2, height, arrbuf);
     444           0 :     resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf);
     445           0 :     fill_arr_to_col(output + i, out_stride, height2, arrbuf2);
     446             :   }
     447             : 
     448             : Error:
     449           0 :   free(intbuf);
     450           0 :   free(tmpbuf);
     451           0 :   free(arrbuf);
     452           0 :   free(arrbuf2);
     453           0 : }
     454             : 
     455             : #if CONFIG_HIGHBITDEPTH
     456           0 : static void highbd_interpolate(const uint16_t *const input, int inlength,
     457             :                                uint16_t *output, int outlength, int bd) {
     458           0 :   const int64_t delta =
     459           0 :       (((uint64_t)inlength << 32) + outlength / 2) / outlength;
     460           0 :   const int64_t offset =
     461             :       inlength > outlength
     462           0 :           ? (((int64_t)(inlength - outlength) << 31) + outlength / 2) /
     463             :                 outlength
     464           0 :           : -(((int64_t)(outlength - inlength) << 31) + outlength / 2) /
     465             :                 outlength;
     466           0 :   uint16_t *optr = output;
     467             :   int x, x1, x2, sum, k, int_pel, sub_pel;
     468             :   int64_t y;
     469             : 
     470           0 :   const interp_kernel *interp_filters =
     471             :       choose_interp_filter(inlength, outlength);
     472             : 
     473           0 :   x = 0;
     474           0 :   y = offset;
     475           0 :   while ((y >> INTERP_PRECISION_BITS) < (INTERP_TAPS / 2 - 1)) {
     476           0 :     x++;
     477           0 :     y += delta;
     478             :   }
     479           0 :   x1 = x;
     480           0 :   x = outlength - 1;
     481           0 :   y = delta * x + offset;
     482           0 :   while ((y >> INTERP_PRECISION_BITS) + (int64_t)(INTERP_TAPS / 2) >=
     483             :          inlength) {
     484           0 :     x--;
     485           0 :     y -= delta;
     486             :   }
     487           0 :   x2 = x;
     488           0 :   if (x1 > x2) {
     489           0 :     for (x = 0, y = offset; x < outlength; ++x, y += delta) {
     490             :       const int16_t *filter;
     491           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     492           0 :       sub_pel =
     493           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     494           0 :       filter = interp_filters[sub_pel];
     495           0 :       sum = 0;
     496           0 :       for (k = 0; k < INTERP_TAPS; ++k) {
     497           0 :         const int pk = int_pel - INTERP_TAPS / 2 + 1 + k;
     498           0 :         sum += filter[k] * input[AOMMAX(AOMMIN(pk, inlength - 1), 0)];
     499             :       }
     500           0 :       *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
     501             :     }
     502             :   } else {
     503             :     // Initial part.
     504           0 :     for (x = 0, y = offset; x < x1; ++x, y += delta) {
     505             :       const int16_t *filter;
     506           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     507           0 :       sub_pel =
     508           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     509           0 :       filter = interp_filters[sub_pel];
     510           0 :       sum = 0;
     511           0 :       for (k = 0; k < INTERP_TAPS; ++k)
     512           0 :         sum += filter[k] * input[AOMMAX(int_pel - INTERP_TAPS / 2 + 1 + k, 0)];
     513           0 :       *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
     514             :     }
     515             :     // Middle part.
     516           0 :     for (; x <= x2; ++x, y += delta) {
     517             :       const int16_t *filter;
     518           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     519           0 :       sub_pel =
     520           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     521           0 :       filter = interp_filters[sub_pel];
     522           0 :       sum = 0;
     523           0 :       for (k = 0; k < INTERP_TAPS; ++k)
     524           0 :         sum += filter[k] * input[int_pel - INTERP_TAPS / 2 + 1 + k];
     525           0 :       *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
     526             :     }
     527             :     // End part.
     528           0 :     for (; x < outlength; ++x, y += delta) {
     529             :       const int16_t *filter;
     530           0 :       int_pel = y >> INTERP_PRECISION_BITS;
     531           0 :       sub_pel =
     532           0 :           (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS_RS)) & SUBPEL_MASK_RS;
     533           0 :       filter = interp_filters[sub_pel];
     534           0 :       sum = 0;
     535           0 :       for (k = 0; k < INTERP_TAPS; ++k)
     536           0 :         sum += filter[k] *
     537           0 :                input[AOMMIN(int_pel - INTERP_TAPS / 2 + 1 + k, inlength - 1)];
     538           0 :       *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
     539             :     }
     540             :   }
     541           0 : }
     542             : #ifndef __clang_analyzer__
     543           0 : static void highbd_down2_symeven(const uint16_t *const input, int length,
     544             :                                  uint16_t *output, int bd) {
     545             :   // Actual filter len = 2 * filter_len_half.
     546             :   static const int16_t *filter = av1_down2_symeven_half_filter;
     547           0 :   const int filter_len_half = sizeof(av1_down2_symeven_half_filter) / 2;
     548             :   int i, j;
     549           0 :   uint16_t *optr = output;
     550           0 :   int l1 = filter_len_half;
     551           0 :   int l2 = (length - filter_len_half);
     552           0 :   l1 += (l1 & 1);
     553           0 :   l2 += (l2 & 1);
     554           0 :   if (l1 > l2) {
     555             :     // Short input length.
     556           0 :     for (i = 0; i < length; i += 2) {
     557           0 :       int sum = (1 << (FILTER_BITS - 1));
     558           0 :       for (j = 0; j < filter_len_half; ++j) {
     559           0 :         sum +=
     560           0 :             (input[AOMMAX(0, i - j)] + input[AOMMIN(i + 1 + j, length - 1)]) *
     561           0 :             filter[j];
     562             :       }
     563           0 :       sum >>= FILTER_BITS;
     564           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     565             :     }
     566             :   } else {
     567             :     // Initial part.
     568           0 :     for (i = 0; i < l1; i += 2) {
     569           0 :       int sum = (1 << (FILTER_BITS - 1));
     570           0 :       for (j = 0; j < filter_len_half; ++j) {
     571           0 :         sum += (input[AOMMAX(0, i - j)] + input[i + 1 + j]) * filter[j];
     572             :       }
     573           0 :       sum >>= FILTER_BITS;
     574           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     575             :     }
     576             :     // Middle part.
     577           0 :     for (; i < l2; i += 2) {
     578           0 :       int sum = (1 << (FILTER_BITS - 1));
     579           0 :       for (j = 0; j < filter_len_half; ++j) {
     580           0 :         sum += (input[i - j] + input[i + 1 + j]) * filter[j];
     581             :       }
     582           0 :       sum >>= FILTER_BITS;
     583           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     584             :     }
     585             :     // End part.
     586           0 :     for (; i < length; i += 2) {
     587           0 :       int sum = (1 << (FILTER_BITS - 1));
     588           0 :       for (j = 0; j < filter_len_half; ++j) {
     589           0 :         sum +=
     590           0 :             (input[i - j] + input[AOMMIN(i + 1 + j, length - 1)]) * filter[j];
     591             :       }
     592           0 :       sum >>= FILTER_BITS;
     593           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     594             :     }
     595             :   }
     596           0 : }
     597             : 
     598           0 : static void highbd_down2_symodd(const uint16_t *const input, int length,
     599             :                                 uint16_t *output, int bd) {
     600             :   // Actual filter len = 2 * filter_len_half - 1.
     601             :   static const int16_t *filter = av1_down2_symodd_half_filter;
     602           0 :   const int filter_len_half = sizeof(av1_down2_symodd_half_filter) / 2;
     603             :   int i, j;
     604           0 :   uint16_t *optr = output;
     605           0 :   int l1 = filter_len_half - 1;
     606           0 :   int l2 = (length - filter_len_half + 1);
     607           0 :   l1 += (l1 & 1);
     608           0 :   l2 += (l2 & 1);
     609           0 :   if (l1 > l2) {
     610             :     // Short input length.
     611           0 :     for (i = 0; i < length; i += 2) {
     612           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     613           0 :       for (j = 1; j < filter_len_half; ++j) {
     614           0 :         sum += (input[AOMMAX(i - j, 0)] + input[AOMMIN(i + j, length - 1)]) *
     615           0 :                filter[j];
     616             :       }
     617           0 :       sum >>= FILTER_BITS;
     618           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     619             :     }
     620             :   } else {
     621             :     // Initial part.
     622           0 :     for (i = 0; i < l1; i += 2) {
     623           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     624           0 :       for (j = 1; j < filter_len_half; ++j) {
     625           0 :         sum += (input[AOMMAX(i - j, 0)] + input[i + j]) * filter[j];
     626             :       }
     627           0 :       sum >>= FILTER_BITS;
     628           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     629             :     }
     630             :     // Middle part.
     631           0 :     for (; i < l2; i += 2) {
     632           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     633           0 :       for (j = 1; j < filter_len_half; ++j) {
     634           0 :         sum += (input[i - j] + input[i + j]) * filter[j];
     635             :       }
     636           0 :       sum >>= FILTER_BITS;
     637           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     638             :     }
     639             :     // End part.
     640           0 :     for (; i < length; i += 2) {
     641           0 :       int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
     642           0 :       for (j = 1; j < filter_len_half; ++j) {
     643           0 :         sum += (input[i - j] + input[AOMMIN(i + j, length - 1)]) * filter[j];
     644             :       }
     645           0 :       sum >>= FILTER_BITS;
     646           0 :       *optr++ = clip_pixel_highbd(sum, bd);
     647             :     }
     648             :   }
     649           0 : }
     650             : #endif
     651             : 
     652           0 : static void highbd_resize_multistep(const uint16_t *const input, int length,
     653             :                                     uint16_t *output, int olength,
     654             :                                     uint16_t *otmp, int bd) {
     655           0 :   if (length == olength) {
     656           0 :     memcpy(output, input, sizeof(output[0]) * length);
     657           0 :     return;
     658             :   }
     659           0 :   const int steps = get_down2_steps(length, olength);
     660             : 
     661           0 :   if (steps > 0) {
     662           0 :     uint16_t *out = NULL;
     663           0 :     int filteredlength = length;
     664             : 
     665           0 :     assert(otmp != NULL);
     666           0 :     uint16_t *otmp2 = otmp + get_down2_length(length, 1);
     667           0 :     for (int s = 0; s < steps; ++s) {
     668           0 :       const int proj_filteredlength = get_down2_length(filteredlength, 1);
     669           0 :       const uint16_t *const in = (s == 0 ? input : out);
     670           0 :       if (s == steps - 1 && proj_filteredlength == olength)
     671           0 :         out = output;
     672             :       else
     673           0 :         out = (s & 1 ? otmp2 : otmp);
     674           0 :       if (filteredlength & 1)
     675           0 :         highbd_down2_symodd(in, filteredlength, out, bd);
     676             :       else
     677           0 :         highbd_down2_symeven(in, filteredlength, out, bd);
     678           0 :       filteredlength = proj_filteredlength;
     679             :     }
     680           0 :     if (filteredlength != olength) {
     681           0 :       highbd_interpolate(out, filteredlength, output, olength, bd);
     682             :     }
     683             :   } else {
     684           0 :     highbd_interpolate(input, length, output, olength, bd);
     685             :   }
     686             : }
     687             : 
     688           0 : static void highbd_fill_col_to_arr(uint16_t *img, int stride, int len,
     689             :                                    uint16_t *arr) {
     690             :   int i;
     691           0 :   uint16_t *iptr = img;
     692           0 :   uint16_t *aptr = arr;
     693           0 :   for (i = 0; i < len; ++i, iptr += stride) {
     694           0 :     *aptr++ = *iptr;
     695             :   }
     696           0 : }
     697             : 
     698           0 : static void highbd_fill_arr_to_col(uint16_t *img, int stride, int len,
     699             :                                    uint16_t *arr) {
     700             :   int i;
     701           0 :   uint16_t *iptr = img;
     702           0 :   uint16_t *aptr = arr;
     703           0 :   for (i = 0; i < len; ++i, iptr += stride) {
     704           0 :     *iptr = *aptr++;
     705             :   }
     706           0 : }
     707             : 
     708           0 : void av1_highbd_resize_plane(const uint8_t *const input, int height, int width,
     709             :                              int in_stride, uint8_t *output, int height2,
     710             :                              int width2, int out_stride, int bd) {
     711             :   int i;
     712           0 :   uint16_t *intbuf = (uint16_t *)malloc(sizeof(uint16_t) * width2 * height);
     713           0 :   uint16_t *tmpbuf =
     714           0 :       (uint16_t *)malloc(sizeof(uint16_t) * AOMMAX(width, height));
     715           0 :   uint16_t *arrbuf = (uint16_t *)malloc(sizeof(uint16_t) * height);
     716           0 :   uint16_t *arrbuf2 = (uint16_t *)malloc(sizeof(uint16_t) * height2);
     717           0 :   if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL || arrbuf2 == NULL)
     718             :     goto Error;
     719           0 :   for (i = 0; i < height; ++i) {
     720           0 :     highbd_resize_multistep(CONVERT_TO_SHORTPTR(input + in_stride * i), width,
     721           0 :                             intbuf + width2 * i, width2, tmpbuf, bd);
     722             :   }
     723           0 :   for (i = 0; i < width2; ++i) {
     724           0 :     highbd_fill_col_to_arr(intbuf + i, width2, height, arrbuf);
     725           0 :     highbd_resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf, bd);
     726           0 :     highbd_fill_arr_to_col(CONVERT_TO_SHORTPTR(output + i), out_stride, height2,
     727             :                            arrbuf2);
     728             :   }
     729             : 
     730             : Error:
     731           0 :   free(intbuf);
     732           0 :   free(tmpbuf);
     733           0 :   free(arrbuf);
     734           0 :   free(arrbuf2);
     735           0 : }
     736             : #endif  // CONFIG_HIGHBITDEPTH
     737             : 
     738           0 : void av1_resize_frame420(const uint8_t *const y, int y_stride,
     739             :                          const uint8_t *const u, const uint8_t *const v,
     740             :                          int uv_stride, int height, int width, uint8_t *oy,
     741             :                          int oy_stride, uint8_t *ou, uint8_t *ov,
     742             :                          int ouv_stride, int oheight, int owidth) {
     743           0 :   av1_resize_plane(y, height, width, y_stride, oy, oheight, owidth, oy_stride);
     744           0 :   av1_resize_plane(u, height / 2, width / 2, uv_stride, ou, oheight / 2,
     745             :                    owidth / 2, ouv_stride);
     746           0 :   av1_resize_plane(v, height / 2, width / 2, uv_stride, ov, oheight / 2,
     747             :                    owidth / 2, ouv_stride);
     748           0 : }
     749             : 
     750           0 : void av1_resize_frame422(const uint8_t *const y, int y_stride,
     751             :                          const uint8_t *const u, const uint8_t *const v,
     752             :                          int uv_stride, int height, int width, uint8_t *oy,
     753             :                          int oy_stride, uint8_t *ou, uint8_t *ov,
     754             :                          int ouv_stride, int oheight, int owidth) {
     755           0 :   av1_resize_plane(y, height, width, y_stride, oy, oheight, owidth, oy_stride);
     756           0 :   av1_resize_plane(u, height, width / 2, uv_stride, ou, oheight, owidth / 2,
     757             :                    ouv_stride);
     758           0 :   av1_resize_plane(v, height, width / 2, uv_stride, ov, oheight, owidth / 2,
     759             :                    ouv_stride);
     760           0 : }
     761             : 
     762           0 : void av1_resize_frame444(const uint8_t *const y, int y_stride,
     763             :                          const uint8_t *const u, const uint8_t *const v,
     764             :                          int uv_stride, int height, int width, uint8_t *oy,
     765             :                          int oy_stride, uint8_t *ou, uint8_t *ov,
     766             :                          int ouv_stride, int oheight, int owidth) {
     767           0 :   av1_resize_plane(y, height, width, y_stride, oy, oheight, owidth, oy_stride);
     768           0 :   av1_resize_plane(u, height, width, uv_stride, ou, oheight, owidth,
     769             :                    ouv_stride);
     770           0 :   av1_resize_plane(v, height, width, uv_stride, ov, oheight, owidth,
     771             :                    ouv_stride);
     772           0 : }
     773             : 
     774             : #if CONFIG_HIGHBITDEPTH
     775           0 : void av1_highbd_resize_frame420(const uint8_t *const y, int y_stride,
     776             :                                 const uint8_t *const u, const uint8_t *const v,
     777             :                                 int uv_stride, int height, int width,
     778             :                                 uint8_t *oy, int oy_stride, uint8_t *ou,
     779             :                                 uint8_t *ov, int ouv_stride, int oheight,
     780             :                                 int owidth, int bd) {
     781           0 :   av1_highbd_resize_plane(y, height, width, y_stride, oy, oheight, owidth,
     782             :                           oy_stride, bd);
     783           0 :   av1_highbd_resize_plane(u, height / 2, width / 2, uv_stride, ou, oheight / 2,
     784             :                           owidth / 2, ouv_stride, bd);
     785           0 :   av1_highbd_resize_plane(v, height / 2, width / 2, uv_stride, ov, oheight / 2,
     786             :                           owidth / 2, ouv_stride, bd);
     787           0 : }
     788             : 
     789           0 : void av1_highbd_resize_frame422(const uint8_t *const y, int y_stride,
     790             :                                 const uint8_t *const u, const uint8_t *const v,
     791             :                                 int uv_stride, int height, int width,
     792             :                                 uint8_t *oy, int oy_stride, uint8_t *ou,
     793             :                                 uint8_t *ov, int ouv_stride, int oheight,
     794             :                                 int owidth, int bd) {
     795           0 :   av1_highbd_resize_plane(y, height, width, y_stride, oy, oheight, owidth,
     796             :                           oy_stride, bd);
     797           0 :   av1_highbd_resize_plane(u, height, width / 2, uv_stride, ou, oheight,
     798             :                           owidth / 2, ouv_stride, bd);
     799           0 :   av1_highbd_resize_plane(v, height, width / 2, uv_stride, ov, oheight,
     800             :                           owidth / 2, ouv_stride, bd);
     801           0 : }
     802             : 
     803           0 : void av1_highbd_resize_frame444(const uint8_t *const y, int y_stride,
     804             :                                 const uint8_t *const u, const uint8_t *const v,
     805             :                                 int uv_stride, int height, int width,
     806             :                                 uint8_t *oy, int oy_stride, uint8_t *ou,
     807             :                                 uint8_t *ov, int ouv_stride, int oheight,
     808             :                                 int owidth, int bd) {
     809           0 :   av1_highbd_resize_plane(y, height, width, y_stride, oy, oheight, owidth,
     810             :                           oy_stride, bd);
     811           0 :   av1_highbd_resize_plane(u, height, width, uv_stride, ou, oheight, owidth,
     812             :                           ouv_stride, bd);
     813           0 :   av1_highbd_resize_plane(v, height, width, uv_stride, ov, oheight, owidth,
     814             :                           ouv_stride, bd);
     815           0 : }
     816             : #endif  // CONFIG_HIGHBITDEPTH
     817             : 
     818             : #if CONFIG_HIGHBITDEPTH
     819           0 : static void resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
     820             :                                     YV12_BUFFER_CONFIG *dst, int bd) {
     821             : #else
     822             : static void resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
     823             :                                     YV12_BUFFER_CONFIG *dst) {
     824             : #endif  // CONFIG_HIGHBITDEPTH
     825             :   // TODO(dkovalev): replace YV12_BUFFER_CONFIG with aom_image_t
     826             :   int i;
     827           0 :   const uint8_t *const srcs[3] = { src->y_buffer, src->u_buffer,
     828           0 :                                    src->v_buffer };
     829           0 :   const int src_strides[3] = { src->y_stride, src->uv_stride, src->uv_stride };
     830           0 :   const int src_widths[3] = { src->y_crop_width, src->uv_crop_width,
     831           0 :                               src->uv_crop_width };
     832           0 :   const int src_heights[3] = { src->y_crop_height, src->uv_crop_height,
     833           0 :                                src->uv_crop_height };
     834           0 :   uint8_t *const dsts[3] = { dst->y_buffer, dst->u_buffer, dst->v_buffer };
     835           0 :   const int dst_strides[3] = { dst->y_stride, dst->uv_stride, dst->uv_stride };
     836           0 :   const int dst_widths[3] = { dst->y_crop_width, dst->uv_crop_width,
     837           0 :                               dst->uv_crop_width };
     838           0 :   const int dst_heights[3] = { dst->y_crop_height, dst->uv_crop_height,
     839           0 :                                dst->uv_crop_height };
     840             : 
     841           0 :   for (i = 0; i < MAX_MB_PLANE; ++i) {
     842             : #if CONFIG_HIGHBITDEPTH
     843           0 :     if (src->flags & YV12_FLAG_HIGHBITDEPTH)
     844           0 :       av1_highbd_resize_plane(srcs[i], src_heights[i], src_widths[i],
     845             :                               src_strides[i], dsts[i], dst_heights[i],
     846             :                               dst_widths[i], dst_strides[i], bd);
     847             :     else
     848             : #endif  // CONFIG_HIGHBITDEPTH
     849           0 :       av1_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i],
     850             :                        dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]);
     851             :   }
     852           0 :   aom_extend_frame_borders(dst);
     853           0 : }
     854             : 
     855           0 : YV12_BUFFER_CONFIG *av1_scale_if_required_fast(AV1_COMMON *cm,
     856             :                                                YV12_BUFFER_CONFIG *unscaled,
     857             :                                                YV12_BUFFER_CONFIG *scaled) {
     858           0 :   if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
     859           0 :       cm->mi_rows * MI_SIZE != unscaled->y_height) {
     860             :     // For 2x2 scaling down.
     861           0 :     aom_scale_frame(unscaled, scaled, unscaled->y_buffer, 9, 2, 1, 2, 1, 0);
     862           0 :     aom_extend_frame_borders(scaled);
     863           0 :     return scaled;
     864             :   } else {
     865           0 :     return unscaled;
     866             :   }
     867             : }
     868             : 
     869           0 : YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
     870             :                                           YV12_BUFFER_CONFIG *unscaled,
     871             :                                           YV12_BUFFER_CONFIG *scaled) {
     872           0 :   if (cm->width != unscaled->y_width || cm->height != unscaled->y_height) {
     873             : #if CONFIG_HIGHBITDEPTH
     874           0 :     resize_and_extend_frame(unscaled, scaled, (int)cm->bit_depth);
     875             : #else
     876             :     resize_and_extend_frame(unscaled, scaled);
     877             : #endif  // CONFIG_HIGHBITDEPTH
     878           0 :     return scaled;
     879             :   } else {
     880           0 :     return unscaled;
     881             :   }
     882             : }

Generated by: LCOV version 1.13