view gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java @ 779:b1f5f2a8840f

Ordered imports. Removed needless imports. Removed empty headers. gnv-artifacts/trunk@854 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 08:51:20 +0000
parents 6e8364e766fa
children c4156275c1e1
line wrap: on
line source
package de.intevation.gnv.raster;

import java.awt.Color;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
 */
public class RasterToPPM
{
    private RasterToPPM() {
    }

    public static void writeToPPM(Raster raster, Palette palette, OutputStream out)
    throws IOException
    {
        int W = raster.getWidth();
        int H = raster.getHeight();
        out.write(("P6\n" + W + " " + H + "\n255\n").getBytes("US-ASCII"));
        double [] values = raster.getValues();
        int pos = 0;
        byte [] data = new byte[W*3];
        int black = Color.BLACK.getRGB();
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < data.length; ++pos) {
                Palette.Entry entry = palette.getEntry(values[pos]);
                int rgb = entry == null
                    ? black
                    : entry.getColor().getRGB();
                data[j++] = (byte)((rgb >> 16) & 0xff);
                data[j++] = (byte)((rgb >>  8) & 0xff);
                data[j++] = (byte)( rgb        & 0xff);
            }
            out.write(data);
        }
        out.flush();
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org