summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2017-12-11 19:52:43 +0000
committerRobin Watts <robin.watts@artifex.com>2017-12-13 11:23:08 +0000
commitb5189a84ddf0ca1454b10bb4a9926cd4f8c4f0eb (patch)
treefc2fb9066a50ac40a3041cf8f100b62090c4aed9 /lib
parent0bdb35346b5a9636bc6c1ca629401ba21232d9bb (diff)
downloadghostpdl-b5189a84ddf0ca1454b10bb4a9926cd4f8c4f0eb.tar.gz
Add PWGDecode filter.
And lib/viewpwg.ps to use it.
Diffstat (limited to 'lib')
-rw-r--r--lib/viewpwg.ps251
1 files changed, 251 insertions, 0 deletions
diff --git a/lib/viewpwg.ps b/lib/viewpwg.ps
new file mode 100644
index 000000000..569542450
--- /dev/null
+++ b/lib/viewpwg.ps
@@ -0,0 +1,251 @@
+% Copyright (C) 2017 Artifex Software, Inc.
+% All Rights Reserved.
+%
+% This software is provided AS-IS with no warranty, either express or
+% implied.
+%
+% This software is distributed under license and may not be copied,
+% modified or distributed except as expressly authorized under the terms
+% of the license contained in the file LICENSE in this distribution.
+%
+% Refer to licensing information at http://www.artifex.com or contact
+% Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
+% CA 94903, U.S.A., +1(415)492-9861, for further information.
+%
+
+% viewpwg.ps
+% Display a PWG file.
+
+% VPWGDEBUG can be predefined to be true to get debugging.
+% /VPWGDEBUG false def
+/VPWGDEBUG where { pop } { /VPWGDEBUG false def } ifelse
+
+/read1 % <file> read1 <int>
+{ read pop
+} bind def
+/read2 % <file> read2 <int>
+{ dup read1 8 bitshift exch read1 add
+} bind def
+/read4 % <file> read4 <int>
+{ dup read2 16 bitshift exch read2 add
+} bind def
+/readString % <file> readString <string>
+{ 0 string
+ dup
+ 0 1 63
+ { % <file> <string> <string> <iteration>
+ 3 index read pop
+ % <file> <string> <string> <iteration> <char>
+ dup 0 eq {pop pop} {put dup} ifelse
+ }
+ for
+ pop
+ exch pop
+} bind def
+/readReserved % <file> readReserved -
+{ read4 0 ne
+ { (Reserved field not zero.\n) print cleartomark stop }
+ if
+} bind def
+/readBoolean % <file> readBoolean <bool>
+{ read4 dup 0 eq
+ { pop false }
+ { 1 eq
+ { 0 }
+ { (Boolean not a boolean.\n) print cleartomark stop }
+ ifelse
+ }
+ ifelse
+} bind def
+
+/readPWGheader % <file> readPWGheader <dict>
+{ 20 dict begin
+ dup 4 string readstring pop
+ <52615332> eq not
+ { (Not a PWG file.\n) print cleartomark stop
+ } if
+ pop
+ currentdict end
+} bind def
+
+/readPWGpageHeader % <file> readPWGpageHeader <dict>
+ % Note: PWG header must be on dict stack
+{ 10 dict begin
+ dup readString /PwgRaster exch def
+ dup readString /MediaColor exch def
+ dup readString /MediaType exch def
+ dup readString /PrintContentOptimize exch def
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup read4 /CutMedia exch def
+ dup readBoolean /Duplex exch def
+ dup read4 /HWResolutionX exch def
+ dup read4 /HWResolutionY exch def
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readBoolean /InsertSheet exch def
+ dup read4 /Jog exch def
+ dup read4 /LeadingEdge exch def
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup read4 /MediaPosition exch def
+ dup read4 /MediaWeightMetric exch def
+ dup readReserved
+ dup readReserved
+ dup read4 /NumCopies exch def
+ dup read4 /Orientation exch def
+ dup readReserved
+ dup read4 /PageSizeX exch def
+ dup read4 /PageSizeY exch def
+ dup readReserved
+ dup readReserved
+ dup read4 /Tumble exch def
+ dup read4 /Width exch def
+ dup read4 /Height exch def
+ dup readReserved
+ dup read4 /BitsPerColor exch def
+ dup read4 /BitsPerPixel exch def
+ dup read4 /BytesPerLine exch def
+ dup read4 /ColorOrder exch def
+ dup read4 /ColorSpace exch def
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup read4 /NumColors exch def
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup read4 /TotalPageCount exch def
+ dup read4 /CrossFeedTransform exch def
+ dup read4 /FeedTransform exch def
+ dup read4 /ImageBoxLeft exch def
+ dup read4 /ImageBoxTop exch def
+ dup read4 /ImageBoxRight exch def
+ dup read4 /ImageBoxBottom exch def
+ dup read4 /AlternatePrimary exch def
+ dup read4 /PrintQuality exch def
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup readReserved
+ dup read4 /VendorIdentifier exch def
+ dup read4 /VendorLength exch def
+ % Skip 1088 bytes of VendorData
+ 1088 { dup read pop pop } repeat
+ % 64 Reserved bytes
+ dup readReserved dup readReserved dup readReserved dup readReserved
+ dup readReserved dup readReserved dup readReserved dup readReserved
+ dup readReserved dup readReserved dup readReserved dup readReserved
+ dup readReserved dup readReserved dup readReserved dup readReserved
+ dup readString /RenderingIntent exch def
+ dup readString /PageSizeName exch def
+ pop
+ currentdict end
+} bind def
+
+/viewPWG % <file|string> viewPWG -
+{ save 20 dict begin
+ /saved exch def
+ dup type /stringtype eq { (r) file } if
+ /F exch def
+ F readPWGheader /Header exch def
+
+ % We have a dictionary with /saved, /F and /Header on the stack.
+
+ % Debug dump Header fields.
+ VPWGDEBUG { Header { exch == == } forall (----------------\n) print flush } if
+
+ {
+ % If we have no bytes left, stop
+ F bytesavailable 0 le { exit } if
+
+ % Read the page header.
+ F readPWGpageHeader /PageHeader exch def
+
+ % Push PageHeader onto the dict stack.
+ PageHeader begin
+
+ % Debug dump the Page Header.
+ VPWGDEBUG { PageHeader { exch == == } forall (----------------\n) print flush } if
+
+ % Define D to be the decoded data from F.
+ /D F
+ <</Width Width
+ /BPP BitsPerPixel
+ >> /PWGDecode filter def
+
+ % Set the Colorspace appropriately.
+ ColorSpace dup dup 3 eq exch 18 eq or exch 48 eq or
+ { % Black or SGray or Device1
+ /DeviceGray setcolorspace
+ /NumComponents 1 def
+ }
+ { ColorSpace dup dup dup 1 eq exch 19 eq or exch 20 eq or exch 50 eq or
+ { % Rgb or sRGB or AdobeRGB or Device3
+ /DeviceRGB setcolorspace
+ /NumComponents 3 def
+ }
+ { ColorSpace dup 6 eq exch 51 eq or
+ { % DeviceCMYK or Device4
+ /DeviceCMYK setcolorspace
+ /NumComponents 4 def
+ }
+ { (Unsupported colorspace in PWG file.\n) print cleartomark stop
+ }
+ ifelse
+ }
+ ifelse
+ }
+ ifelse
+
+ % Do some matrixy stuff I don't understand.
+ matrix currentmatrix
+ 0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
+ setmatrix
+
+ <<
+ /ImageType 1
+ /ImageMatrix [1 0 0 -1 0 Height]
+ /BitsPerComponent BitsPerPixel NumComponents div
+ /Width Width
+ /Height Height
+ /DataSource D
+ >> image
+
+ % Bin the PageHeader dictionary
+ end
+
+ showpage
+ }
+ loop
+ saved end restore
+} bind def
+
+% This lets you do stuff on the command line like:
+% gs -sDEVICE=pdfwrite -o stuff%03d.pdf viewurf.ps -c "(image.urf) << /PageSize 2 index viewURFgetsize 2 array astore >> setpagedevice viewURF"
+% so the output size is influenced by the original image.
+%/viewURFgetsize % <file|string> ==> [width height]
+%{
+% save 20 dict begin
+% /saved exch def
+% dup type /stringtype eq { (r) file } if
+% /F exch def
+% F readURFheader /Header exch def
+% currentdict Header end begin begin
+% VPWGDEBUG { Header { exch == == } forall (----------------\n) print flush } if
+% F readURFimageHeader /ImageHeader exch def
+% currentdict ImageHeader end begin begin
+% F 0 setfileposition % reset file pointer
+% Width Height
+% saved end end end restore
+%} bind def