Niklas created FOP-3372:
---------------------------
Summary: Write PNGs directly instead of through Image I/O for
smaller files and faster output
Key: FOP-3372
URL: https://issues.apache.org/jira/browse/FOP-3372
Project: FOP
Issue Type: Improvement
Components: renderer/png
Reporter: Niklas
When rendering PNGs, more time than necessary is spent on encoding with the
Image I/O PNG writer, and the files are larger than they need to be.
The proposed change in XML Graphics Commons adds {{{}DirectPNGEncoder{}}}.
{{PNGImageWriter}} and {{ImageIOPNGImageWriter}} use it for the common layouts
(INT_RGB/ARGB/BGR, 3BYTE_BGR, 4BYTE_ABGR, 8-bit gray, gray + alpha, and
1/2/4/8-bit palettes). This covers every FOP bitmap color mode. All other
images still go through the previous encoder. FOP needs no code changes.
* *Row filters:* none, as the PNG spec recommends for palette images. (The JDK
writer has this inverted: it filters palette images and leaves truecolor images
unfiltered. On 223 rendered FOP example pages, no filter also gave truecolor
pages the smallest files.)
* {*}Smallest color format that keeps the pixels{*}:
** 256 colors or fewer become a palette.
** An alpha channel that is opaque everywhere is dropped.
** Gray images use the smallest exact gray depth.
** Palettes use fewer bits per pixel when few entries are used.
** Off with {{{}ImageWriterParams.setPNGReduceColors(false){}}}.
* *New {{ImageWriterParams}} settings:* deflate level and {{PNGFilter}} (NONE,
SUB, UP, AVERAGE, PAETH, ADAPTIVE).
* *Defaults:* deflate level 4, the default of the Image I/O writer since Java
9. Before Java 9 the writer always used level 9, so on Java 8 pages that can't
be reduced (8-bit gray, RGB with more than 256 colors) may come out up to about
10% larger than before, in much less time though.
h3. Results
Stock FOP main, {{{}report.fo{}}}, Java 24, one thread; times from a single run.
||Color mode||Render time per page||File size||
|rgba (default), 72 dpi|35.6 → 19.7 ms (−45%)|25,908 → 13,983 bytes (−46%)|
|rgb, 72 dpi|30.4 → 19.9 ms (−35%)|24,957 → 13,983 bytes (−44%)|
|rgba, 300 dpi|172.8 → 58.3 ms (−66%)|180,304 → 94,466 bytes (−48%)|
|binary, 300 dpi|42.7 → 31.1 ms (−27%)|26,567 → 26,579 bytes|
|gray / binary, 72 dpi|within measurement noise|unchanged|
Decoded pixels are identical in all modes.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)