From 4a926b30bb3396b3ea25ab1ec1a18347f2f4b4cc Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Fri, 2 Mar 2018 22:16:34 +0100 Subject: [PATCH] Remove cropOutput --- .../cameraview/CameraViewTest.java | 9 ---- .../otaliastudios/cameraview/CameraView.java | 53 ++----------------- cameraview/src/main/res/values/attrs.xml | 2 - 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java index a32c616b..c03dec5d 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java @@ -102,7 +102,6 @@ public class CameraViewTest extends BaseTest { // Self managed 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.LONG_TAP), GestureAction.DEFAULT_LONG_TAP); assertEquals(cameraView.getGestureAction(Gesture.PINCH), GestureAction.DEFAULT_PINCH); @@ -458,14 +457,6 @@ public class CameraViewTest extends BaseTest { //region test setParameters - @Test - public void testSetCropOutput() { - cameraView.setCropOutput(true); - assertTrue(cameraView.getCropOutput()); - cameraView.setCropOutput(false); - assertFalse(cameraView.getCropOutput()); - } - @Test public void testSetPlaySounds() { cameraView.setPlaySounds(true); diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index edc57343..fa8cc3d0 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -54,7 +54,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { final static boolean DEFAULT_PLAY_SOUNDS = true; // Self managed parameters - private boolean mCropOutput; private boolean mPlaySounds; private HashMap 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); // Self managed - boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); // Camera controller params @@ -171,7 +169,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { addView(mScrollGestureLayout); // Apply self managed - setCropOutput(cropOutput); setPlaySounds(playSounds); // 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 * interesting events that will happen during the camera lifecycle. @@ -1550,23 +1522,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { @Override public void processImage(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) { mLogger.i("processImage"); - mWorkerHandler.post(new Runnable() { - @Override - 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); - } - }); + dispatchOnPictureTaken(jpeg); + // TODO: remove. } @Override @@ -1576,16 +1533,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver { @Override public void run() { byte[] jpeg; - if (mCropOutput && mCameraPreview.isCropping()) { + if (mCameraPreview.isCropping()) { int w = consistentWithView ? getWidth() : getHeight(); int h = consistentWithView ? getHeight() : getWidth(); AspectRatio targetRatio = AspectRatio.of(w, h); mLogger.i("processSnapshot", "is consistent?", consistentWithView); mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight()); - jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 100); + jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 90); } else { 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(); } dispatchOnPictureTaken(jpeg); diff --git a/cameraview/src/main/res/values/attrs.xml b/cameraview/src/main/res/values/attrs.xml index 3fa16da2..83fdf72e 100644 --- a/cameraview/src/main/res/values/attrs.xml +++ b/cameraview/src/main/res/values/attrs.xml @@ -99,8 +99,6 @@ - -