summaryrefslogtreecommitdiffstats
path: root/awt/javax/imageio/ImageTypeSpecifier.java
blob: 505b1c484d5f997b1568e3214e4aee1efc2647c7 (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
343
344
345
346
347
/*
 *  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.image.ColorModel;
import java.awt.image.SampleModel;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.awt.color.ColorSpace;

/**
 * The ImageTypeSpecifier class performs conversion operations on the
 * SampleModel and the ColorModel of an image.
 * 
 * @since Android 1.0
 */
public class ImageTypeSpecifier {

    /**
     * The ColorModel of this ImageTypeSpecifier.
     */
    protected ColorModel colorModel;

    /**
     * The SampleModel of this ImageTypeSpecifier.
     */
    protected SampleModel sampleModel;

    /**
     * Instantiates a new ImageTypeSpecifier with the specified ColorModel and
     * SampleModel objects.
     * 
     * @param colorModel
     *            the ColorModel.
     * @param sampleModel
     *            the SampleModel.
     */
    public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel) {
        if (colorModel == null) {
            throw new IllegalArgumentException("color model should not be NULL");
        }
        if (sampleModel == null) {
            throw new IllegalArgumentException("sample model should not be NULL");
        }
        if (!colorModel.isCompatibleSampleModel(sampleModel)) {
            throw new IllegalArgumentException("color and sample models are not compatible");
        }

        this.colorModel = colorModel;
        this.sampleModel = sampleModel;
    }

    /**
     * Instantiates a new ImageTypeSpecifier using the specified RenderedImage.
     * 
     * @param renderedImage
     *            the RenderedImage.
     */
    public ImageTypeSpecifier(RenderedImage renderedImage) {
        if (renderedImage == null) {
            throw new IllegalArgumentException("image should not be NULL");
        }
        this.colorModel = renderedImage.getColorModel();
        this.sampleModel = renderedImage.getSampleModel();
    }

    /**
     * Creates an ImageTypeSpecifier with the specified DirectColorModel and a
     * packed SampleModel.
     * 
     * @param colorSpace
     *            the ColorSpace.
     * @param redMask
     *            the red mask.
     * @param greenMask
     *            the green mask.
     * @param blueMask
     *            the blue mask.
     * @param alphaMask
     *            the alpha mask.
     * @param transferType
     *            the transfer type.
     * @param isAlphaPremultiplied
     *            the parameter indicates if the color channel is pre-multiplied
     *            by alpha.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createPacked(ColorSpace colorSpace, int redMask,
            int greenMask, int blueMask, int alphaMask, int transferType,
            boolean isAlphaPremultiplied) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates an ImageTypeSpecifier with specified ComponentColorModel and a
     * PixelInterleavedSampleModel.
     * 
     * @param colorSpace
     *            the ColorSpace.
     * @param bandOffsets
     *            the band offsets.
     * @param dataType
     *            the data type.
     * @param hasAlpha
     *            the parameter indicates if alpha channel is needed.
     * @param isAlphaPremultiplied
     *            the parameter indicates if the color channel is pre-multiplied
     *            by alpha.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createInterleaved(ColorSpace colorSpace, int[] bandOffsets,
            int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates a ImageTypeSpecifier for a image with a BandedSampleModel and a
     * ComponentColorModel.
     * 
     * @param colorSpace
     *            the ColorSpace.
     * @param bankIndices
     *            the bank indices.
     * @param bandOffsets
     *            the band offsets.
     * @param dataType
     *            the data type.
     * @param hasAlpha
     *            the parameter indicates a presence of alpha channel.
     * @param isAlphaPremultiplied
     *            the parameter indicates whether or not color channel is alpha
     *            pre-multiplied.
     * @return the image type specifier
     */
    public static ImageTypeSpecifier createBanded(ColorSpace colorSpace, int[] bankIndices,
            int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates a ImageTypeSpecifier for a grayscale image.
     * 
     * @param bits
     *            the number of bits per gray value.
     * @param dataType
     *            the data type.
     * @param isSigned
     *            a signed flag.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates a ImageTypeSpecifier for a grayscale image.
     * 
     * @param bits
     *            the number of bits per gray value.
     * @param dataType
     *            the data type.
     * @param isSigned
     *            a signed flag.
     * @param isAlphaPremultiplied
     *            the parameter indicates if color channel is pre-multiplied by
     *            alpha, or not.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned,
            boolean isAlphaPremultiplied) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates a ImageTypeSpecifier with the indexed image format.
     * 
     * @param redLUT
     *            the red values of indices.
     * @param greenLUT
     *            the green values of indices.
     * @param blueLUT
     *            the blue values of indices.
     * @param alphaLUT
     *            the alpha values of indices.
     * @param bits
     *            the bits number for each index.
     * @param dataType
     *            the data type.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT,
            byte[] alphaLUT, int bits, int dataType) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates the ImageTypeSpecifier from the specified buffered image type.
     * 
     * @param bufferedImageType
     *            the buffered image type.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Creates the ImageTypeSpecifier from the specified RenderedImage.
     * 
     * @param image
     *            the RenderedImage.
     * @return the ImageTypeSpecifier.
     */
    public static ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
        if (null == image) {
            throw new IllegalArgumentException("image should not be NULL");
        }
        return new ImageTypeSpecifier(image);
    }

    /**
     * Gets the BufferedImage type.
     * 
     * @return the BufferedImage type.
     */
    public int getBufferedImageType() {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Gets the number of components.
     * 
     * @return the number of components.
     */
    public int getNumComponents() {
        return colorModel.getNumComponents();
    }

    /**
     * Gets the number of bands.
     * 
     * @return the number of bands.
     */
    public int getNumBands() {
        return sampleModel.getNumBands();
    }

    /**
     * Gets the number of bits per the specified band.
     * 
     * @param band
     *            the index of band.
     * @return the number of bits per the specified band.
     */
    public int getBitsPerBand(int band) {
        if (band < 0 || band >= getNumBands()) {
            throw new IllegalArgumentException();
        }
        return sampleModel.getSampleSize(band);
    }

    /**
     * Gets the SampleModel associated with this ImageTypeSpecifier.
     * 
     * @return the SampleModel associated with this ImageTypeSpecifier.
     */
    public SampleModel getSampleModel() {
        return sampleModel;
    }

    /**
     * Gets a compatible SampleModel with the specified width and height.
     * 
     * @param width
     *            the width.
     * @param height
     *            the height.
     * @return the SampleModel.
     */
    public SampleModel getSampleModel(int width, int height) {
        if ((long)width * height > Integer.MAX_VALUE) {
            throw new IllegalArgumentException("width * height > Integer.MAX_VALUE");
        }
        return sampleModel.createCompatibleSampleModel(width, height);
    }

    /**
     * Gets the ColorModel associated with this ImageTypeSpecifier.
     * 
     * @return the ColorModel associated with this ImageTypeSpecifier.
     */
    public ColorModel getColorModel() {
        return colorModel;
    }

    /**
     * Creates the BufferedImage with the specified width and height and the
     * ColorMadel and SampleModel which are specified by this
     * ImageTypeSpecifier.
     * 
     * @param width
     *            the width of the BufferedImage.
     * @param height
     *            the height of the BufferedImage.
     * @return the BufferedImage.
     */
    public BufferedImage createBufferedImage(int width, int height) {
        throw new UnsupportedOperationException("Not supported yet");
    }

    /**
     * Compares this ImageTypeSpecifier object with the specified object.
     * 
     * @param o
     *            the Object to be compared.
     * @return true, if the object is an ImageTypeSpecifier with the same data
     *         as this ImageTypeSpecifier, false otherwise.
     */
    @Override
    public boolean equals(Object o) {
        boolean rt = false;
        if (o instanceof ImageTypeSpecifier) {
            ImageTypeSpecifier ts = (ImageTypeSpecifier)o;
            rt = colorModel.equals(ts.colorModel) && sampleModel.equals(ts.sampleModel);
        }
        return rt;
    }
}