AWTLoader enhancement mod

I use BufferedImages to dynamically alter JME3 Textures. It was proving a mess, as each even numbered time I updated the Texture (using AWTLoader), the texture was being flipped in Y.

The issue is that my BufferedImage work area was being flipped (in place) as a side effect of calling AWTLoader.load() with flipY == true (Q: is !flipY ever desirable?)

This minor modification to AWTLoader’s extractImageData() method fixes it, but making sure the Texture’s flipped version of the data is separate from the BufferedImage’s own data. The cost of the copy is perhaps a reason to make this fix an option to be provided in addition to, rather than an outright replacement of, the present behavior

private Object extractImageData(BufferedImage img){
DataBuffer buf = img.getRaster().getDataBuffer();
switch (buf.getDataType()){
case DataBuffer.TYPE_BYTE:
DataBufferByte byteBuf = (DataBufferByte) buf;

            return Arrays.copyOf(byteBuf.getData(), byteBuf.getSize());
        case DataBuffer.TYPE_USHORT:
            DataBufferUShort shortBuf = (DataBufferUShort) buf;
            return Arrays.copyOf(shortBuf.getData(), shortBuf.getSize());                
    return null;


1 Like