-
Notifications
You must be signed in to change notification settings - Fork 332
Made calculation of table in BrightnessContrastEffect lazy, and extracted the algorithm
#1726
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
Made calculation of table in BrightnessContrastEffect lazy, and extracted the algorithm
#1726
Conversation
Instead of creating `BrightnessContrastEffect`
BrightnessContrastEffect lazyBrightnessContrastEffect lazy, and extracted the algorithm
Instead of creating `BrightnessContrastEffect`
Instead of creating `BrightnessContrastEffect`
I'd like it to be easy to compose effects from other effects without having to factor out the code somewhere else, so I think we should instead be trying to fix any issues / shortcomings in the effect API that make this hard to do Re: LRU cache I agree with the concerns you mentioned. I'd really rather not add any sort of cache for this lookup table, since I think the problem should be avoidable entirely:
|
|
@cameronwhite I share your vision of making effects composable and more tidy. And I'm trying to get closer to that goal with the refactorings to Why not both, though? Having the algorithms in their own classes (which is more feasible in the short term) and making the effects composable. |
I don't think it's inherently wrong to have an algorithm in its own class, but I don't want to have to do this for every single effect (especially to then have it not be really necessary later if the BaseEffect API has been improved) I guess I'm also not fully understanding why this specific change is important. The original code was already working fine by creating the brightness effect and applying it to the current tile? |
|
@cameronwhite just to clarify, my suggestion is not extracting the algorithm from every single effect, only those that are currently being created inside the But if I understand correctly, your point is that it's not that bad, and when the API is improved and made composable, it won't be hard to migrate all of these compositions at once? // From something like this (currently)
effect1.Render(src, dst, rois);
effect2.Render(src, dst, rois);
effect3.Render(src, dst, rois);
// To something (in rough terms) like this
return Render.Chain(
[effect1, effect2, effect3],
src, dst, rois); |
|
Correct, I don't think the current approach is that bad (aside from the effects being re-created each time Although, the second call is a bit bug-prone since it needs to be |
|
@cameronwhite I propose a different, slightly more conservative approach:
|
|
Thanks! I'm good with this set of changes 👍 |
The algorithm part was moved to its own class so that other effects are able to use it without creating the effect itself.
I am thinking that later on we could also use an LRU cache with a key of type
(int Brightness, int Contrast), and by doing that we could get rid of thePropertyChangedhandler.I'm aware that after the refactorings done in
PencilSketchEffect, andSoftenPortraitEffect, the table is calculated for every row (however, I think the efficiency inGlowEffectis the same). These commits could be discarded and just kept as reference, but they show that this is one further step towards pixel-by-pixel calculation, similar to what many effects already do, and hopefully the benefits of a thread-safe LRU cache would become clearer.I thought of using
ConcurrentDictionary.GetOrAdd, but that is very expensive in memory terms, because there is no tracking of what key was used last, and no deleting of old tables from memory.