Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java @ 540:80630520e25a
merged gnv-artifacts/0.4
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:49 +0200 |
parents | 6e8364e766fa |
children | b1f5f2a8840f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java Fri Sep 28 12:13:49 2012 +0200 @@ -0,0 +1,41 @@ +package de.intevation.gnv.raster; + +import java.io.IOException; +import java.io.OutputStream; + +import java.awt.Color; + +/** + * @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 :