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

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

Improve zoom seekbar and -/+ controls for when min zoom less than 1x.

parent cbef175c
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -1292,18 +1292,41 @@ public class MainActivity extends AppCompatActivity {
        return super.onKeyUp(keyCode, event);
    }

    public void zoomIn() {
        if( preview.supportsZoom() ) {
            mainUI.changeSeekbar(R.id.zoom_seekbar, -1);
    private void zoomByStep(int change) {
        if( MyDebug.LOG )
            Log.d(TAG, "zoomByStep: " + change);
        if( preview.supportsZoom() && change != 0 ) {
            if( preview.getCameraController() != null ) {
                // If the minimum zoom is < 1.0, the seekbar will have repeated entries for 1x zoom
                // (so it's easier for the user to zoom to exactly 1.0x). But if using the -/+ buttons,
                // volume keys etc to zoom, we want to skip over these repeated values.
                int zoom_factor = preview.getCameraController().getZoom();
                int new_zoom_factor = zoom_factor + change;
                if( MyDebug.LOG )
                    Log.d(TAG, "new_zoom_factor: " + new_zoom_factor);
                while( new_zoom_factor > 0 && new_zoom_factor < preview.getMaxZoom() && preview.getZoomRatio(new_zoom_factor) == preview.getZoomRatio() ) {
                    if( change > 0 )
                        change++;
                    else
                        change--;
                    new_zoom_factor = zoom_factor + change;
                    if( MyDebug.LOG )
                        Log.d(TAG, "skip over constant region: " + new_zoom_factor);
                }
            }

    public void zoomOut() {
        if( preview.supportsZoom() ) {
            mainUI.changeSeekbar(R.id.zoom_seekbar, 1);
            mainUI.changeSeekbar(R.id.zoom_seekbar, -change); // seekbar is opposite direction to zoom array
        }
    }

    public void zoomIn() {
        zoomByStep(1);
    }

    public void zoomOut() {
        zoomByStep(-1);
    }

    public void changeExposure(int change) {
        if( preview.supportsExposures() ) {
            mainUI.changeSeekbar(R.id.exposure_seekbar, change);
+40 −24
Original line number Diff line number Diff line
@@ -2562,17 +2562,11 @@ public class CameraController2 extends CameraController {
        }
        if( camera_features.is_zoom_supported ) {
            float zoom_max_min_ratio = max_zoom / min_zoom;
            // set a constant number of steps
            //final int n_steps = 100;
            // set 20 steps per 2x factor
            final int steps_per_2x_factor = 20;
            //final double scale_factor = Math.pow(2.0, 1.0/(double)steps_per_2x_factor);
            int n_steps = (int)( (steps_per_2x_factor * Math.log(zoom_max_min_ratio + 1.0e-11)) / Math.log(2.0));
            final double scale_factor = Math.pow(zoom_max_min_ratio, 1.0/(double)n_steps);
            final int n_zoom_one = n_steps/20 + 1; // if min_zoom < 1.0f and max_zoom > 1.0f, then how often to repeat the 1.0x zoom (so the seekbar for zoom is "sticky")
            if( MyDebug.LOG ) {
                Log.d(TAG, "n_steps: " + n_steps);
                Log.d(TAG, "scale_factor: " + scale_factor);
            }

            camera_features.zoom_ratios = new ArrayList<>();
@@ -2586,34 +2580,56 @@ public class CameraController2 extends CameraController {
                camera_features.zoom_ratios.set(0, camera_features.zoom_ratios.get(0) + 1);
            }

            boolean has_done_one = camera_features.zoom_ratios.get(0) == 100;
            if( has_done_one ) {
                zoom_value_1x = 0;
            if( camera_features.zoom_ratios.get(0) < 100 ) {
                int n_steps_below_one = Math.max(1, n_steps/5);
                // if the min zoom is < 1.0, we add multiple entries for 1x zoom, when using the zoom
                // seekbar it's easy for the user to zoom to exactly 1x
                int n_steps_one = Math.max(1, n_steps/20);
                if( MyDebug.LOG ) {
                    Log.d(TAG, "n_steps_below_one: " + n_steps_below_one);
                    Log.d(TAG, "n_steps_one: " + n_steps_one);
                }

                // add rest of zoom values < 1.0f
                double zoom = min_zoom;
            for(int i=0;i<n_steps-1;i++) {
                final double scale_factor = Math.pow(1.0f / min_zoom, 1.0/(double)n_steps_below_one);
                if( MyDebug.LOG ) {
                    Log.d(TAG, "scale_factor for below 1.0x: " + scale_factor);
                }
                for(int i=0;i<n_steps_below_one-1;i++) {
                    zoom *= scale_factor;
                    int zoom_ratio = (int)(zoom*100);
                if( !has_done_one && zoom_ratio >= 100 ) {
                    camera_features.zoom_ratios.add(zoom_ratio);
                }

                // add values for 1.0f
                zoom_value_1x = camera_features.zoom_ratios.size();
                    for(int j=0;j<n_zoom_one;j++)
                for(int i=0;i<n_steps_one;i++)
                    camera_features.zoom_ratios.add(100);
                    has_done_one = true;
            }
            else {
                zoom_value_1x = 0;
            }

            final int n_steps_above_one = Math.max(1, n_steps - camera_features.zoom_ratios.size());
            if( MyDebug.LOG ) {
                Log.d(TAG, "n_steps_above_one: " + n_steps_above_one);
            }

            // add zoom values > 1.0f
            double zoom = 1.0f;
            final double scale_factor = Math.pow(max_zoom, 1.0/(double)n_steps_above_one);
            if( MyDebug.LOG ) {
                Log.d(TAG, "scale_factor for above 1.0x: " + scale_factor);
            }
            for(int i=0;i<n_steps_above_one-1;i++) {
                zoom *= scale_factor;
                int zoom_ratio = (int)(zoom*100);
                camera_features.zoom_ratios.add(zoom_ratio);
            }

            // add maximum zoom
            int zoom_ratio = (int)(max_zoom*100);
            if( !has_done_one && zoom_ratio > 100 ) {
                zoom_value_1x = camera_features.zoom_ratios.size();
                for(int j=0;j<n_zoom_one;j++)
                    camera_features.zoom_ratios.add(100);
            }
            else if( !has_done_one ) {
                zoom_value_1x = camera_features.zoom_ratios.size();
            }
            camera_features.zoom_ratios.add(zoom_ratio);

            camera_features.max_zoom = camera_features.zoom_ratios.size()-1;
+6 −0
Original line number Diff line number Diff line
@@ -8616,6 +8616,12 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
        return this.zoom_ratios.get(zoom_factor)/100.0f;
    }

    public float getZoomRatio(int index) {
        if( zoom_ratios == null )
            return 1.0f;
        return this.zoom_ratios.get(index)/100.0f;
    }

    public float getMinZoomRatio() {
        if( zoom_ratios == null )
            return 1.0f;