154 for (int i = 0; i < getNumDataElements(); i++) {
155 dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
156 }
157 } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
158 SinglePixelPackedSampleModel sppsm =
159 (SinglePixelPackedSampleModel)sampleModel;
160 this.scanlineStride = sppsm.getScanlineStride();
161 this.pixelStride = 1;
162 this.dataOffsets = new int[1];
163 this.dataOffsets[0] = dbus.getOffset();
164 int xOffset = aRegion.x - origin.x;
165 int yOffset = aRegion.y - origin.y;
166 dataOffsets[0] += xOffset+yOffset*scanlineStride;
167 } else {
168 throw new RasterFormatException("ShortInterleavedRasters must "+
169 "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
170 " or 1 band ComponentSampleModel. Sample model is "+
171 sampleModel);
172 }
173 this.bandOffset = this.dataOffsets[0];
174 verify(false);
175 }
176
177 /**
178 * Returns a copy of the data offsets array. For each band the data offset
179 * is the index into the band's data array, of the first sample of the
180 * band.
181 */
182 public int[] getDataOffsets() {
183 return (int[]) dataOffsets.clone();
184 }
185
186 /**
187 * Returns the data offset for the specified band. The data offset
188 * is the index into the data array in which the first sample
189 * of the first scanline is stored.
190 * @param band The band whose offset is returned.
191 */
192 public int getDataOffset(int band) {
193 return dataOffsets[band];
194 }
743 */
744 public WritableRaster createCompatibleWritableRaster(int w, int h) {
745 if (w <= 0 || h <=0) {
746 throw new RasterFormatException("negative "+
747 ((w <= 0) ? "width" : "height"));
748 }
749
750 SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);
751
752 return new ShortInterleavedRaster(sm, new Point(0, 0));
753 }
754
755 /**
756 * Creates a Raster with the same layout and the same
757 * width and height, and with new zeroed data arrays. If
758 * the Raster is a subRaster, this will call
759 * createCompatibleRaster(width, height).
760 */
761 public WritableRaster createCompatibleWritableRaster() {
762 return createCompatibleWritableRaster(width,height);
763 }
764
765 /**
766 * Verify that the layout parameters are consistent with
767 * the data. If strictCheck
768 * is false, this method will check for ArrayIndexOutOfBounds conditions. If
769 * strictCheck is true, this method will check for additional error
770 * conditions such as line wraparound (width of a line greater than
771 * the scanline stride).
772 * @return String Error string, if the layout is incompatible with
773 * the data. Otherwise returns null.
774 */
775 private void verify (boolean strictCheck) {
776 int maxSize = 0;
777 int size;
778
779 for (int i=0; i < numDataElements; i++) {
780 size = (height-1)*scanlineStride + (width-1)*pixelStride +
781 dataOffsets[i];
782 if (size > maxSize) {
783 maxSize = size;
784 }
785 }
786 if (data.length < maxSize) {
787 throw new RasterFormatException("Data array too small (should be "+
788 maxSize+" )");
789 }
790 }
791
792 public String toString() {
793 return new String ("ShortInterleavedRaster: width = "+width
794 +" height = " + height
795 +" #numDataElements "+numDataElements);
796 // +" xOff = "+xOffset+" yOff = "+yOffset);
797 }
798
799 }
|
154 for (int i = 0; i < getNumDataElements(); i++) {
155 dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
156 }
157 } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
158 SinglePixelPackedSampleModel sppsm =
159 (SinglePixelPackedSampleModel)sampleModel;
160 this.scanlineStride = sppsm.getScanlineStride();
161 this.pixelStride = 1;
162 this.dataOffsets = new int[1];
163 this.dataOffsets[0] = dbus.getOffset();
164 int xOffset = aRegion.x - origin.x;
165 int yOffset = aRegion.y - origin.y;
166 dataOffsets[0] += xOffset+yOffset*scanlineStride;
167 } else {
168 throw new RasterFormatException("ShortInterleavedRasters must "+
169 "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
170 " or 1 band ComponentSampleModel. Sample model is "+
171 sampleModel);
172 }
173 this.bandOffset = this.dataOffsets[0];
174 verify();
175 }
176
177 /**
178 * Returns a copy of the data offsets array. For each band the data offset
179 * is the index into the band's data array, of the first sample of the
180 * band.
181 */
182 public int[] getDataOffsets() {
183 return (int[]) dataOffsets.clone();
184 }
185
186 /**
187 * Returns the data offset for the specified band. The data offset
188 * is the index into the data array in which the first sample
189 * of the first scanline is stored.
190 * @param band The band whose offset is returned.
191 */
192 public int getDataOffset(int band) {
193 return dataOffsets[band];
194 }
743 */
744 public WritableRaster createCompatibleWritableRaster(int w, int h) {
745 if (w <= 0 || h <=0) {
746 throw new RasterFormatException("negative "+
747 ((w <= 0) ? "width" : "height"));
748 }
749
750 SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);
751
752 return new ShortInterleavedRaster(sm, new Point(0, 0));
753 }
754
755 /**
756 * Creates a Raster with the same layout and the same
757 * width and height, and with new zeroed data arrays. If
758 * the Raster is a subRaster, this will call
759 * createCompatibleRaster(width, height).
760 */
761 public WritableRaster createCompatibleWritableRaster() {
762 return createCompatibleWritableRaster(width,height);
763 }
764
765 public String toString() {
766 return new String ("ShortInterleavedRaster: width = "+width
767 +" height = " + height
768 +" #numDataElements "+numDataElements);
769 // +" xOff = "+xOffset+" yOff = "+yOffset);
770 }
771
772 }
|