Search in sources :

Example 11 with SampleModel

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);
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) SampleModel(java.awt.image.SampleModel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Example 12 with SampleModel

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);
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SampleModel(java.awt.image.SampleModel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) RasterFormatException(java.awt.image.RasterFormatException) Point(java.awt.Point)

Example 13 with SampleModel

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);
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) SampleModel(java.awt.image.SampleModel) IndexColorModel(java.awt.image.IndexColorModel) ColorModel(java.awt.image.ColorModel) NodeList(org.w3c.dom.NodeList) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 14 with SampleModel

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);
    }
}
Also used : SampleModel(java.awt.image.SampleModel) ColorModel(java.awt.image.ColorModel)

Example 15 with SampleModel

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);
}
Also used : PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SampleModel(java.awt.image.SampleModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) Point(java.awt.Point) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

SampleModel (java.awt.image.SampleModel)47 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)22 ComponentSampleModel (java.awt.image.ComponentSampleModel)21 Point (java.awt.Point)20 ColorModel (java.awt.image.ColorModel)16 Rectangle (java.awt.Rectangle)15 DataBuffer (java.awt.image.DataBuffer)14 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)14 IndexColorModel (java.awt.image.IndexColorModel)12 RasterFormatException (java.awt.image.RasterFormatException)9 WritableRaster (java.awt.image.WritableRaster)9 DataBufferByte (java.awt.image.DataBufferByte)8 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)8 BufferedImage (java.awt.image.BufferedImage)7 DataBufferInt (java.awt.image.DataBufferInt)7 BandedSampleModel (java.awt.image.BandedSampleModel)6 DirectColorModel (java.awt.image.DirectColorModel)6 Raster (java.awt.image.Raster)6 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)6 DataBufferShort (java.awt.image.DataBufferShort)5