Class: PSD::LayerStyles::ColorOverlay
- Inherits:
-
Object
- Object
- PSD::LayerStyles::ColorOverlay
- Defined in:
- lib/psd/renderer/layer_styles/color_overlay.rb
Class Method Summary collapse
- .can_apply?(canvas, data) ⇒ Boolean
- .for_canvas(canvas) ⇒ Object
-
.should_apply?(canvas, data) ⇒ Boolean
TODO: CMYK support.
Instance Method Summary collapse
- #a ⇒ Object (also: #overlay_opacity)
- #apply! ⇒ Object
- #b ⇒ Object
- #g ⇒ Object
-
#initialize(styles) ⇒ ColorOverlay
constructor
A new instance of ColorOverlay.
- #overlay_color ⇒ Object
- #r ⇒ Object
Constructor Details
#initialize(styles) ⇒ ColorOverlay
Returns a new instance of ColorOverlay.
26 27 28 29 30 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 26 def initialize(styles) @canvas = styles.canvas @node = styles.node @data = styles.data end |
Class Method Details
.can_apply?(canvas, data) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 11 def self.can_apply?(canvas, data) data.has_key?('SoFi') && data['SoFi']['enab'] && canvas.node.header.rgb? end |
.for_canvas(canvas) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 17 def self.for_canvas(canvas) data = canvas.node.object_effects return nil if data.nil? return nil unless can_apply?(canvas, data.data) styles = LayerStyles.new(canvas) self.new(styles) end |
.should_apply?(canvas, data) ⇒ Boolean
TODO: CMYK support
5 6 7 8 9 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 5 def self.should_apply?(canvas, data) data.has_key?('SoFi') && data['SoFi']['enab'] && canvas.node.header.rgb? end |
Instance Method Details
#a ⇒ Object Also known as: overlay_opacity
63 64 65 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 63 def a @a ||= (['Opct'][:value] * 2.55).ceil end |
#apply! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 32 def apply! PSD.logger.debug "Layer style: layer = #{@node.name}, type = color overlay, blend mode = #{blending_mode}" @canvas.height.times do |y| @canvas.width.times do |x| pixel = @canvas[x, y] alpha = ChunkyPNG::Color.a(pixel) next if alpha == 0 new_pixel = Compose.send(blending_mode, , pixel, ) @canvas[x, y] = (new_pixel & 0xFFFFFF00) | alpha end end end |
#b ⇒ Object
59 60 61 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 59 def b @b ||= color_data['Bl '].round end |
#g ⇒ Object
55 56 57 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 55 def g @g ||= color_data['Grn '].round end |
#overlay_color ⇒ Object
47 48 49 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 47 def @overlay_color ||= ChunkyPNG::Color.rgb(r, g, b) end |
#r ⇒ Object
51 52 53 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 51 def r @r ||= color_data['Rd '].round end |