🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #53570

Re: CP compression (or any) - some numbers...

#53570
From: Stuart
Date: Tue, 31 Jul 2001 13:03
138 lines
6598 bytes
In article <0529e.u71200@archiver.winews.net>, The Archiver says...
> If someone wants to define a new scheme for compressing 
> binaries efficiently (with an 8 bit mode) and has to encode
> special chars (NUL, TAB, CR, LF) with 'escape chars':
> 
> I did a scan on a few common filetypes and made an 
> evaluation of the occurrence of bytes.
> A good compressed file would have an occurence of
> approx 0.39% for each binary value (1 / 256).
> 
> 1500 JPG pictures:
> 
> 0x00: 1.3 %
> 0x01: 0.42 %
> 0xFE: 0.52 %
> 0xFF: 0.7%
> 
> 500 MB AVI-DivX files
> 
> 0x00: 1.54%
> 0x01: 0.69%
> 0x05: 0.71%
> 0x80: 0.68%
> 0xFF: 0.33%
> 
> 500 MB  MP3-files
> 
> 0x00: 1.77%
> 0x01: 0.43%
> 0xFB: 0.62%
> 0xFF: 1.30%

Did the MP3s have ID3/ID3v2 tags? Those MP3s I've investigated could 
very much do with an additional compression stage (silence in MP3s seems 
to be encoded as a long string of 0xFFs) A simple RLE-like scheme would 
probably be sufficient for this and perhaps the other file types you've 
investigated.

> 500 MB MPG file (movie)
> 
> 0x00: 4.6%  (!)
> 0x01: 1.3%
> 0x02: 0.7%
> 0x60: 0.5%
> 0x80: 0.9%
> 0xFE: 0.28%
> 0xFF: 0.78%
> 
> In the 'extreme' case an MPG file would result in an overhead
> of > 8% if all NULL chars would be encoded with a double
> byte escape character.

Adding approx 46MB to the size of the encoded file if QPLite were to be 
used. Were those 00s packed together such that an RLE scheme would work 
well? Anyway, a good case for some kind of simple pre-compression could 
be made for this type of file (and to a lesser but still IMO significant 
extent the others you investigated) 1-5% compression on all the above 
file types could be achieved before any further encoding steps took 
place.

I don't suppose you've got a small piece of Win32 software which could be 
used to investigate the statistical distribution for further files, 
or file collections? Did you write something yourself?

> If I would be the one who defines a new encoding then I would
> introduce a fixed (or variable) additive factor to each byte before
> encoding (and checking for NUL,TAB,CR,LF) is done.
> 
> For a fixed value I would propose to add '42' to each byte
> before encoding.
> 
> This makes sure that the special chars (FE,FF,00..31) are all
> moved to '7-bit-ascii' and just the uncommon characters
> 214,223,224,227 are encoded with a two byte escape value.

Or a translation table calculated for each individual file (in order to 
avoid any other, rarer files messing up file size) downside being it 
would be a two pass algorithm. Any such scheme would save (since 1 byte 
is being used instead of two) for each escaped value around 1.5%, plus 
any savings made by the offset, translation &/or compression.

Since there's only 4 values which require escaping, the required data 
could be stored in 2 bits, and those 2 bits used to determine which value 
should replace the escape byte in the encoded file. This property can be 
used to make further space savings in the resulting encoded file.

You could use a 7x2 bit array of values in a two byte matrix (high bit 
set and ignored in each byte, in order to avoid clashes with escaped 
values) after the first of every 7 escape bytes. Every time you encounter 
a value which requires escaping, check forwards in the file until you 
find the next six (should need to check forwards an average of 
7x256/4=448 bytes, assuming the file has been 'fixed' to avoid high 
statistical occurances of the values in question first) Encode the 2 bit 
values after the first escape character, and replace the subsequent six 
escaped values with the escape byte. On decoding, the 7x2 bit array would 
be used as a reference for the next seven occurances of the escape byte. 
A 3x2 bit 1 byte array could be used, at a loss of efficiency, and a 4x2 
bit 1 byte array, at increased coding complexity (the resulting value 
possibly requiring escaping itself)

Despite the explanation being a little bit more complicated than 'use a 
byte offset' this would not IMO be difficult to implement, and would 
provide a further 1.1% saving.

Overhead comparisons:

UUEncoding: 40%
Base64: 37%
QPLite: 3% (average)
QPLite+file of all escaped values: 200% (worst case scenario)
QPLite+offset+1 byte per escape value: 1.5%
Compression+QPLite+1 byte escape value: <1.5% (offset not required)
QPLite+3x2 bit escape values(1 byte array): 0.5%
QPLite+7x2 bit escape values(2 byte array): 0.45%
QPLite+4x2 bit escape values(1 byte array+overhead): 0.4%

Compression could also be applied to the last 3, giving a good chance all 
encoded files will be smaller than the original.

> Compressed binaries really tend to use 00/01/FF more often
> than other values. And if a simple addition can save up to 8%
> then it might be worth thinking about it.

I'd say so. The loss is backwards compatability, though QP-Lite as it 
stands could continue to be used, and an external decoder (which may or 
may not be built into the newsreader depending on takeup) could be used 
on the QP-decoded files in order to retrieve the original unencoded file.

> Just my three cents (one cent for my binary archive ;-)
> Thanks for considering.

I'd like to see something along these lines implemented, even though I'm 
a mere user :) I wouldn't want any efforts for QP-Lite as a standard to 
become fragmented before we've even left the starting block though.

-- 
Stuart
Technical Details
Message-ID: <MPG.15d0bd03e8a0108d989a91@news.easynews.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!cyclone.bc.net!cyclone-sjo1.usenetserver.com!usenetserver.com!newsin.onlynews.com!easynews!news.easynews.com.POSTED!not-for-mail
References: <0529e.u71200@archiver.winews.net>

Show Full Headers
Complete Article Headers
Message-ID: <MPG.15d0bd03e8a0108d989a91@news.easynews.com>
Subject: Re: CP compression (or any) - some numbers...
Date: Tue, 31 Jul 2001 13:03:35 GMT
From: Stuart <stuart@knapton.clara.co.uk>
References: <0529e.u71200@archiver.winews.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!cyclone.bc.net!cyclone-sjo1.usenetserver.com!usenetserver.com!newsin.onlynews.com!easynews!news.easynews.com.POSTED!not-for-mail
Newsgroups: news.software.nntp
X-Newsreader: MicroPlanet Gravity v2.50
Lines: 137
X-Complaints-To: abuse@easynews.com
Organization: EasyNews, UseNet made Easy! - Test our service with our FREE trial at https://www.easynews.com/trial/trial.phtml
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.