Module: Sai::Conversion::RGB::ColorIndexer Private

Defined in:
lib/sai/conversion/rgb/color_indexer.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Color indexing utilities

Author:

Since:

  • 0.3.1

Class Method Summary collapse

Class Method Details

.color_cube(rgb) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert RGB values to 256-color cube index

Parameters:

  • rgb (Array<Integer>) —

    RGB values (0-255)

Returns:

  • (Integer) —

    the color cube index

Author:

Since:

  • 0.1.0



25
26
27
28
# File 'lib/sai/conversion/rgb/color_indexer.rb', line 25

def color_cube(rgb)
  r, g, b = rgb.map { |c| ((c / 255.0) * 5).round } #: [Integer, Integer, Integer]
  16 + (r * 36) + (g * 6) + b
end

.grayscale(rgb) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert RGB values to grayscale index

Parameters:

  • rgb (Array<Integer>) —

    RGB values

Returns:

  • (Integer) —

    the grayscale index

Author:

Since:

  • 0.1.0



41
42
43
# File 'lib/sai/conversion/rgb/color_indexer.rb', line 41

def grayscale(rgb)
  232 + ((rgb[0] / 255.0) * 23).round
end