scale.cc 62.4 KB
Newer Older
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1
/*
2
 *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
3 4 5 6
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS. All contributing project authors may
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
8 9 10
 *  be found in the AUTHORS file in the root of the source tree.
 */

11
#include "libyuv/scale.h"
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
12

13
#include <assert.h>
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
14 15
#include <string.h>

16
#include "libyuv/cpu_id.h"
17
#include "libyuv/planar_functions.h"  // For CopyPlane
18
#include "libyuv/row.h"
19
#include "libyuv/scale_row.h"
20

21 22 23 24 25
#ifdef __cplusplus
namespace libyuv {
extern "C" {
#endif

26 27 28 29
static __inline int Abs(int v) {
  return v >= 0 ? v : -v;
}

30
#define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s)
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
31

fbarchard@google.com's avatar
fbarchard@google.com committed
32 33 34 35
// Scale plane, 1/2
// This is an optimized version for scaling down a plane to 1/2 of
// its original size.

Frank Barchard's avatar
Frank Barchard committed
36 37 38 39 40 41
static void ScalePlaneDown2(int src_width,
                            int src_height,
                            int dst_width,
                            int dst_height,
                            int src_stride,
                            int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
42 43
                            const uint8_t* src_ptr,
                            uint8_t* dst_ptr,
44
                            enum FilterMode filtering) {
45
  int y;
Frank Barchard's avatar
Frank Barchard committed
46 47
  void (*ScaleRowDown2)(const uint8_t* src_ptr, ptrdiff_t src_stride,
                        uint8_t* dst_ptr, int dst_width) =
48 49 50 51
      filtering == kFilterNone
          ? ScaleRowDown2_C
          : (filtering == kFilterLinear ? ScaleRowDown2Linear_C
                                        : ScaleRowDown2Box_C);
52
  int row_stride = src_stride << 1;
53 54
  (void)src_width;
  (void)src_height;
55 56 57 58 59
  if (!filtering) {
    src_ptr += src_stride;  // Point to odd rows.
    src_stride = 0;
  }

mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
60
#if defined(HAS_SCALEROWDOWN2_NEON)
61
  if (TestCpuFlag(kCpuHasNEON)) {
Frank Barchard's avatar
Frank Barchard committed
62 63 64 65 66
    ScaleRowDown2 =
        filtering == kFilterNone
            ? ScaleRowDown2_Any_NEON
            : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_NEON
                                          : ScaleRowDown2Box_Any_NEON);
67
    if (IS_ALIGNED(dst_width, 16)) {
Frank Barchard's avatar
Frank Barchard committed
68 69 70 71
      ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_NEON
                                               : (filtering == kFilterLinear
                                                      ? ScaleRowDown2Linear_NEON
                                                      : ScaleRowDown2Box_NEON);
72
    }
73
  }
74
#endif
75 76
#if defined(HAS_SCALEROWDOWN2_SSSE3)
  if (TestCpuFlag(kCpuHasSSSE3)) {
Frank Barchard's avatar
Frank Barchard committed
77 78 79 80 81
    ScaleRowDown2 =
        filtering == kFilterNone
            ? ScaleRowDown2_Any_SSSE3
            : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_SSSE3
                                          : ScaleRowDown2Box_Any_SSSE3);
82
    if (IS_ALIGNED(dst_width, 16)) {
Frank Barchard's avatar
Frank Barchard committed
83 84 85 86 87
      ScaleRowDown2 =
          filtering == kFilterNone
              ? ScaleRowDown2_SSSE3
              : (filtering == kFilterLinear ? ScaleRowDown2Linear_SSSE3
                                            : ScaleRowDown2Box_SSSE3);
88
    }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
89
  }
90
#endif
91
#if defined(HAS_SCALEROWDOWN2_AVX2)
92
  if (TestCpuFlag(kCpuHasAVX2)) {
Frank Barchard's avatar
Frank Barchard committed
93 94 95 96 97
    ScaleRowDown2 =
        filtering == kFilterNone
            ? ScaleRowDown2_Any_AVX2
            : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_AVX2
                                          : ScaleRowDown2Box_Any_AVX2);
98
    if (IS_ALIGNED(dst_width, 32)) {
Frank Barchard's avatar
Frank Barchard committed
99 100 101 102
      ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_AVX2
                                               : (filtering == kFilterLinear
                                                      ? ScaleRowDown2Linear_AVX2
                                                      : ScaleRowDown2Box_AVX2);
103 104 105
    }
  }
#endif
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
#if defined(HAS_SCALEROWDOWN2_MSA)
  if (TestCpuFlag(kCpuHasMSA)) {
    ScaleRowDown2 =
        filtering == kFilterNone
            ? ScaleRowDown2_Any_MSA
            : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_MSA
                                          : ScaleRowDown2Box_Any_MSA);
    if (IS_ALIGNED(dst_width, 32)) {
      ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_MSA
                                               : (filtering == kFilterLinear
                                                      ? ScaleRowDown2Linear_MSA
                                                      : ScaleRowDown2Box_MSA);
    }
  }
#endif
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
#if defined(HAS_SCALEROWDOWN2_MMI)
  if (TestCpuFlag(kCpuHasMMI)) {
    ScaleRowDown2 =
        filtering == kFilterNone
            ? ScaleRowDown2_Any_MMI
            : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_MMI
                                          : ScaleRowDown2Box_Any_MMI);
    if (IS_ALIGNED(dst_width, 8)) {
      ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_MMI
                                               : (filtering == kFilterLinear
                                                      ? ScaleRowDown2Linear_MMI
                                                      : ScaleRowDown2Box_MMI);
    }
  }
#endif
136

137 138 139
  if (filtering == kFilterLinear) {
    src_stride = 0;
  }
140
  // TODO(fbarchard): Loop through source height to allow odd height.
141
  for (y = 0; y < dst_height; ++y) {
142
    ScaleRowDown2(src_ptr, src_stride, dst_ptr, dst_width);
143
    src_ptr += row_stride;
144
    dst_ptr += dst_stride;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
145 146 147
  }
}

Frank Barchard's avatar
Frank Barchard committed
148 149 150 151 152 153
static void ScalePlaneDown2_16(int src_width,
                               int src_height,
                               int dst_width,
                               int dst_height,
                               int src_stride,
                               int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
154 155
                               const uint16_t* src_ptr,
                               uint16_t* dst_ptr,
156 157
                               enum FilterMode filtering) {
  int y;
Frank Barchard's avatar
Frank Barchard committed
158 159
  void (*ScaleRowDown2)(const uint16_t* src_ptr, ptrdiff_t src_stride,
                        uint16_t* dst_ptr, int dst_width) =
Frank Barchard's avatar
Frank Barchard committed
160 161 162 163
      filtering == kFilterNone
          ? ScaleRowDown2_16_C
          : (filtering == kFilterLinear ? ScaleRowDown2Linear_16_C
                                        : ScaleRowDown2Box_16_C);
164
  int row_stride = src_stride << 1;
165 166
  (void)src_width;
  (void)src_height;
167 168 169 170 171 172 173
  if (!filtering) {
    src_ptr += src_stride;  // Point to odd rows.
    src_stride = 0;
  }

#if defined(HAS_SCALEROWDOWN2_16_NEON)
  if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(dst_width, 16)) {
Frank Barchard's avatar
Frank Barchard committed
174 175
    ScaleRowDown2 =
        filtering ? ScaleRowDown2Box_16_NEON : ScaleRowDown2_16_NEON;
176
  }
177 178
#endif
#if defined(HAS_SCALEROWDOWN2_16_SSE2)
179
  if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 16)) {
Frank Barchard's avatar
Frank Barchard committed
180 181 182 183 184
    ScaleRowDown2 =
        filtering == kFilterNone
            ? ScaleRowDown2_16_SSE2
            : (filtering == kFilterLinear ? ScaleRowDown2Linear_16_SSE2
                                          : ScaleRowDown2Box_16_SSE2);
185
  }
186
#endif
187 188
#if defined(HAS_SCALEROWDOWN2_16_MMI)
  if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 4)) {
189 190 191 192
    ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_16_MMI
                                             : (filtering == kFilterLinear
                                                    ? ScaleRowDown2Linear_16_MMI
                                                    : ScaleRowDown2Box_16_MMI);
193 194
  }
#endif
195 196 197 198 199 200 201 202 203 204 205 206

  if (filtering == kFilterLinear) {
    src_stride = 0;
  }
  // TODO(fbarchard): Loop through source height to allow odd height.
  for (y = 0; y < dst_height; ++y) {
    ScaleRowDown2(src_ptr, src_stride, dst_ptr, dst_width);
    src_ptr += row_stride;
    dst_ptr += dst_stride;
  }
}

fbarchard@google.com's avatar
fbarchard@google.com committed
207 208 209 210
// Scale plane, 1/4
// This is an optimized version for scaling down a plane to 1/4 of
// its original size.

Frank Barchard's avatar
Frank Barchard committed
211 212 213 214 215 216
static void ScalePlaneDown4(int src_width,
                            int src_height,
                            int dst_width,
                            int dst_height,
                            int src_stride,
                            int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
217 218
                            const uint8_t* src_ptr,
                            uint8_t* dst_ptr,
219
                            enum FilterMode filtering) {
220
  int y;
Frank Barchard's avatar
Frank Barchard committed
221 222
  void (*ScaleRowDown4)(const uint8_t* src_ptr, ptrdiff_t src_stride,
                        uint8_t* dst_ptr, int dst_width) =
223 224
      filtering ? ScaleRowDown4Box_C : ScaleRowDown4_C;
  int row_stride = src_stride << 2;
225 226
  (void)src_width;
  (void)src_height;
227 228 229 230
  if (!filtering) {
    src_ptr += src_stride * 2;  // Point to row 2.
    src_stride = 0;
  }
231
#if defined(HAS_SCALEROWDOWN4_NEON)
232
  if (TestCpuFlag(kCpuHasNEON)) {
Frank Barchard's avatar
Frank Barchard committed
233 234
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_Any_NEON : ScaleRowDown4_Any_NEON;
235 236 237
    if (IS_ALIGNED(dst_width, 8)) {
      ScaleRowDown4 = filtering ? ScaleRowDown4Box_NEON : ScaleRowDown4_NEON;
    }
238
  }
239
#endif
240 241
#if defined(HAS_SCALEROWDOWN4_SSSE3)
  if (TestCpuFlag(kCpuHasSSSE3)) {
Frank Barchard's avatar
Frank Barchard committed
242 243
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_Any_SSSE3 : ScaleRowDown4_Any_SSSE3;
244
    if (IS_ALIGNED(dst_width, 8)) {
245
      ScaleRowDown4 = filtering ? ScaleRowDown4Box_SSSE3 : ScaleRowDown4_SSSE3;
246
    }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
247
  }
248
#endif
249 250
#if defined(HAS_SCALEROWDOWN4_AVX2)
  if (TestCpuFlag(kCpuHasAVX2)) {
Frank Barchard's avatar
Frank Barchard committed
251 252
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_Any_AVX2 : ScaleRowDown4_Any_AVX2;
253 254 255 256 257
    if (IS_ALIGNED(dst_width, 16)) {
      ScaleRowDown4 = filtering ? ScaleRowDown4Box_AVX2 : ScaleRowDown4_AVX2;
    }
  }
#endif
258 259 260 261 262 263 264 265 266
#if defined(HAS_SCALEROWDOWN4_MSA)
  if (TestCpuFlag(kCpuHasMSA)) {
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_Any_MSA : ScaleRowDown4_Any_MSA;
    if (IS_ALIGNED(dst_width, 16)) {
      ScaleRowDown4 = filtering ? ScaleRowDown4Box_MSA : ScaleRowDown4_MSA;
    }
  }
#endif
267 268 269 270 271 272 273 274 275
#if defined(HAS_SCALEROWDOWN4_MMI)
  if (TestCpuFlag(kCpuHasMMI)) {
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_Any_MMI : ScaleRowDown4_Any_MMI;
    if (IS_ALIGNED(dst_width, 8)) {
      ScaleRowDown4 = filtering ? ScaleRowDown4Box_MMI : ScaleRowDown4_MMI;
    }
  }
#endif
276

277 278 279
  if (filtering == kFilterLinear) {
    src_stride = 0;
  }
280
  for (y = 0; y < dst_height; ++y) {
281
    ScaleRowDown4(src_ptr, src_stride, dst_ptr, dst_width);
282
    src_ptr += row_stride;
283
    dst_ptr += dst_stride;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
284 285 286
  }
}

