Class: Compass::Magick::Effect
Overview
A class that executes a processing block on each Canvas pixel.
Instance Attribute Summary
Attributes inherited from Command
Attributes included from Scriptable
Class Method Summary collapse
-
.clamp(value) ⇒ Integer
Clamp value between 0..255 so it doesn’t overflow the 8-bit colorspace.
Instance Method Summary collapse
-
#initialize(&process) ⇒ Effect
constructor
Initializes a new Effect instance.
Methods inherited from Command
Methods included from Utils
#assert_one_of, #assert_type, #to_canvas, #to_chunky_color, #value_of
Constructor Details
#initialize(&process) ⇒ Effect
Initializes a new Effect instance.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/magick/effect.rb', line 15 def initialize(&process) @process = process @block = lambda do |canvas| for y in 0...canvas.height do for x in 0...canvas.width do canvas.set_pixel(x, y, @process.call(canvas.get_pixel(x, y))) end end end end |
Class Method Details
.clamp(value) ⇒ Integer
Clamp value between 0..255 so it doesn’t overflow the 8-bit colorspace.
30 31 32 |
# File 'lib/magick/effect.rb', line 30 def self.clamp(value) [0, [value.to_i, 255].min].max end |