annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java @ 1095:c961cd9a13f7

Write svn revision to MANIFEST file while creating jar archive. gnv-artifacts/trunk@1211 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 14 Jun 2010 21:12:23 +0000
parents d766fe2d917a
children f953c9a559d8
rev   line source
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.raster;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 495
diff changeset
3 import java.awt.Color;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 495
diff changeset
4
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.io.IOException;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.io.OutputStream;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 /**
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
9 * Little helper class to write a Raster into an output stream
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
10 * as a Netpbm PPM file.
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
11 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 */
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 public class RasterToPPM
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 {
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 private RasterToPPM() {
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 }
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
18 /**
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
19 * Writes a Raster to a given stream as PPM.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
20 * @param raster The raster to be written.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
21 * @param palette The palette used to figure out the rgb values.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
22 * @param out The stream to write into.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
23 * @throws IOException Thrown if some error occurred during writing
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
24 * data to the output stream.
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
25 */
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
26 public static void writeToPPM(
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
27 Raster raster,
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
28 Palette palette,
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
29 OutputStream out
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
30 )
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 throws IOException
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 {
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 int W = raster.getWidth();
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 int H = raster.getHeight();
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 out.write(("P6\n" + W + " " + H + "\n255\n").getBytes("US-ASCII"));
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 double [] values = raster.getValues();
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 int pos = 0;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 byte [] data = new byte[W*3];
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 int black = Color.BLACK.getRGB();
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 for (int i = 0; i < H; ++i) {
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 for (int j = 0; j < data.length; ++pos) {
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 Palette.Entry entry = palette.getEntry(values[pos]);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 int rgb = entry == null
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 ? black
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 : entry.getColor().getRGB();
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 data[j++] = (byte)((rgb >> 16) & 0xff);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 data[j++] = (byte)((rgb >> 8) & 0xff);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 data[j++] = (byte)( rgb & 0xff);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 }
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 out.write(data);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 out.flush();
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 }
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org