8
8
import org.helioviewer.viewmodel.imagetransport.ImageTransport;
9
9
import org.helioviewer.viewmodel.imagetransport.Int32ImageTransport;
11
/** Representation of image data in RGB24 format.
12
* Representation of image data in RGB24 format.
13
* <p>The image data contains three channels (red, green, blue),
14
* each channel has eight bits per pixel.
15
* The image data contains three channels (red, green, blue), each channel has
16
* eight bits per pixel.
16
18
* @author Ludwig Schmidt
17
19
* @author Markus Langenberg
20
22
public class RGBInt24ImageData implements JavaBufferedImageData {
22
private static final ImageFormat format = new RGB24ImageFormat();
24
private static final ImageFormat format = new RGB24ImageFormat();
23
25
private Int32ImageTransport imageTransport;
24
26
private int width, height;
25
27
private BufferedImage image = null;
27
/** Constructor, given an array as data source.
29
* <p>This constructor receives the raw data as a data source.
30
* If the caller handles raw data as well, the use of this constructor
32
* <p>The pixel data has to be given as a one-dimensional array containing
33
* the pixel data line by line. Each array element represents one pixel.
35
* @param newWidth width of the image
36
* @param newHeight height of the image
37
* @param newPixelData pixel data
30
* Constructor, given an array as data source.
33
* This constructor receives the raw data as a data source. If the caller
34
* handles raw data as well, the use of this constructor is recommended.
36
* The pixel data has to be given as a one-dimensional array containing the
37
* pixel data line by line. Each array element represents one pixel.
39
46
public RGBInt24ImageData(int newWidth, int newHeight, int[] newPixelData) {
41
48
height = newHeight;
42
49
imageTransport = new Int32ImageTransport(newPixelData);
45
/** Constructor, given an BufferedImage as data source.
47
* <p>This constructor receives a BufferedImage as data source.
48
* If the caller operates on BufferedImages as well, the use of this
49
* constructor is recommended.
51
* @param newImage pixel data
53
* Constructor, given an BufferedImage as data source.
56
* This constructor receives a BufferedImage as data source. If the caller
57
* operates on BufferedImages as well, the use of this constructor is
53
63
public RGBInt24ImageData(BufferedImage newImage) {
55
width = newImage.getWidth();
56
height = newImage.getHeight();
57
imageTransport = new Int32ImageTransport(((DataBufferInt) newImage.getRaster().getDataBuffer()).getData());
65
width = newImage.getWidth();
66
height = newImage.getHeight();
67
imageTransport = new Int32ImageTransport(((DataBufferInt) newImage.getRaster().getDataBuffer()).getData());
63
public int getHeight() {
73
public int getHeight() {
70
public int getWidth() {
80
public int getWidth() {
77
public BufferedImage getBufferedImage() {
79
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
87
public BufferedImage getBufferedImage() {
89
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
80
90
image.setRGB(0, 0, width, height, imageTransport.getInt32PixelData(), 0, width);
88
public ImageFormat getImageFormat() {
98
public ImageFormat getImageFormat() {
95
public ImageTransport getImageTransport() {
105
public ImageTransport getImageTransport() {
96
106
return imageTransport;