Commit 69fde2eb authored by Urvang Joshi's avatar Urvang Joshi
Browse files

horzonly-frame-superres: Apply to superres only.

Plain resize is now unaffected by this flag. That is, plain resizing is
performed for both width and height always.

Change-Id: I652204d68ca5266f0a1a413927828038aa5dfdf6
parent 3d8bcb2a
......@@ -1168,33 +1168,45 @@ YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
}
}
void av1_calculate_scaled_size(int *width, int *height, int denom) {
// Calculates scaled dimensions given original dimensions and the scale
// denominator. If 'scale_height' is 1, both width and height are scaled;
// otherwise, only the width is scaled.
static void calculate_scaled_size_helper(int *width, int *height, int denom,
int scale_height) {
if (denom != SCALE_NUMERATOR) {
*width = *width * SCALE_NUMERATOR / denom;
*width += *width & 1; // Make it even.
#if CONFIG_HORZONLY_FRAME_SUPERRES
(void)height;
#else
*height = *height * SCALE_NUMERATOR / denom;
*height += *height & 1; // Make it even.
#endif // !CONFIG_HORZONLY_FRAME_SUPERRES
if (scale_height) {
*height = *height * SCALE_NUMERATOR / denom;
*height += *height & 1; // Make it even.
}
}
}
void av1_calculate_unscaled_size(int *width, int *height, int denom) {
void av1_calculate_scaled_size(int *width, int *height, int resize_denom) {
calculate_scaled_size_helper(width, height, resize_denom, 1);
}
#if CONFIG_FRAME_SUPERRES
void av1_calculate_scaled_superres_size(int *width, int *height,
int superres_denom) {
calculate_scaled_size_helper(width, height, superres_denom,
!CONFIG_HORZONLY_FRAME_SUPERRES);
}
void av1_calculate_unscaled_superres_size(int *width, int *height, int denom) {
if (denom != SCALE_NUMERATOR) {
// Note: av1_calculate_scaled_size() rounds *up* after division when the
// resulting dimensions are odd. So here, we round *down*.
// Note: av1_calculate_scaled_superres_size() rounds *up* after division
// when the resulting dimensions are odd. So here, we round *down*.
*width = *width * denom / SCALE_NUMERATOR;
#if CONFIG_HORZONLY_FRAME_SUPERRES
(void)height;
#else
*height = *height * denom / SCALE_NUMERATOR;
#endif // !CONFIG_HORZONLY_FRAME_SUPERRES
#endif // CONFIG_HORZONLY_FRAME_SUPERRES
}
}
#if CONFIG_FRAME_SUPERRES
// TODO(afergs): Look for in-place upscaling
// TODO(afergs): aom_ vs av1_ functions? Which can I use?
// Upscale decoded image.
......@@ -1268,7 +1280,8 @@ void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool) {
// Scale up and back into frame_to_show.
assert(frame_to_show->y_crop_width != cm->width);
assert(frame_to_show->y_crop_height != cm->height);
assert(IMPLIES(!CONFIG_HORZONLY_FRAME_SUPERRES,
frame_to_show->y_crop_height != cm->height));
#if CONFIG_HIGHBITDEPTH
av1_upscale_normative_and_extend_frame(&copy_buffer, frame_to_show,
(int)cm->bit_depth);
......
......@@ -85,15 +85,21 @@ YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *unscaled,
YV12_BUFFER_CONFIG *scaled);
// Calculates the scaled size from the given original dimensions and the scale
// denominator.
void av1_calculate_scaled_size(int *width, int *height, int denom);
// Inverse of av1_calculate_scaled_size() above: calculates the original size
// from the given scaled dimensions and the scale denominator.
void av1_calculate_unscaled_size(int *width, int *height, int denom);
// Calculates the scaled dimensions from the given original dimensions and the
// resize scale denominator.
void av1_calculate_scaled_size(int *width, int *height, int resize_denom);
#if CONFIG_FRAME_SUPERRES
// Similar to above, but calculates scaled dimensions after superres from the
// given original dimensions and superres scale denominator.
void av1_calculate_scaled_superres_size(int *width, int *height,
int superres_denom);
// Inverse of av1_calculate_scaled_superres_size() above: calculates the
// original dimensions from the given scaled dimensions and the scale
// denominator.
void av1_calculate_unscaled_superres_size(int *width, int *height, int denom);
void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool);
// Returns 1 if a superres upscaled frame is unscaled and 0 otherwise.
......
......@@ -3070,7 +3070,8 @@ static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb,
cm->superres_scale_denominator += SUPERRES_SCALE_DENOMINATOR_MIN;
// Don't edit cm->width or cm->height directly, or the buffers won't get
// resized correctly
av1_calculate_scaled_size(width, height, cm->superres_scale_denominator);
av1_calculate_scaled_superres_size(width, height,
cm->superres_scale_denominator);
} else {
// 1:1 scaling - ie. no scaling, scale not provided
cm->superres_scale_denominator = SCALE_NUMERATOR;
......
......@@ -4489,6 +4489,7 @@ static int dimension_is_ok(int orig_dim, int resized_dim, int denom) {
return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2);
}
// TODO(now): Fix?
static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) {
return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom) &&
(CONFIG_HORZONLY_FRAME_SUPERRES ||
......@@ -4504,15 +4505,10 @@ static int validate_size_scales(RESIZE_MODE resize_mode,
return 1;
}
// Calculate current resize scale.
#if CONFIG_HORZONLY_FRAME_SUPERRES
int resize_denom =
DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width);
#else
// Calculate current resize scale.
int resize_denom =
AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width),
DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height));
#endif // CONFIG_HORZONLY_FRAME_SUPERRES
if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
// Alter superres scale as needed to enforce conformity.
......@@ -4601,7 +4597,8 @@ static void setup_frame_size_from_params(AV1_COMP *cpi, size_params_type *rsz) {
cm->superres_upscaled_width = encode_width;
cm->superres_upscaled_height = encode_height;
cm->superres_scale_denominator = rsz->superres_denom;
av1_calculate_scaled_size(&encode_width, &encode_height, rsz->superres_denom);
av1_calculate_scaled_superres_size(&encode_width, &encode_height,
rsz->superres_denom);
#endif // CONFIG_FRAME_SUPERRES
set_frame_size(cpi, encode_width, encode_height);
}
......
......@@ -545,10 +545,10 @@ static void foreach_rtile_in_tile(const struct rest_search_ctxt *ctxt,
// upscaled frame where the restoration tiles live. To do this, scale up the
// top-left and bottom-right of the tile.
if (!av1_superres_unscaled(cm)) {
av1_calculate_unscaled_size(&tile_col_start, &tile_row_start,
cm->superres_scale_denominator);
av1_calculate_unscaled_size(&tile_col_end, &tile_row_end,
cm->superres_scale_denominator);
av1_calculate_unscaled_superres_size(&tile_col_start, &tile_row_start,
cm->superres_scale_denominator);
av1_calculate_unscaled_superres_size(&tile_col_end, &tile_row_end,
cm->superres_scale_denominator);
// Make sure we don't fall off the bottom-right of the frame.
tile_col_end = AOMMIN(tile_col_end, ctxt->plane_width);
tile_row_end = AOMMIN(tile_row_end, ctxt->plane_height);
......
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