summaryrefslogtreecommitdiffstats
path: root/third_party/aom/aom_scale
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/aom/aom_scale/aom_scale.cmake37
-rw-r--r--third_party/aom/aom_scale/aom_scale.h23
-rw-r--r--third_party/aom/aom_scale/aom_scale_rtcd.c18
-rw-r--r--third_party/aom/aom_scale/aom_scale_rtcd.pl55
-rw-r--r--third_party/aom/aom_scale/generic/aom_scale.c506
-rw-r--r--third_party/aom/aom_scale/generic/gen_scalers.c201
-rw-r--r--third_party/aom/aom_scale/generic/yv12config.c312
-rw-r--r--third_party/aom/aom_scale/generic/yv12extend.c517
-rw-r--r--third_party/aom/aom_scale/yv12config.h214
9 files changed, 1883 insertions, 0 deletions
diff --git a/third_party/aom/aom_scale/aom_scale.cmake b/third_party/aom/aom_scale/aom_scale.cmake
new file mode 100644
index 0000000000..ea94dbc063
--- /dev/null
+++ b/third_party/aom/aom_scale/aom_scale.cmake
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+#
+# This source code is subject to the terms of the BSD 2 Clause License and the
+# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
+# not distributed with this source code in the LICENSE file, you can obtain it
+# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
+# License 1.0 was not distributed with this source code in the PATENTS file, you
+# can obtain it at www.aomedia.org/license/patent.
+#
+if(AOM_AOM_SCALE_AOM_SCALE_CMAKE_)
+ return()
+endif() # AOM_AOM_SCALE_AOM_SCALE_CMAKE_
+set(AOM_AOM_SCALE_AOM_SCALE_CMAKE_ 1)
+
+list(APPEND AOM_SCALE_SOURCES "${AOM_ROOT}/aom_scale/aom_scale.h"
+ "${AOM_ROOT}/aom_scale/generic/aom_scale.c"
+ "${AOM_ROOT}/aom_scale/generic/gen_scalers.c"
+ "${AOM_ROOT}/aom_scale/generic/yv12config.c"
+ "${AOM_ROOT}/aom_scale/generic/yv12extend.c"
+ "${AOM_ROOT}/aom_scale/yv12config.h")
+
+# Creates the aom_scale build target and makes libaom depend on it. The libaom
+# target must exist before this function is called.
+function(setup_aom_scale_targets)
+ add_library(aom_scale OBJECT ${AOM_SCALE_SOURCES})
+ target_sources(aom PRIVATE $<TARGET_OBJECTS:aom_scale>)
+
+ target_sources(aom PRIVATE $<TARGET_OBJECTS:aom_scale>)
+ if(BUILD_SHARED_LIBS)
+ target_sources(aom_static PRIVATE $<TARGET_OBJECTS:aom_scale>)
+ endif()
+
+ # Pass the new lib targets up to the parent scope instance of
+ # $AOM_LIB_TARGETS.
+ set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_scale PARENT_SCOPE)
+endfunction()
diff --git a/third_party/aom/aom_scale/aom_scale.h b/third_party/aom/aom_scale/aom_scale.h
new file mode 100644
index 0000000000..11812a1453
--- /dev/null
+++ b/third_party/aom/aom_scale/aom_scale.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+#ifndef AOM_AOM_SCALE_AOM_SCALE_H_
+#define AOM_AOM_SCALE_AOM_SCALE_H_
+
+#include "aom_scale/yv12config.h"
+
+extern void aom_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
+ unsigned char *temp_area, unsigned char temp_height,
+ unsigned int hscale, unsigned int hratio,
+ unsigned int vscale, unsigned int vratio,
+ unsigned int interlaced, const int num_planes);
+
+#endif // AOM_AOM_SCALE_AOM_SCALE_H_
diff --git a/third_party/aom/aom_scale/aom_scale_rtcd.c b/third_party/aom/aom_scale/aom_scale_rtcd.c
new file mode 100644
index 0000000000..93def357d8
--- /dev/null
+++ b/third_party/aom/aom_scale/aom_scale_rtcd.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+#include "config/aom_config.h"
+
+#define RTCD_C
+#include "config/aom_scale_rtcd.h"
+
+#include "aom_ports/aom_once.h"
+
+void aom_scale_rtcd(void) { aom_once(setup_rtcd_internal); }
diff --git a/third_party/aom/aom_scale/aom_scale_rtcd.pl b/third_party/aom/aom_scale/aom_scale_rtcd.pl
new file mode 100644
index 0000000000..ae0a85687f
--- /dev/null
+++ b/third_party/aom/aom_scale/aom_scale_rtcd.pl
@@ -0,0 +1,55 @@
+##
+## Copyright (c) 2017, Alliance for Open Media. All rights reserved
+##
+## This source code is subject to the terms of the BSD 2 Clause License and
+## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+## was not distributed with this source code in the LICENSE file, you can
+## obtain it at www.aomedia.org/license/software. If the Alliance for Open
+## Media Patent License 1.0 was not distributed with this source code in the
+## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+##
+sub aom_scale_forward_decls() {
+print <<EOF
+struct yv12_buffer_config;
+EOF
+}
+forward_decls qw/aom_scale_forward_decls/;
+
+# Scaler functions
+if (aom_config("CONFIG_SPATIAL_RESAMPLING") eq "yes") {
+ add_proto qw/void aom_horizontal_line_5_4_scale/, "const unsigned char *source, unsigned int source_width, unsigned char *dest, unsigned int dest_width";
+ add_proto qw/void aom_vertical_band_5_4_scale/, "unsigned char *source, int src_pitch, unsigned char *dest, int dest_pitch, unsigned int dest_width";
+ add_proto qw/void aom_horizontal_line_5_3_scale/, "const unsigned char *source, unsigned int source_width, unsigned char *dest, unsigned int dest_width";
+ add_proto qw/void aom_vertical_band_5_3_scale/, "unsigned char *source, int src_pitch, unsigned char *dest, int dest_pitch, unsigned int dest_width";
+ add_proto qw/void aom_horizontal_line_2_1_scale/, "const unsigned char *source, unsigned int source_width, unsigned char *dest, unsigned int dest_width";
+ add_proto qw/void aom_vertical_band_2_1_scale/, "unsigned char *source, int src_pitch, unsigned char *dest, int dest_pitch, unsigned int dest_width";
+ add_proto qw/void aom_vertical_band_2_1_scale_i/, "unsigned char *source, int src_pitch, unsigned char *dest, int dest_pitch, unsigned int dest_width";
+}
+
+add_proto qw/int aom_yv12_realloc_with_new_border/, "struct yv12_buffer_config *ybf, int new_border, int byte_alignment, int num_pyramid_levels, int num_planes";
+
+add_proto qw/void aom_yv12_extend_frame_borders/, "struct yv12_buffer_config *ybf, const int num_planes";
+
+add_proto qw/void aom_yv12_copy_frame/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc, const int num_planes";
+
+add_proto qw/void aom_yv12_copy_y/, "const struct yv12_buffer_config *src_ybc, struct yv12_buffer_config *dst_ybc";
+
+add_proto qw/void aom_yv12_copy_u/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc";
+
+add_proto qw/void aom_yv12_copy_v/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc";
+
+add_proto qw/void aom_yv12_partial_copy_y/, "const struct yv12_buffer_config *src_ybc, int hstart1, int hend1, int vstart1, int vend1, struct yv12_buffer_config *dst_ybc, int hstart2, int vstart2";
+add_proto qw/void aom_yv12_partial_coloc_copy_y/, "const struct yv12_buffer_config *src_ybc, struct yv12_buffer_config *dst_ybc, int hstart, int hend, int vstart, int vend";
+add_proto qw/void aom_yv12_partial_copy_u/, "const struct yv12_buffer_config *src_bc, int hstart1, int hend1, int vstart1, int vend1, struct yv12_buffer_config *dst_bc, int hstart2, int vstart2";
+add_proto qw/void aom_yv12_partial_coloc_copy_u/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc, int hstart, int hend, int vstart, int vend";
+add_proto qw/void aom_yv12_partial_copy_v/, "const struct yv12_buffer_config *src_bc, int hstart1, int hend1, int vstart1, int vend1, struct yv12_buffer_config *dst_bc, int hstart2, int vstart2";
+add_proto qw/void aom_yv12_partial_coloc_copy_v/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc, int hstart, int hend, int vstart, int vend";
+
+add_proto qw/void aom_extend_frame_borders_plane_row/, "const struct yv12_buffer_config *ybf, int plane, int v_start, int v_end";
+
+add_proto qw/void aom_extend_frame_borders/, "struct yv12_buffer_config *ybf, const int num_planes";
+
+add_proto qw/void aom_extend_frame_inner_borders/, "struct yv12_buffer_config *ybf, const int num_planes";
+
+add_proto qw/void aom_extend_frame_borders_y/, "struct yv12_buffer_config *ybf";
+1;
diff --git a/third_party/aom/aom_scale/generic/aom_scale.c b/third_party/aom/aom_scale/generic/aom_scale.c
new file mode 100644
index 0000000000..206c42c9f5
--- /dev/null
+++ b/third_party/aom/aom_scale/generic/aom_scale.c
@@ -0,0 +1,506 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+/****************************************************************************
+ *
+ * Module Title : scale.c
+ *
+ * Description : Image scaling functions.
+ *
+ ***************************************************************************/
+
+/****************************************************************************
+ * Header Files
+ ****************************************************************************/
+#include "config/aom_scale_rtcd.h"
+
+#include "aom_mem/aom_mem.h"
+#include "aom_scale/aom_scale.h"
+#include "aom_scale/yv12config.h"
+
+typedef struct {
+ int expanded_frame_width;
+ int expanded_frame_height;
+
+ int HScale;
+ int HRatio;
+ int VScale;
+ int VRatio;
+
+ YV12_BUFFER_CONFIG *src_yuv_config;
+ YV12_BUFFER_CONFIG *dst_yuv_config;
+
+} SCALE_VARS;
+
+/****************************************************************************
+ *
+ * ROUTINE : scale1d_2t1_i
+ *
+ * INPUTS : const unsigned char *source : Pointer to data to be scaled.
+ * int source_step : Number of pixels to step on
+ * in source.
+ * unsigned int source_scale : Scale for source (UNUSED).
+ * unsigned int source_length : Length of source (UNUSED).
+ * unsigned char *dest : Pointer to output data array.
+ * int dest_step : Number of pixels to step on
+ * in destination.
+ * unsigned int dest_scale : Scale for destination
+ * (UNUSED).
+ * unsigned int dest_length : Length of destination.
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Performs 2-to-1 interpolated scaling.
+ *
+ * SPECIAL NOTES : None.
+ *
+ ****************************************************************************/
+static void scale1d_2t1_i(const unsigned char *source, int source_step,
+ unsigned int source_scale, unsigned int source_length,
+ unsigned char *dest, int dest_step,
+ unsigned int dest_scale, unsigned int dest_length) {
+ const unsigned char *const dest_end = dest + dest_length * dest_step;
+ (void)source_length;
+ (void)source_scale;
+ (void)dest_scale;
+
+ source_step *= 2; // Every other row.
+
+ dest[0] = source[0]; // Special case: 1st pixel.
+ source += source_step;
+ dest += dest_step;
+
+ while (dest < dest_end) {
+ const unsigned int a = 3 * source[-source_step];
+ const unsigned int b = 10 * source[0];
+ const unsigned int c = 3 * source[source_step];
+ *dest = (unsigned char)((8 + a + b + c) >> 4);
+ source += source_step;
+ dest += dest_step;
+ }
+}
+
+/****************************************************************************
+ *
+ * ROUTINE : scale1d_2t1_ps
+ *
+ * INPUTS : const unsigned char *source : Pointer to data to be scaled.
+ * int source_step : Number of pixels to step on
+ * in source.
+ * unsigned int source_scale : Scale for source (UNUSED).
+ * unsigned int source_length : Length of source (UNUSED).
+ * unsigned char *dest : Pointer to output data array.
+ * int dest_step : Number of pixels to step on
+ * in destination.
+ * unsigned int dest_scale : Scale for destination
+ * (UNUSED).
+ * unsigned int dest_length : Length of destination.
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Performs 2-to-1 point subsampled scaling.
+ *
+ * SPECIAL NOTES : None.
+ *
+ ****************************************************************************/
+static void scale1d_2t1_ps(const unsigned char *source, int source_step,
+ unsigned int source_scale,
+ unsigned int source_length, unsigned char *dest,
+ int dest_step, unsigned int dest_scale,
+ unsigned int dest_length) {
+ const unsigned char *const dest_end = dest + dest_length * dest_step;
+ (void)source_length;
+ (void)source_scale;
+ (void)dest_scale;
+
+ source_step *= 2; // Every other row.
+
+ while (dest < dest_end) {
+ *dest = *source;
+ source += source_step;
+ dest += dest_step;
+ }
+}
+/****************************************************************************
+ *
+ * ROUTINE : scale1d_c
+ *
+ * INPUTS : const unsigned char *source : Pointer to data to be scaled.
+ * int source_step : Number of pixels to step on
+ * in source.
+ * unsigned int source_scale : Scale for source.
+ * unsigned int source_length : Length of source (UNUSED).
+ * unsigned char *dest : Pointer to output data array.
+ * int dest_step : Number of pixels to step on
+ * in destination.
+ * unsigned int dest_scale : Scale for destination.
+ * unsigned int dest_length : Length of destination.
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Performs linear interpolation in one dimension.
+ *
+ * SPECIAL NOTES : None.
+ *
+ ****************************************************************************/
+static void scale1d_c(const unsigned char *source, int source_step,
+ unsigned int source_scale, unsigned int source_length,
+ unsigned char *dest, int dest_step,
+ unsigned int dest_scale, unsigned int dest_length) {
+ const unsigned char *const dest_end = dest + dest_length * dest_step;
+ const unsigned int round_value = dest_scale / 2;
+ unsigned int left_modifier = dest_scale;
+ unsigned int right_modifier = 0;
+ unsigned char left_pixel = source[0];
+ unsigned char right_pixel = source[source_step];
+
+ (void)source_length;
+
+ /* These asserts are needed if there are boundary issues... */
+ /* assert ( dest_scale > source_scale );*/
+ /* assert ( (source_length - 1) * dest_scale >= (dest_length - 1) *
+ * source_scale);*/
+
+ while (dest < dest_end) {
+ *dest = (unsigned char)((left_modifier * left_pixel +
+ right_modifier * right_pixel + round_value) /
+ dest_scale);
+
+ right_modifier += source_scale;
+
+ while (right_modifier > dest_scale) {
+ right_modifier -= dest_scale;
+ source += source_step;
+ left_pixel = source[0];
+ right_pixel = source[source_step];
+ }
+
+ left_modifier = dest_scale - right_modifier;
+ }
+}
+
+/****************************************************************************
+ *
+ * ROUTINE : Scale2D
+ *
+ * INPUTS : const unsigned char *source : Pointer to data to be
+ * scaled.
+ * int source_pitch : Stride of source image.
+ * unsigned int source_width : Width of input image.
+ * unsigned int source_height : Height of input image.
+ * unsigned char *dest : Pointer to output data
+ * array.
+ * int dest_pitch : Stride of destination
+ * image.
+ * unsigned int dest_width : Width of destination image.
+ * unsigned int dest_height : Height of destination
+ * image.
+ * unsigned char *temp_area : Pointer to temp work area.
+ * unsigned char temp_area_height : Height of temp work area.
+ * unsigned int hscale : Horizontal scale factor
+ * numerator.
+ * unsigned int hratio : Horizontal scale factor
+ * denominator.
+ * unsigned int vscale : Vertical scale factor
+ * numerator.
+ * unsigned int vratio : Vertical scale factor
+ * denominator.
+ * unsigned int interlaced : Interlace flag.
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Performs 2-tap linear interpolation in two dimensions.
+ *
+ * SPECIAL NOTES : Expansion is performed one band at a time to help with
+ * caching.
+ *
+ ****************************************************************************/
+static void Scale2D(
+ /*const*/
+ unsigned char *source, int source_pitch, unsigned int source_width,
+ unsigned int source_height, unsigned char *dest, int dest_pitch,
+ unsigned int dest_width, unsigned int dest_height, unsigned char *temp_area,
+ unsigned char temp_area_height, unsigned int hscale, unsigned int hratio,
+ unsigned int vscale, unsigned int vratio, unsigned int interlaced) {
+ unsigned int i, j, k;
+ unsigned int bands;
+ unsigned int dest_band_height;
+ unsigned int source_band_height;
+
+ typedef void (*Scale1D)(const unsigned char *source, int source_step,
+ unsigned int source_scale, unsigned int source_length,
+ unsigned char *dest, int dest_step,
+ unsigned int dest_scale, unsigned int dest_length);
+
+ Scale1D Scale1Dv = scale1d_c;
+ Scale1D Scale1Dh = scale1d_c;
+
+ void (*horiz_line_scale)(const unsigned char *, unsigned int, unsigned char *,
+ unsigned int) = NULL;
+ void (*vert_band_scale)(unsigned char *, int, unsigned char *, int,
+ unsigned int) = NULL;
+
+ int ratio_scalable = 1;
+ int interpolation = 0;
+
+ unsigned char *source_base;
+ unsigned char *line_src;
+
+ source_base = (unsigned char *)source;
+
+ if (source_pitch < 0) {
+ int offset;
+
+ offset = (source_height - 1);
+ offset *= source_pitch;
+
+ source_base += offset;
+ }
+
+ /* find out the ratio for each direction */
+ switch (hratio * 10 / hscale) {
+ case 8:
+ /* 4-5 Scale in Width direction */
+ horiz_line_scale = aom_horizontal_line_5_4_scale;
+ break;
+ case 6:
+ /* 3-5 Scale in Width direction */
+ horiz_line_scale = aom_horizontal_line_5_3_scale;
+ break;
+ case 5:
+ /* 1-2 Scale in Width direction */
+ horiz_line_scale = aom_horizontal_line_2_1_scale;
+ break;
+ default:
+ /* The ratio is not acceptable now */
+ /* throw("The ratio is not acceptable for now!"); */
+ ratio_scalable = 0;
+ break;
+ }
+
+ switch (vratio * 10 / vscale) {
+ case 8:
+ /* 4-5 Scale in vertical direction */
+ vert_band_scale = aom_vertical_band_5_4_scale;
+ source_band_height = 5;
+ dest_band_height = 4;
+ break;
+ case 6:
+ /* 3-5 Scale in vertical direction */
+ vert_band_scale = aom_vertical_band_5_3_scale;
+ source_band_height = 5;
+ dest_band_height = 3;
+ break;
+ case 5:
+ /* 1-2 Scale in vertical direction */
+
+ if (interlaced) {
+ /* if the content is interlaced, point sampling is used */
+ vert_band_scale = aom_vertical_band_2_1_scale;
+ } else {
+ interpolation = 1;
+ /* if the content is progressive, interplo */
+ vert_band_scale = aom_vertical_band_2_1_scale_i;
+ }
+
+ source_band_height = 2;
+ dest_band_height = 1;
+ break;
+ default:
+ /* The ratio is not acceptable now */
+ /* throw("The ratio is not acceptable for now!"); */
+ ratio_scalable = 0;
+ break;
+ }
+
+ if (ratio_scalable) {
+ if (source_height == dest_height) {
+ /* for each band of the image */
+ for (k = 0; k < dest_height; ++k) {
+ horiz_line_scale(source, source_width, dest, dest_width);
+ source += source_pitch;
+ dest += dest_pitch;
+ }
+
+ return;
+ }
+
+ if (interpolation) {
+ if (source < source_base) source = source_base;
+
+ horiz_line_scale(source, source_width, temp_area, dest_width);
+ }
+
+ for (k = 0; k < (dest_height + dest_band_height - 1) / dest_band_height;
+ ++k) {
+ /* scale one band horizontally */
+ for (i = 0; i < source_band_height; ++i) {
+ /* Trap case where we could read off the base of the source buffer */
+
+ line_src = source + i * source_pitch;
+
+ if (line_src < source_base) line_src = source_base;
+
+ horiz_line_scale(line_src, source_width,
+ temp_area + (i + 1) * dest_pitch, dest_width);
+ }
+
+ /* Vertical scaling is in place */
+ vert_band_scale(temp_area + dest_pitch, dest_pitch, dest, dest_pitch,
+ dest_width);
+
+ if (interpolation)
+ memcpy(temp_area, temp_area + source_band_height * dest_pitch,
+ dest_width);
+
+ /* Next band... */
+ source += (unsigned long)source_band_height * source_pitch;
+ dest += (unsigned long)dest_band_height * dest_pitch;
+ }
+
+ return;
+ }
+
+ if (hscale == 2 && hratio == 1) Scale1Dh = scale1d_2t1_ps;
+
+ if (vscale == 2 && vratio == 1) {
+ if (interlaced)
+ Scale1Dv = scale1d_2t1_ps;
+ else
+ Scale1Dv = scale1d_2t1_i;
+ }
+
+ if (source_height == dest_height) {
+ /* for each band of the image */
+ for (k = 0; k < dest_height; ++k) {
+ Scale1Dh(source, 1, hscale, source_width + 1, dest, 1, hratio,
+ dest_width);
+ source += source_pitch;
+ dest += dest_pitch;
+ }
+
+ return;
+ }
+
+ if (dest_height > source_height) {
+ dest_band_height = temp_area_height - 1;
+ source_band_height = dest_band_height * source_height / dest_height;
+ } else {
+ source_band_height = temp_area_height - 1;
+ dest_band_height = source_band_height * vratio / vscale;
+ }
+
+ /* first row needs to be done so that we can stay one row ahead for vertical
+ * zoom */
+ Scale1Dh(source, 1, hscale, source_width + 1, temp_area, 1, hratio,
+ dest_width);
+
+ /* for each band of the image */
+ bands = (dest_height + dest_band_height - 1) / dest_band_height;
+
+ for (k = 0; k < bands; ++k) {
+ /* scale one band horizontally */
+ for (i = 1; i < source_band_height + 1; ++i) {
+ if (k * source_band_height + i < source_height) {
+ Scale1Dh(source + i * source_pitch, 1, hscale, source_width + 1,
+ temp_area + i * dest_pitch, 1, hratio, dest_width);
+ } else { /* Duplicate the last row */
+ /* copy temp_area row 0 over from last row in the past */
+ memcpy(temp_area + i * dest_pitch, temp_area + (i - 1) * dest_pitch,
+ dest_pitch);
+ }
+ }
+
+ /* scale one band vertically */
+ for (j = 0; j < dest_width; ++j) {
+ Scale1Dv(&temp_area[j], dest_pitch, vscale, source_band_height + 1,
+ &dest[j], dest_pitch, vratio, dest_band_height);
+ }
+
+ /* copy temp_area row 0 over from last row in the past */
+ memcpy(temp_area, temp_area + source_band_height * dest_pitch, dest_pitch);
+
+ /* move to the next band */
+ source += source_band_height * source_pitch;
+ dest += dest_band_height * dest_pitch;
+ }
+}
+
+/****************************************************************************
+ *
+ * ROUTINE : aom_scale_frame
+ *
+ * INPUTS : YV12_BUFFER_CONFIG *src : Pointer to frame to be
+ * scaled.
+ * YV12_BUFFER_CONFIG *dst : Pointer to buffer to hold
+ * scaled frame.
+ * unsigned char *temp_area : Pointer to temp work area.
+ * unsigned char temp_area_height : Height of temp work area.
+ * unsigned int hscale : Horizontal scale factor
+ * numerator.
+ * unsigned int hratio : Horizontal scale factor
+ * denominator.
+ * unsigned int vscale : Vertical scale factor
+ * numerator.
+ * unsigned int vratio : Vertical scale factor
+ * denominator.
+ * unsigned int interlaced : Interlace flag.
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Performs 2-tap linear interpolation in two dimensions.
+ *
+ * SPECIAL NOTES : Expansion is performed one band at a time to help with
+ * caching.
+ *
+ ****************************************************************************/
+void aom_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
+ unsigned char *temp_area, unsigned char temp_height,
+ unsigned int hscale, unsigned int hratio,
+ unsigned int vscale, unsigned int vratio,
+ unsigned int interlaced, const int num_planes) {
+ const int dw = (hscale - 1 + src->y_width * hratio) / hscale;
+ const int dh = (vscale - 1 + src->y_height * vratio) / vscale;
+
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const int is_uv = plane > 0;
+ const int plane_dw = dw >> is_uv;
+ const int plane_dh = dh >> is_uv;
+
+ Scale2D((unsigned char *)src->buffers[plane], src->strides[is_uv],
+ src->widths[is_uv], src->heights[is_uv],
+ (unsigned char *)dst->buffers[plane], dst->strides[is_uv], plane_dw,
+ plane_dh, temp_area, temp_height, hscale, hratio, vscale, vratio,
+ interlaced);
+
+ if (plane_dw < dst->widths[is_uv])
+ for (int i = 0; i < plane_dh; ++i)
+ memset(dst->buffers[plane] + i * dst->strides[is_uv] + plane_dw - 1,
+ dst->buffers[plane][i * dst->strides[is_uv] + plane_dw - 2],
+ dst->widths[is_uv] - plane_dw + 1);
+
+ if (plane_dh < dst->heights[is_uv])
+ for (int i = plane_dh - 1; i < dst->heights[is_uv]; ++i)
+ memcpy(dst->buffers[plane] + i * dst->strides[is_uv],
+ dst->buffers[plane] + (plane_dh - 2) * dst->strides[is_uv],
+ dst->widths[is_uv] + 1);
+ }
+}
diff --git a/third_party/aom/aom_scale/generic/gen_scalers.c b/third_party/aom/aom_scale/generic/gen_scalers.c
new file mode 100644
index 0000000000..549e2aa690
--- /dev/null
+++ b/third_party/aom/aom_scale/generic/gen_scalers.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+#include "config/aom_scale_rtcd.h"
+
+#include "aom_scale/aom_scale.h"
+#include "aom_mem/aom_mem.h"
+/****************************************************************************
+ * Imports
+ ****************************************************************************/
+
+/****************************************************************************
+ *
+ *
+ * INPUTS : const unsigned char *source : Pointer to source data.
+ * unsigned int source_width : Stride of source.
+ * unsigned char *dest : Pointer to destination data.
+ * unsigned int dest_width : Stride of destination
+ * (NOT USED).
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Copies horizontal line of pixels from source to
+ * destination scaling up by 4 to 5.
+ *
+ * SPECIAL NOTES : None.
+ *
+ ****************************************************************************/
+void aom_horizontal_line_5_4_scale_c(const unsigned char *source,
+ unsigned int source_width,
+ unsigned char *dest,
+ unsigned int dest_width) {
+ const unsigned char *const source_end = source + source_width;
+ (void)dest_width;
+
+ while (source < source_end) {
+ const unsigned int a = source[0];
+ const unsigned int b = source[1];
+ const unsigned int c = source[2];
+ const unsigned int d = source[3];
+ const unsigned int e = source[4];
+
+ dest[0] = (unsigned char)a;
+ dest[1] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
+ dest[2] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
+ dest[3] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
+
+ source += 5;
+ dest += 4;
+ }
+}
+
+void aom_vertical_band_5_4_scale_c(unsigned char *source, int src_pitch,
+ unsigned char *dest, int dest_pitch,
+ unsigned int dest_width) {
+ const unsigned char *const dest_end = dest + dest_width;
+ while (dest < dest_end) {
+ const unsigned int a = source[0 * src_pitch];
+ const unsigned int b = source[1 * src_pitch];
+ const unsigned int c = source[2 * src_pitch];
+ const unsigned int d = source[3 * src_pitch];
+ const unsigned int e = source[4 * src_pitch];
+
+ dest[0 * dest_pitch] = (unsigned char)a;
+ dest[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
+ dest[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
+ dest[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
+
+ ++source;
+ ++dest;
+ }
+}
+
+/*7***************************************************************************
+ *
+ * ROUTINE : aom_horizontal_line_3_5_scale_c
+ *
+ * INPUTS : const unsigned char *source : Pointer to source data.
+ * unsigned int source_width : Stride of source.
+ * unsigned char *dest : Pointer to destination data.
+ * unsigned int dest_width : Stride of destination
+ * (NOT USED).
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Copies horizontal line of pixels from source to
+ * destination scaling up by 3 to 5.
+ *
+ * SPECIAL NOTES : None.
+ *
+ *
+ ****************************************************************************/
+void aom_horizontal_line_5_3_scale_c(const unsigned char *source,
+ unsigned int source_width,
+ unsigned char *dest,
+ unsigned int dest_width) {
+ const unsigned char *const source_end = source + source_width;
+ (void)dest_width;
+ while (source < source_end) {
+ const unsigned int a = source[0];
+ const unsigned int b = source[1];
+ const unsigned int c = source[2];
+ const unsigned int d = source[3];
+ const unsigned int e = source[4];
+
+ dest[0] = (unsigned char)a;
+ dest[1] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
+ dest[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
+
+ source += 5;
+ dest += 3;
+ }
+}
+
+void aom_vertical_band_5_3_scale_c(unsigned char *source, int src_pitch,
+ unsigned char *dest, int dest_pitch,
+ unsigned int dest_width) {
+ const unsigned char *const dest_end = dest + dest_width;
+ while (dest < dest_end) {
+ const unsigned int a = source[0 * src_pitch];
+ const unsigned int b = source[1 * src_pitch];
+ const unsigned int c = source[2 * src_pitch];
+ const unsigned int d = source[3 * src_pitch];
+ const unsigned int e = source[4 * src_pitch];
+
+ dest[0 * dest_pitch] = (unsigned char)a;
+ dest[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
+ dest[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
+
+ ++source;
+ ++dest;
+ }
+}
+
+/****************************************************************************
+ *
+ * ROUTINE : aom_horizontal_line_1_2_scale_c
+ *
+ * INPUTS : const unsigned char *source : Pointer to source data.
+ * unsigned int source_width : Stride of source.
+ * unsigned char *dest : Pointer to destination data.
+ * unsigned int dest_width : Stride of destination
+ * (NOT USED).
+ *
+ * OUTPUTS : None.
+ *
+ * RETURNS : void
+ *
+ * FUNCTION : Copies horizontal line of pixels from source to
+ * destination scaling up by 1 to 2.
+ *
+ * SPECIAL NOTES : None.
+ *
+ ****************************************************************************/
+void aom_horizontal_line_2_1_scale_c(const unsigned char *source,
+ unsigned int source_width,
+ unsigned char *dest,
+ unsigned int dest_width) {
+ const unsigned char *const source_end = source + source_width;
+ (void)dest_width;
+ while (source < source_end) {
+ dest[0] = source[0];
+ source += 2;
+ ++dest;
+ }
+}
+
+void aom_vertical_band_2_1_scale_c(unsigned char *source, int src_pitch,
+ unsigned char *dest, int dest_pitch,
+ unsigned int dest_width) {
+ (void)dest_pitch;
+ (void)src_pitch;
+ memcpy(dest, source, dest_width);
+}
+
+void aom_vertical_band_2_1_scale_i_c(unsigned char *source, int src_pitch,
+ unsigned char *dest, int dest_pitch,
+ unsigned int dest_width) {
+ const unsigned char *const dest_end = dest + dest_width;
+ (void)dest_pitch;
+ while (dest < dest_end) {
+ const unsigned int a = source[-src_pitch] * 3;
+ const unsigned int b = source[0] * 10;
+ const unsigned int c = source[src_pitch] * 3;
+ dest[0] = (unsigned char)((8 + a + b + c) >> 4);
+ ++source;
+ ++dest;
+ }
+}
diff --git a/third_party/aom/aom_scale/generic/yv12config.c b/third_party/aom/aom_scale/generic/yv12config.c
new file mode 100644
index 0000000000..94b400b9e0
--- /dev/null
+++ b/third_party/aom/aom_scale/generic/yv12config.c
@@ -0,0 +1,312 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+#include <assert.h>
+
+#include "aom/internal/aom_image_internal.h"
+#include "aom_dsp/pyramid.h"
+#include "aom_dsp/flow_estimation/corner_detect.h"
+#include "aom_mem/aom_mem.h"
+#include "aom_ports/mem.h"
+#include "aom_scale/yv12config.h"
+#include "av1/common/enums.h"
+
+/****************************************************************************
+ * Exports
+ ****************************************************************************/
+
+/****************************************************************************
+ *
+ ****************************************************************************/
+
+// TODO(jkoleszar): Maybe replace this with struct aom_image
+int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf) {
+ if (ybf) {
+ if (ybf->buffer_alloc_sz > 0) {
+ aom_free(ybf->buffer_alloc);
+ }
+#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+ if (ybf->y_pyramid) {
+ aom_free_pyramid(ybf->y_pyramid);
+ }
+ if (ybf->corners) {
+ av1_free_corner_list(ybf->corners);
+ }
+#endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+ aom_remove_metadata_from_frame_buffer(ybf);
+ /* buffer_alloc isn't accessed by most functions. Rather y_buffer,
+ u_buffer and v_buffer point to buffer_alloc and are used. Clear out
+ all of this so that a freed pointer isn't inadvertently used */
+ memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG));
+ return 0;
+ }
+
+ return AOM_CODEC_MEM_ERROR;
+}
+
+static int realloc_frame_buffer_aligned(
+ YV12_BUFFER_CONFIG *ybf, int width, int height, int ss_x, int ss_y,
+ int use_highbitdepth, int border, int byte_alignment,
+ aom_codec_frame_buffer_t *fb, aom_get_frame_buffer_cb_fn_t cb,
+ void *cb_priv, const int y_stride, const uint64_t yplane_size,
+ const uint64_t uvplane_size, const int aligned_width,
+ const int aligned_height, const int uv_width, const int uv_height,
+ const int uv_stride, const int uv_border_w, const int uv_border_h,
+ int num_pyramid_levels, int alloc_y_plane_only) {
+ if (ybf) {
+ const int aom_byte_align = (byte_alignment == 0) ? 1 : byte_alignment;
+ const uint64_t frame_size =
+ (1 + use_highbitdepth) * (yplane_size + 2 * uvplane_size);
+
+ uint8_t *buf = NULL;
+
+#if CONFIG_REALTIME_ONLY || !CONFIG_AV1_ENCODER
+ // We should only need an 8-bit version of the source frame if we are
+ // encoding in non-realtime mode
+ (void)num_pyramid_levels;
+ assert(num_pyramid_levels == 0);
+#endif // CONFIG_REALTIME_ONLY || !CONFIG_AV1_ENCODER
+
+#if defined AOM_MAX_ALLOCABLE_MEMORY
+ // The size of ybf->buffer_alloc.
+ uint64_t alloc_size = frame_size;
+#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+ // The size of ybf->y_pyramid
+ if (num_pyramid_levels > 0) {
+ alloc_size += aom_get_pyramid_alloc_size(
+ width, height, num_pyramid_levels, use_highbitdepth);
+ alloc_size += av1_get_corner_list_size();
+ }
+#endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+ // The decoder may allocate REF_FRAMES frame buffers in the frame buffer
+ // pool. Bound the total amount of allocated memory as if these REF_FRAMES
+ // frame buffers were allocated in a single allocation.
+ if (alloc_size > AOM_MAX_ALLOCABLE_MEMORY / REF_FRAMES)
+ return AOM_CODEC_MEM_ERROR;
+#endif
+
+ if (cb != NULL) {
+ const int align_addr_extra_size = 31;
+ const uint64_t external_frame_size = frame_size + align_addr_extra_size;
+
+ assert(fb != NULL);
+
+ if (external_frame_size != (size_t)external_frame_size)
+ return AOM_CODEC_MEM_ERROR;
+
+ // Allocation to hold larger frame, or first allocation.
+ if (cb(cb_priv, (size_t)external_frame_size, fb) < 0)
+ return AOM_CODEC_MEM_ERROR;
+
+ if (fb->data == NULL || fb->size < external_frame_size)
+ return AOM_CODEC_MEM_ERROR;
+
+ ybf->buffer_alloc = (uint8_t *)aom_align_addr(fb->data, 32);
+
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+ // This memset is needed for fixing the issue of using uninitialized
+ // value in msan test. It will cause a perf loss, so only do this for
+ // msan test.
+ memset(ybf->buffer_alloc, 0, (size_t)frame_size);
+#endif
+#endif
+ } else if (frame_size > ybf->buffer_alloc_sz) {
+ // Allocation to hold larger frame, or first allocation.
+ aom_free(ybf->buffer_alloc);
+ ybf->buffer_alloc = NULL;
+ ybf->buffer_alloc_sz = 0;
+
+ if (frame_size != (size_t)frame_size) return AOM_CODEC_MEM_ERROR;
+
+ ybf->buffer_alloc = (uint8_t *)aom_memalign(32, (size_t)frame_size);
+ if (!ybf->buffer_alloc) return AOM_CODEC_MEM_ERROR;
+
+ ybf->buffer_alloc_sz = (size_t)frame_size;
+
+ // This memset is needed for fixing valgrind error from C loop filter
+ // due to access uninitialized memory in frame border. It could be
+ // removed if border is totally removed.
+ memset(ybf->buffer_alloc, 0, ybf->buffer_alloc_sz);
+ }
+
+ ybf->y_crop_width = width;
+ ybf->y_crop_height = height;
+ ybf->y_width = aligned_width;
+ ybf->y_height = aligned_height;
+ ybf->y_stride = y_stride;
+
+ ybf->uv_crop_width = (width + ss_x) >> ss_x;
+ ybf->uv_crop_height = (height + ss_y) >> ss_y;
+ ybf->uv_width = uv_width;
+ ybf->uv_height = uv_height;
+ ybf->uv_stride = uv_stride;
+
+ ybf->border = border;
+ ybf->frame_size = (size_t)frame_size;
+ ybf->subsampling_x = ss_x;
+ ybf->subsampling_y = ss_y;
+
+ buf = ybf->buffer_alloc;
+ if (use_highbitdepth) {
+ // Store uint16 addresses when using 16bit framebuffers
+ buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
+ ybf->flags = YV12_FLAG_HIGHBITDEPTH;
+ } else {
+ ybf->flags = 0;
+ }
+
+ ybf->y_buffer = (uint8_t *)aom_align_addr(
+ buf + (border * y_stride) + border, aom_byte_align);
+ if (!alloc_y_plane_only) {
+ ybf->u_buffer = (uint8_t *)aom_align_addr(
+ buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w,
+ aom_byte_align);
+ ybf->v_buffer =
+ (uint8_t *)aom_align_addr(buf + yplane_size + uvplane_size +
+ (uv_border_h * uv_stride) + uv_border_w,
+ aom_byte_align);
+ } else {
+ ybf->u_buffer = NULL;
+ ybf->v_buffer = NULL;
+ }
+
+ ybf->use_external_reference_buffers = 0;
+
+#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+ if (ybf->y_pyramid) {
+ aom_free_pyramid(ybf->y_pyramid);
+ ybf->y_pyramid = NULL;
+ }
+ if (ybf->corners) {
+ av1_free_corner_list(ybf->corners);
+ ybf->corners = NULL;
+ }
+ if (num_pyramid_levels > 0) {
+ ybf->y_pyramid = aom_alloc_pyramid(width, height, num_pyramid_levels,
+ use_highbitdepth);
+ if (!ybf->y_pyramid) return AOM_CODEC_MEM_ERROR;
+ ybf->corners = av1_alloc_corner_list();
+ if (!ybf->corners) return AOM_CODEC_MEM_ERROR;
+ }
+#endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+
+ ybf->corrupted = 0; /* assume not corrupted by errors */
+ return 0;
+ }
+ return AOM_CODEC_MEM_ERROR;
+}
+
+static int calc_stride_and_planesize(
+ const int ss_x, const int ss_y, const int aligned_width,
+ const int aligned_height, const int border, const int byte_alignment,
+ int alloc_y_plane_only, int *y_stride, int *uv_stride,
+ uint64_t *yplane_size, uint64_t *uvplane_size, const int uv_height) {
+ /* Only support allocating buffers that have a border that's a multiple
+ * of 32. The border restriction is required to get 16-byte alignment of
+ * the start of the chroma rows without introducing an arbitrary gap
+ * between planes, which would break the semantics of things like
+ * aom_img_set_rect(). */
+ if (border & 0x1f) return AOM_CODEC_MEM_ERROR;
+ *y_stride = aom_calc_y_stride(aligned_width, border);
+ *yplane_size =
+ (aligned_height + 2 * border) * (uint64_t)(*y_stride) + byte_alignment;
+
+ if (!alloc_y_plane_only) {
+ *uv_stride = *y_stride >> ss_x;
+ *uvplane_size =
+ (uv_height + 2 * (border >> ss_y)) * (uint64_t)(*uv_stride) +
+ byte_alignment;
+ } else {
+ *uv_stride = 0;
+ *uvplane_size = 0;
+ }
+ return 0;
+}
+
+int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
+ int ss_x, int ss_y, int use_highbitdepth,
+ int border, int byte_alignment,
+ aom_codec_frame_buffer_t *fb,
+ aom_get_frame_buffer_cb_fn_t cb, void *cb_priv,
+ int num_pyramid_levels, int alloc_y_plane_only) {
+#if CONFIG_SIZE_LIMIT
+ if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT)
+ return AOM_CODEC_MEM_ERROR;
+#endif
+
+ if (ybf) {
+ int y_stride = 0;
+ int uv_stride = 0;
+ uint64_t yplane_size = 0;
+ uint64_t uvplane_size = 0;
+ const int aligned_width = (width + 7) & ~7;
+ const int aligned_height = (height + 7) & ~7;
+ const int uv_width = aligned_width >> ss_x;
+ const int uv_height = aligned_height >> ss_y;
+ const int uv_border_w = border >> ss_x;
+ const int uv_border_h = border >> ss_y;
+
+ int error = calc_stride_and_planesize(
+ ss_x, ss_y, aligned_width, aligned_height, border, byte_alignment,
+ alloc_y_plane_only, &y_stride, &uv_stride, &yplane_size, &uvplane_size,
+ uv_height);
+ if (error) return error;
+ return realloc_frame_buffer_aligned(
+ ybf, width, height, ss_x, ss_y, use_highbitdepth, border,
+ byte_alignment, fb, cb, cb_priv, y_stride, yplane_size, uvplane_size,
+ aligned_width, aligned_height, uv_width, uv_height, uv_stride,
+ uv_border_w, uv_border_h, num_pyramid_levels, alloc_y_plane_only);
+ }
+ return AOM_CODEC_MEM_ERROR;
+}
+
+int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
+ int ss_x, int ss_y, int use_highbitdepth, int border,
+ int byte_alignment, int num_pyramid_levels,
+ int alloc_y_plane_only) {
+ if (ybf) {
+ aom_free_frame_buffer(ybf);
+ return aom_realloc_frame_buffer(ybf, width, height, ss_x, ss_y,
+ use_highbitdepth, border, byte_alignment,
+ NULL, NULL, NULL, num_pyramid_levels,
+ alloc_y_plane_only);
+ }
+ return AOM_CODEC_MEM_ERROR;
+}
+
+void aom_remove_metadata_from_frame_buffer(YV12_BUFFER_CONFIG *ybf) {
+ if (ybf && ybf->metadata) {
+ aom_img_metadata_array_free(ybf->metadata);
+ ybf->metadata = NULL;
+ }
+}
+
+int aom_copy_metadata_to_frame_buffer(YV12_BUFFER_CONFIG *ybf,
+ const aom_metadata_array_t *arr) {
+ if (!ybf || !arr || !arr->metadata_array) return -1;
+ if (ybf->metadata == arr) return 0;
+ aom_remove_metadata_from_frame_buffer(ybf);
+ ybf->metadata = aom_img_metadata_array_alloc(arr->sz);
+ if (!ybf->metadata) return -1;
+ for (size_t i = 0; i < ybf->metadata->sz; i++) {
+ ybf->metadata->metadata_array[i] = aom_img_metadata_alloc(
+ arr->metadata_array[i]->type, arr->metadata_array[i]->payload,
+ arr->metadata_array[i]->sz, arr->metadata_array[i]->insert_flag);
+ if (ybf->metadata->metadata_array[i] == NULL) {
+ aom_img_metadata_array_free(ybf->metadata);
+ ybf->metadata = NULL;
+ return -1;
+ }
+ }
+ ybf->metadata->sz = arr->sz;
+ return 0;
+}
diff --git a/third_party/aom/aom_scale/generic/yv12extend.c b/third_party/aom/aom_scale/generic/yv12extend.c
new file mode 100644
index 0000000000..5546112d40
--- /dev/null
+++ b/third_party/aom/aom_scale/generic/yv12extend.c
@@ -0,0 +1,517 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+#include <assert.h>
+
+#include "config/aom_config.h"
+#include "config/aom_scale_rtcd.h"
+
+#include "aom/aom_integer.h"
+#include "aom_mem/aom_mem.h"
+#include "aom_ports/mem.h"
+#include "aom_scale/yv12config.h"
+
+static void extend_plane(uint8_t *const src, int src_stride, int width,
+ int height, int extend_top, int extend_left,
+ int extend_bottom, int extend_right, int v_start,
+ int v_end) {
+ assert(src != NULL);
+ int i;
+ const int linesize = extend_left + extend_right + width;
+ assert(linesize <= src_stride);
+
+ /* copy the left and right most columns out */
+ uint8_t *src_ptr1 = src + v_start * src_stride;
+ uint8_t *src_ptr2 = src + v_start * src_stride + width - 1;
+ uint8_t *dst_ptr1 = src + v_start * src_stride - extend_left;
+ uint8_t *dst_ptr2 = src_ptr2 + 1;
+
+ for (i = v_start; i < v_end; ++i) {
+ memset(dst_ptr1, src_ptr1[0], extend_left);
+ memset(dst_ptr2, src_ptr2[0], extend_right);
+ src_ptr1 += src_stride;
+ src_ptr2 += src_stride;
+ dst_ptr1 += src_stride;
+ dst_ptr2 += src_stride;
+ }
+
+ /* Now copy the top and bottom lines into each line of the respective
+ * borders
+ */
+ src_ptr1 = src - extend_left;
+ dst_ptr1 = src_ptr1 + src_stride * -extend_top;
+
+ for (i = 0; i < extend_top; ++i) {
+ memcpy(dst_ptr1, src_ptr1, linesize);
+ dst_ptr1 += src_stride;
+ }
+
+ src_ptr2 = src_ptr1 + src_stride * (height - 1);
+ dst_ptr2 = src_ptr2;
+
+ for (i = 0; i < extend_bottom; ++i) {
+ dst_ptr2 += src_stride;
+ memcpy(dst_ptr2, src_ptr2, linesize);
+ }
+}
+
+#if CONFIG_AV1_HIGHBITDEPTH
+static void extend_plane_high(uint8_t *const src8, int src_stride, int width,
+ int height, int extend_top, int extend_left,
+ int extend_bottom, int extend_right, int v_start,
+ int v_end) {
+ int i;
+ const int linesize = extend_left + extend_right + width;
+ assert(linesize <= src_stride);
+ uint16_t *src = CONVERT_TO_SHORTPTR(src8);
+
+ /* copy the left and right most columns out */
+ uint16_t *src_ptr1 = src + v_start * src_stride;
+ uint16_t *src_ptr2 = src + v_start * src_stride + width - 1;
+ uint16_t *dst_ptr1 = src + v_start * src_stride - extend_left;
+ uint16_t *dst_ptr2 = src_ptr2 + 1;
+
+ for (i = v_start; i < v_end; ++i) {
+ aom_memset16(dst_ptr1, src_ptr1[0], extend_left);
+ aom_memset16(dst_ptr2, src_ptr2[0], extend_right);
+ src_ptr1 += src_stride;
+ src_ptr2 += src_stride;
+ dst_ptr1 += src_stride;
+ dst_ptr2 += src_stride;
+ }
+
+ /* Now copy the top and bottom lines into each line of the respective
+ * borders
+ */
+ src_ptr1 = src - extend_left;
+ dst_ptr1 = src_ptr1 + src_stride * -extend_top;
+
+ for (i = 0; i < extend_top; ++i) {
+ memcpy(dst_ptr1, src_ptr1, linesize * sizeof(uint16_t));
+ dst_ptr1 += src_stride;
+ }
+
+ src_ptr2 = src_ptr1 + src_stride * (height - 1);
+ dst_ptr2 = src_ptr2;
+
+ for (i = 0; i < extend_bottom; ++i) {
+ dst_ptr2 += src_stride;
+ memcpy(dst_ptr2, src_ptr2, linesize * sizeof(uint16_t));
+ }
+}
+#endif // CONFIG_AV1_HIGHBITDEPTH
+
+void aom_extend_frame_borders_plane_row_c(const YV12_BUFFER_CONFIG *ybf,
+ int plane, int v_start, int v_end) {
+ const int ext_size = ybf->border;
+ const int ss_x = ybf->subsampling_x;
+ const int ss_y = ybf->subsampling_y;
+
+ assert(ybf->y_height - ybf->y_crop_height < 16);
+ assert(ybf->y_width - ybf->y_crop_width < 16);
+ assert(ybf->y_height - ybf->y_crop_height >= 0);
+ assert(ybf->y_width - ybf->y_crop_width >= 0);
+
+ const int is_uv = plane > 0;
+ const int top = ext_size >> (is_uv ? ss_y : 0);
+ const int left = ext_size >> (is_uv ? ss_x : 0);
+ const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
+ const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
+ const int extend_top_border = (v_start == 0);
+ const int extend_bottom_border = (v_end == ybf->crop_heights[is_uv]);
+
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
+ extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
+ ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
+ extend_top_border ? top : 0, left,
+ extend_bottom_border ? bottom : 0, right, v_start, v_end);
+ return;
+ }
+#endif
+
+ extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
+ ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
+ extend_top_border ? top : 0, left,
+ extend_bottom_border ? bottom : 0, right, v_start, v_end);
+}
+
+void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
+ const int num_planes) {
+ assert(ybf->border % 2 == 0);
+ assert(ybf->y_height - ybf->y_crop_height < 16);
+ assert(ybf->y_width - ybf->y_crop_width < 16);
+ assert(ybf->y_height - ybf->y_crop_height >= 0);
+ assert(ybf->y_width - ybf->y_crop_width >= 0);
+
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const int is_uv = plane > 0;
+ const int plane_border = ybf->border >> is_uv;
+ extend_plane_high(
+ ybf->buffers[plane], ybf->strides[is_uv], ybf->crop_widths[is_uv],
+ ybf->crop_heights[is_uv], plane_border, plane_border,
+ plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv],
+ plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv], 0,
+ ybf->crop_heights[is_uv]);
+ }
+ return;
+ }
+#endif
+
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const int is_uv = plane > 0;
+ const int plane_border = ybf->border >> is_uv;
+ extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
+ ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
+ plane_border, plane_border,
+ plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv],
+ plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv], 0,
+ ybf->crop_heights[is_uv]);
+ }
+}
+
+static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
+ const int num_planes) {
+ const int ss_x = ybf->subsampling_x;
+ const int ss_y = ybf->subsampling_y;
+
+ assert(ybf->y_height - ybf->y_crop_height < 16);
+ assert(ybf->y_width - ybf->y_crop_width < 16);
+ assert(ybf->y_height - ybf->y_crop_height >= 0);
+ assert(ybf->y_width - ybf->y_crop_width >= 0);
+
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const int is_uv = plane > 0;
+ const int top = ext_size >> (is_uv ? ss_y : 0);
+ const int left = ext_size >> (is_uv ? ss_x : 0);
+ const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
+ const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
+ extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
+ ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top,
+ left, bottom, right, 0, ybf->crop_heights[is_uv]);
+ }
+ return;
+ }
+#endif
+
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const int is_uv = plane > 0;
+ const int top = ext_size >> (is_uv ? ss_y : 0);
+ const int left = ext_size >> (is_uv ? ss_x : 0);
+ const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
+ const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
+ extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
+ ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top, left,
+ bottom, right, 0, ybf->crop_heights[is_uv]);
+ }
+}
+
+void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, const int num_planes) {
+ extend_frame(ybf, ybf->border, num_planes);
+}
+
+void aom_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf,
+ const int num_planes) {
+ const int inner_bw = (ybf->border > AOMINNERBORDERINPIXELS)
+ ? AOMINNERBORDERINPIXELS
+ : ybf->border;
+ extend_frame(ybf, inner_bw, num_planes);
+}
+
+void aom_extend_frame_borders_y_c(YV12_BUFFER_CONFIG *ybf) {
+ int ext_size = ybf->border;
+ assert(ybf->y_height - ybf->y_crop_height < 16);
+ assert(ybf->y_width - ybf->y_crop_width < 16);
+ assert(ybf->y_height - ybf->y_crop_height >= 0);
+ assert(ybf->y_width - ybf->y_crop_width >= 0);
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
+ extend_plane_high(
+ ybf->y_buffer, ybf->y_stride, ybf->y_crop_width, ybf->y_crop_height,
+ ext_size, ext_size, ext_size + ybf->y_height - ybf->y_crop_height,
+ ext_size + ybf->y_width - ybf->y_crop_width, 0, ybf->y_crop_height);
+ return;
+ }
+#endif
+ extend_plane(
+ ybf->y_buffer, ybf->y_stride, ybf->y_crop_width, ybf->y_crop_height,
+ ext_size, ext_size, ext_size + ybf->y_height - ybf->y_crop_height,
+ ext_size + ybf->y_width - ybf->y_crop_width, 0, ybf->y_crop_height);
+}
+
+#if CONFIG_AV1_HIGHBITDEPTH
+static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) {
+ uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
+ uint16_t *src = CONVERT_TO_SHORTPTR(src8);
+ memcpy(dst, src, num * sizeof(uint16_t));
+}
+#endif
+
+// Copies the source image into the destination image and updates the
+// destination's UMV borders.
+// Note: The frames are assumed to be identical in size.
+void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
+ YV12_BUFFER_CONFIG *dst_bc, const int num_planes) {
+ assert(src_bc->y_width == dst_bc->y_width);
+ assert(src_bc->y_height == dst_bc->y_height);
+
+#if CONFIG_AV1_HIGHBITDEPTH
+ assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) ==
+ (dst_bc->flags & YV12_FLAG_HIGHBITDEPTH));
+
+ if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const uint8_t *plane_src = src_bc->buffers[plane];
+ uint8_t *plane_dst = dst_bc->buffers[plane];
+ const int is_uv = plane > 0;
+
+ for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
+ memcpy_short_addr(plane_dst, plane_src, src_bc->widths[is_uv]);
+ plane_src += src_bc->strides[is_uv];
+ plane_dst += dst_bc->strides[is_uv];
+ }
+ }
+ aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
+ return;
+ }
+#endif
+ for (int plane = 0; plane < num_planes; ++plane) {
+ const uint8_t *plane_src = src_bc->buffers[plane];
+ uint8_t *plane_dst = dst_bc->buffers[plane];
+ const int is_uv = plane > 0;
+
+ for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
+ memcpy(plane_dst, plane_src, src_bc->widths[is_uv]);
+ plane_src += src_bc->strides[is_uv];
+ plane_dst += dst_bc->strides[is_uv];
+ }
+ }
+ aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
+}
+
+void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
+ YV12_BUFFER_CONFIG *dst_ybc) {
+ int row;
+ const uint8_t *src = src_ybc->y_buffer;
+ uint8_t *dst = dst_ybc->y_buffer;
+
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
+ uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
+ for (row = 0; row < src_ybc->y_height; ++row) {
+ memcpy(dst16, src16, src_ybc->y_width * sizeof(uint16_t));
+ src16 += src_ybc->y_stride;
+ dst16 += dst_ybc->y_stride;
+ }
+ return;
+ }
+#endif
+
+ for (row = 0; row < src_ybc->y_height; ++row) {
+ memcpy(dst, src, src_ybc->y_width);
+ src += src_ybc->y_stride;
+ dst += dst_ybc->y_stride;
+ }
+}
+
+void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
+ YV12_BUFFER_CONFIG *dst_bc) {
+ int row;
+ const uint8_t *src = src_bc->u_buffer;
+ uint8_t *dst = dst_bc->u_buffer;
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
+ uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
+ for (row = 0; row < src_bc->uv_height; ++row) {
+ memcpy(dst16, src16, src_bc->uv_width * sizeof(uint16_t));
+ src16 += src_bc->uv_stride;
+ dst16 += dst_bc->uv_stride;
+ }
+ return;
+ }
+#endif
+ for (row = 0; row < src_bc->uv_height; ++row) {
+ memcpy(dst, src, src_bc->uv_width);
+ src += src_bc->uv_stride;
+ dst += dst_bc->uv_stride;
+ }
+}
+
+void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
+ YV12_BUFFER_CONFIG *dst_bc) {
+ int row;
+ const uint8_t *src = src_bc->v_buffer;
+ uint8_t *dst = dst_bc->v_buffer;
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
+ uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
+ for (row = 0; row < src_bc->uv_height; ++row) {
+ memcpy(dst16, src16, src_bc->uv_width * sizeof(uint16_t));
+ src16 += src_bc->uv_stride;
+ dst16 += dst_bc->uv_stride;
+ }
+ return;
+ }
+#endif
+ for (row = 0; row < src_bc->uv_height; ++row) {
+ memcpy(dst, src, src_bc->uv_width);
+ src += src_bc->uv_stride;
+ dst += dst_bc->uv_stride;
+ }
+}
+
+void aom_yv12_partial_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, int hstart1,
+ int hend1, int vstart1, int vend1,
+ YV12_BUFFER_CONFIG *dst_ybc, int hstart2,
+ int vstart2) {
+ int row;
+ const uint8_t *src = src_ybc->y_buffer;
+ uint8_t *dst = dst_ybc->y_buffer;
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ const uint16_t *src16 =
+ CONVERT_TO_SHORTPTR(src + vstart1 * src_ybc->y_stride + hstart1);
+ uint16_t *dst16 =
+ CONVERT_TO_SHORTPTR(dst + vstart2 * dst_ybc->y_stride + hstart2);
+
+ for (row = vstart1; row < vend1; ++row) {
+ memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
+ src16 += src_ybc->y_stride;
+ dst16 += dst_ybc->y_stride;
+ }
+ return;
+ }
+#endif
+ src = (src + vstart1 * src_ybc->y_stride + hstart1);
+ dst = (dst + vstart2 * dst_ybc->y_stride + hstart2);
+
+ for (row = vstart1; row < vend1; ++row) {
+ memcpy(dst, src, (hend1 - hstart1));
+ src += src_ybc->y_stride;
+ dst += dst_ybc->y_stride;
+ }
+}
+
+void aom_yv12_partial_coloc_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
+ YV12_BUFFER_CONFIG *dst_ybc, int hstart,
+ int hend, int vstart, int vend) {
+ aom_yv12_partial_copy_y_c(src_ybc, hstart, hend, vstart, vend, dst_ybc,
+ hstart, vstart);
+}
+
+void aom_yv12_partial_copy_u_c(const YV12_BUFFER_CONFIG *src_bc, int hstart1,
+ int hend1, int vstart1, int vend1,
+ YV12_BUFFER_CONFIG *dst_bc, int hstart2,
+ int vstart2) {
+ int row;
+ const uint8_t *src = src_bc->u_buffer;
+ uint8_t *dst = dst_bc->u_buffer;
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ const uint16_t *src16 =
+ CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
+ uint16_t *dst16 =
+ CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
+ for (row = vstart1; row < vend1; ++row) {
+ memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
+ src16 += src_bc->uv_stride;
+ dst16 += dst_bc->uv_stride;
+ }
+ return;
+ }
+#endif
+ src = (src + vstart1 * src_bc->uv_stride + hstart1);
+ dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
+
+ for (row = vstart1; row < vend1; ++row) {
+ memcpy(dst, src, (hend1 - hstart1));
+ src += src_bc->uv_stride;
+ dst += dst_bc->uv_stride;
+ }
+}
+
+void aom_yv12_partial_coloc_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
+ YV12_BUFFER_CONFIG *dst_bc, int hstart,
+ int hend, int vstart, int vend) {
+ aom_yv12_partial_copy_u_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
+ vstart);
+}
+
+void aom_yv12_partial_copy_v_c(const YV12_BUFFER_CONFIG *src_bc, int hstart1,
+ int hend1, int vstart1, int vend1,
+ YV12_BUFFER_CONFIG *dst_bc, int hstart2,
+ int vstart2) {
+ int row;
+ const uint8_t *src = src_bc->v_buffer;
+ uint8_t *dst = dst_bc->v_buffer;
+#if CONFIG_AV1_HIGHBITDEPTH
+ if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
+ const uint16_t *src16 =
+ CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
+ uint16_t *dst16 =
+ CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
+ for (row = vstart1; row < vend1; ++row) {
+ memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
+ src16 += src_bc->uv_stride;
+ dst16 += dst_bc->uv_stride;
+ }
+ return;
+ }
+#endif
+ src = (src + vstart1 * src_bc->uv_stride + hstart1);
+ dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
+
+ for (row = vstart1; row < vend1; ++row) {
+ memcpy(dst, src, (hend1 - hstart1));
+ src += src_bc->uv_stride;
+ dst += dst_bc->uv_stride;
+ }
+}
+
+void aom_yv12_partial_coloc_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
+ YV12_BUFFER_CONFIG *dst_bc, int hstart,
+ int hend, int vstart, int vend) {
+ aom_yv12_partial_copy_v_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
+ vstart);
+}
+
+int aom_yv12_realloc_with_new_border_c(YV12_BUFFER_CONFIG *ybf, int new_border,
+ int byte_alignment,
+ int num_pyramid_levels, int num_planes) {
+ if (ybf) {
+ if (new_border == ybf->border) return 0;
+ YV12_BUFFER_CONFIG new_buf;
+ memset(&new_buf, 0, sizeof(new_buf));
+ const int error = aom_alloc_frame_buffer(
+ &new_buf, ybf->y_crop_width, ybf->y_crop_height, ybf->subsampling_x,
+ ybf->subsampling_y, ybf->flags & YV12_FLAG_HIGHBITDEPTH, new_border,
+ byte_alignment, num_pyramid_levels, 0);
+ if (error) return error;
+ // Copy image buffer
+ aom_yv12_copy_frame(ybf, &new_buf, num_planes);
+
+ // Extend up to new border
+ aom_extend_frame_borders(&new_buf, num_planes);
+
+ // Now free the old buffer and replace with the new
+ aom_free_frame_buffer(ybf);
+ memcpy(ybf, &new_buf, sizeof(new_buf));
+ return 0;
+ }
+ return -2;
+}
diff --git a/third_party/aom/aom_scale/yv12config.h b/third_party/aom/aom_scale/yv12config.h
new file mode 100644
index 0000000000..f192a3032e
--- /dev/null
+++ b/third_party/aom/aom_scale/yv12config.h
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+#ifndef AOM_AOM_SCALE_YV12CONFIG_H_
+#define AOM_AOM_SCALE_YV12CONFIG_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "config/aom_config.h"
+
+#include "aom/aom_codec.h"
+#include "aom/aom_frame_buffer.h"
+#include "aom/aom_integer.h"
+#include "aom/internal/aom_image_internal.h"
+
+/*!\cond */
+
+#define AOMINNERBORDERINPIXELS 160
+#define AOM_INTERP_EXTEND 4
+#define AOM_BORDER_IN_PIXELS 288
+#define AOM_ENC_NO_SCALE_BORDER 160
+#define AOM_ENC_ALLINTRA_BORDER 64
+#define AOM_DEC_BORDER_IN_PIXELS 64
+
+#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+struct image_pyramid;
+struct corner_list;
+#endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+
+/*!\endcond */
+/*!
+ * \brief YV12 frame buffer data structure
+ */
+typedef struct yv12_buffer_config {
+ /*!\cond */
+ union {
+ struct {
+ int y_width;
+ int uv_width;
+ };
+ int widths[2];
+ };
+ union {
+ struct {
+ int y_height;
+ int uv_height;
+ };
+ int heights[2];
+ };
+ union {
+ struct {
+ int y_crop_width;
+ int uv_crop_width;
+ };
+ int crop_widths[2];
+ };
+ union {
+ struct {
+ int y_crop_height;
+ int uv_crop_height;
+ };
+ int crop_heights[2];
+ };
+ union {
+ struct {
+ int y_stride;
+ int uv_stride;
+ };
+ int strides[2];
+ };
+ union {
+ struct {
+ uint8_t *y_buffer;
+ uint8_t *u_buffer;
+ uint8_t *v_buffer;
+ };
+ uint8_t *buffers[3];
+ };
+
+ // Indicate whether y_buffer, u_buffer, and v_buffer points to the internally
+ // allocated memory or external buffers.
+ int use_external_reference_buffers;
+ // This is needed to store y_buffer, u_buffer, and v_buffer when set reference
+ // uses an external refernece, and restore those buffer pointers after the
+ // external reference frame is no longer used.
+ uint8_t *store_buf_adr[3];
+
+ // Global motion search data
+#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+ // 8-bit downsampling pyramid for the Y plane
+ struct image_pyramid *y_pyramid;
+ struct corner_list *corners;
+#endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
+
+ uint8_t *buffer_alloc;
+ size_t buffer_alloc_sz;
+ int border;
+ size_t frame_size;
+ int subsampling_x;
+ int subsampling_y;
+ unsigned int bit_depth;
+ aom_color_primaries_t color_primaries;
+ aom_transfer_characteristics_t transfer_characteristics;
+ aom_matrix_coefficients_t matrix_coefficients;
+ uint8_t monochrome;
+ aom_chroma_sample_position_t chroma_sample_position;
+ aom_color_range_t color_range;
+ int render_width;
+ int render_height;
+
+ int corrupted;
+ int flags;
+ aom_metadata_array_t *metadata;
+ /*!\endcond */
+} YV12_BUFFER_CONFIG;
+
+/*!\cond */
+
+#define YV12_FLAG_HIGHBITDEPTH 8
+
+// Allocate a frame buffer
+//
+// If ybf currently contains an image, all associated memory will be freed and
+// then reallocated. In contrast, aom_realloc_frame_buffer() will reuse any
+// existing allocations where possible. So, if ybf is likely to already be
+// set up, please consider aom_realloc_frame_buffer() instead.
+//
+// See aom_realloc_frame_buffer() for the meanings of the arguments, and
+// available return values.
+int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
+ int ss_x, int ss_y, int use_highbitdepth, int border,
+ int byte_alignment, int num_pyramid_levels,
+ int alloc_y_plane_only);
+
+// Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
+// be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
+// NULL, then libaom is using the frame buffer callbacks to handle memory.
+// If cb is not NULL, libaom will call cb with minimum size in bytes needed
+// to decode the current frame. If cb is NULL, libaom will allocate memory
+// internally to decode the current frame.
+//
+// If num_pyramid_levels > 0, then an image pyramid will be allocated with
+// the specified number of levels.
+//
+// Any buffer which may become a source or ref frame buffer in the encoder
+// must have num_pyramid_levels = cpi->image_pyramid_levels. This will cause
+// an image pyramid to be allocated if one is needed.
+//
+// Any other buffers (in particular, any buffers inside the decoder)
+// must have cpi->image_pyramid_levels = 0, as a pyramid is unneeded there.
+//
+// Returns 0 on success. Returns < 0 on failure.
+int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
+ int ss_x, int ss_y, int use_highbitdepth,
+ int border, int byte_alignment,
+ aom_codec_frame_buffer_t *fb,
+ aom_get_frame_buffer_cb_fn_t cb, void *cb_priv,
+ int num_pyramid_levels, int alloc_y_plane_only);
+
+int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf);
+
+/*!\endcond */
+/*!\brief Removes metadata from YUV_BUFFER_CONFIG struct.
+ *
+ * Frees metadata in frame buffer.
+ * Frame buffer metadata pointer will be set to NULL.
+ *
+ * \param[in] ybf Frame buffer struct pointer
+ */
+void aom_remove_metadata_from_frame_buffer(YV12_BUFFER_CONFIG *ybf);
+
+/*!\brief Copy metadata to YUV_BUFFER_CONFIG struct.
+ *
+ * Copies metadata to frame buffer.
+ * Frame buffer will clear any previous metadata and will reallocate the
+ * metadata array to the new metadata size. Then, it will copy the new metadata
+ * array into it.
+ * If arr metadata pointer points to the same address as current metadata in the
+ * frame buffer, function will do nothing and return 0.
+ * Returns 0 on success or -1 on failure.
+ *
+ * \param[in] ybf Frame buffer struct pointer
+ * \param[in] arr Metadata array struct pointer
+ */
+int aom_copy_metadata_to_frame_buffer(YV12_BUFFER_CONFIG *ybf,
+ const aom_metadata_array_t *arr);
+
+/*!\brief Calculate the stride required for the image.
+ *
+ * Calculates the stride value for an image from aligned width and border.
+ * Returns the y stride value.
+ *
+ * \param[in] aligned_width Aligned width of the image
+ * \param[in] border Border in pixels
+ */
+static AOM_INLINE int aom_calc_y_stride(int aligned_width, int border) {
+ return ((aligned_width + 2 * border) + 31) & ~31;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AOM_AOM_SCALE_YV12CONFIG_H_