MinMaxDescriptor.java
5.25 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* ESO Archive
*
* $Id: MinMaxDescriptor.java,v 1.2 2009/02/20 23:10:11 abrighto Exp $
*
* who when what
* -------------- ---------- ----------------------------------------
* Allan Brighton 1999/05/03 Created
*/
package jsky.image.operator;
import java.lang.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.image.renderable.*;
import javax.media.jai.*;
import javax.media.jai.ROI;
import javax.media.jai.util.Range;
import javax.media.jai.registry.RIFRegistry;
/**
* A single class that is both an OperationDescriptor and
* a RenderedImageFactory.
*/
public class MinMaxDescriptor extends OperationDescriptorImpl implements RenderedImageFactory {
/**
* The resource strings that provide the general documentation and
* specify the parameter list for the "minmax" operation.
*/
private static final String[][] resources = {
{"GlobalName", "minmax"},
{"LocalName", "minmax"},
{"Vendor", "jsky"},
{"Description", "Calculate image min and max values, ignoring the given blank or bad pixel value"},
{"DocURL", "http://archive.eso.org/jsky/jsky-doc/api/jsky/image/operator/MinMaxDescriptor.html"},
{"Version", "1.0"},
{"arg0Desc", "The region of the image to scan"},
{"arg1Desc", "The horizontal sampling rate, may not be less than 1."},
{"arg2Desc", "The vertical sampling rate, may not be less than 1."},
{"arg3Desc", "Ignore pixels with this value."}
};
/**
* The modes that this operator supports. maybe one or more of
* "rendered", "renderable", "collection", and "renderableCollection".
*/
private static final String[] supportedModes = {
"rendered", "renderable"
};
/**
* The parameter names for the "minmax" operation.
*/
private static final String[] paramNames = {
"roi",
"xPeriod",
"yPeriod",
"ignore"
};
/**
* The class types for the parameters of the "minmax" operation.
* User defined classes can be used here as long as the fully
* qualified name is used and the classes can be loaded.
*/
private static final Class[] paramClasses = {
javax.media.jai.ROI.class,
java.lang.Integer.class,
java.lang.Integer.class,
java.lang.Double.class
};
/**
* The default parameter values for the "minmax" operation
* when using a ParameterBlockJAI.
*/
private static final Object[] paramDefaults = {
null,
1,
1,
null
};
/**
* Describes the valid parameter ranges (null means any range for that class)
*/
private static final Object[] validParamValues = {
null,
new Range(Integer.class, 1, null), // must be >= 1
new Range(Integer.class, 1, null), // must be >= 1
null
};
/** Constructor. */
public MinMaxDescriptor() {
// XXX JAI 1.0.2 super(resources, 1, paramClasses, paramNames, paramDefaults);
super(resources, supportedModes, 1, paramNames, paramClasses, paramDefaults, validParamValues);
}
/**
* Register this operation descriptor
*/
public static void register() {
MinMaxDescriptor MinMaxDescriptor = new MinMaxDescriptor();
String operationName = "minmax";
String productName = "jsky";
OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry();
or.registerDescriptor(MinMaxDescriptor);
RIFRegistry.register(or, operationName, productName, MinMaxDescriptor);
}
/**
* Creates a MinMaxOpImage with the given ParameterBlock if the
* MinMaxOpImage can handle the particular ParameterBlock.
*/
public RenderedImage create(ParameterBlock paramBlock,
RenderingHints renderHints) {
if (!validateParameters(paramBlock)) {
return null;
}
return new MinMaxOpImage(paramBlock.getRenderedSource(0),
(ROI) paramBlock.getObjectParameter(0),
(Integer) paramBlock.getObjectParameter(1),
(Integer) paramBlock.getObjectParameter(2),
(Double) paramBlock.getObjectParameter(3));
}
/**
* Checks that all parameters in the ParameterBlock have the
* correct type before constructing the MinMaxOpImage
*/
public boolean validateParameters(ParameterBlock paramBlock) {
int n = getParameterListDescriptor(getSupportedModes()[0]).getNumParameters();
for (int i = 0; i < n; i++) {
Object arg = paramBlock.getObjectParameter(i);
if (arg == null) {
return false;
}
if (i == 0) {
if (!(arg instanceof ROI)) {
return false;
}
} else if (i == 1 || i == 2) {
if (!(arg instanceof Integer)) {
return false;
}
int val = (Integer) arg;
if (val < 1) {
return false;
}
} else if (i == 3) {
if (!(arg instanceof Double)) {
return false;
}
}
}
return true;
}
}