Re: estimate zlib compression ratio?



tim.weiler@xxxxxxxxx wrote:
For example, I need to send files over a socket, and some files are
jpegs, which don't compress that well, but other files are large text
documents with good compression ratios. I'd like to selectively
compress the files based on an estimated compression ratio.

Depending on why exactly you want to do this, zlib may already do it for you. If a chunk of data fails to compress, it copies it uncompressed into the output stream (with a short header that says that it's uncompressed). The only reason this wouldn't be good enough is if you need to cut down on CPU usage on the sending side. In that case, aside from what Phil Carmody already suggested, you might do well by simply looking at the file extension, or, if that's not available, the first few bytes of the file. If it starts FF D8 then it's almost certainly a JPEG image.

-- Ben
.



Relevant Pages

  • Re: Digital Camera question
    ... Either keep the original or compress it to sub ... > Take a typical picture and apply various stages of compression (as I ... and just did to check) and you might get a clue. ... >>jpegs is the difference that matters. ...
    (uk.business.agriculture)
  • Re: Digital Camera question
    ... > Derek Moody writes ... Either keep the original or compress it to sub ... >>jpegs is the difference that matters. ... StrongArm Under construction, FAQ, recipes, tips, booklist, links ...
    (uk.business.agriculture)
  • Re: Digital Camera question
    ... Either keep the original or compress it to sub ... >the shot so keep and work on the high-res tiff. ... >jpegs is the difference that matters. ... You haven't a clue. ...
    (uk.business.agriculture)
  • Re: Digital Camera question
    ... Either keep the original or compress it to sub ... the shot so keep and work on the high-res tiff. ... but it annoys me when smug photonerds suggest to the average punter ... jpegs is the difference that matters. ...
    (uk.business.agriculture)
  • Re: Compressed Folder
    ... Phil wrote: ... > compressed, thus you can't compress them anymore. ... Rather than compressing individual file formats I am concerned about ... and jpegs will not or will all files be compressed equally. ...
    (microsoft.public.windowsxp.general)