Frank Barchard's avatar
Frank Barchard committed
287 288 289 290 291 292
static void ScalePlaneDown4_16(int src_width,
                               int src_height,
                               int dst_width,
                               int dst_height,
                               int src_stride,
                               int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
293 294
                               const uint16_t* src_ptr,
                               uint16_t* dst_ptr,
295 296
                               enum FilterMode filtering) {
  int y;
Frank Barchard's avatar
Frank Barchard committed
297 298
  void (*ScaleRowDown4)(const uint16_t* src_ptr, ptrdiff_t src_stride,
                        uint16_t* dst_ptr, int dst_width) =
299 300
      filtering ? ScaleRowDown4Box_16_C : ScaleRowDown4_16_C;
  int row_stride = src_stride << 2;
301 302
  (void)src_width;
  (void)src_height;
303 304 305 306 307 308
  if (!filtering) {
    src_ptr += src_stride * 2;  // Point to row 2.
    src_stride = 0;
  }
#if defined(HAS_SCALEROWDOWN4_16_NEON)
  if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(dst_width, 8)) {
Frank Barchard's avatar
Frank Barchard committed
309 310
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_16_NEON : ScaleRowDown4_16_NEON;
311
  }
312 313
#endif
#if defined(HAS_SCALEROWDOWN4_16_SSE2)
314
  if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
Frank Barchard's avatar
Frank Barchard committed
315 316
    ScaleRowDown4 =
        filtering ? ScaleRowDown4Box_16_SSE2 : ScaleRowDown4_16_SSE2;
317
  }
318
#endif
319 320
#if defined(HAS_SCALEROWDOWN4_16_MMI)
  if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) {
321
    ScaleRowDown4 = filtering ? ScaleRowDown4Box_16_MMI : ScaleRowDown4_16_MMI;
322 323
  }
#endif
324 325 326 327 328 329 330 331 332 333 334

  if (filtering == kFilterLinear) {
    src_stride = 0;
  }
  for (y = 0; y < dst_height; ++y) {
    ScaleRowDown4(src_ptr, src_stride, dst_ptr, dst_width);
    src_ptr += row_stride;
    dst_ptr += dst_stride;
  }
}

fbarchard@google.com's avatar
fbarchard@google.com committed
335
// Scale plane down, 3/4
Frank Barchard's avatar
Frank Barchard committed
336 337 338 339 340 341
static void ScalePlaneDown34(int src_width,
                             int src_height,
                             int dst_width,
                             int dst_height,
                             int src_stride,
                             int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
342 343
                             const uint8_t* src_ptr,
                             uint8_t* dst_ptr,
344
                             enum FilterMode filtering) {
345
  int y;
Frank Barchard's avatar
Frank Barchard committed
346 347 348 349
  void (*ScaleRowDown34_0)(const uint8_t* src_ptr, ptrdiff_t src_stride,
                           uint8_t* dst_ptr, int dst_width);
  void (*ScaleRowDown34_1)(const uint8_t* src_ptr, ptrdiff_t src_stride,
                           uint8_t* dst_ptr, int dst_width);
350
  const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride;
351 352
  (void)src_width;
  (void)src_height;
353
  assert(dst_width % 3 == 0);
354 355 356 357
  if (!filtering) {
    ScaleRowDown34_0 = ScaleRowDown34_C;
    ScaleRowDown34_1 = ScaleRowDown34_C;
  } else {
358 359
    ScaleRowDown34_0 = ScaleRowDown34_0_Box_C;
    ScaleRowDown34_1 = ScaleRowDown34_1_Box_C;
360
  }
361
#if defined(HAS_SCALEROWDOWN34_NEON)
362
  if (TestCpuFlag(kCpuHasNEON)) {
363
    if (!filtering) {
364 365
      ScaleRowDown34_0 = ScaleRowDown34_Any_NEON;
      ScaleRowDown34_1 = ScaleRowDown34_Any_NEON;
366
    } else {
367 368 369 370 371 372 373 374 375 376 377
      ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_NEON;
      ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_NEON;
    }
    if (dst_width % 24 == 0) {
      if (!filtering) {
        ScaleRowDown34_0 = ScaleRowDown34_NEON;
        ScaleRowDown34_1 = ScaleRowDown34_NEON;
      } else {
        ScaleRowDown34_0 = ScaleRowDown34_0_Box_NEON;
        ScaleRowDown34_1 = ScaleRowDown34_1_Box_NEON;
      }
378
    }
379 380
  }
#endif
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
#if defined(HAS_SCALEROWDOWN34_MSA)
  if (TestCpuFlag(kCpuHasMSA)) {
    if (!filtering) {
      ScaleRowDown34_0 = ScaleRowDown34_Any_MSA;
      ScaleRowDown34_1 = ScaleRowDown34_Any_MSA;
    } else {
      ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_MSA;
      ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_MSA;
    }
    if (dst_width % 48 == 0) {
      if (!filtering) {
        ScaleRowDown34_0 = ScaleRowDown34_MSA;
        ScaleRowDown34_1 = ScaleRowDown34_MSA;
      } else {
        ScaleRowDown34_0 = ScaleRowDown34_0_Box_MSA;
        ScaleRowDown34_1 = ScaleRowDown34_1_Box_MSA;
      }
    }
  }
#endif
401 402 403 404 405 406 407 408 409 410 411 412
#if defined(HAS_SCALEROWDOWN34_MMI)
  if (TestCpuFlag(kCpuHasMMI)) {
    if (!filtering) {
      ScaleRowDown34_0 = ScaleRowDown34_Any_MMI;
      ScaleRowDown34_1 = ScaleRowDown34_Any_MMI;
      if (dst_width % 24 == 0) {
        ScaleRowDown34_0 = ScaleRowDown34_MMI;
        ScaleRowDown34_1 = ScaleRowDown34_MMI;
      }
    }
  }
#endif
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
413
#if defined(HAS_SCALEROWDOWN34_SSSE3)
414
  if (TestCpuFlag(kCpuHasSSSE3)) {
415
    if (!filtering) {
416 417
      ScaleRowDown34_0 = ScaleRowDown34_Any_SSSE3;
      ScaleRowDown34_1 = ScaleRowDown34_Any_SSSE3;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
418
    } else {
419 420 421 422 423 424 425 426 427 428 429
      ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_SSSE3;
      ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_SSSE3;
    }
    if (dst_width % 24 == 0) {
      if (!filtering) {
        ScaleRowDown34_0 = ScaleRowDown34_SSSE3;
        ScaleRowDown34_1 = ScaleRowDown34_SSSE3;
      } else {
        ScaleRowDown34_0 = ScaleRowDown34_0_Box_SSSE3;
        ScaleRowDown34_1 = ScaleRowDown34_1_Box_SSSE3;
      }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
430 431
    }
  }
432
#endif
433

434
  for (y = 0; y < dst_height - 2; y += 3) {
435
    ScaleRowDown34_0(src_ptr, filter_stride, dst_ptr, dst_width);
436
    src_ptr += src_stride;
437
    dst_ptr += dst_stride;
438
    ScaleRowDown34_1(src_ptr, filter_stride, dst_ptr, dst_width);
439 440
    src_ptr += src_stride;
    dst_ptr += dst_stride;
Frank Barchard's avatar
Frank Barchard committed
441
    ScaleRowDown34_0(src_ptr + src_stride, -filter_stride, dst_ptr, dst_width);
442 443 444 445
    src_ptr += src_stride * 2;
    dst_ptr += dst_stride;
  }

446 447
  // Remainder 1 or 2 rows with last row vertically unfiltered
  if ((dst_height % 3) == 2) {
448
    ScaleRowDown34_0(src_ptr, filter_stride, dst_ptr, dst_width);
449 450
    src_ptr += src_stride;
    dst_ptr += dst_stride;
451 452 453
    ScaleRowDown34_1(src_ptr, 0, dst_ptr, dst_width);
  } else if ((dst_height % 3) == 1) {
    ScaleRowDown34_0(src_ptr, 0, dst_ptr, dst_width);
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
454 455 456
  }
}

