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

Commit

Permalink
Merge branch 'rramprasad-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushyanth Maguluru committed Jul 29, 2017
2 parents 5a3ed7c + eedf9d5 commit 641a06e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.dm7.barcodescanner.core;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
Expand Down Expand Up @@ -304,5 +305,46 @@ public void setShouldScaleToFill(boolean shouldScaleToFill) {
public void setAspectTolerance(float aspectTolerance) {
mAspectTolerance = aspectTolerance;
}

public byte[] getRotatedData(byte[] data, Camera camera) {
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++) {
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
}
}

return data;
}
}

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 Expand Up @@ -86,17 +84,7 @@ public void onPreviewFrame(byte[] data, Camera camera) {
int width = size.width;
int height = size.height;

if(DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
}
data = getRotatedData(data, camera);

Image barcode = new Image(width, height, "Y800");
barcode.setData(data);
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 Expand Up @@ -106,17 +104,7 @@ public void onPreviewFrame(byte[] data, Camera camera) {
int width = size.width;
int height = size.height;

if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
}
data = getRotatedData(data, camera);

Result rawResult = null;
PlanarYUVLuminanceSource source = buildLuminanceSource(data, width, height);
Expand Down

0 comments on commit 641a06e

Please sign in to comment.