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

Commit

Permalink
Merge branch 'master' of git://github.com/rramprasad/barcodescanner i…
Browse files Browse the repository at this point in the history
…nto rramprasad-master
  • Loading branch information
Dushyanth Maguluru committed Jul 29, 2017
2 parents 5a3ed7c + 6fcba74 commit 5d5b105
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;
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 @@ -304,5 +306,37 @@ public void setShouldScaleToFill(boolean shouldScaleToFill) {
public void setAspectTolerance(float aspectTolerance) {
mAspectTolerance = 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;
}

for (int i = 0; i < rotationCount; i++) {
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;
}
}

return data;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,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
Expand Up @@ -106,17 +106,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 5d5b105

Please sign in to comment.