Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3dd9cdb5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Camera: Hook up zoom ratio in legacy camera2 shim" into rvc-dev am:...

Merge "Camera: Hook up zoom ratio in legacy camera2 shim" into rvc-dev am: 27e6f4eb am: 94d5cf3d am: 95959726

Change-Id: Ib4fdfb976e7a6004701c766dd8a1a6c4e9f264bd
parents 6b491da7 95959726
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -233,8 +233,10 @@ public class LegacyFaceDetectMapper {
        Camera.Parameters params = legacyRequest.parameters;
        Camera.Parameters params = legacyRequest.parameters;


        Rect activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
        Rect activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
        ZoomData zoomData = ParameterUtils.convertScalerCropRegion(activeArray,
        ZoomData zoomData = ParameterUtils.convertToLegacyZoom(activeArray,
                request.get(CaptureRequest.SCALER_CROP_REGION), previewSize, params);
                request.get(CaptureRequest.SCALER_CROP_REGION),
                request.get(CaptureRequest.CONTROL_ZOOM_RATIO),
                previewSize, params);


        List<Face> convertedFaces = new ArrayList<>();
        List<Face> convertedFaces = new ArrayList<>();
        if (faces != null) {
        if (faces != null) {
+12 −0
Original line number Original line Diff line number Diff line
@@ -771,6 +771,7 @@ public class LegacyMetadataMapper {
                    CameraCharacteristics.CONTROL_AWB_AVAILABLE_MODES                     ,
                    CameraCharacteristics.CONTROL_AWB_AVAILABLE_MODES                     ,
                    CameraCharacteristics.CONTROL_AWB_LOCK_AVAILABLE                      ,
                    CameraCharacteristics.CONTROL_AWB_LOCK_AVAILABLE                      ,
                    CameraCharacteristics.CONTROL_MAX_REGIONS                             ,
                    CameraCharacteristics.CONTROL_MAX_REGIONS                             ,
                    CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE                        ,
                    CameraCharacteristics.FLASH_INFO_AVAILABLE                            ,
                    CameraCharacteristics.FLASH_INFO_AVAILABLE                            ,
                    CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL                   ,
                    CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL                   ,
                    CameraCharacteristics.JPEG_AVAILABLE_THUMBNAIL_SIZES                  ,
                    CameraCharacteristics.JPEG_AVAILABLE_THUMBNAIL_SIZES                  ,
@@ -828,6 +829,7 @@ public class LegacyMetadataMapper {
                    CaptureRequest.CONTROL_MODE,
                    CaptureRequest.CONTROL_MODE,
                    CaptureRequest.CONTROL_SCENE_MODE,
                    CaptureRequest.CONTROL_SCENE_MODE,
                    CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
                    CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
                    CaptureRequest.CONTROL_ZOOM_RATIO,
                    CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE,
                    CaptureRequest.JPEG_GPS_COORDINATES,
                    CaptureRequest.JPEG_GPS_COORDINATES,
                    CaptureRequest.JPEG_GPS_PROCESSING_METHOD,
                    CaptureRequest.JPEG_GPS_PROCESSING_METHOD,
@@ -872,6 +874,7 @@ public class LegacyMetadataMapper {
                    CaptureResult.CONTROL_AWB_MODE                                 ,
                    CaptureResult.CONTROL_AWB_MODE                                 ,
                    CaptureResult.CONTROL_AWB_LOCK                                 ,
                    CaptureResult.CONTROL_AWB_LOCK                                 ,
                    CaptureResult.CONTROL_MODE                                     ,
                    CaptureResult.CONTROL_MODE                                     ,
                    CaptureResult.CONTROL_ZOOM_RATIO                               ,
                    CaptureResult.FLASH_MODE                                       ,
                    CaptureResult.FLASH_MODE                                       ,
                    CaptureResult.JPEG_GPS_COORDINATES                             ,
                    CaptureResult.JPEG_GPS_COORDINATES                             ,
                    CaptureResult.JPEG_GPS_PROCESSING_METHOD                       ,
                    CaptureResult.JPEG_GPS_PROCESSING_METHOD                       ,
@@ -934,6 +937,12 @@ public class LegacyMetadataMapper {
    }
    }


    private static void mapScaler(CameraMetadataNative m, Parameters p) {
    private static void mapScaler(CameraMetadataNative m, Parameters p) {
        /*
         * control.zoomRatioRange
         */
        Range<Float> zoomRatioRange = new Range<Float>(1.0f, ParameterUtils.getMaxZoomRatio(p));
        m.set(CONTROL_ZOOM_RATIO_RANGE, zoomRatioRange);

        /*
        /*
         * scaler.availableMaxDigitalZoom
         * scaler.availableMaxDigitalZoom
         */
         */
@@ -1383,6 +1392,9 @@ public class LegacyMetadataMapper {
        // control.sceneMode -- DISABLED is always available
        // control.sceneMode -- DISABLED is always available
        m.set(CaptureRequest.CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_DISABLED);
        m.set(CaptureRequest.CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_DISABLED);


        // control.zoomRatio -- 1.0
        m.set(CaptureRequest.CONTROL_ZOOM_RATIO, 1.0f);

        /*
        /*
         * statistics.*
         * statistics.*
         */
         */
+2 −1
Original line number Original line Diff line number Diff line
@@ -68,8 +68,9 @@ public class LegacyRequestMapper {
         */
         */
        ParameterUtils.ZoomData zoomData;
        ParameterUtils.ZoomData zoomData;
        {
        {
            zoomData = ParameterUtils.convertScalerCropRegion(activeArray,
            zoomData = ParameterUtils.convertToLegacyZoom(activeArray,
                    request.get(SCALER_CROP_REGION),
                    request.get(SCALER_CROP_REGION),
                    request.get(CONTROL_ZOOM_RATIO),
                    previewSize,
                    previewSize,
                    params);
                    params);


+11 −2
Original line number Original line Diff line number Diff line
@@ -118,8 +118,10 @@ public class LegacyResultMapper {


        Rect activeArraySize = characteristics.get(
        Rect activeArraySize = characteristics.get(
                CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
                CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
        ZoomData zoomData = ParameterUtils.convertScalerCropRegion(activeArraySize,
        ZoomData zoomData = ParameterUtils.convertToLegacyZoom(activeArraySize,
                request.get(CaptureRequest.SCALER_CROP_REGION), previewSize, params);
                request.get(CaptureRequest.SCALER_CROP_REGION),
                request.get(CaptureRequest.CONTROL_ZOOM_RATIO),
                previewSize, params);


        /*
        /*
         * colorCorrection
         * colorCorrection
@@ -516,5 +518,12 @@ public class LegacyResultMapper {
        {
        {
            m.set(SCALER_CROP_REGION, zoomData.reportedCrop);
            m.set(SCALER_CROP_REGION, zoomData.reportedCrop);
        }
        }

        /*
         * control.zoomRatio
         */
        {
            m.set(CONTROL_ZOOM_RATIO, zoomData.reportedZoomRatio);
        }
    }
    }
}
}
+97 −4
Original line number Original line Diff line number Diff line
@@ -73,11 +73,15 @@ public class ParameterUtils {
        public final Rect previewCrop;
        public final Rect previewCrop;
        /** Reported crop-region given the zoom index, coordinates relative to active-array */
        /** Reported crop-region given the zoom index, coordinates relative to active-array */
        public final Rect reportedCrop;
        public final Rect reportedCrop;
        /** Reported zoom ratio given the zoom index */
        public final float reportedZoomRatio;


        public ZoomData(int zoomIndex, Rect previewCrop, Rect reportedCrop) {
        public ZoomData(int zoomIndex, Rect previewCrop, Rect reportedCrop,
                float reportedZoomRatio) {
            this.zoomIndex = zoomIndex;
            this.zoomIndex = zoomIndex;
            this.previewCrop = previewCrop;
            this.previewCrop = previewCrop;
            this.reportedCrop = reportedCrop;
            this.reportedCrop = reportedCrop;
            this.reportedZoomRatio = reportedZoomRatio;
        }
        }
    }
    }


@@ -371,7 +375,8 @@ public class ParameterUtils {
     * @throws NullPointerException if any of the args were {@code null}
     * @throws NullPointerException if any of the args were {@code null}
     */
     */
    public static int getClosestAvailableZoomCrop(
    public static int getClosestAvailableZoomCrop(
            Camera.Parameters params, Rect activeArray, Size streamSize, Rect cropRegion,
            Camera.Parameters params, Rect activeArray,
            Size streamSize, Rect cropRegion,
            /*out*/
            /*out*/
            Rect reportedCropRegion,
            Rect reportedCropRegion,
            Rect previewCropRegion) {
            Rect previewCropRegion) {
@@ -732,6 +737,92 @@ public class ParameterUtils {
        return new SizeF(zoomRatioWidth, zoomRatioHeight);
        return new SizeF(zoomRatioWidth, zoomRatioHeight);
    }
    }


    /**
     * Convert the user-specified crop region/zoom into zoom data; which can be used
     * to set the parameters to a specific zoom index, or to report back to the user what
     * the actual zoom was, or for other calculations requiring the current preview crop region.
     *
     * <p>None of the parameters are mutated.<p>
     *
     * @param activeArraySize active array size of the sensor (e.g. max jpeg size)
     * @param cropRegion the user-specified crop region
     * @param zoomRatio the user-specified zoom ratio
     * @param previewSize the current preview size (in pixels)
     * @param params the current camera parameters (not mutated)
     *
     * @return the zoom index, and the effective/reported crop regions (relative to active array)
     */
    public static ZoomData convertToLegacyZoom(Rect activeArraySize, Rect
            cropRegion, Float zoomRatio, Size previewSize, Camera.Parameters params) {
        final float FLOAT_EQUAL_THRESHOLD = 0.0001f;
        if (zoomRatio != null &&
                Math.abs(1.0f - zoomRatio) > FLOAT_EQUAL_THRESHOLD) {
            // User uses CONTROL_ZOOM_RATIO to control zoom
            return convertZoomRatio(activeArraySize, zoomRatio, previewSize, params);
        }

        return convertScalerCropRegion(activeArraySize, cropRegion, previewSize, params);
    }

    /**
     * Convert the user-specified zoom ratio into zoom data; which can be used
     * to set the parameters to a specific zoom index, or to report back to the user what the
     * actual zoom was, or for other calculations requiring the current preview crop region.
     *
     * <p>None of the parameters are mutated.</p>
     *
     * @param activeArraySize active array size of the sensor (e.g. max jpeg size)
     * @param zoomRatio the current zoom ratio
     * @param previewSize the current preview size (in pixels)
     * @param params the current camera parameters (not mutated)
     *
     * @return the zoom index, and the effective/reported crop regions (relative to active array)
     */
    public static ZoomData convertZoomRatio(Rect activeArraySize, float zoomRatio,
            Size previewSize, Camera.Parameters params) {
        if (DEBUG) {
            Log.v(TAG, "convertZoomRatio - user zoom ratio was " + zoomRatio);
        }

        List<Rect> availableReportedCropRegions =
                getAvailableZoomCropRectangles(params, activeArraySize);
        List<Rect> availablePreviewCropRegions =
                getAvailablePreviewZoomCropRectangles(params, activeArraySize, previewSize);
        if (availableReportedCropRegions.size() != availablePreviewCropRegions.size()) {
            throw new AssertionError("available reported/preview crop region size mismatch");
        }

        // Find the best matched legacy zoom ratio for the requested camera2 zoom ratio.
        int bestZoomIndex = 0;
        Rect reportedCropRegion = new Rect(availableReportedCropRegions.get(0));
        Rect previewCropRegion = new Rect(availablePreviewCropRegions.get(0));
        float reportedZoomRatio = 1.0f;
        if (params.isZoomSupported()) {
            List<Integer> zoomRatios = params.getZoomRatios();
            for (int i = 1; i < zoomRatios.size(); i++) {
                if (zoomRatio * ZOOM_RATIO_MULTIPLIER >= zoomRatios.get(i)) {
                    bestZoomIndex = i;
                    reportedCropRegion = availableReportedCropRegions.get(i);
                    previewCropRegion = availablePreviewCropRegions.get(i);
                    reportedZoomRatio = zoomRatios.get(i);
                } else {
                    break;
                }
            }
        }

        if (DEBUG) {
            Log.v(TAG, "convertZoomRatio - zoom calculated to: " +
                    "zoomIndex = " + bestZoomIndex +
                    ", reported crop region = " + reportedCropRegion +
                    ", preview crop region = " + previewCropRegion +
                    ", reported zoom ratio = " + reportedZoomRatio);
        }

        return new ZoomData(bestZoomIndex, reportedCropRegion,
                previewCropRegion, reportedZoomRatio);
    }

    /**
    /**
     * Convert the user-specified crop region into zoom data; which can be used
     * Convert the user-specified crop region into zoom data; which can be used
     * to set the parameters to a specific zoom index, or to report back to the user what the
     * to set the parameters to a specific zoom index, or to report back to the user what the
@@ -767,15 +858,17 @@ public class ParameterUtils {
        final int zoomIdx = ParameterUtils.getClosestAvailableZoomCrop(params, activeArraySizeOnly,
        final int zoomIdx = ParameterUtils.getClosestAvailableZoomCrop(params, activeArraySizeOnly,
                previewSize, userCropRegion,
                previewSize, userCropRegion,
                /*out*/reportedCropRegion, /*out*/previewCropRegion);
                /*out*/reportedCropRegion, /*out*/previewCropRegion);
        final float reportedZoomRatio = 1.0f;


        if (DEBUG) {
        if (DEBUG) {
            Log.v(TAG, "convertScalerCropRegion - zoom calculated to: " +
            Log.v(TAG, "convertScalerCropRegion - zoom calculated to: " +
                    "zoomIndex = " + zoomIdx +
                    "zoomIndex = " + zoomIdx +
                    ", reported crop region = " + reportedCropRegion +
                    ", reported crop region = " + reportedCropRegion +
                    ", preview crop region = " + previewCropRegion);
                    ", preview crop region = " + previewCropRegion +
                    ", reported zoom ratio = " + reportedZoomRatio);
        }
        }


        return new ZoomData(zoomIdx, previewCropRegion, reportedCropRegion);
        return new ZoomData(zoomIdx, previewCropRegion, reportedCropRegion, reportedZoomRatio);
    }
    }


    /**
    /**