Frank Barchard's avatar
Frank Barchard committed
457 458 459 460 461 462
static void ScalePlaneDown34_16(int src_width,
                                int src_height,
                                int dst_width,
                                int dst_height,
                                int src_stride,
                                int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
463 464
                                const uint16_t* src_ptr,
                                uint16_t* dst_ptr,
465 466
                                enum FilterMode filtering) {
  int y;
Frank Barchard's avatar
Frank Barchard committed
467 468 469 470
  void (*ScaleRowDown34_0)(const uint16_t* src_ptr, ptrdiff_t src_stride,
                           uint16_t* dst_ptr, int dst_width);
  void (*ScaleRowDown34_1)(const uint16_t* src_ptr, ptrdiff_t src_stride,
                           uint16_t* dst_ptr, int dst_width);
471
  const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride;
472 473
  (void)src_width;
  (void)src_height;
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
  assert(dst_width % 3 == 0);
  if (!filtering) {
    ScaleRowDown34_0 = ScaleRowDown34_16_C;
    ScaleRowDown34_1 = ScaleRowDown34_16_C;
  } else {
    ScaleRowDown34_0 = ScaleRowDown34_0_Box_16_C;
    ScaleRowDown34_1 = ScaleRowDown34_1_Box_16_C;
  }
#if defined(HAS_SCALEROWDOWN34_16_NEON)
  if (TestCpuFlag(kCpuHasNEON) && (dst_width % 24 == 0)) {
    if (!filtering) {
      ScaleRowDown34_0 = ScaleRowDown34_16_NEON;
      ScaleRowDown34_1 = ScaleRowDown34_16_NEON;
    } else {
      ScaleRowDown34_0 = ScaleRowDown34_0_Box_16_NEON;
      ScaleRowDown34_1 = ScaleRowDown34_1_Box_16_NEON;
    }
  }
#endif
#if defined(HAS_SCALEROWDOWN34_16_SSSE3)
494
  if (TestCpuFlag(kCpuHasSSSE3) && (dst_width % 24 == 0)) {
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    if (!filtering) {
      ScaleRowDown34_0 = ScaleRowDown34_16_SSSE3;
      ScaleRowDown34_1 = ScaleRowDown34_16_SSSE3;
    } else {
      ScaleRowDown34_0 = ScaleRowDown34_0_Box_16_SSSE3;
      ScaleRowDown34_1 = ScaleRowDown34_1_Box_16_SSSE3;
    }
  }
#endif

  for (y = 0; y < dst_height - 2; y += 3) {
    ScaleRowDown34_0(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride;
    dst_ptr += dst_stride;
    ScaleRowDown34_1(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride;
    dst_ptr += dst_stride;
Frank Barchard's avatar
Frank Barchard committed
512
    ScaleRowDown34_0(src_ptr + src_stride, -filter_stride, dst_ptr, dst_width);
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
    src_ptr += src_stride * 2;
    dst_ptr += dst_stride;
  }

  // Remainder 1 or 2 rows with last row vertically unfiltered
  if ((dst_height % 3) == 2) {
    ScaleRowDown34_0(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride;
    dst_ptr += dst_stride;
    ScaleRowDown34_1(src_ptr, 0, dst_ptr, dst_width);
  } else if ((dst_height % 3) == 1) {
    ScaleRowDown34_0(src_ptr, 0, dst_ptr, dst_width);
  }
}

fbarchard@google.com's avatar
fbarchard@google.com committed
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
// Scale plane, 3/8
// This is an optimized version for scaling down a plane to 3/8
// of its original size.
//
// Uses box filter arranges like this
// aaabbbcc -> abc
// aaabbbcc    def
// aaabbbcc    ghi
// dddeeeff
// dddeeeff
// dddeeeff
// ggghhhii
// ggghhhii
// Boxes are 3x3, 2x3, 3x2 and 2x2

Frank Barchard's avatar
Frank Barchard committed
543 544 545 546 547 548
static void ScalePlaneDown38(int src_width,
                             int src_height,
                             int dst_width,
                             int dst_height,
                             int src_stride,
                             int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
549 550
                             const uint8_t* src_ptr,
                             uint8_t* dst_ptr,
551
                             enum FilterMode filtering) {
552
  int y;
Frank Barchard's avatar
Frank Barchard committed
553 554 555 556
  void (*ScaleRowDown38_3)(const uint8_t* src_ptr, ptrdiff_t src_stride,
                           uint8_t* dst_ptr, int dst_width);
  void (*ScaleRowDown38_2)(const uint8_t* src_ptr, ptrdiff_t src_stride,
                           uint8_t* dst_ptr, int dst_width);
557 558
  const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride;
  assert(dst_width % 3 == 0);
559 560
  (void)src_width;
  (void)src_height;
561 562 563 564
  if (!filtering) {
    ScaleRowDown38_3 = ScaleRowDown38_C;
    ScaleRowDown38_2 = ScaleRowDown38_C;
  } else {
565 566
    ScaleRowDown38_3 = ScaleRowDown38_3_Box_C;
    ScaleRowDown38_2 = ScaleRowDown38_2_Box_C;
567
  }
568

569
#if defined(HAS_SCALEROWDOWN38_NEON)
570
  if (TestCpuFlag(kCpuHasNEON)) {
571
    if (!filtering) {
572 573
      ScaleRowDown38_3 = ScaleRowDown38_Any_NEON;
      ScaleRowDown38_2 = ScaleRowDown38_Any_NEON;
574
    } else {
575 576 577 578 579 580 581 582 583 584 585
      ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_NEON;
      ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_NEON;
    }
    if (dst_width % 12 == 0) {
      if (!filtering) {
        ScaleRowDown38_3 = ScaleRowDown38_NEON;
        ScaleRowDown38_2 = ScaleRowDown38_NEON;
      } else {
        ScaleRowDown38_3 = ScaleRowDown38_3_Box_NEON;
        ScaleRowDown38_2 = ScaleRowDown38_2_Box_NEON;
      }
586
    }
587
  }
588 589
#endif
#if defined(HAS_SCALEROWDOWN38_SSSE3)
590
  if (TestCpuFlag(kCpuHasSSSE3)) {
591
    if (!filtering) {
592 593 594 595 596 597 598
      ScaleRowDown38_3 = ScaleRowDown38_Any_SSSE3;
      ScaleRowDown38_2 = ScaleRowDown38_Any_SSSE3;
    } else {
      ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_SSSE3;
      ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_SSSE3;
    }
    if (dst_width % 12 == 0 && !filtering) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
599 600
      ScaleRowDown38_3 = ScaleRowDown38_SSSE3;
      ScaleRowDown38_2 = ScaleRowDown38_SSSE3;
601 602
    }
    if (dst_width % 6 == 0 && filtering) {
603 604
      ScaleRowDown38_3 = ScaleRowDown38_3_Box_SSSE3;
      ScaleRowDown38_2 = ScaleRowDown38_2_Box_SSSE3;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
605 606
    }
  }
607
#endif
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
#if defined(HAS_SCALEROWDOWN38_MSA)
  if (TestCpuFlag(kCpuHasMSA)) {
    if (!filtering) {
      ScaleRowDown38_3 = ScaleRowDown38_Any_MSA;
      ScaleRowDown38_2 = ScaleRowDown38_Any_MSA;
    } else {
      ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_MSA;
      ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_MSA;
    }
    if (dst_width % 12 == 0) {
      if (!filtering) {
        ScaleRowDown38_3 = ScaleRowDown38_MSA;
        ScaleRowDown38_2 = ScaleRowDown38_MSA;
      } else {
        ScaleRowDown38_3 = ScaleRowDown38_3_Box_MSA;
        ScaleRowDown38_2 = ScaleRowDown38_2_Box_MSA;
      }
    }
  }
#endif
628

629
  for (y = 0; y < dst_height - 2; y += 3) {
630
    ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width);
631 632
    src_ptr += src_stride * 3;
    dst_ptr += dst_stride;
633
    ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width);
634 635
    src_ptr += src_stride * 3;
    dst_ptr += dst_stride;
636
    ScaleRowDown38_2(src_ptr, filter_stride, dst_ptr, dst_width);
637
    src_ptr += src_stride * 2;
638
    dst_ptr += dst_stride;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
639
  }
640 641 642

  // Remainder 1 or 2 rows with last row vertically unfiltered
  if ((dst_height % 3) == 2) {
643
    ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width);
644 645
    src_ptr += src_stride * 3;
    dst_ptr += dst_stride;
646 647 648
    ScaleRowDown38_3(src_ptr, 0, dst_ptr, dst_width);
  } else if ((dst_height % 3) == 1) {
    ScaleRowDown38_3(src_ptr, 0, dst_ptr, dst_width);
649
  }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
650 651
}

Frank Barchard's avatar
Frank Barchard committed
652 653 654 655 656 657
static void ScalePlaneDown38_16(int src_width,
                                int src_height,
                                int dst_width,
                                int dst_height,
                                int src_stride,
                                int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
658 659
                                const uint16_t* src_ptr,
                                uint16_t* dst_ptr,
660 661
                                enum FilterMode filtering) {
  int y;
Frank Barchard's avatar
Frank Barchard committed
662 663 664 665
  void (*ScaleRowDown38_3)(const uint16_t* src_ptr, ptrdiff_t src_stride,
                           uint16_t* dst_ptr, int dst_width);
  void (*ScaleRowDown38_2)(const uint16_t* src_ptr, ptrdiff_t src_stride,
                           uint16_t* dst_ptr, int dst_width);
666
  const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride;
667 668
  (void)src_width;
  (void)src_height;
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
  assert(dst_width % 3 == 0);
  if (!filtering) {
    ScaleRowDown38_3 = ScaleRowDown38_16_C;
    ScaleRowDown38_2 = ScaleRowDown38_16_C;
  } else {
    ScaleRowDown38_3 = ScaleRowDown38_3_Box_16_C;
    ScaleRowDown38_2 = ScaleRowDown38_2_Box_16_C;
  }
#if defined(HAS_SCALEROWDOWN38_16_NEON)
  if (TestCpuFlag(kCpuHasNEON) && (dst_width % 12 == 0)) {
    if (!filtering) {
      ScaleRowDown38_3 = ScaleRowDown38_16_NEON;
      ScaleRowDown38_2 = ScaleRowDown38_16_NEON;
    } else {
      ScaleRowDown38_3 = ScaleRowDown38_3_Box_16_NEON;
      ScaleRowDown38_2 = ScaleRowDown38_2_Box_16_NEON;
    }
  }
687 688
#endif
#if defined(HAS_SCALEROWDOWN38_16_SSSE3)
689
  if (TestCpuFlag(kCpuHasSSSE3) && (dst_width % 24 == 0)) {
690 691 692 693 694 695 696 697
    if (!filtering) {
      ScaleRowDown38_3 = ScaleRowDown38_16_SSSE3;
      ScaleRowDown38_2 = ScaleRowDown38_16_SSSE3;
    } else {
      ScaleRowDown38_3 = ScaleRowDown38_3_Box_16_SSSE3;
      ScaleRowDown38_2 = ScaleRowDown38_2_Box_16_SSSE3;
    }
  }
698
#endif
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722

  for (y = 0; y < dst_height - 2; y += 3) {
    ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride * 3;
    dst_ptr += dst_stride;
    ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride * 3;
    dst_ptr += dst_stride;
    ScaleRowDown38_2(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride * 2;
    dst_ptr += dst_stride;
  }

  // Remainder 1 or 2 rows with last row vertically unfiltered
  if ((dst_height % 3) == 2) {
    ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width);
    src_ptr += src_stride * 3;
    dst_ptr += dst_stride;
    ScaleRowDown38_3(src_ptr, 0, dst_ptr, dst_width);
  } else if ((dst_height % 3) == 1) {
    ScaleRowDown38_3(src_ptr, 0, dst_ptr, dst_width);
  }
}

723 724
#define MIN1(x) ((x) < 1 ? 1 : (x))

