New issue
Advanced search Search tips

Issue 870384 link

Starred by 1 user

Issue metadata

Status: Started
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Simplify API of color_utils functions for blending to a minimum contrast

Project Member Reported by orinj@chromium.org, Aug 2

Issue description

As discussed in crrev.com/c/1147605 it is possible that we can eliminate the alpha_error_tolerance parameter on GetBlendValueForContrastRatio (currently only used by GetColorWithMinimumContrast passing in kCloseEnoughAlphaDelta).  The benefit is simpler code and slightly improved accuracy for contrast ratios, which may be worth the few extra cycles.  To be sure, we should measure speed and see whether this gets called in any tight loops.
 
Cc: msw@chromium.org
msw@ and pkasting@ also mentioned the possibility of interpolation search.  It's a good idea if we can find the right guessing method.  Inverting the function to calculate directly would still be ideal, though, if possible.
Components: UI>GFX
Labels: M-70
Status: Available (was: Untriaged)
Summary: Simplify API of color_utils functions for blending to a minimum contrast (was: Consider speed and accuracy in use of color_utils::GetBlendValueForContrastRatio)
We should also simplify the API from three functions to one.  Not only is this simpler to use, it guarantees consistent behavior.  All callers probably want to use GetResultingPaintColor(), but FindBlendValueWithMinimumContrast() doesn't(); and the other two functions don't let you retrieve exact alpha.

I think the right API is roughly:

struct BlendResult {
  SkColor color;
  SkAlpha alpha;
};

// Alpha-blends |default_foreground| toward |high_contrast_foreground| until the
// result has a contrast ratio against |background| of at least
// |contrast_ratio|.  Returns both the blended color and the alpha used to
// achieve that blend, since different callers want one or the other and it's
// more efficient to compute them both at once.  If |default_foreground| already
// has sufficient contrast, returns {default_foreground, 0}.
BlendResult GetBlendWithMinimumContrast(
    SkColor background,
    SkColor default_foreground,
    SkColor high_contrast_foreground =
        BlendTowardOppositeLuma(base, SK_AlphaOPAQUE),
    float contrast_ratio = kMinimumReadableContrastRatio);

And the implementation would use GetResultingPaintColor() first, ensure that we only run one contrast check in the case where there's sufficient contrast already, and compute exact alpha.
Labels: Hotlist-DesktopUIChecked Hotlist-DesktopUIToolingRequired
***UI Mass Triage***

Adding appropriate label for expert review.
Cc: -pkasting@chromium.org
Owner: pkasting@chromium.org
Status: Started (was: Available)

Sign in to add a comment