view artifacts/src/main/java/org/dive4elements/river/jfree/ColorMapper.java @ 9181:5dacb6ea75a1

Fixed: pattern got wrong colors
author gernotbelger
date Tue, 26 Jun 2018 20:18:18 +0200
parents d9c89651bd67
children c5c53e52f190
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 compare rgb, so we even keep the transparency level
        if (src[0] == this.from[0] && src[1] == this.from[1] && src[2] == this.from[2]) {
            out[0] = this.to[0];
            out[1] = this.to[1];
            out[2] = this.to[2];
            out[3] = src[3];
        } else {
            System.arraycopy(src, 0, out, 0, src.length);
        }

        return out;
    }
}

http://dive4elements.wald.intevation.org