Color blending functions with transparency. #1704
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Color blending functions now respect alpha channel with compositing and blending implemented according to this W3C draft.
Changed functions:
This update is a "breaking changes" one. Backward compatibility:
softlight
mode whose formula is gently different.This patch does not add any new functions. The referenced specification defines some additional blending modes not present in LESS but this is a subject for another feature-request/update and needs further discussions/decisions.
Differences from the W3C spec.:
The functions do not clamp their output (as well as input) color values despite the spec. states that:
Just like the old blending functions do not (as well as color operations). The rationale behind this is to allow intermediate out-of-range values inside multiple color op/blend chains e.g.:
So this update assumes that color values are clipped on final CSS output (i.e. #1693, also related #1676).
Well, in general, this whole thing of "clamping or not clamping of intermediate results" needs further discussion and may require some further changes/updates/fine-tuning, but it's somewhat out this patch scope (again) since we need to review that functionality in context of all color functions, conversions and whatever related things (for instance, contrary to color math ops and blending functions, the "Color Operations" functions like
saturate
always clamp their input and output values. So ideally, we'd probably like this all to be somehow unified eventually).P.S. It is actually possible to fine-tune the new functions to output exactly the same as old values on rounding when non-transparent colors are passed in (for example the simplest way would be to just requantize the result to some reasonable precision by using something like
r[i] = Math.round(cr * 2550000) / 10000;
in this line). But I did not bother with this to keep the code "clean" since the whole patch is "breaking changes" anyway.