Slick Forums

Discuss the Slick 2D Library
It is currently Sun Dec 17, 2017 6:14 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: PNGDecoder problems...
PostPosted: Sat Jul 06, 2013 7:09 pm 
Offline

Joined: Sat Jun 12, 2010 1:51 am
Posts: 23
Hello.
I just started using the excellent PNGDecoder and was extremely satisfied with both its performance and memory usage! I have a few problems with it though...


I also have images which I only want the red channel of the PNG texture. There's no Format for that so I'm currently being forced to store it as RGB and let OpenGL only store the R component, which is really inefficient...

IGNORE THE FOLLOWING, was my fault...
I'm having trouble reading from a special file format I've designed which contain multiple PNG images written to a single file using ImageIO.write. Reading one of them worked fine with ImageIO.load(FileInputStream) but PNGDecoder simply gives me a java.io.IOException: Not a valid PNG file when I create the PNGDecoder from my input stream (set to the correct location of course). It does however work when reading the last image in the file. Could it be that because the stream doesn't end after the image it reads too far and crashes?


Thanks!


Top
 Profile  
 
PostPosted: Sat Jul 06, 2013 9:35 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
The PNGDecoder was not designed to manipulate the data while decoding. There is only support for swapping R and B, and adding or removing alpha.

As for reading several PNG files - the decoder does not read the IEND tag (or any other data) after the last IDAT (there can be several IDAT chunks per image). So I assume that reading a single PNG out of the stream should work just fine when you position the stream correctly before reading.
If you would include the full stack trace of the exception it might help - otherwise I have to guess and say you didn't position your input stream right or the data is corrupted.
As InputStream doesn't support seeking you would need to write a custom InputStream which reads a specified region of a RandomAccessFile.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Sat Jul 06, 2013 11:13 pm 
Offline

Joined: Sat Jun 12, 2010 1:51 am
Posts: 23
The error when reading a file containing multiple images was my fault. For some reason ImageIO was okay with skipping the first 4 bytes without an error, while PNGDecoder was not. Fixed that and it worked out fine.

I don't want to manipulate the data in any way, I just want to only extract the red channel, not all channels.


Top
 Profile  
 
PostPosted: Sun Jul 07, 2013 4:20 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
Why not save it as a grey scale PNG?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Sun Jul 07, 2013 8:38 pm 
Offline

Joined: Sat Jun 12, 2010 1:51 am
Posts: 23
Hmm, I will try that. Thanks for your fast responses!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group