[poppler] Set color space in poppler-cpp

Jakub Kucharski jakubkucharski97 at gmail.com
Sun Aug 28 12:54:31 UTC 2016


On Sun, 2016-08-28 at 10:05 +0200, Jeroen Ooms wrote:
> Is there an option in poppler-cpp 'page_renderer' to output RGBA
> instead of BGRA?

Are you talking about page_renderer::render_page()? Judging from the
source code: no. Here is the relevant part:

SplashColor bgColor;
bgColor[0] = d->paper_color & 0xff;
bgColor[1] = (d->paper_color >> 8) & 0xff;
bgColor[2] = (d->paper_color >> 16) & 0xff;
SplashOutputDev splashOutputDev(splashModeXBGR8, 4, gFalse, bgColor, gTrue);

So it doesn't look like there was an option. If you later call
poppler::image::save() and save the image as a PNG file, it is
translated in this function like this:

rowptr[0] = (pixel >> 16) & 0xff;
rowptr[1] = (pixel >> 8) & 0xff;
rowptr[2] = pixel & 0xff;

So if you want to manually edit the bitmap, you have to use BGRA. If you want to edit it with a library, that does it only on RGBA, you have to convert it yourself. If you just want to save it as a file, it shouldn't be a problem.

Now, my question to Pino would be: why does page_renderer::render_page() discard the "alpha" part of BGRA? AFAIC it leaves this byte uninitialized. And then image::save() discards it as well, and the resulting PNG file always has a solid background color regardless of the value passed to page_renderer::set_paper_color(). Or am I missing something? If this is a bug, I can find some time to work on it.

Jakub


> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/poppler



More information about the poppler mailing list