Frank Barchard's avatar
Frank Barchard committed
725 726
static __inline uint32_t SumPixels(int iboxwidth, const uint16_t* src_ptr) {
  uint32_t sum = 0u;
727
  int x;
728
  assert(iboxwidth > 0);
729
  for (x = 0; x < iboxwidth; ++x) {
730
    sum += src_ptr[x];
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
731 732 733 734
  }
  return sum;
}

Frank Barchard's avatar
Frank Barchard committed
735 736
static __inline uint32_t SumPixels_16(int iboxwidth, const uint32_t* src_ptr) {
  uint32_t sum = 0u;
737 738 739 740 741 742 743 744
  int x;
  assert(iboxwidth > 0);
  for (x = 0; x < iboxwidth; ++x) {
    sum += src_ptr[x];
  }
  return sum;
}

Frank Barchard's avatar
Frank Barchard committed
745 746 747 748
static void ScaleAddCols2_C(int dst_width,
                            int boxheight,
                            int x,
                            int dx,
Frank Barchard's avatar
Frank Barchard committed
749 750
                            const uint16_t* src_ptr,
                            uint8_t* dst_ptr) {
751
  int i;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
752
  int scaletbl[2];
753
  int minboxwidth = dx >> 16;
754
  int boxwidth;
755 756
  scaletbl[0] = 65536 / (MIN1(minboxwidth) * boxheight);
  scaletbl[1] = 65536 / (MIN1(minboxwidth + 1) * boxheight);
757
  for (i = 0; i < dst_width; ++i) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
758 759
    int ix = x >> 16;
    x += dx;
760
    boxwidth = MIN1((x >> 16) - ix);
Frank Barchard's avatar
Frank Barchard committed
761 762 763
    *dst_ptr++ =
        SumPixels(boxwidth, src_ptr + ix) * scaletbl[boxwidth - minboxwidth] >>
        16;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
764 765 766
  }
}

Frank Barchard's avatar
Frank Barchard committed
767 768 769 770
static void ScaleAddCols2_16_C(int dst_width,
                               int boxheight,
                               int x,
                               int dx,
Frank Barchard's avatar
Frank Barchard committed
771 772
                               const uint32_t* src_ptr,
                               uint16_t* dst_ptr) {
773 774
  int i;
  int scaletbl[2];
775
  int minboxwidth = dx >> 16;
776
  int boxwidth;
777 778
  scaletbl[0] = 65536 / (MIN1(minboxwidth) * boxheight);
  scaletbl[1] = 65536 / (MIN1(minboxwidth + 1) * boxheight);
779 780 781
  for (i = 0; i < dst_width; ++i) {
    int ix = x >> 16;
    x += dx;
782
    boxwidth = MIN1((x >> 16) - ix);
783
    *dst_ptr++ = SumPixels_16(boxwidth, src_ptr + ix) *
Frank Barchard's avatar
Frank Barchard committed
784 785
                     scaletbl[boxwidth - minboxwidth] >>
                 16;
786 787 788
  }
}

Frank Barchard's avatar
Frank Barchard committed
789 790 791
static void ScaleAddCols0_C(int dst_width,
                            int boxheight,
                            int x,
792
                            int dx,
Frank Barchard's avatar
Frank Barchard committed
793 794
                            const uint16_t* src_ptr,
                            uint8_t* dst_ptr) {
795 796
  int scaleval = 65536 / boxheight;
  int i;
797
  (void)dx;
798 799 800 801 802 803
  src_ptr += (x >> 16);
  for (i = 0; i < dst_width; ++i) {
    *dst_ptr++ = src_ptr[i] * scaleval >> 16;
  }
}

Frank Barchard's avatar
Frank Barchard committed
804 805 806 807
static void ScaleAddCols1_C(int dst_width,
                            int boxheight,
                            int x,
                            int dx,
Frank Barchard's avatar
Frank Barchard committed
808 809
                            const uint16_t* src_ptr,
                            uint8_t* dst_ptr) {
810
  int boxwidth = MIN1(dx >> 16);
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
811
  int scaleval = 65536 / (boxwidth * boxheight);
812
  int i;
813
  x >>= 16;
814
  for (i = 0; i < dst_width; ++i) {
815
    *dst_ptr++ = SumPixels(boxwidth, src_ptr + x) * scaleval >> 16;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
816 817 818 819
    x += boxwidth;
  }
}

Frank Barchard's avatar
Frank Barchard committed
820 821 822 823
static void ScaleAddCols1_16_C(int dst_width,
                               int boxheight,
                               int x,
                               int dx,
Frank Barchard's avatar
Frank Barchard committed
824 825
                               const uint32_t* src_ptr,
                               uint16_t* dst_ptr) {
826
  int boxwidth = MIN1(dx >> 16);
827 828 829 830 831 832 833 834
  int scaleval = 65536 / (boxwidth * boxheight);
  int i;
  for (i = 0; i < dst_width; ++i) {
    *dst_ptr++ = SumPixels_16(boxwidth, src_ptr + x) * scaleval >> 16;
    x += boxwidth;
  }
}

fbarchard@google.com's avatar
fbarchard@google.com committed
835 836 837 838 839 840 841
// Scale plane down to any dimensions, with interpolation.
// (boxfilter).
//
// Same method as SimpleScale, which is fixed point, outputting
// one pixel of destination using fixed point (16.16) to step
// through source, sampling a box of pixel with simple
// averaging.
Frank Barchard's avatar
Frank Barchard committed
842 843 844 845 846 847
static void ScalePlaneBox(int src_width,
                          int src_height,
                          int dst_width,
                          int dst_height,
                          int src_stride,
                          int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
848 849
                          const uint8_t* src_ptr,
                          uint8_t* dst_ptr) {
850
  int j, k;
851
  // Initial source x/y coordinate and step values as 16.16 fixed point.
852 853
  int x = 0;
  int y = 0;
854 855
  int dx = 0;
  int dy = 0;
856
  const int max_y = (src_height << 16);
Frank Barchard's avatar
Frank Barchard committed
857 858
  ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterBox, &x, &y,
             &dx, &dy);
859
  src_width = Abs(src_width);
860
  {
Frank Barchard's avatar
Frank Barchard committed
861
    // Allocate a row buffer of uint16_t.
862 863
    align_buffer_64(row16, src_width * 2);
    void (*ScaleAddCols)(int dst_width, int boxheight, int x, int dx,
Frank Barchard's avatar
Frank Barchard committed
864
                         const uint16_t* src_ptr, uint8_t* dst_ptr) =
Frank Barchard's avatar
Frank Barchard committed
865 866
        (dx & 0xffff) ? ScaleAddCols2_C
                      : ((dx != 0x10000) ? ScaleAddCols1_C : ScaleAddCols0_C);
867 868
    void (*ScaleAddRow)(const uint8_t* src_ptr, uint16_t* dst_ptr,
                        int src_width) = ScaleAddRow_C;
869
#if defined(HAS_SCALEADDROW_SSE2)
870
    if (TestCpuFlag(kCpuHasSSE2)) {
871
      ScaleAddRow = ScaleAddRow_Any_SSE2;
872
      if (IS_ALIGNED(src_width, 16)) {
873
        ScaleAddRow = ScaleAddRow_SSE2;
874
      }
875
    }
876
#endif
877
#if defined(HAS_SCALEADDROW_AVX2)
878
    if (TestCpuFlag(kCpuHasAVX2)) {
879
      ScaleAddRow = ScaleAddRow_Any_AVX2;
880
      if (IS_ALIGNED(src_width, 32)) {
881
        ScaleAddRow = ScaleAddRow_AVX2;
882
      }
883 884
    }
#endif
885
#if defined(HAS_SCALEADDROW_NEON)
886
    if (TestCpuFlag(kCpuHasNEON)) {
887
      ScaleAddRow = ScaleAddRow_Any_NEON;
888
      if (IS_ALIGNED(src_width, 16)) {
889
        ScaleAddRow = ScaleAddRow_NEON;
890
      }
891 892
    }
#endif
893 894 895 896 897 898 899 900
#if defined(HAS_SCALEADDROW_MSA)
    if (TestCpuFlag(kCpuHasMSA)) {
      ScaleAddRow = ScaleAddRow_Any_MSA;
      if (IS_ALIGNED(src_width, 16)) {
        ScaleAddRow = ScaleAddRow_MSA;
      }
    }
#endif
901 902 903 904 905 906 907 908
#if defined(HAS_SCALEADDROW_MMI)
    if (TestCpuFlag(kCpuHasMMI)) {
      ScaleAddRow = ScaleAddRow_Any_MMI;
      if (IS_ALIGNED(src_width, 8)) {
        ScaleAddRow = ScaleAddRow_MMI;
      }
    }
#endif
909

910 911 912
    for (j = 0; j < dst_height; ++j) {
      int boxheight;
      int iy = y >> 16;
Frank Barchard's avatar
Frank Barchard committed
913
      const uint8_t* src = src_ptr + iy * src_stride;
914
      y += dy;
915 916
      if (y > max_y) {
        y = max_y;
917
      }
918
      boxheight = MIN1((y >> 16) - iy);
919 920
      memset(row16, 0, src_width * 2);
      for (k = 0; k < boxheight; ++k) {
Frank Barchard's avatar
Frank Barchard committed
921
        ScaleAddRow(src, (uint16_t*)(row16), src_width);
922 923
        src += src_stride;
      }
Frank Barchard's avatar
Frank Barchard committed
924
      ScaleAddCols(dst_width, boxheight, x, dx, (uint16_t*)(row16), dst_ptr);
925 926 927
      dst_ptr += dst_stride;
    }
    free_aligned_buffer_64(row16);
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
928 929 930
  }
}

Frank Barchard's avatar
Frank Barchard committed
931 932 933 934 935 936
static void ScalePlaneBox_16(int src_width,
                             int src_height,
                             int dst_width,
                             int dst_height,
                             int src_stride,
                             int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
937 938
                             const uint16_t* src_ptr,
                             uint16_t* dst_ptr) {
939
  int j, k;
940 941 942 943 944
  // Initial source x/y coordinate and step values as 16.16 fixed point.
  int x = 0;
  int y = 0;
  int dx = 0;
  int dy = 0;
945
  const int max_y = (src_height << 16);
Frank Barchard's avatar
Frank Barchard committed
946 947
  ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterBox, &x, &y,
             &dx, &dy);
948
  src_width = Abs(src_width);
949
  {
Frank Barchard's avatar
Frank Barchard committed
950
    // Allocate a row buffer of uint32_t.
951 952
    align_buffer_64(row32, src_width * 4);
    void (*ScaleAddCols)(int dst_width, int boxheight, int x, int dx,
Frank Barchard's avatar
Frank Barchard committed
953
                         const uint32_t* src_ptr, uint16_t* dst_ptr) =
Frank Barchard's avatar
Frank Barchard committed
954
        (dx & 0xffff) ? ScaleAddCols2_16_C : ScaleAddCols1_16_C;
955 956
    void (*ScaleAddRow)(const uint16_t* src_ptr, uint32_t* dst_ptr,
                        int src_width) = ScaleAddRow_16_C;
957

958
#if defined(HAS_SCALEADDROW_16_SSE2)
959
    if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(src_width, 16)) {
960
      ScaleAddRow = ScaleAddRow_16_SSE2;
961 962 963
    }
