Package java.awt.image

Examples of java.awt.image.ColorModel


                                                          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; and
        // d. the source ColorModel is either null or is non-null
        //    and has a ColorSpace equal to CS_sRGB.
        if((layout == null || !il.isValid(ImageLayout.COLOR_MODEL_MASK)) &&
           source.getSampleModel().getDataType() == DataBuffer.TYPE_BYTE &&
           il.getSampleModel(null).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())) {
                int size = colorMap.getNumEntries();
                byte[][] cmap = new byte[3][256];
                for(int i = 0; i < 3; i++) {
                    byte[] band = cmap[i];
                    byte[] data = colorMap.getByteData(i);
View Full Code Here


                // 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(
                  srcSM.getDataType(),
                  srcSM.getWidth(),
View Full Code Here

        if(config != null &&
           config.containsKey(JAI.KEY_COLOR_MODEL_FACTORY)) {
            ColorModelFactory cmf =
                (ColorModelFactory)config.get(JAI.KEY_COLOR_MODEL_FACTORY);
            ColorModel cm = cmf.createColorModel(sampleModel,
                                                 sources,
                                                 config);
            if(cm != null &&
               JDKWorkarounds.areCompatibleDataModels(sampleModel, cm)) {
                layout.setColorModel(cm);
View Full Code Here

                                                 layout.getTileHeight(source),
                                                 1);
            layout.setSampleModel(sm);
        }

        ColorModel cm = layout.getColorModel(null);
        if(cm == null ||
           !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
            layout.setColorModel(ImageUtil.getCompatibleColorModel(sm,
                                                                   config));
        }
View Full Code Here

                                                          newHeight,
                                                          numBands);
            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);
            }
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
View Full Code Here

         * If the source has IndexColorModel, override the default setting
         * in OpImage. The dest shall have exactly the same SampleModel and
         * ColorModel as the source.
         * Note, in this case, the source should have an integral data type.
         */
        ColorModel srcColorModel = source.getColorModel();
        if (srcColorModel instanceof IndexColorModel) {
             sampleModel = source.getSampleModel().createCompatibleSampleModel(
                                                   tileWidth, tileHeight);
             colorModel = srcColorModel;
        }
View Full Code Here

        /*
         * If the source has IndexColorModel, get the RGB color table.
         * Note, in this case, the source should have an integral data type.
         * And dest always has data type byte.
         */
        ColorModel srcColorModel = source.getColorModel();
        if (srcColorModel instanceof IndexColorModel) {
            IndexColorModel icm = (IndexColorModel)srcColorModel;
            ctable = new byte[3][icm.getMapSize()];
            icm.getReds(ctable[0]);
            icm.getGreens(ctable[1]);
View Full Code Here

             new int[] {0});
  }

        layout.setSampleModel(sm);

  ColorModel cm = layout.getColorModel(null);

        if(cm == null ||
           !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {

            layout.setColorModel(ImageUtil.getCompatibleColorModel(sm,
View Full Code Here

                                                          sm.getNumBands());

            il.setSampleModel(sm);

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

TOP

Related Classes of java.awt.image.ColorModel

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.