/*
- * Sixth 3D engine. Copyright ©2012-2020, 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;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
+import static java.util.Arrays.fill;
+
public class Texture {
public final TextureBitmap primaryBitmap;
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;
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) {
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) {
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;
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);
pixelCount++;
}
+ /**
+ * Resets the accumulator
+ */
public void reset() {
a = 0;
r = 0;
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);