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.
27 28 29 30 31 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 27 def initialize(styles) @canvas = styles.canvas @node = styles.node @data = styles.data end |
Class Method Details
.can_apply?(canvas, data) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 12 def self.can_apply?(canvas, data) data.has_key?('SoFi') && data['SoFi']['enab'] && canvas.node.header.rgb? end |
.for_canvas(canvas) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 18 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 10 |
# 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? && !PSD::Renderer::VectorShape.can_render?(canvas) end |
Instance Method Details
#a ⇒ Object Also known as: overlay_opacity
64 65 66 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 64 def a @a ||= (['Opct'][:value] * 2.55).ceil end |
#apply! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 33 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
60 61 62 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 60 def b @b ||= color_data['Bl '].round end |
#g ⇒ Object
56 57 58 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 56 def g @g ||= color_data['Grn '].round end |
#overlay_color ⇒ Object
48 49 50 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 48 def @overlay_color ||= ChunkyPNG::Color.rgb(r, g, b) end |
#r ⇒ Object
52 53 54 |
# File 'lib/psd/renderer/layer_styles/color_overlay.rb', line 52 def r @r ||= color_data['Rd '].round end |