Class TextureBitmap
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:
- Alpha-blended pixel transfer to a target raster (
drawPixel(int, byte[], 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 byte[]Raw pixel data in ABGR byte order (Alpha, Blue, Green, Red).final intThe height of this bitmap in pixels.doubleThe scale factor of this bitmap relative to the primary (native) texture resolution.final intThe width of this bitmap in pixels. -
Constructor Summary
ConstructorsConstructorDescriptionTextureBitmap(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 TypeMethodDescriptionvoiddrawPixel(int sourceBitmapPixelAddress, byte[] targetBitmap, int targetBitmapPixelAddress) Transfer (render) one pixel from currentTextureBitmapto target raster bitmap.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.voidFills the entire bitmap with the specified color.intgetAddress(int x, int y)
-
Field Details
-
bytes
public final byte[] bytesRaw pixel data in ABGR byte order (Alpha, Blue, Green, Red). The array length iswidth * height * 4. -
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, 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 pixelsheight- the bitmap height in pixelsbytes- the raw pixel data array (must be at leastwidth * height * 4bytes)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 pixelsheight- the bitmap height in pixelsmultiplicationFactor- 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 currentTextureBitmapto target raster bitmap.- Parameters:
sourceBitmapPixelAddress- Pixel address within currentTextureBitmapas 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
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.- 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 byte offset into thebytesarray 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 byte offset of the first component (alpha) for the specified pixel
-