how to color mask in c

后端 未结 4 969
自闭症患者
自闭症患者 2021-01-26 04:32

how do you color mask a 32 bit unsigned integer for the red, green, and blue values

is it like this? (color_to_be_masked>>8)

4条回答
  •  野性不改
    2021-01-26 05:22

    If you cast to char or uint8_t afterwards, it works like you said.

    Otherwise you need to add a &0xffas well, or you'll have the remaining bits too (for all but the most significant color). So, something like (color >> multiple_of_8) &0xff.

    Important detail: There is RGBA and BGRA component ordering, and there are different endiannesses on different CPUs. You must know which one you have to get it right (e.g. Windows GDI is BGRA).

提交回复
热议问题