int transparencyDepth) {
if (data == null)
return null;
if (transparencyDepth == 1)
return data.getTransparencyMask();
ImageData mask = null;
if (data.maskData != null && data.depth == 32) {
ImageData m = data.getTransparencyMask();
mask = new ImageData(data.width, data.height, 8, ALPHA_PALETTE,
data.width, new byte[data.width * data.height]);
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
int alpha = data.getPixel(x, y) & 0xFF;
if (alpha == 0) {
if (m.getPixel(x, y) != 0)
alpha = 255;
}
mask.setPixel(x, y, alpha);
}
}
} else if (data.maskData != null || data.transparentPixel != -1) {
ImageData m = data.getTransparencyMask();
mask = new ImageData(data.width, data.height, 8, ALPHA_PALETTE,
data.width, new byte[data.width * data.height]);
for (int y = 0; y < mask.height; y++) {
for (int x = 0; x < mask.width; x++) {
mask.setPixel(x, y, m.getPixel(x, y) != 0 ? (byte) 255 : 0);
}
}
} else if (data.alpha != -1) {
mask = new ImageData(data.width, data.height, 8, ALPHA_PALETTE,
data.width, new byte[data.width * data.height]);
for (int i = 0; i < mask.data.length; i++) {
mask.data[i] = (byte) data.alpha;
}
} else if (data.alphaData != null) {
mask = new ImageData(data.width, data.height, 8, ALPHA_PALETTE,
data.width, data.alphaData);
} else {
mask = new ImageData(data.width, data.height, 8, ALPHA_PALETTE,
data.width, new byte[data.width * data.height]);
for (int i = 0; i < mask.data.length; i++) {
mask.data[i] = (byte) 255;
}
}