view artifacts/src/main/java/org/dive4elements/river/jfree/ColorMapper.java @ 9602:6b2496d71936

Reimplemented baseline for tkh. Extended area-dataset to be able to draw baseline.
author gernotbelger
date Tue, 12 Feb 2019 14:08:16 +0100
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