Blame view

src/jsky/image/fits/codec/FITSData.java 3.19 KB
fe0fb87e   Elodie Bourrec   First push to cre...
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright 2002 Association for Universities for Research in Astronomy, Inc.,
 * Observatory Control System, Gemini Telescopes Project.
 *
 * $Id: FITSData.java,v 1.3 2009/03/04 11:13:45 abrighto Exp $
 */

package jsky.image.fits.codec;

import java.awt.image.Raster;
import java.io.*;

import nom.tam.image.*;

/**
 * An abstract base class for performing data type specific operations
 * on 2D FITS data.
 *
 * @version $Revision: 1.3 $
 * @author Allan Brighton
 */
public abstract class FITSData {

    /** Reference to the class managing the image access */
    protected FITSImage _fitsImage;

    /** Object used to access the image tiles */
    private ImageTiler _tiler;

    /** Number of axes (Currently only the width and height are considerred) */
    protected int _naxis;

    /** The number of FITS pixels in the X direction */
    protected int _width;

    /** The number of FITS pixels in the Y direction */
    protected int _height;


    /**
     * Constructor.
     *
     * @param fitsImage the FITS image
     */
    public FITSData(FITSImage fitsImage) {
        this._fitsImage = fitsImage;
        _tiler = _fitsImage.getImageTiler();
        _naxis = _fitsImage.getNAXIS();
        _width = _fitsImage.getRealWidth();
        _height = _fitsImage.getRealHeight();
    }

    /**
     * Fill the given array with image data starting at the given offsets
     * and with the given width and height in image pixels.
     *
     * @param destArray the image data array
     * @param x the x offset in the image data
     * @param y the y offset in the image data
     * @param w the width of the data to get
     * @param h the height of the data to get
     */
    protected void fillTile(Object destArray, int x, int y, int w, int h) throws IOException {
        int[] corners, lengths;
        switch (_naxis) {
            case 2:
                corners = new int[]{y, x};
                lengths = new int[]{h, w};
                break;
            case 3:
                corners = new int[]{0, y, x};
                lengths = new int[]{0, h, w};
                break;
            case 4:
                corners = new int[]{0, 0, y, x};
                lengths = new int[]{0, 0, h, w};
                break;
            default:
                throw new RuntimeException("Unsupported number of axes");
        }

        // The dimensions of the arguments to tiler.getTile() are dependent on NAXIS.
        _tiler.getTile(destArray, corners, lengths);
    }

    void setTiler(ImageTiler tiler) {
        _tiler = tiler;
    }

    /**
     * Fill in the given tile with the appropriate image data.
     *
     * @param tile the tile to fill with data
     * @param subsample the increment to use when zooming out using the mapped byte buffer
     * @param width the total image width in pixels
     * @param height the total image height in pixels
     *
     * @return the tile argument
     */
    public abstract Raster getTile(Raster tile, int subsample, int width, int height) throws IOException;

    /**
     * Return a prescaled preview image at "1/factor" of the normal size in the given
     * raster tile.
     */
    public abstract Raster getPreviewImage(Raster tile, int factor) throws IOException;
}