shithub: libvpx

Download patch

ref: 8121366fd1c587b7975a416d7d87717010c4eb94
parent: 374eaf20e76e2a9413329ed11f16613ed2687edb
parent: 2bdd43d8d4295f41d1dceecefbaa4855b0dc4634
author: Dmitry Kovalev <dkovalev@google.com>
date: Wed Feb 12 16:44:21 EST 2014

Merge "Adding and reusing vpx_img_plane_{width, height}() functions."

--- 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) {
--- 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
--- 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);
--