java.awt.image.SampleModel Java Examples
The following examples show how to use
java.awt.image.SampleModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BMPImageWriterSpi.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { int dataType= type.getSampleModel().getDataType(); if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT) return false; SampleModel sm = type.getSampleModel(); int numBands = sm.getNumBands(); if (!(numBands == 1 || numBands == 3)) return false; if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE) return false; if (dataType > DataBuffer.TYPE_BYTE && !(sm instanceof SinglePixelPackedSampleModel)) return false; return true; }
Example #2
Source File: ICMColorDataTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void makeImage() { int scanLineBytes = WIDTH / PIXELS_IN_BYTE; if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) { // Make sure all the pixels in a scan line fit scanLineBytes += 1; } byte[] bits = new byte[scanLineBytes * HEIGHT]; DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0); SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, WIDTH, HEIGHT, BITS_PER_PIXEL); WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null); IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE); BufferedImage bufImage = new BufferedImage(indexModel, raster, indexModel.isAlphaPremultiplied(), null); Graphics g = bufImage.getGraphics(); g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1); g.dispose(); }
Example #3
Source File: ImageUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static long getBandSize(SampleModel sm) { int elementSize = DataBuffer.getDataTypeSize(sm.getDataType()); if (sm instanceof ComponentSampleModel) { ComponentSampleModel csm = (ComponentSampleModel)sm; int pixelStride = csm.getPixelStride(); int scanlineStride = csm.getScanlineStride(); long size = Math.min(pixelStride, scanlineStride); if (pixelStride > 0) size += pixelStride * (sm.getWidth() - 1); if (scanlineStride > 0) size += scanlineStride * (sm.getHeight() - 1); return size * ((elementSize + 7) / 8); } else return getTileSize(sm); }
Example #4
Source File: BMPImageWriterSpi.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { int dataType= type.getSampleModel().getDataType(); if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT) return false; SampleModel sm = type.getSampleModel(); int numBands = sm.getNumBands(); if (!(numBands == 1 || numBands == 3)) return false; if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE) return false; if (dataType > DataBuffer.TYPE_BYTE && !(sm instanceof SinglePixelPackedSampleModel)) return false; return true; }
Example #5
Source File: JPEGImageWriterSpi.java From JDKSourceCode1.8 with MIT License | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sampleModel = type.getSampleModel(); // Find the maximum bit depth across all channels int[] sampleSize = sampleModel.getSampleSize(); int bitDepth = sampleSize[0]; for (int i = 1; i < sampleSize.length; i++) { if (sampleSize[i] > bitDepth) { bitDepth = sampleSize[i]; } } // 4450894: Ensure bitDepth is between 1 and 8 if (bitDepth < 1 || bitDepth > 8) { return false; } return true; }
Example #6
Source File: GIFImageWriterSpi.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { if (type == null) { throw new IllegalArgumentException("type == null!"); } SampleModel sm = type.getSampleModel(); ColorModel cm = type.getColorModel(); boolean canEncode = sm.getNumBands() == 1 && sm.getSampleSize(0) <= 8 && sm.getWidth() <= 65535 && sm.getHeight() <= 65535 && (cm == null || cm.getComponentSize()[0] <= 8); if (canEncode) { return true; } else { return PaletteBuilder.canCreatePalette(type); } }
Example #7
Source File: ImageUtil.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public static int getElementSize(SampleModel sm) { int elementSize = DataBuffer.getDataTypeSize(sm.getDataType()); if (sm instanceof MultiPixelPackedSampleModel) { MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel)sm; return mppsm.getSampleSize(0) * mppsm.getNumBands(); } else if (sm instanceof ComponentSampleModel) { return sm.getNumBands() * elementSize; } else if (sm instanceof SinglePixelPackedSampleModel) { return elementSize; } return elementSize * sm.getNumBands(); }
Example #8
Source File: GIFImageWriterSpi.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { if (type == null) { throw new IllegalArgumentException("type == null!"); } SampleModel sm = type.getSampleModel(); ColorModel cm = type.getColorModel(); boolean canEncode = sm.getNumBands() == 1 && sm.getSampleSize(0) <= 8 && sm.getWidth() <= 65535 && sm.getHeight() <= 65535 && (cm == null || cm.getComponentSize()[0] <= 8); if (canEncode) { return true; } else { return PaletteBuilder.canCreatePalette(type); } }
Example #9
Source File: ByteComponentRaster.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Creates a Raster with the same layout but using a different * width and height, and with new zeroed data arrays. */ public WritableRaster createCompatibleWritableRaster(int w, int h) { if (w <= 0 || h <=0) { throw new RasterFormatException("negative "+ ((w <= 0) ? "width" : "height")); } SampleModel sm = sampleModel.createCompatibleSampleModel(w, h); return new ByteComponentRaster(sm , new Point(0,0)); }
Example #10
Source File: ShortInterleavedRaster.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a ShortInterleavedRaster with the given SampleModel. * The Raster's upper left corner is origin and it is the same * size as the SampleModel. A DataBuffer large enough to describe the * Raster is automatically created. SampleModel must be of type * PixelInterleavedSampleModel or SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param origin The Point that specified the origin. */ public ShortInterleavedRaster(SampleModel sampleModel, Point origin) { this(sampleModel, (DataBufferUShort) sampleModel.createDataBuffer(), new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); }
Example #11
Source File: HistogramConfig.java From geowave with Apache License 2.0 | 5 votes |
public HistogramConfig(final SampleModel sampleModel) { final int numBands = sampleModel.getNumBands(); highValues = new double[numBands]; lowValues = new double[numBands]; numBins = new int[numBands]; for (int b = 0; b < numBands; b++) { final NumberRange range = TypeMap.getRange(TypeMap.getSampleDimensionType(sampleModel, b)); int bins; double min = range.getMinimum(true); double max = range.getMaximum(true); if (Double.isInfinite(min) || Double.isInfinite(max) || Double.isNaN(min) || Double.isNaN(max)) { // in this case there is no reasonable default, just use a range // of 0 to 1 as a placeholder min = 0; max = 1; bins = MAX_DEFAULT_NUM_BINS; } else { bins = (int) Math.min(MAX_DEFAULT_NUM_BINS, (max - min) + 1); } lowValues[b] = min; highValues[b] = max; numBins[b] = bins; } }
Example #12
Source File: ShortInterleavedRaster.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a Writable subRaster given a region of the Raster. The x and y * coordinates specify the horizontal and vertical offsets * from the upper-left corner of this Raster to the upper-left corner * of the subRaster. A subset of the bands of the parent Raster may * be specified. If this is null, then all the bands are present in the * subRaster. A translation to the subRaster may also be specified. * Note that the subRaster will reference the same * DataBuffers as the parent Raster, but using different offsets. * @param x X offset. * @param y Y offset. * @param width Width (in pixels) of the subraster. * @param height Height (in pixels) of the subraster. * @param x0 Translated X origin of the subraster. * @param y0 Translated Y origin of the subraster. * @param bandList Array of band indices. * @exception RasterFormatException * if the specified bounding box is outside of the parent Raster. */ public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) { if (x < this.minX) { throw new RasterFormatException("x lies outside the raster"); } if (y < this.minY) { throw new RasterFormatException("y lies outside the raster"); } if ((x+width < x) || (x+width > this.minX + this.width)) { throw new RasterFormatException("(x + width) is outside of Raster"); } if ((y+height < y) || (y+height > this.minY + this.height)) { throw new RasterFormatException("(y + height) is outside of Raster"); } SampleModel sm; if (bandList != null) sm = sampleModel.createSubsetSampleModel(bandList); else sm = sampleModel; int deltaX = x0 - x; int deltaY = y0 - y; return new ShortInterleavedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); }
Example #13
Source File: IntegerComponentRaster.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Constructs a IntegerComponentRaster with the given SampleModel * and DataBuffer. The Raster's upper left corner is origin and * it is the same sizes the SampleModel. The DataBuffer is not * initialized and must be a DataBufferInt compatible with SampleModel. * SampleModel must be of type SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param dataBuffer The DataBufferInt that contains the image data. * @param origin The Point that specifies the origin. */ public IntegerComponentRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin) { this(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); }
Example #14
Source File: ColCvtAlpha.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB); // Set src pixel values Color pelColor = new Color(100, 100, 100, 128); for (int i = 0; i < 10; i++) { src.setRGB(0, i, pelColor.getRGB()); } ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8,8}, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); SampleModel sm = new PixelInterleavedSampleModel (DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int [] { 0, 1 }); WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0)); BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); dst = dst.getSubimage(0, 0, 1, 10); ColorConvertOp op = new ColorConvertOp(null); op.filter(src, dst); for (int i = 0; i < 10; i++) { if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) { throw new RuntimeException( "Incorrect destination alpha value."); } } }
Example #15
Source File: WBMPImageWriterSpi.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sm = type.getSampleModel(); if (!(sm instanceof MultiPixelPackedSampleModel)) return false; if (sm.getSampleSize(0) != 1) return false; return true; }
Example #16
Source File: ShortInterleavedRaster.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Constructs a ShortInterleavedRaster with the given SampleModel. * The Raster's upper left corner is origin and it is the same * size as the SampleModel. A DataBuffer large enough to describe the * Raster is automatically created. SampleModel must be of type * PixelInterleavedSampleModel or SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param origin The Point that specified the origin. */ public ShortInterleavedRaster(SampleModel sampleModel, Point origin) { this(sampleModel, (DataBufferUShort) sampleModel.createDataBuffer(), new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); }
Example #17
Source File: ByteBandedRaster.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Creates a Raster with the same layout but using a different * width and height, and with new zeroed data arrays. */ public WritableRaster createCompatibleWritableRaster(int w, int h) { if (w <= 0 || h <=0) { throw new RasterFormatException("negative "+ ((w <= 0) ? "width" : "height")); } SampleModel sm = sampleModel.createCompatibleSampleModel(w,h); return new ByteBandedRaster(sm, new Point(0,0)); }
Example #18
Source File: RasterUtils.java From geowave with Apache License 2.0 | 5 votes |
private static BufferedImage copyImage( final int targetWidth, final int targetHeight, final Color backgroundColor, final double[][] noDataValues, final RenderedImage originalImage) { Hashtable<String, Object> properties = null; if (originalImage.getPropertyNames() != null) { properties = new Hashtable<>(); for (final String name : originalImage.getPropertyNames()) { properties.put(name, originalImage.getProperty(name)); } } final SampleModel sm = originalImage.getSampleModel().createCompatibleSampleModel(targetWidth, targetHeight); final WritableRaster raster = Raster.createWritableRaster(sm, null); final ColorModel colorModel = originalImage.getColorModel(); final boolean alphaPremultiplied = colorModel.isAlphaPremultiplied(); RasterUtils.fillWithNoDataValues(raster, noDataValues); final BufferedImage image = new BufferedImage(colorModel, raster, alphaPremultiplied, properties); if (noDataValues == null) { final Graphics2D g2D = (Graphics2D) image.getGraphics(); final Color save = g2D.getColor(); g2D.setColor(backgroundColor); g2D.fillRect(0, 0, image.getWidth(), image.getHeight()); g2D.setColor(save); } return image; }
Example #19
Source File: IntegerComponentRaster.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a subraster given a region of the raster. The x and y * coordinates specify the horizontal and vertical offsets * from the upper-left corner of this raster to the upper-left corner * of the subraster. A subset of the bands of the parent Raster may * be specified. If this is null, then all the bands are present in the * subRaster. A translation to the subRaster may also be specified. * Note that the subraster will reference the same * DataBuffer as the parent raster, but using different offsets. * @param x X offset. * @param y Y offset. * @param width Width (in pixels) of the subraster. * @param height Height (in pixels) of the subraster. * @param x0 Translated X origin of the subraster. * @param y0 Translated Y origin of the subraster. * @param bandList Array of band indices. * @exception RasterFormatException * if the specified bounding box is outside of the parent raster. */ public WritableRaster createWritableChild (int x, int y, int width, int height, int x0, int y0, int bandList[]) { if (x < this.minX) { throw new RasterFormatException("x lies outside raster"); } if (y < this.minY) { throw new RasterFormatException("y lies outside raster"); } if ((x+width < x) || (x+width > this.minX + this.width)) { throw new RasterFormatException("(x + width) is outside raster"); } if ((y+height < y) || (y+height > this.minY + this.height)) { throw new RasterFormatException("(y + height) is outside raster"); } SampleModel sm; if (bandList != null) sm = sampleModel.createSubsetSampleModel(bandList); else sm = sampleModel; int deltaX = x0 - x; int deltaY = y0 - y; return new IntegerComponentRaster(sm, dataBuffer, new Rectangle(x0,y0,width,height), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); }
Example #20
Source File: ShortComponentRaster.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a ShortComponentRaster with the given SampleModel * and DataBuffer. The Raster's upper left corner is origin and * it is the same sizes the SampleModel. The DataBuffer is not * initialized and must be a DataBufferUShort compatible with SampleModel. * SampleModel must be of type ComponentSampleModel or * SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param dataBuffer The DataBufferUShort that contains the image data. * @param origin The Point that specifies the origin. */ public ShortComponentRaster(SampleModel sampleModel, DataBufferUShort dataBuffer, Point origin) { this(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); }
Example #21
Source File: SimpleRenderedImage.java From ganttproject with GNU General Public License v3.0 | 5 votes |
/** * Copies an arbitrary rectangular region of the RenderedImage into a * caller-supplied WritableRaster. The region to be computed is determined by * clipping the bounds of the supplied WritableRaster against the bounds of * the image. The supplied WritableRaster must have a SampleModel that is * compatible with that of the image. * * <p> * If the raster argument is null, the entire image will be copied into a * newly-created WritableRaster with a SampleModel that is compatible with * that of the image. * * @param dest * a WritableRaster to hold the returned portion of the image. * @return a reference to the supplied WritableRaster, or to a new * WritableRaster if the supplied one was null. */ @Override public WritableRaster copyData(WritableRaster dest) { Rectangle bounds; Raster tile; if (dest == null) { bounds = getBounds(); Point p = new Point(minX, minY); /* A SampleModel to hold the entire image. */ SampleModel sm = sampleModel.createCompatibleSampleModel(width, height); dest = Raster.createWritableRaster(sm, p); } else { bounds = dest.getBounds(); } int startX = XToTileX(bounds.x); int startY = YToTileY(bounds.y); int endX = XToTileX(bounds.x + bounds.width - 1); int endY = YToTileY(bounds.y + bounds.height - 1); for (int j = startY; j <= endY; j++) { for (int i = startX; i <= endX; i++) { tile = getTile(i, j); Rectangle intersectRect = bounds.intersection(tile.getBounds()); Raster liveRaster = tile.createChild(intersectRect.x, intersectRect.y, intersectRect.width, intersectRect.height, intersectRect.x, intersectRect.y, null); /* * WritableRaster.setDataElements takes into account of inRaster's minX * and minY and add these to x and y. Since liveRaster has the origin at * the correct location, the following call should not again give these * coordinates in places of x and y. */ dest.setDataElements(0, 0, liveRaster); } } return dest; }
Example #22
Source File: BytePackedRaster.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Creates a Writable subRaster given a region of the Raster. The x and y * coordinates specify the horizontal and vertical offsets * from the upper-left corner of this Raster to the upper-left corner * of the subRaster. The bandList is ignored. * A translation to the subRaster may also be specified. * Note that the subRaster will reference the same * DataBuffer as the parent Raster, but using different offsets. * @param x X offset. * @param y Y offset. * @param width Width (in pixels) of the subraster. * @param height Height (in pixels) of the subraster. * @param x0 Translated X origin of the subraster. * @param y0 Translated Y origin of the subraster. * @param bandList Array of band indices. * @exception RasterFormatException * if the specified bounding box is outside of the parent Raster. */ public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) { if (x < this.minX) { throw new RasterFormatException("x lies outside the raster"); } if (y < this.minY) { throw new RasterFormatException("y lies outside the raster"); } if ((x+width < x) || (x+width > this.minX + this.width)) { throw new RasterFormatException("(x + width) is outside of Raster"); } if ((y+height < y) || (y+height > this.minY + this.height)) { throw new RasterFormatException("(y + height) is outside of Raster"); } SampleModel sm; if (bandList != null) { sm = sampleModel.createSubsetSampleModel(bandList); } else { sm = sampleModel; } int deltaX = x0 - x; int deltaY = y0 - y; return new BytePackedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); }
Example #23
Source File: ShortComponentRaster.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Constructs a ShortComponentRaster with the given SampleModel. * The Raster's upper left corner is origin and it is the same * size as the SampleModel. A DataBuffer large enough to describe the * Raster is automatically created. SampleModel must be of type * ComponentSampleModel or SinglePixelPackedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param origin The Point that specified the origin. */ public ShortComponentRaster(SampleModel sampleModel, Point origin) { this(sampleModel, (DataBufferUShort) sampleModel.createDataBuffer(), new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); }
Example #24
Source File: ShortInterleavedRaster.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Creates a Writable subRaster given a region of the Raster. The x and y * coordinates specify the horizontal and vertical offsets * from the upper-left corner of this Raster to the upper-left corner * of the subRaster. A subset of the bands of the parent Raster may * be specified. If this is null, then all the bands are present in the * subRaster. A translation to the subRaster may also be specified. * Note that the subRaster will reference the same * DataBuffers as the parent Raster, but using different offsets. * @param x X offset. * @param y Y offset. * @param width Width (in pixels) of the subraster. * @param height Height (in pixels) of the subraster. * @param x0 Translated X origin of the subraster. * @param y0 Translated Y origin of the subraster. * @param bandList Array of band indices. * @exception RasterFormatException * if the specified bounding box is outside of the parent Raster. */ public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) { if (x < this.minX) { throw new RasterFormatException("x lies outside the raster"); } if (y < this.minY) { throw new RasterFormatException("y lies outside the raster"); } if ((x+width < x) || (x+width > this.minX + this.width)) { throw new RasterFormatException("(x + width) is outside of Raster"); } if ((y+height < y) || (y+height > this.minY + this.height)) { throw new RasterFormatException("(y + height) is outside of Raster"); } SampleModel sm; if (bandList != null) sm = sampleModel.createSubsetSampleModel(bandList); else sm = sampleModel; int deltaX = x0 - x; int deltaY = y0 - y; return new ShortInterleavedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); }
Example #25
Source File: IntegerComponentRaster.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Creates a subraster given a region of the raster. The x and y * coordinates specify the horizontal and vertical offsets * from the upper-left corner of this raster to the upper-left corner * of the subraster. A subset of the bands of the parent Raster may * be specified. If this is null, then all the bands are present in the * subRaster. A translation to the subRaster may also be specified. * Note that the subraster will reference the same * DataBuffer as the parent raster, but using different offsets. * @param x X offset. * @param y Y offset. * @param width Width (in pixels) of the subraster. * @param height Height (in pixels) of the subraster. * @param x0 Translated X origin of the subraster. * @param y0 Translated Y origin of the subraster. * @param bandList Array of band indices. * @exception RasterFormatException * if the specified bounding box is outside of the parent raster. */ public WritableRaster createWritableChild (int x, int y, int width, int height, int x0, int y0, int bandList[]) { if (x < this.minX) { throw new RasterFormatException("x lies outside raster"); } if (y < this.minY) { throw new RasterFormatException("y lies outside raster"); } if ((x+width < x) || (x+width > this.minX + this.width)) { throw new RasterFormatException("(x + width) is outside raster"); } if ((y+height < y) || (y+height > this.minY + this.height)) { throw new RasterFormatException("(y + height) is outside raster"); } SampleModel sm; if (bandList != null) sm = sampleModel.createSubsetSampleModel(bandList); else sm = sampleModel; int deltaX = x0 - x; int deltaY = y0 - y; return new IntegerComponentRaster(sm, dataBuffer, new Rectangle(x0,y0,width,height), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); }
Example #26
Source File: ShortBandedRaster.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Constructs a ShortBandedRaster with the given SampleModel, * DataBuffer, and parent. DataBuffer must be a DataBufferUShort and * SampleModel must be of type BandedSampleModel. * When translated into the base Raster's * coordinate system, aRegion must be contained by the base Raster. * Origin is the coordinate in the new Raster's coordinate system of * the origin of the base Raster. (The base Raster is the Raster's * ancestor which has no parent.) * * Note that this constructor should generally be called by other * constructors or create methods, it should not be used directly. * @param sampleModel The SampleModel that specifies the layout. * @param dataBuffer The DataBufferUShort that contains the image data. * @param aRegion The Rectangle that specifies the image area. * @param origin The Point that specifies the origin. * @param parent The parent (if any) of this raster. */ public ShortBandedRaster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point origin, ShortBandedRaster parent) { super(sampleModel, dataBuffer, aRegion, origin, parent); this.maxX = minX + width; this.maxY = minY + height; if (!(dataBuffer instanceof DataBufferUShort)) { throw new RasterFormatException("ShortBandedRaster must have " + "ushort DataBuffers"); } DataBufferUShort dbus = (DataBufferUShort)dataBuffer; if (sampleModel instanceof BandedSampleModel) { BandedSampleModel bsm = (BandedSampleModel)sampleModel; this.scanlineStride = bsm.getScanlineStride(); int bankIndices[] = bsm.getBankIndices(); int bandOffsets[] = bsm.getBandOffsets(); int dOffsets[] = dbus.getOffsets(); dataOffsets = new int[bankIndices.length]; data = new short[bankIndices.length][]; int xOffset = aRegion.x - origin.x; int yOffset = aRegion.y - origin.y; for (int i = 0; i < bankIndices.length; i++) { data[i] = stealData(dbus, bankIndices[i]); dataOffsets[i] = dOffsets[bankIndices[i]] + xOffset + yOffset*scanlineStride + bandOffsets[i]; } } else { throw new RasterFormatException("ShortBandedRasters must have "+ "BandedSampleModels"); } verify(); }
Example #27
Source File: PngDitDepthTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IIOInvalidTreeException { // getting the writer for the png format Iterator iter = ImageIO.getImageWritersByFormatName("png"); ImageWriter writer = (ImageWriter) iter.next(); // creating a color model ColorModel colorModel = ColorModel.getRGBdefault(); // creating a sample model SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480); // creating a default metadata object IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null); String formatName = metaData.getNativeMetadataFormatName(); // first call Node metaDataNode = metaData.getAsTree(formatName); try { metaData.setFromTree(formatName, metaDataNode); } catch (Exception ex) { ex.printStackTrace(); } // second call (bitdepht is already set to an invalid value) metaDataNode = metaData.getAsTree(formatName); metaData.setFromTree(formatName, metaDataNode); }
Example #28
Source File: ShortInterleavedRaster.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Creates a Writable subRaster given a region of the Raster. The x and y * coordinates specify the horizontal and vertical offsets * from the upper-left corner of this Raster to the upper-left corner * of the subRaster. A subset of the bands of the parent Raster may * be specified. If this is null, then all the bands are present in the * subRaster. A translation to the subRaster may also be specified. * Note that the subRaster will reference the same * DataBuffers as the parent Raster, but using different offsets. * @param x X offset. * @param y Y offset. * @param width Width (in pixels) of the subraster. * @param height Height (in pixels) of the subraster. * @param x0 Translated X origin of the subraster. * @param y0 Translated Y origin of the subraster. * @param bandList Array of band indices. * @exception RasterFormatException * if the specified bounding box is outside of the parent Raster. */ public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) { if (x < this.minX) { throw new RasterFormatException("x lies outside the raster"); } if (y < this.minY) { throw new RasterFormatException("y lies outside the raster"); } if ((x+width < x) || (x+width > this.minX + this.width)) { throw new RasterFormatException("(x + width) is outside of Raster"); } if ((y+height < y) || (y+height > this.minY + this.height)) { throw new RasterFormatException("(y + height) is outside of Raster"); } SampleModel sm; if (bandList != null) sm = sampleModel.createSubsetSampleModel(bandList); else sm = sampleModel; int deltaX = x0 - x; int deltaY = y0 - y; return new ShortInterleavedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX+deltaX, sampleModelTranslateY+deltaY), this); }
Example #29
Source File: ByteBandedRaster.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Constructs a ByteBandedRaster with the given sampleModel. The * Raster's upper left corner is origin and it is the same * size as the SampleModel. A dataBuffer large * enough to describe the Raster is automatically created. SampleModel * must be of type BandedSampleModel. * @param sampleModel The SampleModel that specifies the layout. * @param origin The Point that specifies the origin. */ public ByteBandedRaster(SampleModel sampleModel, Point origin) { this(sampleModel, sampleModel.createDataBuffer(), new Rectangle(origin.x, origin.y, sampleModel.getWidth(), sampleModel.getHeight()), origin, null); }
Example #30
Source File: UnsignedIntColorModel.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public WritableRaster createCompatibleWritableRaster(final int w, final int h) { final int[] bandOffsets = new int[nChannels]; for (int i = 0; i < nChannels; i++) bandOffsets[i] = i; final SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT, w, h, nChannels, w * nChannels, bandOffsets); final DataBuffer db = new DataBufferInt(w * h, nChannels); return Raster.createWritableRaster(m, db, null); }