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 simply multiplies pixel values by a given scale factor.
024 */
025public class RescaleFilter extends TransferFilter {
026        
027        private float scale = 1.0f;
028        
029        public RescaleFilter() {
030    }
031    
032        public RescaleFilter(float scale) {
033                this.scale = scale;
034    }
035    
036    protected float transferFunction( float v ) {
037                return v * scale;
038        }
039
040        /**
041     * Specifies the scale factor.
042     * @param scale the scale factor.
043     * @min-value 1
044     * @max-value 5+
045     * @see #getScale
046     */
047        public void setScale(float scale) {
048                this.scale = scale;
049                initialized = false;
050        }
051        
052        /**
053     * Returns the scale factor.
054     * @return the scale factor.
055     * @see #setScale
056     */
057        public float getScale() {
058                return scale;
059        }
060
061        public String toString() {
062                return "Colors/Rescale...";
063        }
064
065}
066