Code

Store cached icons to disk between runs, and invalidate/purge as needed.
[inkscape.git] / src / color.h
index 824604afc95fd1c76f36d12027d853b669dc32b5..bebeaec60b4e188bb2dbe7ae8514c6fbb8858b01 100644 (file)
@@ -2,11 +2,12 @@
 #define __SP_COLOR_H__
 
 /** \file
- * Colors and colorspaces
+ * 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.
@@ -15,8 +16,7 @@
  */
 
 #include <gdk/gdktypes.h>
-
-struct SPColorSpace;
+#include <string>
 
 /* Useful composition macros */
 
@@ -25,7 +25,7 @@ struct SPColorSpace;
 #define SP_RGBA32_B_U(v) (((v) >> 8) & 0xff)
 #define SP_RGBA32_A_U(v) ((v) & 0xff)
 #define SP_COLOR_U_TO_F(v) ((v) / 255.0)
-#define SP_COLOR_F_TO_U(v) ((unsigned int) ((v) * 255.9999))
+#define SP_COLOR_F_TO_U(v) ((unsigned int) ((v) * 255. + .5))
 #define SP_RGBA32_R_F(v) SP_COLOR_U_TO_F (SP_RGBA32_R_U (v))
 #define SP_RGBA32_G_F(v) SP_COLOR_U_TO_F (SP_RGBA32_G_U (v))
 #define SP_RGBA32_B_F(v) SP_COLOR_U_TO_F (SP_RGBA32_B_U (v))
@@ -33,44 +33,36 @@ struct SPColorSpace;
 #define SP_RGBA32_U_COMPOSE(r,g,b,a) ((((r) & 0xff) << 24) | (((g) & 0xff) << 16) | (((b) & 0xff) << 8) | ((a) & 0xff))
 #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))
 
-typedef enum {
-       SP_COLORSPACE_CLASS_INVALID,
-       SP_COLORSPACE_CLASS_NONE,
-       SP_COLORSPACE_CLASS_UNKNOWN,
-       SP_COLORSPACE_CLASS_PROCESS,
-       SP_COLORSPACE_CLASS_SPOT
-} SPColorSpaceClass;
-
-typedef enum {
-       SP_COLORSPACE_TYPE_INVALID,
-       SP_COLORSPACE_TYPE_NONE,
-       SP_COLORSPACE_TYPE_UNKNOWN,
-       SP_COLORSPACE_TYPE_RGB,
-       SP_COLORSPACE_TYPE_CMYK
-} SPColorSpaceType;
+struct SVGICCColor;
 
 /**
- * An RGBA color in an SPColorSpace
+ * An RGB color with optional icc-color part
  */
 struct SPColor {
-       const SPColorSpace *colorspace;
-       union {
-               float c[4];
-       } v;
-};
+    SPColor();
+    SPColor( SPColor const& other );
+    SPColor( float r, float g, float b );
+    SPColor( guint32 value );
+    virtual ~SPColor();
 
-SPColorSpaceClass sp_color_get_colorspace_class (const SPColor *color);
-SPColorSpaceType sp_color_get_colorspace_type (const SPColor *color);
+    SPColor& operator= (SPColor const& other);
 
-void sp_color_copy (SPColor *dst, const SPColor *src);
+    bool operator == ( SPColor const& other ) const;
+    bool isClose( SPColor const& other, float epsilon ) const;
 
-bool sp_color_is_equal (const SPColor *c0, const SPColor *c1);
-bool sp_color_is_close (const SPColor *c0, const SPColor *c1, float epsilon);
+    void set( float r, float g, float b );
+    void set( guint32 value );
 
-void sp_color_set_rgb_float (SPColor *color, float r, float g, float b);
-void sp_color_set_rgb_rgba32 (SPColor *color, guint32 value);
+    guint32 toRGBA32( gint alpha ) const;
+    guint32 toRGBA32( gdouble alpha ) const;
 
-void sp_color_set_cmyk_float (SPColor *color, float c, float m, float y, float k);
+    std::string toString() const;
+
+    SVGICCColor* icc;
+    union {
+        float c[3];
+    } v;
+};
 
 guint32 sp_color_get_rgba32_ualpha (const SPColor *color, guint32 alpha);
 guint32 sp_color_get_rgba32_falpha (const SPColor *color, float alpha);
@@ -90,6 +82,5 @@ void sp_color_rgb_to_cmyk_floatv (float *cmyk, float r, float g, float b);
 void sp_color_cmyk_to_rgb_floatv (float *rgb, float c, float m, float y, float k);
 
 
-
 #endif