Code

moving trunk for module inkscape
[inkscape.git] / src / color.h
1 #ifndef __SP_COLOR_H__
2 #define __SP_COLOR_H__
4 /** \file
5  * Colors and colorspaces
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   bulia byak <buliabyak@users.sf.net>
10  *
11  * Copyright (C) 2001-2002 Lauris Kaplinski
12  * Copyright (C) 2001 Ximian, Inc.
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include <gdk/gdktypes.h>
19 struct SPColorSpace;
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.9999))
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 typedef enum {
37         SP_COLORSPACE_CLASS_INVALID,
38         SP_COLORSPACE_CLASS_NONE,
39         SP_COLORSPACE_CLASS_UNKNOWN,
40         SP_COLORSPACE_CLASS_PROCESS,
41         SP_COLORSPACE_CLASS_SPOT
42 } SPColorSpaceClass;
44 typedef enum {
45         SP_COLORSPACE_TYPE_INVALID,
46         SP_COLORSPACE_TYPE_NONE,
47         SP_COLORSPACE_TYPE_UNKNOWN,
48         SP_COLORSPACE_TYPE_RGB,
49         SP_COLORSPACE_TYPE_CMYK
50 } SPColorSpaceType;
52 /**
53  * An RGBA color in an SPColorSpace
54  */
55 struct SPColor {
56         const SPColorSpace *colorspace;
57         union {
58                 float c[4];
59         } v;
60 };
62 SPColorSpaceClass sp_color_get_colorspace_class (const SPColor *color);
63 SPColorSpaceType sp_color_get_colorspace_type (const SPColor *color);
65 void sp_color_copy (SPColor *dst, const SPColor *src);
67 gboolean sp_color_is_equal (const SPColor *c0, const SPColor *c1);
68 gboolean sp_color_is_close (const SPColor *c0, const SPColor *c1, float epsilon);
70 void sp_color_set_rgb_float (SPColor *color, float r, float g, float b);
71 void sp_color_set_rgb_rgba32 (SPColor *color, guint32 value);
73 void sp_color_set_cmyk_float (SPColor *color, float c, float m, float y, float k);
75 guint32 sp_color_get_rgba32_ualpha (const SPColor *color, guint32 alpha);
76 guint32 sp_color_get_rgba32_falpha (const SPColor *color, float alpha);
78 void sp_color_get_rgb_floatv (const SPColor *color, float *rgb);
79 void sp_color_get_cmyk_floatv (const SPColor *color, float *cmyk);
81 /* Plain mode helpers */
83 void sp_color_rgb_to_hsv_floatv (float *hsv, float r, float g, float b);
84 void sp_color_hsv_to_rgb_floatv (float *rgb, float h, float s, float v);
86 void sp_color_rgb_to_hsl_floatv (float *hsl, float r, float g, float b);
87 void sp_color_hsl_to_rgb_floatv (float *rgb, float h, float s, float l);
89 void sp_color_rgb_to_cmyk_floatv (float *cmyk, float r, float g, float b);
90 void sp_color_cmyk_to_rgb_floatv (float *rgb, float c, float m, float y, float k);
94 #endif