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 Igor V. Stolyarov
019: * @version $Revision$
020: */package java.awt.image;
021:
022: import org.apache.harmony.awt.internal.nls.Messages;
023:
024: public class PixelInterleavedSampleModel extends ComponentSampleModel {
025:
026: public PixelInterleavedSampleModel(int dataType, int w, int h,
027: int pixelStride, int scanlineStride, int bandOffsets[]) {
028:
029: super (dataType, w, h, pixelStride, scanlineStride, bandOffsets);
030:
031: int maxOffset = bandOffsets[0];
032: int minOffset = bandOffsets[0];
033: for (int i = 1; i < bandOffsets.length; i++) {
034: if (bandOffsets[i] > maxOffset) {
035: maxOffset = bandOffsets[i];
036: }
037: if (bandOffsets[i] < minOffset) {
038: minOffset = bandOffsets[i];
039: }
040: }
041:
042: maxOffset -= minOffset;
043:
044: if (maxOffset > scanlineStride) {
045: // awt.241=Any offset between bands is greater than the Scanline stride
046: throw new IllegalArgumentException(Messages
047: .getString("awt.241")); //$NON-NLS-1$
048: }
049:
050: if (maxOffset > pixelStride) {
051: // awt.242=Pixel stride is less than any offset between bands
052: throw new IllegalArgumentException(Messages
053: .getString("awt.242")); //$NON-NLS-1$
054: }
055:
056: if (pixelStride * w > scanlineStride) {
057: // awt.243=Product of Pixel stride and w is greater than Scanline stride
058: throw new IllegalArgumentException(Messages
059: .getString("awt.243")); //$NON-NLS-1$
060: }
061:
062: }
063:
064: @Override
065: public SampleModel createSubsetSampleModel(int bands[]) {
066: int newOffsets[] = new int[bands.length];
067: for (int i = 0; i < bands.length; i++) {
068: newOffsets[i] = bandOffsets[bands[i]];
069: }
070:
071: return new PixelInterleavedSampleModel(dataType, width, height,
072: pixelStride, scanlineStride, newOffsets);
073: }
074:
075: @Override
076: public SampleModel createCompatibleSampleModel(int w, int h) {
077: int newOffsets[];
078: int minOffset = bandOffsets[0];
079:
080: for (int i = 1; i < numBands; i++) {
081: if (bandOffsets[i] < minOffset) {
082: minOffset = bandOffsets[i];
083: }
084: }
085:
086: if (minOffset > 0) {
087: newOffsets = new int[numBands];
088: for (int i = 0; i < numBands; i++) {
089: newOffsets[i] = bandOffsets[i] - minOffset;
090: }
091: } else {
092: newOffsets = bandOffsets;
093: }
094:
095: return new PixelInterleavedSampleModel(dataType, w, h,
096: pixelStride, pixelStride * w, newOffsets);
097: }
098:
099: @Override
100: public int hashCode() {
101: int hash = super .hashCode();
102: int tmp = hash >>> 8;
103: hash <<= 8;
104: hash |= tmp;
105:
106: return hash ^ 0x66;
107: }
108:
109: }
|