# Class RgbImage

java.lang.Object
uk.ac.starlink.ttools.plot2.paper.RgbImage

public class RgbImage extends Object
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 Type
Method
Description
`static 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[]`
`getBuffer()`
Returns the data as a modifiable int array.
`BufferedImage`
`getImage()`
Returns the data as a BufferedImage.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### getImage

public BufferedImage 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

public static RgbImage createRgbImage(int width, int height, boolean hasAlpha)
Constructs an RgbImage with default background colour.

Parameters:
  `width` - width in pixels
  `height` - height in pixels
  `hasAlpha` - true for ARGB, false for RGB
Returns:
  new instance

### createRgbImage

public static RgbImage createRgbImage(int width, int height, boolean hasAlpha, int bg)
Constructs an RgbImage with a given background coour.

Parameters:
  `width` - width in pixels
  `height` - height in pixels
  `hasAlpha` - true for ARGB, false for RGB
  `bg` - initial value for all elements in the image buffer
Returns:
  new instance