use of android.hardware.camera2.TotalCaptureResult in project android_packages_apps_Snap by LineageOS.
the class PostProcessor method reprocessImage.
private void reprocessImage(Image image, TotalCaptureResult metadata) {
if (mController.isLongShotActive()) {
mController.checkAndPlayShutterSound(mController.getMainCameraId());
}
synchronized (lock) {
if (mCameraDevice == null || mCaptureSession == null || mImageReader == null) {
Log.e(TAG, "Reprocess request is called even before taking picture");
image.close();
return;
}
if (mZSLReprocessImageReader == null) {
image.close();
return;
}
if (DEBUG_ZSL)
Log.d(TAG, "reprocess Image request " + image.getTimestamp());
CaptureRequest.Builder builder = null;
try {
builder = mCameraDevice.createReprocessCaptureRequest(metadata);
builder.set(CaptureRequest.JPEG_ORIENTATION, CameraUtil.getJpegRotation(mController.getMainCameraId(), mController.getDisplayOrientation()));
builder.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, mController.getThumbSize());
builder.set(CaptureRequest.JPEG_THUMBNAIL_QUALITY, (byte) 80);
builder.set(CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE, CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY);
builder.set(CaptureRequest.EDGE_MODE, CaptureRequest.EDGE_MODE_HIGH_QUALITY);
builder.set(CaptureRequest.NOISE_REDUCTION_MODE, CaptureRequest.NOISE_REDUCTION_MODE_HIGH_QUALITY);
// CDS 0-OFF, 1-ON, 2-AUTO
VendorTagUtil.setCdsMode(builder, 2);
VendorTagUtil.setJpegCropEnable(builder, (byte) 1);
Rect cropRect = image.getCropRect();
if (cropRect == null || cropRect.isEmpty()) {
cropRect = new Rect(0, 0, image.getWidth(), image.getHeight());
}
int targetWidth = mZSLReprocessImageReader.getWidth();
int targetHeight = mZSLReprocessImageReader.getHeight();
float targetRatio = (float) targetWidth / (float) targetHeight;
cropRect = CameraUtil.getFinalCropRect(cropRect, targetRatio);
// has crop rect. apply to jpeg request
VendorTagUtil.setJpegCropRect(builder, new int[] { cropRect.left, cropRect.top, cropRect.width(), cropRect.height() });
VendorTagUtil.setJpegRoiRect(builder, new int[] { 0, 0, targetWidth, targetHeight });
Location location = mController.getLocationManager().getCurrentLocation();
if (location != null) {
location = new Location(location);
Log.d(TAG, "sendReprocessRequest gps: " + location.toString());
// workaround for Google bug. Need to convert timestamp from ms -> sec
location.setTime(location.getTime() / 1000);
builder.set(CaptureRequest.JPEG_GPS_LOCATION, location);
}
builder.addTarget(mZSLReprocessImageReader.getSurface());
try {
mImageWriter.queueInputImage(image);
} catch (IllegalStateException e) {
Log.e(TAG, "Queueing more than it can have");
}
mCaptureSession.capture(builder.build(), new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
Log.d(TAG, "reprocessImage onCaptureCompleted");
}
@Override
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure result) {
Log.d(TAG, "reprocessImage onCaptureFailed");
}
@Override
public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber) {
Log.d(TAG, "reprocessImage onCaptureSequenceCompleted");
}
}, mHandler);
} catch (CameraAccessException e) {
}
}
}
use of android.hardware.camera2.TotalCaptureResult in project android_packages_apps_Snap by LineageOS.
the class Camera2GraphView method captureStillPictureForLongshot.
private void captureStillPictureForLongshot(CaptureRequest.Builder captureBuilder, int id) throws CameraAccessException {
Log.d(TAG, "captureStillPictureForLongshot " + id);
List<CaptureRequest> burstList = new ArrayList<>();
for (int i = 0; i < PersistUtil.getLongshotShotLimit(); i++) {
burstList.add(captureBuilder.build());
}
mCaptureSession[id].captureBurst(burstList, new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
Log.d(TAG, "captureStillPictureForLongshot onCaptureCompleted: " + id);
if (mLongshotActive) {
checkAndPlayShutterSound(id);
}
}
@Override
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure result) {
Log.d(TAG, "captureStillPictureForLongshot onCaptureFailed: " + id);
}
@Override
public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber) {
Log.d(TAG, "captureStillPictureForLongshot onCaptureSequenceCompleted: " + id);
mLongshotActive = false;
unlockFocus(id);
}
}, mCaptureCallbackHandler);
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mUI.enableVideo(false);
}
});
}
use of android.hardware.camera2.TotalCaptureResult in project habpanelviewer by vbier.
the class CameraImplV2 method takePicture.
@Override
public void takePicture(IPictureListener iPictureHandler) {
if (mCamera != null) {
if (mPictureThread == null) {
mPictureThread = new HandlerThread("takePictureThread");
mPictureThread.start();
mPictureHandler = new Handler(mPictureThread.getLooper());
}
try {
int width = 640;
int height = 480;
ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
List<Surface> outputSurfaces = new ArrayList<>(2);
outputSurfaces.add(reader.getSurface());
final CaptureRequest.Builder captureBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(reader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
ImageReader.OnImageAvailableListener readerListener = reader1 -> {
Image image = null;
try {
image = reader1.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
iPictureHandler.picture(bytes);
} finally {
if (image != null) {
image.close();
}
}
};
reader.setOnImageAvailableListener(readerListener, mPictureHandler);
final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
}
};
mCamera.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
try {
session.capture(captureBuilder.build(), captureListener, mPictureHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {
}
}, mPictureHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
} else {
throw new IllegalStateException("Motion detection not running");
}
}
Aggregations