#endif

964 965 966 967 968
#if defined(HAS_SCALEADDROW_16_MMI)
    if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(src_width, 4)) {
      ScaleAddRow = ScaleAddRow_16_MMI;
    }
#endif
969 970 971
    for (j = 0; j < dst_height; ++j) {
      int boxheight;
      int iy = y >> 16;
Frank Barchard's avatar
Frank Barchard committed
972
      const uint16_t* src = src_ptr + iy * src_stride;
973
      y += dy;
974 975
      if (y > max_y) {
        y = max_y;
976
      }
977
      boxheight = MIN1((y >> 16) - iy);
978 979
      memset(row32, 0, src_width * 4);
      for (k = 0; k < boxheight; ++k) {
Frank Barchard's avatar
Frank Barchard committed
980
        ScaleAddRow(src, (uint32_t*)(row32), src_width);
981 982
        src += src_stride;
      }
Frank Barchard's avatar
Frank Barchard committed
983
      ScaleAddCols(dst_width, boxheight, x, dx, (uint32_t*)(row32), dst_ptr);
984 985 986 987 988 989 990
      dst_ptr += dst_stride;
    }
    free_aligned_buffer_64(row32);
  }
}

// Scale plane down with bilinear interpolation.
Frank Barchard's avatar
Frank Barchard committed
991 992 993 994 995 996
void ScalePlaneBilinearDown(int src_width,
                            int src_height,
                            int dst_width,
                            int dst_height,
                            int src_stride,
                            int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
997 998
                            const uint8_t* src_ptr,
                            uint8_t* dst_ptr,
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
                            enum FilterMode filtering) {
  // Initial source x/y coordinate and step values as 16.16 fixed point.
  int x = 0;
  int y = 0;
  int dx = 0;
  int dy = 0;
  // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear.
  // Allocate a row buffer.
  align_buffer_64(row, src_width);

  const int max_y = (src_height - 1) << 16;
  int j;
1011 1012
  void (*ScaleFilterCols)(uint8_t * dst_ptr, const uint8_t* src_ptr,
                          int dst_width, int x, int dx) =
1013
      (src_width >= 32768) ? ScaleFilterCols64_C : ScaleFilterCols_C;
Frank Barchard's avatar
Frank Barchard committed
1014
  void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr,
Frank Barchard's avatar
Frank Barchard committed
1015 1016 1017 1018
                         ptrdiff_t src_stride, int dst_width,
                         int source_y_fraction) = InterpolateRow_C;
  ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
             &dx, &dy);
1019 1020 1021
  src_width = Abs(src_width);

#if defined(HAS_INTERPOLATEROW_SSSE3)
1022
  if (TestCpuFlag(kCpuHasSSSE3)) {
1023 1024
    InterpolateRow = InterpolateRow_Any_SSSE3;
    if (IS_ALIGNED(src_width, 16)) {
1025
      InterpolateRow = InterpolateRow_SSSE3;
1026 1027 1028
    }
  }
#endif
1029
#if defined(HAS_INTERPOLATEROW_AVX2)
1030
  if (TestCpuFlag(kCpuHasAVX2)) {
1031 1032 1033 1034 1035 1036
    InterpolateRow = InterpolateRow_Any_AVX2;
    if (IS_ALIGNED(src_width, 32)) {
      InterpolateRow = InterpolateRow_AVX2;
    }
  }
#endif
1037
#if defined(HAS_INTERPOLATEROW_NEON)
1038
  if (TestCpuFlag(kCpuHasNEON)) {
1039 1040 1041 1042 1043 1044
    InterpolateRow = InterpolateRow_Any_NEON;
    if (IS_ALIGNED(src_width, 16)) {
      InterpolateRow = InterpolateRow_NEON;
    }
  }
#endif
1045 1046 1047 1048 1049 1050 1051 1052
#if defined(HAS_INTERPOLATEROW_MSA)
  if (TestCpuFlag(kCpuHasMSA)) {
    InterpolateRow = InterpolateRow_Any_MSA;
    if (IS_ALIGNED(src_width, 32)) {
      InterpolateRow = InterpolateRow_MSA;
    }
  }
#endif
1053 1054 1055 1056 1057 1058 1059 1060
#if defined(HAS_INTERPOLATEROW_MMI)
  if (TestCpuFlag(kCpuHasMMI)) {
    InterpolateRow = InterpolateRow_Any_MMI;
    if (IS_ALIGNED(src_width, 16)) {
      InterpolateRow = InterpolateRow_MMI;
    }
  }
#endif
1061 1062

#if defined(HAS_SCALEFILTERCOLS_SSSE3)
1063
  if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
1064 1065
    ScaleFilterCols = ScaleFilterCols_SSSE3;
  }
1066 1067 1068 1069 1070 1071 1072 1073
#endif
#if defined(HAS_SCALEFILTERCOLS_NEON)
  if (TestCpuFlag(kCpuHasNEON) && src_width < 32768) {
    ScaleFilterCols = ScaleFilterCols_Any_NEON;
    if (IS_ALIGNED(dst_width, 8)) {
      ScaleFilterCols = ScaleFilterCols_NEON;
    }
  }
1074 1075 1076 1077 1078 1079 1080 1081
#endif
#if defined(HAS_SCALEFILTERCOLS_MSA)
  if (TestCpuFlag(kCpuHasMSA) && src_width < 32768) {
    ScaleFilterCols = ScaleFilterCols_Any_MSA;
    if (IS_ALIGNED(dst_width, 16)) {
      ScaleFilterCols = ScaleFilterCols_MSA;
    }
  }
1082
#endif
1083 1084 1085
  if (y > max_y) {
    y = max_y;
  }
1086

1087
  for (j = 0; j < dst_height; ++j) {
1088
    int yi = y >> 16;
Frank Barchard's avatar
Frank Barchard committed
1089
    const uint8_t* src = src_ptr + yi * src_stride;
1090
    if (filtering == kFilterLinear) {
1091
      ScaleFilterCols(dst_ptr, src, dst_width, x, dx);
1092 1093 1094
    } else {
      int yf = (y >> 8) & 255;
      InterpolateRow(row, src, src_stride, src_width, yf);
1095
      ScaleFilterCols(dst_ptr, row, dst_width, x, dx);
1096
    }
1097
    dst_ptr += dst_stride;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1098
    y += dy;
1099 1100 1101
    if (y > max_y) {
      y = max_y;
    }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1102
  }
1103
  free_aligned_buffer_64(row);
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1104 1105
}

Frank Barchard's avatar
Frank Barchard committed
1106 1107 1108 1109 1110 1111
void ScalePlaneBilinearDown_16(int src_width,
                               int src_height,
                               int dst_width,
                               int dst_height,
                               int src_stride,
                               int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
1112 1113
                               const uint16_t* src_ptr,
                               uint16_t* dst_ptr,
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
                               enum FilterMode filtering) {
  // Initial source x/y coordinate and step values as 16.16 fixed point.
  int x = 0;
  int y = 0;
  int dx = 0;
  int dy = 0;
  // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear.
  // Allocate a row buffer.
  align_buffer_64(row, src_width * 2);

  const int max_y = (src_height - 1) << 16;
  int j;
Frank Barchard's avatar
Frank Barchard committed
1126
  void (*ScaleFilterCols)(uint16_t * dst_ptr, const uint16_t* src_ptr,
1127
                          int dst_width, int x, int dx) =
1128
      (src_width >= 32768) ? ScaleFilterCols64_16_C : ScaleFilterCols_16_C;
Frank Barchard's avatar
Frank Barchard committed
1129
  void (*InterpolateRow)(uint16_t * dst_ptr, const uint16_t* src_ptr,
Frank Barchard's avatar
Frank Barchard committed
1130 1131 1132 1133
                         ptrdiff_t src_stride, int dst_width,
                         int source_y_fraction) = InterpolateRow_16_C;
  ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
             &dx, &dy);
1134 1135 1136
  src_width = Abs(src_width);

#if defined(HAS_INTERPOLATEROW_16_SSE2)
1137
  if (TestCpuFlag(kCpuHasSSE2)) {
1138 1139
    InterpolateRow = InterpolateRow_Any_16_SSE2;
    if (IS_ALIGNED(src_width, 16)) {
1140
      InterpolateRow = InterpolateRow_16_SSE2;
1141 1142 1143 1144
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_16_SSSE3)
1145
  if (TestCpuFlag(kCpuHasSSSE3)) {
1146 1147
    InterpolateRow = InterpolateRow_Any_16_SSSE3;
    if (IS_ALIGNED(src_width, 16)) {
1148
      InterpolateRow = InterpolateRow_16_SSSE3;
1149 1150 1151 1152
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_16_AVX2)
1153
  if (TestCpuFlag(kCpuHasAVX2)) {
1154 1155 1156 1157 1158 1159 1160
    InterpolateRow = InterpolateRow_Any_16_AVX2;
    if (IS_ALIGNED(src_width, 32)) {
      InterpolateRow = InterpolateRow_16_AVX2;
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_16_NEON)
1161
  if (TestCpuFlag(kCpuHasNEON)) {
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
    InterpolateRow = InterpolateRow_Any_16_NEON;
    if (IS_ALIGNED(src_width, 16)) {
      InterpolateRow = InterpolateRow_16_NEON;
    }
  }
#endif

#if defined(HAS_SCALEFILTERCOLS_16_SSSE3)
  if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
    ScaleFilterCols = ScaleFilterCols_16_SSSE3;
  }
#endif
  if (y > max_y) {
    y = max_y;
  }

  for (j = 0; j < dst_height; ++j) {
    int yi = y >> 16;
Frank Barchard's avatar
Frank Barchard committed
1180
    const uint16_t* src = src_ptr + yi * src_stride;
1181 1182 1183 1184
    if (filtering == kFilterLinear) {
      ScaleFilterCols(dst_ptr, src, dst_width, x, dx);
    } else {
      int yf = (y >> 8) & 255;
Frank Barchard's avatar
Frank Barchard committed
1185 1186
      InterpolateRow((uint16_t*)row, src, src_stride, src_width, yf);
      ScaleFilterCols(dst_ptr, (uint16_t*)row, dst_width, x, dx);
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
    }
    dst_ptr += dst_stride;
    y += dy;
    if (y > max_y) {
      y = max_y;
    }
  }
  free_aligned_buffer_64(row);
}

fbarchard@google.com's avatar
fbarchard@google.com committed
1197
// Scale up down with bilinear interpolation.
Frank Barchard's avatar
Frank Barchard committed
1198 1199 1200 1201 1202 1203
void ScalePlaneBilinearUp(int src_width,
                          int src_height,
                          int dst_width,
                          int dst_height,
                          int src_stride,
                          int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
1204 1205
                          const uint8_t* src_ptr,
                          uint8_t* dst_ptr,
1206
                          enum FilterMode filtering) {
1207
  int j;
1208
  // Initial source x/y coordinate and step values as 16.16 fixed point.
1209 1210
  int x = 0;
  int y = 0;
1211 1212
  int dx = 0;
  int dy = 0;
1213
  const int max_y = (src_height - 1) << 16;
Frank Barchard's avatar
Frank Barchard committed
1214
  void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr,
Frank Barchard's avatar
Frank Barchard committed
1215 1216
                         ptrdiff_t src_stride, int dst_width,
                         int source_y_fraction) = InterpolateRow_C;
1217 1218
  void (*ScaleFilterCols)(uint8_t * dst_ptr, const uint8_t* src_ptr,
                          int dst_width, int x, int dx) =
1219
      filtering ? ScaleFilterCols_C : ScaleCols_C;
Frank Barchard's avatar
Frank Barchard committed
1220 1221
  ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
             &dx, &dy);
