Article View: comp.lang.postscript
Article #8910Re: looking for compressed readhexstring
From: Amanda Walker
Date: Thu, 08 Feb 1990 00:28
Date: Thu, 08 Feb 1990 00:28
82 lines
3291 bytes
3291 bytes
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"
Technical Details
Message-ID:
<1990Feb8.002814.1211@intercon.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!intercon!newsReferences:
<125@riscsm.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!intercon!news From: amanda@mermaid.intercon.com (Amanda Walker) Newsgroups: comp.lang.postscript Subject: Re: looking for compressed readhexstring Message-ID: <1990Feb8.002814.1211@intercon.com> Date: 8 Feb 90 00:28:14 GMT References: <125@riscsm.UUCP> Sender: @intercon.com Reply-To: amanda@mermaid.intercon.com (Amanda Walker) Organization: InterCon Systems Corporation, Sterling, VA Lines: 82