fix selfie horizontal flip

Closes #4635
// FREEBIE
This commit is contained in:
Jake McGinty 2015-11-20 11:24:29 -08:00 committed by Moxie Marlinspike
parent d5bd7bcf5f
commit 3bfb123b33
2 changed files with 8 additions and 5 deletions

View File

@ -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;

View File

@ -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++) {