Article View: comp.lang.postscript
Article #720Re: compressed images
From: Tomas G. Rokicki
Date: Thu, 20 Jul 1989 18:39
Date: Thu, 20 Jul 1989 18:39
61 lines
2633 bytes
2633 bytes
> 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
...
Technical Details
Message-ID:
<10750@polya.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!shelby!polya!rokickiReferences:
<59760@philabs.Philips.Com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!shelby!polya!rokicki 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 References: <59760@philabs.Philips.Com> Sender: Tomas G. Rokicki <rokicki@Polya.Stanford.EDU> Organization: Stanford University Lines: 61