Search code examples
limiteps

Encapsulated poscript max line limit


I think that I'm exceeding EPS max line limits: I'm generating an eps programmatically that consists of a grid of pictures. My EPS has this structure:

%!PS-Adobe-3.0 EPSF-3.0
.
.
%%BeginProlog
%%EndProlog
%%Page: 1 1
%%Begin Raster Image. Index: 0
save
449 2576 translate
0 rotate
-282 -304 translate
[1 0 0 1 0 0] concat
0 0 translate
[1 0 0 1 0 0] concat
0 0 translate
userdict begin
DisplayImage
0 0
564 608
12
564 608
0
0

FBDBB9FBDCBCFDDBBAFFD8B2FFD7A9FED4A1FCD29CFDD09EFED0A2FFD0A6FFCDA3FFCBA0FFCBA0...
EED79CEBD09CEDD19EEED2A1EFD3A3F0D4A5F0D4A6F0D4A7F1D4A4F3D4A0F3D49F
end
restore
%%End Raster Image
%%Begin Raster Image. Index: 1
.
.
end
restore
%%End Raster Image
%%Begin Raster Image. Index: 2
etc

So the thing is if I write up to 4 images to the EPS, everything works fine, but when I try to write a 5th, the eps won't open on any EPS viewer including Adobe Illustrator (the operation cannot complete because of an unknown error). I tried using different images to make sure that the particular images were ok and I got the same result, as long as I'm writing 4 images (105825 lines file) everything works. But when I use 5 (132253 lines file) it fails.

Is it possible that I'm exceeding the maximum line limit for EPS? This are the files in question if you'd like to analyze them: the one that works - >https://files.fm/u/bfn2d32m and the one that doesn't -> https://files.fm/u/4gbybr3y


Solution

  • There's no 'line limit' in PostScript or EPS, so you can't be hitting that.

    When I run your file through Ghostscript it throws an error /undefined in yImage (I'd suggest you debug PostScript using a proper PostScript interpreter, not Adobe Illustrator).

    This suggests to me that one of your images is using more data than you have supplied, so the interpreter runs off the end of the data, consuming parts of the program, until it has read sufficient bytes from currentfile to satisfy the request. At that point is starts processing the file as PostScript again, but the file pointer now points to the 'yImage' of the next 'DisplayImage'. Since you haven't defined a 'yImage' key, naturally this gives you an 'undefined' error.

    From your description, this would seem likely to be the 4th image, since adding the 5th throws the error. Note that if your program terminates without supplying enough data (so the interpreter reaches EOF) then the data supplied will be drawn. So it might look like your 4th image is correct even when it isn't, provided it isn't followed by any further program code.

    A style note; PostScript is a stack-based language, so normally one would proceed by pushing values onto the stack and reading them from there, instead of executing the 'token' operator.

    So your input would be more like :

    0 0
    564 608
    12
    564 608
    0
    0
    DisplayImage
    FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
    ...
    

    And the DisplayImage code would be :

    /DisplayImage
    {
        %
        % Display a DirectClass or PseudoClass image.
        %
        % Parameters:
        %   x & y translation.
        %   x & y scale.
        %   label pointsize.
        %   image label.
        %   image columns & rows.
        %   class: 0-DirectClass or 1-PseudoClass.
        %   compression: 0-none or 1-RunlengthEncoded.
        %   hex color packets.
        %
        gsave
        /buffer 512 string def
        /byte 1 string def
        /color_packet 3 string def
        /pixels 768 string def
    
        /compression exch def
        /class exch def
        /rows exch def
        /columns exch def
        /pointsize exch def
        scale
        translate
    

    This avoids you having to use token at all for the scale and translate operations for instance.