1222
  src_width = Abs(src_width);
1223

fbarchard@google.com's avatar
fbarchard@google.com committed
1224
#if defined(HAS_INTERPOLATEROW_SSSE3)
1225
  if (TestCpuFlag(kCpuHasSSSE3)) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1226 1227
    InterpolateRow = InterpolateRow_Any_SSSE3;
    if (IS_ALIGNED(dst_width, 16)) {
1228
      InterpolateRow = InterpolateRow_SSSE3;
fbarchard@google.com's avatar
fbarchard@google.com committed
1229 1230 1231 1232
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_AVX2)
1233
  if (TestCpuFlag(kCpuHasAVX2)) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1234 1235 1236 1237 1238 1239 1240
    InterpolateRow = InterpolateRow_Any_AVX2;
    if (IS_ALIGNED(dst_width, 32)) {
      InterpolateRow = InterpolateRow_AVX2;
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_NEON)
1241
  if (TestCpuFlag(kCpuHasNEON)) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1242 1243 1244 1245 1246 1247 1248
    InterpolateRow = InterpolateRow_Any_NEON;
    if (IS_ALIGNED(dst_width, 16)) {
      InterpolateRow = InterpolateRow_NEON;
    }
  }
#endif

1249 1250 1251
  if (filtering && src_width >= 32768) {
    ScaleFilterCols = ScaleFilterCols64_C;
  }
fbarchard@google.com's avatar
fbarchard@google.com committed
1252
#if defined(HAS_SCALEFILTERCOLS_SSSE3)
1253
  if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1254 1255
    ScaleFilterCols = ScaleFilterCols_SSSE3;
  }
1256 1257 1258 1259 1260 1261 1262 1263
#endif
#if defined(HAS_SCALEFILTERCOLS_NEON)
  if (filtering && TestCpuFlag(kCpuHasNEON) && src_width < 32768) {
    ScaleFilterCols = ScaleFilterCols_Any_NEON;
    if (IS_ALIGNED(dst_width, 8)) {
      ScaleFilterCols = ScaleFilterCols_NEON;
    }
  }
1264 1265 1266 1267 1268 1269 1270 1271
#endif
#if defined(HAS_SCALEFILTERCOLS_MSA)
  if (filtering && TestCpuFlag(kCpuHasMSA) && src_width < 32768) {
    ScaleFilterCols = ScaleFilterCols_Any_MSA;
    if (IS_ALIGNED(dst_width, 16)) {
      ScaleFilterCols = ScaleFilterCols_MSA;
    }
  }
fbarchard@google.com's avatar
fbarchard@google.com committed
1272
#endif
1273 1274 1275
  if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
    ScaleFilterCols = ScaleColsUp2_C;
#if defined(HAS_SCALECOLS_SSE2)
1276
    if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
1277 1278
      ScaleFilterCols = ScaleColsUp2_SSE2;
    }
1279 1280 1281 1282 1283
#endif
#if defined(HAS_SCALECOLS_MMI)
    if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) {
      ScaleFilterCols = ScaleColsUp2_MMI;
    }
1284
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
1285 1286 1287 1288 1289
  }

  if (y > max_y) {
    y = max_y;
  }
1290 1291
  {
    int yi = y >> 16;
Frank Barchard's avatar
Frank Barchard committed
1292
    const uint8_t* src = src_ptr + yi * src_stride;
1293

1294
    // Allocate 2 row buffers.
1295
    const int kRowSize = (dst_width + 31) & ~31;
1296
    align_buffer_64(row, kRowSize * 2);
1297

Frank Barchard's avatar
Frank Barchard committed
1298
    uint8_t* rowptr = row;
1299 1300
    int rowstride = kRowSize;
    int lasty = yi;
fbarchard@google.com's avatar
fbarchard@google.com committed
1301

1302 1303 1304 1305 1306
    ScaleFilterCols(rowptr, src, dst_width, x, dx);
    if (src_height > 1) {
      src += src_stride;
    }
    ScaleFilterCols(rowptr + rowstride, src, dst_width, x, dx);
fbarchard@google.com's avatar
fbarchard@google.com committed
1307 1308
    src += src_stride;

1309 1310
    for (j = 0; j < dst_height; ++j) {
      yi = y >> 16;
1311
      if (yi != lasty) {
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
        if (y > max_y) {
          y = max_y;
          yi = y >> 16;
          src = src_ptr + yi * src_stride;
        }
        if (yi != lasty) {
          ScaleFilterCols(rowptr, src, dst_width, x, dx);
          rowptr += rowstride;
          rowstride = -rowstride;
          lasty = yi;
          src += src_stride;
        }
fbarchard@google.com's avatar
fbarchard@google.com committed
1324
      }
1325 1326 1327 1328 1329 1330 1331 1332
      if (filtering == kFilterLinear) {
        InterpolateRow(dst_ptr, rowptr, 0, dst_width, 0);
      } else {
        int yf = (y >> 8) & 255;
        InterpolateRow(dst_ptr, rowptr, rowstride, dst_width, yf);
      }
      dst_ptr += dst_stride;
      y += dy;
fbarchard@google.com's avatar
fbarchard@google.com committed
1333
    }
1334
    free_aligned_buffer_64(row);
fbarchard@google.com's avatar
fbarchard@google.com committed
1335 1336 1337
  }
}

Frank Barchard's avatar
Frank Barchard committed
1338 1339 1340 1341 1342 1343
void ScalePlaneBilinearUp_16(int src_width,
                             int src_height,
                             int dst_width,
                             int dst_height,
                             int src_stride,
                             int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
1344 1345
                             const uint16_t* src_ptr,
                             uint16_t* dst_ptr,
1346 1347 1348 1349 1350 1351 1352 1353
                             enum FilterMode filtering) {
  int j;
  // Initial source x/y coordinate and step values as 16.16 fixed point.
  int x = 0;
  int y = 0;
  int dx = 0;
  int dy = 0;
  const int max_y = (src_height - 1) << 16;
Frank Barchard's avatar
Frank Barchard committed
1354
  void (*InterpolateRow)(uint16_t * dst_ptr, const uint16_t* src_ptr,
Frank Barchard's avatar
Frank Barchard committed
1355 1356
                         ptrdiff_t src_stride, int dst_width,
                         int source_y_fraction) = InterpolateRow_16_C;
Frank Barchard's avatar
Frank Barchard committed
1357
  void (*ScaleFilterCols)(uint16_t * dst_ptr, const uint16_t* src_ptr,
1358
                          int dst_width, int x, int dx) =
1359
      filtering ? ScaleFilterCols_16_C : ScaleCols_16_C;
Frank Barchard's avatar
Frank Barchard committed
1360 1361
  ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
             &dx, &dy);
1362 1363 1364
  src_width = Abs(src_width);

#if defined(HAS_INTERPOLATEROW_16_SSE2)
1365
  if (TestCpuFlag(kCpuHasSSE2)) {
1366 1367
    InterpolateRow = InterpolateRow_Any_16_SSE2;
    if (IS_ALIGNED(dst_width, 16)) {
1368
      InterpolateRow = InterpolateRow_16_SSE2;
1369 1370 1371 1372
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_16_SSSE3)
1373
  if (TestCpuFlag(kCpuHasSSSE3)) {
1374 1375
    InterpolateRow = InterpolateRow_Any_16_SSSE3;
    if (IS_ALIGNED(dst_width, 16)) {
1376
      InterpolateRow = InterpolateRow_16_SSSE3;
1377 1378 1379 1380
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_16_AVX2)
1381
  if (TestCpuFlag(kCpuHasAVX2)) {
1382 1383 1384 1385 1386 1387 1388
    InterpolateRow = InterpolateRow_Any_16_AVX2;
    if (IS_ALIGNED(dst_width, 32)) {
      InterpolateRow = InterpolateRow_16_AVX2;
    }
  }
#endif
#if defined(HAS_INTERPOLATEROW_16_NEON)
1389
  if (TestCpuFlag(kCpuHasNEON)) {
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
    InterpolateRow = InterpolateRow_Any_16_NEON;
    if (IS_ALIGNED(dst_width, 16)) {
      InterpolateRow = InterpolateRow_16_NEON;
    }
  }
#endif

  if (filtering && src_width >= 32768) {
    ScaleFilterCols = ScaleFilterCols64_16_C;
  }
#if defined(HAS_SCALEFILTERCOLS_16_SSSE3)
  if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
    ScaleFilterCols = ScaleFilterCols_16_SSSE3;
  }
#endif
  if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
    ScaleFilterCols = ScaleColsUp2_16_C;
#if defined(HAS_SCALECOLS_16_SSE2)
1408
    if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
1409 1410
      ScaleFilterCols = ScaleColsUp2_16_SSE2;
    }
1411 1412 1413 1414 1415
#endif
#if defined(HAS_SCALECOLS_16_MMI)
    if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) {
      ScaleFilterCols = ScaleColsUp2_16_MMI;
    }
1416 1417 1418 1419 1420 1421 1422 1423
#endif
  }

  if (y > max_y) {
    y = max_y;
  }
  {
    int yi = y >> 16;
Frank Barchard's avatar
Frank Barchard committed
1424
    const uint16_t* src = src_ptr + yi * src_stride;
1425 1426

    // Allocate 2 row buffers.
1427
    const int kRowSize = (dst_width + 31) & ~31;
1428 1429
    align_buffer_64(row, kRowSize * 4);

Frank Barchard's avatar
Frank Barchard committed
1430
    uint16_t* rowptr = (uint16_t*)row;
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
    int rowstride = kRowSize;
    int lasty = yi;

    ScaleFilterCols(rowptr, src, dst_width, x, dx);
    if (src_height > 1) {
      src += src_stride;
    }
    ScaleFilterCols(rowptr + rowstride, src, dst_width, x, dx);
    src += src_stride;

    for (j = 0; j < dst_height; ++j) {
      yi = y >> 16;
      if (yi != lasty) {
        if (y > max_y) {
          y = max_y;
          yi = y >> 16;
          src = src_ptr + yi * src_stride;
        }
        if (yi != lasty) {
          ScaleFilterCols(rowptr, src, dst_width, x, dx);
          rowptr += rowstride;
          rowstride = -rowstride;
          lasty = yi;
          src += src_stride;
        }
      }
      if (filtering == kFilterLinear) {
        InterpolateRow(dst_ptr, rowptr, 0, dst_width, 0);
      } else {
        int yf = (y >> 8) & 255;
        InterpolateRow(dst_ptr, rowptr, rowstride, dst_width, yf);
      }
      dst_ptr += dst_stride;
      y += dy;
    }
    free_aligned_buffer_64(row);
  }
}

