|
|
@ -157,10 +157,11 @@ public class BitmapUtil {
|
|
|
|
final int width,
|
|
|
|
final int width,
|
|
|
|
final int height,
|
|
|
|
final int height,
|
|
|
|
int rotation,
|
|
|
|
int rotation,
|
|
|
|
final Rect croppingRect)
|
|
|
|
final Rect croppingRect,
|
|
|
|
|
|
|
|
final boolean flipHorizontal)
|
|
|
|
throws IOException
|
|
|
|
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 rotatedWidth = rotation % 180 > 0 ? height : width;
|
|
|
|
final int rotatedHeight = rotation % 180 > 0 ? width : height;
|
|
|
|
final int rotatedHeight = rotation % 180 > 0 ? width : height;
|
|
|
|
YuvImage previewImage = new YuvImage(rotated, ImageFormat.NV21,
|
|
|
|
YuvImage previewImage = new YuvImage(rotated, ImageFormat.NV21,
|
|
|
@ -183,7 +184,8 @@ public class BitmapUtil {
|
|
|
|
public static byte[] rotateNV21(@NonNull final byte[] yuv,
|
|
|
|
public static byte[] rotateNV21(@NonNull final byte[] yuv,
|
|
|
|
final int width,
|
|
|
|
final int width,
|
|
|
|
final int height,
|
|
|
|
final int height,
|
|
|
|
final int rotation)
|
|
|
|
final int rotation,
|
|
|
|
|
|
|
|
final boolean flipHorizontal)
|
|
|
|
throws IOException
|
|
|
|
throws IOException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (rotation == 0) return yuv;
|
|
|
|
if (rotation == 0) return yuv;
|
|
|
@ -196,7 +198,7 @@ public class BitmapUtil {
|
|
|
|
final byte[] output = new byte[yuv.length];
|
|
|
|
final byte[] output = new byte[yuv.length];
|
|
|
|
final int frameSize = width * height;
|
|
|
|
final int frameSize = width * height;
|
|
|
|
final boolean swap = rotation % 180 != 0;
|
|
|
|
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;
|
|
|
|
final boolean yflip = rotation >= 180;
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < height; j++) {
|
|
|
|
for (int j = 0; j < height; j++) {
|
|
|
|