Class: Compass::Magick::Effect

Inherits:
Command
  • Object
show all
Defined in:
lib/magick/effect.rb

Overview

A class that executes a processing block on each Canvas pixel.

Examples:


# Turn all pixels opaque
Effect.new do |pixel|
  pixel | 0x000000ff
end

Instance Attribute Summary

Attributes inherited from Command

#block

Attributes included from Scriptable

#context, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#to_s

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.

Parameters:

  • process (Proc)

    The processing block to execute.



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.

Parameters:

  • value (Float)

    The value to clamp.

Returns:

  • (Integer)

    The value as an integer between 0..255.



30
31
32
# File 'lib/magick/effect.rb', line 30

def self.clamp(value)
  [0, [value.to_i, 255].min].max
end