Remove cropOutput

v2
Mattia Iavarone 7 years ago
parent 74a4bac091
commit 7378e781cd
  1. 9
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  2. 53
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 2
      cameraview/src/main/res/values/attrs.xml

@ -102,7 +102,6 @@ public class CameraViewTest extends BaseTest {
// Self managed // Self managed
assertEquals(cameraView.getPlaySounds(), CameraView.DEFAULT_PLAY_SOUNDS); assertEquals(cameraView.getPlaySounds(), CameraView.DEFAULT_PLAY_SOUNDS);
assertEquals(cameraView.getCropOutput(), CameraView.DEFAULT_CROP_OUTPUT);
assertEquals(cameraView.getGestureAction(Gesture.TAP), GestureAction.DEFAULT_TAP); assertEquals(cameraView.getGestureAction(Gesture.TAP), GestureAction.DEFAULT_TAP);
assertEquals(cameraView.getGestureAction(Gesture.LONG_TAP), GestureAction.DEFAULT_LONG_TAP); assertEquals(cameraView.getGestureAction(Gesture.LONG_TAP), GestureAction.DEFAULT_LONG_TAP);
assertEquals(cameraView.getGestureAction(Gesture.PINCH), GestureAction.DEFAULT_PINCH); assertEquals(cameraView.getGestureAction(Gesture.PINCH), GestureAction.DEFAULT_PINCH);
@ -458,14 +457,6 @@ public class CameraViewTest extends BaseTest {
//region test setParameters //region test setParameters
@Test
public void testSetCropOutput() {
cameraView.setCropOutput(true);
assertTrue(cameraView.getCropOutput());
cameraView.setCropOutput(false);
assertFalse(cameraView.getCropOutput());
}
@Test @Test
public void testSetPlaySounds() { public void testSetPlaySounds() {
cameraView.setPlaySounds(true); cameraView.setPlaySounds(true);

@ -54,7 +54,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
final static boolean DEFAULT_PLAY_SOUNDS = true; final static boolean DEFAULT_PLAY_SOUNDS = true;
// Self managed parameters // Self managed parameters
private boolean mCropOutput;
private boolean mPlaySounds; private boolean mPlaySounds;
private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4);
@ -98,7 +97,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0);
// Self managed // Self managed
boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT);
boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS);
// Camera controller params // Camera controller params
@ -171,7 +169,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
addView(mScrollGestureLayout); addView(mScrollGestureLayout);
// Apply self managed // Apply self managed
setCropOutput(cropOutput);
setPlaySounds(playSounds); setPlaySounds(playSounds);
// Apply camera controller params // Apply camera controller params
@ -1070,31 +1067,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
} }
/**
* Whether we should crop the picture output to match CameraView aspect ratio.
* This is only relevant if CameraView dimensions were somehow constrained
* (e.g. by fixed value or MATCH_PARENT) and do not match internal aspect ratio.
*
* Please note that this requires additional computations after the picture is taken.
*
* @param cropOutput whether to crop
*/
public void setCropOutput(boolean cropOutput) {
this.mCropOutput = cropOutput;
}
/**
* Returns whether we should crop the picture output to match CameraView aspect ratio.
*
* @see #setCropOutput(boolean)
* @return whether we crop
*/
public boolean getCropOutput() {
return mCropOutput;
}
/** /**
* Sets a {@link CameraListener} instance to be notified of all * Sets a {@link CameraListener} instance to be notified of all
* interesting events that will happen during the camera lifecycle. * interesting events that will happen during the camera lifecycle.
@ -1550,23 +1522,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@Override @Override
public void processImage(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) { public void processImage(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) {
mLogger.i("processImage"); mLogger.i("processImage");
mWorkerHandler.post(new Runnable() { dispatchOnPictureTaken(jpeg);
@Override // TODO: remove.
public void run() {
byte[] jpeg2 = jpeg;
if (mCropOutput && mCameraPreview.isCropping()) {
// If consistent, dimensions of the jpeg Bitmap and dimensions of getWidth(), getHeight()
// Live in the same reference system.
int w = consistentWithView ? getWidth() : getHeight();
int h = consistentWithView ? getHeight() : getWidth();
AspectRatio targetRatio = AspectRatio.of(w, h);
mLogger.i("processImage", "is consistent?", consistentWithView);
mLogger.i("processImage", "viewWidth?", getWidth(), "viewHeight?", getHeight());
jpeg2 = CropHelper.cropToJpeg(jpeg, targetRatio, 100);
}
dispatchOnPictureTaken(jpeg2);
}
});
} }
@Override @Override
@ -1576,16 +1533,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@Override @Override
public void run() { public void run() {
byte[] jpeg; byte[] jpeg;
if (mCropOutput && mCameraPreview.isCropping()) { if (mCameraPreview.isCropping()) {
int w = consistentWithView ? getWidth() : getHeight(); int w = consistentWithView ? getWidth() : getHeight();
int h = consistentWithView ? getHeight() : getWidth(); int h = consistentWithView ? getHeight() : getWidth();
AspectRatio targetRatio = AspectRatio.of(w, h); AspectRatio targetRatio = AspectRatio.of(w, h);
mLogger.i("processSnapshot", "is consistent?", consistentWithView); mLogger.i("processSnapshot", "is consistent?", consistentWithView);
mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight()); mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight());
jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 100); jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 90);
} else { } else {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
yuv.compressToJpeg(new Rect(0, 0, yuv.getWidth(), yuv.getHeight()), 100, out); yuv.compressToJpeg(new Rect(0, 0, yuv.getWidth(), yuv.getHeight()), 90, out);
jpeg = out.toByteArray(); jpeg = out.toByteArray();
} }
dispatchOnPictureTaken(jpeg); dispatchOnPictureTaken(jpeg);

@ -99,8 +99,6 @@
<enum name="max2160p" value="6" /> <enum name="max2160p" value="6" />
</attr> </attr>
<attr name="cameraCropOutput" format="boolean" />
<attr name="cameraAudio" format="enum"> <attr name="cameraAudio" format="enum">
<enum name="off" value="0" /> <enum name="off" value="0" />
<enum name="on" value="1" /> <enum name="on" value="1" />

Loading…
Cancel
Save