From 3bfb123b3332cb6c9a61aa63af925ada03b8ae42 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Fri, 20 Nov 2015 11:24:29 -0800 Subject: [PATCH] fix selfie horizontal flip Closes #4635 // FREEBIE --- .../securesms/components/camera/CameraView.java | 3 ++- src/org/thoughtcrime/securesms/util/BitmapUtil.java | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/camera/CameraView.java b/src/org/thoughtcrime/securesms/components/camera/CameraView.java index 8f0845118a..4e958ec084 100644 --- a/src/org/thoughtcrime/securesms/components/camera/CameraView.java +++ b/src/org/thoughtcrime/securesms/components/camera/CameraView.java @@ -541,7 +541,8 @@ public class CameraView extends FrameLayout { previewSize.width, previewSize.height, rotation, - croppingRect); + croppingRect, + cameraId == CameraInfo.CAMERA_FACING_FRONT); } catch (IOException e) { Log.w(TAG, e); return null; diff --git a/src/org/thoughtcrime/securesms/util/BitmapUtil.java b/src/org/thoughtcrime/securesms/util/BitmapUtil.java index 2371b3bc73..409741a995 100644 --- a/src/org/thoughtcrime/securesms/util/BitmapUtil.java +++ b/src/org/thoughtcrime/securesms/util/BitmapUtil.java @@ -157,10 +157,11 @@ public class BitmapUtil { final int width, final int height, int rotation, - final Rect croppingRect) + final Rect croppingRect, + final boolean flipHorizontal) throws IOException { - byte[] rotated = rotateNV21(data, width, height, rotation); + byte[] rotated = rotateNV21(data, width, height, rotation, flipHorizontal); final int rotatedWidth = rotation % 180 > 0 ? height : width; final int rotatedHeight = rotation % 180 > 0 ? width : height; YuvImage previewImage = new YuvImage(rotated, ImageFormat.NV21, @@ -183,7 +184,8 @@ public class BitmapUtil { public static byte[] rotateNV21(@NonNull final byte[] yuv, final int width, final int height, - final int rotation) + final int rotation, + final boolean flipHorizontal) throws IOException { if (rotation == 0) return yuv; @@ -196,7 +198,7 @@ public class BitmapUtil { final byte[] output = new byte[yuv.length]; final int frameSize = width * height; final boolean swap = rotation % 180 != 0; - final boolean xflip = rotation % 270 != 0; + final boolean xflip = flipHorizontal ? rotation % 270 == 0 : rotation % 270 != 0; final boolean yflip = rotation >= 180; for (int j = 0; j < height; j++) {