Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 97376d90 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

Camera2: add toString for two params classes

Add toString for RggbChannelVector and ColorSpaceTransform.
Also change ColorSpaceTransform equals implementation to actually
compare the underlying rationals.

bug 16963063

Change-Id: I858153b405bc3541959be79962db750d429413a3
parent 3a6eba01
Loading
Loading
Loading
Loading
+59 −2
Original line number Diff line number Diff line
@@ -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;
};
}
+26 −0
Original line number Diff line number Diff line
@@ -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;