diff --git a/av1/common/tile_common.c b/av1/common/tile_common.c index 9ecae2ab660b8208a4132ee73cd7e5595d685de7..75e7d6abbebe1a6bf4261ab7e7bd8b9cffd848cb 100644 --- a/av1/common/tile_common.c +++ b/av1/common/tile_common.c @@ -103,6 +103,17 @@ void av1_setup_frame_boundary_info(const AV1_COMMON *const cm) { } } +int get_tile_size(int frame_mi_size, int log2_tile_num) { + // Round the frame up to a whole number of max superblocks + frame_mi_size = ALIGN_POWER_OF_TWO(frame_mi_size, MAX_MIB_SIZE_LOG2); + // Divide by the number of tiles, rounding up to the multiple of the max + // superblock size. To do this, shift right (and round up) to get the number + // of super-blocks and then shift left again to convert it to mi units. + const int shift = log2_tile_num + MAX_MIB_SIZE_LOG2; + const int round = (1 << shift) - 1; + return ((frame_mi_size + round) >> shift) << MAX_MIB_SIZE_LOG2; +} + #if CONFIG_LOOPFILTERING_ACROSS_TILES void av1_setup_across_tile_boundary_info(const AV1_COMMON *const cm, const TileInfo *const tile_info) { diff --git a/av1/common/tile_common.h b/av1/common/tile_common.h index 5d91e16a19ca6fd9836288837f0684cf92647977..0bc80c987a94fe1db7eb587b8e030dd560dfe6f5 100644 --- a/av1/common/tile_common.h +++ b/av1/common/tile_common.h @@ -44,6 +44,10 @@ void av1_get_tile_n_bits(int mi_cols, int *min_log2_tile_cols, void av1_setup_frame_boundary_info(const struct AV1Common *const cm); +// Calculate the correct tile size (width or height) for (1 << log2_tile_num) +// tiles horizontally or vertically in the frame. +int get_tile_size(int frame_mi_size, int log2_tile_num); + #if CONFIG_LOOPFILTERING_ACROSS_TILES void av1_setup_across_tile_boundary_info(const struct AV1Common *const cm, const TileInfo *const tile_info); diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c index c7b013b747ca0a1eb0a125d358469bba0e787314..2fb2673cf3a61ad40b8f4c97db3ce941edfcbb1b 100644 --- a/av1/decoder/decodeframe.c +++ b/av1/decoder/decodeframe.c @@ -3207,14 +3207,8 @@ static void read_tile_info(AV1Decoder *const pbi, cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); #endif // CONFIG_LOOPFILTERING_ACROSS_TILES - cm->tile_width = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); - cm->tile_width >>= cm->log2_tile_cols; - cm->tile_height = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); - cm->tile_height >>= cm->log2_tile_rows; - - // round to integer multiples of superblock size - cm->tile_width = ALIGN_POWER_OF_TWO(cm->tile_width, MAX_MIB_SIZE_LOG2); - cm->tile_height = ALIGN_POWER_OF_TWO(cm->tile_height, MAX_MIB_SIZE_LOG2); + cm->tile_width = get_tile_size(cm->mi_cols, cm->log2_tile_cols); + cm->tile_height = get_tile_size(cm->mi_rows, cm->log2_tile_rows); const int max_cols = (cm->mi_cols + cm->tile_width - 1) / cm->tile_width; const int max_rows = (cm->mi_rows + cm->tile_height - 1) / cm->tile_height; diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index b1bb0f1fcfc446f592e670275ed2d7c69c384319..d0ec1f7b12f81328bab5adba05fd8efb2e603ef8 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c @@ -896,14 +896,8 @@ static void set_tile_info(AV1_COMP *cpi) { clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); cm->log2_tile_rows = cpi->oxcf.tile_rows; - cm->tile_width = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); - cm->tile_width >>= cm->log2_tile_cols; - cm->tile_height = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); - cm->tile_height >>= cm->log2_tile_rows; - - // round to integer multiples of max superblock size - cm->tile_width = ALIGN_POWER_OF_TWO(cm->tile_width, MAX_MIB_SIZE_LOG2); - cm->tile_height = ALIGN_POWER_OF_TWO(cm->tile_height, MAX_MIB_SIZE_LOG2); + cm->tile_width = get_tile_size(cm->mi_cols, cm->log2_tile_cols); + cm->tile_height = get_tile_size(cm->mi_rows, cm->log2_tile_rows); const int max_cols = (cm->mi_cols + cm->tile_width - 1) / cm->tile_width; const int max_rows = (cm->mi_rows + cm->tile_height - 1) / cm->tile_height;