use of android.hardware.camera2.params.MeteringRectangle in project platform_frameworks_base by android.
the class CameraTestUtils method getExpectedOutputRegion.
/**
* Calculate output 3A region from the intersection of input 3A region and cropped region.
*
* @param requestRegions The input 3A regions
* @param cropRect The cropped region
* @return expected 3A regions output in capture result
*/
public static MeteringRectangle[] getExpectedOutputRegion(MeteringRectangle[] requestRegions, Rect cropRect) {
MeteringRectangle[] resultRegions = new MeteringRectangle[requestRegions.length];
for (int i = 0; i < requestRegions.length; i++) {
Rect requestRect = requestRegions[i].getRect();
Rect resultRect = new Rect();
assertTrue("Input 3A region must intersect cropped region", resultRect.setIntersect(requestRect, cropRect));
resultRegions[i] = new MeteringRectangle(resultRect, requestRegions[i].getMeteringWeight());
}
return resultRegions;
}
use of android.hardware.camera2.params.MeteringRectangle in project platform_frameworks_base by android.
the class CameraMetadataTest method testReadWriteMeteringRectangle.
@SmallTest
public void testReadWriteMeteringRectangle() {
// int32 x 5 x area_count [but we pretend it's a single element]
checkKeyMarshal("android.control.aeRegions", new MeteringRectangle(/*x*/
1, /*y*/
2, /*width*/
100, /*height*/
200, /*weight*/
5), /* xmin, ymin, xmax, ymax, weight */
toByteArray(1, 2, 1 + 100, 2 + 200, 5));
// int32 x 5 x area_count
checkKeyMarshal("android.control.afRegions", new MeteringRectangle[] { new MeteringRectangle(/*x*/
5, /*y*/
6, /*width*/
123, /*height*/
456, /*weight*/
7), new MeteringRectangle(/*x*/
7, /*y*/
8, /*width*/
456, /*height*/
999, /*weight*/
6), new MeteringRectangle(/*x*/
1, /*y*/
2, /*width*/
100, /*height*/
200, /*weight*/
5) }, toByteArray(5, 6, 5 + 123, 6 + 456, 7, 7, 8, 7 + 456, 8 + 999, 6, 1, 2, 1 + 100, 2 + 200, 5));
}
use of android.hardware.camera2.params.MeteringRectangle in project platform_frameworks_base by android.
the class LegacyMetadataMapper method createRequestTemplate.
/**
* Create a request template
*
* @param c a non-{@code null} camera characteristics for this camera
* @param templateId a non-negative template ID
*
* @return a non-{@code null} request template
*
* @throws IllegalArgumentException if {@code templateId} was invalid
*
* @see android.hardware.camera2.CameraDevice#TEMPLATE_MANUAL
*/
public static CameraMetadataNative createRequestTemplate(CameraCharacteristics c, int templateId) {
if (!ArrayUtils.contains(sAllowedTemplates, templateId)) {
throw new IllegalArgumentException("templateId out of range");
}
CameraMetadataNative m = new CameraMetadataNative();
/*
* NOTE: If adding new code here and it needs to query the static info,
* query the camera characteristics, so we can reuse this for api2 code later
* to create our own templates in the framework
*/
/*
* control.*
*/
// control.awbMode
m.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO);
// AWB is always unconditionally available in API1 devices
// control.aeAntibandingMode
m.set(CaptureRequest.CONTROL_AE_ANTIBANDING_MODE, CONTROL_AE_ANTIBANDING_MODE_AUTO);
// control.aeExposureCompensation
m.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 0);
// control.aeLock
m.set(CaptureRequest.CONTROL_AE_LOCK, false);
// control.aePrecaptureTrigger
m.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CONTROL_AE_PRECAPTURE_TRIGGER_IDLE);
// control.afTrigger
m.set(CaptureRequest.CONTROL_AF_TRIGGER, CONTROL_AF_TRIGGER_IDLE);
// control.awbMode
m.set(CaptureRequest.CONTROL_AWB_MODE, CONTROL_AWB_MODE_AUTO);
// control.awbLock
m.set(CaptureRequest.CONTROL_AWB_LOCK, false);
// control.aeRegions, control.awbRegions, control.afRegions
{
Rect activeArray = c.get(SENSOR_INFO_ACTIVE_ARRAY_SIZE);
MeteringRectangle[] activeRegions = new MeteringRectangle[] { new MeteringRectangle(/*x*/
0, /*y*/
0, /*width*/
activeArray.width() - 1, /*height*/
activeArray.height() - 1, /*weight*/
0) };
m.set(CaptureRequest.CONTROL_AE_REGIONS, activeRegions);
m.set(CaptureRequest.CONTROL_AWB_REGIONS, activeRegions);
m.set(CaptureRequest.CONTROL_AF_REGIONS, activeRegions);
}
// control.captureIntent
{
int captureIntent;
switch(templateId) {
case CameraDevice.TEMPLATE_PREVIEW:
captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
break;
case CameraDevice.TEMPLATE_STILL_CAPTURE:
captureIntent = CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
break;
case CameraDevice.TEMPLATE_RECORD:
captureIntent = CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
break;
default:
// Can't get anything else since it's guarded by the IAE check
throw new AssertionError("Impossible; keep in sync with sAllowedTemplates");
}
m.set(CaptureRequest.CONTROL_CAPTURE_INTENT, captureIntent);
}
// control.aeMode
m.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
// AE is always unconditionally available in API1 devices
// control.mode
m.set(CaptureRequest.CONTROL_MODE, CONTROL_MODE_AUTO);
// control.afMode
{
Float minimumFocusDistance = c.get(LENS_INFO_MINIMUM_FOCUS_DISTANCE);
int afMode;
if (minimumFocusDistance != null && minimumFocusDistance == LENS_INFO_MINIMUM_FOCUS_DISTANCE_FIXED_FOCUS) {
// Cannot control auto-focus with fixed-focus cameras
afMode = CameraMetadata.CONTROL_AF_MODE_OFF;
} else {
// If a minimum focus distance is reported; the camera must have AF
afMode = CameraMetadata.CONTROL_AF_MODE_AUTO;
if (templateId == CameraDevice.TEMPLATE_RECORD || templateId == CameraDevice.TEMPLATE_VIDEO_SNAPSHOT) {
if (ArrayUtils.contains(c.get(CONTROL_AF_AVAILABLE_MODES), CONTROL_AF_MODE_CONTINUOUS_VIDEO)) {
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO;
}
} else if (templateId == CameraDevice.TEMPLATE_PREVIEW || templateId == CameraDevice.TEMPLATE_STILL_CAPTURE) {
if (ArrayUtils.contains(c.get(CONTROL_AF_AVAILABLE_MODES), CONTROL_AF_MODE_CONTINUOUS_PICTURE)) {
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE;
}
}
}
if (DEBUG) {
Log.v(TAG, "createRequestTemplate (templateId=" + templateId + ")," + " afMode=" + afMode + ", minimumFocusDistance=" + minimumFocusDistance);
}
m.set(CaptureRequest.CONTROL_AF_MODE, afMode);
}
{
// control.aeTargetFpsRange
Range<Integer>[] availableFpsRange = c.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
// Pick FPS range with highest max value, tiebreak on higher min value
Range<Integer> bestRange = availableFpsRange[0];
for (Range<Integer> r : availableFpsRange) {
if (bestRange.getUpper() < r.getUpper()) {
bestRange = r;
} else if (bestRange.getUpper() == r.getUpper() && bestRange.getLower() < r.getLower()) {
bestRange = r;
}
}
m.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, bestRange);
}
// control.sceneMode -- DISABLED is always available
m.set(CaptureRequest.CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_DISABLED);
/*
* statistics.*
*/
// statistics.faceDetectMode
m.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE, STATISTICS_FACE_DETECT_MODE_OFF);
/*
* flash.*
*/
// flash.mode
m.set(CaptureRequest.FLASH_MODE, FLASH_MODE_OFF);
/*
* noiseReduction.*
*/
if (templateId == CameraDevice.TEMPLATE_STILL_CAPTURE) {
m.set(CaptureRequest.NOISE_REDUCTION_MODE, NOISE_REDUCTION_MODE_HIGH_QUALITY);
} else {
m.set(CaptureRequest.NOISE_REDUCTION_MODE, NOISE_REDUCTION_MODE_FAST);
}
/*
* colorCorrection.*
*/
if (templateId == CameraDevice.TEMPLATE_STILL_CAPTURE) {
m.set(CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE, COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY);
} else {
m.set(CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE, COLOR_CORRECTION_ABERRATION_MODE_FAST);
}
/*
* lens.*
*/
// lens.focalLength
m.set(CaptureRequest.LENS_FOCAL_LENGTH, c.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)[0]);
/*
* jpeg.*
*/
// jpeg.thumbnailSize - set smallest non-zero size if possible
Size[] sizes = c.get(CameraCharacteristics.JPEG_AVAILABLE_THUMBNAIL_SIZES);
m.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, (sizes.length > 1) ? sizes[1] : sizes[0]);
// TODO: map other request template values
return m;
}
use of android.hardware.camera2.params.MeteringRectangle in project PhotoNoter by yydcdut.
the class Camera2FocusModel method triggerFocus.
@Override
public void triggerFocus(int viewWidth, int viewHeight, int x, int y) {
if (mIsSupport) {
mState = FOCUS_STATE_FOCUSING;
float ratioRowX = ((float) x) / viewWidth;
float ratioRowY = ((float) y) / viewHeight;
float newX = (ratioRowX) * mRect.height();
float newY = (ratioRowY) * mRect.width();
float left = newX - LENGTH < mRect.left ? mRect.left : newX - LENGTH;
left = left > mRect.right ? mRect.right - 1 : left;
float right = newX + LENGTH > mRect.right ? mRect.right : newX + LENGTH;
right = right < mRect.left ? mRect.left + 1 : right;
float top = newY - LENGTH < mRect.top ? mRect.top : newY - LENGTH;
top = top > mRect.bottom ? mRect.bottom - 1 : top;
float boom = newY + LENGTH > mRect.bottom ? mRect.bottom : newY + LENGTH;
boom = boom < mRect.top ? mRect.top + 1 : boom;
MeteringRectangle meteringRectangle = new MeteringRectangle(new Rect((int) left, (int) top, (int) right, (int) boom), MeteringRectangle.METERING_WEIGHT_MAX);
mBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] { meteringRectangle });
mBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, new MeteringRectangle[] { meteringRectangle });
mBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
mBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
doChange();
}
}
use of android.hardware.camera2.params.MeteringRectangle in project android_frameworks_base by DirtyUnicorns.
the class CameraTestUtils method getExpectedOutputRegion.
/**
* Calculate output 3A region from the intersection of input 3A region and cropped region.
*
* @param requestRegions The input 3A regions
* @param cropRect The cropped region
* @return expected 3A regions output in capture result
*/
public static MeteringRectangle[] getExpectedOutputRegion(MeteringRectangle[] requestRegions, Rect cropRect) {
MeteringRectangle[] resultRegions = new MeteringRectangle[requestRegions.length];
for (int i = 0; i < requestRegions.length; i++) {
Rect requestRect = requestRegions[i].getRect();
Rect resultRect = new Rect();
assertTrue("Input 3A region must intersect cropped region", resultRect.setIntersect(requestRect, cropRect));
resultRegions[i] = new MeteringRectangle(resultRect, requestRegions[i].getMeteringWeight());
}
return resultRegions;
}
Aggregations