Module: Abachrome::PaletteMixins::StretchLuminance
- Defined in:
- lib/abachrome/palette_mixins/stretch_luminance.rb
Instance Method Summary collapse
- #compress_luminance(amount = 0.5) ⇒ Object
- #compress_luminance!(amount = 0.5) ⇒ Object
- #normalize_luminance ⇒ Object
- #normalize_luminance! ⇒ Object
- #stretch_luminance(new_min: 0.0, new_max: 1.0) ⇒ Object
- #stretch_luminance!(new_min: 0.0, new_max: 1.0) ⇒ Object
Instance Method Details
#compress_luminance(amount = 0.5) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/abachrome/palette_mixins/stretch_luminance.rb', line 51 def compress_luminance(amount = 0.5) amount = AbcDecimal(amount) mid_point = AbcDecimal("0.5") stretch_luminance( new_min: mid_point - (mid_point * amount), new_max: mid_point + (mid_point * amount) ) end |
#compress_luminance!(amount = 0.5) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/abachrome/palette_mixins/stretch_luminance.rb', line 60 def compress_luminance!(amount = 0.5) amount = AbcDecimal(amount) mid_point = AbcDecimal("0.5") stretch_luminance!( new_min: mid_point - (mid_point * amount), new_max: mid_point + (mid_point * amount) ) end |
#normalize_luminance ⇒ Object
43 44 45 |
# File 'lib/abachrome/palette_mixins/stretch_luminance.rb', line 43 def normalize_luminance stretch_luminance(new_min: 0.0, new_max: 1.0) end |
#normalize_luminance! ⇒ Object
47 48 49 |
# File 'lib/abachrome/palette_mixins/stretch_luminance.rb', line 47 def normalize_luminance! stretch_luminance!(new_min: 0.0, new_max: 1.0) end |
#stretch_luminance(new_min: 0.0, new_max: 1.0) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/abachrome/palette_mixins/stretch_luminance.rb', line 6 def stretch_luminance(new_min: 0.0, new_max: 1.0) return self if empty? new_min = AbcDecimal(new_min) new_max = AbcDecimal(new_max) oklab_colors = @colors.map(&:to_oklab) current_min = oklab_colors.map { |c| c.coordinates[0] }.min current_max = oklab_colors.map { |c| c.coordinates[0] }.max range = current_max - current_min new_range = new_max - new_min self.class.new( oklab_colors.map do |color| l, a, b = color.coordinates scaled_l = if range.zero? new_min else new_min + ((l - current_min) * new_range / range) end Color.new( ColorSpace.find(:oklab), [scaled_l, a, b], color.alpha ) end ) end |
#stretch_luminance!(new_min: 0.0, new_max: 1.0) ⇒ Object
37 38 39 40 41 |
# File 'lib/abachrome/palette_mixins/stretch_luminance.rb', line 37 def stretch_luminance!(new_min: 0.0, new_max: 1.0) stretched = stretch_luminance(new_min: new_min, new_max: new_max) @colors = stretched.colors self end |