RGBImageFilterpublic abstract class RGBImageFilter extends ImageFilter The RGBImageFilter class represents a filter which modifies pixels of an
image in the default RGB ColorModel. |
Fields Summary |
---|
protected ColorModel | origmodelThe original model is the ColorModel to be replaced by the new model when
substituteColorModel is called. | protected ColorModel | newmodelThe new model is the ColorModel with which to replace the original model
when substituteColorModel is called. | protected boolean | canFilterIndexColorModelThe canFilterIndexColorModel indicates if it is acceptable to apply the
color filtering of the filterRGB method to the color table entries of an
IndexColorModel object. |
Constructors Summary |
---|
public RGBImageFilter()Instantiates a new RGBImageFilter.
|
Methods Summary |
---|
public java.awt.image.IndexColorModel | filterIndexColorModel(java.awt.image.IndexColorModel icm)Filters an IndexColorModel object by calling filterRGB function for each
entry of IndexColorModel.
int transferType = icm.getTransferType();
int bits = icm.getPixelSize();
int mapSize = icm.getMapSize();
int colorMap[] = new int[mapSize];
int filteredColorMap[] = new int[mapSize];
icm.getRGBs(colorMap);
int trans = -1;
boolean hasAlpha = false;
for (int i = 0; i < mapSize; i++) {
filteredColorMap[i] = filterRGB(-1, -1, colorMap[i]);
int alpha = filteredColorMap[i] >>> 24;
if (alpha != 0xff) {
if (!hasAlpha) {
hasAlpha = true;
}
if (alpha == 0 && trans < 0) {
trans = i;
}
}
}
return new IndexColorModel(bits, mapSize, filteredColorMap, 0, hasAlpha, trans,
transferType);
| public abstract int | filterRGB(int x, int y, int rgb)Converts a single input pixel in the default RGB ColorModel to a single
output pixel.
| public void | filterRGBPixels(int x, int y, int w, int h, int[] pixels, int off, int scansize)Filters a region of pixels in the default RGB ColorModel by calling the
filterRGB method for them.
for (int sy = y, lineOff = off; sy < y + h; sy++, lineOff += scansize) {
for (int sx = x, idx = 0; sx < x + w; sx++, idx++) {
pixels[lineOff + idx] = filterRGB(sx, sy, pixels[lineOff + idx]);
}
}
consumer.setPixels(x, y, w, h, ColorModel.getRGBdefault(), pixels, off, scansize);
| public void | setColorModel(java.awt.image.ColorModel model)
if (model instanceof IndexColorModel && canFilterIndexColorModel) {
IndexColorModel icm = (IndexColorModel)model;
ColorModel filteredModel = filterIndexColorModel(icm);
substituteColorModel(model, filteredModel);
consumer.setColorModel(filteredModel);
} else {
consumer.setColorModel(ColorModel.getRGBdefault());
}
| public void | setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, int[] pixels, int off, int scansize)
if (model == null || model == origmodel) {
consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
} else {
int rgbPixels[] = new int[w];
for (int sy = y, pixelsOff = off; sy < y + h; sy++, pixelsOff += scansize) {
for (int sx = x, idx = 0; sx < x + w; sx++, idx++) {
rgbPixels[idx] = model.getRGB(pixels[pixelsOff + idx]);
}
filterRGBPixels(x, sy, w, 1, rgbPixels, 0, w);
}
}
| public void | setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, byte[] pixels, int off, int scansize)
if (model == null || model == origmodel) {
consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
} else {
int rgbPixels[] = new int[w];
for (int sy = y, pixelsOff = off; sy < y + h; sy++, pixelsOff += scansize) {
for (int sx = x, idx = 0; sx < x + w; sx++, idx++) {
rgbPixels[idx] = model.getRGB(pixels[pixelsOff + idx] & 0xff);
}
filterRGBPixels(x, sy, w, 1, rgbPixels, 0, w);
}
}
| public void | substituteColorModel(java.awt.image.ColorModel oldcm, java.awt.image.ColorModel newcm)Replaces the original color model and the new one.
origmodel = oldcm;
newmodel = newcm;
|
|