app/src/main/java/cn/lytcom/camera2kit/AutoFocusHelper.java
/**
     * Compute 3A regions for a sensor-referenced touch coordinate.
     * Returns a MeteringRectangle[] with length 1.
     *
     * @param nx                x coordinate of the touch point, in normalized portrait
     *                          coordinates.
     * @param ny                y coordinate of the touch point, in normalized portrait
     *                          coordinates.
     * @param fraction          Fraction in [0,1]. Multiplied by min(cropRegion.width(),
     *                          cropRegion.height())
     *                          to determine the side length of the square MeteringRectangle.
     * @param cropRegion        Crop region of the image.
     * @param sensorOrientation sensor orientation as defined by
     *                          CameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION).
     */
Compute 3A regions for a sensor-referenced touch coordinate.
Returns a MeteringRectangle[] with length 1.

@param nx                x coordinate of the touch point, in normalized portrait
coordinates.
@param ny                y coordinate of the touch point, in normalized portrait
coordinates.
@param fraction          Fraction in [0,1]. Multiplied by min(cropRegion.width(),
cropRegion.height())
to determine the side length of the square MeteringRectangle.
@param cropRegion        Crop region of the image.
Compute 3A regions for a sensor - referenced touch coordinate . Returns a MeteringRectangle [] with length 1 . @param nx x coordinate of the touch point in normalized portrait coordinates . @param ny y coordinate of the touch point in normalized portrait coordinates . @param fraction Fraction in [ 0 1 ] . Multiplied by min ( cropRegion . width () cropRegion . height () ) to determine the side length of the square MeteringRectangle . @param cropRegion Crop region of the image .
private static MeteringRectangle[] regionsForNormalizedCoord(
        float nx, float ny, float fraction, final Rect cropRegion, int sensorOrientation) {
        int minCropEdge = Math.min(cropRegion.width(), cropRegion.height());
        int halfSideLength = (int) (0.5f * fraction * minCropEdge);
        PointF nsc = CameraUtil.normalizedSensorCoordsForNormalizedDisplayCoords(
            nx, ny, sensorOrientation);
        int xCenterSensor = (int) (cropRegion.left + nsc.x * cropRegion.width());
        int yCenterSensor = (int) (cropRegion.top + nsc.y * cropRegion.height());
        Rect meteringRegion = new Rect(xCenterSensor - halfSideLength,
            yCenterSensor - halfSideLength,
            xCenterSensor + halfSideLength,
            yCenterSensor + halfSideLength);
        meteringRegion.left = CameraUtil.clamp(meteringRegion.left, cropRegion.left,
            cropRegion.right);
        meteringRegion.top = CameraUtil.clamp(meteringRegion.top, cropRegion.top,
            cropRegion.bottom);
        meteringRegion.right = CameraUtil.clamp(meteringRegion.right, cropRegion.left,
            cropRegion.right);
        meteringRegion.bottom = CameraUtil.clamp(meteringRegion.bottom, cropRegion.top,
            cropRegion.bottom);
        return new MeteringRectangle[]{new MeteringRectangle(meteringRegion,
            CAMERA2_REGION_WEIGHT)};
    }
private static MeteringRectangle [ ] regionsForNormalizedCoord ( float nx , float ny , float fraction , final Rect cropRegion , int sensorOrientation ) { int minCropEdge = Math . min ( cropRegion . width ( ) , cropRegion . height ( ) ) ; int halfSideLength = ( int ) ( 0.5f * fraction * minCropEdge ) ; PointF nsc = CameraUtil . normalizedSensorCoordsForNormalizedDisplayCoords ( nx , ny , sensorOrientation ) ; int xCenterSensor = ( int ) ( cropRegion . left + nsc . x * cropRegion . width ( ) ) ; int yCenterSensor = ( int ) ( cropRegion . top + nsc . y * cropRegion . height ( ) ) ; Rect meteringRegion = new Rect ( xCenterSensor - halfSideLength , yCenterSensor - halfSideLength , xCenterSensor + halfSideLength , yCenterSensor + halfSideLength ) ; meteringRegion . left = CameraUtil . clamp ( meteringRegion . left , cropRegion . left , cropRegion . right ) ; meteringRegion . top = CameraUtil . clamp ( meteringRegion . top , cropRegion . top , cropRegion . bottom ) ; meteringRegion . right = CameraUtil . clamp ( meteringRegion . right , cropRegion . left , cropRegion . right ) ; meteringRegion . bottom = CameraUtil . clamp ( meteringRegion . bottom , cropRegion . top , cropRegion . bottom ) ; return new MeteringRectangle [ ] { new MeteringRectangle ( meteringRegion , CAMERA2_REGION_WEIGHT ) } ; }
Compute 3A regions for a sensor-referenced touch coordinate.
Compute 3A regions for a sensor - referenced touch coordinate .
// Compute half side length in pixels. // Compute the output MeteringRectangle in sensor space. // nx, ny is normalized to the screen. // Crop region itself is specified in sensor coordinates. // Normalized coordinates, now rotated into sensor space. // Clamp meteringRegion to cropRegion.