halostatue / color

Color tools for Ruby.
Other
133 stars 41 forks source link

add packed rgb #19

Closed markgandolfo closed 7 years ago

markgandolfo commented 9 years ago

Add PackedRGB functionality.

i.e.

Color::PackedRGB.new(-6306817).to_rgb
=> RGB [#9fc3ff]
coveralls commented 9 years ago

Coverage Status

Coverage decreased (-2.11%) to 94.82% when pulling 4b410cc379347111fe43683783de7c8aa40cf7ef on markgandolfo:packed_rgb into 4e24c50261a8a73673ae12ce0955ecd4732702e6 on halostatue:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-2.11%) to 94.82% when pulling 4b410cc379347111fe43683783de7c8aa40cf7ef on markgandolfo:packed_rgb into 4e24c50261a8a73673ae12ce0955ecd4732702e6 on halostatue:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-2.11%) to 94.82% when pulling 4b410cc379347111fe43683783de7c8aa40cf7ef on markgandolfo:packed_rgb into 4e24c50261a8a73673ae12ce0955ecd4732702e6 on halostatue:master.

halostatue commented 9 years ago

I’d like a bit deeper explanation of what a Packed RGB colour is for inclusion. At the same time, this feels like it should be an alternative constructor to the Color::RGB, say Color::RGB.from_packed(integer) (although I hate throwing away the alpha value in that process).

markgandolfo commented 9 years ago

I'm happy to move it into the RGB class. A good explanation can be found: http://stackoverflow.com/questions/7358533/how-to-pack-argb-to-one-integer-uniquely

In regards to the alpha channel, maybe I misread the source, but it doesn't look like RGB handles alpha now, and hard sets it at 1? Perhaps we can create an RGBA class that extends the RGB class that handles alpha in some common scenarios, such as .html() which can return rgba(r,g,b,a)

halostatue commented 9 years ago

Yeah. I didn’t want to suggest that for this PR, but it feels like we could have a meaningful RGBA class…or maybe we add alpha capabilities to RGB. I’m thinking of a color 2.0 release sometime this year, and this would be (probably) an acceptable (potentially) breaking change.