'Tiger' renders with the wrong colours?
g40 opened this issue · comments
BGR -> RGB
Indeed. That could explain it. But there is not much space in this code in which to make such a mistake:
filename = "tiger.svg";
auto document = lunasvg::Document::loadFromFile(filename);
auto bitmap = document->renderToBitmap(width, height, bgColor);
filename += _T(".png");
stbi_write_png(filename.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
Certainly, it looks like adding bitmap.convertToRGBA();
before saving the PNG would ensure the correct format. Here's the adjusted code:
filename = "tiger.svg";
auto document = lunasvg::Document::loadFromFile(filename);
auto bitmap = document->renderToBitmap(width, height, bgColor);
bitmap.convertToRGBA(); // Add this line to ensure correct format
filename += _T(".png");
stbi_write_png(filename.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
This should help ensure that the bitmap is in the RGBA format before saving it as a PNG.
@sammycage Thank you. It's just slightly confusing.
What is the native internal color format then? Does it vary according to platform?
For example, https://github.com/g40/lunasvg/blob/master/svg2png.cpp calls bitmap.convertToRGBA()
which implies something else.