OSDN Git Service

Camera2: add toString for two params classes
authorYin-Chia Yeh <yinchiayeh@google.com>
Wed, 20 Aug 2014 16:48:33 +0000 (09:48 -0700)
committerYin-Chia Yeh <yinchiayeh@google.com>
Thu, 21 Aug 2014 15:28:17 +0000 (08:28 -0700)
Add toString for RggbChannelVector and ColorSpaceTransform.
Also change ColorSpaceTransform equals implementation to actually
compare the underlying rationals.

bug 16963063

Change-Id: I858153b405bc3541959be79962db750d429413a3

core/java/android/hardware/camera2/params/ColorSpaceTransform.java
core/java/android/hardware/camera2/params/RggbChannelVector.java

index b4289db..1e1c4b1 100644 (file)
@@ -225,7 +225,18 @@ public final class ColorSpaceTransform {
         }
         if (obj instanceof ColorSpaceTransform) {
             final ColorSpaceTransform other = (ColorSpaceTransform) obj;
-            return Arrays.equals(mElements, other.mElements);
+            for (int i = 0, j = 0; i < COUNT; ++i, j += RATIONAL_SIZE) {
+                int numerator = mElements[j + OFFSET_NUMERATOR];
+                int denominator = mElements[j + OFFSET_DENOMINATOR];
+                int numeratorOther = other.mElements[j + OFFSET_NUMERATOR];
+                int denominatorOther = other.mElements[j + OFFSET_DENOMINATOR];
+                Rational r = new Rational(numerator, denominator);
+                Rational rOther = new Rational(numeratorOther, denominatorOther);
+                if (!r.equals(rOther)) {
+                    return false;
+                }
+            }
+            return true;
         }
         return false;
     }
@@ -238,5 +249,51 @@ public final class ColorSpaceTransform {
         return HashCodeHelpers.hashCode(mElements);
     }
 
+    /**
+     * Return the color space transform as a string representation.
+     *
+     *  <p> Example:
+     * {@code "ColorSpaceTransform([1/1, 0/1, 0/1], [0/1, 1/1, 0/1], [0/1, 0/1, 1/1])"} is an
+     * identity transform. Elements are printed in row major order. </p>
+     *
+     * @return string representation of color space transform
+     */
+    @Override
+    public String toString() {
+        return String.format("ColorSpaceTransform%s", toShortString());
+    }
+
+    /**
+     * Return the color space transform as a compact string representation.
+     *
+     *  <p> Example:
+     * {@code "([1/1, 0/1, 0/1], [0/1, 1/1, 0/1], [0/1, 0/1, 1/1])"} is an identity transform.
+     * Elements are printed in row major order. </p>
+     *
+     * @return compact string representation of color space transform
+     */
+    private String toShortString() {
+        StringBuilder sb = new StringBuilder("(");
+        for (int row = 0, i = 0; row < ROWS; row++) {
+            sb.append("[");
+            for (int col = 0; col < COLUMNS; col++, i += RATIONAL_SIZE) {
+                int numerator = mElements[i + OFFSET_NUMERATOR];
+                int denominator = mElements[i + OFFSET_DENOMINATOR];
+                sb.append(numerator);
+                sb.append("/");
+                sb.append(denominator);
+                if (col < COLUMNS - 1) {
+                    sb.append(", ");
+                }
+            }
+            sb.append("]");
+            if (row < ROWS - 1) {
+                sb.append(", ");
+            }
+        }
+        sb.append(")");
+        return sb.toString();
+    }
+
     private final int[] mElements;
-};
+}
index cf3e1de..e08ec55 100644 (file)
@@ -190,6 +190,32 @@ public final class RggbChannelVector {
                 Float.floatToIntBits(mBlue);
     }
 
+    /**
+     * Return the RggbChannelVector as a string representation.
+     *
+     * <p> {@code "RggbChannelVector{R:%f, G_even:%f, G_odd:%f, B:%f}"}, where each
+     * {@code %f} respectively represents one of the the four color channels. </p>
+     *
+     * @return string representation of {@link RggbChannelVector}
+     */
+    @Override
+    public String toString() {
+        return String.format("RggbChannelVector%s", toShortString());
+    }
+
+    /**
+     * Return the RggbChannelVector as a string in compact form.
+     *
+     * <p> {@code "{R:%f, G_even:%f, G_odd:%f, B:%f}"}, where each {@code %f}
+     * respectively represents one of the the four color channels. </p>
+     *
+     * @return compact string representation of {@link RggbChannelVector}
+     */
+    private String toShortString() {
+        return String.format("{R:%f, G_even:%f, G_odd:%f, B:%f}",
+                mRed, mGreenEven, mGreenOdd, mBlue);
+    }
+
     private final float mRed;
     private final float mGreenEven;
     private final float mGreenOdd;