Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we un-premultiply alpha before applying filters. #2048

Merged
merged 1 commit into from Nov 17, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -91,33 +91,22 @@ void main(void) {
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

vec4 Contrast(vec4 Cs, float amount) {
return vec4(Cs.rgb * amount - 0.5 * amount + 0.5, 1.0);
return vec4(Cs.rgb * amount - 0.5 * amount + 0.5, Cs.a);
}

vec4 Invert(vec4 Cs, float amount) {
Cs.rgb /= Cs.a;

vec3 color = mix(Cs.rgb, vec3(1.0) - Cs.rgb, amount);

// Pre-multiply the alpha into the output value.
return vec4(color.rgb * Cs.a, Cs.a);
return vec4(mix(Cs.rgb, vec3(1.0) - Cs.rgb, amount), Cs.a);
}

vec4 Brightness(vec4 Cs, float amount) {
// Un-premultiply the input.
Cs.rgb /= Cs.a;

// Apply the brightness factor.
// Resulting color needs to be clamped to output range
// since we are pre-multiplying alpha in the shader.
vec3 color = clamp(Cs.rgb * amount, vec3(0.0), vec3(1.0));

// Pre-multiply the alpha into the output value.
return vec4(color.rgb * Cs.a, Cs.a);
return vec4(clamp(Cs.rgb * amount, vec3(0.0), vec3(1.0)), Cs.a);
}

vec4 Opacity(vec4 Cs, float amount) {
return Cs * amount;
return vec4(Cs.rgb, Cs.a * amount);
}

void main(void) {
@@ -128,6 +117,9 @@ void main(void) {
discard;
}

// Un-premultiply the input.
Cs.rgb /= Cs.a;

switch (vOp) {
case 0:
oFragColor = Cs;
@@ -147,5 +139,8 @@ void main(void) {
default:
oFragColor = vColorMat * Cs;
}

// Pre-multiply the alpha into the output value.
oFragColor.rgb *= oFragColor.a;
}
#endif
@@ -0,0 +1,13 @@
---
root:
items:
- type: stacking-context
bounds: [0, 0, 120, 120]
items:
- type: rect
bounds: [0, 0, 120, 120]
color: [255, 255, 255, 1]

- type: rect
bounds: [10, 10, 100, 100]
color: [223, 223, 223, 1]
@@ -0,0 +1,13 @@
---
root:
items:
- type: stacking-context
bounds: [0, 0, 120, 120]
items:
- type: stacking-context
bounds: [10, 10, 100, 100]
filters: contrast(0)
items:
- type: rect
bounds: [0, 0, 100, 100]
color: [128, 128, 128, 0.25]
@@ -9,6 +9,7 @@
== filter-brightness-2.yaml filter-brightness-2-ref.yaml
== filter-brightness-3.yaml filter-brightness-3-ref.yaml
== filter-brightness-4.yaml filter-brightness-4-ref.yaml
== filter-contrast-gray-alpha-1.yaml filter-contrast-gray-alpha-1-ref.yaml
== filter-invert.yaml filter-invert-ref.yaml
== filter-invert-2.yaml filter-invert-2-ref.yaml
== filter-large-blur-radius.yaml filter-large-blur-radius.png
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.