Class: Abachrome::Converters::SrgbToYiq
- Inherits:
-
Object
- Object
- Abachrome::Converters::SrgbToYiq
- Defined in:
- lib/abachrome/converters/srgb_to_yiq.rb
Class Method Summary collapse
-
.convert(srgb_color) ⇒ Abachrome::Color
Converts a color from sRGB color space to YIQ color space.
Class Method Details
.convert(srgb_color) ⇒ Abachrome::Color
Converts a color from sRGB color space to YIQ color space. This method applies the NTSC standard transformation matrix.
with the same alpha value as the input color
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/abachrome/converters/srgb_to_yiq.rb', line 30 def self.convert(srgb_color) r, g, b = srgb_color.coordinates.map { |c| AbcDecimal(c) } # NTSC RGB to YIQ transformation matrix # Y = 0.299R + 0.587G + 0.114B (Rec. 601 luma) # I = 0.596R - 0.275G - 0.321B (In-phase: orange-blue) # Q = 0.212R - 0.523G + 0.311B (Quadrature: purple-green) y = (AD("0.299") * r) + (AD("0.587") * g) + (AD("0.114") * b) i = (AD("0.5959") * r) - (AD("0.2746") * g) - (AD("0.3213") * b) q = (AD("0.2115") * r) - (AD("0.5227") * g) + (AD("0.3112") * b) Color.new( ColorSpace.find(:yiq), [y, i, q], srgb_color.alpha ) end |