Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Cleanup code in getRotatedData method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushyanth Maguluru committed Jul 29, 2017
1 parent 5d5b105 commit eedf9d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.hardware.Camera;
import android.support.annotation.ColorInt;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -308,22 +307,31 @@ public void setAspectTolerance(float aspectTolerance) {
}

public byte[] getRotatedData(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
int width = size.width;
int height = size.height;
int displayOrientation = mPreview.getDisplayOrientation();

int rotationCount = 0;
switch (displayOrientation) {
case 0: rotationCount = 0; break;
case 90: rotationCount = 1; break;
case 180: rotationCount = 2; break;
case 270: rotationCount = 3; break;
}
if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
int width = size.width;
int height = size.height;

int displayOrientation = mPreview.getDisplayOrientation();

int rotationCount = 0;
switch (displayOrientation) {
case 0:
rotationCount = 0;
break;
case 90:
rotationCount = 1;
break;
case 180:
rotationCount = 2;
break;
case 270:
rotationCount = 3;
break;
}

for (int i = 0; i < rotationCount; i++) {
if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
for (int i = 0; i < rotationCount; i++) {
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.dm7.barcodescanner.zbar;

import android.content.Context;
import android.content.res.Configuration;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -20,7 +19,6 @@
import java.util.List;

import me.dm7.barcodescanner.core.BarcodeScannerView;
import me.dm7.barcodescanner.core.DisplayUtils;

public class ZBarScannerView extends BarcodeScannerView {
private static final String TAG = "ZBarScannerView";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.dm7.barcodescanner.zxing;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.hardware.Camera;
import android.os.Handler;
Expand All @@ -27,7 +26,6 @@
import java.util.Map;

import me.dm7.barcodescanner.core.BarcodeScannerView;
import me.dm7.barcodescanner.core.DisplayUtils;

public class ZXingScannerView extends BarcodeScannerView {
private static final String TAG = "ZXingScannerView";
Expand Down

0 comments on commit eedf9d5

Please sign in to comment.