Converting an RGBW color to a standard RGB/HSB representation

前端 未结 3 1159
不知归路
不知归路 2021-01-03 02:14

I am building an interface for light management in a home automation system. I managed to control standard on/off and dimmable light for various providers with little proble

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 03:20

    I have been reviewing the answer suggested by Roberto but the colors seemed dimmer and undersaturated in many cases. Taking the example of RGB = (255,255,2) leads to RGBW = (128,128,1,2).

    Digging further, it seems that the paper by Chul Lee has an error in its equation for K. The equation, which comes from a paper by Lili Wang ("Trade-off between luminance and color in RGBW displays for mobile-phone usage") is actually:

    K = (Wo + M)/M
    

    Note that it is a capital M, not a lowercase m. Given this change, you also do not need Q since it scales properly by nature. Using the new K on the same RGB = (255,255,2) example leads to a much more reasonable RGBW = (255,255,0,2).

    Putting it all together:

    M = max(Ri,Gi,Bi)
    m = min(Ri,Gi,Bi)
    
    Wo = if (m/M < 0.5) use ( (m*M) / (M-m) ) else M 
    K = (Wo + M) / M
    Ro = floor[ ( K * Ri ) - Wo ]
    Go = floor[ ( K * Gi ) - Wo ]
    Bo = floor[ ( K * Bi ) - Wo ]
    

提交回复
热议问题