Re: PNG loading time
Karl Berry <[email protected]>
| Newsgroups | gmane.comp.tex.live |
|---|---|
| Message-ID | <[email protected]> |
BTW: the pdftex manual gives (thanks to Hans, I believe) two specific
cases that disable copying: interlaced PNGs, and PNGs using gamma
correction.
I confess I did not delve into the details of the other cases you and
Hartmut mentioned (cHRM, bKGD, "colortype 3 palettes"), but I mentioned
them in the manual anyway, along with RGBA. --thanks, karl.
%%%%%%%%%%%%%%%%%%%%%%%%
\section{\PNG\ graphics}
The lossless compressing \PNG\ format is useful for embedding crisp
pixel graphics (\eg\ line scans, screenshots). As of \PDFTEX\ 1.30.0,
the alpha channel of \PNG\ images is processed if available; this allows
embedding of images with simple transparency. The \PNG\ format does not
support the CMYK color model, which is sometimes required for print
media (this often can be replaced by four component \JPEG\ in high
quality or lossless compression mode). Photos in \PNG\ format have
rather poor compression; for that, \JPEG\ format is preferable.
Embedding \PNG\ images in the general case requires \PDFTEX\ to
uncompress the pixel array and then re\hyph compress it to the \PDF\
format's requirements; this can take a noticeable amount of time. Since
\PDFTEX\ 1.30.0 there is also a fast \PNG\ embedding mode that does not
need uncompressing: the image data are directly copied into the \PDF\
stream, resulting in a much higher embedding speed. This direct-copy
mode can only be used if the image array structure of the \PNG\ file is
compatible with the \PDF\ image structure; \eg\ an interlaced \PNG\
image requires uncompressing to rearrange the image lines. The use of
gamma correction also disables fast copying, as it requires calculations
with individual pixels.
Whether the fast copy mode is used for a \PNG\ image can be seen from
the log file, which then shows the string `(PNG copy)' after the \PNG\
file name. Further, as of \PDFTEX\ 1.40.29 (2026), if the environment
variable \type{TEXMF_DEBUG_PNG_COPY} is set to 1, \PDFTEX\ reports
various attributes of each \PNG\ image as well as whether it was copied.
Thus it's possible to discern why a given image was not copied, and
perhaps do mass conversions beforehand to speed up the \PDFTEX\ run. See
the mailing list thread around
\url{https://tug.org/pipermail/tex-live/2026-February/052105.html} for
some conversion incantations and other PNG image attributes which
prevent copying (some keywords: RGBA, cHRM, bKGD, colortype~3 palettes).