001/*******************************************************************************
002 * This software is provided as a supplement to the authors' textbooks on digital
003 * image processing published by Springer-Verlag in various languages and editions.
004 * Permission to use and distribute this software is granted under the BSD 2-Clause
005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause).
006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved.
007 * Visit https://imagingbook.com for additional details.
008 ******************************************************************************/
009package imagingbook.common.color.gamma;
010
011/**
012 * <p>
013 * Defines the basic "gamma correction" used for converting linear to non-linear color component values. The mapping
014 * function consists of a non-linear part only. Note that {@code gamma} specifies the nominal &gamma; parameter for the
015 * <em>forward</em> (i.e., linear to non-linear) mapping, e.g., &gamma; ~ 1/2.2 for Adobe RGB. See Sec. 3.7.2 of [1] for
016 * more details.
017 * </p>
018 * <p>
019 * [1] W. Burger, M.J. Burge, <em>Digital Image Processing &ndash; An Algorithmic Introduction</em>, 3rd ed, Springer
020 * (2022).
021 * </p>
022 *
023 * @author WB
024 * @version 2022/11/14
025 */
026public class SimpleGammaMapping implements GammaMapping {
027        
028        private final double gamma;
029        private final double igamma;
030
031        /**
032         * Constructor.
033         * @param gamma nominal &gamma; value for the forward mapping (e.g., &gamma; ~ 1/2.2 for Adobe RGB)
034         */
035        public SimpleGammaMapping(double gamma) {
036                this.gamma = gamma;
037                this.igamma = 1.0 / gamma;
038        }
039
040        @Override
041        public double applyFwd(double a) {
042                return Math.pow(a, gamma);
043        }
044
045        @Override
046        public double applyInv(double b) {
047                return Math.pow(b, igamma);
048        }
049
050}