summaryrefslogtreecommitdiffstats
path: root/awt/javax/imageio/IIOParam.java
blob: 2ccc9450f5b4a5ade2802e5fd87202d98de0990f (plain)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Rustem V. Rafikov
 * @version $Revision: 1.3 $
 */

package javax.imageio;

import java.awt.*;

/**
 * The IIOParam abstract class is superclass for ImageReadParam and
 * ImageWriteParam classes and provides methods and variables which they share.
 * 
 * @since Android 1.0
 */
public abstract class IIOParam {

    /**
     * The source region.
     */
    protected Rectangle sourceRegion;

    /**
     * The source x subsampling.
     */
    protected int sourceXSubsampling = 1;

    /**
     * The source y subsampling.
     */
    protected int sourceYSubsampling = 1;

    /**
     * The subsampling x offset.
     */
    protected int subsamplingXOffset;

    /**
     * The subsampling y offset.
     */
    protected int subsamplingYOffset;

    /**
     * The source bands.
     */
    protected int[] sourceBands;

    /**
     * The destination type.
     */
    protected ImageTypeSpecifier destinationType;

    /**
     * The destination offset.
     */
    protected Point destinationOffset = new Point(0, 0);

    /**
     * The default controller.
     */
    protected IIOParamController defaultController;

    /**
     * The controller.
     */
    protected IIOParamController controller;

    /**
     * Instantiates a new IIOParam.
     */
    protected IIOParam() {
    }

    /**
     * Sets the source region as a Rectangle object.
     * 
     * @param sourceRegion
     *            the Rectangle which specifies the source region.
     */
    public void setSourceRegion(Rectangle sourceRegion) {
        if (sourceRegion != null) {
            if (sourceRegion.x < 0) {
                throw new IllegalArgumentException("x < 0");
            }
            if (sourceRegion.y < 0) {
                throw new IllegalArgumentException("y < 0");
            }
            if (sourceRegion.width <= 0) {
                throw new IllegalArgumentException("width <= 0");
            }
            if (sourceRegion.height <= 0) {
                throw new IllegalArgumentException("height <= 0");
            }

            if (sourceRegion.width <= subsamplingXOffset) {
                throw new IllegalArgumentException("width <= subsamplingXOffset");
            }

            if (sourceRegion.height <= subsamplingYOffset) {
                throw new IllegalArgumentException("height <= subsamplingXOffset");
            }
            // -- clone it to avoid unexpected modifications
            this.sourceRegion = (Rectangle)sourceRegion.clone();
        } else {
            this.sourceRegion = null;
        }
    }

    /**
     * Gets the source region.
     * 
     * @return the source region as Rectangle.
     */
    public Rectangle getSourceRegion() {
        if (sourceRegion == null) {
            return null;
        }
        // -- clone it to avoid unexpected modifications
        return (Rectangle)sourceRegion.clone();
    }

    /**
     * Sets the source subsampling. The sourceXSubsampling and
     * sourceYSubsampling parameters specify the number of rows and columns to
     * advance after every source pixel.
     * 
     * @param sourceXSubsampling
     *            the source X subsampling.
     * @param sourceYSubsampling
     *            the source Y subsampling.
     * @param subsamplingXOffset
     *            the subsampling X offset.
     * @param subsamplingYOffset
     *            the subsampling Y offset.
     */
    public void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling,
            int subsamplingXOffset, int subsamplingYOffset) {

        if (sourceXSubsampling <= 0) {
            throw new IllegalArgumentException("sourceXSubsampling <= 0");
        }
        if (sourceYSubsampling <= 0) {
            throw new IllegalArgumentException("sourceYSubsampling <= 0");
        }

        if (subsamplingXOffset <= 0 || subsamplingXOffset >= sourceXSubsampling) {
            throw new IllegalArgumentException("subsamplingXOffset is wrong");
        }

        if (subsamplingYOffset <= 0 || subsamplingYOffset >= sourceYSubsampling) {
            throw new IllegalArgumentException("subsamplingYOffset is wrong");
        }

        // -- does region contain pixels
        if (sourceRegion != null) {
            if (sourceRegion.width <= subsamplingXOffset
                    || sourceRegion.height <= subsamplingYOffset) {
                throw new IllegalArgumentException("there are no pixels in region");
            }
        }

        this.sourceXSubsampling = sourceXSubsampling;
        this.sourceYSubsampling = sourceYSubsampling;
        this.subsamplingXOffset = subsamplingXOffset;
        this.subsamplingYOffset = subsamplingYOffset;
    }

    /**
     * Gets the source X subsampling - the number of source columns to advance
     * for each pixel.
     * 
     * @return the source X subsampling.
     */
    public int getSourceXSubsampling() {
        return sourceXSubsampling;
    }

    /**
     * Gets the source Y subsampling - the number of source rows to advance for
     * each pixel.
     * 
     * @return the source Y subsampling.
     */
    public int getSourceYSubsampling() {
        return sourceYSubsampling;
    }

    /**
     * Gets the horizontal offset of the subsampling grid.
     * 
     * @return the horizontal offset of the subsampling grid.
     */
    public int getSubsamplingXOffset() {
        return subsamplingXOffset;
    }

    /**
     * Gets the vertical offset of the subsampling grid.
     * 
     * @return the vertical offset of the subsampling grid.
     */
    public int getSubsamplingYOffset() {
        return subsamplingYOffset;
    }

    /**
     * Sets the indices of the source bands.
     * 
     * @param sourceBands
     *            the indices of the source bands.
     */
    public void setSourceBands(int[] sourceBands) {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Gets the array of source bands.
     * 
     * @return the array of source bands.
     */
    public int[] getSourceBands() {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Sets the specified ImageTypeSpecifier for the destination image.
     * 
     * @param destinationType
     *            the ImageTypeSpecifier.
     */
    public void setDestinationType(ImageTypeSpecifier destinationType) {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Gets the type of the destination image as an ImageTypeSpecifier. .
     * 
     * @return the ImageTypeSpecifier.
     */
    public ImageTypeSpecifier getDestinationType() {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Sets the offset in the destination image where the decoded pixels are
     * placed as a result of reading, or specified an area to be written while
     * writing operation.
     * 
     * @param destinationOffset
     *            the destination offset.
     */
    public void setDestinationOffset(Point destinationOffset) {
        if (destinationOffset == null) {
            throw new IllegalArgumentException("destinationOffset == null!");
        }

        this.destinationOffset = (Point)destinationOffset.clone();
    }

    /**
     * Gets the offset in the destination image for placing pixels.
     * 
     * @return the offset in the destination image.
     */
    public Point getDestinationOffset() {
        return (Point)destinationOffset.clone();
    }

    /**
     * Sets the IIOParamController to this IIOParam object for providing
     * settings to this IIOParam.
     * 
     * @param controller
     *            the new IIOParamController.
     */
    public void setController(IIOParamController controller) {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Gets the current IIOParamController controller for this IIOParam.
     * 
     * @return the current IIOParamController controller for this IIOParam.
     */
    public IIOParamController getController() {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Gets the default IIOParamController controller for this IIOParam.
     * 
     * @return the default IIOParamController controller for this IIOParam, or
     *         null.
     */
    public IIOParamController getDefaultController() {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Returns true if IIOParamController is installed for this IIOParam.
     * 
     * @return true, if IIOParamController is installed for this IIOParam, false
     *         otherwise.
     */
    public boolean hasController() {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Activates the controller.
     * 
     * @return true, if successful, false otherwise.
     */
    public boolean activateController() {
        // TODO implement
        throw new UnsupportedOperationException("not implemented yet");
    }
}