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

Consider more generic ways to represent and invert channels #24

Open
flying-sheep opened this issue Jan 5, 2015 · 8 comments
Open

Consider more generic ways to represent and invert channels #24

flying-sheep opened this issue Jan 5, 2015 · 8 comments

Comments

@flying-sheep
Copy link

Lab* colors are usually represented as one of the following two

L* a* b*
0 – 100 -120 – 120 -120 – 120
0 – 100 -128 – 128 -128 – 128

the last one more “accomodating” to computers (to almost represent them as i8, i guess).

now adding this is a problem: we’d have to add two more ways to invert this: 100 - L and the simple -a/-b.

i think we should consider a way to handle this, e.g. by tying the kind of channel to the color model:

HSV Lab* RGB
H/L*/R circular unsigned unsigned
S/a*/G unsigned signed unsigned
V/b*/B unsigned signed unsigned

that would involve either normalizing float channels (always clamp to [-1..1] or [0..1], modulo when circular). also bits would be lost: using 3×i8 for Lab* would mean using all int values from -128 to 127, but only 100 lightness levels!


do you have a different idea how to handle this?

@flying-sheep flying-sheep changed the title Consider more generic ways to invert channels Consider more generic ways to represent and invert channels Jan 5, 2015
@retep998
Copy link

retep998 commented Jan 5, 2015

Couldn't we just expand the channel for lightness to also use the full range of its integer type?
Granted we wouldn't be following existing practice.

@flying-sheep
Copy link
Author

yeah, sure. But if that should be meaningful, we’d need l:u8, a:i8, b:i8, which isn’t supported by the current generics model (one type of numeric primitive as type parameter)

because neither an a that can’t go below 0 nor a l that can makes sense.

@retep998
Copy link

retep998 commented Jan 5, 2015

Perhaps we could have tag types for the 4 sizes of integers, with a trait + associated types specifying the signed and unsigned versions. Thus you can specialize the color models on the tag types and have signed ints for some components and unsigned ints for other components.

@flying-sheep
Copy link
Author

sorry, i’m a rust noob: tag types?

but i understand what you mean. basically something connecting both.

@retep998
Copy link

retep998 commented Jan 6, 2015

Something like this

struct Int8;
impl Something for Int8 {
    type Signed = i8;
    type Unsigned = u8;
}
struct ColorLab<T: Something> {
    L: T::Unsigned,
    a: T::Signed,
    b: T::Signed,
}
// Code can now use ColorLab<Int8>

@flying-sheep
Copy link
Author

ah, that brand new thing! very good idea.

here is also an awesome comprehensive implementation of this calculator powered by this math.

@brendanzab
Copy link
Owner

Thanks for spending the time to write this up! I will have to spend some digesting this. Are you available on #rust-gamedev at any time to have a chat?

@flying-sheep
Copy link
Author

sure, i’ll hop on right now!

as it’s been almost 24 hours ago that you commented, you could be there :D

/edit: you weren’t there. usually i’m online from around the time this comment was originally made (19-20⁰⁰ CET)

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