]> granicus.if.org Git - libvpx/commitdiff
Fix image width alignment. Enable ImageSizeSetting test.
authorJerome Jiang <jianj@google.com>
Wed, 27 Sep 2017 18:08:37 +0000 (11:08 -0700)
committerJerome Jiang <jianj@google.com>
Thu, 28 Sep 2017 18:25:24 +0000 (11:25 -0700)
BUG=b/64710201

Change-Id: I5465f6c6481d3c9a5e00fcab024cf4ae562b6b01

test/encode_api_test.cc
vpx/src/vpx_image.c

index cad4c0e471c10630dd57a81f4ac3a6ce1a1d26f8..164db5a7bc413b27b99c3d7183a4b76614012865 100644 (file)
@@ -80,7 +80,7 @@ TEST(EncodeAPI, HighBitDepthCapability) {
 }
 
 #if CONFIG_VP8_ENCODER
-TEST(EncodeAPI, DISABLED_ImageSizeSetting) {
+TEST(EncodeAPI, ImageSizeSetting) {
   const int width = 711;
   const int height = 360;
   const int bps = 12;
index dba439c10a8490f82e1a7dc03f2f90f7f66309ca..ebd3d7f7456b88b2836a21a318e7edeb987b9874 100644 (file)
@@ -88,11 +88,10 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt,
     default: ycs = 0; break;
   }
 
-  /* Calculate storage sizes given the chroma subsampling */
-  align = (1 << xcs) - 1;
-  w = (d_w + align) & ~align;
-  align = (1 << ycs) - 1;
-  h = (d_h + align) & ~align;
+  /* Calculate storage sizes. If the buffer was allocated externally, the width
+   * and height shouldn't be adjusted. */
+  w = d_w;
+  h = d_h;
   s = (fmt & VPX_IMG_FMT_PLANAR) ? w : bps * w / 8;
   s = (s + stride_align - 1) & ~(stride_align - 1);
   stride_in_bytes = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s;
@@ -111,9 +110,18 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt,
   img->img_data = img_data;
 
   if (!img_data) {
-    const uint64_t alloc_size = (fmt & VPX_IMG_FMT_PLANAR)
-                                    ? (uint64_t)h * s * bps / 8
-                                    : (uint64_t)h * s;
+    uint64_t alloc_size;
+    /* Calculate storage sizes given the chroma subsampling */
+    align = xcs ? (1 << xcs) - 1 : 1;
+    w = (d_w + align - 1) & ~(align - 1);
+    align = ycs ? (1 << ycs) - 1 : 1;
+    h = (d_h + align - 1) & ~(align - 1);
+
+    s = (fmt & VPX_IMG_FMT_PLANAR) ? w : bps * w / 8;
+    s = (s + stride_align - 1) & ~(stride_align - 1);
+    stride_in_bytes = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s;
+    alloc_size = (fmt & VPX_IMG_FMT_PLANAR) ? (uint64_t)h * s * bps / 8
+                                            : (uint64_t)h * s;
 
     if (alloc_size != (size_t)alloc_size) goto fail;