aboutsummaryrefslogtreecommitdiff
path: root/src/HeightMapReader.java
blob: 83376fc5f1e2c312239360b16e81b09762f974b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*    */ import java.awt.Color;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.io.File;
/*    */ import javax.imageio.ImageIO;
/*    */ 
/*    */ public class HeightMapReader
/*    */ {
/*    */   private BufferedImage heightMap;
/*    */   private double multiplier;
/*    */ 
/*    */   public HeightMapReader(String file, double multiplier)
/*    */     throws Exception
/*    */   {
/* 18 */     this(new File(file), multiplier);
/*    */   }
/*    */   public HeightMapReader(File file, double multiplier) throws Exception {
/* 21 */     this(ImageIO.read(file), multiplier);
/*    */   }
/*    */   public HeightMapReader(BufferedImage image, double multiplier) {
/* 24 */     this.heightMap = image;
/* 25 */     this.multiplier = multiplier;
/*    */   }
/*    */   public Point3D readPoint(int x, int y) {
/* 28 */     Color pixelColor = new Color(this.heightMap.getRGB(x, y));
/*    */ 
/* 30 */     return new Point3D(x - this.heightMap.getWidth() / 2.0D, pixelColor.getRed() * this.multiplier, y - this.heightMap.getHeight() / 2.0D);
/*    */   }
/*    */ 
/*    */   public Point3D[][] readAll(int xstep, int ystep) {
/* 34 */     Point3D[][] ret = new Point3D[this.heightMap.getWidth() / xstep][this.heightMap.getHeight() / ystep];
/*    */ 
/* 36 */     for (int x = 0; (x < ret.length * xstep) && (x < this.heightMap.getWidth()); x += xstep) {
/* 37 */       Point3D[] toAdd = new Point3D[this.heightMap.getWidth() / xstep];
/* 38 */       for (int y = 0; (y < toAdd.length * ystep) && (y < this.heightMap.getHeight()); y += ystep) {
/* 39 */         toAdd[(y / ystep)] = readPoint(x, y);
/*    */       }
/* 41 */       ret[(x / xstep)] = toAdd;
/*    */     }
/*    */ 
/* 44 */     return ret;
/*    */   }
/* 46 */   public double getMultiplier() { return this.multiplier; } 
/*    */   public Color getColorAt(int x, int y) {
/* 48 */     return new Color(this.heightMap.getRGB(x, y));
/*    */   }
/*    */ }

/* Location:           Modulus.jar
 * Qualified Name:     HeightMapReader
 * JD-Core Version:    0.6.2
 */