- java.lang.Object
-
- java.awt.image.ImageFilter
-
- java.awt.image.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)); } }
-
-
Field Summary
Fields Modifier and Type Field and Description protected boolean
canFilterIndexColorModel
This boolean indicates whether or not it is acceptable to apply the color filtering of the filterRGB method to the color table entries of an IndexColorModel object in lieu of pixel by pixel filtering.protected ColorModel
newmodel
TheColorModel
with which to replaceorigmodel
when the user callssubstituteColorModel
.protected ColorModel
origmodel
-
Fields inherited from class java.awt.image.ImageFilter
consumer
-
Fields inherited from interface java.awt.image.ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
-
-
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.-
Methods inherited from class java.awt.image.ImageFilter
clone, getFilterInstance, imageComplete, resendTopDownLeftRight, setDimensions, setHints, setProperties
-
-
-
-
Field Detail
-
origmodel
protected ColorModel origmodel
-
newmodel
protected ColorModel newmodel
TheColorModel
with which to replaceorigmodel
when the user callssubstituteColorModel
.
-
canFilterIndexColorModel
protected boolean canFilterIndexColorModel
This boolean indicates whether or not it is acceptable to apply the color filtering of the filterRGB method to the color table entries of an IndexColorModel object in lieu of pixel by pixel filtering. Subclasses should set this variable to true in their constructor if their filterRGB method does not depend on the coordinate of the pixel being filtered.
-
-
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 theImage
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 interfaceImageConsumer
- Overrides:
setColorModel
in classImageFilter
- Parameters:
model
- the specifiedColorModel
- 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 flynewcm
- 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
- ificm
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 pixelsy
- the Y coordinate of the upper-left corner of the region of pixelsw
- the width of the region of pixelsh
- the height of the region of pixelspixels
- the array of pixelsoff
- the offset into thepixels
arrayscansize
- 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 theImage
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 interfaceImageConsumer
- Overrides:
setPixels
in classImageFilter
- Parameters:
x
- the X coordinate of the upper-left corner of the area of pixels to be sety
- the Y coordinate of the upper-left corner of the area of pixels to be setw
- the width of the area of pixelsh
- the height of the area of pixelsmodel
- the specifiedColorModel
pixels
- the array of pixelsoff
- the offset into thepixels
arrayscansize
- the distance from one row of pixels to the next in thepixels
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 theImage
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 interfaceImageConsumer
- Overrides:
setPixels
in classImageFilter
- Parameters:
x
- the X coordinate of the upper-left corner of the area of pixels to be sety
- the Y coordinate of the upper-left corner of the area of pixels to be setw
- the width of the area of pixelsh
- the height of the area of pixelsmodel
- the specifiedColorModel
pixels
- the array of pixelsoff
- the offset into thepixels
arrayscansize
- the distance from one row of pixels to the next in thepixels
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 pixely
- the Y coordinate of the pixelrgb
- 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)
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/image/RGBImageFilter.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.