module ChunkyPNG::Canvas::Masking

def extract_mask(mask_color, bg_color = ChunkyPNG::Color::WHITE, tolerance = 5)

Other tags:
    See: #change_mask_color! -
    See: #change_theme_color! -

Returns:
  • (Array) - An array with the base canvas and the mask

Parameters:
  • tolerance (Integer) -- The tolerance level to use when extracting the mask image. Five is
  • bg_color (Integer) -- The background color on which the theme colored pixels are applied.
  • mask_color (Integer) -- The current theme color.
def extract_mask(mask_color, bg_color = ChunkyPNG::Color::WHITE, tolerance = 5)
  base_pixels = []
  mask_pixels = []
  pixels.each do |pixel|
    if ChunkyPNG::Color.alpha_decomposable?(pixel, mask_color, bg_color, tolerance)
      mask_pixels << ChunkyPNG::Color.decompose_color(pixel, mask_color, bg_color, tolerance)
      base_pixels << bg_color
    else
      mask_pixels << (mask_color & 0xffffff00)
      base_pixels << pixel
    end
  end
  
  [ self.class.new(width, height, base_pixels), self.class.new(width, height, mask_pixels) ]
end