Bug 692275 - Support rendering a part (subrectangle) of a document
Summary: Support rendering a part (subrectangle) of a document
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 8.71
Hardware: PC Linux
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-12 12:19 UTC by whiskey
Modified: 2011-06-12 14:35 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description whiskey 2011-06-12 12:19:20 UTC
For my postscript-viewer I need to render part (the visible rectangle) of a page
into a .png-file.

Zooming works fine, but so far I can only render the whole page.
Rendering only the interesting rectangle would speed things up
(maybe not the rendering but my image loading code).

Is that already possible (I spent hours searching the docs)?
Could that possibility be added?


Note:
When rendering to the x11 device, one can communicate the "bounding box"(?)
vie X11-atoms and thus restrict the rendered part.
Using png12m as output device this does not work. (Moreover a
commandline switch would be way more convenient than having to code X11 calls.)


Short version:
Can
gs -dSAFER -dQUIET -sDEVICE=png16m -sOutputFile=/tmp/x.png
   -r96x96 -dTextAlphaBits=4 -dGraphicsAlphaBits=4
   -dNOPLATFONTS -dNOPAUSE -dBATCH  x.ps
be augmented by some options (or environment variable) such that
/tmp/x.png contains not the whole page but only a subrectangle?
I am thinking of something like a (new?) option:
  -sBBOX=100,100,400,500
that allows to specify the rectangle that should be contained
in the output file.


Best regards
Christoph
Comment 1 Ray Johnston 2011-06-12 14:35:23 UTC
If the document is an EPS file that has %%BoundingBox: comments, then
-dEPSCrop will do this automatically.

For general PostScript you can set the page size to a a width height using
-gWxH (where W and H are in pixels).

You can move the origin up to the interesting port part of the page by
using the 'translate' operator to move the graphics down.

If the 100,100 lower region in the example was in points (1/72 inch) and
the 400,500 is the upper right corner (also in points), then the origin
needs to be at (100*96/72=133.3333) assuming -r96 is being used for the png
and the page size in pixels will be 400 by 534 pixels (rounding 533.333 up)

thus this command line would be used:
gs -q -sDEVICE=png16m -r96 -g400x534 -dNOPLATFONTS -dTextAlphaBits=4 \
   -dGraphicsAlphaBits=4 -o /tmp/x.png \
   -c "<< /Install { -133.3333 dup translate } >> setpagedevice" x.ps

The magic "Install" procedure establishes the 'initgraphics' CTM for PS
and is standard PostScript straight out of the PLRM.

This isn't a bug, so closing as "FIXED" by this example.

Next time try asking someone on comp.lang.postscript or IRC #ghostscript or
stackoverflow.