Class: Abachrome::Converters::LrgbToSrgb
- Defined in:
- lib/abachrome/converters/lrgb_to_srgb.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.convert(lrgb_color) ⇒ Abachrome::Color
Converts a color from linear RGB to sRGB color space.
-
.to_srgb(v) ⇒ AbcDecimal
Converts a linear RGB value to standard RGB color space (sRGB) value.
Methods inherited from Base
#can_convert?, #convert, find_converter, #initialize, raise_unless, register
Constructor Details
This class inherits a constructor from Abachrome::Converters::Base
Class Method Details
.convert(lrgb_color) ⇒ Abachrome::Color
Converts a color from linear RGB to sRGB color space.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/abachrome/converters/lrgb_to_srgb.rb', line 23 def self.convert(lrgb_color) raise_unless lrgb_color, :lrgb r, g, b = lrgb_color.coordinates.map { |c| to_srgb(AbcDecimal(c)) } output_coords = [r, g, b] Color.new( ColorSpace.find(:srgb), output_coords, lrgb_color.alpha ) end |
.to_srgb(v) ⇒ AbcDecimal
Converts a linear RGB value to standard RGB color space (sRGB) value.
This method implements the standard linearization function used in the sRGB color space. For small values (≤ 0.0031308), a simple linear transformation is applied. For larger values, a power function with gamma correction is used.
44 45 46 47 48 49 50 51 52 |
# File 'lib/abachrome/converters/lrgb_to_srgb.rb', line 44 def self.to_srgb(v) v_abs = v.abs v_sign = v.negative? ? -1 : 1 if v_abs <= AD("0.0031308") v * AD("12.92") else v_sign * ((AD("1.055") * (v_abs**Rational(1.0, 2.4))) - AD("0.055")) end end |