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
022public class CurvesFilter extends TransferFilter {
023
024        private Curve[] curves = new Curve[1];
025        
026    public CurvesFilter() {
027        curves = new Curve[3];
028        curves[0] = new Curve();
029        curves[1] = new Curve();
030        curves[2] = new Curve();
031    }
032    
033        protected void initialize() {
034                initialized = true;
035                if ( curves.length == 1 )
036            rTable = gTable = bTable = curves[0].makeTable();
037        else {
038            rTable = curves[0].makeTable();
039            gTable = curves[1].makeTable();
040            bTable = curves[2].makeTable();
041        }
042        }
043
044        public void setCurve( Curve curve ) {
045        curves = new Curve[] { curve };
046                initialized = false;
047        }
048        
049        public void setCurves( Curve[] curves ) {
050                if ( curves == null || (curves.length != 1 && curves.length != 3) )
051            throw new IllegalArgumentException( "Curves must be length 1 or 3" );
052        this.curves = curves;
053                initialized = false;
054        }
055        
056        public Curve[] getCurves() {
057                return curves;
058        }
059
060        public String toString() {
061                return "Colors/Curves...";
062        }
063
064}
065