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

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

New "Auto source" mode for focus bracketing.

parent d67c05d4
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -239,8 +239,11 @@ will be available which instead work by making the screen light up (note, front
    mode. (Only available on some devices, and if Camera2 API is
    used.) This mode takes a series of photos each with a different focus distance. Two sliders appear, allowing you
    to change the "source" and "target" focus distance. In this mode, you can change the number of photos to take from
    the popup menu. Also on the popup menu, the option "Add infinite distance" if enabled will mean an extra photo is
    taken, at infinite focus distance. Focus bracketing is typically used with
    the popup menu, and the option "Add infinite distance" if enabled will mean an extra photo is taken, at infinite focus distance.
    Also on the popup menu, enabling "Auto source" will mean that the "source" focus distance will be set automatically via
    continuous focus (or touching to focus will also select the source focus distance in this mode). Manually adjusting the
    source focus distance slider will exit "Auto source" mode.
    Focus bracketing is typically used with
    <a href="https://en.wikipedia.org/wiki/Focus_stacking">Focus stacking</a> software to merge the images into a single
    photo. Note that whilst taking a set of focus bracketed photos, you can cancel the set by pressing the "take photo"
    button again. Also see the options "Focus assist" and "Focus peaking" under Settings/Camera preview/
+2 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ ADDED Support for choosing a specific physical lens (e.g., specifically choosi
        on supported devices (requires Android 9+ and Camera2 API).
ADDED   Support for UltraHDR on supported devices, under Settings/Photo settings/"Image format"
        (requires Android 14+ and Camera2 API).
ADDED   New "Auto source" mode for focus bracketing: in this mode, the source focus distance will be
        automatically set via continuous focus or touch to focus.
UPDATED Now requires Android 5+, Android 4.x no longer supported (sorry to anyone still on those
        devices - but latest AndroidX libraries now require Android 5+).
UPDATED Improved performance for Camera2 API (on Android 12+) for taking photos with continuous
+31 −4
Original line number Diff line number Diff line
@@ -5995,22 +5995,38 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
        }
    }

    public void setManualFocusSeekbarProgress(final boolean is_target_distance, float focus_distance) {
        final SeekBar focusSeekBar = findViewById(is_target_distance ? R.id.focus_bracketing_target_seekbar : R.id.focus_seekbar);
        ManualSeekbars.setProgressSeekbarScaled(focusSeekBar, 0.0, preview.getMinimumFocusDistance(), focus_distance);
    }

    private void setManualFocusSeekbar(final boolean is_target_distance) {
        if( MyDebug.LOG )
            Log.d(TAG, "setManualFocusSeekbar");
        final SeekBar focusSeekBar = findViewById(is_target_distance ? R.id.focus_bracketing_target_seekbar : R.id.focus_seekbar);
        focusSeekBar.setOnSeekBarChangeListener(null); // clear an existing listener - don't want to call the listener when setting up the progress bar to match the existing state
        ManualSeekbars.setProgressSeekbarScaled(focusSeekBar, 0.0, preview.getMinimumFocusDistance(), is_target_distance ? preview.getCameraController().getFocusBracketingTargetDistance() : preview.getCameraController().getFocusDistance());
        setManualFocusSeekbarProgress(is_target_distance, is_target_distance ? preview.getCameraController().getFocusBracketingTargetDistance() : preview.getCameraController().getFocusDistance());
        focusSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            private boolean has_saved_zoom;
            private int saved_zoom_factor;

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if( !is_target_distance && applicationInterface.isFocusBracketingSourceAutoPref() ) {
                    // source is set from continuous focus, not by changing the seekbar
                    if( fromUser ) {
                        // but if user has manually changed, then exit auto mode
                        applicationInterface.setFocusBracketingSourceAutoPref(false);
                        mainUI.destroyPopup(); // need to recreate popup
                    }
                    else {
                        return;
                    }
                }
                double frac = progress/(double)focusSeekBar.getMax();
                double scaling = ManualSeekbars.seekbarScaling(frac);
                float focus_distance = (float)(scaling * preview.getMinimumFocusDistance());
                preview.setFocusDistance(focus_distance, is_target_distance);
                preview.setFocusDistance(focus_distance, is_target_distance, true);
            }

            @Override
