X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Ftexture%2FTexture.java;h=70a6107714791ef1d340faa801711b440a70e938;hb=a3ff3683bd0a025061667b26b6fcf56fe20f0afc;hp=402c23b21eaf9c1f9dd6ff6cb5fd5826acb12594;hpb=59baa428fb2d9e7f0fe5423f4cea47f2d6245914;p=sixth-3d.git 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 402c23b..70a6107 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 @@ -1,12 +1,7 @@ /* - * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. - * + * Sixth 3D engine. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. */ - package eu.svjatoslav.sixth.e3d.renderer.raster.texture; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; @@ -16,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; @@ -64,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; @@ -108,6 +111,12 @@ 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) { @@ -123,6 +132,12 @@ 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) { @@ -141,14 +156,21 @@ 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; @@ -185,10 +207,23 @@ 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); @@ -207,6 +242,9 @@ public class Texture { pixelCount++; } + /** + * Resets the accumulator + */ public void reset() { a = 0; r = 0; @@ -215,6 +253,13 @@ 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);