Adding and reusing vpx_img_plane_{width, height}() functions.
Change-Id: I668afb50614644d2eac2e968e1fafd6d73170bec
diff --git a/tools_common.c b/tools_common.c
index 5a1b701..f0e1606 100644
--- a/tools_common.c
+++ b/tools_common.c
@@ -220,14 +220,31 @@
return NULL;
}
+// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
+// of vpx_image_t support
+int vpx_img_plane_width(const vpx_image_t *img, int plane) {
+ if (plane > 0 && img->x_chroma_shift > 0)
+ return (img->d_w + 1) >> img->x_chroma_shift;
+ else
+ return img->d_w;
+}
+
+int vpx_img_plane_height(const vpx_image_t *img, int plane) {
+ if (plane > 0 && img->y_chroma_shift > 0)
+ return (img->d_h + 1) >> img->y_chroma_shift;
+ else
+ return img->d_h;
+}
+
void vpx_img_write(const vpx_image_t *img, FILE *file) {
- int plane, y;
+ int plane;
for (plane = 0; plane < 3; ++plane) {
const unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
- const int w = plane ? (img->d_w + 1) >> 1 : img->d_w;
- const int h = plane ? (img->d_h + 1) >> 1 : img->d_h;
+ const int w = vpx_img_plane_width(img, plane);
+ const int h = vpx_img_plane_height(img, plane);
+ int y;
for (y = 0; y < h; ++y) {
fwrite(buf, 1, w, file);
@@ -242,8 +259,8 @@
for (plane = 0; plane < 3; ++plane) {
unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
- const int w = plane ? (img->d_w + 1) >> 1 : img->d_w;
- const int h = plane ? (img->d_h + 1) >> 1 : img->d_h;
+ const int w = vpx_img_plane_width(img, plane);
+ const int h = vpx_img_plane_height(img, plane);
int y;
for (y = 0; y < h; ++y) {
diff --git a/tools_common.h b/tools_common.h
index da87b6d..2e90259 100644
--- a/tools_common.h
+++ b/tools_common.h
@@ -140,10 +140,9 @@
// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
// of vpx_image_t support
+int vpx_img_plane_width(const vpx_image_t *img, int plane);
+int vpx_img_plane_height(const vpx_image_t *img, int plane);
void vpx_img_write(const vpx_image_t *img, FILE *file);
-
-// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
-// of vpx_image_t support
int vpx_img_read(vpx_image_t *img, FILE *file);
#ifdef __cplusplus
diff --git a/vpxdec.c b/vpxdec.c
index 7f85fc9..e85c4fa 100644
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -229,18 +229,6 @@
}
}
-static int get_image_plane_width(int plane, const vpx_image_t *img) {
- return (plane > 0 && img->x_chroma_shift > 0) ?
- (img->d_w + 1) >> img->x_chroma_shift :
- img->d_w;
-}
-
-static int get_image_plane_height(int plane, const vpx_image_t *img) {
- return (plane > 0 && img->y_chroma_shift > 0) ?
- (img->d_h + 1) >> img->y_chroma_shift :
- img->d_h;
-}
-
static void update_image_md5(const vpx_image_t *img, const int planes[3],
MD5Context *md5) {
int i, y;
@@ -249,8 +237,8 @@
const int plane = planes[i];
const unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
- const int w = get_image_plane_width(plane, img);
- const int h = get_image_plane_height(plane, img);
+ const int w = vpx_img_plane_width(img, plane);
+ const int h = vpx_img_plane_height(img, plane);
for (y = 0; y < h; ++y) {
MD5Update(md5, buf, w);
@@ -267,8 +255,8 @@
const int plane = planes[i];
const unsigned char *buf = img->planes[plane];
const int stride = img->stride[plane];
- const int w = get_image_plane_width(plane, img);
- const int h = get_image_plane_height(plane, img);
+ const int w = vpx_img_plane_width(img, plane);
+ const int h = vpx_img_plane_height(img, plane);
for (y = 0; y < h; ++y) {
fwrite(buf, 1, w, file);