Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Sep 18, 2017
1 parent 1e9ab85 commit 076e653
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/budiyev/android/codescanner/CodeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public final class CodeScanner {
private volatile List<BarcodeFormat> mFormats = ALL_FORMATS;
private volatile DecodeCallback mDecodeCallback;
private volatile Camera mCamera;
private volatile Camera.CameraInfo mCameraInfo;
private volatile Decoder mDecoder;
private volatile Point mPreviewSize;
private volatile Point mFrameSize;
Expand Down Expand Up @@ -224,6 +225,7 @@ public void releaseResources() {
mCamera.release();
mDecoder.shutdown();
mCamera = null;
mCameraInfo = null;
mDecoder = null;
mPreviewSize = null;
mFrameSize = null;
Expand All @@ -248,11 +250,12 @@ private void initialize(int width, int height) {
new InitializationThread(width, height).start();
}

private void finishInitialization(@NonNull Camera camera, @NonNull Point previewSize,
@NonNull Point frameSize, int displayOrientation) {
private void finishInitialization(@NonNull Camera camera, @NonNull Camera.CameraInfo cameraInfo,
@NonNull Point previewSize, @NonNull Point frameSize, int displayOrientation) {
mInitializeLock.lock();
try {
mCamera = camera;
mCameraInfo = cameraInfo;
mDecoder = new Decoder(mDecoderStateListener, mFormats);
mDecoder.start();
mPreviewSize = previewSize;
Expand Down Expand Up @@ -331,7 +334,8 @@ public void onPreviewFrame(byte[] data, Camera camera) {
Point previewSize = mPreviewSize;
Point frameSize = mFrameSize;
mDecoder.decode(data, previewSize.x, previewSize.y, frameSize.x, frameSize.y,
mDisplayOrientation, mScannerView.isSquareFrame(), mDecodeCallback);
mDisplayOrientation, mScannerView.isSquareFrame(),
mCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT, mDecodeCallback);
}
}

Expand Down Expand Up @@ -418,7 +422,7 @@ public void run() {
portrait ? previewSize.x : previewSize.y, mWidth, mHeight);
camera.setParameters(Utils.optimizeParameters(parameters));
camera.setDisplayOrientation(orientation);
finishInitialization(camera, previewSize, frameSize, orientation);
finishInitialization(camera, cameraInfo, previewSize, frameSize, orientation);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/budiyev/android/codescanner/DecodeTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ final class DecodeTask {
private final int mFrameHeight;
private final int mOrientation;
private final boolean mSquareFrame;
private final boolean mReverseHorizontal;
private final DecodeCallback mCallback;

public DecodeTask(@NonNull byte[] data, int dataWidth, int dataHeight, int frameWidth,
int frameHeight, int orientation, boolean squareFrame,
int frameHeight, int orientation, boolean squareFrame, boolean reverseHorizontal,
@NonNull DecodeCallback callback) {
mData = data;
mDataWidth = dataWidth;
Expand All @@ -53,6 +54,7 @@ public DecodeTask(@NonNull byte[] data, int dataWidth, int dataHeight, int frame
mFrameHeight = frameHeight;
mOrientation = orientation;
mSquareFrame = squareFrame;
mReverseHorizontal = reverseHorizontal;
mCallback = callback;
}

Expand Down Expand Up @@ -85,6 +87,7 @@ public Result decode(@NonNull MultiFormatReader reader) throws ReaderException {
mFrameHeight);
return reader.decodeWithState(new BinaryBitmap(new HybridBinarizer(
new PlanarYUVLuminanceSource(data, dataWidth, dataHeight, frameRect.left,
frameRect.top, frameRect.width(), frameRect.height(), false))));
frameRect.top, frameRect.width(), frameRect.height(),
mReverseHorizontal))));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/budiyev/android/codescanner/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public void setFormats(@NonNull List<BarcodeFormat> formats) {
}

public void decode(@NonNull byte[] data, int dataWidth, int dataHeight, int frameWidth,
int frameHeight, int orientation, boolean squareFrame,
int frameHeight, int orientation, boolean squareFrame, boolean reverseHorizontal,
@NonNull DecodeCallback decodeCallback) {
mDecodeQueue.add(new DecodeTask(data, dataWidth, dataHeight, frameWidth, frameHeight,
orientation, squareFrame, decodeCallback));
orientation, squareFrame, reverseHorizontal, decodeCallback));
}

public void start() {
Expand Down

0 comments on commit 076e653

Please sign in to comment.