color.cpp revision 7dbf6452671352c61f0176f2492814251338410e
#define __SP_COLOR_C__
/** \file
* Colors and colorspaces.
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* 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"
/// A color space is just a name.
struct SPColorSpace {
};
/**
* Returns one of three values depending on if color is valid and if it
* has a valid color space. Likely redundant as soon as this is C++.
*/
{
return SP_COLORSPACE_CLASS_UNKNOWN;
}
/**
* Returns the SPColorSpaceType corresponding to color's color space.
* \todo color->colorspace should simply be a named enum.
*/
{
return SP_COLORSPACE_TYPE_UNKNOWN;
}
/**
* Shallow copy of color struct with NULL check.
*/
void
{
}
/**
*/
{
return TRUE;
}
/**
* Returns TRUE if no RGB value differs epsilon or more in both colors,
* with CMYK aditionally comparing opacity, or if c0 or c1 is NULL.
* \note Do we want the latter?
*/
{
return TRUE;
}
/**
* Sets RGB values and colorspace in color.
* \pre color != NULL && 0 <={r,g,b}<=1
*/
void
{
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);
color->v.c[0] = r;
color->v.c[1] = g;
color->v.c[2] = b;
color->v.c[3] = 0;
}
/**
* Converts 32bit value to RGB floats and sets color.
* \pre color != NULL
*/
void
{
color->v.c[3] = 0;
}
/**
* Sets CMYK values and colorspace in color.
* \pre color != NULL && 0 <={c,m,y,k}<=1
*/
void
{
g_return_if_fail(c >= 0.0);
g_return_if_fail(c <= 1.0);
g_return_if_fail(m >= 0.0);
g_return_if_fail(m <= 1.0);
g_return_if_fail(y >= 0.0);
g_return_if_fail(y <= 1.0);
g_return_if_fail(k >= 0.0);
g_return_if_fail(k <= 1.0);
color->v.c[0] = c;
color->v.c[1] = m;
color->v.c[2] = y;
color->v.c[3] = k;
}
/**
* Convert SPColor with integer alpha value to 32bit RGBA value.
* \pre color != NULL && alpha < 256
*/
{
alpha);
} else {
float rgb[3];
alpha);
}
return rgba;
}
/**
* Convert SPColor with float alpha value to 32bit RGBA value.
* \pre color != NULL && 0 <= alpha <= 1
*/
{
}
/**
* Fill rgb float array with values from SPColor.
* \pre color != NULL && rgb != NULL && rgb[0-2] is meaningful
*/
void
{
color->v.c[0],
color->v.c[1],
color->v.c[2],
color->v.c[3]);
}
}
/**
* 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:encoding=utf-8:textwidth=99 :