Reputation: 689
I am trying to convert PWG raster file data into postscript data. I have generated at test file which is as follows:
%!PS-Adobe-3.0
%%BoundingBox: 0 0 5100 6600
%Creator: Cups-Filters
%LanguageLevel: 2
%DocumentData: Clean7Bit
%EndComments
%BeginProlog
%EndProlog
%Pages: (atend)
%%Page: 1 1
%%BeginPageSetup
<< /PageSize[5100 6600]/ImagingBBox null>> setpagedevice
%%EndPageSetup
gsave
gsave
5100 6600 scale
5100 6600 8 [5100 0 0 -6600 0 6600]
{currentfile 3 5100 string readhexstring pop} bind
false 3 colorimage
...hexadecimal information cut...
grestore
showpage
%PageTrailer
%Trailer
%%Pages: 1
%EOF
Whenever I try to run the program using GhostScript interpretor, I get the following error:
$ ghostscript sample.ps
GPL Ghostscript 9.18 (2015-10-05)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /typecheck in --colorimage--
Operand stack:
--nostringval-- 3 (\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000...)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1977 1 3 %oparray_pop 1976 1 3 %oparray_pop 1960 1 3 %oparray_pop 1852 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 1878 7 3 %oparray_pop
Dictionary stack:
--dict:1194/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)--
Current allocation mode is local
Current file position is 399
GPL Ghostscript 9.18: Unrecoverable error, exit code 1
The PS file is about 128 MB with about 99% data being the hexadecimal representation of the coloured image.
I tried searching it and one source suggested to add 'setpagedevice' parameter to the PS file. I have added it but to no effect.
How can I get rid of this error ? Also, is there any other way to represent very large images in postscript ?
Upvotes: 3
Views: 170
Reputation: 31141
Your code contains:
{currentfile 3 5100 string readhexstring pop} bind
If we break that up and add comments about the stack content we get:
{
currentfile % Stack contents: -file-
3 % stack contents: -file- 3
5100 % stack contents: -file- 3 5100
string % string consumes the top operand, creates a string
% object of that size, and places the string on the stack
% stack contains: -file- 3 (string)
readhexstring % consume string and file operands, return substring, bool
%
pop % pop the boolean
}
The problem is that readhexstring expects to see -file- (string) but the stack actually contains 3 (string), 3 isn't a file object so you get a typecheck error.
Upvotes: 2