IT Community - Software Programming, Web Development and Technical Support

compressing and uncompressing png file

This is a discussion on compressing and uncompressing png file within the Game Development forums, part of the Software Development category; You are almost right. It should be (width+1)*height+11. Afaik the '+1' is the byte used to seperate ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Game Development

Register FAQ Members List Calendar Mark Forums Read
  #21 (permalink)  
Old 09-18-2007, 03:02 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Default Re: compressing and uncompressing png file

Quote:
You are almost right. It should be (width+1)*height+11. Afaik the '+1' is the byte used to seperate scanlines and the 11 bytes are for IDAT compression flags and checksum stuff.


A-HA! (No, not the band.) Got it! Each scanline is being presented in its own deflate block. So you have to add 4 bytes (LEN and NLEN) to each one. It becomes 3 (for flags) + (width+5)*height + 4 (for adler) => (width+5)*height + 7. Again, that does not include the IDAT label, size and CRC, which represent a further 12 bytes (right?).

Your comment on the scanline separator was what got me the solution.

I think I missed a couple of bytes somewhere, but I'm not sure.

PNG Specification: Deflate/Inflate Compression
RFC 1950 (rfc1950) - ZLIB Compressed Data Format Specification version 3.3
RFC 1951 (rfc1951) - DEFLATE Compressed Data Format Specification version

Cool, now I can sleep tonight.

Cheers!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 09-18-2007, 03:04 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Default Re: compressing and uncompressing png file

Quote:
A-HA! (No, not the band.) Got it! Each scanline is being presented in its own deflate block. So you have to add 4 bytes (LEN and NLEN) to each one. It becomes 3 (for flags) + (width+5)*height + 4 (for adler) => (width+5)*height + 7. Again, that does not include the IDAT label, size and CRC, which represent a further 12 bytes (right?).
If the above is correct (not having reviewed your references in depth) then neither GIMP's nor pngout's uncompressed PNG format is "correct". The IDAT chunks have wrong sizes.

test case:
width:144
height: 43

Shold be: (width+1+2+2)*height+4+3+4+4 = 6422
GIMP uncompressed IDAT: 6246
PngOut uncompressed IDAT: 6456
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23 (permalink)  
Old 09-18-2007, 03:07 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Default Re: compressing and uncompressing png file

Quote:
If the above is correct (not having reviewed your references in depth) then neither GIMP's nor pngout's uncompressed PNG format is "correct". The IDAT chunks have wrong sizes.

Let me stop you right there. Correctness is defined by whether it can be correctly read by a compliant parser. Like, there are several different ways for me to say this to you, and none of them are more "correct" than the others (although the correct ones probably don't start with "like").

Specifically, you can split the data in deflate blocks wherever you want, as long as they're all within the 32k boundary. PNGOut is splitting them at each scanline -- probably due to lazyness more than anything else, since he thought nobody would use the uncompressed format. GIMP is splitting it in a different way. But they are both "correct". So there.

So long, and until the next mistery...!

Cheers!

PS: Thanks for the puzzle. Please do post other questions like yours, it's very interesting stuff.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24 (permalink)  
Old 09-18-2007, 03:09 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Default Re: compressing and uncompressing png file

Quote:
Let me stop you right there. Correctness is defined by whether it can be correctly read by a compliant parser. Like, there are several different ways for me to say this to you, and none of them are more "correct" than the others (although the correct ones probably don't start with "like").
i totally agree. I had hoped that the quotes around correct in my last post indicated that I'm aware that the correctness of any format relies on the interpreters in question.



Quote:
PS: Thanks for the puzzle. Please do post other questions like yours, it's very interesting stuff.
Will do. Thanks for the feedback
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File extension of the code file & object repository file in QTP vigneshgets Testing Tools 1 01-16-2008 11:43 PM
How can I extract just the extension file name from a forms file upload field? itbarota HTML, CSS and Javascript Coding Techniques 1 10-22-2007 08:32 AM
convert Excel file to CSV(or text) file using java mobilegeek Java Programming 2 09-06-2007 06:42 AM
Difference between a file and Random access file Classes anbuchezhians Java Programming 1 08-08-2007 02:53 AM
set the file path for file type input tag Jeyaseelansarc PHP Programming 0 05-19-2007 05:01 AM


All times are GMT -7. The time now is 07:24 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0