From 22ac70761257d5eb045762846e598b51e82aef50 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 3 Sep 2017 20:28:01 +1000 Subject: [PATCH] Fix cfi smooth edges --- .../fawe/jnbt/anvil/HeightMapMCAGenerator.java | 12 ++++++------ .../fawe/object/collection/SummedAreaTable.java | 16 +++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java index 71460778..b03f8e65 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java @@ -142,9 +142,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { for (int x = 0; x < getWidth(); x++, index++) { int height = img.getRGB(x, z) & 0xFF; if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) { - int newHeight = table.average(x, z, index); - int blockHeight = (newHeight - 1) >> 3; - int layerHeight = (newHeight - 1) & 0x7; + int newHeight = table.average(x, z, index) - 1; + int blockHeight = (newHeight) >> 3; + int layerHeight = (newHeight) & 0x7; heights[index] = (byte) blockHeight; int id = floor[index] >> 4; if (id == 78 || id == 80) { @@ -161,9 +161,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { mutable.mutX(x); mutable.mutY(y); if (mask.test(mutable)) { - int height = table.average(x, z, index); - int blockHeight = (height - 1) >> 3; - int layerHeight = (height - 1) & 0x7; + int newHeight = table.average(x, z, index) - 1; + int blockHeight = (newHeight) >> 3; + int layerHeight = (newHeight) & 0x7; heights[index] = (byte) blockHeight; int id = floor[index] >> 4; if (id == 78 || id == 80) { diff --git a/core/src/main/java/com/boydti/fawe/object/collection/SummedAreaTable.java b/core/src/main/java/com/boydti/fawe/object/collection/SummedAreaTable.java index 9fe5e36d..f4127b30 100644 --- a/core/src/main/java/com/boydti/fawe/object/collection/SummedAreaTable.java +++ b/core/src/main/java/com/boydti/fawe/object/collection/SummedAreaTable.java @@ -10,6 +10,7 @@ public class SummedAreaTable { private final int area; private final int radius; private final float areaInverse; + private final float[] areaInverses; public SummedAreaTable(long[] buffer, char[] matrix, int width, int radius) { this.source = matrix; @@ -19,6 +20,10 @@ public class SummedAreaTable { this.radius = radius; this.area = MathMan.sqr(radius * 2 + 1); this.areaInverse = 1f / area; + this.areaInverses = new float[area - 2]; + for (int area = 2; area < this.area; area++) { + this.areaInverses[area - 2] = 1f / area; + } } public void processSummedAreaTable() { @@ -27,7 +32,8 @@ public class SummedAreaTable { int index = 0; for (int i = 0; i < rowSize; i++) { for (int j = 0; j < colSize; j++, index++) { - summed[index] = getVal(i, j, index, source[index]); + long val = getVal(i, j, index, source[index]); + summed[index] = val; } } } @@ -43,8 +49,8 @@ public class SummedAreaTable { int minZ = Math.max(0, z - radius) - z; int maxX = Math.min(width - 1, x + radius) - x; int maxZ = Math.min(length - 1, z + radius) - z; - int maxzw = maxZ * width; - int XZ = index + maxzw + maxX; + int maxzwi = maxZ * width; + int XZ = index + maxzwi + maxX; int area = (maxX - minX + 1) * (maxZ - minZ + 1); long total = getSum(XZ); @@ -52,7 +58,7 @@ public class SummedAreaTable { int minzw = minZ * width; int Z = index + minzw + maxX; if (x > radius) { - int X = index + minX + maxzw; + int X = index + minX + maxzwi; int M = index + minzw + minX; total -= summed[X - 1]; total += getSum(M - width - 1); @@ -61,7 +67,7 @@ public class SummedAreaTable { if (area == this.area) { return (int) (total * areaInverse); } else { - return MathMan.lossyFastDivide((int) total, area); + return Math.round(total * areaInverses[area - 2]); } }