java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.texture.TextureBitmap

public class TextureBitmap extends Object
Represents a single resolution level of a texture as a raw byte array.

Each pixel is stored as 4 consecutive bytes in ABGR order: Alpha, Blue, Green, Red. This byte ordering matches the BufferedImage.TYPE_4BYTE_ABGR format used by the rendering pipeline.

TextureBitmap is used internally by Texture to represent individual mipmap levels. The multiplicationFactor records the scale ratio relative to the primary (native) resolution -- for example, a value of 0.5 means this bitmap is half the original size, and 2.0 means it is double.

This class provides low-level pixel operations including:

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final byte[]
    Raw pixel data in ABGR byte order (Alpha, Blue, Green, Red).
    final int
    The height of this bitmap in pixels.
    double
    The scale factor of this bitmap relative to the primary (native) texture resolution.
    final int
    The width of this bitmap in pixels.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextureBitmap(int width, int height, byte[] bytes, double multiplicationFactor)
    Creates a texture bitmap backed by an existing byte array.
    TextureBitmap(int width, int height, double multiplicationFactor)
    Creates a texture bitmap with a newly allocated byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    drawPixel(int sourceBitmapPixelAddress, byte[] targetBitmap, int targetBitmapPixelAddress)
    Transfer (render) one pixel from current TextureBitmap to target raster bitmap.
    void
    drawPixel(int x, int y, Color color)
    Draws a single pixel at the specified coordinates using the given color.
    void
    drawRectangle(int x1, int y1, int x2, int y2, Color color)
    Fills a rectangular region with the specified color.
    void
    Fills the entire bitmap with the specified color.
    int
    getAddress(int x, int y)
    Computes the byte offset into the bytes array for the pixel at (x, y).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • bytes

      public final byte[] bytes
      Raw pixel data in ABGR byte order (Alpha, Blue, Green, Red). The array length is width * height * 4.
    • width

      public final int width
      The width of this bitmap in pixels.
    • height

      public final int height
      The height of this bitmap in pixels.
    • multiplicationFactor

      public double multiplicationFactor
      The scale factor of this bitmap relative to the primary (native) texture resolution. A value of 1.0 indicates the native resolution, 0.5 indicates half-size, 2.0 indicates double-size, etc.
  • Constructor Details

    • TextureBitmap

      public TextureBitmap(int width, int height, byte[] bytes, double multiplicationFactor)
      Creates a texture bitmap backed by an existing byte array.

      This constructor is typically used when the bitmap data is obtained from a BufferedImage's raster, allowing direct access to the image's pixel data without copying.

      Parameters:
      width - the bitmap width in pixels
      height - the bitmap height in pixels
      bytes - the raw pixel data array (must be at least width * height * 4 bytes)
      multiplicationFactor - the scale factor relative to the native texture resolution
    • TextureBitmap

      public TextureBitmap(int width, int height, double multiplicationFactor)
      Creates a texture bitmap with a newly allocated byte array.

      The pixel data array is initialized to all zeros (fully transparent black).

      Parameters:
      width - the bitmap width in pixels
      height - the bitmap height in pixels
      multiplicationFactor - the scale factor relative to the native texture resolution
  • Method Details

    • drawPixel

      public void drawPixel(int sourceBitmapPixelAddress, byte[] targetBitmap, int targetBitmapPixelAddress)
      Transfer (render) one pixel from current TextureBitmap to target raster bitmap.
      Parameters:
      sourceBitmapPixelAddress - Pixel address within current TextureBitmap as indicated by its offset.
      targetBitmap - Bitmap of the target image where pixel should be rendered to.
      targetBitmapPixelAddress - Pixel location within target image where pixel should be rendered to.
    • drawPixel

      public void drawPixel(int x, int y, Color color)
      Draws a single pixel at the specified coordinates using the given color.

      The color components are written directly without alpha blending. Coordinates are clamped to the bitmap bounds by getAddress(int, int).

      Parameters:
      x - the x coordinate of the pixel
      y - the y coordinate of the pixel
      color - the color to write
    • drawRectangle

      public void drawRectangle(int x1, int y1, int x2, int y2, Color color)
      Fills a rectangular region with the specified color.

      If x1 > x2, the coordinates are swapped to ensure correct rendering. The same applies to y1 and y2. The rectangle is exclusive of the right and bottom edges.

      Parameters:
      x1 - the left x coordinate
      y1 - the top y coordinate
      x2 - the right x coordinate (exclusive)
      y2 - the bottom y coordinate (exclusive)
      color - the fill color
    • fillColor

      public void fillColor(Color color)
      Fills the entire bitmap with the specified color.

      Every pixel in the bitmap is set to the given color value, overwriting all existing content.

      Parameters:
      color - the color to fill the entire bitmap with
    • getAddress

      public int getAddress(int x, int y)
      Computes the byte offset into the bytes array for the pixel at (x, y).

      Coordinates are clamped to the valid range [0, width-1] and [0, height-1] so that out-of-bounds accesses are safely handled by sampling the nearest edge pixel.

      Parameters:
      x - the x coordinate of the pixel
      y - the y coordinate of the pixel
      Returns:
      the byte offset of the first component (alpha) for the specified pixel