-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Support different Gradient modes for Color gradient brushes #22
Comments
@jongleur1983 We don't actually calculate the intermediate color that way anymore. |
thanks @JimBobSquarePants changed the description accordingly. Did not meant to close this issue, sorry for that. Not sure how to undo the stuff the automation did as a result... |
@jongleur1983 Don't worry about it mate. I closed another one with a commit message the other day by accident! |
Revisiting this after several years. Hard edges can already be achieved. It works like CSS gradients in that you add additional stops. For example, the following stops were used to generate the above image. new ColorStop(0, Color.Red),
new ColorStop(0.5f, Color.Red),
new ColorStop(0.5f, Color.Yellow),
new ColorStop(1f, Color.Yellow) The difference between 3 and 4 is the result of gamma handling. We can mimic 3 by transforming the colors to the linear equivalent. CSS defaults to our approach though for RGB as it's interpreted as sRGB. |
In general Gradients from colorA to colorB can have different styles, e.g. gradienting around the color-wheel (clockwise, counter-clockwise), gradienting in a straight line in the color cube or something else.
A sample for that can be seen in Gimp, that has the following options (condensed to those relevant for ImageSharp Gradients):
Translated to English:
Option 3 and 4 don't differ on the red-to-yellow example, but do on green-to-red:
Up to now there's no option on how to calculate the gradients yet.
Currently we calculate an intermediate color by this code:
https://github.com/SixLabors/ImageSharp/blob/133d90879b17577032a4cc165014915c0829540e/src/ImageSharp.Drawing/Processing/GradientBrush.cs#L121
If I'm not mistaking that's how option 4 from GIMP works.
With the options from the GIMP example above this would be exchanged by
HardEdge:
onLocalGradient > 0.5 ? toAsVector : fromAsVector
for HsvClockwise and HsvCounterClockwise the logic basically would be
Conversion HSV<>RGB is already implenmented in HsvAndRgbConverter.cs
The text was updated successfully, but these errors were encountered: