Differences between revisions 3 and 4
Revision 3 as of 2012-06-15 14:16:50
Size: 2059
Editor: LuisBernardo
Comment:
Revision 4 as of 2014-09-03 09:43:08
Size: 2196
Editor: LuisBernardo
Comment: removed line that disabled default image loader, to avoid confusing users
Deletions are marked like this. Additions are marked like this.
Line 8: Line 8:
    <penalty value="INFINITE" class="org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO" />
Line 22: Line 21:
Note that in the above example the ImageLoaderPNG and the ImageLoaderImageIO image loaders were disabled. The penalty of -10000 (reverse penalty) compensates the default penalty of 1000, and makes the ImageLoaderRawPNG image loader the preferred one. Note that in the above example the ImageLoaderPNG image loader has been disabled. The penalty of -10000 (reverse penalty) compensates the default penalty of 1000, and makes the ImageLoaderRawPNG image loader the preferred one (the default image loader, org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO, has no intrinsic penalty).
Line 24: Line 23:
The ImageLoaderPNG image loader is similar to the ImageLoaderImageIO one, in the sense that it also decodes the IDAT chunk, but it does so using the org.apache.xmlgraphics.image.codec.png.PNGImageDecoder class instead of com.sun.imageio.plugins.png.PNGImageReader class. The ImageLoaderPNG image loader is similar to the ImageLoaderImageIO one, in the sense that it also decodes the IDAT chunk, but it does so using the org.apache.xmlgraphics.image.codec.png.PNGImageDecoder class instead of com.sun.imageio.plugins.png.PNGImageReader class. In practical terms, it offers no advantages over the default ImageLoaderImageIO, except in situations where a JVM does not offer a PNG image reader.

XMLGraphicsCommons includes an image loader for raw PNG. This means the PNG bytes from the IDAT chunk can be embedded in the output format (PDF and PS for now) without the need to decode them. Note that usually the decoding would revert the filter applied to the image bytes (this is a filter applied before compression to make the PNG files smaller) resulting in larger files and sometimes a performance impact (reverting some filters, in particular the Paeth filter, is generally expensive).

The ImageLoaderRawPNG is not selected (it has an intrinsic penalty of 1000) by default since it does not handle all kinds of PNG images. As of this writing it only supports images with 8 bits per channel (which are most of the PNG images), without interlacing. To enable the image loader a negative penalty needs to be awarded to it in the FOP configuration file (fop.xconf):

  <image-loading>
    <penalty value="-10000" class="org.apache.xmlgraphics.image.loader.impl.ImageLoaderRawPNG" />
    <penalty value="INFINITE" class="org.apache.xmlgraphics.image.loader.impl.ImageLoaderPNG" />
  </image-loading>
  <renderers>
    <renderer mime="application/pdf">
      <filterList>
        <value>flate</value>
      </filterList>
      <xmlHandler mime="text/svg+xml"/>
    </renderer>
    <renderer mime="application/postscript">
      <xmlHandler mime="text/svg+xml"/>
    </renderer>
  </renderers>

Note that in the above example the ImageLoaderPNG image loader has been disabled. The penalty of -10000 (reverse penalty) compensates the default penalty of 1000, and makes the ImageLoaderRawPNG image loader the preferred one (the default image loader, org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO, has no intrinsic penalty).

The ImageLoaderPNG image loader is similar to the ImageLoaderImageIO one, in the sense that it also decodes the IDAT chunk, but it does so using the org.apache.xmlgraphics.image.codec.png.PNGImageDecoder class instead of com.sun.imageio.plugins.png.PNGImageReader class. In practical terms, it offers no advantages over the default ImageLoaderImageIO, except in situations where a JVM does not offer a PNG image reader.

HowTo/ImageLoaderRawPNG (last edited 2014-09-03 09:43:08 by LuisBernardo)