logoalt Hacker News

darkwater • today at 10:13 PM • 1 reply • view on HN

Out of curiosity, how do you compare your rendering output to the ground truth rendering? It's probably a naive question but I have zero knowledge on this domain and I'm curious to learn!


Replies

RedMindZ • today at 10:35 PM

Very reasonable question!

On Pryzmera's side, the same way it renders to the window, it can render to an image file instead (PNG). On the "ground truth" side, I use mutool (based on MuPDF) to render the same PDF into another image file. Both renders are configured to use the same resolution, and then they can be compared pixel-by-pixel. Pixels are simply 3 numbers, representing the intensity of the red, green, and blue colors in the pixel. Each one of those can be directly compared to the same color in the other pixel by simply calculating their absolute difference (AKA |red1 - red2|). You can also use other functions here, like squared distance and such. All of the differences are summed to give you the error for each pixel, and then you can measure different metrics, like the pixel with the biggest error in the image, or the average pixel error for the image.

One note about "ground truth": When it comes to PDF rendering, the specification is incredibly long and complicated, which means there is basically not a single renderer that renders PDFs 100% correctly, even Acrobat likely has bugs. Thus, the output for each renderer is usually slightly different, especially around weird edge cases. For that reason, "whatever Acrobat does" has often times become the effective specification.

And if you have any other questions, please don't hesitate to ask!