/*
- * Sixth - System for data storage, computation, exploration and interaction.
- * Copyright ©2012-2016, 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.renderer.raster.Color;
public class TextureBitmap {
/**
- * Byte order: ABGR
+ * Byte order: Alpha, Blue, Green, Red
*/
public final byte[] bytes;
this(width, height, new byte[width * height * 4], multiplicationFactor);
}
- public void drawPixel(int textureOffset,
- final byte[] targetRenderingAreaBytes, int targetRenderingAreaOffset) {
+ /**
+ * Transfer (render) one pixel from current {@link TextureBitmap} to target raster bitmap.
+ *
+ * @param sourceBitmapPixelAddress Pixel address within current {@link TextureBitmap} as indicated by its offset.
+ * @param targetBitmap Bitmap of the target image where pixel should be rendered to.
+ * @param targetBitmapPixelAddress Pixel location within target image where pixel should be rendered to.
+ */
+ public void drawPixel(int sourceBitmapPixelAddress,
+ final byte[] targetBitmap, int targetBitmapPixelAddress) {
- final int textureAlpha = bytes[textureOffset] & 0xff;
+ final int textureAlpha = bytes[sourceBitmapPixelAddress] & 0xff;
if (textureAlpha == 0)
return;
if (textureAlpha == 255) {
// skip reading of background for fully opaque pixels
- targetRenderingAreaBytes[targetRenderingAreaOffset] = (byte) 255;
+ targetBitmap[targetBitmapPixelAddress] = (byte) 255;
- targetRenderingAreaOffset++;
- textureOffset++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = bytes[textureOffset];
+ targetBitmapPixelAddress++;
+ sourceBitmapPixelAddress++;
+ targetBitmap[targetBitmapPixelAddress] = bytes[sourceBitmapPixelAddress];
- targetRenderingAreaOffset++;
- textureOffset++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = bytes[textureOffset];
+ targetBitmapPixelAddress++;
+ sourceBitmapPixelAddress++;
+ targetBitmap[targetBitmapPixelAddress] = bytes[sourceBitmapPixelAddress];
- targetRenderingAreaOffset++;
- textureOffset++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = bytes[textureOffset];
+ targetBitmapPixelAddress++;
+ sourceBitmapPixelAddress++;
+ targetBitmap[targetBitmapPixelAddress] = bytes[sourceBitmapPixelAddress];
return;
}
final int backgroundAlpha = 255 - textureAlpha;
- textureOffset++;
+ sourceBitmapPixelAddress++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = (byte) 255;
- targetRenderingAreaOffset++;
+ targetBitmap[targetBitmapPixelAddress] = (byte) 255;
+ targetBitmapPixelAddress++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = (byte) ((((targetRenderingAreaBytes[targetRenderingAreaOffset] & 0xff) * backgroundAlpha) + ((bytes[textureOffset] & 0xff) * textureAlpha)) / 256);
- textureOffset++;
- targetRenderingAreaOffset++;
+ targetBitmap[targetBitmapPixelAddress] = (byte) ((((targetBitmap[targetBitmapPixelAddress] & 0xff) * backgroundAlpha) + ((bytes[sourceBitmapPixelAddress] & 0xff) * textureAlpha)) / 256);
+ sourceBitmapPixelAddress++;
+ targetBitmapPixelAddress++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = (byte) ((((targetRenderingAreaBytes[targetRenderingAreaOffset] & 0xff) * backgroundAlpha) + ((bytes[textureOffset] & 0xff) * textureAlpha)) / 256);
- textureOffset++;
- targetRenderingAreaOffset++;
+ targetBitmap[targetBitmapPixelAddress] = (byte) ((((targetBitmap[targetBitmapPixelAddress] & 0xff) * backgroundAlpha) + ((bytes[sourceBitmapPixelAddress] & 0xff) * textureAlpha)) / 256);
+ sourceBitmapPixelAddress++;
+ targetBitmapPixelAddress++;
- targetRenderingAreaBytes[targetRenderingAreaOffset] = (byte) ((((targetRenderingAreaBytes[targetRenderingAreaOffset] & 0xff) * backgroundAlpha) + ((bytes[textureOffset] & 0xff) * textureAlpha)) / 256);
+ targetBitmap[targetBitmapPixelAddress] = (byte) ((((targetBitmap[targetBitmapPixelAddress] & 0xff) * backgroundAlpha) + ((bytes[sourceBitmapPixelAddress] & 0xff) * textureAlpha)) / 256);
}
public void drawPixel(final int x, final int y, final Color color) {