Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 6e8364e766fa |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
590:5f5f273c8566 | 657:af3f56758f59 |
---|---|
1 package de.intevation.gnv.raster; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.OutputStream; | |
5 | |
6 import java.awt.Color; | |
7 | |
8 /** | |
9 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | |
10 */ | |
11 public class RasterToPPM | |
12 { | |
13 private RasterToPPM() { | |
14 } | |
15 | |
16 public static void writeToPPM(Raster raster, Palette palette, OutputStream out) | |
17 throws IOException | |
18 { | |
19 int W = raster.getWidth(); | |
20 int H = raster.getHeight(); | |
21 out.write(("P6\n" + W + " " + H + "\n255\n").getBytes("US-ASCII")); | |
22 double [] values = raster.getValues(); | |
23 int pos = 0; | |
24 byte [] data = new byte[W*3]; | |
25 int black = Color.BLACK.getRGB(); | |
26 for (int i = 0; i < H; ++i) { | |
27 for (int j = 0; j < data.length; ++pos) { | |
28 Palette.Entry entry = palette.getEntry(values[pos]); | |
29 int rgb = entry == null | |
30 ? black | |
31 : entry.getColor().getRGB(); | |
32 data[j++] = (byte)((rgb >> 16) & 0xff); | |
33 data[j++] = (byte)((rgb >> 8) & 0xff); | |
34 data[j++] = (byte)( rgb & 0xff); | |
35 } | |
36 out.write(data); | |
37 } | |
38 out.flush(); | |
39 } | |
40 } | |
41 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |