diff options
Diffstat (limited to 'third_party/aom/aom_scale/generic')
-rw-r--r-- | third_party/aom/aom_scale/generic/aom_scale.c | 76 | ||||
-rw-r--r-- | third_party/aom/aom_scale/generic/yv12config.c | 13 | ||||
-rw-r--r-- | third_party/aom/aom_scale/generic/yv12extend.c | 167 |
3 files changed, 95 insertions, 161 deletions
diff --git a/third_party/aom/aom_scale/generic/aom_scale.c b/third_party/aom/aom_scale/generic/aom_scale.c index 14f3ae0da..d124832b7 100644 --- a/third_party/aom/aom_scale/generic/aom_scale.c +++ b/third_party/aom/aom_scale/generic/aom_scale.c @@ -476,54 +476,30 @@ void aom_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, unsigned int hscale, unsigned int hratio, unsigned int vscale, unsigned int vratio, unsigned int interlaced) { - int i; - int dw = (hscale - 1 + src->y_width * hratio) / hscale; - int dh = (vscale - 1 + src->y_height * vratio) / vscale; - - /* call our internal scaling routines!! */ - Scale2D((unsigned char *)src->y_buffer, src->y_stride, src->y_width, - src->y_height, (unsigned char *)dst->y_buffer, dst->y_stride, dw, dh, - temp_area, temp_height, hscale, hratio, vscale, vratio, interlaced); - - if (dw < (int)dst->y_width) - for (i = 0; i < dh; ++i) - memset(dst->y_buffer + i * dst->y_stride + dw - 1, - dst->y_buffer[i * dst->y_stride + dw - 2], dst->y_width - dw + 1); - - if (dh < (int)dst->y_height) - for (i = dh - 1; i < (int)dst->y_height; ++i) - memcpy(dst->y_buffer + i * dst->y_stride, - dst->y_buffer + (dh - 2) * dst->y_stride, dst->y_width + 1); - - Scale2D((unsigned char *)src->u_buffer, src->uv_stride, src->uv_width, - src->uv_height, (unsigned char *)dst->u_buffer, dst->uv_stride, - dw / 2, dh / 2, temp_area, temp_height, hscale, hratio, vscale, - vratio, interlaced); - - if (dw / 2 < (int)dst->uv_width) - for (i = 0; i < dst->uv_height; ++i) - memset(dst->u_buffer + i * dst->uv_stride + dw / 2 - 1, - dst->u_buffer[i * dst->uv_stride + dw / 2 - 2], - dst->uv_width - dw / 2 + 1); - - if (dh / 2 < (int)dst->uv_height) - for (i = dh / 2 - 1; i < (int)dst->y_height / 2; ++i) - memcpy(dst->u_buffer + i * dst->uv_stride, - dst->u_buffer + (dh / 2 - 2) * dst->uv_stride, dst->uv_width); - - Scale2D((unsigned char *)src->v_buffer, src->uv_stride, src->uv_width, - src->uv_height, (unsigned char *)dst->v_buffer, dst->uv_stride, - dw / 2, dh / 2, temp_area, temp_height, hscale, hratio, vscale, - vratio, interlaced); - - if (dw / 2 < (int)dst->uv_width) - for (i = 0; i < dst->uv_height; ++i) - memset(dst->v_buffer + i * dst->uv_stride + dw / 2 - 1, - dst->v_buffer[i * dst->uv_stride + dw / 2 - 2], - dst->uv_width - dw / 2 + 1); - - if (dh / 2 < (int)dst->uv_height) - for (i = dh / 2 - 1; i < (int)dst->y_height / 2; ++i) - memcpy(dst->v_buffer + i * dst->uv_stride, - dst->v_buffer + (dh / 2 - 2) * dst->uv_stride, dst->uv_width); + 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 < 3; ++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/yv12config.c b/third_party/aom/aom_scale/generic/yv12config.c index ee15ae103..fce719273 100644 --- a/third_party/aom/aom_scale/generic/yv12config.c +++ b/third_party/aom/aom_scale/generic/yv12config.c @@ -11,9 +11,9 @@ #include <assert.h> -#include "aom_scale/yv12config.h" #include "aom_mem/aom_mem.h" #include "aom_ports/mem.h" +#include "aom_scale/yv12config.h" /**************************************************************************** * Exports @@ -35,7 +35,7 @@ int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf) { } #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION - if (ybf->y_buffer_8bit) free(ybf->y_buffer_8bit); + if (ybf->y_buffer_8bit) aom_free(ybf->y_buffer_8bit); #endif /* buffer_alloc isn't accessed by most functions. Rather y_buffer, @@ -168,9 +168,12 @@ int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, aom_byte_align); #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION - if (ybf->y_buffer_8bit) { - free(ybf->y_buffer_8bit); - ybf->y_buffer_8bit = NULL; + if (use_highbitdepth) { + if (ybf->y_buffer_8bit) aom_free(ybf->y_buffer_8bit); + ybf->y_buffer_8bit = (uint8_t *)aom_memalign(32, (size_t)yplane_size); + if (!ybf->y_buffer_8bit) return -1; + } else { + assert(!ybf->y_buffer_8bit); } #endif diff --git a/third_party/aom/aom_scale/generic/yv12extend.c b/third_party/aom/aom_scale/generic/yv12extend.c index 05e463362..8266743cf 100644 --- a/third_party/aom/aom_scale/generic/yv12extend.c +++ b/third_party/aom/aom_scale/generic/yv12extend.c @@ -101,8 +101,6 @@ static void extend_plane_high(uint8_t *const src8, int src_stride, int width, #endif void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { - const int uv_border = ybf->border / 2; - assert(ybf->border % 2 == 0); assert(ybf->y_height - ybf->y_crop_height < 16); assert(ybf->y_width - ybf->y_crop_width < 16); @@ -111,49 +109,33 @@ void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { #if CONFIG_HIGHBITDEPTH if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) { - extend_plane_high(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width, - ybf->y_crop_height, ybf->border, ybf->border, - ybf->border + ybf->y_height - ybf->y_crop_height, - ybf->border + ybf->y_width - ybf->y_crop_width); - - extend_plane_high(ybf->u_buffer, ybf->uv_stride, ybf->uv_crop_width, - ybf->uv_crop_height, uv_border, uv_border, - uv_border + ybf->uv_height - ybf->uv_crop_height, - uv_border + ybf->uv_width - ybf->uv_crop_width); - - extend_plane_high(ybf->v_buffer, ybf->uv_stride, ybf->uv_crop_width, - ybf->uv_crop_height, uv_border, uv_border, - uv_border + ybf->uv_height - ybf->uv_crop_height, - uv_border + ybf->uv_width - ybf->uv_crop_width); + for (int plane = 0; plane < 3; ++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]); + } return; } #endif - extend_plane(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width, - ybf->y_crop_height, ybf->border, ybf->border, - ybf->border + ybf->y_height - ybf->y_crop_height, - ybf->border + ybf->y_width - ybf->y_crop_width); - - extend_plane(ybf->u_buffer, ybf->uv_stride, ybf->uv_crop_width, - ybf->uv_crop_height, uv_border, uv_border, - uv_border + ybf->uv_height - ybf->uv_crop_height, - uv_border + ybf->uv_width - ybf->uv_crop_width); - - extend_plane(ybf->v_buffer, ybf->uv_stride, ybf->uv_crop_width, - ybf->uv_crop_height, uv_border, uv_border, - uv_border + ybf->uv_height - ybf->uv_crop_height, - uv_border + ybf->uv_width - ybf->uv_crop_width); + for (int plane = 0; plane < 3; ++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]); + } } #if CONFIG_AV1 static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) { - const int c_w = ybf->uv_crop_width; - const int c_h = ybf->uv_crop_height; const int ss_x = ybf->uv_width < ybf->y_width; const int ss_y = ybf->uv_height < ybf->y_height; - const int c_et = ext_size >> ss_y; - const int c_el = ext_size >> ss_x; - const int c_eb = c_et + ybf->uv_height - ybf->uv_crop_height; - const int c_er = c_el + ybf->uv_width - ybf->uv_crop_width; assert(ybf->y_height - ybf->y_crop_height < 16); assert(ybf->y_width - ybf->y_crop_width < 16); @@ -162,25 +144,29 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) { #if CONFIG_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); - extend_plane_high(ybf->u_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, - c_er); - extend_plane_high(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, - c_er); + for (int plane = 0; plane < 3; ++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); + } 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); - - extend_plane(ybf->u_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er); - - extend_plane(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er); + for (int plane = 0; plane < 3; ++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); + } } void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { @@ -230,10 +216,6 @@ static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) { // 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) { - int row; - const uint8_t *src = src_bc->y_buffer; - uint8_t *dst = dst_bc->y_buffer; - #if 0 /* These assertions are valid in the codec, but the libaom-tester uses * this code slightly differently. @@ -243,63 +225,36 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc, #endif #if CONFIG_HIGHBITDEPTH - if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { - assert(dst_bc->flags & YV12_FLAG_HIGHBITDEPTH); - for (row = 0; row < src_bc->y_height; ++row) { - memcpy_short_addr(dst, src, src_bc->y_width); - src += src_bc->y_stride; - dst += dst_bc->y_stride; - } - - src = src_bc->u_buffer; - dst = dst_bc->u_buffer; - - for (row = 0; row < src_bc->uv_height; ++row) { - memcpy_short_addr(dst, src, src_bc->uv_width); - src += src_bc->uv_stride; - dst += dst_bc->uv_stride; - } - - src = src_bc->v_buffer; - dst = dst_bc->v_buffer; + assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) == + (dst_bc->flags & YV12_FLAG_HIGHBITDEPTH)); - for (row = 0; row < src_bc->uv_height; ++row) { - memcpy_short_addr(dst, src, src_bc->uv_width); - src += src_bc->uv_stride; - dst += dst_bc->uv_stride; + if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { + for (int plane = 0; plane < 3; ++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); return; - } else { - assert(!(dst_bc->flags & YV12_FLAG_HIGHBITDEPTH)); } #endif - - for (row = 0; row < src_bc->y_height; ++row) { - memcpy(dst, src, src_bc->y_width); - src += src_bc->y_stride; - dst += dst_bc->y_stride; - } - - src = src_bc->u_buffer; - dst = dst_bc->u_buffer; - - 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; - } - - src = src_bc->v_buffer; - dst = dst_bc->v_buffer; - - 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; + for (int plane = 0; plane < 3; ++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); } |