Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,20 @@ public void initializeFromIntent(Intent intent, Bundle savedInstanceState) {
protected void lockOrientation() {
// Only get the orientation if it's not locked to one yet.
if (this.orientationLock == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
// Adapted from http://stackoverflow.com/a/14565436
Display display = activity.getWindowManager().getDefaultDisplay();
int rotation = display.getRotation();
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
int displayRotation = defaultDisplay.getRotation();
int baseOrientation = activity.getResources().getConfiguration().orientation;

int orientation = 0;

if (baseOrientation == Configuration.ORIENTATION_LANDSCAPE) {
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
if (displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90) {
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else {
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
}
} else if (baseOrientation == Configuration.ORIENTATION_PORTRAIT) {
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) {
if (displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_270) {
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else {
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ public RawImageData rotateCameraPreview(int cameraRotation) {
* @return the rotated bytes
*/
public static byte[] rotateCW(byte[] data, int imageWidth, int imageHeight) {
// Adapted from http://stackoverflow.com/a/15775173
// data may contain more than just y (u and v), but we are only interested in the y section.

byte[] yuv = new byte[imageWidth * imageHeight];
int i = 0;
byte[] flippedLuma = new byte[imageWidth * imageHeight];

int destIndex = 0;
for (int x = 0; x < imageWidth; x++) {
for (int y = imageHeight - 1; y >= 0; y--) {
yuv[i] = data[y * imageWidth + x];
i++;
flippedLuma[destIndex] = data[y * imageWidth + x];
destIndex++;
}
}
return yuv;
return flippedLuma;
}

/**
Expand Down