java.awt.image

Class RGBImageFilter

  • All Implemented Interfaces:
    ImageConsumer, Cloneable
    Direct Known Subclasses:
    GrayFilter

    public abstract class RGBImageFilter
    extends ImageFilter
    This class provides an easy way to create an ImageFilter which modifies the pixels of an image in the default RGB ColorModel. It is meant to be used in conjunction with a FilteredImageSource object to produce filtered versions of existing images. It is an abstract class that provides the calls needed to channel all of the pixel data through a single method which converts pixels one at a time in the default RGB ColorModel regardless of the ColorModel being used by the ImageProducer. The only method which needs to be defined to create a useable image filter is the filterRGB method. Here is an example of a definition of a filter which swaps the red and blue components of an image:
    
          class RedBlueSwapFilter extends RGBImageFilter {
              public RedBlueSwapFilter() {
                  // The filter's operation does not depend on the
                  // pixel's location, so IndexColorModels can be
                  // filtered directly.
                  canFilterIndexColorModel = true;
              }
    
              public int filterRGB(int x, int y, int rgb) {
                  return ((rgb & 0xff00ff00)
                          | ((rgb & 0xff0000) >> 16)
                          | ((rgb & 0xff) << 16));
              }
          }
    
     
    See Also:
    FilteredImageSource, ImageFilter, ColorModel.getRGBdefault()
    • Constructor Summary

      Constructors 
      Constructor and Description
      RGBImageFilter() 

        

    • Method Summary

      Methods 
      Modifier and Type Method and Description
      IndexColorModel filterIndexColorModel(IndexColorModel icm)
      Filters an IndexColorModel object by running each entry in its color tables through the filterRGB function that RGBImageFilter subclasses must provide.
      abstract int filterRGB(int x, int y, int rgb)
      Subclasses must specify a method to convert a single input pixel in the default RGB ColorModel to a single output pixel.
      void filterRGBPixels(int x, int y, int w, int h, int[] pixels, int off, int scansize)
      Filters a buffer of pixels in the default RGB ColorModel by passing them one by one through the filterRGB method.
      void setColorModel(ColorModel model)
      If the ColorModel is an IndexColorModel and the subclass has set the canFilterIndexColorModel flag to true, we substitute a filtered version of the color model here and wherever that original ColorModel object appears in the setPixels methods.
      void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize)
      If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel.
      void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize)
      If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel, otherwise converts the buffer of integer pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method to be converted one by one.
      void substituteColorModel(ColorModel oldcm, ColorModel newcm)
      Registers two ColorModel objects for substitution.

        

    • Field Detail

      • newmodel

        protected ColorModel newmodel
        The ColorModel with which to replace origmodel when the user calls substituteColorModel.
    • Constructor Detail

      • RGBImageFilter

        public RGBImageFilter()
    • Method Detail

      • setColorModel

        public void setColorModel(ColorModel model)
        If the ColorModel is an IndexColorModel and the subclass has set the canFilterIndexColorModel flag to true, we substitute a filtered version of the color model here and wherever that original ColorModel object appears in the setPixels methods. If the ColorModel is not an IndexColorModel or is null, this method overrides the default ColorModel used by the ImageProducer and specifies the default RGB ColorModel instead.

        Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being filtered. Developers using this class to filter pixels from an image should avoid calling this method directly since that operation could interfere with the filtering operation.

        Specified by:
        setColorModel in interface ImageConsumer
        Overrides:
        setColorModel in class ImageFilter
        Parameters:
        model - the specified ColorModel
        See Also:
        ImageConsumer, ColorModel.getRGBdefault()
      • substituteColorModel

        public void substituteColorModel(ColorModel oldcm,
                                ColorModel newcm)
        Registers two ColorModel objects for substitution. If the oldcm is encountered during any of the setPixels methods, the newcm is substituted and the pixels passed through untouched (but with the new ColorModel object).
        Parameters:
        oldcm - the ColorModel object to be replaced on the fly
        newcm - the ColorModel object to replace oldcm on the fly
      • filterIndexColorModel

        public IndexColorModel filterIndexColorModel(IndexColorModel icm)
        Filters an IndexColorModel object by running each entry in its color tables through the filterRGB function that RGBImageFilter subclasses must provide. Uses coordinates of -1 to indicate that a color table entry is being filtered rather than an actual pixel value.
        Parameters:
        icm - the IndexColorModel object to be filtered
        Returns:
        a new IndexColorModel representing the filtered colors
        Throws:
        NullPointerException - if icm is null
      • filterRGBPixels

        public void filterRGBPixels(int x,
                           int y,
                           int w,
                           int h,
                           int[] pixels,
                           int off,
                           int scansize)
        Filters a buffer of pixels in the default RGB ColorModel by passing them one by one through the filterRGB method.
        Parameters:
        x - the X coordinate of the upper-left corner of the region of pixels
        y - the Y coordinate of the upper-left corner of the region of pixels
        w - the width of the region of pixels
        h - the height of the region of pixels
        pixels - the array of pixels
        off - the offset into the pixels array
        scansize - the distance from one row of pixels to the next in the array
        See Also:
        ColorModel.getRGBdefault(), filterRGB(int, int, int)
      • setPixels

        public void setPixels(int x,
                     int y,
                     int w,
                     int h,
                     ColorModel model,
                     byte[] pixels,
                     int off,
                     int scansize)
        If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel. Otherwise converts the buffer of byte pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method to be converted one by one.

        Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being filtered. Developers using this class to filter pixels from an image should avoid calling this method directly since that operation could interfere with the filtering operation.

        Specified by:
        setPixels in interface ImageConsumer
        Overrides:
        setPixels in class ImageFilter
        Parameters:
        x - the X coordinate of the upper-left corner of the area of pixels to be set
        y - the Y coordinate of the upper-left corner of the area of pixels to be set
        w - the width of the area of pixels
        h - the height of the area of pixels
        model - the specified ColorModel
        pixels - the array of pixels
        off - the offset into the pixels array
        scansize - the distance from one row of pixels to the next in the pixels array
        See Also:
        ColorModel.getRGBdefault(), filterRGBPixels(int, int, int, int, int[], int, int)
      • setPixels

        public void setPixels(int x,
                     int y,
                     int w,
                     int h,
                     ColorModel model,
                     int[] pixels,
                     int off,
                     int scansize)
        If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel, otherwise converts the buffer of integer pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method to be converted one by one. Converts a buffer of integer pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method.

        Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being filtered. Developers using this class to filter pixels from an image should avoid calling this method directly since that operation could interfere with the filtering operation.

        Specified by:
        setPixels in interface ImageConsumer
        Overrides:
        setPixels in class ImageFilter
        Parameters:
        x - the X coordinate of the upper-left corner of the area of pixels to be set
        y - the Y coordinate of the upper-left corner of the area of pixels to be set
        w - the width of the area of pixels
        h - the height of the area of pixels
        model - the specified ColorModel
        pixels - the array of pixels
        off - the offset into the pixels array
        scansize - the distance from one row of pixels to the next in the pixels array
        See Also:
        ColorModel.getRGBdefault(), filterRGBPixels(int, int, int, int, int[], int, int)
      • filterRGB

        public abstract int filterRGB(int x,
                    int y,
                    int rgb)
        Subclasses must specify a method to convert a single input pixel in the default RGB ColorModel to a single output pixel.
        Parameters:
        x - the X coordinate of the pixel
        y - the Y coordinate of the pixel
        rgb - the integer pixel representation in the default RGB color model
        Returns:
        a filtered pixel in the default RGB color model.
        See Also:
        ColorModel.getRGBdefault(), filterRGBPixels(int, int, int, int, int[], int, int)

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

22/12/2024 14:00:56 Cette version de la page est en cache (à la date du 22/12/2024 14:00:56) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.

Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/awt/image/rgbimagefilter.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, RGBImageFilter

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut