color.cpp revision b7ad916b7d3da57961c30b5c7312674fef2faa92
/*
* Colors.
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2001-2002 Lauris Kaplinski
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <math.h>
#include "color.h"
#include "svg/svg-icc-color.h"
#include "svg/svg-color.h"
#include "svg/css-ostringstream.h"
using Inkscape::CSSOStringStream;
#define PROFILE_EPSILON 0.00000001
icc(0)
{
v.c[0] = 0;
v.c[1] = 0;
v.c[2] = 0;
}
icc(0)
{
*this = other;
}
icc(0)
{
set( r, g, b );
}
icc(0)
{
}
{
delete icc;
icc = 0;
}
{
if (this == &other){
return *this;
}
v.c[0] = other.v.c[0];
if ( icc ) {
delete icc;
}
return *this;
}
/**
* Returns true if colors match.
*/
{
return match;
}
/**
* Returns true if no RGB value differs epsilon or more in both colors,
* false otherwise.
*/
{
bool match = false;
return match;
}
bool match = false;
match = true;
} else {
if ( match ) {
}
}
}
return match;
}
/**
* Sets RGB values and colorspace in color.
* \pre 0 <={r,g,b}<=1
*/
{
g_return_if_fail(r >= 0.0);
g_return_if_fail(r <= 1.0);
g_return_if_fail(g >= 0.0);
g_return_if_fail(g <= 1.0);
g_return_if_fail(b >= 0.0);
g_return_if_fail(b <= 1.0);
// TODO clear icc if set?
v.c[0] = r;
v.c[1] = g;
v.c[2] = b;
}
/**
* Converts 32bit value to RGB floats and sets color.
*/
{
// TODO clear icc if set?
}
/**
* Convert SPColor with integer alpha value to 32bit RGBA value.
* \pre alpha < 256
*/
{
SP_COLOR_F_TO_U(v.c[1]),
SP_COLOR_F_TO_U(v.c[2]),
alpha );
return rgba;
}
/**
* Convert SPColor with float alpha value to 32bit RGBA value.
* \pre color != NULL && 0 <= alpha <= 1
*/
{
}
{
char tmp[64] = {0};
if ( icc ) {
css << " ";
}
i != iEnd; ++i) {
css << ", " << *i;
}
css << ')';
}
}
/**
* Fill rgb float array with values from SPColor.
* \pre color != NULL && rgb != NULL && rgb[0-2] is meaningful
*/
void
{
}
/**
* Fill cmyk float array with values from SPColor.
* \pre color != NULL && cmyk != NULL && cmyk[0-3] is meaningful
*/
void
{
color->v.c[0],
color->v.c[1],
color->v.c[2] );
}
/* Plain mode helpers */
/**
* Fill hsv float array from r,g,b float values.
*/
void
sp_color_rgb_to_hsv_floatv (float *hsv, float r, float g, float b)
{
if (max > 0) {
} else {
}
if (r == max) {
} else if (g == max) {
} else {
}
}
else
hsv[0] = 0.0;
}
/**
* Fill rgb float array from h,s,v float values.
*/
void
sp_color_hsv_to_rgb_floatv (float *rgb, float h, float s, float v)
{
gdouble f, w, q, t, d;
d = h * 5.99999999;
f = d - floor (d);
w = v * (1.0 - s);
q = v * (1.0 - (s * f));
t = v * (1.0 - (s * (1.0 - f)));
if (d < 1.0) {
*rgb++ = v;
*rgb++ = t;
*rgb++ = w;
} else if (d < 2.0) {
*rgb++ = q;
*rgb++ = v;
*rgb++ = w;
} else if (d < 3.0) {
*rgb++ = w;
*rgb++ = v;
*rgb++ = t;
} else if (d < 4.0) {
*rgb++ = w;
*rgb++ = q;
*rgb++ = v;
} else if (d < 5.0) {
*rgb++ = t;
*rgb++ = w;
*rgb++ = v;
} else {
*rgb++ = v;
*rgb++ = w;
*rgb++ = q;
}
}
/**
* Fill hsl float array from r,g,b float values.
*/
void
sp_color_rgb_to_hsl_floatv (float *hsl, float r, float g, float b)
{
if (delta == 0) {
hsl[0] = 0;
hsl[1] = 0;
} else {
else
}
}
float
{
if (h < 0) h += 6.0;
if (h > 6) h -= 6.0;
if (h < 3) return v2;
return v1;
}
/**
* Fill rgb float array from h,s,l float values.
*/
void
sp_color_hsl_to_rgb_floatv (float *rgb, float h, float s, float l)
{
if (s == 0) {
rgb[0] = l;
rgb[1] = l;
rgb[2] = l;
} else {
float v2;
if (l < 0.5) {
v2 = l * (1 + s);
} else {
v2 = l + s - l*s;
}
}
}
/**
* Fill cmyk float array from r,g,b float values.
*/
void
sp_color_rgb_to_cmyk_floatv (float *cmyk, float r, float g, float b)
{
float c, m, y, k, kd;
c = 1.0 - r;
m = 1.0 - g;
y = 1.0 - b;
c = c - k;
m = m - k;
y = y - k;
kd = 1.0 - k;
if (kd > 1e-9) {
c = c / kd;
m = m / kd;
y = y / kd;
}
cmyk[0] = c;
cmyk[1] = m;
cmyk[2] = y;
cmyk[3] = k;
}
/**
* Fill rgb float array from c,m,y,k float values.
*/
void
sp_color_cmyk_to_rgb_floatv (float *rgb, float c, float m, float y, float k)
{
float kd;
kd = 1.0 - k;
c = c * kd;
m = m * kd;
y = y * kd;
c = c + k;
m = m + k;
y = y + k;
rgb[0] = 1.0 - c;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :