001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.image.colormap;
020
021import icy.util.ColorUtil;
022
023import java.awt.Color;
024
025/**
026 * @author stephane
027 */
028public class LinearColorMap extends IcyColorMap
029{
030    /**
031     * A built-in 'black-to-black' linear color map
032     */
033    public static final LinearColorMap black_ = new LinearColorMap("Black", Color.black, IcyColorMapType.GRAY);
034
035    /**
036     * A built-in 'black-to-white' linear color map
037     */
038    public static final LinearColorMap gray_ = new LinearColorMap("Gray", Color.white, IcyColorMapType.GRAY);
039    public static final LinearColorMap white_ = gray_;
040
041    /**
042     * A built-in 'white-to-black' linear color map
043     */
044    public static final LinearColorMap gray_inv_ = new LinearColorMap("Gray inverse", Color.white, Color.black,
045            IcyColorMapType.GRAY);
046    public static final LinearColorMap white_inv_ = gray_inv_;
047
048    /**
049     * A built-in 'black-to-red' linear color map
050     */
051    public static final LinearColorMap red_ = new LinearColorMap("Red", Color.red);
052
053    /**
054     * A built-in 'black-to-blue' linear color map
055     */
056    public static final LinearColorMap blue_ = new LinearColorMap("Blue", Color.blue);
057
058    /**
059     * A built-in 'black-to-pink' linear color map
060     */
061    public static final LinearColorMap pink_ = new LinearColorMap("Pink", Color.pink);
062
063    /**
064     * A built-in 'black-to-cyan' linear color map
065     */
066    public static final LinearColorMap cyan_ = new LinearColorMap("Cyan", Color.cyan);
067
068    /**
069     * A built-in 'black-to-orange' linear color map
070     */
071    public static final LinearColorMap orange_ = new LinearColorMap("Orange", Color.orange);
072
073    /**
074     * A built-in 'black-to-yellow' linear color map
075     */
076    public static final LinearColorMap yellow_ = new LinearColorMap("Yellow", Color.yellow);
077
078    /**
079     * A built-in 'black-to-green' linear color map
080     */
081    public static final LinearColorMap green_ = new LinearColorMap("Green", Color.green);
082
083    /**
084     * A built-in 'black-to-magenta' linear color map
085     */
086    public static final LinearColorMap magenta_ = new LinearColorMap("Magenta", Color.magenta);
087
088    /**
089     * A built-in 'transparent-to-opaque' linear color map
090     */
091    public static final LinearColorMap alpha_ = new LinearColorMap("Alpha", new Color(0f, 0f, 0f, 0f), new Color(0f,
092            0f, 0f, 1f), IcyColorMapType.ALPHA);
093
094    /**
095     * Creates a simple color map using a linear gradient of the given Color.
096     */
097    public LinearColorMap(String mapName, Color color)
098    {
099        this(mapName, Color.black, color, IcyColorMapType.RGB);
100    }
101
102    /**
103     * Creates a simple color map using a linear gradient of the given Color.
104     */
105    public LinearColorMap(String mapName, Color color, IcyColorMapType type)
106    {
107        this(mapName, Color.black, color, type);
108    }
109
110    /**
111     * Creates a simple color map using a linear gradient from 'colorFrom' to 'colorTo'.
112     */
113    public LinearColorMap(String mapName, Color colorFrom, Color colorTo)
114    {
115        this(mapName, colorFrom, colorTo, IcyColorMapType.RGB);
116    }
117
118    /**
119     * Creates a simple color map using a linear gradient from 'colorFrom' to 'colorTo'.
120     */
121    public LinearColorMap(String mapName, Color colorFrom, Color colorTo, IcyColorMapType type)
122    {
123        super(mapName, type);
124
125        beginUpdate();
126        try
127        {
128            red.setControlPoint(0, colorFrom.getRed());
129            green.setControlPoint(0, colorFrom.getGreen());
130            blue.setControlPoint(0, colorFrom.getBlue());
131            gray.setControlPoint(0, ColorUtil.getGrayMix(colorFrom));
132            alpha.setControlPoint(0, colorFrom.getAlpha());
133
134            red.setControlPoint(MAX_INDEX, colorTo.getRed());
135            green.setControlPoint(MAX_INDEX, colorTo.getGreen());
136            blue.setControlPoint(MAX_INDEX, colorTo.getBlue());
137            gray.setControlPoint(MAX_INDEX, ColorUtil.getGrayMix(colorTo));
138            alpha.setControlPoint(MAX_INDEX, colorTo.getAlpha());
139        }
140        finally
141        {
142            endUpdate();
143        }
144    }
145
146}