}
int w = raster.getWidth();
int h = raster.getHeight();
WritableRaster distRaster = model.createCompatibleWritableRaster(w, h);
int minX = raster.getMinX();
int minY = raster.getMinY();
Object obj = null;
int pixels[] = null;
for (int i = 0; i < h; i++, minY++) {
obj = raster.getDataElements(minX, minY, w, 1, obj);
if (obj instanceof byte[]) {
byte ba[] = (byte[]) obj;
if (pixels == null) {
pixels = new int[ba.length];
}
for (int j = 0; j < ba.length; j++) {
pixels[j] = colorMap[ba[j] & 0xff];
}
} else if (obj instanceof short[]) {
short sa[] = (short[]) obj;
if (pixels == null) {
pixels = new int[sa.length];
}
for (int j = 0; j < sa.length; j++) {
pixels[j] = colorMap[sa[j] & 0xffff];
}
}
if (obj instanceof int[]) {
int ia[] = (int[]) obj;
if (pixels == null) {
pixels = new int[ia.length];
}
for (int j = 0; j < ia.length; j++) {
pixels[j] = colorMap[ia[j]];
}
}
distRaster.setDataElements(0, i, w, 1, pixels);
}
return new BufferedImage(model, distRaster, false, null);
}