lib/psd/renderer/blender.rb in psd-2.1.2 vs lib/psd/renderer/blender.rb in psd-3.1.2

- old
+ new

@@ -14,11 +14,12 @@ end # Composes the foreground Canvas onto the background Canvas using the # blending mode specified by the foreground. def compose! - PSD.logger.debug "Composing #{fg.node.debug_name} onto #{bg.node.debug_name} with #{fg.node.blending_mode} blending" + PSD.logger.debug "#{fg.node.debug_name} -> #{bg.node.debug_name}: #{fg.node.blending_mode} blending" + PSD.logger.debug "fg: (#{fg.left}, #{fg.top}) #{fg.width}x#{fg.height}; bg: (#{bg.left}, #{bg.top}) #{bg.width}x#{bg.height}" offset_x = fg.left - bg.left offset_y = fg.top - bg.top fg.height.times do |y| @@ -28,16 +29,16 @@ next if base_x < 0 || base_y < 0 || base_x >= bg.width || base_y >= bg.height color = Compose.send( fg.node.blending_mode, - fg.canvas[x, y], - bg.canvas[base_x, base_y], - compose_options + fg.get_pixel(x, y), + bg.get_pixel(base_x, base_y), + calculated_opacity ) - bg.canvas[base_x, base_y] = color + bg.set_pixel base_x, base_y, color end end end private @@ -45,9 +46,13 @@ def compose_options { opacity: @opacity, fill_opacity: @fill_opacity } + end + + def calculated_opacity + @calculated_opacity ||= compose_options[:opacity] * compose_options[:fill_opacity] / 255 end end end end \ No newline at end of file