Skip to content
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

getBrightness() set to work with RGB format only - should be available for any format #5

Open
stam66 opened this issue Mar 7, 2022 · 0 comments

Comments

@stam66
Copy link
Contributor

stam66 commented Mar 7, 2022

As it stands getBrightness(pRGB) is set up for RGB formatted colours only, and by extension this applies to isLight() and isDark() as well.

This creates unnecessary work in liveCode to pass a colour formatted as RGB - for example if a control has had a colour attribute set by colorName or hex then this is passed to isDark() for example, the developer has to write extra code to translate this to RGB format (if you don't you get an error in the messageBox).

This is easily fixable by passing a color (rather than specifically RBG) and just making it the tinyColor sColor, from which the RBG is seamlessly extracted.

With the principle of minimising any changes to existing code, the handler could look like this:

function getBrightness pColor
    // http://www.w3.org/TR/AERT#color-contrast
    local tRGB
    get tinyColor(pColor, empty)
    put _fixRGB(toRGB(true)) into tRGB 
    split tRGB by comma
    return ((tRGB[1]* 299) + (tRGB[2]* 587) + (tRGB[3]* 114)) / 1000
end getBrightness

This works seamlessly with any color format passed - but i don't understand the _fixRBG() handler.
If the RBG values are revived directly from the tinyColor sColor this shouldn't be needed but have left in as i don't understand it.

if it isn't needed now, the handler could be a bit simpler:

function getBrightness pColor
    // http://www.w3.org/TR/AERT#color-contrast
    local tRGB
    get tinyColor(pColor, empty)
    put toRGB(true) into tRGB 
    split tRGB by comma
    return ((tRGB[1]* 299) + (tRGB[2]* 587) + (tRGB[3]* 114)) / 1000
end getBrightness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant