Write uint16_t samples without assuming byte order

The previous commit assumes the little-endian byte order for 16-bit
words: https://aomedia-review.googlesource.com/155722

For high bit depth, write 16-bit words directly (instead of bytes) so
that the byte order doesn't matter.

Bug: b/227207606
Change-Id: Ic93cc4a3953ff5f68f8e0517c0c2cae4d42bcd5d
diff --git a/common/rawenc.c b/common/rawenc.c
index 5f64103..aa80d2c 100644
--- a/common/rawenc.c
+++ b/common/rawenc.c
@@ -36,27 +36,29 @@
                             void *file_or_md5) {
   // Batch 8 writes for low bit-depth, 4 writes for high bit-depth.
   int bytes_per_sample;
-  uint8_t batched[BATCH_SIZE];
+  union {
+    uint8_t u8[BATCH_SIZE];
+    uint16_t u16[BATCH_SIZE / 2];
+  } batched;
   if (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
     bytes_per_sample = 2;
-    for (int i = 0; i < BATCH_SIZE; i += 2) {
-      batched[i] = 0;
-      batched[i + 1] = 1 << (img->bit_depth - 9);
+    for (int i = 0; i < BATCH_SIZE / 2; ++i) {
+      batched.u16[i] = 1 << (img->bit_depth - 1);
     }
   } else {
     bytes_per_sample = 1;
     for (int i = 0; i < BATCH_SIZE; ++i) {
-      batched[i] = 0x80;
+      batched.u8[i] = 0x80;
     }
   }
   const int samples_per_batch = BATCH_SIZE / bytes_per_sample;
   const int num_batched_writes = n / samples_per_batch;
   for (int i = 0; i < num_batched_writes; ++i) {
-    writer_func(file_or_md5, batched, sizeof(uint8_t), BATCH_SIZE);
+    writer_func(file_or_md5, batched.u8, sizeof(uint8_t), BATCH_SIZE);
   }
   const int remaining = n % samples_per_batch;
   for (int i = 0; i < remaining; ++i) {
-    writer_func(file_or_md5, batched, sizeof(uint8_t), bytes_per_sample);
+    writer_func(file_or_md5, batched.u8, sizeof(uint8_t), bytes_per_sample);
   }
 }