Module: Abachrome::ColorMixins::ToGrayscale
- Defined in:
- lib/abachrome/color_mixins/to_grayscale.rb
Instance Method Summary collapse
-
#luma ⇒ AbcDecimal
Calculates the relative luminance using the default Rec.
-
#luma_601 ⇒ AbcDecimal
Calculates the relative luminance (luma) value using Rec.
-
#luma_709 ⇒ AbcDecimal
Calculates the relative luminance (luma) value using Rec.
-
#to_grayscale ⇒ Abachrome::Color
Converts the color to grayscale using the default Rec.
-
#to_grayscale_601 ⇒ Abachrome::Color
Converts the color to grayscale using Rec.
-
#to_grayscale_709 ⇒ Abachrome::Color
Converts the color to grayscale using Rec.
Instance Method Details
#luma ⇒ AbcDecimal
Calculates the relative luminance using the default Rec. 601 standard. Alias for luma_601.
82 83 84 |
# File 'lib/abachrome/color_mixins/to_grayscale.rb', line 82 def luma luma_601 end |
#luma_601 ⇒ AbcDecimal
Calculates the relative luminance (luma) value using Rec. 601 coefficients. This returns just the Y component without creating a new color.
62 63 64 65 66 |
# File 'lib/abachrome/color_mixins/to_grayscale.rb', line 62 def luma_601 rgb_color = to_srgb r, g, b = rgb_color.coordinates (AD("0.299") * r) + (AD("0.587") * g) + (AD("0.114") * b) end |
#luma_709 ⇒ AbcDecimal
Calculates the relative luminance (luma) value using Rec. 709 coefficients. This returns just the Y component without creating a new color.
72 73 74 75 76 |
# File 'lib/abachrome/color_mixins/to_grayscale.rb', line 72 def luma_709 rgb_color = to_srgb r, g, b = rgb_color.coordinates (AD("0.2126") * r) + (AD("0.7152") * g) + (AD("0.0722") * b) end |
#to_grayscale ⇒ Abachrome::Color
Converts the color to grayscale using the default Rec. 601 standard. This is an alias for to_grayscale_601 and matches the legacy behavior expected by most image processing applications.
54 55 56 |
# File 'lib/abachrome/color_mixins/to_grayscale.rb', line 54 def to_grayscale to_grayscale_601 end |
#to_grayscale_601 ⇒ Abachrome::Color
Converts the color to grayscale using Rec. 601 luma coefficients (legacy NTSC standard). This is the same calculation used in the YIQ color space's Y component.
26 27 28 29 30 31 32 33 34 |
# File 'lib/abachrome/color_mixins/to_grayscale.rb', line 26 def to_grayscale_601 rgb_color = to_srgb r, g, b = rgb_color.coordinates # Rec. 601 luma: Y = 0.299R + 0.587G + 0.114B luma = (AD("0.299") * r) + (AD("0.587") * g) + (AD("0.114") * b) Color.from_rgb(luma, luma, luma, alpha) end |
#to_grayscale_709 ⇒ Abachrome::Color
Converts the color to grayscale using Rec. 709 luma coefficients (HDTV standard).
39 40 41 42 43 44 45 46 47 |
# File 'lib/abachrome/color_mixins/to_grayscale.rb', line 39 def to_grayscale_709 rgb_color = to_srgb r, g, b = rgb_color.coordinates # Rec. 709 luma: Y = 0.2126R + 0.7152G + 0.0722B luma = (AD("0.2126") * r) + (AD("0.7152") * g) + (AD("0.0722") * b) Color.from_rgb(luma, luma, luma, alpha) end |