pdftocairo inconsistent color rendering
I am bumping into the issue of certain colors being changed during conversion (colors in resulting png differ from original pdf).
Steps to reproduce
Test file contains three sets of hex numbers (one set for each color component), each number is written in respective color (e.g. 42
in blue paragraph has #000042
color).
- generating PDF file using
xelatex
(optional) test.tex
xelatex test.tex
- converting pdf to png (no aliasing, transparent background) test.pdf
pdftocairo -transp -r 300 -antialias none -png test.pdf test
Observations
Most of the colors are rendered correctly, only the following colors with specific value of any of the component cause the issue. I have inspected the contents of PDF and looked for stroke and fill color values (rg
and RG
tags).
TEX value | PDF value | PNG value |
---|---|---|
07 | 0.027 | 06 |
08 | 0.031 | 07 |
09 | 0.035 | 08 |
0a | 0.039 | 09 |
14 | 0.078 | 13 |
15 | 0.082 | 14 |
ea | 0.918 | eb |
eb | 0.922 | ec |
f5 | 0.961 | f6 |
f6 | 0.965 | f7 |
f7 | 0.969 | f8 |
f8 | 0.973 | f9 |
xelatex
seems to convert RGB 0-255 color component c
using sprintf(_, '%.3f', (c / 255.0))
. The conflicting values are symmetrical (07
-15
correspond to f8
-ea
). Eventhough the value in PDF is not the exactly the original one i would expect the converted color to be closest match - i.e. the correct color.
I was unable to trace the whole conversion code and potential origin of the issue in poppler library. Hope it will be
NB: my pdftocairo version is 0.62.0, reading the changelog I did not found any change in newer versions relating to this issue.