use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class ShortComponentRaster method createWritableChild.
/**
* 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 ShortComponentRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class ShortInterleavedRaster method createWritableChild.
/**
* 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);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class GIFImageWriteParam method writeImage.
/**
* Writes any extension blocks, the Image Descriptor, and the image data
*
* @param iioimage The image and image metadata.
* @param param The write parameters.
* @param globalColorTable The Global Color Table.
* @param sourceBounds The source region.
* @param destSize The destination dimensions.
*/
private void writeImage(RenderedImage image, GIFWritableImageMetadata imageMetadata, ImageWriteParam param, byte[] globalColorTable, Rectangle sourceBounds, Dimension destSize) throws IOException {
ColorModel colorModel = image.getColorModel();
SampleModel sampleModel = image.getSampleModel();
boolean writeGraphicsControlExtension;
if (imageMetadata == null) {
// Create default metadata.
imageMetadata = (GIFWritableImageMetadata) getDefaultImageMetadata(new ImageTypeSpecifier(image), param);
// Set GraphicControlExtension flag only if there is
// transparency.
writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
} else {
// Check for GraphicControlExtension element.
NodeList list = null;
try {
IIOMetadataNode root = (IIOMetadataNode) imageMetadata.getAsTree(IMAGE_METADATA_NAME);
list = root.getElementsByTagName("GraphicControlExtension");
} catch (IllegalArgumentException iae) {
// Should never happen.
}
// Set GraphicControlExtension flag if element present.
writeGraphicsControlExtension = list != null && list.getLength() > 0;
// the interlacing is set per the ImageWriteParam mode setting.
if (param != null && param.canWriteProgressive()) {
if (param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
imageMetadata.interlaceFlag = false;
} else if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) {
imageMetadata.interlaceFlag = true;
}
}
}
// Unset local color table if equal to global color table.
if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
imageMetadata.localColorTable = null;
}
// Override dimensions
imageMetadata.imageWidth = destSize.width;
imageMetadata.imageHeight = destSize.height;
// Write Graphics Control Extension.
if (writeGraphicsControlExtension) {
writeGraphicControlExtension(imageMetadata);
}
// Write extension blocks.
writePlainTextExtension(imageMetadata);
writeApplicationExtension(imageMetadata);
writeCommentExtension(imageMetadata);
// Write Image Descriptor
int bitsPerPixel = getNumBits(imageMetadata.localColorTable == null ? (globalColorTable == null ? sampleModel.getSampleSize(0) : globalColorTable.length / 3) : imageMetadata.localColorTable.length / 3);
writeImageDescriptor(imageMetadata, bitsPerPixel);
// Write image data
writeRasterData(image, sourceBounds, destSize, param, imageMetadata.interlaceFlag);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class GIFImageWriterSpi method canEncodeImage.
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);
}
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class GIFImageReader method createIndexed.
// We don't check all parameters as ImageTypeSpecifier.createIndexed do
// since this method is private and we pass consistent data here
private ImageTypeSpecifier createIndexed(byte[] r, byte[] g, byte[] b, int bits) {
ColorModel colorModel;
if (imageMetadata.transparentColorFlag) {
// Some files erroneously have a transparent color index
// of 255 even though there are fewer than 256 colors.
int idx = Math.min(imageMetadata.transparentColorIndex, r.length - 1);
colorModel = new IndexColorModel(bits, r.length, r, g, b, idx);
} else {
colorModel = new IndexColorModel(bits, r.length, r, g, b);
}
SampleModel sampleModel;
if (bits == 8) {
int[] bandOffsets = { 0 };
sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 1, 1, 1, 1, bandOffsets);
} else {
sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 1, 1, bits);
}
return new ImageTypeSpecifier(colorModel, sampleModel);
}
Aggregations