diff options
Diffstat (limited to 'src/newt/classes/jogamp/newt/driver/opengl/JoglUtilPNGIcon.java')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/opengl/JoglUtilPNGIcon.java | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/opengl/JoglUtilPNGIcon.java b/src/newt/classes/jogamp/newt/driver/opengl/JoglUtilPNGIcon.java index f9f1f13ad..f7d6b9f25 100644 --- a/src/newt/classes/jogamp/newt/driver/opengl/JoglUtilPNGIcon.java +++ b/src/newt/classes/jogamp/newt/driver/opengl/JoglUtilPNGIcon.java @@ -46,9 +46,17 @@ public class JoglUtilPNGIcon { data_size[0] = 0; for(int i=0; i<resources.resourceCount(); i++) { final URLConnection urlConn = resources.resolve(i); - final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), PixelFormat.BGRA8888, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); - data_size[0] += 2 + image.getSize().getWidth() * image.getSize().getHeight(); - images[i] = image; + if( null != urlConn ) { + final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), PixelFormat.BGRA8888, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + data_size[0] += 2 + image.getSize().getWidth() * image.getSize().getHeight(); + images[i] = image; + } else { + images[i] = null; + } + } + if( 0 == data_size[0] ) { + // no image, abort + return null; } final boolean is64Bit = Platform.is64Bit(); elem_bytesize[0] = is64Bit ? Buffers.SIZEOF_LONG : Buffers.SIZEOF_INT; @@ -56,29 +64,31 @@ public class JoglUtilPNGIcon { for(int i=0; i<images.length; i++) { final PNGPixelRect image1 = images[i]; - final int width = image1.getSize().getWidth(); - final int height = image1.getSize().getHeight(); - if( is64Bit ) { - buffer.putLong(width); - buffer.putLong(height); - } else { - buffer.putInt(width); - buffer.putInt(height); - } - final ByteBuffer bb = image1.getPixels(); - final int stride = image1.getStride(); - for(int y=0; y<height; y++) { - int bbOff = y * stride; - for(int x=0; x<width; x++) { - long pixel; - pixel = ( 0xffL & bb.get(bbOff++) ); // B - pixel |= ( 0xffL & bb.get(bbOff++) ) << 8; // G - pixel |= ( 0xffL & bb.get(bbOff++) ) << 16; // R - pixel |= ( 0xffL & bb.get(bbOff++) ) << 24; // A - if( is64Bit ) { - buffer.putLong(pixel); - } else { - buffer.putInt((int)pixel); + if( null != image1 ) { + final int width = image1.getSize().getWidth(); + final int height = image1.getSize().getHeight(); + if( is64Bit ) { + buffer.putLong(width); + buffer.putLong(height); + } else { + buffer.putInt(width); + buffer.putInt(height); + } + final ByteBuffer bb = image1.getPixels(); + final int stride = image1.getStride(); + for(int y=0; y<height; y++) { + int bbOff = y * stride; + for(int x=0; x<width; x++) { + long pixel; + pixel = ( 0xffL & bb.get(bbOff++) ); // B + pixel |= ( 0xffL & bb.get(bbOff++) ) << 8; // G + pixel |= ( 0xffL & bb.get(bbOff++) ) << 16; // R + pixel |= ( 0xffL & bb.get(bbOff++) ) << 24; // A + if( is64Bit ) { + buffer.putLong(pixel); + } else { + buffer.putInt((int)pixel); + } } } } |