Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed formatting
  • Loading branch information
mvanbeusekom committed Apr 20, 2021
commit f7807420ba1963eb937104a05d7cca1519774dea
Original file line number Diff line number Diff line change
Expand Up @@ -14,155 +14,153 @@
import android.util.Size;
import androidx.annotation.RequiresApi;

/**
* An interface allowing access to the different characteristics of the device's camera.
*/
/** An interface allowing access to the different characteristics of the device's camera. */
public interface CameraProperties {
String getCameraName();
String getCameraName();

Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges();
Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges();

Range<Integer> getControlAutoExposureCompensationRange();
Range<Integer> getControlAutoExposureCompensationRange();

double getControlAutoExposureCompensationStep();
double getControlAutoExposureCompensationStep();

int[] getControlAutoFocusAvailableModes();
int[] getControlAutoFocusAvailableModes();

Integer getControlMaxRegionsAutoExposure();
Integer getControlMaxRegionsAutoExposure();

Integer getControlMaxRegionsAutoFocus();
Integer getControlMaxRegionsAutoFocus();

int[] getDistortionCorrectionAvailableModes();
int[] getDistortionCorrectionAvailableModes();

Boolean getFlashInfoAvailable();
Boolean getFlashInfoAvailable();

int getLensFacing();
int getLensFacing();

Float getLensInfoMinimumFocusDistance();
Float getLensInfoMinimumFocusDistance();

Float getScalerAvailableMaxDigitalZoom();
Float getScalerAvailableMaxDigitalZoom();

Rect getSensorInfoActiveArraySize();
Rect getSensorInfoActiveArraySize();

Size getSensorInfoPixelArraySize();
Size getSensorInfoPixelArraySize();

Rect getSensorInfoPreCorrectionActiveArraySize();
Rect getSensorInfoPreCorrectionActiveArraySize();

int getSensorOrientation();
int getSensorOrientation();

int getHardwareLevel();
int getHardwareLevel();

int[] getAvailableNoiseReductionModes();
int[] getAvailableNoiseReductionModes();
}

/**
* Implementation of the @see CameraProperties interface using the @see android.hardware.camera2.CameraCharacteristics
* class to access the different characteristics.
* Implementation of the @see CameraProperties interface using the @see
* android.hardware.camera2.CameraCharacteristics class to access the different characteristics.
*/
class CameraPropertiesImpl implements CameraProperties {
private final CameraCharacteristics cameraCharacteristics;
private final String cameraName;

public CameraPropertiesImpl(String cameraName, CameraManager cameraManager)
throws CameraAccessException {
this.cameraName = cameraName;
this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
}

@Override
public String getCameraName() {
return cameraName;
}

@Override
public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
}

@Override
public Range<Integer> getControlAutoExposureCompensationRange() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
}

@Override
public double getControlAutoExposureCompensationStep() {
Rational rational =
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);

return rational == null ? 0.0 : rational.doubleValue();
}

@Override
public int[] getControlAutoFocusAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
}

@Override
public Integer getControlMaxRegionsAutoExposure() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
}

@Override
public Integer getControlMaxRegionsAutoFocus() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
}

@RequiresApi(api = VERSION_CODES.P)
@Override
public int[] getDistortionCorrectionAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
}

@Override
public Boolean getFlashInfoAvailable() {
return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
}

@Override
public int getLensFacing() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
}

@Override
public Float getLensInfoMinimumFocusDistance() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
}

@Override
public Float getScalerAvailableMaxDigitalZoom() {
return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
}

@Override
public Rect getSensorInfoActiveArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
}

@Override
public Size getSensorInfoPixelArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
}

@RequiresApi(api = VERSION_CODES.M)
@Override
public Rect getSensorInfoPreCorrectionActiveArraySize() {
return cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
}

@Override
public int getSensorOrientation() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}

@Override
public int getHardwareLevel() {
return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
}

@Override
public int[] getAvailableNoiseReductionModes() {
return cameraCharacteristics.get(
CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES);
}
}
private final CameraCharacteristics cameraCharacteristics;
private final String cameraName;

public CameraPropertiesImpl(String cameraName, CameraManager cameraManager)
throws CameraAccessException {
this.cameraName = cameraName;
this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
}

@Override
public String getCameraName() {
return cameraName;
}

@Override
public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
}

@Override
public Range<Integer> getControlAutoExposureCompensationRange() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
}

@Override
public double getControlAutoExposureCompensationStep() {
Rational rational =
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);

return rational == null ? 0.0 : rational.doubleValue();
}

@Override
public int[] getControlAutoFocusAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
}

@Override
public Integer getControlMaxRegionsAutoExposure() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
}

@Override
public Integer getControlMaxRegionsAutoFocus() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
}

@RequiresApi(api = VERSION_CODES.P)
@Override
public int[] getDistortionCorrectionAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
}

@Override
public Boolean getFlashInfoAvailable() {
return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
}

@Override
public int getLensFacing() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
}

@Override
public Float getLensInfoMinimumFocusDistance() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
}

@Override
public Float getScalerAvailableMaxDigitalZoom() {
return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
}

@Override
public Rect getSensorInfoActiveArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
}

@Override
public Size getSensorInfoPixelArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
}

@RequiresApi(api = VERSION_CODES.M)
@Override
public Rect getSensorInfoPreCorrectionActiveArraySize() {
return cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
}

@Override
public int getSensorOrientation() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}

@Override
public int getHardwareLevel() {
return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
}

@Override
public int[] getAvailableNoiseReductionModes() {
return cameraCharacteristics.get(
CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@
* @param <T>
*/
public abstract class CameraFeature<T> {
protected final CameraProperties cameraProperties;

protected CameraFeature(@NonNull CameraProperties cameraProperties) {
this.cameraProperties = cameraProperties;
}

/** Debug name for this feature. */
public abstract String getDebugName();

/**
* Get the current value of this feature's setting.
*
* @return
*/
public abstract T getValue();

/**
* Set a new value for this feature's setting.
*
* @param value
*/
public abstract void setValue(T value);

/**
* Returns whether or not this feature is supported.
*
* @return
*/
public abstract boolean checkIsSupported();

/**
* Update the setting in a provided request builder.
*
* @param requestBuilder
*/
public abstract void updateBuilder(CaptureRequest.Builder requestBuilder);
}
protected final CameraProperties cameraProperties;

protected CameraFeature(@NonNull CameraProperties cameraProperties) {
this.cameraProperties = cameraProperties;
}

/** Debug name for this feature. */
public abstract String getDebugName();

/**
* Get the current value of this feature's setting.
*
* @return
*/
public abstract T getValue();

/**
* Set a new value for this feature's setting.
*
* @param value
*/
public abstract void setValue(T value);

/**
* Returns whether or not this feature is supported.
*
* @return
*/
public abstract boolean checkIsSupported();

/**
* Update the setting in a provided request builder.
*
* @param requestBuilder
*/
public abstract void updateBuilder(CaptureRequest.Builder requestBuilder);
}
Loading