sammycage / lunasvg

lunasvg is a standalone SVG rendering library in C++
MIT License
818 stars 115 forks source link

Colour format/conversion clarification. #146

Closed g40 closed 6 months ago

g40 commented 7 months ago

Can we clarify natural colour order please?

Following on from https://github.com/sammycage/lunasvg/issues/144: lunasvg.h has this comment:

* @note Bitmap format is ARGB32 Premultiplied.

There is also a convert function which rewrites the bitmap colour ordering according to the function arguments:

void convertToRGBA() { convert(0, 1, 2, 3, true); }

which definitely works but convert() has the code below which indicates the internal pixel arrangement is BGRA?

Or (entirely likely) have I missed something?

           auto b = data[0];
           auto g = data[1];
           auto r = data[2];
           auto a = data[3];

as does clear() (https://github.com/sammycage/lunasvg/blob/master/source/lunasvg.cpp#L80)

sammycage commented 7 months ago

Each pixel is a 32-bit quantity, with alpha in the upper 8 bits, then red, then green, then blue. The 32-bit quantities are stored native-endian. Pre-multiplied alpha is used. (That is, 50 transparent red is 0x80800000, not 0x80ff0000.). In short Bitmap format is BGRA(Pre-multiplied) in little endian machine and ARGB(Pre-multiplied) in big endian machine.