Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  TWL's PNGDecoder now available as standalone JAR  (Read 6163 times)
0 Members and 1 Guest are viewing this topic.
Offline Matthias

Senior Member


Medals: 3
Projects: 1


TWL - Themable Widget Library


« Posted 2010-05-15 22:04:12 »

The PNGDecoder from the TWL - Themable Widget Library is now available as a separate JAR.

JAR: PNGDecoder.jar
Source: PNGDecoder.java

Example usage:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
InputStream in = new FileInputStream("white_pixel.png");
PNGDecoder decoder = new PNGDecoder(in);

System.out.println("width="+decoder.getWidth());
System.out.println("height="+decoder.getHeight());

ByteBuffer buf = ByteBuffer.allocateDirect(4*decoder.getWidth()*decoder.getHeight());
decoder.decode(buf, decoder.getWidth()*4, Format.RGBA);
buf.flip();

while(buf.hasRemaining()) {
   System.out.printf("%02X\n", buf.get() & 255);
}


Have fun Smiley

EDIT: The PNGDecoder has been moved into the de.matthiasmann.twl.utils package. A class in the old package is still there and forwards all methods to the new PNGDecoder.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2010-05-15 22:14:23 »

Care to share why we should use the TWL PNGLoader as opposed to ImageIO? Performance? If so, what's the diff?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2010-05-15 22:19:07 »

I just stumbled upon this code:
1  
2  
3  
4  
         int read = input.read(buffer, 0, SIGNATURE.length);
         if(read != SIGNATURE.length || ...) {
             throw new IOException("Not a valid PNG file");
         }


Isn't it perfectly valid for 'read' not to be equal to 'SIGNATURE.length' ... Shocked

Think about network traffic that gets sliced and diced.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Matthias

Senior Member


Medals: 3
Projects: 1


TWL - Themable Widget Library


« Reply #3 - Posted 2010-05-15 22:27:38 »

Thanks Riven, it's fixed in the repository Smiley

And the main benefit of this PNGDecoder is the ability to decode into a NIO buffer in OpenGL compatible formats. This avoids unnecessary memory copies. To support NPOT textures it's also possible to specify the stride.
Offline DzzD
« Reply #4 - Posted 2010-05-19 16:43:41 »

Thanks Riven, it's fixed in the repository Smiley

And the main benefit of this PNGDecoder is the ability to decode into a NIO buffer in OpenGL compatible formats. This avoids unnecessary memory copies. To support NPOT textures it's also possible to specify the stride.

does you built your own zlib ?

( EDIT: in case of I posted some times ago a PNG loader source code here http://www.java-gaming.org/topics/pure-java-png-loader-with-efficient-clear-code/22041/view.html but unfortunatly it does not contain its own zlib, but the nice part is that it can be adapted easily to match any requierement : memory / streaming / decoded format / etc... )

EDIT2:  just looked at it, nice source code

Offline Matthias

Senior Member


Medals: 3
Projects: 1


TWL - Themable Widget Library


« Reply #5 - Posted 2010-05-19 17:10:47 »

It uses Inflater from java.util.zip and I did not provide a hook to exchange it with another zlib implementation.

What's that all about custom zlib versions? Are there huge performance gains by using a Java based zlib (which I doubt)? The additional code size is an issue, I want to keep the library small.
Offline DzzD
« Reply #6 - Posted 2010-05-19 17:22:49 »

It uses Inflater from java.util.zip and I did not provide a hook to exchange it with another zlib implementation.

What's that all about custom zlib versions? Are there huge performance gains by using a Java based zlib (which I doubt)? The additional code size is an issue, I want to keep the library small.

hum zlib is native code in java and should be pretty fast, it seems to me to be a copy (used often in other project than java jre) of an existing librarie (probably "sun-java-boys" get afraid too to redo it from scratch Smiley ), the interresting thing would have be to get better control but also provide a full-cross platform png loader (not dependent on any external libraries)

NB: I just noticed that you only implement paletized PNG ? ( even if it would requiere few lines, this is the only one I did not take the time to implement as it was not yet really requiered for me, I have done some debug/improvments that I will try to post "a day ...")

Offline Matthias

Senior Member


Medals: 3
Projects: 1


TWL - Themable Widget Library


« Reply #7 - Posted 2010-05-19 17:48:40 »

The java.util.zip package is part of core J2SE - so that's always available.

What do you mean with only palettized?!? It supports every non interlaced format except 16 bit per component.
Offline DzzD
« Reply #8 - Posted 2010-05-19 18:01:42 »

The java.util.zip package is part of core J2SE - so that's always available.
nothing really important just that it is an "external libraries" not a pure java program, I did not care before it was pointed to me too...

but if you would like to take full control on abort decoding / memory usage & performances it may be nice to have one pure java, zlib decompression is probably the part that requiere the most processor and may do allocation here and here but who care...

What do you mean with only palettized?!? It supports every non interlaced format except 16 bit per component.
probably that I may buy glasses... I missed that "if ( bitdepth != 8 )"


Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #9 - Posted 2010-05-19 19:06:52 »

The java.util.zip package is part of core J2SE - so that's always available.

What do you mean with only palettized?!? It supports every non interlaced format except 16 bit per component.

If you removed the dependency upon the java.util.zip package you'd open your library up to being of use to J2ME developers.

Not a criticism as such, just a thought.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (35 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!