Code

Indent support for XSLT extensions output.
[inkscape.git] / src / color.h
1 #ifndef __SP_COLOR_H__
2 #define __SP_COLOR_H__
4 /** \file
5  * Colors.
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   bulia byak <buliabyak@users.sf.net>
10  *   Jon A. Cruz <jon@joncruz.org>
11  *
12  * Copyright (C) 2001-2002 Lauris Kaplinski
13  * Copyright (C) 2001 Ximian, Inc.
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #include <gdk/gdktypes.h>
19 #include <string>
21 /* Useful composition macros */
23 #define SP_RGBA32_R_U(v) (((v) >> 24) & 0xff)
24 #define SP_RGBA32_G_U(v) (((v) >> 16) & 0xff)
25 #define SP_RGBA32_B_U(v) (((v) >> 8) & 0xff)
26 #define SP_RGBA32_A_U(v) ((v) & 0xff)
27 #define SP_COLOR_U_TO_F(v) ((v) / 255.0)
28 #define SP_COLOR_F_TO_U(v) ((unsigned int) ((v) * 255. + .5))
29 #define SP_RGBA32_R_F(v) SP_COLOR_U_TO_F (SP_RGBA32_R_U (v))
30 #define SP_RGBA32_G_F(v) SP_COLOR_U_TO_F (SP_RGBA32_G_U (v))
31 #define SP_RGBA32_B_F(v) SP_COLOR_U_TO_F (SP_RGBA32_B_U (v))
32 #define SP_RGBA32_A_F(v) SP_COLOR_U_TO_F (SP_RGBA32_A_U (v))
33 #define SP_RGBA32_U_COMPOSE(r,g,b,a) ((((r) & 0xff) << 24) | (((g) & 0xff) << 16) | (((b) & 0xff) << 8) | ((a) & 0xff))
34 #define SP_RGBA32_F_COMPOSE(r,g,b,a) SP_RGBA32_U_COMPOSE (SP_COLOR_F_TO_U (r), SP_COLOR_F_TO_U (g), SP_COLOR_F_TO_U (b), SP_COLOR_F_TO_U (a))
36 struct SVGICCColor;
38 /**
39  * An RGB color with optional icc-color part
40  */
41 struct SPColor {
42     SPColor();
43     SPColor( SPColor const& other );
44     SPColor( float r, float g, float b );
45     SPColor( guint32 value );
46     virtual ~SPColor();
48     SPColor& operator= (SPColor const& other);
50     bool operator == ( SPColor const& other ) const;
51     bool isClose( SPColor const& other, float epsilon ) const;
53     void set( float r, float g, float b );
54     void set( guint32 value );
56     guint32 toRGBA32( gint alpha ) const;
57     guint32 toRGBA32( gdouble alpha ) const;
59     std::string toString() const;
61     SVGICCColor* icc;
62     union {
63         float c[3];
64     } v;
65 };
67 guint32 sp_color_get_rgba32_ualpha (const SPColor *color, guint32 alpha);
68 guint32 sp_color_get_rgba32_falpha (const SPColor *color, float alpha);
70 void sp_color_get_rgb_floatv (const SPColor *color, float *rgb);
71 void sp_color_get_cmyk_floatv (const SPColor *color, float *cmyk);
73 /* Plain mode helpers */
75 void sp_color_rgb_to_hsv_floatv (float *hsv, float r, float g, float b);
76 void sp_color_hsv_to_rgb_floatv (float *rgb, float h, float s, float v);
78 void sp_color_rgb_to_hsl_floatv (float *hsl, float r, float g, float b);
79 void sp_color_hsl_to_rgb_floatv (float *rgb, float h, float s, float l);
81 void sp_color_rgb_to_cmyk_floatv (float *cmyk, float r, float g, float b);
82 void sp_color_cmyk_to_rgb_floatv (float *rgb, float c, float m, float y, float k);
85 #endif