Class: PSD::LayerStyles::ColorOverlay

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/renderer/layer_styles/color_overlay.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(styles) ⇒ ColorOverlay

Returns a new instance of ColorOverlay.



8
9
10
11
12
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 8

def initialize(styles)
  @canvas = styles.canvas
  @node = styles.node
  @data = styles.data
end

Class Method Details

.should_apply?(data) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 4

def self.should_apply?(data)
  data.has_key?('SoFi')
end

Instance Method Details

#apply!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 14

def apply!
  # TODO - implement CMYK color overlay
  return if @node.header.cmyk?

  width = @canvas.width
  height = @canvas.height

  # puts width, height
  # puts @canvas.canvas.width, @canvas.canvas.height

  PSD.logger.debug "Layer style: layer = #{@node.name}, type = color overlay, blend mode = #{blending_mode}"

  height.times do |y|
    width.times do |x|
      pixel = @canvas[x, y]
      alpha = ChunkyPNG::Color.a(pixel)
      next if alpha == 0

      overlay_color = ChunkyPNG::Color.rgba(r, g, b, alpha)
      @canvas[x, y] = Compose.send(blending_mode, overlay_color, pixel)
    end
  end
end