X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Ftexture%2FTexture.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Ftexture%2FTexture.java;h=6009bb8025d4409fe4f34b593998261ee2c6031c;hp=0a677bd79a54e01e00f39e834cc255d9cd031137;hb=24e68b2f99037dec8a3442030dcb15013c930652;hpb=316a696bf9db6e8eddf90ef3df5e1119481c0192 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/texture/Texture.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/texture/Texture.java index 0a677bd..6009bb8 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/texture/Texture.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/texture/Texture.java @@ -11,6 +11,8 @@ import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image.WritableRaster; +import static java.util.Arrays.fill; + public class Texture { public final TextureBitmap primaryBitmap; @@ -59,6 +61,12 @@ public class Texture { return upSampled.length - 1; } + /** + * Downscale given bitmap by factor of 2. + * + * @param originalBitmap Bitmap to downscale. + * @return Downscaled bitmap. + */ public TextureBitmap downscaleBitmap(final TextureBitmap originalBitmap) { int newWidth = originalBitmap.width / 2; int newHeight = originalBitmap.height / 2; @@ -103,6 +111,11 @@ public class Texture { return downSampled[scaleFactor]; } + /** + * Returns the bitmap that should be used for rendering at the given zoom + * @param scaleFactor The upscale factor + * @return The bitmap + */ public TextureBitmap getUpscaledBitmap(final int scaleFactor) { if (upSampled[scaleFactor] == null) { @@ -118,6 +131,11 @@ public class Texture { return upSampled[scaleFactor]; } + /** + * Returns the bitmap that should be used for rendering at the given zoom + * @param zoomLevel The zoom level + * @return The bitmap + */ public TextureBitmap getZoomedBitmap(final double zoomLevel) { if (zoomLevel < 1) { @@ -136,14 +154,20 @@ public class Texture { return primaryBitmap; } + /** + * Resets the cache of resampled bitmaps + */ public void resetResampledBitmapCache() { - for (int i = 0; i < upSampled.length; i++) - upSampled[i] = null; + fill(upSampled, null); - for (int i = 0; i < downSampled.length; i++) - downSampled[i] = null; + fill(downSampled, null); } + /** + * Upscales the given bitmap by a factor of 2 + * @param originalBitmap The bitmap to upscale + * @return The upscaled bitmap + */ public TextureBitmap upscaleBitmap(final TextureBitmap originalBitmap) { final int newWidth = originalBitmap.width * 2; final int newHeight = originalBitmap.height * 2; @@ -180,10 +204,22 @@ public class Texture { return upScaled; } - public class ColorAccumulator { + /** + * A helper class that accumulates color values for a given area of a bitmap + */ + public static class ColorAccumulator { + // Accumulated color values public int r, g, b, a; + + // Number of pixels that have been accumulated public int pixelCount = 0; + /** + * Accumulates the color values of the given pixel + * @param bitmap The bitmap + * @param x The x coordinate of the pixel + * @param y The y coordinate of the pixel + */ public void accumulate(final TextureBitmap bitmap, final int x, final int y) { int address = bitmap.getAddress(x, y); @@ -202,6 +238,9 @@ public class Texture { pixelCount++; } + /** + * Resets the accumulator + */ public void reset() { a = 0; r = 0; @@ -210,6 +249,12 @@ public class Texture { pixelCount = 0; } + /** + * Stores the accumulated color values in the given bitmap + * @param bitmap The bitmap + * @param x The x coordinate of the pixel + * @param y The y coordinate of the pixel + */ public void storeResult(final TextureBitmap bitmap, final int x, final int y) { int address = bitmap.getAddress(x, y);