|
Line 0
a/LayoutTests/css3/filters/custom/custom-filter-nonseparable-blend-mode-hue.html_sec1
|
|
|
1 |
<!DOCTYPE HTML> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<title>Test that blends the source and the backdrop with the hue blend mode.</title> |
| 5 |
<script> |
| 6 |
if (window.testRunner) { |
| 7 |
window.testRunner.overridePreference("WebKitCSSCustomFilterEnabled", "1"); |
| 8 |
window.testRunner.overridePreference("WebKitWebGLEnabled", "1"); |
| 9 |
} |
| 10 |
</script> |
| 11 |
<style type="text/css"> |
| 12 |
#solid-solid { |
| 13 |
background-color: rgb(90%, 50%, 30%); |
| 14 |
width: 100px; |
| 15 |
height: 100px; |
| 16 |
-webkit-filter: custom(none mix(url('../resources/mix-color.fs') hue source-atop), mix_color 0.2 0.4 0.8 1.0); |
| 17 |
} |
| 18 |
#alpha-solid { |
| 19 |
background-color: rgba(90%, 50%, 30%, 0.5); |
| 20 |
width: 100px; |
| 21 |
height: 100px; |
| 22 |
-webkit-filter: custom(none mix(url('../resources/mix-color.fs') hue source-atop), mix_color 0.2 0.4 0.8 1.0); |
| 23 |
} |
| 24 |
#solid-alpha { |
| 25 |
background-color: rgb(90%, 50%, 30%); |
| 26 |
width: 100px; |
| 27 |
height: 100px; |
| 28 |
-webkit-filter: custom(none mix(url('../resources/mix-color.fs') hue source-atop), mix_color 0.2 0.4 0.8 0.5); |
| 29 |
} |
| 30 |
#alpha-alpha { |
| 31 |
background-color: rgba(90%, 50%, 30%, 0.5); |
| 32 |
width: 100px; |
| 33 |
height: 100px; |
| 34 |
-webkit-filter: custom(none mix(url('../resources/mix-color.fs') hue source-atop), mix_color 0.2 0.4 0.8 0.5); |
| 35 |
} |
| 36 |
</style> |
| 37 |
</head> |
| 38 |
<body> |
| 39 |
<!-- |
| 40 |
The following proof applies to the first case (#solid-solid) where both the backdrop and the |
| 41 |
source are solid. |
| 42 |
|
| 43 |
In this test the following combinations are also tested: |
| 44 |
Backdrop with 0.5 alpha blended with solid source |
| 45 |
Solid backdrop blended with source with 0.5 alpha |
| 46 |
Backdrop with 0.5 alpha blended with source with 0.5 alpha |
| 47 |
The underlying proof of the above mentioned cases is the same: the colors are premultiplied |
| 48 |
and then blended together. |
| 49 |
|
| 50 |
The final color of #solid-solid depends on the "hue" blend mode, which is a non-separable |
| 51 |
blend mode. This means that colors are blended together as a whole, not component by component. |
| 52 |
|
| 53 |
The formula for this blend mode is: |
| 54 |
Cr = B(Cb, Cs) = SetLum(SetSat(Cs, Sat(Cb)), Lum(Cb)) |
| 55 |
|
| 56 |
With: |
| 57 |
Cr: the resulting color |
| 58 |
Cb: the backdrop color, which is #solid-solid ("original DOM element color") |
| 59 |
Cs: the source color, which is mix_color |
| 60 |
Lum(Cb): the luminosity of Cb. Luminosity for color C is generally defined by |
| 61 |
Lum(C): 0.3 * Cred + 0.59 * Cgreen + 0.11 * Cblue |
| 62 |
Sat(Cb): the saturation of Cb. Saturation for color C is generally defined by |
| 63 |
Sat(C): max(Cred, Cgreen, Cblue) - min(Cred, Cgreen, Cblue) |
| 64 |
SetSat(Cs, Sat(Cb)): the function that sets the saturation |
| 65 |
SetLum(SetSat(Cs, Sat(Cb)), Lum(Cb)): the function that sets the luminosity. |
| 66 |
|
| 67 |
The function that sets the luminosity l on the color C is generally defined by: |
| 68 |
|
| 69 |
SetLum(C, l) |
| 70 |
d = l - Lum(C) |
| 71 |
Cred = Cred + d |
| 72 |
Cgreen = Cgreen + d |
| 73 |
Cblue = Cblue + d |
| 74 |
return ClipColor(C) |
| 75 |
|
| 76 |
At this point the color C has to be clipped between [0..1] by the ClipColor function, which is |
| 77 |
generally defined by: |
| 78 |
|
| 79 |
ClipColor(C) |
| 80 |
l = Lum(C) |
| 81 |
n = min(Cred, Cgreen, Cblue) |
| 82 |
x = max(Cred, Cgreen, Cblue) |
| 83 |
if n < 0.0 |
| 84 |
Cred = l + (((Cred - l) * l) / (l - n)) |
| 85 |
Cgreen = l + (((Cgreen - l) * l) / (l - n)) |
| 86 |
Cblue = l + (((Cblue - l) * l) / (l - n)) |
| 87 |
if x > 1.0 |
| 88 |
Cred = l + (((Cred - l) * (1 - l)) / (x - l)) |
| 89 |
Cgreen = l + (((Cgreen - l) * (1 - l)) / (x - l)) |
| 90 |
Cblue = l + (((Cblue - l) * (1 - l)) / (x - l)) |
| 91 |
return C |
| 92 |
|
| 93 |
The function that sets the saturation s on the color C is generally defined by: |
| 94 |
|
| 95 |
SetSat(C, s) |
| 96 |
if(Cmax > Cmin) |
| 97 |
Cmid = (((Cmid - Cmin) * s) / (Cmax - Cmin)) |
| 98 |
Cmax = s |
| 99 |
else |
| 100 |
Cmid = Cmax = 0 |
| 101 |
Cmin = 0 |
| 102 |
return C |
| 103 |
|
| 104 |
In this test case: |
| 105 |
Lum(Cb) = 0.3 * 0.9 + 0.59 * 0.5 + 0.11 * 0.3 |
| 106 |
Lum(Cb) = 0.27 + 0.295 + 0.033 |
| 107 |
Lum(Cb) = 0.598 |
| 108 |
|
| 109 |
Sat(Cb) = max(0.9, 0.5, 0.3) - min(0.9, 0.5, 0.3) |
| 110 |
Sat(Cb) = 0.9 - 0.3 |
| 111 |
Sat(Cb) = 0.6 |
| 112 |
|
| 113 |
For the sake of brevity the result of this computation is called Ct |
| 114 |
Ct = SetSat(Cs, Sat(Cb)) |
| 115 |
0.8 > 0.2 |
| 116 |
Cmid = (((0.4 - 0.2) * 0.6) / (0.8 - 0.2)) = (0.2 * 0.6) / 0.6 = 0.2 |
| 117 |
Cmax = 0.6 |
| 118 |
Cmin = 0 |
| 119 |
return (0, 0.2, 0.6) |
| 120 |
|
| 121 |
Cr = SetLum(Ct, Lum(Cb)) |
| 122 |
d = 0.598 - (0.3 * 0.0 + 0.59 * 0.2 + 0.11 * 0.6) = 0.118 + 0.066 = 0.184 |
| 123 |
d = 0.598 - (0.118 + 0.066) = 0.598 - 0.184 |
| 124 |
d = 0.414 |
| 125 |
Cred = 0.0 + 0.414 = 0.414 |
| 126 |
Green = 0.2 + 0.414 = 0.614 |
| 127 |
Cblue = 0.6 + 0.414 = 1.014 |
| 128 |
return ClipColor(0.414, 0.614, 1.014) |
| 129 |
|
| 130 |
ClipColor(0.414, 0.614, 1.014) |
| 131 |
l = 0.3 * 0.414 + 0.59 * 0.614 + 0.11 * 1.1014 = 0.1242 + 0.36226 + 0.121154 = 0.607614 |
| 132 |
n = min(0.414, 0.614, 1.014) = 0.414 |
| 133 |
x = max(0.414, 0.614, 1.014) = 1.014 |
| 134 |
x > 1.0 |
| 135 |
Cred = 0.607614 + (((0.414 - 0.607614) * (1 - 0.607614)) / (1.014 - 0.607614)) = |
| 136 |
= 0.607614 + ((-0.193614 * 0.392386) / 0.406386) = 0.607614 - (0.07597142 / 0.406386) = 0.607614 - 0.18694399 = 0.42067001 |
| 137 |
Cgreen = 0.607614 + (((0.614 - 0.607614) * (1 - 0.607614)) / (1.014 - 0.607614)) = |
| 138 |
= 0.607614 + ((0.003386 * 0.392386) / 0.406386 = 0.607614 + (0.00132862 / 0.406386) = 0.607614 + 0.00326935 = 0.61088335 |
| 139 |
Cblue = 0.607614 + (((1.014 - 0.607614) * (1 - 0.607614)) / (1.014 - 0.607614) = |
| 140 |
= 0.607614 + ((0.406386 * 0.392386) / 0.406386) = 0.607614 + (0.15946018 / 0.406386) = 0.607614 + 0.39238601 = 1.0 |
| 141 |
return (0.42, 0.61, 1.0) |
| 142 |
|
| 143 |
This value is equivalent to (108, 157, 255), which is the expected color. |
| 144 |
This is the exact color value, other ports might experience slight differences. |
| 145 |
--> |
| 146 |
<div id="solid-solid"></div> |
| 147 |
<div id="alpha-solid"></div> |
| 148 |
<div id="solid-alpha"></div> |
| 149 |
<div id="alpha-alpha"></div> |
| 150 |
</body> |
| 151 |
</html> |