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

Commit 641a06e

Browse files
author
Dushyanth Maguluru
committed
Merge branch 'rramprasad-master'
2 parents 5a3ed7c + eedf9d5 commit 641a06e

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

core/src/main/java/me/dm7/barcodescanner/core/BarcodeScannerView.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.dm7.barcodescanner.core;
22

33
import android.content.Context;
4+
import android.content.res.Configuration;
45
import android.content.res.TypedArray;
56
import android.graphics.Color;
67
import android.graphics.Rect;
@@ -304,5 +305,46 @@ public void setShouldScaleToFill(boolean shouldScaleToFill) {
304305
public void setAspectTolerance(float aspectTolerance) {
305306
mAspectTolerance = aspectTolerance;
306307
}
308+
309+
public byte[] getRotatedData(byte[] data, Camera camera) {
310+
if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
311+
Camera.Parameters parameters = camera.getParameters();
312+
Camera.Size size = parameters.getPreviewSize();
313+
int width = size.width;
314+
int height = size.height;
315+
316+
int displayOrientation = mPreview.getDisplayOrientation();
317+
318+
int rotationCount = 0;
319+
switch (displayOrientation) {
320+
case 0:
321+
rotationCount = 0;
322+
break;
323+
case 90:
324+
rotationCount = 1;
325+
break;
326+
case 180:
327+
rotationCount = 2;
328+
break;
329+
case 270:
330+
rotationCount = 3;
331+
break;
332+
}
333+
334+
for (int i = 0; i < rotationCount; i++) {
335+
byte[] rotatedData = new byte[data.length];
336+
for (int y = 0; y < height; y++) {
337+
for (int x = 0; x < width; x++)
338+
rotatedData[x * height + height - y - 1] = data[x + y * width];
339+
}
340+
int tmp = width;
341+
width = height;
342+
height = tmp;
343+
data = rotatedData;
344+
}
345+
}
346+
347+
return data;
348+
}
307349
}
308350

zbar/src/main/java/me/dm7/barcodescanner/zbar/ZBarScannerView.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package me.dm7.barcodescanner.zbar;
22

33
import android.content.Context;
4-
import android.content.res.Configuration;
54
import android.hardware.Camera;
65
import android.os.Handler;
76
import android.os.Looper;
@@ -20,7 +19,6 @@
2019
import java.util.List;
2120

2221
import me.dm7.barcodescanner.core.BarcodeScannerView;
23-
import me.dm7.barcodescanner.core.DisplayUtils;
2422

2523
public class ZBarScannerView extends BarcodeScannerView {
2624
private static final String TAG = "ZBarScannerView";
@@ -86,17 +84,7 @@ public void onPreviewFrame(byte[] data, Camera camera) {
8684
int width = size.width;
8785
int height = size.height;
8886

89-
if(DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
90-
byte[] rotatedData = new byte[data.length];
91-
for (int y = 0; y < height; y++) {
92-
for (int x = 0; x < width; x++)
93-
rotatedData[x * height + height - y - 1] = data[x + y * width];
94-
}
95-
int tmp = width;
96-
width = height;
97-
height = tmp;
98-
data = rotatedData;
99-
}
87+
data = getRotatedData(data, camera);
10088

10189
Image barcode = new Image(width, height, "Y800");
10290
barcode.setData(data);

zxing/src/main/java/me/dm7/barcodescanner/zxing/ZXingScannerView.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package me.dm7.barcodescanner.zxing;
22

33
import android.content.Context;
4-
import android.content.res.Configuration;
54
import android.graphics.Rect;
65
import android.hardware.Camera;
76
import android.os.Handler;
@@ -27,7 +26,6 @@
2726
import java.util.Map;
2827

2928
import me.dm7.barcodescanner.core.BarcodeScannerView;
30-
import me.dm7.barcodescanner.core.DisplayUtils;
3129

3230
public class ZXingScannerView extends BarcodeScannerView {
3331
private static final String TAG = "ZXingScannerView";
@@ -106,17 +104,7 @@ public void onPreviewFrame(byte[] data, Camera camera) {
106104
int width = size.width;
107105
int height = size.height;
108106

109-
if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
110-
byte[] rotatedData = new byte[data.length];
111-
for (int y = 0; y < height; y++) {
112-
for (int x = 0; x < width; x++)
113-
rotatedData[x * height + height - y - 1] = data[x + y * width];
114-
}
115-
int tmp = width;
116-
width = height;
117-
height = tmp;
118-
data = rotatedData;
119-
}
107+
data = getRotatedData(data, camera);
120108

121109
Result rawResult = null;
122110
PlanarYUVLuminanceSource source = buildLuminanceSource(data, width, height);

0 commit comments

Comments
 (0)