Complete engine/options logic for RAW

pull/691/head
Mattia Iavarone 6 years ago
parent 2d410709be
commit e7c039b255
  1. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/controls/PictureFormat.java
  2. 35
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  3. 18
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/options/Camera2Options.java

@ -6,8 +6,6 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.CameraOptions;
import com.otaliastudios.cameraview.CameraView;
import java.io.File;
/**
* Format of the picture results for pictures that are taken with {@link CameraView#takePicture()}.
* This does not apply to picture snapshots.

@ -387,7 +387,14 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
LOG.i("createCamera:", "Applying default parameters.");
mCameraCharacteristics = mManager.getCameraCharacteristics(mCameraId);
boolean flip = getAngles().flip(Reference.SENSOR, Reference.VIEW);
mCameraOptions = new Camera2Options(mManager, mCameraId, flip);
int format;
switch (mPictureFormat) {
case JPEG: format = ImageFormat.JPEG; break;
case DNG: format = ImageFormat.RAW_SENSOR; break;
default: throw new IllegalArgumentException("Unknown format:"
+ mPictureFormat);
}
mCameraOptions = new Camera2Options(mManager, mCameraId, flip, format);
createRepeatingRequestBuilder(CameraDevice.TEMPLATE_PREVIEW);
} catch (CameraAccessException e) {
task.trySetException(createCameraException(e));
@ -484,23 +491,19 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
}
// 3. PICTURE RECORDING
// Format is supported, or it would have thrown in Camera2Options constructor.
if (getMode() == Mode.PICTURE) {
if (mCameraOptions.supports(mPictureFormat)) {
int format;
switch (mPictureFormat) {
case JPEG: format = ImageFormat.JPEG; break;
case DNG: format = ImageFormat.RAW_SENSOR; break;
default: throw new IllegalArgumentException("Unknown format:" + mPictureFormat);
}
mPictureReader = ImageReader.newInstance(
mCaptureSize.getWidth(),
mCaptureSize.getHeight(),
format, 2);
outputSurfaces.add(mPictureReader.getSurface());
} else {
throw new IllegalStateException("Unsupported picture format: " + mPictureFormat
+ ". Please check CameraOptions before applying.");
int format;
switch (mPictureFormat) {
case JPEG: format = ImageFormat.JPEG; break;
case DNG: format = ImageFormat.RAW_SENSOR; break;
default: throw new IllegalArgumentException("Unknown format:" + mPictureFormat);
}
mPictureReader = ImageReader.newInstance(
mCaptureSize.getWidth(),
mCaptureSize.getHeight(),
format, 2);
outputSurfaces.add(mPictureReader.getSurface());
}
// 4. FRAME PROCESSING

@ -33,8 +33,9 @@ import static android.hardware.camera2.CameraCharacteristics.*;
public class Camera2Options extends CameraOptions {
public Camera2Options(@NonNull CameraManager manager,
@NonNull String cameraId,
boolean flipSizes) throws CameraAccessException {
@NonNull String cameraId,
boolean flipSizes,
int pictureFormat) throws CameraAccessException {
Camera2Mapper mapper = Camera2Mapper.get();
CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics(cameraId);
@ -114,7 +115,18 @@ public class Camera2Options extends CameraOptions {
if (streamMap == null) {
throw new RuntimeException("StreamConfigurationMap is null. Should not happen.");
}
android.util.Size[] psizes = streamMap.getOutputSizes(ImageFormat.JPEG);
int[] pictureFormats = streamMap.getOutputFormats();
boolean hasPictureFormat = false;
for (int picFormat : pictureFormats) {
if (picFormat == pictureFormat) {
hasPictureFormat = true;
break;
}
}
if (!hasPictureFormat) {
throw new IllegalStateException("Picture format not supported: " + pictureFormat);
}
android.util.Size[] psizes = streamMap.getOutputSizes(pictureFormat);
for (android.util.Size size : psizes) {
int width = flipSizes ? size.getHeight() : size.getWidth();
int height = flipSizes ? size.getWidth() : size.getHeight();

Loading…
Cancel
Save