Fix setSnapshotMaxWidth / Height bugs

pull/704/head
Mattia Iavarone 6 years ago
parent db1c60a948
commit f7a95e1ff1
  1. 114
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  2. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java
  3. 4
      cameraview/src/main/res/values/attrs.xml

@ -201,6 +201,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
boolean pictureSnapshotMetering = a.getBoolean(
R.styleable.CameraView_cameraPictureSnapshotMetering,
DEFAULT_PICTURE_SNAPSHOT_METERING);
int snapshotMaxWidth = a.getInteger(R.styleable.CameraView_cameraSnapshotMaxWidth, 0);
int snapshotMaxHeight = a.getInteger(R.styleable.CameraView_cameraSnapshotMaxHeight, 0);
// Size selectors and gestures
SizeSelectorParser sizeSelectors = new SizeSelectorParser(a);
@ -257,6 +259,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoBitRate(videoBitRate);
setAutoFocusResetDelay(autoFocusResetDelay);
setPreviewFrameRate(videoFrameRate);
setSnapshotMaxWidth(snapshotMaxWidth);
setSnapshotMaxHeight(snapshotMaxHeight);
// Apply gestures
mapGesture(Gesture.TAP, gestures.getTapAction());
@ -966,6 +970,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoBitRate(oldEngine.getVideoBitRate());
setAutoFocusResetDelay(oldEngine.getAutoFocusResetDelay());
setPreviewFrameRate(oldEngine.getPreviewFrameRate());
setSnapshotMaxWidth(oldEngine.getSnapshotMaxWidth());
setSnapshotMaxHeight(oldEngine.getSnapshotMaxHeight());
}
/**
@ -1553,47 +1559,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mListeners.clear();
}
/**
* Adds a {@link FrameProcessor} instance to be notified of
* new frames in the preview stream.
*
* @param processor a frame processor.
*/
public void addFrameProcessor(@Nullable FrameProcessor processor) {
if (processor != null) {
mFrameProcessors.add(processor);
if (mFrameProcessors.size() == 1) {
mCameraEngine.setHasFrameProcessors(true);
}
}
}
/**
* Remove a {@link FrameProcessor} that was previously registered.
*
* @param processor a frame processor
*/
public void removeFrameProcessor(@Nullable FrameProcessor processor) {
if (processor != null) {
mFrameProcessors.remove(processor);
if (mFrameProcessors.size() == 0) {
mCameraEngine.setHasFrameProcessors(false);
}
}
}
/**
* Clears the list of {@link FrameProcessor} that have been registered
* to preview frames.
*/
public void clearFrameProcessors() {
boolean had = mFrameProcessors.size() > 0;
mFrameProcessors.clear();
if (had) {
mCameraEngine.setHasFrameProcessors(false);
}
}
/**
* Asks the camera to capture an image of the current scene.
* This will trigger {@link CameraListener#onPictureTaken(PictureResult)} if a listener
@ -2275,6 +2240,73 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
//endregion
//region Frame Processing
/**
* Adds a {@link FrameProcessor} instance to be notified of
* new frames in the preview stream.
*
* @param processor a frame processor.
*/
public void addFrameProcessor(@Nullable FrameProcessor processor) {
if (processor != null) {
mFrameProcessors.add(processor);
if (mFrameProcessors.size() == 1) {
mCameraEngine.setHasFrameProcessors(true);
}
}
}
/**
* Remove a {@link FrameProcessor} that was previously registered.
*
* @param processor a frame processor
*/
public void removeFrameProcessor(@Nullable FrameProcessor processor) {
if (processor != null) {
mFrameProcessors.remove(processor);
if (mFrameProcessors.size() == 0) {
mCameraEngine.setHasFrameProcessors(false);
}
}
}
/**
* Clears the list of {@link FrameProcessor} that have been registered
* to preview frames.
*/
public void clearFrameProcessors() {
boolean had = mFrameProcessors.size() > 0;
mFrameProcessors.clear();
if (had) {
mCameraEngine.setHasFrameProcessors(false);
}
}
/**
* Sets the max width for frame processing {@link Frame}s.
* This option is only supported by {@link Camera2Engine} and will have no effect
* on other engines.
*
* @param maxWidth max width for frames
*/
public void setFrameProcessingMaxWidth(int maxWidth) {
mCameraEngine.setFrameProcessingMaxWidth(maxWidth);
}
/**
* Sets the max height for frame processing {@link Frame}s.
* This option is only supported by {@link Camera2Engine} and will have no effect
* on other engines.
*
* @param maxHeight max height for frames
*/
public void setFrameProcessingMaxHeight(int maxHeight) {
mCameraEngine.setFrameProcessingMaxHeight(maxHeight);
}
//endregion
//region Overlays
@Override

@ -78,8 +78,8 @@ public abstract class CameraBaseEngine extends CameraEngine {
private int mAudioBitRate;
private boolean mHasFrameProcessors;
private long mAutoFocusResetDelayMillis;
private int mSnapshotMaxWidth = Integer.MAX_VALUE; // in REF_VIEW like SizeSelectors
private int mSnapshotMaxHeight = Integer.MAX_VALUE; // in REF_VIEW like SizeSelectors
private int mSnapshotMaxWidth; // in REF_VIEW like SizeSelectors
private int mSnapshotMaxHeight; // in REF_VIEW like SizeSelectors
private Overlay mOverlay;
// Ops used for testing.
@ -721,6 +721,8 @@ public abstract class CameraBaseEngine extends CameraEngine {
boolean flip = getAngles().flip(reference, Reference.VIEW);
int maxWidth = flip ? mSnapshotMaxHeight : mSnapshotMaxWidth;
int maxHeight = flip ? mSnapshotMaxWidth : mSnapshotMaxHeight;
if (maxWidth <= 0) maxWidth = Integer.MAX_VALUE;
if (maxHeight <= 0) maxHeight = Integer.MAX_VALUE;
float baseRatio = AspectRatio.of(baseSize).toFloat();
float maxValuesRatio = AspectRatio.of(maxWidth, maxHeight).toFloat();
if (maxValuesRatio >= baseRatio) {

@ -25,8 +25,8 @@
<attr name="cameraSnapshotMaxWidth" format="integer|reference" />
<attr name="cameraSnapshotMaxHeight" format="integer|reference" />
<!--attr name="cameraFrameProcessingMaxWidth" format="integer|reference" />
<attr name="cameraFrameProcessingMaxHeight" format="integer|reference" /-->
<attr name="cameraFrameProcessingMaxWidth" format="integer|reference" />
<attr name="cameraFrameProcessingMaxHeight" format="integer|reference" />
<attr name="cameraVideoBitRate" format="integer|reference" />
<attr name="cameraAudioBitRate" format="integer|reference" />

Loading…
Cancel
Save