1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
* Color_Sep.cc -- ePiX CMYK Color separation functions
*
* This file is part of ePiX, a C++ library for creating high-quality
* figures in LaTeX
*
* Version 1.2.2
*
* Last Change: October 30, 2007
*
*
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
* Andrew D. Hwang <ahwang -at- holycross -dot- edu>
* Department of Mathematics and Computer Science
* College of the Holy Cross
* Worcester, MA, 01610-2395, USA
*
*
* ePiX is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ePiX is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ePiX; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include "Color_Utils.h"
#include "Color.h"
#include "Color_Sep.h"
namespace ePiX {
Cyan_Layer::Cyan_Layer(double arg)
: m_dens(clip_to_unit(arg)) { }
// Return Cyan channel of color
Cyan_Layer& Cyan_Layer::filter(const Color_Base& color)
{
Color_Base::RGB_Densities s(color.to_rgb());
if (Color(color).is_unset())
s = Color_Base::RGB_Densities(1,1,1);
m_dens = std::min(m_dens, 1-s.m_dens_red);
return *this;
}
Cyan_Layer* Cyan_Layer::clone() const
{
return new Cyan_Layer(*this);
}
Color_Base::RGB_Densities Cyan_Layer::to_rgb() const
{
return Color_Base::RGB_Densities(1-m_dens, 1, 1);
}
std::string Cyan_Layer::model() const
{
return "cmyk";
}
std::string Cyan_Layer::name() const
{
std::ostringstream nm;
nm << "c_proc_" << dtohex(m_dens);
return nm.str();
}
std::vector<double> Cyan_Layer::densities() const
{
std::vector<double> val(4);
val.at(0) = rd(m_dens);
val.at(1) = 0;
val.at(2) = 0;
val.at(3) = 0;
return val;
}
// Magenta_Layer
Magenta_Layer::Magenta_Layer(double arg)
: m_dens(clip_to_unit(arg)) { }
// Return Magenta channel of color
Magenta_Layer& Magenta_Layer::filter(const Color_Base& color)
{
Color_Base::RGB_Densities s(color.to_rgb());
if (Color(color).is_unset())
s = Color_Base::RGB_Densities(1,1,1);
m_dens = std::min(m_dens, 1-s.m_dens_green);
return *this;
}
Magenta_Layer* Magenta_Layer::clone() const
{
return new Magenta_Layer(*this);
}
Color_Base::RGB_Densities Magenta_Layer::to_rgb() const
{
return Color_Base::RGB_Densities(1, 1-m_dens, 1);
}
std::string Magenta_Layer::model() const
{
return "cmyk";
}
std::string Magenta_Layer::name() const
{
std::ostringstream nm;
nm << "m_proc_" << dtohex(m_dens);
return nm.str();
}
std::vector<double> Magenta_Layer::densities() const
{
std::vector<double> val(4);
val.at(0) = 0;
val.at(1) = rd(m_dens);
val.at(2) = 0;
val.at(3) = 0;
return val;
}
// Yellow_Layer
Yellow_Layer::Yellow_Layer(double arg)
: m_dens(clip_to_unit(arg)) { }
// Return Yellow channel of color
Yellow_Layer& Yellow_Layer::filter(const Color_Base& color)
{
Color_Base::RGB_Densities s(color.to_rgb());
if (Color(color).is_unset())
s = Color_Base::RGB_Densities(1,1,1);
m_dens = std::min(m_dens, 1-s.m_dens_blue);
return *this;
}
Yellow_Layer* Yellow_Layer::clone() const
{
return new Yellow_Layer(*this);
}
Color_Base::RGB_Densities Yellow_Layer::to_rgb() const
{
return Color_Base::RGB_Densities(1, 1, 1-m_dens);
}
std::string Yellow_Layer::model() const
{
return "cmyk";
}
std::string Yellow_Layer::name() const
{
std::ostringstream nm;
nm << "y_proc_" << dtohex(m_dens);
return nm.str();
}
std::vector<double> Yellow_Layer::densities() const
{
std::vector<double> val(4);
val.at(0) = 0;
val.at(1) = 0;
val.at(2) = rd(m_dens);
val.at(3) = 0;
return val;
}
// Black_Layer
Black_Layer::Black_Layer(double arg)
: m_dens(clip_to_unit(arg)) { }
// Return Black channel of color
Black_Layer& Black_Layer::filter(const Color_Base& color)
{
Color_Base::RGB_Densities s(color.to_rgb());
if (Color(color).is_unset())
s = Color_Base::RGB_Densities(1,1,1);
double c(1-s.m_dens_red), m(1-s.m_dens_green), y(1-s.m_dens_blue);
double k(std::min(std::min(c, m), y));
m_dens = std::min(m_dens, k);
return *this;
}
Black_Layer* Black_Layer::clone() const
{
return new Black_Layer(*this);
}
Color_Base::RGB_Densities Black_Layer::to_rgb() const
{
return Color_Base::RGB_Densities(1-m_dens, 1-m_dens, 1-m_dens);
}
std::string Black_Layer::model() const
{
return "cmyk";
}
std::string Black_Layer::name() const
{
std::ostringstream nm;
nm << "k_proc_" << dtohex(m_dens);
return nm.str();
}
std::vector<double> Black_Layer::densities() const
{
std::vector<double> val(4);
val.at(0) = 0;
val.at(1) = 0;
val.at(2) = 0;
val.at(3) = rd(m_dens);
return val;
}
// null operations
Cyan_Layer& Cyan_Layer::operator*= (double x) { return *this; }
Cyan_Layer& Cyan_Layer::blend(const Color_Base& col, double d)
{ return *this; }
Cyan_Layer& Cyan_Layer::superpose(const Color_Base& col) { return *this; }
Cyan_Layer& Cyan_Layer::invert() { return *this; }
Magenta_Layer& Magenta_Layer::operator*= (double x) { return *this; }
Magenta_Layer& Magenta_Layer::blend(const Color_Base& col, double d)
{ return *this; }
Magenta_Layer& Magenta_Layer::superpose(const Color_Base& col) { return *this; }
Magenta_Layer& Magenta_Layer::invert() { return *this; }
Yellow_Layer& Yellow_Layer::operator*= (double x) { return *this; }
Yellow_Layer& Yellow_Layer::blend(const Color_Base& col, double d)
{ return *this; }
Yellow_Layer& Yellow_Layer::superpose(const Color_Base& col) { return *this; }
Yellow_Layer& Yellow_Layer::invert() { return *this; }
Black_Layer& Black_Layer::operator*= (double x) { return *this; }
Black_Layer& Black_Layer::blend(const Color_Base& col, double d)
{ return *this; }
Black_Layer& Black_Layer::superpose(const Color_Base& col) { return *this; }
Black_Layer& Black_Layer::invert() { return *this; }
} // end of namespace
|