Class TextureBitmap
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:
- Alpha-blended pixel transfer to a target raster (
drawPixel(int, int[], int)) - Direct pixel writes using engine
Color(drawPixel(int, int, Color)) - Filled rectangle drawing (
drawRectangle(int, int, int, int, Color)) - Full-surface color fill (
fillColor(Color))
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intThe height of this bitmap in pixels.doubleThe scale factor of this bitmap relative to the primary (native) texture resolution.final int[]Raw pixel data in ARGB int format.final intThe width of this bitmap in pixels. -
Constructor Summary
ConstructorsConstructorDescriptionTextureBitmap(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 TypeMethodDescriptionvoiddrawPixel(int sourcePixelAddress, int[] targetBitmap, int targetPixelAddress) Transfer (render) one pixel from currentTextureBitmapto target RGB raster.voidDraws a single pixel at the specified coordinates using the given color.voiddrawRectangle(int x1, int y1, int x2, int y2, Color color) Fills a rectangular region with the specified color.voiddrawScanlineWithAddresses(int[] sourceAddresses, int[] targetBitmap, int targetStartAddress, int pixelCount) Renders a scanline using pre-computed source pixel addresses.voidFills the entire bitmap with the specified color.intgetAddress(int x, int y)
-
Field Details
-
pixels
public final int[] pixelsRaw pixel data in ARGB int format. Each int encodes:(alpha << 24) | (red << 16) | (green << 8) | blue. The array length iswidth * height. -
width
public final int widthThe width of this bitmap in pixels. -
height
public final int heightThe height of this bitmap in pixels. -
multiplicationFactor
public double multiplicationFactorThe 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 pixelsheight- the bitmap height in pixelspixels- the raw pixel data array (must be at leastwidth * heightints)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 pixelsheight- the bitmap height in pixelsmultiplicationFactor- 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 currentTextureBitmapto 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 arraytargetStartAddress- starting index in the target arraypixelCount- number of pixels to render
-
drawPixel
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 pixely- the y coordinate of the pixelcolor- the color to write
-
drawRectangle
Fills a rectangular region with the specified color.If
x1 > x2, the coordinates are swapped to ensure correct rendering. The same applies toy1andy2. 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 coordinatey1- the top y coordinatex2- the right x coordinate (exclusive)y2- the bottom y coordinate (exclusive)color- the fill color
-
fillColor
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 thepixelsarray 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 pixely- the y coordinate of the pixel- Returns:
- the index into the pixels array for the specified pixel
-