@@ -6047,10 +6063,13 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
    }

    public boolean showManualFocusSeekbar(final boolean is_target_distance) {
        boolean is_visible = preview.getCurrentFocusValue() != null && this.getPreview().getCurrentFocusValue().equals("focus_mode_manual2");
        if( (applicationInterface.getPhotoMode() == MyApplicationInterface.PhotoMode.FocusBracketing) && !preview.isVideo() ) {
            return true; // both seekbars shown in focus bracketing mode
        }
        if( is_target_distance ) {
            is_visible = is_visible && (applicationInterface.getPhotoMode() == MyApplicationInterface.PhotoMode.FocusBracketing) && !preview.isVideo();
            return false; // target seekbar only shown in focus bracketing mode
        }
        boolean is_visible = preview.getCurrentFocusValue() != null && this.getPreview().getCurrentFocusValue().equals("focus_mode_manual2");
        return is_visible;
    }

@@ -6141,6 +6160,14 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
        return preview.supportsFocusBracketing();
    }

    /** Whether we support the auto mode for setting source focus distance for focus bracketing mode.
     *  Note the caller should still separately call supportsFocusBracketing() to see if focus
     *  bracketing is supported in the first place.
     */
    public boolean supportsFocusBracketingSourceAuto() {
        return preview.supportsFocus() && preview.getSupportedFocusValues().contains("focus_mode_continuous_picture");
    }

    public boolean supportsPanorama() {
        // don't support panorama mode if called from image capture intent
        // in theory this works, but problem that currently we'd end up doing the processing on the UI thread, so risk ANR
+26 −2
Original line number Diff line number Diff line
@@ -440,9 +440,13 @@ public class MyApplicationInterface extends BasicApplicationInterface {
    @Override
    public String getFocusPref(boolean is_video) {
        if( getPhotoMode() == PhotoMode.FocusBracketing && !main_activity.getPreview().isVideo() ) {
            // alway run in manual focus mode for focus bracketing
            if( isFocusBracketingSourceAutoPref() ) {
                return "focus_mode_continuous_picture";
            }
            else {
                return "focus_mode_manual2";
            }
        }
        return sharedPreferences.getString(PreferenceKeys.getFocusPreferenceKey(cameraId, is_video), "");
    }

@@ -1536,6 +1540,26 @@ public class MyApplicationInterface extends BasicApplicationInterface {
        return sharedPreferences.getFloat(is_target_distance ? PreferenceKeys.FocusBracketingTargetDistancePreferenceKey : PreferenceKeys.FocusDistancePreferenceKey, 0.0f);
    }

    @Override
    public boolean isFocusBracketingSourceAutoPref() {
        if( !main_activity.supportsFocusBracketingSourceAuto() )
            return false; // not supported
        return sharedPreferences.getBoolean(PreferenceKeys.FocusBracketingAutoSourceDistancePreferenceKey, false);
    }

    /** Sets whether in focus bracketing auto focusing mode for source focus distance.
     *  If enabled==false (i.e. returning to manual mode), the caller should call Preview.setFocusDistance()
     *  to set the new manual focus distance.
     */
    public void setFocusBracketingSourceAutoPref(boolean enabled) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(PreferenceKeys.FocusBracketingAutoSourceDistancePreferenceKey, enabled);
        editor.apply();
        if( main_activity.getPreview().getCameraController() != null ) {
            main_activity.getPreview().setFocusPref(true);
        }
    }

    @Override
    public boolean isExpoBracketingPref() {
        PhotoMode photo_mode = getPhotoMode();
+2 −0
Original line number Diff line number Diff line
@@ -111,6 +111,8 @@ public class PreferenceKeys {

    public static final String FocusBracketingTargetDistancePreferenceKey = "preference_focus_bracketing_target_distance";

    public static final String FocusBracketingAutoSourceDistancePreferenceKey = "preference_focus_bracketing_auto_source_distance";

    public static final String FocusBracketingNImagesPreferenceKey = "preference_focus_bracketing_n_images";

    public static final String FocusBracketingAddInfinityPreferenceKey = "preference_focus_bracketing_add_infinity";
Loading