From efe8c7c31c9957dcfabf4be8ee7dc730c9a775d2 Mon Sep 17 00:00:00 2001 From: Tomas Krajci Date: Fri, 5 Oct 2018 23:38:11 +0200 Subject: [PATCH] Better processing of PNG heightmap import --- .gitignore | 6 ++++++ src/net/buddat/wgenerator/HeightMap.java | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b267804..c3dd5cc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,9 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# IntelliJ project files +.idea +*.iml +out +maps/ \ No newline at end of file diff --git a/src/net/buddat/wgenerator/HeightMap.java b/src/net/buddat/wgenerator/HeightMap.java index 6b4281f..7e842bd 100644 --- a/src/net/buddat/wgenerator/HeightMap.java +++ b/src/net/buddat/wgenerator/HeightMap.java @@ -2,6 +2,7 @@ import java.awt.image.BufferedImage; import java.awt.image.DataBufferUShort; +import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.io.File; import java.io.IOException; @@ -83,18 +84,17 @@ private void importHeightImage() { } long startTime = System.currentTimeMillis(); - try { - DataBufferUShort buffer = (DataBufferUShort) heightImage.getRaster().getDataBuffer(); + Raster data = heightImage.getData(); - int[][] array = new int[mapSize][mapSize]; + for (int x = 0; x < mapSize; x++) { + for (int y = 0; y < mapSize; y++) { - for (int x = 0; x < mapSize; x++) { - for (int y = 0; y < mapSize; y++) { + double[] dArray = null; - array[x][y] = buffer.getElem(x + y * mapSize); + dArray = data.getPixel(x,y, dArray); - setHeight(x, y, getHeight(x, y) + (array[x][y] / 65536f), false); + setHeight(x, y, getHeight(x, y) + (dArray[0] / 65536f), false); } }