[comp.lang.postscript] Is run-length compression possible in PostScript?

marc@rna.UUCP (Marc Johnson) (09/23/88)

I am producing bitmapped images on a LaserWriter Plus using PostScript,
noteably the "image" operator.  The image data can get huge, and I would
like to do run-length compression.  Anybody know how if this is possible
using the "image" operator, or any other method in PostScript?

Please e-mail responses.

Thanx,
Marc Johnson
Rockefeller Univ.

marc%rna@rockefeller.edu (129.85.2.1)
rna!marc@rockvax.bitnet
...cmcl2!rna!marc

john@trigraph.UUCP (John Chew) (09/26/88)

In article <260@rna.UUCP> marc@rna.UUCP (Marc Johnson) writes:
>I am producing bitmapped images on a LaserWriter Plus using PostScript,
>noteably the "image" operator.  The image data can get huge, and I would
>like to do run-length compression.  Anybody know how if this is possible
>using the "image" operator, or any other method in PostScript?

>Please e-mail responses.

Well... it's only a dozen lines and it might be of general interest, so
here's what we use to send large bitmap logos over slow serial links to
remote laserwriters.  I am open to e-mailed constructive criticism, con-
cerning anything but indentation style :-).

To use, put the definitions for ++ and rld (run-length-decode) in your
program prologue, then put in reasonable values for tx, ty, sx, sy, wid,
hgt, inv, mat, lots-of-hex-data, size-of-expanded-string and put the rest
into your program script.  This should of course work with the image
operator just as easily as with the imagemask operator.

%%%%% START CUTTING HERE %%%%%
/++ {dup load dup 1 add exch 3 1 roll def}bind def
/rld {0 begin/s 2 index def/d 1 index def/sln s length def/sp 0 def/dp 0 def
{sp sln eq {exit}if
	s/sp ++ get dup 127 gt
	{256 sub neg s/sp ++ get exch {dup d/dp ++ 3 -1 roll put}repeat pop}
	{{d/dp ++ s/sp ++ get put}repeat}ifelse
}loop end}bind def/rld load 0 5 dict put

tx ty translate sx sy scale
wid hgt inv [mat] 
{<lots-of-hex-data> size-of-expanded-string string rld exch pop}
imagemask
%%%%% THAT'S ALL %%%%%

John Chew

-- 
john j. chew, iii  poslfit@utorgpu.bitnet
    trigraph, inc. poslfit@gpu.utcs.toronto.edu
  toronto, canada  {uunet!mnetor!utzoo,utgpu,utcsri}!trigraph!john
  [it is my opinion that these are solely my opinions.]

gordon@spinifex.eecs.unsw.oz (Gordon Rowell) (09/27/88)

In article <260@rna.UUCP>, marc@rna.UUCP (Marc Johnson) writes:
> I am producing bitmapped images on a LaserWriter Plus using PostScript,
> noteably the "image" operator.  The image data can get huge, and I would
> like to do run-length compression.  Anybody know how if this is possible
> using the "image" operator, or any other method in PostScript?
> 

There are two examples that I know of. Sun2PS, which takes Sun format
windows and generates PostScript images from them, and the X11 version
of xpr. Both use RLL encoding to generate much smaller (e.g. ~30% size)
files. Check with a site near you that has Suns or X11, or they
can be posted if needed. (BTW I have made an X10 version for anyone who
is interested).
		Gordon Rowell	(gordon@spinifex.eecs.unsw.oz)
		Department of Computer Science, 
		University of N.S.W., Sydney, Australia