halostatue/color — pull request #6 by bkudria (2014-04-18 23:58:25+00:00)
Title: Correct YIQ conversion, and YIQ#to_rgb

This patch fixes RGB=>YIQ conversion, and provides YIQ=>RGB conversion. I'd love to replace to_yiq, but this would break existing clients. This seems like a reasonable compromise, but I'm open to other ideas.

You can verify these conversions using http://www.picturetopeople.org/color_converter.html. The Wikipedia article on YIQ also notes these ranges: http://en.wikipedia.org/wiki/YIQ. (I'm using the same numbers you are, just at higher precision.)

In YIQ, only Y is in the 0..1 range, I and Q have a different min/max.
In this change:
- RGB::to_correct_yiq will correctly re-scale and accurately convert
I/Q.
- Adds YIQ.from_ntsc_fraction and YIQ#to_ntsc to rescale to and from
the 0..1 range into the actual range.
- Adds YIQ#to_rgb to enable going back to RGB from YIQ.
- Uses stdlib matrix for conversion.