Why are images sometimes inverted in SVG output?

Skip to first unread message

Aaron Gravesdale

Nov 20, 2013, 4:02:32 PM11/20/13
to pdfne...@googlegroups.com

In the generated SVG file, in the “Image” Element, and in the attributes “xlink:href”, sometimes  the value contains “_msk”.  Then the associated image is a sort of negative; its colours are the inverse of the image in the source PDF.

For example, the SVG contains this output:

<mask id="msk7" maskUnits="userSpaceOnUse" x="0" y="0" width="1" height="1">
<image width="1" height="1" preserveAspectRatio="none" image-rendering="optimizeSpeed" xlink:href="foobar_msk7.png"/>

Why are the colours inverted?  Is the non-inverted image available?  How can we test whether or not the image is inverted?


These are image masks, which will appear inverted if you view them as images.  From the PDF specification:

An image mask (an image XObject whose ImageMask entry is true) is a monochrome image, in which each sample is specified by a single bit. However, instead of being painted in opaque black and white, the image mask is treated as a stencil mask that is partly opaque and partly transparent. Sample values in the image do not represent black and white pixels; rather, they designate places on the page that should either be marked with the current color or masked out (not marked at all).  Areas that are masked out retain their former contents. The effect is like applying paint in the current color through a cut-out stencil, which allows the paint to reach the page in some places and masks it out in others.

Only the image mask exists -- no "non-inverted" version of the image exists.

The <image> tag is within a <mask> tag.  Use that to test whether the image is inverted.

Reply all
Reply to author
0 new messages