Search in sources :

Example 21 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

the class RationalTest method testEquals.

@SmallTest
public void testEquals() {
    Rational r = new Rational(1, 2);
    assertEquals(1, r.getNumerator());
    assertEquals(2, r.getDenominator());
    assertEquals(r, r);
    assertFalse(r.equals(null));
    assertFalse(r.equals(new Object()));
    Rational twoThirds = new Rational(2, 3);
    assertFalse(r.equals(twoThirds));
    assertFalse(twoThirds.equals(r));
    Rational fourSixths = new Rational(4, 6);
    assertEquals(twoThirds, fourSixths);
    assertEquals(fourSixths, twoThirds);
    Rational moreComplicated = new Rational(5 * 6 * 7 * 8 * 9, 1 * 2 * 3 * 4 * 5);
    Rational moreComplicated2 = new Rational(5 * 6 * 7 * 8 * 9 * 78, 1 * 2 * 3 * 4 * 5 * 78);
    assertEquals(moreComplicated, moreComplicated2);
    assertEquals(moreComplicated2, moreComplicated);
    // Ensure negatives are fine
    twoThirds = new Rational(-2, 3);
    fourSixths = new Rational(-4, 6);
    assertEquals(twoThirds, fourSixths);
    assertEquals(fourSixths, twoThirds);
    moreComplicated = new Rational(-5 * 6 * 7 * 8 * 9, 1 * 2 * 3 * 4 * 5);
    moreComplicated2 = new Rational(-5 * 6 * 7 * 8 * 9 * 78, 1 * 2 * 3 * 4 * 5 * 78);
    assertEquals(moreComplicated, moreComplicated2);
    assertEquals(moreComplicated2, moreComplicated);
    // Zero is always equal to itself
    Rational zero2 = new Rational(0, 100);
    assertEquals(ZERO, zero2);
    assertEquals(zero2, ZERO);
    // NaN is always equal to itself
    Rational nan = NaN;
    Rational nan2 = new Rational(0, 0);
    assertTrue(nan.equals(nan));
    assertTrue(nan.equals(nan2));
    assertTrue(nan2.equals(nan));
    assertFalse(nan.equals(r));
    assertFalse(r.equals(nan));
    // Infinities of the same sign are equal.
    Rational posInf = POSITIVE_INFINITY;
    Rational posInf2 = new Rational(2, 0);
    Rational negInf = NEGATIVE_INFINITY;
    Rational negInf2 = new Rational(-2, 0);
    assertEquals(posInf, posInf);
    assertEquals(negInf, negInf);
    assertEquals(posInf, posInf2);
    assertEquals(negInf, negInf2);
    // Infinities aren't equal to anything else.
    assertFalse(posInf.equals(negInf));
    assertFalse(negInf.equals(posInf));
    assertFalse(negInf.equals(r));
    assertFalse(posInf.equals(r));
    assertFalse(r.equals(negInf));
    assertFalse(r.equals(posInf));
    assertFalse(posInf.equals(nan));
    assertFalse(negInf.equals(nan));
    assertFalse(nan.equals(posInf));
    assertFalse(nan.equals(negInf));
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 22 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

the class ColorSpaceTransform method equals.

/**
     * Check if this {@link ColorSpaceTransform} is equal to another {@link ColorSpaceTransform}.
     *
     * <p>Two color space transforms are equal if and only if all of their elements are
     * {@link Object#equals equal}.</p>
     *
     * @return {@code true} if the objects were equal, {@code false} otherwise
     */
@Override
public boolean equals(final Object obj) {
    if (obj == null) {
        return false;
    }
    if (this == obj) {
        return true;
    }
    if (obj instanceof ColorSpaceTransform) {
        final ColorSpaceTransform other = (ColorSpaceTransform) obj;
        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;
}
Also used : Rational(android.util.Rational)

Example 23 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

the class ColorSpaceTransform method copyElements.

/**
     * Copy the {@link Rational} elements in row-major order from this matrix into the destination.
     *
     * @param destination
     *          an array big enough to hold at least {@code 9} elements after the
     *          {@code offset}
     * @param offset
     *          a non-negative offset into the array
     * @throws NullPointerException
     *          If {@code destination} was {@code null}
     * @throws ArrayIndexOutOfBoundsException
     *          If there's not enough room to write the elements at the specified destination and
     *          offset.
     */
public void copyElements(Rational[] destination, int offset) {
    checkArgumentNonnegative(offset, "offset must not be negative");
    checkNotNull(destination, "destination must not be null");
    if (destination.length - offset < COUNT) {
        throw new ArrayIndexOutOfBoundsException("destination too small to fit elements");
    }
    for (int i = 0, j = 0; i < COUNT; ++i, j += RATIONAL_SIZE) {
        int numerator = mElements[j + OFFSET_NUMERATOR];
        int denominator = mElements[j + OFFSET_DENOMINATOR];
        destination[i + offset] = new Rational(numerator, denominator);
    }
}
Also used : Rational(android.util.Rational)

Example 24 with Rational

use of android.util.Rational in project android_frameworks_base by crdroidandroid.

the class Camera2StillCaptureTest method verifyRawCaptureResult.

/**
     * Validate that raw {@link CaptureResult}.
     *
     * @param rawRequest a {@link CaptureRequest} use to capture a RAW16 image.
     * @param rawResult the {@link CaptureResult} corresponding to the given request.
     */
private void verifyRawCaptureResult(CaptureRequest rawRequest, CaptureResult rawResult) {
    assertNotNull(rawRequest);
    assertNotNull(rawResult);
    Rational[] empty = new Rational[] { Rational.ZERO, Rational.ZERO, Rational.ZERO };
    Rational[] neutralColorPoint = mCollector.expectKeyValueNotNull("NeutralColorPoint", rawResult, CaptureResult.SENSOR_NEUTRAL_COLOR_POINT);
    if (neutralColorPoint != null) {
        mCollector.expectEquals("NeutralColorPoint length", empty.length, neutralColorPoint.length);
        mCollector.expectNotEquals("NeutralColorPoint cannot be all zeroes, ", empty, neutralColorPoint);
        mCollector.expectValuesGreaterOrEqual("NeutralColorPoint", neutralColorPoint, Rational.ZERO);
    }
    mCollector.expectKeyValueGreaterOrEqual(rawResult, CaptureResult.SENSOR_GREEN_SPLIT, 0.0f);
    Pair<Double, Double>[] noiseProfile = mCollector.expectKeyValueNotNull("NoiseProfile", rawResult, CaptureResult.SENSOR_NOISE_PROFILE);
    if (noiseProfile != null) {
        mCollector.expectEquals("NoiseProfile length", noiseProfile.length, /*Num CFA channels*/
        4);
        for (Pair<Double, Double> p : noiseProfile) {
            mCollector.expectTrue("NoiseProfile coefficients " + p + " must have: S > 0, O >= 0", p.first > 0 && p.second >= 0);
        }
    }
    Integer hotPixelMode = mCollector.expectKeyValueNotNull("HotPixelMode", rawResult, CaptureResult.HOT_PIXEL_MODE);
    Boolean hotPixelMapMode = mCollector.expectKeyValueNotNull("HotPixelMapMode", rawResult, CaptureResult.STATISTICS_HOT_PIXEL_MAP_MODE);
    Point[] hotPixelMap = rawResult.get(CaptureResult.STATISTICS_HOT_PIXEL_MAP);
    Size pixelArraySize = mStaticInfo.getPixelArraySizeChecked();
    boolean[] availableHotPixelMapModes = mStaticInfo.getValueFromKeyNonNull(CameraCharacteristics.STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES);
    if (hotPixelMode != null) {
        Integer requestMode = mCollector.expectKeyValueNotNull(rawRequest, CaptureRequest.HOT_PIXEL_MODE);
        if (requestMode != null) {
            mCollector.expectKeyValueEquals(rawResult, CaptureResult.HOT_PIXEL_MODE, requestMode);
        }
    }
    if (hotPixelMapMode != null) {
        Boolean requestMapMode = mCollector.expectKeyValueNotNull(rawRequest, CaptureRequest.STATISTICS_HOT_PIXEL_MAP_MODE);
        if (requestMapMode != null) {
            mCollector.expectKeyValueEquals(rawResult, CaptureResult.STATISTICS_HOT_PIXEL_MAP_MODE, requestMapMode);
        }
        if (!hotPixelMapMode) {
            mCollector.expectTrue("HotPixelMap must be empty", hotPixelMap == null || hotPixelMap.length == 0);
        } else {
            mCollector.expectTrue("HotPixelMap must not be empty", hotPixelMap != null);
            mCollector.expectNotNull("AvailableHotPixelMapModes must not be null", availableHotPixelMapModes);
            if (availableHotPixelMapModes != null) {
                mCollector.expectContains("HotPixelMapMode", availableHotPixelMapModes, true);
            }
            int height = pixelArraySize.getHeight();
            int width = pixelArraySize.getWidth();
            for (Point p : hotPixelMap) {
                mCollector.expectTrue("Hotpixel " + p + " must be in pixelArray " + pixelArraySize, p.x >= 0 && p.x < width && p.y >= 0 && p.y < height);
            }
        }
    }
// TODO: profileHueSatMap, and profileToneCurve aren't supported yet.
}
Also used : Rational(android.util.Rational) Size(android.util.Size) Point(android.graphics.Point) Point(android.graphics.Point) Pair(android.util.Pair)

Example 25 with Rational

use of android.util.Rational in project android_frameworks_base by crdroidandroid.

the class ColorSpaceTransform method equals.

/**
     * Check if this {@link ColorSpaceTransform} is equal to another {@link ColorSpaceTransform}.
     *
     * <p>Two color space transforms are equal if and only if all of their elements are
     * {@link Object#equals equal}.</p>
     *
     * @return {@code true} if the objects were equal, {@code false} otherwise
     */
@Override
public boolean equals(final Object obj) {
    if (obj == null) {
        return false;
    }
    if (this == obj) {
        return true;
    }
    if (obj instanceof ColorSpaceTransform) {
        final ColorSpaceTransform other = (ColorSpaceTransform) obj;
        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;
}
Also used : Rational(android.util.Rational)

Aggregations

Rational (android.util.Rational)96 SmallTest (android.test.suitebuilder.annotation.SmallTest)50 Range (android.util.Range)15 Size (android.util.Size)6 Point (android.graphics.Point)5 Pair (android.util.Pair)5 InvalidObjectException (java.io.InvalidObjectException)5 PictureInPictureParams (android.app.PictureInPictureParams)4 TargetApi (android.annotation.TargetApi)3 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 RemoteAction (android.app.RemoteAction)1 Intent (android.content.Intent)1 Rect (android.graphics.Rect)1 RequiresApi (androidx.annotation.RequiresApi)1 RequiresPermission (androidx.annotation.RequiresPermission)1 CameraSelector (androidx.camera.core.CameraSelector)1 StringBuilder (java.lang.StringBuilder)1 DecimalFormat (java.text.DecimalFormat)1