[comp.lang.postscript] looking for compressed readhexstring

cary@Scripps.EDU (Steve Cary) (01/25/90)

In an attempt to not re-invent the wheel,
does anyone have a readhexstring implementation
that supports ascii run-length encoding???

The "natives" are getting restless about the
~2 hours required to download an 8-bit color
postscript image to our QMS Colorscript 100
via a 9600 baud serial line...

THANKS!

	-Steve Cary
	cary@scripps.edu
	Research Institute of Scripps Clinic, La Jolla, CA

amanda@mermaid.intercon.com (Amanda Walker) (02/08/90)

Here's some code that was posted a while back by Tomas G. Rokicki that
does run-length encoding for black & white images.  It will need some
editing for use with the 'colorimage' operator, but it's the most
efficient version of this kind of thing that I have seen yet:

From: rokicki@polya.Stanford.EDU (Tomas G. Rokicki)
Newsgroups: comp.lang.postscript
Subject: Re: compressed images
Message-ID: <10750@polya.Stanford.EDU>
Date: 20 Jul 89 18:39:33 GMT

> Has anyone implemented a PostScript run length decoder procedure that
> will allow run length compressed files to be sent to the printer?
> Assume that the compression is done by a C program in advance.

Here's my entry.  Comments have been added to the normal output of
the program.

% random definitions for width, height, etc.
/W  378 def /H  230 def /BS 1 def /PW 0.99 def /ST 128 string def
% a single-byte string for grabbing byte by byte
/T 1 string def
% n S -
% This subroutine grabs the next `n' bytes from the stream and
% returns them literally.  Does it by grabbing a subinterval of
% the appropriate length, and then readhexstring.
/S { %def
   ST exch 0 exch getinterval
   currentfile exch readhexstring pop
} bind def
% n S -
% This subroutine does a run-code; it grabs the next byte and
% repeats it n-128 times.
% First it grabs the next byte and stuffs it into all 128
% positions of the string.  (This has been shown to be faster
% than the `for' loop method.)  It then grabs the appropriate
% subinterval of that string.
/R { %def
   128 sub
   currentfile T readhexstring pop 0 get
   dup ST exch 0 exch put
   dup ST exch 1 exch put
   dup ST exch 2 exch put
   dup ST exch 3 exch put pop ST
   dup dup  4 exch 0  4 getinterval putinterval
   dup dup  8 exch 0  8 getinterval putinterval
   dup dup 16 exch 0 16 getinterval putinterval
   dup dup 32 exch 0 32 getinterval putinterval
   dup dup 64 exch 0 64 getinterval putinterval
   exch 0 exch getinterval
} bind def
% This is the general subroutine.  We repeatedly get a byte,
% compare it with 128, and call the appropriate routine.
/G { %def
   currentfile T readhexstring pop 0 get
   dup 128 lt { S } { R } ifelse
} bind def
% Of course, image calls the above routine as many times as
% appropriate.
/DP { %def
  W H BS [W 0 0 H neg 0 H]
  { G }
  image grestore
} bind def
%%EndProlog
gsave
DP
% And now, the data . . .
AFFF01C091FF01EF9DFF01C091FF01E09DFF01C091FF02EF1F9CFF01C08CFF01BF84FF02EFE39C
FF04C0E0F87F89FF017F84FF03EFFC3F9BFF04C0F2733F88FF01FE85FF03EFFFC79BFF04C0F332
3F88FF01FD85FF03EFFFF89BFF04C0F3303F88FF01FB85FF04EFFFFF0F9AFF04C0F3313F88FF01
..


Enjoy,

--
Amanda Walker
InterCon Systems Corporation

"Many of the truths we cling to depend greatly upon our own point of view."
	--Obi-Wan Kenobi in "Return of the Jedi"

jef@well.sf.ca.us (Jef Poskanzer) (02/08/90)

So, is someone going to volunteer to do a frequently asked questions
posting for comp.lang.postscript?  I'm not interested enough in
PostScript to do it.
---
Jef

  Jef Poskanzer  jef@well.sf.ca.us  {ucbvax, apple, hplabs}!well!jef
"I am endeavoring, ma'am, to construct a mnemonic memory circuit, using
                     stone knives and bearskins."

woody@rpp386.cactus.org (Woodrow Baker) (02/09/90)

In article <16032@well.sf.ca.us>, jef@well.sf.ca.us (Jef Poskanzer) writes:
> So, is someone going to volunteer to do a frequently asked questions
I am working on it.  I am currently archieving all of the postscript
newsgroup messages.  I am also analyzing the questions asked, for 
frequency.  Any input as to what questions to include the answers
to will be much appreciated.

Cheers
Woody

> 
> "I am endeavoring, ma'am, to construct a mnemonic memory circuit, using
>                      stone knives and bearskins."
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  (SPOCK)