Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1239 , Redmi RAW crash #1240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.otaliastudios.cameraview.engine.options;

import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
Expand Down Expand Up @@ -126,8 +127,31 @@ public Camera2Options(@NonNull CameraManager manager,
if (!hasPictureFormat) {
throw new IllegalStateException("Picture format not supported: " + pictureFormat);
}

// Prevent to use a RAW_SENSOR size bigger than the actual sensor size
// Fix bug and fatal error in RAW on Redmi Note 8 Pro
android.util.Size rawMaxSize = null;
if (pictureFormat == ImageFormat.RAW_SENSOR) {
// If the device doesn't report the SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
// use the SENSOR_INFO_PIXEL_ARRAY_SIZE instead.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
Rect preCorrectionActiveArrayRect =
cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
rawMaxSize = new android.util.Size(
preCorrectionActiveArrayRect.width(),preCorrectionActiveArrayRect.height());
}
if (rawMaxSize == null)
rawMaxSize = cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
}

android.util.Size[] psizes = streamMap.getOutputSizes(pictureFormat);
for (android.util.Size size : psizes) {
if (rawMaxSize != null && size.getWidth() > rawMaxSize.getWidth() &&
size.getHeight() > rawMaxSize.getHeight()) {
continue;
}
int width = flipSizes ? size.getHeight() : size.getWidth();
int height = flipSizes ? size.getWidth() : size.getHeight();
supportedPictureSizes.add(new Size(width, height));
Expand Down