www.GetXFactor.com

Leading Technology, Science,
Agriculture News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

ZLIB compress() problems... (newbie)
   Science and Technology news... Forum Index -> Compression Forum  
View previous topic :: View next topic  
Author Message
Mike
Guest






PostPosted: Sun Aug 03, 2003 8:29 pm    Post subject: ZLIB compress() problems... (newbie) Reply with quote

Hi,
This may a c/c++ problem rather than a zlib problem, but hopefully
many here will have used zlib and can tell me if I>m OT.

I>m writing a compressed SWF file (Flash). In this format, the first 8
bytes should be uncompressed, the rest compressed with zlib. The first
8 bytes indicate whether compression is used, the version num, and the
uncompressed file size.

If I write my file uncompressed, with appropriate header, it plays
back fine. If I try to make a compressed version, it doesn>t.
Here>s the relevant code (using vc++):

///////////////////////////////////

std::ofstream fileout(fileName.GetBuffer(0),std::ios::binary);
fileName.ReleaseBuffer();
std::ostringstream f(std::ios::binary);

..
..
..
..

// compressed file - write start of header to fileout
fileout << "CWS";
UBYTE version = 6;
fileout << version;

UDWORD filesize = f.str().size();
int minbits = (int)ceil(((fbase_max(GetBitSize(size.GetX2()),
GetBitSize(size.GetY2())+1)) * 4 + 5) / 8.0);
UDWORD size_adjust = 12+minbits;
filesize += size_adjust;
WRITE_UDWORD2(filesize, fileout)

// compress f with zlib, write to fileout

unsigned long csize = filesize+(UDWORD)(filesize/100)+12; // satisfy
min size requirements for compression buffer
unsigned char *compression_buffer = (unsigned char*)malloc(csize);

if(compress(compression_buffer, &csize, (const unsigned char*)&f,
filesize/*, Z_BEST_COMPRESSION*/) == Z_OK){
fileout.write((char*)compression_buffer,csize);
}
else
{
//throw
TRACE ("Compression didn>t work\n");
}
free(compression_buffer);

///////////////////////////////////

Is this the wrong use of compress() with a std::ostringstream?
Compress2() doesn>t work either. Or have I missed something?
Thanks for any suggestions.
M
Back to top
Mike
Guest






PostPosted: Mon Aug 04, 2003 2:03 pm    Post subject: Re: ZLIB compress() problems... (newbie) Reply with quote

snip
[quote]///////////////////////////////////

Is this the wrong use of compress() with a std::ostringstream?
Compress2() doesn>t work either. Or have I missed something?
Thanks for any suggestions.
M
[/quote]
It>S OK, fixed it.
M
Back to top
Display posts from previous:   
   Science and Technology news... Forum Index -> Compression Forum  
Page 1 of 1
All times are GMT

 
Jump to:  
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 vote in polls in this forum