FITSEncoder.java
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* ESO Archive
*
* $Id: FITSEncoder.java,v 1.2 2009/02/20 23:10:11 abrighto Exp $
*
* who when what
* -------------- ---------- ----------------------------------------
* Allan Brighton 1999/05/03 Created
*/
package jsky.image.fits.codec;
import nom.tam.fits.*;
import java.awt.image.RenderedImage;
import java.io.IOException;
import java.io.OutputStream;
import com.sun.media.jai.codec.ImageEncoderImpl;
import com.sun.media.jai.codec.ImageEncodeParam;
/**
* An <code>ImageEncoder</code> for the FITS file format.
*
* @version $Revision: 1.2 $
* @author Allan Brighton
*/
public class FITSEncoder extends ImageEncoderImpl {
public FITSEncoder(OutputStream output, ImageEncodeParam param) {
super(output, param);
if (this.param == null) {
this.param = new FITSEncodeParam();
}
}
/**
* Encodes a RenderedImage and writes the output to the
* OutputStream associated with this ImageEncoder.
*/
public void encode(RenderedImage im) throws IOException {
throw new RuntimeException("FITSEncoder not implemented");
/*...
SampleModel sampleModel = im.getSampleModel();
int dataType = sampleModel.getTransferType();
if ((dataType == DataBuffer.TYPE_FLOAT) ||
(dataType == DataBuffer.TYPE_DOUBLE)) {
throw new RuntimeException("Source image has float/double data type: not supported yet");
}
int width = im.getWidth();
int height = im.getHeight();
int numBands = sampleModel.getNumBands();
if (numBands != 1) {
throw new RuntimeException("Source image has an unsupported number of bands.");
}
// Read parameters
// if (((FITSEncodeParam)param).getRaw()) ... XXX not impl
// Grab the pixels
// Raster src = im.getData(new Rectangle(minX, row, width, rows));
int[] pixels = new int[width*height*numBands];
Raster src = im.getData();
src.getPixels(0, 0, width, height, pixels);
// get 2D array for writing (XXX need to do this with fewer copies)
int[][] imageArray = new int[width][height];
// write it....
Fits fits = new Fits();
try {
fits.addHDU(new ImageHDU(imageArray));
fits.write(output);
} catch (FitsException e) {
e.printStackTrace();
throw new RuntimeException("A FitsException occured while writing the FITS file.");
}
// Force all buffered bytes to be written out.
output.flush();
...*/
}
}