public static Image createColorImageFromLuminance8(final Image lumImage, final boolean useAlpha,
final ReadOnlyColorRGBA... colorTable) {
assert (colorTable.length == 256) : "color table must be size 256.";
final List<ByteBuffer> dataList = new ArrayList<ByteBuffer>(lumImage.getDepth());
ReadOnlyColorRGBA c;
for (int i = 0; i < lumImage.getDepth(); i++) {
final ByteBuffer src = lumImage.getData(i);
final int size = src.capacity();
final ByteBuffer out = BufferUtils.createByteBuffer(size * (useAlpha ? 4 : 3));
final byte[] data = new byte[out.capacity()];
int j = 0;
for (int x = 0; x < size; x++) {
c = colorTable[src.get(x) & 0xFF];
data[j++] = (byte) (c.getRed() * 255);
data[j++] = (byte) (c.getGreen() * 255);
data[j++] = (byte) (c.getBlue() * 255);
if (useAlpha) {
data[j++] = (byte) (c.getAlpha() * 255);
}
}
out.put(data);
out.rewind();
dataList.add(out);