2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #ifndef AOM_AOM_SCALE_YV12CONFIG_H_
13 #define AOM_AOM_SCALE_YV12CONFIG_H_
19 #include "config/aom_config.h"
21 #include "aom/aom_codec.h"
22 #include "aom/aom_frame_buffer.h"
23 #include "aom/aom_integer.h"
24 #include "aom/internal/aom_image_internal.h"
28 #define AOMINNERBORDERINPIXELS 160
29 #define AOM_INTERP_EXTEND 4
30 #define AOM_BORDER_IN_PIXELS 288
31 #define AOM_ENC_NO_SCALE_BORDER 160
32 #define AOM_ENC_ALLINTRA_BORDER 64
33 #define AOM_DEC_BORDER_IN_PIXELS 64
37 * \brief YV12 frame buffer data structure
39 typedef struct yv12_buffer_config
{
85 // Indicate whether y_buffer, u_buffer, and v_buffer points to the internally
86 // allocated memory or external buffers.
87 int use_external_reference_buffers
;
88 // This is needed to store y_buffer, u_buffer, and v_buffer when set reference
89 // uses an external refernece, and restore those buffer pointers after the
90 // external reference frame is no longer used.
91 uint8_t *store_buf_adr
[3];
93 // If the frame is stored in a 16-bit buffer, this stores an 8-bit version
94 // for use in global motion detection. It is allocated on-demand.
95 uint8_t *y_buffer_8bit
;
98 uint8_t *buffer_alloc
;
99 size_t buffer_alloc_sz
;
104 unsigned int bit_depth
;
105 aom_color_primaries_t color_primaries
;
106 aom_transfer_characteristics_t transfer_characteristics
;
107 aom_matrix_coefficients_t matrix_coefficients
;
109 aom_chroma_sample_position_t chroma_sample_position
;
110 aom_color_range_t color_range
;
116 aom_metadata_array_t
*metadata
;
118 } YV12_BUFFER_CONFIG
;
122 #define YV12_FLAG_HIGHBITDEPTH 8
124 int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG
*ybf
, int width
, int height
,
125 int ss_x
, int ss_y
, int use_highbitdepth
, int border
,
128 // Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
129 // be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
130 // NULL, then libaom is using the frame buffer callbacks to handle memory.
131 // If cb is not NULL, libaom will call cb with minimum size in bytes needed
132 // to decode the current frame. If cb is NULL, libaom will allocate memory
133 // internally to decode the current frame. Returns 0 on success. Returns < 0
135 int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG
*ybf
, int width
, int height
,
136 int ss_x
, int ss_y
, int use_highbitdepth
,
137 int border
, int byte_alignment
,
138 aom_codec_frame_buffer_t
*fb
,
139 aom_get_frame_buffer_cb_fn_t cb
, void *cb_priv
,
140 int alloc_y_buffer_8bit
);
142 int aom_free_frame_buffer(YV12_BUFFER_CONFIG
*ybf
);
145 /*!\brief Removes metadata from YUV_BUFFER_CONFIG struct.
147 * Frees metadata in frame buffer.
148 * Frame buffer metadata pointer will be set to NULL.
150 * \param[in] ybf Frame buffer struct pointer
152 void aom_remove_metadata_from_frame_buffer(YV12_BUFFER_CONFIG
*ybf
);
154 /*!\brief Copy metadata to YUV_BUFFER_CONFIG struct.
156 * Copies metadata to frame buffer.
157 * Frame buffer will clear any previous metadata and will reallocate the
158 * metadata array to the new metadata size. Then, it will copy the new metadata
160 * If arr metadata pointer points to the same address as current metadata in the
161 * frame buffer, function will do nothing and return 0.
162 * Returns 0 on success or -1 on failure.
164 * \param[in] ybf Frame buffer struct pointer
165 * \param[in] arr Metadata array struct pointer
167 int aom_copy_metadata_to_frame_buffer(YV12_BUFFER_CONFIG
*ybf
,
168 const aom_metadata_array_t
*arr
);
170 /*!\brief Calculate the stride required for the image.
172 * Calculates the stride value for an image from aligned width and border.
173 * Returns the y stride value.
175 * \param[in] aligned_width Aligned width of the image
176 * \param[in] border Border in pixels
178 static AOM_INLINE
int aom_calc_y_stride(int aligned_width
, int border
) {
179 return ((aligned_width
+ 2 * border
) + 31) & ~31;
186 #endif // AOM_AOM_SCALE_YV12CONFIG_H_