Alexander Rolek
Alexander Rolek

Reputation: 973

Is it possible to get the area of a fill in a postscript object?

I'm currently extracting the colors of an .eps file via a .ps program. I'm trying to figure out how much each color is being used in the .eps file. Is it possible to get the area, or some measurement of the fill shape so I know how much the color is used overall in the .eps file?

My current solution is to rasterize the image and parse the histogram, but I'm trying to do this with the vector file.

Upvotes: 1

Views: 169

Answers (2)

U. Windl
U. Windl

Reputation: 4401

Maybe Ink coverage output (special ghostscript output devices) is what you actually want:

There are two special inkcov devices that print the ink coverage of each page; the inkcov device and the ink_cov device.

As an example, If we take a page which is covered by a pure 100% cyan fill both devices would give the same result 1.00 0.00 0.00 0.00; each pixel is marked by the cyan ink and each pixel contains 100% cyan. If however we use a 50% cyan fill the inkcov device will still give 1.00 0.00 0.00 0.00 as 100% of the pixels contain cyan. The ink_cov device, however, would give a result of 0.50 0.00 0.00 0.00.

Upvotes: 0

luser droog
luser droog

Reputation: 19504

To start investigating this, here's a replacement for fill which will dump the path contents to stdout.

/={=only( )print}def
/oldfill /fill load def
/fill {
    gsave
        clip
        clippath
        { exch = = (moveto\n)print }
        { exch = = (lineto\n)print }
        { 6 -1 1 { -1 roll = } for (curveto\n)print }
        { (closepath\n)print }
        pathforall
    grestore
    oldfill
} def

Upvotes: 0

Related Questions