Package java.awt.image

Examples of java.awt.image.SampleModel


        Rectangle bounds;
        if (dest == null) {
            // Create a WritableRaster for the entire image.
            bounds = imageBounds;
            Point p = new Point(minX, minY);
            SampleModel sm =
                sampleModel.createCompatibleSampleModel(width, height);
            dest = RasterFactory.createWritableRaster(sm, p);
        } else {
            bounds = dest.getBounds();
        }
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

        return com.lightcrafts.media.jai.codec.PNGDecodeParam.class;
    }

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

        // PNG doesn't handle float or double pixels
        int dataType = sampleModel.getTransferType();
        if ((dataType == DataBuffer.TYPE_FLOAT) ||
            (dataType == DataBuffer.TYPE_DOUBLE)) {
            return false;
        }

        int[] sampleSize = sampleModel.getSampleSize();
        int bitDepth = sampleSize[0];

        // Ensure all channels have the same bit depth
        for (int i = 1; i < sampleSize.length; i++) {
            if (sampleSize[i] != bitDepth) {
                return false;
            }
        }

        // Bit depth must be between 1 and 16
        if (bitDepth < 1 || bitDepth > 16) {
            return false;
        }

        // Number of bands must be between 1 and 4
        int numBands = sampleModel.getNumBands();
        if (numBands < 1 || numBands > 4) {
            return false;
        }

        // Palette images must be 1-banded, depth 8 or less
View Full Code Here

                                                int width, int height,
                                                int tileX, int tileY,
                                                int tileWidth, int tileHeight,
                                                int dataType, int numBands,
                                                boolean isBanded) {
        SampleModel sampleModel;
        if (isBanded) {
            sampleModel = RasterFactory.createBandedSampleModel(
                          dataType, tileWidth, tileHeight, numBands);
        } else {
            sampleModel = RasterFactory.createPixelInterleavedSampleModel(
View Full Code Here

        long total = benchmarkOpImage(img,loops);

        int w = img.getWidth();
        int h = img.getHeight();
        SampleModel sm = img.getSampleModel();

        double time = (total)/1000.0;
        int width = img.getWidth();
        int height = img.getHeight();
        System.out.print("\tLoops : " + loops);
View Full Code Here

      throw new IllegalArgumentException(
    JaiI18N.getString("TileEncoder1")) ;

  ByteArrayOutputStream baos = new ByteArrayOutputStream() ;

  SampleModel sm = ras.getSampleModel() ;

  JPEGEncodeParam j2dEP = convertToJ2DJPEGEncodeParam(paramList, sm) ;
        ((JPEGParam)j2dEP).setWidth(ras.getWidth()) ;
  ((JPEGParam)j2dEP).setHeight(ras.getHeight()) ;
View Full Code Here

                                          int tileWidth,
                                          int tileHeight,
                                          int pixelStride,
                                          int scanlineStride,
                                          int bandOffsets[]) {
        SampleModel sampleModel = null;

        if(dataType == DataBuffer.TYPE_FLOAT) {
            // This is a hack to make this work with JAI which in some
            // cases downcasts the DataBuffer to a type-specific class.
            // In the case of float data this current means the JAI class
View Full Code Here

        if (src == null) {
            throw
        new IllegalArgumentException(JaiI18N.getString("LookupTableJAI1"));
        }

        SampleModel srcSampleModel = src.getSampleModel();
        if (!isIntegralDataType(srcSampleModel)) {
            throw
        new IllegalArgumentException(JaiI18N.getString("LookupTableJAI2"));
        }

        // 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(JaiI18N.getString("LookupTableJAI3"));
            }
        }
View Full Code Here

     * @return Whether the color map is valid.
     */
    private static boolean isValidColorMap(RenderedImage sourceImage,
                                           ColorCube colorMap,
                                           StringBuffer msg) {
        SampleModel srcSampleModel = sourceImage.getSampleModel();

        if(colorMap.getDataType() != srcSampleModel.getTransferType()) {
            msg.append(JaiI18N.getString("OrderedDitherDescriptor3"));
            return false;
        } else if (colorMap.getNumBands() != srcSampleModel.getNumBands()) {
            msg.append(JaiI18N.getString("OrderedDitherDescriptor4"));
            return false;
        }

        return true;
View Full Code Here

        il.setMinY(source.getMinY());
        il.setWidth(source.getWidth());
        il.setHeight(source.getHeight());

        // Get the SampleModel.
        SampleModel sm = il.getSampleModel(source);

        // Ensure an appropriate SampleModel.
        if(colormap.getNumBands() == 1 &&
           colormap.getNumEntries() == 2 &&
           !ImageUtil.isBinary(il.getSampleModel(source))) {
            sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                 il.getTileWidth(source),
                                                 il.getTileHeight(source),
                                                 1);
            il.setSampleModel(sm);
        }

        // Make sure that this OpImage is single-banded.
        if (sm.getNumBands() != 1) {
            sm =
                RasterFactory.createComponentSampleModel(sm,
                                                         sm.getTransferType(),
                                                         sm.getWidth(),
                                                         sm.getHeight(),
                                                         1);
      il.setSampleModel(sm);

            // Clear the ColorModel mask if needed.
            ColorModel cm = il.getColorModel(null);
            if(cm != null &&
               !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
                // Clear the mask bit if incompatible.
                il.unsetValid(ImageLayout.COLOR_MODEL_MASK);
            }
        }

        // Set an IndexColorModel on the image if:
        // a. none is provided in the layout;
        // b. source, destination, and colormap have byte data type;
        // c. the colormap has 3 bands.
        if((layout == null || !il.isValid(ImageLayout.COLOR_MODEL_MASK)) &&
           source.getSampleModel().getDataType() == DataBuffer.TYPE_BYTE &&
           sm.getDataType() == DataBuffer.TYPE_BYTE &&
           colormap.getDataType() == DataBuffer.TYPE_BYTE &&
           colormap.getNumBands() == 3) {
            ColorModel cm = source.getColorModel();
            if(cm == null ||
               (cm != null && cm.getColorSpace().isCS_sRGB())) {
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.