| Method from java.awt.image.RGBImageFilter Detail: |
public IndexColorModel filterIndexColorModel(IndexColorModel icm) {
int mapsize = icm.getMapSize();
byte r[] = new byte[mapsize];
byte g[] = new byte[mapsize];
byte b[] = new byte[mapsize];
byte a[] = new byte[mapsize];
icm.getReds(r);
icm.getGreens(g);
icm.getBlues(b);
icm.getAlphas(a);
int trans = icm.getTransparentPixel();
boolean needalpha = false;
for (int i = 0; i < mapsize; i++) {
int rgb = filterRGB(-1, -1, icm.getRGB(i));
a[i] = (byte) (rgb > > 24);
if (a[i] != ((byte)0xff) && i != trans) {
needalpha = true;
}
r[i] = (byte) (rgb > > 16);
g[i] = (byte) (rgb > > 8);
b[i] = (byte) (rgb > > 0);
}
if (needalpha) {
return new IndexColorModel(icm.getPixelSize(), mapsize,
r, g, b, a);
} else {
return new IndexColorModel(icm.getPixelSize(), mapsize,
r, g, b, trans);
}
}
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. |
abstract public 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. |
public void filterRGBPixels(int x,
int y,
int w,
int h,
int[] pixels,
int off,
int scansize) {
int index = off;
for (int cy = 0; cy < h; cy++) {
for (int cx = 0; cx < w; cx++) {
pixels[index] = filterRGB(x + cx, y + cy, pixels[index]);
index++;
}
index += scansize - w;
}
consumer.setPixels(x, y, w, h, ColorModel.getRGBdefault(),
pixels, off, scansize);
}
Filters a buffer of pixels in the default RGB ColorModel by passing
them one by one through the filterRGB method. |
public void setColorModel(ColorModel model) {
if (canFilterIndexColorModel && (model instanceof IndexColorModel)) {
ColorModel newcm = filterIndexColorModel((IndexColorModel)model);
substituteColorModel(model, newcm);
consumer.setColorModel(newcm);
} else {
consumer.setColorModel(ColorModel.getRGBdefault());
}
}
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. |
public void setPixels(int x,
int y,
int w,
int h,
ColorModel model,
byte[] pixels,
int off,
int scansize) {
if (model == origmodel) {
consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
} else {
int filteredpixels[] = new int[w];
int index = off;
for (int cy = 0; cy < h; cy++) {
for (int cx = 0; cx < w; cx++) {
filteredpixels[cx] = model.getRGB((pixels[index] & 0xff));
index++;
}
index += scansize - w;
filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
}
}
}
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. |
public void setPixels(int x,
int y,
int w,
int h,
ColorModel model,
int[] pixels,
int off,
int scansize) {
if (model == origmodel) {
consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
} else {
int filteredpixels[] = new int[w];
int index = off;
for (int cy = 0; cy < h; cy++) {
for (int cx = 0; cx < w; cx++) {
filteredpixels[cx] = model.getRGB(pixels[index]);
index++;
}
index += scansize - w;
filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
}
}
}
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. |
public void substituteColorModel(ColorModel oldcm,
ColorModel newcm) {
origmodel = oldcm;
newmodel = 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). |