summaryrefslogtreecommitdiff
path: root/media/libaom/src/aom_scale/generic/yv12extend.c
diff options
context:
space:
mode:
Diffstat (limited to 'media/libaom/src/aom_scale/generic/yv12extend.c')
-rw-r--r--media/libaom/src/aom_scale/generic/yv12extend.c152
1 files changed, 109 insertions, 43 deletions
diff --git a/media/libaom/src/aom_scale/generic/yv12extend.c b/media/libaom/src/aom_scale/generic/yv12extend.c
index ba183520a0..834a59dbff 100644
--- a/media/libaom/src/aom_scale/generic/yv12extend.c
+++ b/media/libaom/src/aom_scale/generic/yv12extend.c
@@ -59,6 +59,7 @@ static void extend_plane(uint8_t *const src, int src_stride, int width,
}
}
+#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) {
@@ -99,6 +100,7 @@ static void extend_plane_high(uint8_t *const src8, int src_stride, int width,
dst_ptr2 += src_stride;
}
}
+#endif // CONFIG_AV1_HIGHBITDEPTH
void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
const int num_planes) {
@@ -108,6 +110,7 @@ void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
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;
@@ -120,6 +123,8 @@ void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
}
return;
}
+#endif
+
for (int plane = 0; plane < num_planes; ++plane) {
const int is_uv = plane > 0;
const int plane_border = ybf->border >> is_uv;
@@ -141,6 +146,7 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
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;
@@ -154,6 +160,8 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
}
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);
@@ -184,7 +192,7 @@ void aom_extend_frame_borders_y_c(YV12_BUFFER_CONFIG *ybf) {
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,
@@ -192,17 +200,20 @@ void aom_extend_frame_borders_y_c(YV12_BUFFER_CONFIG *ybf) {
ext_size + ybf->y_width - ybf->y_crop_width);
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);
}
+#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.
@@ -217,6 +228,7 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
assert(src_bc->y_height == dst_bc->y_height);
#endif
+#if CONFIG_AV1_HIGHBITDEPTH
assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) ==
(dst_bc->flags & YV12_FLAG_HIGHBITDEPTH));
@@ -235,6 +247,7 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
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];
@@ -255,6 +268,7 @@ void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
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);
@@ -265,6 +279,7 @@ void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
}
return;
}
+#endif
for (row = 0; row < src_ybc->y_height; ++row) {
memcpy(dst, src, src_ybc->y_width);
@@ -278,7 +293,7 @@ void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_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);
@@ -289,7 +304,7 @@ void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
}
return;
}
-
+#endif
for (row = 0; row < src_bc->uv_height; ++row) {
memcpy(dst, src, src_bc->uv_width);
src += src_bc->uv_stride;
@@ -302,7 +317,7 @@ void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_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);
@@ -313,7 +328,7 @@ void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
}
return;
}
-
+#endif
for (row = 0; row < src_bc->uv_height; ++row) {
memcpy(dst, src, src_bc->uv_width);
src += src_bc->uv_stride;
@@ -321,91 +336,142 @@ void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
}
}
-void aom_yv12_partial_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
- YV12_BUFFER_CONFIG *dst_ybc, int hstart,
- int hend, int vstart, int vend) {
+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 + vstart * src_ybc->y_stride + hstart);
+ CONVERT_TO_SHORTPTR(src + vstart1 * src_ybc->y_stride + hstart1);
uint16_t *dst16 =
- CONVERT_TO_SHORTPTR(dst + vstart * dst_ybc->y_stride + hstart);
- for (row = vstart; row < vend; ++row) {
- memcpy(dst16, src16, (hend - hstart) * sizeof(uint16_t));
+ 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;
}
- src = (src + vstart * src_ybc->y_stride + hstart);
- dst = (dst + vstart * dst_ybc->y_stride + hstart);
+#endif
+ src = (src + vstart1 * src_ybc->y_stride + hstart1);
+ dst = (dst + vstart2 * dst_ybc->y_stride + hstart2);
- for (row = vstart; row < vend; ++row) {
- memcpy(dst, src, (hend - hstart));
+ 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_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
- YV12_BUFFER_CONFIG *dst_bc, int hstart, int hend,
- int vstart, int vend) {
+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 + vstart * src_bc->uv_stride + hstart);
+ CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
uint16_t *dst16 =
- CONVERT_TO_SHORTPTR(dst + vstart * dst_bc->uv_stride + hstart);
- for (row = vstart; row < vend; ++row) {
- memcpy(dst16, src16, (hend - hstart) * sizeof(uint16_t));
+ 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);
- src = (src + vstart * src_bc->uv_stride + hstart);
- dst = (dst + vstart * dst_bc->uv_stride + hstart);
-
- for (row = vstart; row < vend; ++row) {
- memcpy(dst, src, (hend - hstart));
+ 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_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
- YV12_BUFFER_CONFIG *dst_bc, int hstart, int hend,
- int vstart, int vend) {
+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 + vstart * src_bc->uv_stride + hstart);
+ CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
uint16_t *dst16 =
- CONVERT_TO_SHORTPTR(dst + vstart * dst_bc->uv_stride + hstart);
- for (row = vstart; row < vend; ++row) {
- memcpy(dst16, src16, (hend - hstart) * sizeof(uint16_t));
+ 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);
- src = (src + vstart * src_bc->uv_stride + hstart);
- dst = (dst + vstart * dst_bc->uv_stride + hstart);
-
- for (row = vstart; row < vend; ++row) {
- memcpy(dst, src, (hend - hstart));
+ 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_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);
+ 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;
+}