1470
// Scale Plane to/from any dimensions, without interpolation.
fbarchard@google.com's avatar
fbarchard@google.com committed
1471 1472 1473 1474
// Fixed point math is used for performance: The upper 16 bits
// of x and dx is the integer part of the source position and
// the lower 16 bits are the fixed decimal part.

Frank Barchard's avatar
Frank Barchard committed
1475 1476 1477 1478 1479 1480
static void ScalePlaneSimple(int src_width,
                             int src_height,
                             int dst_width,
                             int dst_height,
                             int src_stride,
                             int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
1481 1482
                             const uint8_t* src_ptr,
                             uint8_t* dst_ptr) {
1483
  int i;
1484 1485
  void (*ScaleCols)(uint8_t * dst_ptr, const uint8_t* src_ptr, int dst_width,
                    int x, int dx) = ScaleCols_C;
1486
  // Initial source x/y coordinate and step values as 16.16 fixed point.
1487 1488
  int x = 0;
  int y = 0;
1489 1490
  int dx = 0;
  int dy = 0;
Frank Barchard's avatar
Frank Barchard committed
1491 1492
  ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterNone, &x, &y,
             &dx, &dy);
1493
  src_width = Abs(src_width);
1494

1495 1496 1497
  if (src_width * 2 == dst_width && x < 0x8000) {
    ScaleCols = ScaleColsUp2_C;
#if defined(HAS_SCALECOLS_SSE2)
1498
    if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
1499
      ScaleCols = ScaleColsUp2_SSE2;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1500
    }
1501 1502 1503 1504 1505
#endif
#if defined(HAS_SCALECOLS_MMI)
    if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) {
      ScaleCols = ScaleColsUp2_MMI;
    }
1506
#endif
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1507 1508
  }

1509
  for (i = 0; i < dst_height; ++i) {
1510
    ScaleCols(dst_ptr, src_ptr + (y >> 16) * src_stride, dst_width, x, dx);
1511 1512
    dst_ptr += dst_stride;
    y += dy;
fbarchard@google.com's avatar
fbarchard@google.com committed
1513
  }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1514 1515
}

Frank Barchard's avatar
Frank Barchard committed
1516 1517 1518 1519 1520 1521
static void ScalePlaneSimple_16(int src_width,
                                int src_height,
                                int dst_width,
                                int dst_height,
                                int src_stride,
                                int dst_stride,
Frank Barchard's avatar
Frank Barchard committed
1522 1523
                                const uint16_t* src_ptr,
                                uint16_t* dst_ptr) {
1524
  int i;
Frank Barchard's avatar
Frank Barchard committed
1525
  void (*ScaleCols)(uint16_t * dst_ptr, const uint16_t* src_ptr, int dst_width,
Frank Barchard's avatar
Frank Barchard committed
1526
                    int x, int dx) = ScaleCols_16_C;
1527 1528 1529 1530 1531
  // Initial source x/y coordinate and step values as 16.16 fixed point.
  int x = 0;
  int y = 0;
  int dx = 0;
  int dy = 0;
Frank Barchard's avatar
Frank Barchard committed
1532 1533
  ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterNone, &x, &y,
             &dx, &dy);
1534 1535 1536 1537 1538
  src_width = Abs(src_width);

  if (src_width * 2 == dst_width && x < 0x8000) {
    ScaleCols = ScaleColsUp2_16_C;
#if defined(HAS_SCALECOLS_16_SSE2)
1539
    if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
1540 1541
      ScaleCols = ScaleColsUp2_16_SSE2;
    }
1542 1543 1544 1545 1546
#endif
#if defined(HAS_SCALECOLS_16_MMI)
    if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) {
      ScaleCols = ScaleColsUp2_16_MMI;
    }
1547 1548 1549 1550
#endif
  }

  for (i = 0; i < dst_height; ++i) {
Frank Barchard's avatar
Frank Barchard committed
1551
    ScaleCols(dst_ptr, src_ptr + (y >> 16) * src_stride, dst_width, x, dx);
1552 1553 1554 1555 1556
    dst_ptr += dst_stride;
    y += dy;
  }
}

1557
// Scale a plane.
1558
// This function dispatches to a specialized scaler based on scale factor.
1559

1560
LIBYUV_API
Frank Barchard's avatar
Frank Barchard committed
1561
void ScalePlane(const uint8_t* src,
Frank Barchard's avatar
Frank Barchard committed
1562 1563 1564
                int src_stride,
                int src_width,
                int src_height,
Frank Barchard's avatar
Frank Barchard committed
1565
                uint8_t* dst,
Frank Barchard's avatar
Frank Barchard committed
1566 1567 1568
                int dst_stride,
                int dst_width,
                int dst_height,
1569
                enum FilterMode filtering) {
1570
  // Simplify filtering when possible.
Frank Barchard's avatar
Frank Barchard committed
1571 1572
  filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height,
                                filtering);
1573

1574 1575 1576 1577 1578 1579 1580
  // Negative height means invert the image.
  if (src_height < 0) {
    src_height = -src_height;
    src = src + (src_height - 1) * src_stride;
    src_stride = -src_stride;
  }

mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1581 1582
  // Use specialized scales to improve performance for common resolutions.
  // For example, all the 1/2 scalings will use ScalePlaneDown2()
1583
  if (dst_width == src_width && dst_height == src_height) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1584
    // Straight copy.
1585
    CopyPlane(src, src_stride, dst, dst_stride, dst_width, dst_height);
fbarchard@google.com's avatar
fbarchard@google.com committed
1586 1587
    return;
  }
1588
  if (dst_width == src_width && filtering != kFilterBox) {
1589
    int dy = FixedDiv(src_height, dst_height);
1590
    // Arbitrary scale vertically, but unscaled horizontally.
Frank Barchard's avatar
Frank Barchard committed
1591 1592
    ScalePlaneVertical(src_height, dst_width, dst_height, src_stride,
                       dst_stride, src, dst, 0, 0, dy, 1, filtering);
fbarchard@google.com's avatar
fbarchard@google.com committed
1593 1594 1595
    return;
  }
  if (dst_width <= Abs(src_width) && dst_height <= src_height) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1596
    // Scale down.
1597
    if (4 * dst_width == 3 * src_width && 4 * dst_height == 3 * src_height) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1598
      // optimized, 3/4
Frank Barchard's avatar
Frank Barchard committed
1599 1600
      ScalePlaneDown34(src_width, src_height, dst_width, dst_height, src_stride,
                       dst_stride, src, dst, filtering);
fbarchard@google.com's avatar
fbarchard@google.com committed
1601 1602 1603
      return;
    }
    if (2 * dst_width == src_width && 2 * dst_height == src_height) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1604
      // optimized, 1/2
Frank Barchard's avatar
Frank Barchard committed
1605 1606
      ScalePlaneDown2(src_width, src_height, dst_width, dst_height, src_stride,
                      dst_stride, src, dst, filtering);
fbarchard@google.com's avatar
fbarchard@google.com committed
1607 1608
      return;
    }
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1609
    // 3/8 rounded up for odd sized chroma height.
1610
    if (8 * dst_width == 3 * src_width && 8 * dst_height == 3 * src_height) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1611
      // optimized, 3/8
Frank Barchard's avatar
Frank Barchard committed
1612 1613
      ScalePlaneDown38(src_width, src_height, dst_width, dst_height, src_stride,
                       dst_stride, src, dst, filtering);
fbarchard@google.com's avatar
fbarchard@google.com committed
1614 1615 1616
      return;
    }
    if (4 * dst_width == src_width && 4 * dst_height == src_height &&
1617
        (filtering == kFilterBox || filtering == kFilterNone)) {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1618
      // optimized, 1/4
Frank Barchard's avatar
Frank Barchard committed
1619 1620
      ScalePlaneDown4(src_width, src_height, dst_width, dst_height, src_stride,
                      dst_stride, src, dst, filtering);
fbarchard@google.com's avatar
fbarchard@google.com committed
1621
      return;
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1622 1623
    }
  }
fbarchard@google.com's avatar
fbarchard@google.com committed
1624
  if (filtering == kFilterBox && dst_height * 2 < src_height) {
Frank Barchard's avatar
Frank Barchard committed
1625 1626
    ScalePlaneBox(src_width, src_height, dst_width, dst_height, src_stride,
                  dst_stride, src, dst);
1627 1628
    return;
  }
1629
  if (filtering && dst_height > src_height) {
1630 1631 1632 1633
    ScalePlaneBilinearUp(src_width, src_height, dst_width, dst_height,
                         src_stride, dst_stride, src, dst, filtering);
    return;
  }
1634
  if (filtering) {
1635 1636 1637 1638
    ScalePlaneBilinearDown(src_width, src_height, dst_width, dst_height,
                           src_stride, dst_stride, src, dst, filtering);
    return;
  }
Frank Barchard's avatar
Frank Barchard committed
1639 1640
  ScalePlaneSimple(src_width, src_height, dst_width, dst_height, src_stride,
                   dst_stride, src, dst);
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1641 1642
}

1643
LIBYUV_API
Frank Barchard's avatar
Frank Barchard committed
1644
void ScalePlane_16(const uint16_t* src,
Frank Barchard's avatar
Frank Barchard committed
1645 1646 1647
                   int src_stride,
                   int src_width,
                   int src_height,
Frank Barchard's avatar
Frank Barchard committed
1648
                   uint16_t* dst,
Frank Barchard's avatar
Frank Barchard committed
1649 1650 1651 1652
                   int dst_stride,
                   int dst_width,
                   int dst_height,
                   enum FilterMode filtering) {
1653
  // Simplify filtering when possible.
Frank Barchard's avatar
Frank Barchard committed
1654 1655
  filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height,
                                filtering);
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670

  // Negative height means invert the image.
  if (src_height < 0) {
    src_height = -src_height;
    src = src + (src_height - 1) * src_stride;
    src_stride = -src_stride;
  }

  // Use specialized scales to improve performance for common resolutions.
  // For example, all the 1/2 scalings will use ScalePlaneDown2()
  if (dst_width == src_width && dst_height == src_height) {
    // Straight copy.
    CopyPlane_16(src, src_stride, dst, dst_stride, dst_width, dst_height);
    return;
  }
