将光栅文件转换为PostScript文件时出现错误

3

我正在尝试将PWG光栅文件数据转换为Postscript数据。我已经生成了一个测试文件,其内容如下:

%!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

每次我尝试使用GhostScript解释器运行程序时,都会出现以下错误:
$ 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

PS文件大小约为128 MB,其中约99%的数据是彩色图像的十六进制表示。

我尝试过搜索,有一个来源建议在PS文件中添加“setpagedevice”参数。我已经添加了它,但没有效果。

如何解决这个问题?另外,是否有其他方法来表示非常大的图像在Postscript中?


你尝试过在{currentfile 3 5100 string readhexstring pop}后面不加bind吗?我在PSLRM中没有看到它与bind一起使用。 - Stefan Hegny
绑定不应该引起问题,所有发生的事情就是在绑定时将运算符定义替换为它们当前的值。因此,如果您在过程之后但在执行过程之前重新定义了readhexstring等操作,则使用和不使用绑定会得到不同的结果。我建议问题出在读取数据的代码上。请参见下文。 - KenS
1个回答

2

您的代码包含:

{currentfile 3 5100 string readhexstring pop} bind

如果我们拆分并添加有关堆栈内容的注释,我们会得到:

如果我们拆分并添加有关堆栈内容的注释,我们会得到:

{
  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
}

问题在于readhexstring期望看到的是一个文件(字符串),但是栈上实际包含了3(字符串)。因为3不是文件对象,所以会出现类型检查错误。

那真的帮了很多(即使是其他我苦苦挣扎的事情)。我移除了“3”,现在一切都正常了。谢谢。 - Pranjal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接