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
021/**
022 * @author stephane
023 */
024public class FromRGBColorMap
025{
026    /**
027     * define colormap size
028     */
029    public static final int COLORMAP_SIZE = 0x100;
030    public static final int COLORMAP_MAX = COLORMAP_SIZE - 1;
031
032    /**
033     * normalized maps
034     */
035    public final float[][] maps;
036
037    /**
038         * 
039         */
040    public FromRGBColorMap(int numComponents)
041    {
042        // normalized maps
043        maps = new float[numComponents][COLORMAP_SIZE];
044
045        // default [0..1]
046        for (int comp = 0; comp < numComponents; comp++)
047        {
048            for (int index = 0; index < COLORMAP_SIZE; index++)
049            {
050                maps[comp][index] = (float) index / COLORMAP_MAX;
051            }
052        }
053    }
054
055    /**
056     * Get normalized component intensity from a normalized input RGB value
057     */
058    public float getFromRGBColor(int component, float rgbValue)
059    {
060        return maps[component][(int) (rgbValue * COLORMAP_MAX)];
061    }
062
063    /**
064     * Get normalized component intensity from a unnormalized input RGB value
065     */
066    public float getFromRGBColor(int component, int rgbValue)
067    {
068        return maps[component][rgbValue];
069    }
070
071    /**
072     * Set normalized component intensity for a normalized input RGB value
073     */
074    public void setFromRGBColor(int component, float rgbValue, float value)
075    {
076        maps[component][(int) (rgbValue * COLORMAP_MAX)] = value;
077    }
078
079}