1671
  if (dst_width == src_width && filtering != kFilterBox) {
1672 1673
    int dy = FixedDiv(src_height, dst_height);
    // Arbitrary scale vertically, but unscaled vertically.
Frank Barchard's avatar
Frank Barchard committed
1674 1675
    ScalePlaneVertical_16(src_height, dst_width, dst_height, src_stride,
                          dst_stride, src, dst, 0, 0, dy, 1, filtering);
1676 1677 1678 1679
    return;
  }
  if (dst_width <= Abs(src_width) && dst_height <= src_height) {
    // Scale down.
Frank Barchard's avatar
Frank Barchard committed
1680
    if (4 * dst_width == 3 * src_width && 4 * dst_height == 3 * src_height) {
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
      // optimized, 3/4
      ScalePlaneDown34_16(src_width, src_height, dst_width, dst_height,
                          src_stride, dst_stride, src, dst, filtering);
      return;
    }
    if (2 * dst_width == src_width && 2 * dst_height == src_height) {
      // optimized, 1/2
      ScalePlaneDown2_16(src_width, src_height, dst_width, dst_height,
                         src_stride, dst_stride, src, dst, filtering);
      return;
    }
    // 3/8 rounded up for odd sized chroma height.
1693
    if (8 * dst_width == 3 * src_width && 8 * dst_height == 3 * src_height) {
1694 1695 1696 1697 1698 1699
      // optimized, 3/8
      ScalePlaneDown38_16(src_width, src_height, dst_width, dst_height,
                          src_stride, dst_stride, src, dst, filtering);
      return;
    }
    if (4 * dst_width == src_width && 4 * dst_height == src_height &&
1700
        (filtering == kFilterBox || filtering == kFilterNone)) {
1701 1702 1703 1704 1705 1706 1707
      // optimized, 1/4
      ScalePlaneDown4_16(src_width, src_height, dst_width, dst_height,
                         src_stride, dst_stride, src, dst, filtering);
      return;
    }
  }
  if (filtering == kFilterBox && dst_height * 2 < src_height) {
Frank Barchard's avatar
Frank Barchard committed
1708 1709
    ScalePlaneBox_16(src_width, src_height, dst_width, dst_height, src_stride,
                     dst_stride, src, dst);
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721
    return;
  }
  if (filtering && dst_height > src_height) {
    ScalePlaneBilinearUp_16(src_width, src_height, dst_width, dst_height,
                            src_stride, dst_stride, src, dst, filtering);
    return;
  }
  if (filtering) {
    ScalePlaneBilinearDown_16(src_width, src_height, dst_width, dst_height,
                              src_stride, dst_stride, src, dst, filtering);
    return;
  }
Frank Barchard's avatar
Frank Barchard committed
1722 1723
  ScalePlaneSimple_16(src_width, src_height, dst_width, dst_height, src_stride,
                      dst_stride, src, dst);
1724 1725
}

1726 1727
// Scale an I420 image.
// This function in turn calls a scaling function for each plane.
1728

1729
LIBYUV_API
Frank Barchard's avatar
Frank Barchard committed
1730
int I420Scale(const uint8_t* src_y,
Frank Barchard's avatar
Frank Barchard committed
1731
              int src_stride_y,
Frank Barchard's avatar
Frank Barchard committed
1732
              const uint8_t* src_u,
Frank Barchard's avatar
Frank Barchard committed
1733
              int src_stride_u,
Frank Barchard's avatar
Frank Barchard committed
1734
              const uint8_t* src_v,
Frank Barchard's avatar
Frank Barchard committed
1735 1736 1737
              int src_stride_v,
              int src_width,
              int src_height,
Frank Barchard's avatar
Frank Barchard committed
1738
              uint8_t* dst_y,
Frank Barchard's avatar
Frank Barchard committed
1739
              int dst_stride_y,
Frank Barchard's avatar
Frank Barchard committed
1740
              uint8_t* dst_u,
Frank Barchard's avatar
Frank Barchard committed
1741
              int dst_stride_u,
Frank Barchard's avatar
Frank Barchard committed
1742
              uint8_t* dst_v,
Frank Barchard's avatar
Frank Barchard committed
1743 1744 1745
              int dst_stride_v,
              int dst_width,
              int dst_height,
1746
              enum FilterMode filtering) {
1747 1748 1749 1750
  int src_halfwidth = SUBSAMPLE(src_width, 1, 1);
  int src_halfheight = SUBSAMPLE(src_height, 1, 1);
  int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1);
  int dst_halfheight = SUBSAMPLE(dst_height, 1, 1);
1751
  if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 ||
Frank Barchard's avatar
Frank Barchard committed
1752 1753
      src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v ||
      dst_width <= 0 || dst_height <= 0) {
1754 1755
    return -1;
  }
1756

Frank Barchard's avatar
Frank Barchard committed
1757 1758 1759 1760 1761 1762
  ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y,
             dst_width, dst_height, filtering);
  ScalePlane(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u,
             dst_stride_u, dst_halfwidth, dst_halfheight, filtering);
  ScalePlane(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v,
             dst_stride_v, dst_halfwidth, dst_halfheight, filtering);
1763 1764 1765
  return 0;
}

1766
LIBYUV_API
Frank Barchard's avatar
Frank Barchard committed
1767
int I420Scale_16(const uint16_t* src_y,
Frank Barchard's avatar
Frank Barchard committed
1768
                 int src_stride_y,
Frank Barchard's avatar
Frank Barchard committed
1769
                 const uint16_t* src_u,
Frank Barchard's avatar
Frank Barchard committed
1770
                 int src_stride_u,
Frank Barchard's avatar
Frank Barchard committed
1771
                 const uint16_t* src_v,
Frank Barchard's avatar
Frank Barchard committed
1772 1773 1774
                 int src_stride_v,
                 int src_width,
                 int src_height,
Frank Barchard's avatar
Frank Barchard committed
1775
                 uint16_t* dst_y,
Frank Barchard's avatar
Frank Barchard committed
1776
                 int dst_stride_y,
Frank Barchard's avatar
Frank Barchard committed
1777
                 uint16_t* dst_u,
Frank Barchard's avatar
Frank Barchard committed
1778
                 int dst_stride_u,
Frank Barchard's avatar
Frank Barchard committed
1779
                 uint16_t* dst_v,
Frank Barchard's avatar
Frank Barchard committed
1780 1781 1782
                 int dst_stride_v,
                 int dst_width,
                 int dst_height,
1783 1784 1785 1786 1787 1788
                 enum FilterMode filtering) {
  int src_halfwidth = SUBSAMPLE(src_width, 1, 1);
  int src_halfheight = SUBSAMPLE(src_height, 1, 1);
  int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1);
  int dst_halfheight = SUBSAMPLE(dst_height, 1, 1);
  if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 ||
Frank Barchard's avatar
Frank Barchard committed
1789 1790
      src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v ||
      dst_width <= 0 || dst_height <= 0) {
1791 1792 1793
    return -1;
  }

Frank Barchard's avatar
Frank Barchard committed
1794 1795 1796 1797 1798 1799
  ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y,
                dst_width, dst_height, filtering);
  ScalePlane_16(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u,
                dst_stride_u, dst_halfwidth, dst_halfheight, filtering);
  ScalePlane_16(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v,
                dst_stride_v, dst_halfwidth, dst_halfheight, filtering);
1800 1801 1802
  return 0;
}

1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
// Scale an I444 image.
// This function in turn calls a scaling function for each plane.

LIBYUV_API
int I444Scale(const uint8_t* src_y,
              int src_stride_y,
              const uint8_t* src_u,
              int src_stride_u,
              const uint8_t* src_v,
              int src_stride_v,
              int src_width,
              int src_height,
              uint8_t* dst_y,
              int dst_stride_y,
              uint8_t* dst_u,
              int dst_stride_u,
              uint8_t* dst_v,
              int dst_stride_v,
              int dst_width,
              int dst_height,
              enum FilterMode filtering) {
  if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 ||
      src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v ||
      dst_width <= 0 || dst_height <= 0) {
    return -1;
  }

  ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y,
             dst_width, dst_height, filtering);
  ScalePlane(src_u, src_stride_u, src_width, src_height, dst_u, dst_stride_u,
             dst_width, dst_height, filtering);
  ScalePlane(src_v, src_stride_v, src_width, src_height, dst_v, dst_stride_v,
             dst_width, dst_height, filtering);
  return 0;
}

1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
LIBYUV_API
int I444Scale_16(const uint16_t* src_y,
                 int src_stride_y,
                 const uint16_t* src_u,
                 int src_stride_u,
                 const uint16_t* src_v,
                 int src_stride_v,
                 int src_width,
                 int src_height,
                 uint16_t* dst_y,
                 int dst_stride_y,
                 uint16_t* dst_u,
                 int dst_stride_u,
                 uint16_t* dst_v,
                 int dst_stride_v,
                 int dst_width,
                 int dst_height,
                 enum FilterMode filtering) {
  if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 ||
      src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v ||
      dst_width <= 0 || dst_height <= 0) {
    return -1;
  }

  ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y,
                dst_width, dst_height, filtering);
  ScalePlane_16(src_u, src_stride_u, src_width, src_height, dst_u, dst_stride_u,
                dst_width, dst_height, filtering);
  ScalePlane_16(src_v, src_stride_v, src_width, src_height, dst_v, dst_stride_v,
                dst_width, dst_height, filtering);
  return 0;
}

1872
// Deprecated api
1873
LIBYUV_API
Frank Barchard's avatar
Frank Barchard committed
1874 1875 1876
int Scale(const uint8_t* src_y,
          const uint8_t* src_u,
          const uint8_t* src_v,
Frank Barchard's avatar
Frank Barchard committed
1877 1878 1879 1880 1881
          int src_stride_y,
          int src_stride_u,
          int src_stride_v,
          int src_width,
          int src_height,
Frank Barchard's avatar
Frank Barchard committed
1882 1883 1884
          uint8_t* dst_y,
          uint8_t* dst_u,
          uint8_t* dst_v,
Frank Barchard's avatar
Frank Barchard committed
1885 1886 1887 1888 1889
          int dst_stride_y,
          int dst_stride_u,
          int dst_stride_v,
          int dst_width,
          int dst_height,
1890
          LIBYUV_BOOL interpolate) {
Frank Barchard's avatar
Frank Barchard committed
1891 1892 1893 1894
  return I420Scale(src_y, src_stride_y, src_u, src_stride_u, src_v,
                   src_stride_v, src_width, src_height, dst_y, dst_stride_y,
                   dst_u, dst_stride_u, dst_v, dst_stride_v, dst_width,
                   dst_height, interpolate ? kFilterBox : kFilterNone);
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1895 1896
}

1897 1898
#ifdef __cplusplus
}  // extern "C"
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1899
}  // namespace libyuv
1900
#endif