001/*
002Copyright 2006 Jerry Huxtable
003
004Licensed under the Apache License, Version 2.0 (the "License");
005you may not use this file except in compliance with the License.
006You may obtain a copy of the License at
007
008   http://www.apache.org/licenses/LICENSE-2.0
009
010Unless required by applicable law or agreed to in writing, software
011distributed under the License is distributed on an "AS IS" BASIS,
012WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013See the License for the specific language governing permissions and
014limitations under the License.
015*/
016
017package com.jhlabs.image;
018
019import java.awt.*;
020import java.awt.image.*;
021
022/**
023 * A filter which changes the gain and bias of an image - similar to ContrastFilter.
024 */
025public class GainFilter extends TransferFilter {
026
027        private float gain = 0.5f;
028        private float bias = 0.5f;
029        
030        protected float transferFunction( float f ) {
031                f = ImageMath.gain(f, gain);
032                f = ImageMath.bias(f, bias);
033                return f;
034        }
035
036    /**
037     * Set the gain.
038     * @param gain the gain
039     * @min-value: 0
040     * @max-value: 1
041     * @see #getGain
042     */
043        public void setGain(float gain) {
044                this.gain = gain;
045                initialized = false;
046        }
047        
048    /**
049     * Get the gain.
050     * @return the gain
051     * @see #setGain
052     */
053        public float getGain() {
054                return gain;
055        }
056
057    /**
058     * Set the bias.
059     * @param bias the bias
060     * @min-value: 0
061     * @max-value: 1
062     * @see #getBias
063     */
064        public void setBias(float bias) {
065                this.bias = bias;
066                initialized = false;
067        }
068        
069    /**
070     * Get the bias.
071     * @return the bias
072     * @see #setBias
073     */
074        public float getBias() {
075                return bias;
076        }
077
078        public String toString() {
079                return "Colors/Gain...";
080        }
081
082}
083