module Spectrum

Colour Management with Ruby

Constants

COLOR_EPSILON

The maximum “resolution” for colour math; if any value is less than or equal to this value, it is treated as zero.

COLOR_TOLERANCE

The tolerance for comparing the components of two colours. In general, colours are considered equal if all of their components are within this tolerance value of each other.

COLOR_VERSION
GreyScale

A colour object representing shades of grey. Used primarily in PDF document creation.

Public Class Methods

near_one?(value) click to toggle source

Returns true if the value is within COLOR_EPSILON of one.

# File lib/spectrum.rb, line 46
def near_one?(value)
  near_zero?(value - 1.0)
end
near_one_or_more?(value) click to toggle source

Returns true if the value is within COLOR_EPSILON of one or more than one.

# File lib/spectrum.rb, line 52
def near_one_or_more?(value)
  (value > 1.0 or near_one?(value))
end
near_zero?(value) click to toggle source

Returns true if the value is less than COLOR_EPSILON.

# File lib/spectrum.rb, line 35
def near_zero?(value)
  (value.abs <= COLOR_EPSILON)
end
near_zero_or_less?(value) click to toggle source

Returns true if the value is within COLOR_EPSILON of zero or less than zero.

# File lib/spectrum.rb, line 41
def near_zero_or_less?(value)
  (value < 0.0 or near_zero?(value))
end
normalize(value) click to toggle source

Normalizes the value to the range (0.0) .. (1.0).

# File lib/spectrum.rb, line 57
def normalize(value)
  if near_zero_or_less? value
    0.0
  elsif near_one_or_more? value
    1.0
  else
    value
  end
end
Also aliased as: normalize_fractional
normalize_16bit(value)
Alias for: normalize_word
normalize_8bit(value)
Alias for: normalize_byte
normalize_byte(value) click to toggle source

Normalize the value to the range (0) .. (255).

# File lib/spectrum.rb, line 81
def normalize_byte(value)
  normalize_to_range(value, 0..255).to_i
end
Also aliased as: normalize_8bit
normalize_fractional(value)
Alias for: normalize
normalize_to_range(value, range) click to toggle source
# File lib/spectrum.rb, line 68
def normalize_to_range(value, range)
  range = (range.end..range.begin) if (range.end < range.begin)

  if value <= range.begin
    range.begin
  elsif value >= range.end
    range.end
  else
    value
  end
end
normalize_word(value) click to toggle source

Normalize the value to the range (0) .. (65535).

# File lib/spectrum.rb, line 87
def normalize_word(value)
  normalize_to_range(value, 0..65535).to_i
end
Also aliased as: normalize_16bit