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

Commit c1d3f39f authored by Mark Harman's avatar Mark Harman Committed by Mohammed Althaf T
Browse files

Smoother zoom for Camera2 API - both more zoom entries, and supporting smooth zoom for pinch zoom.

parent 6dca4fb3
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ FIXED Long pressing on the shutter button in video mode meant nothing happened
ADDED   Camera vendor extensions show percentage progress on supported Android 14 devices.
ADDED   Long press on switch camera icons now bring up a menu to jump to any camera (for devices
        that expose multiple cameras).
UPDATED Smoother zoom for Camera2 API.
UPDATED Improvements for loading thumbnails for gallery icon (including fixing orientation for
        X-NIGHT portrait images on Pixel 6 Pro).
UPDATED Improvements for popup menu and exposure UI when using large font sizes.
+4 −2
Original line number Diff line number Diff line
@@ -2653,7 +2653,7 @@ public class MainActivity extends AppCompatActivity {
            zoom = getNextMultiZoomRatio(frontZoomRatios);
        }

        preview.zoomTo(preview.findNxZoom(zoom));
        preview.zoomTo(preview.findNxZoom(zoom), true);
        updateMultiPixelIcon(backZoomRatios.indexOf(zoom));

        if( MyDebug.LOG )
@@ -5865,7 +5865,9 @@ public class MainActivity extends AppCompatActivity {
                            Log.d(TAG, "zoom onProgressChanged: " + progress);
                        // note we zoom even if !fromUser, as various other UI controls (multitouch, volume key zoom, -/+ zoomcontrol)
                        // indirectly set zoom via this method, from setting the zoom slider
                        preview.zoomTo(progress);
                        // if hasSmoothZoom()==true, then the preview already handled zooming to the current value
                        if( !preview.hasSmoothZoom() )
                            preview.zoomTo(preview.getMaxZoom() - progress, false);

                        updateMultiCameraIcon();
                    }
+18 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public abstract class CameraController {
    public static class CameraFeatures {
        public boolean is_zoom_supported;
        public int max_zoom;
        public List<Integer> zoom_ratios;
        public List<Integer> zoom_ratios; // list of supported zoom ratios; each value is the zoom multiplied by 100
        public boolean supports_face_detection;
        public List<CameraController.Size> picture_sizes;
        public List<CameraController.Size> video_sizes;
@@ -541,8 +541,25 @@ public abstract class CameraController {
    public abstract TonemapProfile getTonemapProfile();
    public abstract int getJpegQuality();
    public abstract void setJpegQuality(int quality);
    /** Returns the current zoom. The returned value is an index into the CameraFeatures.zoom_ratios
     *  array.
     */
    public abstract int getZoom();
    /** Set the zoom.
     * @param value The index into the CameraFeatures.zoom_ratios array.
     */
    public abstract void setZoom(int value);
    /** Set the zoom. Unlike setZoom(value), this allows specifying any zoom level within the
     *  supported range.
     * @param value The index into the CameraFeatures.zoom_ratios array.
     * @param smooth_zoom The desired zoom. With CameraController1 (old Camera API), this is ignored.
     *                    With CameraController2 (Camera2 API), this is used instead of the zoom_ratios
     *                    value. Note that getZoom() will return the value passed to this method, so
     *                    passing an appropriate value (e.g., whatever zoom_ratio is closest to the
     *                    smooth_zoom) is still useful if you want to make use of getZoom().
     *                    smooth_zoom must still be within the supported range of zoom values.
     */
    public abstract void setZoom(int value, float smooth_zoom);
    public abstract void resetZoom(); // resets to zoom 1x
    public abstract int getExposureCompensation();
    public abstract boolean setExposureCompensation(int new_exposure);
+5 −0
Original line number Diff line number Diff line
@@ -977,6 +977,11 @@ public class CameraController1 extends CameraController {
        }
    }

    @Override
    public void setZoom(int value, float smooth_zoom) {
        setZoom(value);
    }

    @Override
    public void resetZoom() {
        setZoom(0);
+23 −4
Original line number Diff line number Diff line
@@ -2528,12 +2528,12 @@ public class CameraController2 extends CameraController {
        int zoom_value_1x;

        // prepare zoom rations > 1x
        // set 20 steps per 2x factor
        final double scale_factor_c = 1.0352649238413775043477881942112;
        // set 40 steps per 2x factor
        final double scale_factor_c = 1.0174796921026863936352862847966;
        List<Integer> zoom_ratios_above_one = new ArrayList<>();
        double zoom = scale_factor_c;
        while( zoom < max_zoom - 1.0e-5f ) {
            int zoom_ratio = (int)(zoom*100);
            int zoom_ratio = (int)(zoom*100+1.0e-5);
            zoom_ratios_above_one.add(zoom_ratio);
            zoom *= scale_factor_c;
        }
@@ -4837,6 +4837,11 @@ public class CameraController2 extends CameraController {

    @Override
    public void setZoom(int value) {
        setZoom(value, -1.0f);
    }

    @Override
    public void setZoom(int value, float smooth_zoom) {
        if( zoom_ratios == null ) {
            if( MyDebug.LOG )
                Log.d(TAG, "zoom not supported");
@@ -4857,7 +4862,21 @@ public class CameraController2 extends CameraController {
                Log.e(TAG, "invalid zoom value" + value);
            throw new RuntimeException(); // throw as RuntimeException, as this is a programming error
        }
        float zoom = zoom_ratios.get(value)/100.0f;
        if( smooth_zoom > 0.0f ) {
            if( smooth_zoom < zoom_ratios.get(0)/100.0f ) {
                if( MyDebug.LOG )
                    Log.e(TAG, "invalid smooth_zoom: " + smooth_zoom);
                throw new RuntimeException("smooth_zoom too small");
            }
            else if( smooth_zoom > zoom_ratios.get(zoom_ratios.size()-1)/100.0f ) {
                if( MyDebug.LOG )
                    Log.e(TAG, "invalid smooth_zoom: " + smooth_zoom);
                throw new RuntimeException("smooth_zoom too large");
            }
        }
        float zoom = smooth_zoom > 0.0f ? smooth_zoom : zoom_ratios.get(value)/100.0f;
        if( MyDebug.LOG )
            Log.d(TAG, "zoom to: " + zoom);

        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.R ) {
            camera_settings.has_control_zoom_ratio = true;
Loading