Module: Postsvg::Colors

Defined in:
lib/postsvg/colors.rb

Overview

Color conversion utilities for PostScript color models

Class Method Summary collapse

Class Method Details

.cmyk2rgb(cmyk) ⇒ Object

Convert CMYK values (0-1) to RGB color string



22
23
24
25
26
27
28
29
30
31
# File 'lib/postsvg/colors.rb', line 22

def self.cmyk2rgb(cmyk)
  c, m, y, k = cmyk
  r = 255 * (1 - c) * (1 - k)
  g = 255 * (1 - m) * (1 - k)
  b = 255 * (1 - y) * (1 - k)
  r = [[r, 0].max, 255].min.round
  g = [[g, 0].max, 255].min.round
  b = [[b, 0].max, 255].min.round
  format("rgb(%d, %d, %d)", r, g, b)
end

.color2rgb(rgb) ⇒ Object

Convert RGB values (0-1) to RGB color string



7
8
9
10
11
12
13
# File 'lib/postsvg/colors.rb', line 7

def self.color2rgb(rgb)
  r, g, b = rgb
  r = [[r * 255, 0].max, 255].min.round
  g = [[g * 255, 0].max, 255].min.round
  b = [[b * 255, 0].max, 255].min.round
  format("rgb(%d, %d, %d)", r, g, b)
end

.gray2rgb(gray) ⇒ Object

Convert grayscale value (0-1) to RGB color string



16
17
18
19
# File 'lib/postsvg/colors.rb', line 16

def self.gray2rgb(gray)
  val = [[gray * 255, 0].max, 255].min.round
  format("rgb(%d, %d, %d)", val, val, val)
end