Class: SwfConverter::Engine::Alphize::Blender
- Inherits:
-
Object
- Object
- SwfConverter::Engine::Alphize::Blender
- Includes:
- Runner
- Defined in:
- lib/swf_converter/engine/alphize/blender.rb
Instance Method Summary collapse
- #blend!(output_path) ⇒ Object
-
#initialize(images) ⇒ Blender
constructor
A new instance of Blender.
Methods included from Runner
Constructor Details
#initialize(images) ⇒ Blender
Returns a new instance of Blender.
11 12 13 |
# File 'lib/swf_converter/engine/alphize/blender.rb', line 11 def initialize(images) @originals = images end |
Instance Method Details
#blend!(output_path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/swf_converter/engine/alphize/blender.rb', line 15 def blend!(output_path) # The strategy here is based on the following principle: # original_image.alpha == (CHANNEL_MAX - image_on_white.red) + image_on_black.red # (Applies to blue and green, too. Derived from the formulas applied # by the original composition; not too hard to work out.) # So, we will first get a grayscale version of an alpha mask by # negating the image-on-white (create_negative!), then add it to the # image-on-black to get the grayscale alpha mask (create_alpha!). # The alpha mask image has white where the original image is opaque, # and black where it is fully transparent, and gray where it is # partially transparent. Once we have that image, since the RGB # values in image-on-black were found by multiplying by the alpha # value, we divide image-on-black by the grayscale alpha mask to get # an opaque version of the image with the correct colors # (create_division!), then apply that grayscale image as an alpha # mask to save the final image (create_final!). with_temps do |temps| create_negative!(temps) create_alpha!(temps) create_division!(temps) create_final!(output_path, temps) end end |