Search in sources :

Example 56 with TotalCaptureResult

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) {
        }
    }
}
Also used : Rect(android.graphics.Rect) CaptureFailure(android.hardware.camera2.CaptureFailure) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) CameraAccessException(android.hardware.camera2.CameraAccessException) CaptureRequest(android.hardware.camera2.CaptureRequest) Location(android.location.Location)

Example 57 with TotalCaptureResult

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);
        }
    });
}
Also used : CaptureFailure(android.hardware.camera2.CaptureFailure) ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 58 with TotalCaptureResult

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");
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) RequiresApi(android.support.annotation.RequiresApi) NonNull(android.support.annotation.NonNull) CameraManager(android.hardware.camera2.CameraManager) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) Manifest(android.Manifest) Image(android.media.Image) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) Handler(android.os.Handler) Matrix(android.graphics.Matrix) Build(android.os.Build) Log(android.util.Log) RectF(android.graphics.RectF) SurfaceTexture(android.graphics.SurfaceTexture) ImageFormat(android.graphics.ImageFormat) Surface(android.view.Surface) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) CameraMetadata(android.hardware.camera2.CameraMetadata) Point(android.graphics.Point) ImageReader(android.media.ImageReader) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) TextureView(android.view.TextureView) ActivityCompat(android.support.v4.app.ActivityCompat) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) R(de.vier_bier.habpanelviewer.R) HandlerThread(android.os.HandlerThread) CameraAccessException(android.hardware.camera2.CameraAccessException) CameraDevice(android.hardware.camera2.CameraDevice) CaptureRequest(android.hardware.camera2.CaptureRequest) Activity(android.app.Activity) Size(android.util.Size) ArrayList(java.util.ArrayList) Handler(android.os.Handler) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) Image(android.media.Image) ByteBuffer(java.nio.ByteBuffer) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) Point(android.graphics.Point) Surface(android.view.Surface) CameraAccessException(android.hardware.camera2.CameraAccessException) HandlerThread(android.os.HandlerThread) NonNull(android.support.annotation.NonNull) CaptureRequest(android.hardware.camera2.CaptureRequest) ImageReader(android.media.ImageReader)

Aggregations

TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)53 ArrayList (java.util.ArrayList)34 CaptureRequest (android.hardware.camera2.CaptureRequest)33 Image (android.media.Image)32 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)30 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)25 CaptureFailure (android.hardware.camera2.CaptureFailure)9 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)8 Size (android.util.Size)7 Surface (android.view.Surface)7 CameraAccessException (android.hardware.camera2.CameraAccessException)6 PublicKey (android.hardware.camera2.impl.PublicKey)5 SyntheticKey (android.hardware.camera2.impl.SyntheticKey)5 Field (java.lang.reflect.Field)5 Point (android.graphics.Point)4 Activity (android.app.Activity)3 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)3 CameraManager (android.hardware.camera2.CameraManager)3 ImageReader (android.media.ImageReader)2 NonNull (android.support.annotation.NonNull)2