1
package org.helioviewer.viewmodel.imagedata;
4
import java.awt.image.BufferedImage;
5
import java.awt.image.DataBufferUShort;
6
import java.awt.image.Raster;
8
import org.helioviewer.viewmodel.imageformat.ImageFormat;
9
import org.helioviewer.viewmodel.imageformat.SingleChannelImageFormat;
10
import org.helioviewer.viewmodel.imagetransport.ImageTransport;
11
import org.helioviewer.viewmodel.imagetransport.Short16ImageTransport;
14
* Representation of image data in single channel format, using 9 to 16 bits per
18
* Note that this is the only implementation of ImageData, which is supposed to
19
* handle a variable number of bits per pixel.
21
* @author Ludwig Schmidt
22
* @author Markus Langenberg
25
public class SingleChannelShortImageData extends AbstractImageData {
27
private SingleChannelImageFormat format;
28
private Short16ImageTransport imageTransport;
31
* Constructor, given an array as data source.
34
* This constructor receives the raw data as a data source. If the caller
35
* handles raw data as well, the use of this constructor is recommended.
37
* The pixel data has to be given as a one-dimensional array containing the
38
* pixel data line by line. Each array element represents one pixel.
45
* number of bits per pixel
49
* color mask of the image
51
public SingleChannelShortImageData(int newWidth, int newHeight, int newBitDepth, short[] newPixelData, ColorMask newColorMask) {
52
super(newWidth, newHeight, newColorMask);
53
imageTransport = new Short16ImageTransport(newPixelData);
54
format = new SingleChannelImageFormat(newBitDepth);
58
* Constructor, given an array as data source.
61
* This constructor receives the raw data as a data source. If the caller
62
* handles raw data as well, the use of this constructor is recommended.
64
* The pixel data has to be given as a one-dimensional array containing the
65
* pixel data line by line. Each array element represents one pixel.
68
* original ImageData-object
72
public SingleChannelShortImageData(ImageData base, short[] newPixelData) {
74
imageTransport = new Short16ImageTransport(newPixelData);
75
format = (SingleChannelImageFormat) base.getImageFormat();
79
* Constructor, given an BufferedImage as data source.
82
* This constructor receives a BufferedImage as data source. If the caller
83
* operates on BufferedImages as well, the use of this constructor is
87
* number of bits per pixel
91
* color mask of the image
93
public SingleChannelShortImageData(int newBitDepth, BufferedImage newImage, ColorMask newColorMask) {
94
super(newImage.getWidth(), newImage.getHeight(), newColorMask);
96
imageTransport = new Short16ImageTransport(((DataBufferUShort) newImage.getRaster().getDataBuffer()).getData());
97
format = new SingleChannelImageFormat(newBitDepth);
101
* Constructor, given an BufferedImage as data source.
104
* This constructor receives a BufferedImage as data source. If the caller
105
* operates on BufferedImages as well, the use of this constructor is
109
* original ImageData-object
113
public SingleChannelShortImageData(ImageData base, BufferedImage newImage) {
116
imageTransport = new Short16ImageTransport(((DataBufferUShort) newImage.getRaster().getDataBuffer()).getData());
117
format = (SingleChannelImageFormat) base.getImageFormat();
123
public ImageFormat getImageFormat() {
130
public ImageTransport getImageTransport() {
131
return imageTransport;
137
protected BufferedImage createBufferedImageFromImageTransport() {
138
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY);
139
DataBufferUShort dataBuffer = new DataBufferUShort(imageTransport.getShort16PixelData(), width * height);
141
// create the appropriate bit mask
142
int mask = 0xffffffff;
143
mask = mask >>> (32 - format.getBitDepth());
145
Raster raster = Raster.createPackedRaster(dataBuffer, width, height, width, new int[] { mask }, new Point(0, 0));
146
newImage.setData(raster);