1
by mental
moving trunk for module inkscape |
1 |
#ifndef __SP_COLOR_H__
|
2 |
#define __SP_COLOR_H__
|
|
3 |
||
4 |
/** \file
|
|
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
5 |
* Colors.
|
1
by mental
moving trunk for module inkscape |
6 |
*
|
7 |
* Author:
|
|
8 |
* Lauris Kaplinski <lauris@kaplinski.com>
|
|
9 |
* bulia byak <buliabyak@users.sf.net>
|
|
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
10 |
* Jon A. Cruz <jon@joncruz.org>
|
1
by mental
moving trunk for module inkscape |
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 |
*/
|
|
17 |
||
9020
by JazzyNico
Code refactoring and merging with trunk (revision 10599). |
18 |
#include <gdk/gdk.h> |
3794
by joncruz
Initial support for icc color selection including CMYK |
19 |
#include <string> |
1
by mental
moving trunk for module inkscape |
20 |
|
21 |
/* Useful composition macros */
|
|
22 |
||
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)
|
|
7616
by jaspervdg
And now gradients should be (almost) perfect... The gradient vector is set up to be a good approximation to the "true" gradient and it is used consistently throughout (I hope). |
28 |
#define SP_COLOR_F_TO_U(v) ((unsigned int) ((v) * 255. + .5))
|
1
by mental
moving trunk for module inkscape |
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))
|
|
35 |
||
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
36 |
struct SVGICCColor; |
1
by mental
moving trunk for module inkscape |
37 |
|
38 |
/**
|
|
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
39 |
* An RGB color with optional icc-color part
|
1
by mental
moving trunk for module inkscape |
40 |
*/
|
41 |
struct SPColor { |
|
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
42 |
SPColor(); |
43 |
SPColor( SPColor const& other ); |
|
44 |
SPColor( float r, float g, float b ); |
|
45 |
SPColor( guint32 value ); |
|
4024
by johanengelen
Add virtual to a lot of the destructors. Note: perhaps it will have to be reverted for some files to keep them C-compatible. |
46 |
virtual ~SPColor(); |
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
47 |
|
48 |
SPColor& operator= (SPColor const& other); |
|
49 |
||
50 |
bool operator == ( SPColor const& other ) const; |
|
51 |
bool isClose( SPColor const& other, float epsilon ) const; |
|
52 |
||
53 |
void set( float r, float g, float b ); |
|
54 |
void set( guint32 value ); |
|
55 |
||
56 |
guint32 toRGBA32( gint alpha ) const; |
|
57 |
guint32 toRGBA32( gdouble alpha ) const; |
|
58 |
||
3794
by joncruz
Initial support for icc color selection including CMYK |
59 |
std::string toString() const; |
60 |
||
3753
by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation |
61 |
SVGICCColor* icc; |
62 |
union { |
|
63 |
float c[3]; |
|
64 |
} v; |
|
1
by mental
moving trunk for module inkscape |
65 |
};
|
66 |
||
67 |
guint32 sp_color_get_rgba32_ualpha (const SPColor *color, guint32 alpha); |
|
68 |
guint32 sp_color_get_rgba32_falpha (const SPColor *color, float alpha); |
|
69 |
||
70 |
void sp_color_get_rgb_floatv (const SPColor *color, float *rgb); |
|
71 |
void sp_color_get_cmyk_floatv (const SPColor *color, float *cmyk); |
|
72 |
||
73 |
/* Plain mode helpers */
|
|
74 |
||
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); |
|
77 |
||
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); |
|
80 |
||
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); |
|
83 |
||
84 |
||
85 |
#endif
|
|
86 |