view artifacts/src/main/java/org/dive4elements/river/jfree/ColorMapper.java @ 9611:8ed6c45136fa

#20 UI
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Wed, 09 Oct 2019 15:58:46 +0200
parents c5c53e52f190
children
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.jfree;

import java.awt.Color;
import java.awt.image.LookupTable;

final class ColorMapper extends LookupTable {

    private final int[] from;
    private final int[] to;

    public ColorMapper(final Color from, final Color to) {
        super(0, 4);

        this.from = new int[] { from.getRed(), from.getGreen(), from.getBlue(), from.getAlpha(), };
        this.to = new int[] { to.getRed(), to.getGreen(), to.getBlue(), to.getAlpha(), };
    }

    @Override
    public int[] lookupPixel(final int[] src, final int[] dest) {
        final int[] out = dest == null ? new int[src.length] : dest;

        // REMARK: only check opacity, because the transparency of the pattern-images is not 100% good
        if (src[3] > 128) {
            out[0] = this.to[0];
            out[1] = this.to[1];
            out[2] = this.to[2];
            out[3] = this.to[3];
        } else {
            out[0] = 0;
            out[1] = 0;
            out[2] = 0;
            out[3] = 0;
        }

        return out;
    }
}

http://dive4elements.wald.intevation.org