Move aom_shift_img() to tools_common cherry-pick of 3a607f7b00e9e9a47675c510c4196f792a6d3a28 from master Moved aom_shift_img() to tools_common, so that it can be called from other files. BUG=aomedia:1999 Change-Id: I3a4fec1056fb2222573a6887883ff92bea0df4dc
diff --git a/apps/aomdec.c b/apps/aomdec.c index e9f7ef6..70ba3099 100644 --- a/apps/aomdec.c +++ b/apps/aomdec.c
@@ -436,13 +436,6 @@ } } -static int img_shifted_realloc_required(const aom_image_t *img, - const aom_image_t *shifted, - aom_img_fmt_t required_fmt) { - return img->d_w != shifted->d_w || img->d_h != shifted->d_h || - required_fmt != shifted->fmt; -} - static int main_loop(int argc, const char **argv_) { aom_codec_ctx_t decoder; char *fn = NULL; @@ -887,37 +880,8 @@ output_bit_depth = fixed_output_bit_depth; } // Shift up or down if necessary - if (output_bit_depth != 0) { - const aom_img_fmt_t shifted_fmt = - output_bit_depth == 8 - ? img->fmt ^ (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) - : img->fmt | AOM_IMG_FMT_HIGHBITDEPTH; - - if (shifted_fmt != img->fmt || output_bit_depth != img->bit_depth) { - if (img_shifted && - img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { - aom_img_free(img_shifted); - img_shifted = NULL; - } - if (img_shifted) { - img_shifted->monochrome = img->monochrome; - } - if (!img_shifted) { - img_shifted = - aom_img_alloc(NULL, shifted_fmt, img->d_w, img->d_h, 16); - img_shifted->bit_depth = output_bit_depth; - img_shifted->monochrome = img->monochrome; - } - if (output_bit_depth > img->bit_depth) { - aom_img_upshift(img_shifted, img, - output_bit_depth - img->bit_depth); - } else { - aom_img_downshift(img_shifted, img, - img->bit_depth - output_bit_depth); - } - img = img_shifted; - } - } + if (output_bit_depth != 0) + aom_shift_img(output_bit_depth, &img, &img_shifted); aom_input_ctx.width = img->d_w; aom_input_ctx.height = img->d_h;
diff --git a/common/tools_common.c b/common/tools_common.c index 359ec734..11d343b 100644 --- a/common/tools_common.c +++ b/common/tools_common.c
@@ -421,3 +421,44 @@ lowbd_img_downshift(dst, src, down_shift); } } + +static int img_shifted_realloc_required(const aom_image_t *img, + const aom_image_t *shifted, + aom_img_fmt_t required_fmt) { + return img->d_w != shifted->d_w || img->d_h != shifted->d_h || + required_fmt != shifted->fmt; +} + +void aom_shift_img(unsigned int output_bit_depth, aom_image_t **img_ptr, + aom_image_t **img_shifted_ptr) { + aom_image_t *img = *img_ptr; + aom_image_t *img_shifted = *img_shifted_ptr; + + const aom_img_fmt_t shifted_fmt = output_bit_depth == 8 + ? img->fmt & ~AOM_IMG_FMT_HIGHBITDEPTH + : img->fmt | AOM_IMG_FMT_HIGHBITDEPTH; + + if (shifted_fmt != img->fmt || output_bit_depth != img->bit_depth) { + if (img_shifted && + img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { + aom_img_free(img_shifted); + img_shifted = NULL; + } + if (img_shifted) { + img_shifted->monochrome = img->monochrome; + } + if (!img_shifted) { + img_shifted = aom_img_alloc(NULL, shifted_fmt, img->d_w, img->d_h, 16); + img_shifted->bit_depth = output_bit_depth; + img_shifted->monochrome = img->monochrome; + img_shifted->csp = img->csp; + } + if (output_bit_depth > img->bit_depth) { + aom_img_upshift(img_shifted, img, output_bit_depth - img->bit_depth); + } else { + aom_img_downshift(img_shifted, img, img->bit_depth - output_bit_depth); + } + *img_shifted_ptr = img_shifted; + *img_ptr = img_shifted; + } +}
diff --git a/common/tools_common.h b/common/tools_common.h index abee4ea..31b1322 100644 --- a/common/tools_common.h +++ b/common/tools_common.h
@@ -154,6 +154,8 @@ double sse_to_psnr(double samples, double peak, double mse); void aom_img_upshift(aom_image_t *dst, aom_image_t *src, int input_shift); void aom_img_downshift(aom_image_t *dst, aom_image_t *src, int down_shift); +void aom_shift_img(unsigned int output_bit_depth, aom_image_t **img_ptr, + aom_image_t **img_shifted_ptr); void aom_img_truncate_16_to_8(aom_image_t *dst, aom_image_t *src); #ifdef __cplusplus