Method: PSD::Compose#overlay
- Defined in:
- lib/psd/renderer/compose.rb
#overlay(fg, bg, opts = {}) ⇒ Object
Contrasting blend modes
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/psd/renderer/compose.rb', line 159 def (fg, bg, opts={}) return apply_opacity(fg, opts) if fully_transparent?(bg) return bg if fully_transparent?(fg) mix_alpha, dst_alpha = calculate_alphas(fg, bg, DEFAULT_OPTS.merge(opts)) calculate_foreground = Proc.new do |b, f| if b < 128 b * f >> 7 else 255 - ((255 - b) * (255 - f) >> 7) end end new_r = blend_channel(r(bg), calculate_foreground.call(r(bg), r(fg)), mix_alpha) new_g = blend_channel(g(bg), calculate_foreground.call(g(bg), g(fg)), mix_alpha) new_b = blend_channel(b(bg), calculate_foreground.call(b(bg), b(fg)), mix_alpha) rgba(new_r, new_g, new_b, dst_alpha) end |