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

Commit db4329f7 authored by Mark Harman's avatar Mark Harman
Browse files

Pinch zoom improvements - zoom faster, but also fix jitter.

parent b5635cf4
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ Version 1.52 (Working in progress)


FIXED   Crash related to multi-camera devices.
FIXED   Crash related to multi-camera devices.
FIXED   Possible crash when failing to save with Storage Access Framework.
FIXED   Possible crash when failing to save with Storage Access Framework.
FIXED   Jittery zoom when using multitouch pinch but pinching slowly.
FIXED   Don't show zebra stripes, focus peaking or histogram, when displaying resultant photo for
FIXED   Don't show zebra stripes, focus peaking or histogram, when displaying resultant photo for
        "Pause after taking photo" option.
        "Pause after taking photo" option.
FIXED   Problem where clicking on gallery icon would sometimes go to a "base" image instead of HDR
FIXED   Problem where clicking on gallery icon would sometimes go to a "base" image instead of HDR
@@ -69,6 +70,7 @@ FIXED Problem on some tablets where zoom seekbar showed under navigation bar i
ADDED   Support for zoom with camera vendor extensions (for supported Android 13+ devices).
ADDED   Support for zoom with camera vendor extensions (for supported Android 13+ devices).
ADDED   Support for displaying on-screen ISO and exposure time with camera vendor extensions (for
ADDED   Support for displaying on-screen ISO and exposure time with camera vendor extensions (for
        supported Android 13+ devices).
        supported Android 13+ devices).
UPDATED Made pinch zoom more sensitive (better support for modern devices with higher zoom levels).
UPDATED "Touch to capture" option now supports starting and stopping video.
UPDATED "Touch to capture" option now supports starting and stopping video.
UPDATED Applied a timeout of 2 second for focusing with original camera API.
UPDATED Applied a timeout of 2 second for focusing with original camera API.
UPDATED Improved performance for NR photo mode.
UPDATED Improved performance for NR photo mode.
+53 −3
Original line number Original line Diff line number Diff line
@@ -766,7 +766,12 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
        @Override
        @Override
        public boolean onScale(@NonNull ScaleGestureDetector detector) {
        public boolean onScale(@NonNull ScaleGestureDetector detector) {
            if( Preview.this.camera_controller != null && Preview.this.has_zoom ) {
            if( Preview.this.camera_controller != null && Preview.this.has_zoom ) {
                Preview.this.scaleZoom(detector.getScaleFactor());
                float scale_factor = detector.getScaleFactor();
                if( MyDebug.LOG )
                    Log.d(TAG, "onScale: " + scale_factor);
                // make pinch zoom more sensitive:
                scale_factor = 1.0f + 2.0f*(scale_factor - 1.0f);
                Preview.this.scaleZoom(scale_factor);
            }
            }
            return true;
            return true;
        }
        }
@@ -4205,8 +4210,55 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
                if( has_smooth_zoom )
                if( has_smooth_zoom )
                    smooth_zoom = zoom_ratios.get(max_zoom_factor)/100.0f;
                    smooth_zoom = zoom_ratios.get(max_zoom_factor)/100.0f;
            }
            }
            else if( has_smooth_zoom ) {
                // Find the closest zoom level by rounding to nearest.
                // Important to have same behaviour whether zooming in or out, otherwise problem when touching with two fingers and not
                // moving - we'll get very small scale factors alternately between zooming in and out.
                // The only reason we have separate codepath for zooming in or out is for performance (since we know to only look at
                // higher or lower zoom ratios).
                float dist = Math.abs(zoom_ratio - zoom_ratios.get(zoom_factor)/100.0f);
                if( MyDebug.LOG )
                    Log.d(TAG, "    current dist: " + dist);

                if( scale_factor > 1.0f ) {
                    // zooming in
                    for(int i=zoom_factor+1;i<zoom_ratios.size();i++) {
                        float this_dist = Math.abs(zoom_ratio - zoom_ratios.get(i)/100.0f);
                        if( MyDebug.LOG )
                            Log.d(TAG, "    this_dist: " + this_dist);
                        if( this_dist < dist ) {
                            new_zoom_factor = i;
                            dist = this_dist;
                            if( MyDebug.LOG )
                                Log.d(TAG, "zoom in, found new zoom by comparing " + zoom_ratios.get(i)/100.0f + " to " + zoom_ratio + " , dist " + dist);
                        }
                        else if( this_dist > dist+1.0e-5f ) {
                            break;
                        }
                    }
                }
                else {
                    // zooming out
                    for(int i=zoom_factor-1;i>=0;i--) {
                        float this_dist = Math.abs(zoom_ratio - zoom_ratios.get(i)/100.0f);
                        if( this_dist < dist ) {
                            new_zoom_factor = i;
                            dist = this_dist;
                            if( MyDebug.LOG )
                                Log.d(TAG, "zoom out, found new zoom by comparing " + zoom_ratios.get(i)/100.0f + " to " + zoom_ratio + " , dist " + dist);
                        }
                        else if( this_dist > dist+1.0e-5f ) {
                            break;
                        }
                    }
                }

                smooth_zoom = zoom_ratio;
            }
            else {
            else {
                // find the closest zoom level
                // find the closest zoom level
                // unclear if we need this code anymore (smooth_zoom should always be true?)

                if( scale_factor > 1.0f ) {
                if( scale_factor > 1.0f ) {
                    // zooming in
                    // zooming in
                    for(int i=zoom_factor;i<zoom_ratios.size();i++) {
                    for(int i=zoom_factor;i<zoom_ratios.size();i++) {
@@ -4229,8 +4281,6 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
                        }
                        }
                    }
                    }
                }
                }
                if( has_smooth_zoom )
                    smooth_zoom = zoom_ratio;
            }
            }
            if( MyDebug.LOG ) {
            if( MyDebug.LOG ) {
                Log.d(TAG, "zoom_ratio is now " + zoom_ratio);
                Log.d(TAG, "zoom_ratio is now " + zoom_ratio);