mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Better zoom utility method, and FPS method that doesn't always pick the highest FPS, and that can be given a min/max FPS
This commit is contained in:
parent
2209df1afa
commit
461d15a890
|
@ -43,6 +43,7 @@ public final class CameraConfigurationUtils {
|
||||||
private static final float MIN_EXPOSURE_COMPENSATION = 0.0f;
|
private static final float MIN_EXPOSURE_COMPENSATION = 0.0f;
|
||||||
private static final double MAX_ASPECT_DISTORTION = 0.15;
|
private static final double MAX_ASPECT_DISTORTION = 0.15;
|
||||||
private static final int MIN_FPS = 10;
|
private static final int MIN_FPS = 10;
|
||||||
|
private static final int MAX_FPS = 20;
|
||||||
private static final int AREA_PER_1000 = 400;
|
private static final int AREA_PER_1000 = 400;
|
||||||
|
|
||||||
private CameraConfigurationUtils() {
|
private CameraConfigurationUtils() {
|
||||||
|
@ -129,33 +130,33 @@ public final class CameraConfigurationUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBestPreviewFPS(Camera.Parameters parameters) {
|
public static void setBestPreviewFPS(Camera.Parameters parameters) {
|
||||||
setBestPreviewFPS(parameters, MIN_FPS);
|
setBestPreviewFPS(parameters, MIN_FPS, MAX_FPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS) {
|
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) {
|
||||||
List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange();
|
List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange();
|
||||||
Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges));
|
Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges));
|
||||||
if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) {
|
if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) {
|
||||||
int[] minimumSuitableFpsRange = null;
|
int[] suitableFPSRange = null;
|
||||||
for (int[] fpsRange : supportedPreviewFpsRanges) {
|
for (int[] fpsRange : supportedPreviewFpsRanges) {
|
||||||
int fpsMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];
|
int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX];
|
||||||
if (fpsMax >= minFPS * 1000 &&
|
int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];
|
||||||
(minimumSuitableFpsRange == null ||
|
if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) {
|
||||||
fpsMax > minimumSuitableFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX])) {
|
suitableFPSRange = fpsRange;
|
||||||
minimumSuitableFpsRange = fpsRange;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (minimumSuitableFpsRange == null) {
|
if (suitableFPSRange == null) {
|
||||||
Log.i(TAG, "No suitable FPS range?");
|
Log.i(TAG, "No suitable FPS range?");
|
||||||
} else {
|
} else {
|
||||||
int[] currentFpsRange = new int[2];
|
int[] currentFpsRange = new int[2];
|
||||||
parameters.getPreviewFpsRange(currentFpsRange);
|
parameters.getPreviewFpsRange(currentFpsRange);
|
||||||
if (Arrays.equals(currentFpsRange, minimumSuitableFpsRange)) {
|
if (Arrays.equals(currentFpsRange, suitableFPSRange)) {
|
||||||
Log.i(TAG, "FPS range already set to " + Arrays.toString(minimumSuitableFpsRange));
|
Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange));
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "Setting FPS range to " + Arrays.toString(minimumSuitableFpsRange));
|
Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange));
|
||||||
parameters.setPreviewFpsRange(minimumSuitableFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
|
parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
|
||||||
minimumSuitableFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
|
suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,14 +215,12 @@ public final class CameraConfigurationUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMaxZoom(Camera.Parameters parameters) {
|
public static void setZoom(Camera.Parameters parameters, double targetZoomRatio) {
|
||||||
int maxZoom = parameters.getMaxZoom();
|
|
||||||
Log.i(TAG, "Setting zoom to max of " + maxZoom);
|
|
||||||
setZoom(parameters, maxZoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setZoom(Camera.Parameters parameters, int zoom) {
|
|
||||||
if (parameters.isZoomSupported()) {
|
if (parameters.isZoomSupported()) {
|
||||||
|
Integer zoom = indexOfClosestZoom(parameters, targetZoomRatio);
|
||||||
|
if (zoom == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (parameters.getZoom() == zoom) {
|
if (parameters.getZoom() == zoom) {
|
||||||
Log.i(TAG, "Zoom is already set to " + zoom);
|
Log.i(TAG, "Zoom is already set to " + zoom);
|
||||||
} else {
|
} else {
|
||||||
|
@ -233,6 +232,28 @@ public final class CameraConfigurationUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Integer indexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio) {
|
||||||
|
List<Integer> ratios = parameters.getZoomRatios();
|
||||||
|
Log.i(TAG, "Zoom ratios: " + ratios);
|
||||||
|
int maxZoom = parameters.getMaxZoom();
|
||||||
|
if (ratios == null || ratios.isEmpty() || ratios.size() != maxZoom + 1) {
|
||||||
|
Log.w(TAG, "Invalid zoom ratios!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
double target100 = 100.0 * targetZoomRatio;
|
||||||
|
double smallestDiff = Double.POSITIVE_INFINITY;
|
||||||
|
int closestIndex = 0;
|
||||||
|
for (int i = 0; i < ratios.size(); i++) {
|
||||||
|
double diff = Math.abs(ratios.get(i) - target100);
|
||||||
|
if (diff < smallestDiff) {
|
||||||
|
smallestDiff = diff;
|
||||||
|
closestIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.i(TAG, "Chose zoom ratio of " + (ratios.get(closestIndex) / 100.0));
|
||||||
|
return closestIndex;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setInvertColor(Camera.Parameters parameters) {
|
public static void setInvertColor(Camera.Parameters parameters) {
|
||||||
if (Camera.Parameters.EFFECT_NEGATIVE.equals(parameters.getColorEffect())) {
|
if (Camera.Parameters.EFFECT_NEGATIVE.equals(parameters.getColorEffect())) {
|
||||||
Log.i(TAG, "Negative effect already set");
|
Log.i(TAG, "Negative effect already set");
|
||||||
|
|
|
@ -31,8 +31,10 @@ final class CameraConfigurationManager {
|
||||||
static void configure(Camera camera) {
|
static void configure(Camera camera) {
|
||||||
Camera.Parameters parameters = camera.getParameters();
|
Camera.Parameters parameters = camera.getParameters();
|
||||||
//parameters.setPreviewSize(1024, 768);
|
//parameters.setPreviewSize(1024, 768);
|
||||||
parameters.setPreviewSize(512, 288);
|
parameters.setPreviewSize(1024, 576);
|
||||||
//configureAdvanced(parameters);
|
// parameters.setPreviewSize(512, 288);
|
||||||
|
|
||||||
|
configureAdvanced(parameters);
|
||||||
camera.setParameters(parameters);
|
camera.setParameters(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +43,7 @@ final class CameraConfigurationManager {
|
||||||
CameraConfigurationUtils.setBarcodeSceneMode(parameters);
|
CameraConfigurationUtils.setBarcodeSceneMode(parameters);
|
||||||
CameraConfigurationUtils.setVideoStabilization(parameters);
|
CameraConfigurationUtils.setVideoStabilization(parameters);
|
||||||
CameraConfigurationUtils.setMetering(parameters);
|
CameraConfigurationUtils.setMetering(parameters);
|
||||||
CameraConfigurationUtils.setMaxZoom(parameters);
|
CameraConfigurationUtils.setZoom(parameters, 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue