Module: HexaPDF::Content::ColorSpace::ColorUtils

Included in:
DeviceCMYK::Color, DeviceGray::Color, DeviceRGB::Color, Universal::Color
Defined in:
lib/hexapdf/content/color_space.rb

Overview

This module includes utility functions that are useful for all color classes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.normalize_value(value, upper) ⇒ Object

Normalizes the given color value so that it is in the range from 0.0 to 1.0.

The conversion is done in the following way:

  • If the color value is an Integer, it is converted to a float and divided by upper.

  • If the color value is greater than 1.0, it is set to 1.0.

  • If the color value is less than 0.0, it is set to 0.0.



403
404
405
406
# File 'lib/hexapdf/content/color_space.rb', line 403

def normalize_value(value, upper)
  value = value.to_f / upper if value.kind_of?(Integer)
  value.clamp(0, 1)
end

Instance Method Details

#==(other) ⇒ Object

Compares this color to another one by looking at their associated color spaces and their components.



412
413
414
415
# File 'lib/hexapdf/content/color_space.rb', line 412

def ==(other)
  other.respond_to?(:components) && other.respond_to?(:color_space) &&
    components == other.components && color_space == other.color_space
end