use of android.util.Rational in project android-player-samples by BrightcoveOS.
the class SettingsModel method getPictureInPictureAspectRatio.
@TargetApi(Build.VERSION_CODES.O)
public Rational getPictureInPictureAspectRatio() {
Rational rational = null;
int numerator;
int denominator;
String rationalString = preferences.getString(PIP_ASPECT_RATIO, null);
try {
if (rationalString != null && rationalString.contains(":")) {
String[] numbers = rationalString.split(":");
numerator = Integer.parseInt(numbers[0]);
denominator = Integer.parseInt(numbers[1]);
Log.w("PIP", String.format("RATIONAL N=%s, D=%s", numerator, denominator));
rational = new Rational(numerator, denominator);
}
} catch (NumberFormatException e) {
Log.e(TAG, "Error retrieving bitrate configuration.", e);
}
return rational;
}
use of android.util.Rational in project platform_frameworks_base by android.
the class Utils method parseRationalRange.
static Range<Rational> parseRationalRange(Object o, Range<Rational> fallback) {
try {
String s = (String) o;
int ix = s.indexOf('-');
if (ix >= 0) {
return Range.create(Rational.parseRational(s.substring(0, ix)), Rational.parseRational(s.substring(ix + 1)));
}
Rational value = Rational.parseRational(s);
return Range.create(value, value);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return fallback;
} catch (IllegalArgumentException e) {
}
Log.w(TAG, "could not parse rational range '" + o + "'");
return fallback;
}
use of android.util.Rational in project platform_frameworks_base by android.
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.
}
use of android.util.Rational in project platform_frameworks_base by android.
the class StaticMetadata method getAeCompensationStepChecked.
/**
* Get value of key android.control.aeCompensationStep and do the sanity check.
*
* @return default value if the value is null.
*/
public Rational getAeCompensationStepChecked() {
Key<Rational> key = CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP;
Rational compensationStep = getValueFromKeyNonNull(key);
if (compensationStep == null) {
// Return default step.
return CONTROL_AE_COMPENSATION_STEP_DEFAULT;
}
// Legacy devices don't have a minimum step requirement
if (isHardwareLevelLimitedOrBetter()) {
float compensationStepF = (float) compensationStep.getNumerator() / compensationStep.getDenominator();
checkTrueForKey(key, " value must be no more than 1/2", compensationStepF <= 0.5f);
}
return compensationStep;
}
use of android.util.Rational in project platform_frameworks_base by android.
the class StaticMetadata method getAeCompensationRangeChecked.
/**
* Get value of key android.control.aeCompensationRange and do the sanity check.
*
* @return default value if the value is null or malformed.
*/
public Range<Integer> getAeCompensationRangeChecked() {
Key<Range<Integer>> key = CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE;
Range<Integer> compensationRange = getValueFromKeyNonNull(key);
Rational compensationStep = getAeCompensationStepChecked();
float compensationStepF = compensationStep.floatValue();
final Range<Integer> DEFAULT_RANGE = Range.create((int) (CONTROL_AE_COMPENSATION_RANGE_DEFAULT_MIN / compensationStepF), (int) (CONTROL_AE_COMPENSATION_RANGE_DEFAULT_MAX / compensationStepF));
final Range<Integer> ZERO_RANGE = Range.create(0, 0);
if (compensationRange == null) {
return ZERO_RANGE;
}
// Legacy devices don't have a minimum range requirement
if (isHardwareLevelLimitedOrBetter() && !compensationRange.equals(ZERO_RANGE)) {
checkTrueForKey(key, " range value must be at least " + DEFAULT_RANGE + ", actual " + compensationRange + ", compensation step " + compensationStep, compensationRange.getLower() <= DEFAULT_RANGE.getLower() && compensationRange.getUpper() >= DEFAULT_RANGE.getUpper());
}
return compensationRange;
}
Aggregations