EmptyRenderedImage.java
2.56 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: EmptyRenderedImage.java,v 1.2 2009/02/20 23:10:11 abrighto Exp $
*
* who when what
* -------------- ---------- ----------------------------------------
* Allan Brighton 1999/05/03 Created
*/
package jsky.image;
import java.awt.Point;
import java.awt.image.*;
import javax.media.jai.*;
import com.sun.media.jai.codec.*;
import jsky.image.fits.codec.FITSImage;
/**
* Implements a dummy RenderedImage, for use when there is no image to display.
*
* @version $Revision: 1.2 $
* @author Allan Brighton
*/
public class EmptyRenderedImage extends jsky.image.SimpleRenderedImage {
/** The one tile. */
private Raster tile;
/** Construct an "empty" image with the given width and height in pixels */
public EmptyRenderedImage(int w, int h) {
// set variables required by the base class for tiling
minX = minY = 0;
tileWidth = width = w;
tileHeight = height = h;
sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, w, h, 3);
colorModel = ImageCodec.createComponentColorModel(sampleModel);
}
/** Construct an "empty" image */
public EmptyRenderedImage() {
this(2, 2);
}
/**
* Generate and return the given tile (required by the RenderedImage interface).
*
* @param tileX the X index of the requested tile in the tile array.
* @param tileY the Y index of the requested tile in the tile array.
* @return the tile given by (tileX, tileY).
*/
public synchronized Raster getTile(int tileX, int tileY) {
if (tile == null)
tile = RasterFactory.createWritableRaster(sampleModel, new Point(0, 0));
return tile;
}
/**
* Gets a property from the property set of this image.
* (redefined from parent class to support teh #preview_image property
* as for FITS files).
*
* @see jsky.image.fits.codec.FITSImage
* @param name the name of the property to get, as a String.
* @return a reference to the property value or null if not found.
*/
public Object xxxgetProperty(String name) {
if (name.equals("#preview_image")) {
return getPreviewImage(FITSImage.getPreviewSize());
}
return super.getProperty(name);
}
/**
* Return a prescaled PlanarImage that fits entirely in a window of the given size,
* of null if there are any errors.
*/
protected PlanarImage getPreviewImage(int size) {
return PlanarImage.wrapRenderedImage(new EmptyRenderedImage(size, size));
}
}