Fix output YUV bitdepth

When the input bitstream is 8 bit, the output YUV should default to
8 bit, even if the internal storage format is 16-bit.

Change-Id: I77eea8a78a60411cfd707c7a4605365abc508200
diff --git a/aomdec.c b/aomdec.c
index 825d46d..2897761 100644
--- a/aomdec.c
+++ b/aomdec.c
@@ -890,28 +890,32 @@
         output_bit_depth = img->bit_depth;
       }
       // Shift up or down if necessary
-      if (output_bit_depth != 0 && output_bit_depth != img->bit_depth) {
+      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 (img_shifted &&
-            img_shifted_realloc_required(img, img_shifted, shifted_fmt)) {
-          aom_img_free(img_shifted);
-          img_shifted = NULL;
+
+        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 =
+                aom_img_alloc(NULL, shifted_fmt, img->d_w, img->d_h, 16);
+            img_shifted->bit_depth = output_bit_depth;
+          }
+          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 (!img_shifted) {
-          img_shifted =
-              aom_img_alloc(NULL, shifted_fmt, img->d_w, img->d_h, 16);
-          img_shifted->bit_depth = output_bit_depth;
-        }
-        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;
       }
 #endif