Package java.awt.image

Examples of java.awt.image.SampleModel


        // Create the alpha accessors.
        RasterAccessor[] a = new RasterAccessor[numSources];
        if(alphaRaster != null) {
            for(int i = 0; i < numSources; i++) {
                if(alphaRaster[i] != null) {
                    SampleModel alphaSM = alphaRaster[i].getSampleModel();
                    int alphaFormatTagID =
                        RasterAccessor.findCompatibleTag(null, alphaSM);
                    RasterFormatTag alphaFormatTag =
                        new RasterFormatTag(alphaSM, alphaFormatTagID);
                    a[i] = new RasterAccessor(alphaRaster[i], destRect, 
View Full Code Here


        if (bounds == null) {
            bounds = new Rectangle(im.getMinX(), im.getMinY(),
                                   im.getWidth(), im.getHeight());
        }

        SampleModel sm = im.getSampleModel();
        if (sm instanceof ComponentSampleModel) {
            switch (sm.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                return new RectIterCSMByte(im, bounds);
            case DataBuffer.TYPE_SHORT:
                // return new RectIterCSMShort(im, bounds);
    break;
View Full Code Here

        if (bounds == null) {
            bounds = new Rectangle(im.getMinX(), im.getMinY(),
                                   im.getWidth(), im.getHeight());
        }

        SampleModel sm = im.getSampleModel();
        if (sm instanceof ComponentSampleModel) {
            switch (sm.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                return new WritableRectIterCSMByte(im, bounds);
            case DataBuffer.TYPE_SHORT:
                // return new WritableRectIterCSMShort(im, bounds);
    break;
View Full Code Here

        // Initialize the SampleModel creation flag.
        boolean createNewSampleModel = false;

        // Determine the number of required bands.
        SampleModel srcSampleModel = source.getSampleModel();
        int requiredNumBands = srcSampleModel.getNumBands();
        if(isComplexSource && !isComplexDest) {
            requiredNumBands /= 2;
        } else if(!isComplexSource && isComplexDest) {
            requiredNumBands *= 2;
        }

        // Set the number of bands.
        SampleModel sm = il.getSampleModel(source);
        int numBands = sm.getNumBands();
        if(numBands != requiredNumBands) {
            numBands = requiredNumBands;
            createNewSampleModel = true;
        }

        // Force the image to contain floating point data.
        int dataType = sm.getTransferType();
        if(dataType != DataBuffer.TYPE_FLOAT &&
           dataType != DataBuffer.TYPE_DOUBLE) {
            dataType = DataBuffer.TYPE_FLOAT;
            createNewSampleModel = true;
        }
View Full Code Here

        KernelJAI unRotatedKernel =
            (KernelJAI)paramBlock.getObjectParameter(0);
        KernelJAI kJAI = unRotatedKernel.getRotatedKernel();

  RenderedImage source = paramBlock.getRenderedSource(0);
  SampleModel sm = source.getSampleModel();

  // check dataType and binary
        int dataType = sm.getDataType();

        boolean isBinary = (sm instanceof MultiPixelPackedSampleModel) &&
            (sm.getSampleSize(0) == 1) &&
            (dataType == DataBuffer.TYPE_BYTE ||
             dataType == DataBuffer.TYPE_USHORT ||
             dataType == DataBuffer.TYPE_INT);

  // possible speed up later: 3x3 with table lookup
View Full Code Here

        } else {
            il = (ImageLayout)layout.clone();
        }

        // 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) {
            // TODO: Force to SHORT or USHORT if FLOAT or DOUBLE?
            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);
View Full Code Here

            } else if(il.getSampleModel(null) != null) {

                // Target SampleModel is available.

                // Get SampleModel from "il"; guaranteed to be non-null.
                SampleModel sm = il.getSampleModel(null);

                // Get ColorModel from "layout".
                ColorModel cmLayout = layout.getColorModel(null);

                // First attempt to set the ColorModel to that specified
                // in the original layout, if any.
                if(cmLayout != null) {
                    // ColorModel is set in original layout.
                    if(JDKWorkarounds.areCompatibleDataModels(sm, cmLayout)) {
                        // ColorModel is compatible with target SampleModel.
                        il.setColorModel(cmLayout);

                    } else if(layout.getSampleModel(null) == null) {
                        // SampleModel not set in original layout so
                        // ColorModel must be incompatible with source
                        // SampleModel: create a compatible SampleModel.

                        // Set the ColorModel to that desired.
                        il.setColorModel(cmLayout);

                        // Derive a new SampleModel from the desired ColorModel
                        SampleModel derivedSM =
                            cmLayout.createCompatibleSampleModel(
                                il.getTileWidth(null),
                                il.getTileHeight(null));

                        // Set the SampleModel to that derived from the CM.
                        il.setSampleModel(derivedSM);

                    }
                }

                // If ColorModel not set from ImageLayout, attempt to set
                // using a ColorModelFactory and if that fails, attempt to
                // use the ColorModel of the source.
                if(!il.isValid(ImageLayout.COLOR_MODEL_MASK) &&
                   !setColorModelFromFactory(sm, sources, config, il)) {
                    // Get ColorModel from "im", i.e., the source.
                    ColorModel cmSource = im.getColorModel();
                    if(cmSource != null &&
                       JDKWorkarounds.areCompatibleDataModels(sm, cmSource)) {
                        // Set to source ColorModel.
      if (cmSource != null &&
          cmSource instanceof IndexColorModel &&
          config != null &&
          config.containsKey(
           JAI.KEY_REPLACE_INDEX_COLOR_MODEL) &&
          ((Boolean)config.get(JAI.KEY_REPLACE_INDEX_COLOR_MODEL)).booleanValue()) {
         
          ColorModel newCM =
        PlanarImage.getDefaultColorModel(
              sm.getDataType(),
              cmSource.getNumComponents());

          SampleModel newSM;
          if (newCM != null) {
        newSM =
            newCM.createCompatibleSampleModel(
                   il.getTileWidth(null),
                   il.getTileHeight(null));
          } else {
        newSM =
            RasterFactory.createPixelInterleavedSampleModel(
              sm.getDataType(),
              il.getTileWidth(null),
              il.getTileHeight(null),
              cmSource.getNumComponents());
          }

          il.setSampleModel(newSM);         
          if (newCM != null)
        il.setColorModel(newCM);
      } else {
          il.setColorModel(cmSource);
      }
                    }
                }
            } else if(il.getSampleModel(null) == null) { // null SampleModel
                // Set to whatever is available.
                il.setColorModel(layout.getColorModel(im));
            }
            // end of block if(im != null)
        } else if(il != null) {
            // Can only get here if im == null && layout != null.
            // Make sure that il is a clone of layout.
            il = (ImageLayout)layout.clone();

            // If the ColorModel is set but the SampleModel is not,
            // derive a SampleModel from the ColorModel.
            if(il.getColorModel(null) != null &&
               il.getSampleModel(null) == null) {
                // Set SampleModel dimensions.
                int smWidth = il.getTileWidth(null);
                if(smWidth == 0) {
                    smWidth = 512;
                }
                int smHeight = il.getTileHeight(null);
                if(smHeight == 0) {
                    smHeight = 512;
                }

                // Derive a new SampleModel from the desired ColorModel
                SampleModel derivedSM =
                    il.getColorModel(null).createCompatibleSampleModel(smWidth,
                                                                       smHeight);

                // Set the SampleModel to that derived from the CM.
                il.setSampleModel(derivedSM);
            }
        } // end of block if(il != null)

        // If no ColorModel is set, then first attempt to set a ColorModel
        // using the ColorModelFactory; otherwise set a default ColorModel
        // if either the configuration mapping is null, it does not contain
        // a mapping of the key KEY_DEFAULT_COLOR_MODEL_ENABLED, or this key
        // is mapped to Boolean.TRUE.
        if(il != null &&
           !il.isValid(ImageLayout.COLOR_MODEL_MASK) &&
           il.getSampleModel(null) != null &&
           !setColorModelFromFactory(il.getSampleModel(null),
                                     sources, config, il)) {

      ColorModel cm = null;
      SampleModel srcSM = il.getSampleModel(null);
     
      // If it is not a byte image, then probably all the above did not
      // manage to set a ColorModel and ImageUtil.getCompatibleColorModel
      // will be used to get the ColorModel. However we want to ensure
      // that the destination ColorModel is expanded if the ColorModel
      // of the source is an IndexColorModel and we've been asked to
      // do IndexColorModel expansion
      if (im != null &&
    im.getColorModel() != null &&
    im.getColorModel() instanceof IndexColorModel &&
    config != null &&
    config.containsKey(JAI.KEY_REPLACE_INDEX_COLOR_MODEL) &&
    ((Boolean)config.get(JAI.KEY_REPLACE_INDEX_COLOR_MODEL)).booleanValue()) {

    IndexColorModel icm = (IndexColorModel)im.getColorModel();

    // We need to change the ColorModel to a non IndexColorModel
    // so that operations such as geometric can take place
    // correctly. If the ColorModel is changed the SampleModel
    // needs to be changed too, so that they are compatible
    cm = PlanarImage.getDefaultColorModel(srcSM.getDataType(),
                  icm.getNumComponents());
   
    SampleModel newSM;
    if (cm != null) {
        newSM = cm.createCompatibleSampleModel(srcSM.getWidth(),
                 srcSM.getHeight());
    } else {
        newSM = RasterFactory.createPixelInterleavedSampleModel(
View Full Code Here

                                            Map config) {

        ImageLayout layout = (il == null) ?
            new ImageLayout() : (ImageLayout)il.clone();

        SampleModel sm = layout.getSampleModel(source);
        if(!ImageUtil.isBinary(sm)) {
            sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                 layout.getTileWidth(source),
                                                 layout.getTileHeight(source),
                                                 1);
View Full Code Here

            tr.setTransform(1.0, shear_amt, 0.0, 1.0, 0.0, yTrans);
        }

        // Do Affine
        if (interp instanceof InterpolationNearest) {
            SampleModel sm = source.getSampleModel();
            boolean isBinary = (sm instanceof MultiPixelPackedSampleModel) &&
                (sm.getSampleSize(0) == 1) &&
                (sm.getDataType() == DataBuffer.TYPE_BYTE ||
                 sm.getDataType() == DataBuffer.TYPE_USHORT ||
                 sm.getDataType() == DataBuffer.TYPE_INT);
            if(isBinary) {
                return new AffineNearestBinaryOpImage(source,
                                                      extender,
                                                      renderHints,
                                                      layout,
View Full Code Here

        this.source1Alpha = source1Alpha;
        this.source2Alpha = source2Alpha;
        this.alphaPremultiplied = alphaPremultiplied;

        SampleModel sm = source1.getSampleModel();
        ColorModel cm = source1.getColorModel();
        int dtype = sm.getTransferType();
        int bands;
        if (cm instanceof IndexColorModel) {
            bands = cm.getNumComponents();
        } else {
            bands = sm.getNumBands();
        }
        bands += 1;                             // one additional alpha channel

        if (sampleModel.getTransferType() != dtype ||
            sampleModel.getNumBands() != bands) {
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.