Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Evil Bill

PNG Encoding

This topic is 5545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've had a look at the search page, and didn't find anything useful... I'm trying to write a program to generate PNG images from a bitmap, but i can't get it working. It seems that zlib is compressing my 110 byte bitmap data down to 12 bytes, surely thats not right? My input image looks like this: My pretty picture And heres the code for the compression:
        
   // Setup compression stream //

   ZeroMemory(&theStream,sizeof(theStream));
   deflateInit(&theStream,9);
   theStream.next_in = pbyInput;
   theStream.avail_in = (bmpInfo.bmWidth+1)*bmpInfo.bmHeight;
   theStream.total_in = 0;
   theStream.next_out = pbyData;
   theStream.avail_out = dwLen;
   theStream.total_out = 0;
   
   // Compress Chunk //

   if(deflate(&theStream,Z_FINISH) != Z_STREAM_END) goto lblError;
   delete[] pbyInput;
   pbyInput = NULL;
   
   // Write Chunk//

   // Snipped - just writes theStream.total_out bytes to file //

   delete[] pbyData;
   pbyData = NULL;

   deflateEnd(&theStream);
    
I get my image data from GetObject() on a DIB section, and i copy it into pbyInput, adding a 0 byte at the start of each scanline (for the filter type), so in total my input data is 110 bytes. Any help would be great. [edited by - Evil Bill on April 19, 2003 10:41:03 AM] [edited by - Evil Bill on April 19, 2003 10:41:30 AM] [edited by - Evil Bill on April 19, 2003 11:45:51 AM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Evil Bill
It seems that zlib is compressing my 110 byte bitmap data down to 12 bytes, surely thats not right?


Since your image is very simple, such a result wouldn''t surprise me at all. If you really want to make sure it work, why don''t you uncompress it and see if you get the original image ?

Share this post


Link to post
Share on other sites
quote:

If you really want to make sure it work, why don''t you uncompress it and see if you get the original image ?


D''oh! I''ll try that now...

Share this post


Link to post
Share on other sites
Ok, i made a stupid mistake so it was saving 110 bytes of 0x00's, now it outputs 63 bytes, which is much more realistic.

But it still doesn't work . I tried inflating the data after i deflated it and it comes out the same as it went in, so its compressing it ok.
I'll rename the topic to something to do with PNGs i think.



[edited by - Evil Bill on April 19, 2003 11:45:31 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Evil Bill
But it still doesn''t work . I tried inflating the data after i deflated it and it comes out the same as it went in, so its compressing it ok.


What doesn''t work if it''s compressing it well ? By the way, if you want to create PNG images, you should perhaps use libPNG, it would be much easier.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!