

I tried adding a Dark Reader mode to Okular. Here's where I got stuck.
I was experimenting with adding a Dark Reader–style mode to Okular for PDF documents.
The goal was to darken the page while keeping embedded images untouched. The existing accessibility color modes recolor every pixel, so photos, screenshots, and other raster images also get inverted or recolored, which isn't ideal.
My first implementation worked by post-processing the rendered page. Since Poppler gives you a flattened bitmap through renderToImage(), I used a simple chroma heuristic: recolor near-grayscale pixels (assuming they're text/background) and leave colorful pixels alone. It actually worked reasonably well, but grayscale or muted-color images could still get recolored, which is an unavoidable limitation of that approach.
So I tried to be more hacky.
Instead of modifying the final rasterized image, I tried working inside Poppler before everything gets flattened. From what I understood, poppler-qt6 only exposes Page::renderToImage(), but Poppler's core library has the OutputDev API (SplashOutputDev, CairoOutputDev, etc.), where the renderer still knows whether it's drawing text, vector graphics, or embedded images. My idea was to hook in there so I could recolor only text/vector content while leaving raster images completely untouched.
Unfortunately, I couldn't get it working the way I wanted. The result was basically just a grayscale/black-and-white rendering instead of the Dark Reader–style effect I was aiming for.
Has anyone here worked with Poppler's OutputDev API or implemented something similar? Is this the right direction, or is there a better approach for separating text/vector content from images during rendering?
The code is here if anyone is curious or wants to point out where I'm going wrong:
https://github.com/JustBipin/okular
Note: I'm not familiar with the C++ ecosystem at all, so I leaned pretty heavily on Zed Editor's free AI to help build the feature. I eventually ran out of free usage though. 😿 Any guidance from people who know Poppler or Okular's rendering pipeline would be greatly appreciated.