How to fade color

后端 未结 8 1304
我寻月下人不归
我寻月下人不归 2021-02-06 05:56

I would like to fade the color of a pixel out toward white, but obviously maintain the same color. If I have a pixel (200,120,40), will adding 10 to each value to m

8条回答
  •  醉话见心
    2021-02-06 06:30

    You might want to check out this answer by denis:

    RGB -> ^gamma -> Y -> L*

    In color science, the common RGB values, as in html rgb( 10%, 20%, 30% ), are called "nonlinear" or Gamma corrected. "Linear" values are defined as

    Rlin = R^gamma,  Glin = G^gamma,  Blin = B^gamma
    

    where gamma is 2.2 for many PCs. The usual R G B are sometimes written as R' G' B' (R' = Rlin ^ (1/gamma)) (purists tongue-click) but here I'll drop the '.

    Brightness on a CRT display is proportional to RGBlin = RGB ^ gamma, so 50% gray on a CRT is quite dark: .5 ^ 2.2 = 22% of maximum brightness. (LCD displays are more complex; furthermore, some graphics cards compensate for gamma.)

    To get the measure of lightness called L* from RGB, first divide R G B by 255, and compute

    Y = .2126 * R^gamma + .7152 * G^gamma + .0722 * B^gamma
    

    This is Y in XYZ color space; it is a measure of color "luminance". (The real formulas are not exactly x^gamma, but close; stick with x^gamma for a first pass.)

    Finally, L* = 116 * Y ^ 1/3 - 16 "... aspires to perceptual uniformity ... closely matches human perception of lightness." -- Wikipedia Lab color space

提交回复
热议问题