Class: Abachrome::ColorModels::CMYK
- Inherits:
-
Object
- Object
- Abachrome::ColorModels::CMYK
- Includes:
- ToAbcd
- Defined in:
- lib/abachrome/color_models/cmyk.rb
Class Method Summary collapse
-
.from_rgb_gcr(r, g, b, amount = 1.0) ⇒ Array<AbcDecimal>
Alias for from_rgb_ucr with full GCR (the standard approach).
-
.from_rgb_naive(r, g, b) ⇒ Array<AbcDecimal>
Converts RGB values to CMYK using the standard naive conversion.
-
.from_rgb_ucr(r, g, b, gcr_amount = 1.0) ⇒ Array<AbcDecimal>
Converts RGB values to CMYK using Undercolor Removal (UCR).
-
.normalize(c, m, y, k) ⇒ Array<AbcDecimal>
Normalizes CMYK color component values to the [0,1] range.
-
.to_rgb(c, m, y, k) ⇒ Array<AbcDecimal>
Converts CMYK values back to RGB.
-
.total_area_coverage(c, m, y, k) ⇒ AbcDecimal
Calculates the Total Area Coverage (TAC) for CMYK values.
Methods included from ToAbcd
Class Method Details
.from_rgb_gcr(r, g, b, amount = 1.0) ⇒ Array<AbcDecimal>
Alias for from_rgb_ucr with full GCR (the standard approach). GCR is essentially the same as UCR but allows control over how much of the gray component to extract.
118 119 120 |
# File 'lib/abachrome/color_models/cmyk.rb', line 118 def from_rgb_gcr(r, g, b, amount = 1.0) from_rgb_ucr(r, g, b, amount) end |
.from_rgb_naive(r, g, b) ⇒ Array<AbcDecimal>
Converts RGB values to CMYK using the standard naive conversion. This produces high ink coverage and is generally not recommended for production.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/abachrome/color_models/cmyk.rb', line 63 def from_rgb_naive(r, g, b) r = AbcDecimal(r) g = AbcDecimal(g) b = AbcDecimal(b) # Simple complementary conversion c = AbcDecimal(1) - r m = AbcDecimal(1) - g y = AbcDecimal(1) - b k = AbcDecimal(0) [c, m, y, k] end |
.from_rgb_ucr(r, g, b, gcr_amount = 1.0) ⇒ Array<AbcDecimal>
Converts RGB values to CMYK using Undercolor Removal (UCR). This extracts the gray component to the black (K) channel, reducing ink usage.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/abachrome/color_models/cmyk.rb', line 85 def from_rgb_ucr(r, g, b, gcr_amount = 1.0) r = AbcDecimal(r) g = AbcDecimal(g) b = AbcDecimal(b) gcr = AbcDecimal(gcr_amount) # Calculate complementary CMY values c = AbcDecimal(1) - r m = AbcDecimal(1) - g y = AbcDecimal(1) - b # Find the minimum (gray component) k = [c, m, y].min * gcr # Remove the gray component from CMY if k > 0 if k.positive? c -= k m -= k y -= k end [c, m, y, k] end |
.normalize(c, m, y, k) ⇒ Array<AbcDecimal>
Normalizes CMYK color component values to the [0,1] range.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/abachrome/color_models/cmyk.rb', line 36 def normalize(c, m, y, k) [c, m, y, k].map do |value| case value when String if value.end_with?("%") value_without_percent = value.chomp("%") AbcDecimal(value_without_percent) / AbcDecimal(100) else AbcDecimal(value) end when Numeric if value > 1 AbcDecimal(value) / AbcDecimal(100) else AbcDecimal(value) end end end end |
.to_rgb(c, m, y, k) ⇒ Array<AbcDecimal>
Converts CMYK values back to RGB. This is a straightforward inverse of the naive RGB→CMY conversion plus the addition of the black channel.
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/abachrome/color_models/cmyk.rb', line 131 def to_rgb(c, m, y, k) c = AbcDecimal(c) m = AbcDecimal(m) y = AbcDecimal(y) k = AbcDecimal(k) # Standard CMYK to RGB conversion r = (AbcDecimal(1) - c) * (AbcDecimal(1) - k) g = (AbcDecimal(1) - m) * (AbcDecimal(1) - k) b = (AbcDecimal(1) - y) * (AbcDecimal(1) - k) [r, g, b] end |
.total_area_coverage(c, m, y, k) ⇒ AbcDecimal
Calculates the Total Area Coverage (TAC) for CMYK values. TAC is the sum of all four ink percentages and is critical in print workflows to prevent excessive ink that can cause smearing or paper damage.
154 155 156 |
# File 'lib/abachrome/color_models/cmyk.rb', line 154 def total_area_coverage(c, m, y, k) AbcDecimal(c) + AbcDecimal(m) + AbcDecimal(y) + AbcDecimal(k) end |