-
-
Notifications
You must be signed in to change notification settings - Fork 855
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
Porter-Duff enumaration split in two #535
Comments
@vpenades You definitely know a lot more about this than I do. Fancy giving a PR a go? |
@JimBobSquarePants Right now my hands are full at work and on another side project... maybe I could try to do something in two weeks if nobody else picks the task. Just did a fast overview of the code, and it implies changing the T4 template generators so they can produce more pixel blender combinations. |
Leave as much detail as you can here describing the required changes and we'll see what we can do. A bit rushed myself just now so completely understand. |
Ok, here's more or less: The current set of PixelBlenders generated with the T4 has two flavours:
So it's like if you have a NxM, but only Nx1 and 1xM combinations are being generated. The current pixel blender generators look like this: // Color blenders using alpha "SourceOver" composition
GeneratePixelBlender("Multiply");
GeneratePixelBlender("Add");
GeneratePixelBlender("Subtract");
.
.
// Alpha composers using "Source" color
GeneratePixelBlender("Atop");
GeneratePixelBlender("Over");
GeneratePixelBlender("In");
.
. And I think the T4 template generator should be changed so the generators would look like this: GeneratePixelBlender("Source","SourceOver"); // Generates Source-SourceOver AKA Normal
.
.
GeneratePixelBlender("Multiply","SourceAtop"); // Generates Multiply-SourceAtop
GeneratePixelBlender("Multiply","SourceOver"); // Generates Multiply-SourceOver
GeneratePixelBlender("Multiply","SourceIn"); // Generates Multiply-SourceIn
.
.
GeneratePixelBlender("Add","SourceAtop"); // Generates Add-SourceAtop
GeneratePixelBlender("Add","SourceOver"); // Generates Add-SourceOver
GeneratePixelBlender("Add","SourceIn"); // Generates Add-SourceIn
.
. A hurdle for doing this is that the code for each Color Blender is custom code, so the generator needs some way of getting such code, maybe with a switch statement within the generator. Once all the ColorBlender x AlphaComposer combinations are ready, it's about splitting the enum into Alpha and Color blend modes, which would affect the API surface quite a lot. An alternative from splitting the enum to avoid heavy API surface changes would be to declare it with [flags]
enum BlendMode
{
ColorMask = 255,
ColorSource = 1,
ColorDest = 2,
ColorMultiply = 3,
ColorAdd = 4,
.
.
AlphaMask = 255 << 8,
AlphaSourceAtop = 1 << 8,
AlphaSourceOver = 2 << 8,
AlphaSourceIn = 3 <<8,
AlphaSourceOut = 4 <<8,
AlphaDestAtop = 5 << 8,
AlphaDestOver = 6 << 8,
AlphaDestIn = 7 <<8,
AlphaDestOut = 8 <<8
.
.
} So defining a specific mode would look like this:
Also, changing the big span processors here would be required. |
@dlemstra I had to undo some of your changes in order to easily allow all combinations; right now I'm looking only for something that works, I'm open to improvements and optimizations. @JimBobSquarePants @tocsoft let me know if you see something fishy; I know this part of the code is quite critical. |
WIP Generate all Pixel Blender/Composer possible combinations to solve #535
@JimBobSquarePants Thanks! Now that we have the building blocks to move on, here's the proposal: Until now, with the current In order to support combined operations, I would like to propose splitting enum ColorBlendingMode
{
Normal,
Add,
Multiply,
Subtract,
etc
} enum AlphaCompositionMode
{
Src,
SrcOver,
SrcAtop
Dst,
DstOver,
DstAtop,
etc
} Also, In most cases, users will probably need to change only the ColorBlending property as they used to do with The only drawback is that the PixelBlender selector here becomes more convoluted, and will require a two tier switch. |
WIP Generate all Pixel Blender/Composer possible combinations to solve SixLabors#535
Prerequisites
DEBUG
andRELEASE
modeDescription
Right now, the Porter-Duff blend modes enumeration is a plain list of modes, but I noticed that some of the enumerated values are in fact a combination of two effects.
I think the enumeration could be split in two enumerations:
and
This would cover all current blending options, plus new ones currently unavailable.
This would allow having blend modes like
Multiply + In
andMultiply + Out
that are very useful for dropping inner/outer shadows and other kind of effects.Normal blend mode would be
Source + Over
Steps to Reproduce
System Configuration
The text was updated successfully, but these errors were encountered: