1 7 8 package java.awt.image; 9 10 37 38 public class PixelInterleavedSampleModel extends ComponentSampleModel 39 { 40 64 public PixelInterleavedSampleModel(int dataType, 65 int w, int h, 66 int pixelStride, 67 int scanlineStride, 68 int bandOffsets[]) { 69 super(dataType, w, h, pixelStride, scanlineStride, bandOffsets); 70 int minBandOff=bandOffsets[0]; 71 int maxBandOff=bandOffsets[0]; 72 for (int i=1; i<bandOffsets.length; i++) { 73 minBandOff = Math.min(minBandOff,bandOffsets[i]); 74 maxBandOff = Math.max(maxBandOff,bandOffsets[i]); 75 } 76 maxBandOff -= minBandOff; 77 if (maxBandOff > scanlineStride) { 78 throw new IllegalArgumentException ("Offsets between bands must be"+ 79 " less than the scanline "+ 80 " stride"); 81 } 82 if (pixelStride*w > scanlineStride) { 83 throw new IllegalArgumentException ("Pixel stride times width "+ 84 "must be less than or "+ 85 "equal to the scanline "+ 86 "stride"); 87 } 88 if (pixelStride < maxBandOff) { 89 throw new IllegalArgumentException ("Pixel stride must be greater"+ 90 " than or equal to the offsets"+ 91 " between bands"); 92 } 93 } 94 95 108 public SampleModel createCompatibleSampleModel(int w, int h) { 109 int minBandoff=bandOffsets[0]; 110 int numBands = bandOffsets.length; 111 for (int i=1; i < numBands; i++) { 112 if (bandOffsets[i] < minBandoff) { 113 minBandoff = bandOffsets[i]; 114 } 115 } 116 int[] bandOff; 117 if (minBandoff > 0) { 118 bandOff = new int[numBands]; 119 for (int i=0; i < numBands; i++) { 120 bandOff[i] = bandOffsets[i] - minBandoff; 121 } 122 } 123 else { 124 bandOff = bandOffsets; 125 } 126 return new PixelInterleavedSampleModel (dataType, w, h, pixelStride, 127 pixelStride*w, bandOff); 128 } 129 130 139 public SampleModel createSubsetSampleModel(int bands[]) { 140 int newBandOffsets[] = new int[bands.length]; 141 for (int i=0; i<bands.length; i++) { 142 newBandOffsets[i] = bandOffsets[bands[i]]; 143 } 144 return new PixelInterleavedSampleModel (this.dataType, width, height, 145 this.pixelStride, 146 scanlineStride, newBandOffsets); 147 } 148 149 public int hashCode() { 151 return super.hashCode() ^ 0x1; 152 } 153 } 154 | Popular Tags |