Class RgbImage
java.lang.Object
uk.ac.starlink.ttools.plot2.paper.RgbImage
An efficiently stored RGB or RGBA image backed by an int buffer.
Each pixel is represented by a 4-byte int, with the three least-significant
bytes giving 0-255 levels of red, green, blue (msb->lsb)
and, optionally, the most significant byte giving alpha.
This corresponds to the
BufferedImage
constants
TYPE_INT_RGB
and TYPE_INT_ARGB
.
The values in the buffer are therefore the same as those used by
BufferedImage
setRGB
/getRGB
,
but can (presumably) be manipulated more efficiently by addressing the
array here directly.
These RGB values are also the same as those used by Compositor
.
Note: in tests, painting a colour on the image's
graphics context does not seem to give exactly the expected result
in terms of ARGB values in the buffer, though it's not far off.
See the RgbImageTest
testcase for more discussion.
- Since:
- 14 Feb 2013
- Author:
- Mark Taylor
-
Method Summary
Modifier and TypeMethodDescriptionstatic RgbImage
createRgbImage
(int width, int height, boolean hasAlpha) Constructs an RgbImage with default background colour.static RgbImage
createRgbImage
(int width, int height, boolean hasAlpha, int bg) Constructs an RgbImage with a given background coour.int[]
Returns the data as a modifiable int array.getImage()
Returns the data as a BufferedImage.
-
Method Details
-
getImage
Returns the data as a BufferedImage.- Returns:
- image
-
getBuffer
public int[] getBuffer()Returns the data as a modifiable int array.- Returns:
- int buffer
-
createRgbImage
Constructs an RgbImage with default background colour.- Parameters:
width
- width in pixelsheight
- height in pixelshasAlpha
- true for ARGB, false for RGB- Returns:
- new instance
-
createRgbImage
Constructs an RgbImage with a given background coour.- Parameters:
width
- width in pixelsheight
- height in pixelshasAlpha
- true for ARGB, false for RGBbg
- initial value for all elements in the image buffer- Returns:
- new instance
-