Package java.awt.image

Examples of java.awt.image.SampleModel


     * <code>FloatDoubleColorModel</code>.
     *
     * @param raster a <code>Raster</code>to be checked for compatibility.
     */
    public boolean isCompatibleRaster(Raster raster) {
        SampleModel sm = raster.getSampleModel();
        return isCompatibleSampleModel(sm);
    }
View Full Code Here


     *
     * @see java.awt.image.WritableRaster
     * @see java.awt.image.SampleModel
     */
    public WritableRaster createCompatibleWritableRaster(int w, int h) {
        SampleModel sm = createCompatibleSampleModel(w, h);
        return RasterFactory.createWritableRaster(sm, new Point(0, 0));
    }
View Full Code Here

    public void encode(RenderedImage im) throws IOException {
        //
        // Check data type and band count compatibility.
        // This implementation handles only 1 and 3 band source images.
        //
        SampleModel sampleModel = im.getSampleModel();
        ColorModel  colorModel  = im.getColorModel();

        // Must be a 1 or 3 band BYTE image
        int numBands  = colorModel.getNumColorComponents();
        int transType = sampleModel.getTransferType();
        if (((transType != DataBuffer.TYPE_BYTE) &&
             !CodecUtils.isPackedByteImage(im)) ||
            ((numBands != 1) && (numBands != 3) )) {
            throw new RuntimeException(JaiI18N.getString("JPEGImageEncoder0"));
        }

        // Must be GRAY or RGB
        int cspaceType = colorModel.getColorSpace().getType();
        if (cspaceType != ColorSpace.TYPE_GRAY &&
            cspaceType != ColorSpace.TYPE_RGB) {
            throw new RuntimeException(JaiI18N.getString("JPEGImageEncoder1"));
        }

        //
        // Create a BufferedImage to be encoded.
        // The JPEG interfaces really need a whole image.
        //
        BufferedImage bi;
        if(im instanceof BufferedImage) {
            bi = (BufferedImage)im;
        } else {
            //
            // Get a contiguous raster. Jpeg compression can't work
            // on tiled data in most cases.
            // Also need to be sure that the raster doesn't have a
            // non-zero origin, since BufferedImage won't accept that.
            // (Bug ID 4253990)
            //

            //Fix 4694162: JPEGImageEncoder throws ClassCastException
            // Obtain the contiguous Raster.
            Raster ras;
            if(im.getNumXTiles() == 1 && im.getNumYTiles() == 1) {
                // Image is not tiled so just get a reference to the tile.
                ras = im.getTile(im.getMinTileX(), im.getMinTileY());
            } else {
                // Image is tiled so need to get a contiguous raster.

                // Create an interleaved raster for copying for 8-bit case.
                // This ensures that for RGB data the band offsets are {0,1,2}.
                // If the JPEG encoder encounters data with BGR offsets as
                // {2,1,0} then it will make yet another copy of the data
                // which might as well be averted here.
                WritableRaster target = sampleModel.getSampleSize(0) == 8 ?
                    Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                                   im.getWidth(),
                                                   im.getHeight(),
                                                   sampleModel.getNumBands(),
                                                   new Point(im.getMinX(),
                                                             im.getMinY())) :
                    null;

                // Copy the data.
View Full Code Here

     *
     * @param w The width in pixels.
     * @param h The height in pixels
     */
    public SampleModel createCompatibleSampleModel(int w, int h) {
        SampleModel ret=null;
        long size;
        int minBandOff=bandOffsets[0];
        int maxBandOff=bandOffsets[0];
        for (int i=1; i<bandOffsets.length; i++) {
            minBandOff = Math.min(minBandOff,bandOffsets[i]);
View Full Code Here

        if (src == null) {
            throw
              new IllegalArgumentException("Null Source");
        }

        SampleModel srcSampleModel = src.getSampleModel();
        if (!isIntegralDataType(srcSampleModel)) {
            throw
              new IllegalArgumentException("Source Data Type must be an Integral Data Type");
        }

        // Validate rectangle.
        if (rect == null) {
            rect = src.getBounds();
        } else {
            rect = rect.intersection(src.getBounds());
        }

        if (dst != null) {
            rect = rect.intersection(dst.getBounds());
        }

        // Validate destination.
        SampleModel dstSampleModel;
        if (dst == null) {  // create dst according to table
            dstSampleModel = getDestSampleModel(srcSampleModel,
                                                rect.width, rect.height);
            dst =
                RasterFactory.createWritableRaster(dstSampleModel,
                                                   new Point(rect.x, rect.y));
        } else {
            dstSampleModel = dst.getSampleModel();

            if (dstSampleModel.getTransferType() != getDataType() ||
                dstSampleModel.getNumBands() !=
                getDestNumBands(srcSampleModel.getNumBands())) {
                throw new
                  IllegalArgumentException("Incompatible Destination Image");
            }
        }
View Full Code Here

        return Object.class;
    }

    public boolean canEncodeImage(RenderedImage im,
                                  ImageEncodeParam param) {
        SampleModel sampleModel = im.getSampleModel();

        int dataType = sampleModel.getTransferType();
        if (dataType == DataBuffer.TYPE_FLOAT  ||
            dataType == DataBuffer.TYPE_DOUBLE ||
            sampleModel.getNumBands() != 1     ||
            sampleModel.getSampleSize(0) != 1) {
            return false;
        }

        return true;
    }
View Full Code Here

        super(output, param);
    }

    public void encode(RenderedImage im) throws IOException {
        // Get the SampleModel.
        SampleModel sm = im.getSampleModel();

        // Check the data type, band count, and sample size.
        int dataType = sm.getTransferType();
        if (dataType == DataBuffer.TYPE_FLOAT ||
            dataType == DataBuffer.TYPE_DOUBLE) {
            throw new IllegalArgumentException(JaiI18N.getString("WBMPImageEncoder0"));
        } else if (sm.getNumBands() != 1) {
            throw new IllegalArgumentException(JaiI18N.getString("WBMPImageEncoder1"));
        } else if (sm.getSampleSize(0) != 1) {
            throw new IllegalArgumentException(JaiI18N.getString("WBMPImageEncoder2"));
        }

        // Save image dimensions.
        int width = im.getWidth();
        int height = im.getHeight();

        // Write WBMP header.
        output.write(0); // TypeField
        output.write(0); // FixHeaderField
        output.write(intToMultiByte(width)); // width
        output.write(intToMultiByte(height)); // height

        Raster tile = null;

        // If the data are not formatted nominally then reformat.
        if(sm.getDataType() != DataBuffer.TYPE_BYTE ||
           !(sm instanceof MultiPixelPackedSampleModel) ||
           ((MultiPixelPackedSampleModel)sm).getDataBitOffset() != 0) {
            MultiPixelPackedSampleModel mppsm =
                new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                width, height, 1,
View Full Code Here

        // Handle the special case of adding a single band image to
        // each band of a multi-band image.
        int numBandsDst;
        if (layout != null && layout.isValid(ImageLayout.SAMPLE_MODEL_MASK)) {
            SampleModel sm = layout.getSampleModel(null);
            numBandsDst = sm.getNumBands();

            // One of the sources must be single-banded and the other must
            // have at most the number of bands in the SampleModel hint.
            if (numBandsDst > 1 &&
                ((numBands1 == 1 && numBands2 > 1) ||
View Full Code Here

     *
     * @param src The <code>RenderedImage</code> to test.
     * @return Whether the image is byte-packed.
     */
    static final boolean isPackedByteImage(RenderedImage im) {
        SampleModel imageSampleModel = im.getSampleModel();

        if(imageSampleModel instanceof SinglePixelPackedSampleModel) {
            for(int i = 0; i < imageSampleModel.getNumBands(); i++) {
                if(imageSampleModel.getSampleSize(i) > 8) {
                    return false;
                }
            }

            return true;
View Full Code Here

    JaiI18N.getString("JPEGTileDecoder0") );
  return decode(null);
    }

    public Raster decode(Point location) throws IOException{
  SampleModel sm = null;
  byte[] data = null;

        ObjectInputStream ois = new ObjectInputStream(inputStream);

        try {
View Full Code Here

TOP

Related Classes of java.awt.image.SampleModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.