Skip to content

clamping on colors should be done when the values are asked #9

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

Open
MARTIMM opened this issue Nov 26, 2017 · 3 comments
Open

clamping on colors should be done when the values are asked #9

MARTIMM opened this issue Nov 26, 2017 · 3 comments
Assignees

Comments

@MARTIMM
Copy link
Collaborator

MARTIMM commented Nov 26, 2017

There are some blending operations which have intermediate color values exceeding their maximum or minimum values and are clamped to their maximum or minimum. A suggestion is to postpone the clamping until the values are asked for using the to-string methods and others.

A piece of code shows that operations can result in wrong values

my Color $b .= new('#08f');
my Color $c .= new('#8f0");
my Color $r1 = ($b + $c)/2;                    # '#447F7F'
my Color $r2 = $b/2 + $c/2;                   # '#44C37F'

The value of $r2 is the correct one but it needs more operations to get it right. There might be operations which are not that easy to circumvent and always deliver a wrong result.

Regards,
Marcel

@MARTIMM
Copy link
Collaborator Author

MARTIMM commented Dec 2, 2017

🤓 In the code, I saw a lot of clip-to() actions. Moving them to the output routines would also have a positive performance effect.

@lizmat
Copy link
Contributor

lizmat commented Feb 20, 2022

I'm not yet familiar enough with Color, could you give an example of such a change?

@2colours 2colours self-assigned this Jan 22, 2023
@2colours
Copy link

This modification seems a bit touchy without really rebuilding the API of this distro - the assumption seems to be everywhere that whatever a Color object holds at any moment is valid for RGB(A). I think this can be faked by writing accessor methods for all the data a Color object holds - meaning, any access to data in a Color object would settle the values.

What I don't know yet is if this breaks down on too many premature data accesses - that would basically mean that Color objects still finalize immediately, except in a more obfuscated way.

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

3 participants