🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.postscript
4 messages
4 total messages Started by David M. Laur Tue, 08 Sep 1992 14:38
PS L2 compression behavior
#1891
Author: David M. Laur
Date: Tue, 08 Sep 1992 14:38
32 lines
1758 bytes
I've written a pbm+ to eps filter which allows optional
PostScript Level 2 image encoding. Since the thing is now
functional, I'm looking for ways to make it faster, more
correct, and generally cooler. 

I have one specific question about data expansion resulting
from 'compressed' encoding of worst-case input files: am I correct
in computing the worst case expansion of an input file under
RunLengthEncode followed by ASCII85Encode to be

   (worst output size) = (input data size) (4/3) (5/4)


i.e.  for data of the form "abbabbabbabb ..." the RLE algorithm
requires two bytes for each 'a' (right?), and Ascii85 is a 5:4
encoding.


Secondly, is there something wonderfully magic about the number 85
that makes the encoding algorithm Very Easy(tm)?  So far, I've just
been doing brute force integer divide/remainders by the various powers
of 85.

Thanks for any insight!

--

David Laur                                It is absurd to divide people
Princeton University                      into good and bad; people are
Interactive Computer Graphics Lab         either charming or tedious.
dmlaur@princeton.edu                                - Oscar Wilde
Re: PS L2 compression behavior
#1897
Author: Ed Taft
Date: Tue, 08 Sep 1992 20:52
24 lines
1542 bytes
In article <1992Sep8.143846.3667@Princeton.EDU>
dmlaur@ernie.Princeton.EDU (David M. Laur) writes:

>Am I correct in computing the worst case expansion of an input file
>under RunLengthEncode followed by ASCII85Encode to be
>
>   (worst output size) = (input data size) (4/3) (5/4)
>
>i.e.  for data of the form "abbabbabbabb ..." the RLE algorithm
>requires two bytes for each 'a' (right?)

No. There is nothing that requires you to encode repeated characters
as a repetition. You can encode the entire input as literal text,
producing an expansion of 128/127. This is the worst case. Use the
repetition encoding only when there is an advantage in doing so.

>Secondly, is there something wonderfully magic about the number 85
>that makes the encoding algorithm Very Easy(tm)?

I'm not aware of any tricks that apply specifically to multiplying and
dividing by 85. The choice of 85 as a base derives from it being the
smallest integer n such than n^5 >= 2^32.
-- 
Ed Taft      taft@adobe.com      ...decwrl!adobe!taft
Re: PS L2 compression behavior
#1898
Author: Tom Lane
Date: Tue, 08 Sep 1992 22:49
25 lines
1854 bytes
taft@adobe.com (Ed Taft) writes:
> dmlaur@ernie.Princeton.EDU (David M. Laur) writes:
> >Secondly, is there something wonderfully magic about the number 85
> >that makes the encoding algorithm Very Easy(tm)?
> 
> I'm not aware of any tricks that apply specifically to multiplying and
> dividing by 85. The choice of 85 as a base derives from it being the
> smallest integer n such than n^5 >= 2^32.

No, 85 is not particularly easy, it's just the largest "safe" value for this
application.  Base-85 representation is customarily used for representing
arbitrary binary files as ASCII text so that they can be mailed around on
Usenet.  It happens that there are 85 printable ASCII characters that have
exact EBCDIC equivalents.  If you try to use all 95 ASCII characters, you
run the risk of your file getting mangled in an ASCII <=> EBCDIC conversion
performed by some mail gateway.  (And of course, using any ASCII control
characters or characters with the 8th bit set is hopeless...)

At least, that was *my* understanding of the design.  The fact that 5
base-85 characters can represent 32 bits is convenient but it's not really
the driving force.

				regards, tom lane

ps: any further discussion should probably move to comp.compression.
Re: PS L2 compression behavior
#1936
Author: C.E. Thompson
Date: Sun, 13 Sep 1992 00:42
25 lines
1626 bytes
In article <1992Sep8.205244.17495@adobe.com>, taft@adobe.com (Ed Taft) writes:
|> In article <1992Sep8.143846.3667@Princeton.EDU>
|> dmlaur@ernie.Princeton.EDU (David M. Laur) writes:
[...]
|> >Secondly, is there something wonderfully magic about the number 85
|> >that makes the encoding algorithm Very Easy(tm)?
|> 
|> I'm not aware of any tricks that apply specifically to multiplying and
|> dividing by 85. The choice of 85 as a base derives from it being the
|> smallest integer n such than n^5 >= 2^32.

However, it so happens that there are some tricks to aid multiplication
and division by 85, in the absence of decent integer multiply or divide
hardware, based on the fact that 85 = (2^8-1)/3. For multiplication

  y = (x<<2)+x ; z = (y<<4)+y   /* would be two instructions on an ARM */

makes z == 85*x. For division use 1/85 = 3/2^8 + 3/2^16 + 3/2^24 + ...;
details left as an exercise for the reader (as they say in all the best
books).

Chris Thompson
Cambridge University Computing Service
JANET:    cet1@uk.ac.cam.phx
Internet: cet1@phx.cam.ac.uk
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads