From 1b5cc94e065c5fa99a050e5b43e5341be3b66c07 Mon Sep 17 00:00:00 2001 From: Tim Lindner Date: Mon, 29 Sep 2025 15:35:21 +0200 Subject: [PATCH] rewrite copyleft code from stackoverflow --- .../journeyapps/barcodescanner/CaptureManager.java | 11 ++++++----- .../com/journeyapps/barcodescanner/RawImageData.java | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/CaptureManager.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/CaptureManager.java index 6e35b10a3..6ba53bf85 100644 --- a/zxing-android-embedded/src/com/journeyapps/barcodescanner/CaptureManager.java +++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/CaptureManager.java @@ -190,19 +190,20 @@ public void initializeFromIntent(Intent intent, Bundle savedInstanceState) { protected void lockOrientation() { // Only get the orientation if it's not locked to one yet. if (this.orientationLock == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { - // Adapted from http://stackoverflow.com/a/14565436 - Display display = activity.getWindowManager().getDefaultDisplay(); - int rotation = display.getRotation(); + Display defaultDisplay = activity.getWindowManager().getDefaultDisplay(); + int displayRotation = defaultDisplay.getRotation(); int baseOrientation = activity.getResources().getConfiguration().orientation; + int orientation = 0; + if (baseOrientation == Configuration.ORIENTATION_LANDSCAPE) { - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { + if (displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90) { orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else { orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else if (baseOrientation == Configuration.ORIENTATION_PORTRAIT) { - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) { + if (displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_270) { orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else { orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/RawImageData.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/RawImageData.java index 12455ae06..0e059c5f9 100644 --- a/zxing-android-embedded/src/com/journeyapps/barcodescanner/RawImageData.java +++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/RawImageData.java @@ -85,18 +85,18 @@ public RawImageData rotateCameraPreview(int cameraRotation) { * @return the rotated bytes */ public static byte[] rotateCW(byte[] data, int imageWidth, int imageHeight) { - // Adapted from http://stackoverflow.com/a/15775173 // data may contain more than just y (u and v), but we are only interested in the y section. - byte[] yuv = new byte[imageWidth * imageHeight]; - int i = 0; + byte[] flippedLuma = new byte[imageWidth * imageHeight]; + + int destIndex = 0; for (int x = 0; x < imageWidth; x++) { for (int y = imageHeight - 1; y >= 0; y--) { - yuv[i] = data[y * imageWidth + x]; - i++; + flippedLuma[destIndex] = data[y * imageWidth + x]; + destIndex++; } } - return yuv; + return flippedLuma; } /**