summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeb Mukherjee <debargha@google.com>2014-10-08 11:44:50 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2014-10-08 11:44:50 -0700
commit25b4a694432da3c471eae5a97484729148469a6c (patch)
treef4cbc87332bdb26972cdf2eb6b1f016274871e20
parente638aff245ea6beadffcd70bdadcfe5267c55b72 (diff)
parent7a2a611667a31302096820fd27154d7df391ac15 (diff)
downloadlibvpx-25b4a694432da3c471eae5a97484729148469a6c.tar
libvpx-25b4a694432da3c471eae5a97484729148469a6c.tar.gz
libvpx-25b4a694432da3c471eae5a97484729148469a6c.tar.bz2
libvpx-25b4a694432da3c471eae5a97484729148469a6c.zip
Merge "Refactoring of highbitdepth bitshift operations"
-rw-r--r--tools_common.c216
-rw-r--r--tools_common.h6
-rw-r--r--vpxdec.c180
-rw-r--r--vpxenc.c135
4 files changed, 229 insertions, 308 deletions
diff --git a/tools_common.c b/tools_common.c
index 0d4774f1a..30fd35205 100644
--- a/tools_common.c
+++ b/tools_common.c
@@ -268,3 +268,219 @@ double sse_to_psnr(double samples, double peak, double sse) {
return kMaxPSNR;
}
}
+
+// TODO(debargha): Consolidate the functions below into a separate file.
+#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
+static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src,
+ int input_shift) {
+ // Note the offset is 1 less than half.
+ const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0;
+ int plane;
+ if (dst->w != src->w || dst->h != src->h ||
+ dst->x_chroma_shift != src->x_chroma_shift ||
+ dst->y_chroma_shift != src->y_chroma_shift ||
+ dst->fmt != src->fmt || input_shift < 0) {
+ fatal("Unsupported image conversion");
+ }
+ switch (src->fmt) {
+ case VPX_IMG_FMT_I42016:
+ case VPX_IMG_FMT_I42216:
+ case VPX_IMG_FMT_I44416:
+ case VPX_IMG_FMT_I44016:
+ break;
+ default:
+ fatal("Unsupported image conversion");
+ break;
+ }
+ for (plane = 0; plane < 3; plane++) {
+ int w = src->w;
+ int h = src->h;
+ int x, y;
+ if (plane) {
+ w >>= src->x_chroma_shift;
+ h >>= src->y_chroma_shift;
+ }
+ for (y = 0; y < h; y++) {
+ uint16_t *p_src =
+ (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
+ uint16_t *p_dst =
+ (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]);
+ for (x = 0; x < w; x++)
+ *p_dst++ = (*p_src++ << input_shift) + offset;
+ }
+ }
+}
+
+static void lowbd_img_upshift(vpx_image_t *dst, vpx_image_t *src,
+ int input_shift) {
+ // Note the offset is 1 less than half.
+ const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0;
+ int plane;
+ if (dst->w != src->w || dst->h != src->h ||
+ dst->x_chroma_shift != src->x_chroma_shift ||
+ dst->y_chroma_shift != src->y_chroma_shift ||
+ dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
+ input_shift < 0) {
+ fatal("Unsupported image conversion");
+ }
+ switch (src->fmt) {
+ case VPX_IMG_FMT_I420:
+ case VPX_IMG_FMT_I422:
+ case VPX_IMG_FMT_I444:
+ case VPX_IMG_FMT_I440:
+ break;
+ default:
+ fatal("Unsupported image conversion");
+ break;
+ }
+ for (plane = 0; plane < 3; plane++) {
+ int w = src->w;
+ int h = src->h;
+ int x, y;
+ if (plane) {
+ w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
+ h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
+ }
+ for (y = 0; y < h; y++) {
+ uint8_t *p_src = src->planes[plane] + y * src->stride[plane];
+ uint16_t *p_dst =
+ (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]);
+ for (x = 0; x < w; x++) {
+ *p_dst++ = (*p_src++ << input_shift) + offset;
+ }
+ }
+ }
+}
+
+void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src,
+ int input_shift) {
+ if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
+ highbd_img_upshift(dst, src, input_shift);
+ } else {
+ lowbd_img_upshift(dst, src, input_shift);
+ }
+}
+
+void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src) {
+ int plane;
+ if (dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH != src->fmt ||
+ dst->d_w != src->d_w || dst->d_h != src->d_h ||
+ dst->x_chroma_shift != src->x_chroma_shift ||
+ dst->y_chroma_shift != src->y_chroma_shift) {
+ fatal("Unsupported image conversion");
+ }
+ switch (dst->fmt) {
+ case VPX_IMG_FMT_I420:
+ case VPX_IMG_FMT_I422:
+ case VPX_IMG_FMT_I444:
+ case VPX_IMG_FMT_I440:
+ break;
+ default:
+ fatal("Unsupported image conversion");
+ break;
+ }
+ for (plane = 0; plane < 3; plane++) {
+ int w = src->d_w;
+ int h = src->d_h;
+ int x, y;
+ if (plane) {
+ w >>= src->x_chroma_shift;
+ h >>= src->y_chroma_shift;
+ }
+ for (y = 0; y < h; y++) {
+ uint16_t *p_src =
+ (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
+ uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
+ for (x = 0; x < w; x++) {
+ *p_dst++ = *p_src++;
+ }
+ }
+ }
+}
+
+static void highbd_img_downshift(vpx_image_t *dst, vpx_image_t *src,
+ int down_shift) {
+ int plane;
+ if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
+ dst->x_chroma_shift != src->x_chroma_shift ||
+ dst->y_chroma_shift != src->y_chroma_shift ||
+ dst->fmt != src->fmt || down_shift < 0) {
+ fatal("Unsupported image conversion");
+ }
+ switch (src->fmt) {
+ case VPX_IMG_FMT_I42016:
+ case VPX_IMG_FMT_I42216:
+ case VPX_IMG_FMT_I44416:
+ case VPX_IMG_FMT_I44016:
+ break;
+ default:
+ fatal("Unsupported image conversion");
+ break;
+ }
+ for (plane = 0; plane < 3; plane++) {
+ int w = src->d_w;
+ int h = src->d_h;
+ int x, y;
+ if (plane) {
+ w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
+ h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
+ }
+ for (y = 0; y < h; y++) {
+ uint16_t *p_src =
+ (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
+ uint16_t *p_dst =
+ (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]);
+ for (x = 0; x < w; x++)
+ *p_dst++ = *p_src++ >> down_shift;
+ }
+ }
+}
+
+static void lowbd_img_downshift(vpx_image_t *dst, vpx_image_t *src,
+ int down_shift) {
+ int plane;
+ if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
+ dst->x_chroma_shift != src->x_chroma_shift ||
+ dst->y_chroma_shift != src->y_chroma_shift ||
+ src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
+ down_shift < 0) {
+ fatal("Unsupported image conversion");
+ }
+ switch (dst->fmt) {
+ case VPX_IMG_FMT_I420:
+ case VPX_IMG_FMT_I422:
+ case VPX_IMG_FMT_I444:
+ case VPX_IMG_FMT_I440:
+ break;
+ default:
+ fatal("Unsupported image conversion");
+ break;
+ }
+ for (plane = 0; plane < 3; plane++) {
+ int w = src->d_w;
+ int h = src->d_h;
+ int x, y;
+ if (plane) {
+ w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
+ h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
+ }
+ for (y = 0; y < h; y++) {
+ uint16_t *p_src =
+ (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
+ uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
+ for (x = 0; x < w; x++) {
+ *p_dst++ = *p_src++ >> down_shift;
+ }
+ }
+ }
+}
+
+void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src,
+ int down_shift) {
+ if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
+ highbd_img_downshift(dst, src, down_shift);
+ } else {
+ lowbd_img_downshift(dst, src, down_shift);
+ }
+}
+#endif // CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
diff --git a/tools_common.h b/tools_common.h
index c1f466b01..de6c38f0f 100644
--- a/tools_common.h
+++ b/tools_common.h
@@ -149,6 +149,12 @@ int vpx_img_read(vpx_image_t *img, FILE *file);
double sse_to_psnr(double samples, double peak, double mse);
+#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
+void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, int input_shift);
+void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, int down_shift);
+void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src);
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/vpxdec.c b/vpxdec.c
index 45dd04125..04690714e 100644
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -527,180 +527,6 @@ static FILE *open_outfile(const char *name) {
}
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
-static void high_img_upshift(vpx_image_t *dst, vpx_image_t *src,
- int input_shift) {
- const int offset = input_shift > 0 ? (1 << (input_shift - 1)) : 0;
- int plane;
- if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift ||
- dst->fmt != src->fmt || input_shift < 0) {
- fatal("Unsupported image conversion");
- }
- switch (src->fmt) {
- case VPX_IMG_FMT_I42016:
- case VPX_IMG_FMT_I42216:
- case VPX_IMG_FMT_I44416:
- case VPX_IMG_FMT_I44016:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->d_w;
- int h = src->d_h;
- int x, y;
- if (plane) {
- w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
- h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint16_t *p_src = (uint16_t *)(src->planes[plane] +
- y * src->stride[plane]);
- uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
- y * dst->stride[plane]);
- for (x = 0; x < w; x++)
- *p_dst++ = (*p_src++ << input_shift) + offset;
- }
- }
-}
-
-static void low_img_upshift(vpx_image_t *dst, vpx_image_t *src,
- int input_shift) {
- const int offset = input_shift > 0 ? (1 << (input_shift - 1)) : 0;
- int plane;
- if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift ||
- dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
- input_shift < 0) {
- fatal("Unsupported image conversion");
- }
- switch (src->fmt) {
- case VPX_IMG_FMT_I420:
- case VPX_IMG_FMT_I422:
- case VPX_IMG_FMT_I444:
- case VPX_IMG_FMT_I440:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->d_w;
- int h = src->d_h;
- int x, y;
- if (plane) {
- w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
- h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint8_t *p_src = src->planes[plane] + y * src->stride[plane];
- uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
- y * dst->stride[plane]);
- for (x = 0; x < w; x++) {
- *p_dst++ = (*p_src++ << input_shift) + offset;
- }
- }
- }
-}
-
-static void img_upshift(vpx_image_t *dst, vpx_image_t *src,
- int input_shift) {
- if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
- high_img_upshift(dst, src, input_shift);
- } else {
- low_img_upshift(dst, src, input_shift);
- }
-}
-
-static void high_img_downshift(vpx_image_t *dst, vpx_image_t *src,
- int down_shift) {
- int plane;
- if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift ||
- dst->fmt != src->fmt || down_shift < 0) {
- fatal("Unsupported image conversion");
- }
- switch (src->fmt) {
- case VPX_IMG_FMT_I42016:
- case VPX_IMG_FMT_I42216:
- case VPX_IMG_FMT_I44416:
- case VPX_IMG_FMT_I44016:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->d_w;
- int h = src->d_h;
- int x, y;
- if (plane) {
- w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
- h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint16_t *p_src = (uint16_t *)(src->planes[plane] +
- y * src->stride[plane]);
- uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
- y * dst->stride[plane]);
- for (x = 0; x < w; x++)
- *p_dst++ = *p_src++ >> down_shift;
- }
- }
-}
-
-static void low_img_downshift(vpx_image_t *dst, vpx_image_t *src,
- int down_shift) {
- int plane;
- if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift ||
- src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
- down_shift < 0) {
- fatal("Unsupported image conversion");
- }
- switch (dst->fmt) {
- case VPX_IMG_FMT_I420:
- case VPX_IMG_FMT_I422:
- case VPX_IMG_FMT_I444:
- case VPX_IMG_FMT_I440:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->d_w;
- int h = src->d_h;
- int x, y;
- if (plane) {
- w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
- h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint16_t *p_src = (uint16_t *)(src->planes[plane] +
- y * src->stride[plane]);
- uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
- for (x = 0; x < w; x++) {
- *p_dst++ = *p_src++ >> down_shift;
- }
- }
- }
-}
-
-static void img_downshift(vpx_image_t *dst, vpx_image_t *src,
- int down_shift) {
- if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
- high_img_downshift(dst, src, down_shift);
- } else {
- low_img_downshift(dst, src, down_shift);
- }
-}
-
static int img_shifted_realloc_required(const vpx_image_t *img,
const vpx_image_t *shifted,
vpx_img_fmt_t required_fmt) {
@@ -1156,9 +982,11 @@ int main_loop(int argc, const char **argv_) {
img_shifted->bit_depth = output_bit_depth;
}
if (output_bit_depth > img->bit_depth) {
- img_upshift(img_shifted, img, output_bit_depth - img->bit_depth);
+ vpx_img_upshift(img_shifted, img,
+ output_bit_depth - img->bit_depth);
} else {
- img_downshift(img_shifted, img, img->bit_depth - output_bit_depth);
+ vpx_img_downshift(img_shifted, img,
+ img->bit_depth - output_bit_depth);
}
img = img_shifted;
}
diff --git a/vpxenc.c b/vpxenc.c
index b323e3c44..e40f2244a 100644
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -1716,135 +1716,6 @@ static float usec_to_fps(uint64_t usec, unsigned int frames) {
return (float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
}
-#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
-static void high_img_upshift(vpx_image_t *dst, vpx_image_t *src,
- int input_shift) {
- // Note the offset is 1 less than half
- const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0;
- int plane;
- if (dst->w != src->w || dst->h != src->h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift ||
- dst->fmt != src->fmt || input_shift < 0) {
- fatal("Unsupported image conversion");
- }
- switch (src->fmt) {
- case VPX_IMG_FMT_I42016:
- case VPX_IMG_FMT_I42216:
- case VPX_IMG_FMT_I44416:
- case VPX_IMG_FMT_I44016:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->w;
- int h = src->h;
- int x, y;
- if (plane) {
- w >>= src->x_chroma_shift;
- h >>= src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint16_t *p_src = (uint16_t *)(src->planes[plane] +
- y * src->stride[plane]);
- uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
- y * dst->stride[plane]);
- for (x = 0; x < w; x++)
- *p_dst++ = (*p_src++ << input_shift) + offset;
- }
- }
-}
-
-static void low_img_upshift(vpx_image_t *dst, vpx_image_t *src,
- int input_shift) {
- // Note the offset is 1 less than half
- const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0;
- int plane;
- if (dst->w != src->w || dst->h != src->h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift ||
- dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
- input_shift < 0) {
- fatal("Unsupported image conversion");
- }
- switch (src->fmt) {
- case VPX_IMG_FMT_I420:
- case VPX_IMG_FMT_I422:
- case VPX_IMG_FMT_I444:
- case VPX_IMG_FMT_I440:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->w;
- int h = src->h;
- int x, y;
- if (plane) {
- w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
- h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint8_t *p_src = src->planes[plane] + y * src->stride[plane];
- uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
- y * dst->stride[plane]);
- for (x = 0; x < w; x++) {
- *p_dst++ = (*p_src++ << input_shift) + offset;
- }
- }
- }
-}
-
-static void img_upshift(vpx_image_t *dst, vpx_image_t *src,
- int input_shift) {
- if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
- high_img_upshift(dst, src, input_shift);
- } else {
- low_img_upshift(dst, src, input_shift);
- }
-}
-
-static void img_cast_16_to_8(vpx_image_t *dst, vpx_image_t *src) {
- int plane;
- if (dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH != src->fmt ||
- dst->d_w != src->d_w || dst->d_h != src->d_h ||
- dst->x_chroma_shift != src->x_chroma_shift ||
- dst->y_chroma_shift != src->y_chroma_shift) {
- fatal("Unsupported image conversion");
- }
- switch (dst->fmt) {
- case VPX_IMG_FMT_I420:
- case VPX_IMG_FMT_I422:
- case VPX_IMG_FMT_I444:
- case VPX_IMG_FMT_I440:
- break;
- default:
- fatal("Unsupported image conversion");
- break;
- }
- for (plane = 0; plane < 3; plane++) {
- int w = src->d_w;
- int h = src->d_h;
- int x, y;
- if (plane) {
- w >>= src->x_chroma_shift;
- h >>= src->y_chroma_shift;
- }
- for (y = 0; y < h; y++) {
- uint16_t *p_src = (uint16_t *)(src->planes[plane] +
- y * src->stride[plane]);
- uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
- for (x = 0; x < w; x++) {
- *p_dst++ = *p_src++;
- }
- }
- }
-}
-#endif
-
static void test_decode(struct stream_state *stream,
enum TestDecodeFatality fatal,
const VpxInterface *codec) {
@@ -1884,12 +1755,12 @@ static void test_decode(struct stream_state *stream,
if (enc_img.fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
vpx_img_alloc(&enc_img, enc_img.fmt - VPX_IMG_FMT_HIGHBITDEPTH,
enc_img.d_w, enc_img.d_h, 16);
- img_cast_16_to_8(&enc_img, &ref_enc.img);
+ vpx_img_truncate_16_to_8(&enc_img, &ref_enc.img);
}
if (dec_img.fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
vpx_img_alloc(&dec_img, dec_img.fmt - VPX_IMG_FMT_HIGHBITDEPTH,
dec_img.d_w, dec_img.d_h, 16);
- img_cast_16_to_8(&dec_img, &ref_dec.img);
+ vpx_img_cast_16_to_8(&dec_img, &ref_dec.img);
}
}
#endif
@@ -2200,7 +2071,7 @@ int main(int argc, const char **argv_) {
input.width, input.height, 32);
allocated_raw_shift = 1;
}
- img_upshift(&raw_shift, &raw, input_shift);
+ vpx_img_upshift(&raw_shift, &raw, input_shift);
frame_to_encode = &raw_shift;
} else {
frame_to_encode = &raw;