for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { raster.getPixel(x, y, samples); dst_raster.setPixel(x, y, samples);
if(dst_model instanceof DirectColorModel) if(model instanceof ComponentColorModel){ for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) dst_raster.setPixel(x, y, raster.getPixel(x, y, samples)); } else if(model instanceof IndexColorModel){ final IndexColorModel icm = (IndexColorModel) model; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++){ int sample = raster.getSample(x, y, 0); samples[0] = icm.getRed(sample); samples[1] = icm.getGreen(sample); samples[2] = icm.getBlue(sample); samples[3] = icm.getAlpha(sample); dst_raster.setPixel(x, y, samples); } } else { log.error("Unimplemented raster conversion"); return raster;
	private Raster createCompatibleRaster(Raster raster) {        //todo fix gif images (index color model?), optimize        final ColorModel dst_model = surface.getColorModel();        final int[] samples = new int[4];        final int w = raster.getWidth();        final int h = raster.getHeight();        final WritableRaster dst_raster = dst_model.createCompatibleWritableRaster(w, h);        for (int y = 0; y < h; y++) {            for (int x = 0; x < w; x++) {                raster.getPixel(x, y, samples);                dst_raster.setPixel(x, y, samples);            }        }		return dst_raster;	}