Commit 557ce7b5 authored by David Barker's avatar David Barker Committed by Debargha Mukherjee

Enable global motion in high bit depth mode

The global motion detection only works on 8-bit buffers,
so any frames using 16-bit buffers are now down-converted
to 8 bits when necessary.

Change-Id: I4f88f4ccd449e73a2292cda70fe573dc49fcb8a0
parent 94b876f4
......@@ -34,6 +34,10 @@ int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf) {
aom_free(ybf->buffer_alloc);
}
#if CONFIG_AOM_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION
if (ybf->y_buffer_8bit) free(ybf->y_buffer_8bit);
#endif
/* 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 */
......@@ -163,6 +167,13 @@ int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
(uv_border_h * uv_stride) + uv_border_w,
aom_byte_align);
#if CONFIG_AOM_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION
if (ybf->y_buffer_8bit) {
free(ybf->y_buffer_8bit);
ybf->y_buffer_8bit = NULL;
}
#endif
ybf->corrupted = 0; /* assume not corrupted by errors */
return 0;
}
......
......@@ -56,6 +56,12 @@ typedef struct yv12_buffer_config {
uint8_t *v_buffer;
uint8_t *alpha_buffer;
#if CONFIG_AOM_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION
// If the frame is stored in a 16-bit buffer, this stores an 8-bit version
// for use in global motion detection. It is allocated on-demand.
uint8_t *y_buffer_8bit;
#endif
uint8_t *buffer_alloc;
size_t buffer_alloc_sz;
int border;
......
......@@ -4798,7 +4798,11 @@ static void encode_frame_internal(AV1_COMP *cpi) {
if (ref_buf) {
aom_clear_system_state();
if (compute_global_motion_feature_based(GLOBAL_TRANS_TYPES - 1,
cpi->Source, ref_buf, params)) {
cpi->Source, ref_buf,
#if CONFIG_AOM_HIGHBITDEPTH
cpi->common.bit_depth,
#endif // CONFIG_AOM_HIGHBITDEPTH
params)) {
convert_model_to_params(params, &cm->global_motion[frame]);
if (cm->global_motion[frame].wmtype != IDENTITY) {
refine_integerized_param(
......
......@@ -54,9 +54,27 @@ static int compute_global_motion_params(TransformationType type,
return num_inliers;
}
#if CONFIG_AOM_HIGHBITDEPTH
unsigned char *downconvert_frame(YV12_BUFFER_CONFIG *frm, int bit_depth) {
int i, j;
uint16_t *orig_buf = CONVERT_TO_SHORTPTR(frm->y_buffer);
uint8_t *buf = malloc(frm->y_height * frm->y_stride * sizeof(*buf));
for (i = 0; i < frm->y_height; ++i)
for (j = 0; j < frm->y_width; ++j)
buf[i * frm->y_stride + j] =
orig_buf[i * frm->y_stride + j] >> (bit_depth - 8);
return buf;
}
#endif
int compute_global_motion_feature_based(TransformationType type,
YV12_BUFFER_CONFIG *frm,
YV12_BUFFER_CONFIG *ref,
#if CONFIG_AOM_HIGHBITDEPTH
int bit_depth,
#endif
double *params) {
int num_frm_corners, num_ref_corners;
int num_correspondences;
......@@ -64,20 +82,37 @@ int compute_global_motion_feature_based(TransformationType type,
int num_inliers;
int frm_corners[2 * MAX_CORNERS], ref_corners[2 * MAX_CORNERS];
int *inlier_map = NULL;
unsigned char *frm_buffer = frm->y_buffer;
unsigned char *ref_buffer = ref->y_buffer;
#if CONFIG_AOM_HIGHBITDEPTH
if (frm->flags & YV12_FLAG_HIGHBITDEPTH) {
// The frame buffer is 16-bit, so we need to convert to 8 bits for the
// following code. We cache the result until the frame is released.
if (frm->y_buffer_8bit)
frm_buffer = frm->y_buffer_8bit;
else
frm_buffer = frm->y_buffer_8bit = downconvert_frame(frm, bit_depth);
}
if (ref->flags & YV12_FLAG_HIGHBITDEPTH) {
if (ref->y_buffer_8bit)
ref_buffer = ref->y_buffer_8bit;
else
ref_buffer = ref->y_buffer_8bit = downconvert_frame(ref, bit_depth);
}
#endif
// compute interest points in images using FAST features
num_frm_corners =
fast_corner_detect(frm->y_buffer, frm->y_width, frm->y_height,
frm->y_stride, frm_corners, MAX_CORNERS);
num_ref_corners =
fast_corner_detect(ref->y_buffer, ref->y_width, ref->y_height,
ref->y_stride, ref_corners, MAX_CORNERS);
num_frm_corners = fast_corner_detect(frm_buffer, frm->y_width, frm->y_height,
frm->y_stride, frm_corners, MAX_CORNERS);
num_ref_corners = fast_corner_detect(ref_buffer, ref->y_width, ref->y_height,
ref->y_stride, ref_corners, MAX_CORNERS);
// find correspondences between the two images
correspondences =
(double *)malloc(num_frm_corners * 4 * sizeof(*correspondences));
num_correspondences = determine_correspondence(
frm->y_buffer, (int *)frm_corners, num_frm_corners, ref->y_buffer,
frm_buffer, (int *)frm_corners, num_frm_corners, ref_buffer,
(int *)ref_corners, num_ref_corners, frm->y_width, frm->y_height,
frm->y_stride, ref->y_stride, correspondences);
......
......@@ -31,6 +31,9 @@ extern "C" {
int compute_global_motion_feature_based(TransformationType type,
YV12_BUFFER_CONFIG *frm,
YV12_BUFFER_CONFIG *ref,
#if CONFIG_AOM_HIGHBITDEPTH
int bit_depth,
#endif
double *params);
#ifdef __cplusplus
} // extern "C"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment