*/
static Image compositeImage(Device device, ImageData base,
ImageData[] overlay) {
if (base == null)
return null;
Image image = new Image(device, new ImageData(base.width, base.height,
24, new PaletteData(0xff, 0xff00, 0xff00000)));
GC gc = new GC(image);
ImageData src;
int maskDepth = 0, baseMaskDepth = 0;
ImageData underlay = src = overlay.length > UNDERLAY ? overlay[UNDERLAY]
: null;
if (src != null) {
maskDepth = Math.max(maskDepth, getTransparencyDepth(src));
Image img = new Image(device, src);
gc.drawImage(img, 0, 0);
img.dispose();
}
src = base;
if (base != null) {
maskDepth = Math.max(maskDepth,
baseMaskDepth = getTransparencyDepth(src));
Image img = new Image(device, src);
gc.drawImage(img, 0, 0);
img.dispose();
}
ImageData topLeft = src = overlay[TOP_LEFT];
if (src != null) {
maskDepth = Math.max(maskDepth, getTransparencyDepth(src));
Image img = new Image(device, src);
gc.drawImage(img, 0, 0);
img.dispose();
}
ImageData topRight = src = overlay[TOP_RIGHT];
if (src != null) {
maskDepth = Math.max(maskDepth, getTransparencyDepth(src));
Image img = new Image(device, src);
gc.drawImage(img, base.width - src.width, 0);
img.dispose();
}
ImageData bottomLeft = src = overlay[BOTTOM_LEFT];
if (src != null) {
maskDepth = Math.max(maskDepth, getTransparencyDepth(src));
Image img = new Image(device, src);
gc.drawImage(img, 0, base.height - src.height);
img.dispose();
}
ImageData bottomRight = src = overlay[BOTTOM_RIGHT];
if (src != null) {
maskDepth = Math.max(maskDepth, getTransparencyDepth(src));
Image img = new Image(device, src);
gc.drawImage(img, base.width - src.width, base.height - src.height);
img.dispose();
}
gc.dispose();
if (baseMaskDepth > 0) {
ImageData newData = image.getImageData();
image.dispose();
ImageData mask = null;
switch (maskDepth) {
case 1:
mask = new ImageData(base.width, base.height, maskDepth,
BW_PALETTE);
break;
case 8:
mask = new ImageData(base.width, base.height, maskDepth,
ALPHA_PALETTE, base.width, new byte[base.width
* base.height]);
break;
}
src = getTransparency(underlay, maskDepth);