001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Rustem V. Rafikov
019: * @version $Revision: 1.3 $
020: */package javax.imageio;
021:
022: import java.awt.image.ColorModel;
023: import java.awt.image.SampleModel;
024: import java.awt.image.BufferedImage;
025: import java.awt.image.RenderedImage;
026: import java.awt.color.ColorSpace;
027:
028: import org.apache.harmony.luni.util.NotImplementedException;
029:
030: /**
031: * TODO implement all the methods
032: */
033: public class ImageTypeSpecifier {
034:
035: protected ColorModel colorModel;
036: protected SampleModel sampleModel;
037:
038: public ImageTypeSpecifier(ColorModel colorModel,
039: SampleModel sampleModel) {
040: if (colorModel == null) {
041: throw new IllegalArgumentException(
042: "color model should not be NULL");
043: }
044: if (sampleModel == null) {
045: throw new IllegalArgumentException(
046: "sample model should not be NULL");
047: }
048: if (!colorModel.isCompatibleSampleModel(sampleModel)) {
049: throw new IllegalArgumentException(
050: "color and sample models are not compatible");
051: }
052:
053: this .colorModel = colorModel;
054: this .sampleModel = sampleModel;
055: }
056:
057: public ImageTypeSpecifier(RenderedImage renderedImage) {
058: if (renderedImage == null) {
059: throw new IllegalArgumentException(
060: "image should not be NULL");
061: }
062: this .colorModel = renderedImage.getColorModel();
063: this .sampleModel = renderedImage.getSampleModel();
064: }
065:
066: public static ImageTypeSpecifier createPacked(
067: ColorSpace colorSpace, int redMask, int greenMask,
068: int blueMask, int alphaMask, int transferType,
069: boolean isAlphaPremultiplied)
070: throws NotImplementedException {
071: // TODO: implement
072: throw new NotImplementedException();
073: }
074:
075: public static ImageTypeSpecifier createInterleaved(
076: ColorSpace colorSpace, int[] bandOffsets, int dataType,
077: boolean hasAlpha, boolean isAlphaPremultiplied)
078: throws NotImplementedException {
079: // TODO: implement
080: throw new NotImplementedException();
081: }
082:
083: public static ImageTypeSpecifier createBanded(
084: ColorSpace colorSpace, int[] bankIndices,
085: int[] bandOffsets, int dataType, boolean hasAlpha,
086: boolean isAlphaPremultiplied)
087: throws NotImplementedException {
088: // TODO: implement
089: throw new NotImplementedException();
090: }
091:
092: public static ImageTypeSpecifier createGrayscale(int bits,
093: int dataType, boolean isSigned)
094: throws NotImplementedException {
095: // TODO: implement
096: throw new NotImplementedException();
097: }
098:
099: public static ImageTypeSpecifier createGrayscale(int bits,
100: int dataType, boolean isSigned, boolean isAlphaPremultiplied)
101: throws NotImplementedException {
102: // TODO: implement
103: throw new NotImplementedException();
104: }
105:
106: public static ImageTypeSpecifier createIndexed(byte[] redLUT,
107: byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits,
108: int dataType) throws NotImplementedException {
109: // TODO: implement
110: throw new NotImplementedException();
111: }
112:
113: public static ImageTypeSpecifier createFromBufferedImageType(
114: int bufferedImageType) throws NotImplementedException {
115: // TODO: implement
116: throw new NotImplementedException();
117: }
118:
119: public static ImageTypeSpecifier createFromRenderedImage(
120: RenderedImage image) {
121: if (null == image) {
122: throw new IllegalArgumentException(
123: "image should not be NULL");
124: }
125: return new ImageTypeSpecifier(image);
126: }
127:
128: public int getBufferedImageType() throws NotImplementedException {
129: // TODO: implement
130: throw new NotImplementedException();
131: }
132:
133: public int getNumComponents() {
134: return colorModel.getNumComponents();
135: }
136:
137: public int getNumBands() {
138: return sampleModel.getNumBands();
139: }
140:
141: public int getBitsPerBand(int band) {
142: if (band < 0 || band >= getNumBands()) {
143: throw new IllegalArgumentException();
144: }
145: return sampleModel.getSampleSize(band);
146: }
147:
148: public SampleModel getSampleModel() {
149: return sampleModel;
150: }
151:
152: public SampleModel getSampleModel(int width, int height) {
153: if ((long) width * height > Integer.MAX_VALUE) {
154: throw new IllegalArgumentException(
155: "width * height > Integer.MAX_VALUE");
156: }
157: return sampleModel.createCompatibleSampleModel(width, height);
158: }
159:
160: public ColorModel getColorModel() {
161: return colorModel;
162: }
163:
164: public BufferedImage createBufferedImage(int width, int height)
165: throws NotImplementedException {
166: // TODO: implement
167: throw new NotImplementedException();
168: }
169:
170: @Override
171: public boolean equals(Object o) {
172: boolean rt = false;
173: if (o instanceof ImageTypeSpecifier) {
174: ImageTypeSpecifier ts = (ImageTypeSpecifier) o;
175: rt = colorModel.equals(ts.colorModel)
176: && sampleModel.equals(ts.sampleModel);
177: }
178: return rt;
179: }
180: }
|