camera CTS: Fix RawConverter to handle stride.

Bug: 20491097
Change-Id: I7cba5b0c9e059fcacbb8283cd0e966d0e2eea7a2
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/DngCreatorTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/DngCreatorTest.java
index d5972e2..03d4502 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/DngCreatorTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/DngCreatorTest.java
@@ -369,8 +369,9 @@
                 raw.getPlanes()[0].getBuffer().get(rawPlane);
                 raw.getPlanes()[0].getBuffer().rewind();
                 RawConverter.convertToSRGB(RenderScriptSingleton.getRS(), raw.getWidth(),
-                        raw.getHeight(), rawPlane, characteristics,
-                        resultPair.second, /*offsetX*/0, /*offsetY*/0, /*out*/rawBitmap);
+                        raw.getHeight(), raw.getPlanes()[0].getRowStride(), rawPlane,
+                        characteristics, resultPair.second, /*offsetX*/0, /*offsetY*/0,
+                        /*out*/rawBitmap);
 
                 // Decompress JPEG image to a bitmap
                 byte[] compressedJpegData = CameraTestUtils.getDataFromImage(jpeg);
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/rs/RawConverter.java b/tests/tests/hardware/src/android/hardware/camera2/cts/rs/RawConverter.java
index 2cd2469..8ca650f 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/rs/RawConverter.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/rs/RawConverter.java
@@ -163,6 +163,7 @@
      * @param rs a {@link RenderScript} context to use.
      * @param inputWidth width of the input RAW16 image in pixels.
      * @param inputHeight height of the input RAW16 image in pixels.
+     * @param inputStride stride of the input RAW16 image in bytes.
      * @param rawImageInput a byte array containing a RAW16 image.
      * @param staticMetadata the {@link CameraCharacteristics} for this RAW capture.
      * @param dynamicMetadata the {@link CaptureResult} for this RAW capture.
@@ -176,7 +177,7 @@
      *                   image to be rendered.
      */
     public static void convertToSRGB(RenderScript rs, int inputWidth, int inputHeight,
-            byte[] rawImageInput, CameraCharacteristics staticMetadata,
+            int inputStride, byte[] rawImageInput, CameraCharacteristics staticMetadata,
             CaptureResult dynamicMetadata, int outputOffsetX, int outputOffsetY,
             /*out*/Bitmap argbOutput) {
         int cfa = staticMetadata.get(CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT);
@@ -209,7 +210,7 @@
 
         LensShadingMap shadingMap = dynamicMetadata.get(CaptureResult.STATISTICS_LENS_SHADING_CORRECTION_MAP);
 
-        convertToSRGB(rs, inputWidth, inputHeight, cfa, blackLevelPattern, whiteLevel,
+        convertToSRGB(rs, inputWidth, inputHeight, inputStride, cfa, blackLevelPattern, whiteLevel,
                 rawImageInput, ref1, ref2, calib1, calib2, color1, color2,
                 forward1, forward2, neutral, shadingMap, outputOffsetX, outputOffsetY, argbOutput);
     }
@@ -219,8 +220,8 @@
      *
      * @see #convertToSRGB
      */
-    private static void convertToSRGB(RenderScript rs, int inputWidth, int inputHeight, int cfa,
-            int[] blackLevelPattern, int whiteLevel, byte[] rawImageInput,
+    private static void convertToSRGB(RenderScript rs, int inputWidth, int inputHeight,
+            int inputStride, int cfa, int[] blackLevelPattern, int whiteLevel, byte[] rawImageInput,
             int referenceIlluminant1, int referenceIlluminant2, float[] calibrationTransform1,
             float[] calibrationTransform2, float[] colorMatrix1, float[] colorMatrix2,
             float[] forwardTransform1, float[] forwardTransform2, Rational[/*3*/] neutralColorPoint,
@@ -238,6 +239,12 @@
         if (outputOffsetX < 0 || outputOffsetY < 0) {
             throw new IllegalArgumentException("Negative offset passed to convertToSRGB");
         }
+        if ((inputStride / 2) < inputWidth) {
+            throw new IllegalArgumentException("Stride too small.");
+        }
+        if ((inputStride % 2) != 0) {
+            throw new IllegalArgumentException("Invalid stride for RAW16 format, see graphics.h.");
+        }
         int outWidth = argbOutput.getWidth();
         int outHeight = argbOutput.getHeight();
         if (outWidth + outputOffsetX > inputWidth || outHeight + outputOffsetY > inputHeight) {
@@ -314,7 +321,7 @@
 
         // Setup input allocation (16-bit raw pixels)
         Type.Builder typeBuilder = new Type.Builder(rs, Element.U16(rs));
-        typeBuilder.setX(inputWidth);
+        typeBuilder.setX((inputStride / 2));
         typeBuilder.setY(inputHeight);
         Type inputType = typeBuilder.create();
         Allocation input = Allocation.createTyped(rs, inputType);