Ignore:
Timestamp:
2016-04-16T23:59:37+02:00 (8 years ago)
Author:
bastiK
Message:

fixed #12758 - better scale for gamma value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java

    r10144 r10148  
    4040public final class LayerVisibilityAction extends AbstractAction implements IEnabledStateUpdating, LayerAction {
    4141    protected static final int SLIDER_STEPS = 100;
    42     private static final double MAX_GAMMA_FACTOR = 2;
    4342    private static final double MAX_SHARPNESS_FACTOR = 2;
    4443    private static final double MAX_COLORFUL_FACTOR = 2;
     
    316315         */
    317316        GammaFilterSlider() {
    318             super(0, MAX_GAMMA_FACTOR, ImageryLayer.class);
     317            super(-1, 1, ImageryLayer.class);
    319318            setToolTipText(tr("Adjust gamma value of the layer."));
    320319        }
     
    323322        protected void updateSliderWhileEnabled(Collection<? extends Layer> usedLayers, boolean allHidden) {
    324323            double gamma = ((ImageryLayer) usedLayers.iterator().next()).getGamma();
    325             setRealValue(gamma);
     324            setRealValue(mapGammaToInterval(gamma));
    326325        }
    327326
    328327        @Override
    329328        protected void applyValueToLayer(ImageryLayer layer) {
    330             layer.setGamma(getRealValue());
     329            layer.setGamma(mapIntervalToGamma(getRealValue()));
    331330        }
    332331
     
    339338        public String getLabel() {
    340339            return tr("Gamma");
     340        }
     341
     342        /**
     343         * Maps a number x from the range (-1,1) to a gamma value.
     344         * Gamma value is in the range (0, infinity).
     345         * Gamma values of 3 and 1/3 have opposite effects, so the mapping
     346         * should be symmetric in that sense.
     347         * @param x the slider value in the range (-1,1)
     348         * @return the gamma value
     349         */
     350        private double mapIntervalToGamma(double x) {
     351            // properties of the mapping:
     352            // g(-1) = 0
     353            // g(0) = 1
     354            // g(1) = infinity
     355            // g(-x) = 1 / g(x)
     356            return (1 + x) / (1 - x);
     357        }
     358
     359        private double mapGammaToInterval(double gamma) {
     360            return (gamma - 1) / (gamma + 1);
    341361        }
    342362    }
Note: See TracChangeset for help on using the changeset viewer.