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 int array.

Each pixel is stored as a single int in ARGB format: (alpha << 24) | (red << 16) | (green << 8) | blue. This matches the BufferedImage.TYPE_INT_ARGB format.

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 int
    The height of this bitmap in pixels.
    double
    The scale factor of this bitmap relative to the primary (native) texture resolution.
    final int[]
    Raw pixel data in ARGB int format.
    final int
    The width of this bitmap in pixels.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    drawPixel(int sourcePixelAddress, int[] targetBitmap, int targetPixelAddress)
    Transfer (render) one pixel from current TextureBitmap to target RGB raster.
    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
    drawScanlineWithAddresses(int[] sourceAddresses, int[] targetBitmap, int targetStartAddress, int pixelCount)
    Renders a scanline using pre-computed source pixel addresses.
    void
    Fills the entire bitmap with the specified color.
    int
    getAddress(int x, int y)
    Computes the index into the pixels 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

    • pixels

      public final int[] pixels
      Raw pixel data in ARGB int format. Each int encodes: (alpha << 24) | (red << 16) | (green << 8) | blue. The array length is width * height.
    • 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, int[] pixels, double multiplicationFactor)
      Creates a texture bitmap backed by an existing int 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
      pixels - the raw pixel data array (must be at least width * height ints)
      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 int 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 sourcePixelAddress, int[] targetBitmap, int targetPixelAddress)
      Transfer (render) one pixel from current TextureBitmap to target RGB raster.

      This texture stores pixels in ARGB format. The target is RGB format (no alpha). Alpha blending is performed based on the source pixel's alpha value.

      Performance note: Uses bit-shift instead of division for alpha blending, and pre-multiplies source colors to reduce per-pixel operations.

      Parameters:
      sourcePixelAddress - Pixel index within current texture.
      targetBitmap - Target RGB pixel array.
      targetPixelAddress - Pixel index within target image.
    • drawScanlineWithAddresses

      public void drawScanlineWithAddresses(int[] sourceAddresses, int[] targetBitmap, int targetStartAddress, int pixelCount)
      Renders a scanline using pre-computed source pixel addresses.

      This variant is optimized for cases where source addresses are computed externally (e.g., by a caller that already has the stepping logic). The sourceAddresses array must contain valid indices into pixels.

      Parameters:
      sourceAddresses - array of source pixel addresses (indices into pixels array)
      targetBitmap - target RGB pixel array
      targetStartAddress - starting index in the target array
      pixelCount - number of pixels to render
    • 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.

      Performance: Uses Arrays.fill(int[], int, int, int) per scanline for optimal JVM-optimized memory writes.

      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 index into the pixels 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 index into the pixels array for the specified pixel