Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/RasterToPPM.java @ 787:6cd8492019d8
Validate wkt string and display error messages if the validation failed (issue214).
gnv-artifacts/trunk@869 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 30 Mar 2010 16:51:20 +0000 |
parents | c4156275c1e1 |
children | d766fe2d917a |
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 /** |
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
|
9 * @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
|
10 */ |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 public class RasterToPPM |
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 private 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 |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 public static void writeToPPM(Raster raster, Palette palette, OutputStream out) |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 throws IOException |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 { |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 int W = raster.getWidth(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 int H = raster.getHeight(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 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
|
22 double [] values = raster.getValues(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 int pos = 0; |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 byte [] data = new byte[W*3]; |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 int black = Color.BLACK.getRGB(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 for (int i = 0; i < H; ++i) { |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 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
|
28 Palette.Entry entry = palette.getEntry(values[pos]); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 int rgb = entry == null |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 ? black |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 : entry.getColor().getRGB(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 data[j++] = (byte)((rgb >> 16) & 0xff); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 data[j++] = (byte)((rgb >> 8) & 0xff); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 data[j++] = (byte)( rgb & 0xff); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 out.write(data); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 out.flush(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |