* @param bytesPerLine
* @return The created instance
*/
public static BitmapGraphics createInstance(DataBuffer dataBuffer,
int width, int height, int bytesPerLine, int transparency) {
final ResourceManager rm;
try {
rm = InitialNaming.lookup(ResourceManager.NAME);
} catch (NamingException ex) {
throw new RuntimeException("Cannot find ResourceManager", ex);
}
final int dbOffset = dataBuffer.getOffset();
switch (dataBuffer.getDataType()) {
case DataBuffer.TYPE_BYTE: {
final byte[] data = ((DataBufferByte) dataBuffer).getData();
return new BitmapGraphics8bpp(rm.asMemoryResource(data), width,
height, dbOffset, bytesPerLine);
}
case DataBuffer.TYPE_SHORT: {
final short[] data = ((DataBufferShort) dataBuffer).getData();
return new BitmapGraphics16bpp(rm.asMemoryResource(data), width,
height, dbOffset * 2, bytesPerLine);
}
case DataBuffer.TYPE_USHORT: {
final short[] data = ((DataBufferUShort) dataBuffer).getData();
return new BitmapGraphics16bpp(rm.asMemoryResource(data), width,
height, dbOffset * 2, bytesPerLine);
}
case DataBuffer.TYPE_INT: {
final int[] data = ((DataBufferInt) dataBuffer).getData();
return new BitmapGraphics32bpp(rm.asMemoryResource(data), width,
height, dbOffset * 4, bytesPerLine, transparency);
}
default: {
throw new RuntimeException("Unimplemented databuffer type " + dataBuffer.getDataType());
}