• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

go-color.h

Go to the documentation of this file.
00001 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
00002 /*
00003  * go-color.h
00004  *
00005  * Copyright (C) 1999, 2000 EMC Capital Management, Inc.
00006  *
00007  * Developed by Jon Trowbridge <trow@gnu.org> and
00008  * Havoc Pennington <hp@pobox.com>.
00009  *
00010  * This program is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License as
00012  * published by the Free Software Foundation; either version 2 of the
00013  * License, or (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00023  * USA
00024  */
00025 
00026 #ifndef GO_COLOR_H
00027 #define GO_COLOR_H
00028 
00029 #include <goffice/goffice.h>
00030 
00031 G_BEGIN_DECLS
00032 
00033 typedef struct {
00034     GOColor      color;
00035     char const  *name;  /* english name - eg. "white" */
00036 } GONamedColor;
00037 
00038 /*
00039   Some convenient macros for drawing into an RGB buffer.
00040   Beware of side effects, code-bloat, and all of the other classic
00041   cpp-perils...
00042 */
00043 
00044 #define GO_COLOR_FROM_GDK_RGBA(c)   GO_COLOR_FROM_RGBA((int)((c).red * 255.), (int)((c).green * 255.), (int)((c).blue * 255.), (int)((c).alpha * 255.))
00045 
00046 #define GO_COLOR_FROM_RGB(r,g,b)    ((((guint)(r&0xff))<<24)|(((guint)(g&0xff))<<16)|((guint)(b&0xff)<<8)|0xff)
00047 #define GO_COLOR_FROM_RGBA(r,g,b,a) ((((guint)(r&0xff))<<24)|(((guint)(g&0xff))<<16)|((guint)(b&0xff)<<8)|(guint)(a&0xff))
00048 #define GO_COLOR_WHITE  GO_COLOR_FROM_RGB(0xff, 0xff, 0xff)
00049 #define GO_COLOR_BLACK   GO_COLOR_FROM_RGB(0x00, 0x00, 0x00)
00050 #define GO_COLOR_RED     GO_COLOR_FROM_RGB(0xff, 0x00, 0x00)
00051 #define GO_COLOR_GREEN   GO_COLOR_FROM_RGB(0x00, 0xff, 0x00)
00052 #define GO_COLOR_BLUE   GO_COLOR_FROM_RGB(0x00, 0x00, 0xff)
00053 #define GO_COLOR_YELLOW  GO_COLOR_FROM_RGB(0xff, 0xff, 0x00)
00054 #define GO_COLOR_VIOLET  GO_COLOR_FROM_RGB(0xff, 0x00, 0xff)
00055 #define GO_COLOR_CYAN    GO_COLOR_FROM_RGB(0x00, 0xff, 0xff)
00056 #define GO_COLOR_GREY(x) GO_COLOR_FROM_RGB(x,x,x)
00057 
00058 #define GO_COLOR_UINT_R(x) (((guint)(x))>>24)
00059 #define GO_COLOR_UINT_G(x) ((((guint)(x))>>16)&0xff)
00060 #define GO_COLOR_UINT_B(x) ((((guint)(x))>>8)&0xff)
00061 #define GO_COLOR_UINT_A(x) (((guint)(x))&0xff)
00062 #define GO_COLOR_CHANGE_R(x, r) (((x)&(~(0xff<<24)))|(((r)&0xff)<<24))
00063 #define GO_COLOR_CHANGE_G(x, g) (((x)&(~(0xff<<16)))|(((g)&0xff)<<16))
00064 #define GO_COLOR_CHANGE_B(x, b) (((x)&(~(0xff<<8)))|(((b)&0xff)<<8))
00065 #define GO_COLOR_CHANGE_A(x, a) (((x)&(~0xff))|((a)&0xff))
00066 #define GO_COLOR_TO_RGB(u,r,g,b) \
00067 { (*(r)) = ((u)>>24)&0xff; (*(g)) = ((u)>>16)&0xff; (*(b)) = ((u)>>8)&0xff; }
00068 #define GO_COLOR_TO_RGBA(u,r,g,b,a) \
00069 {GO_COLOR_TO_RGB((u),r,g,b); (*(a)) = (u)&0xff; }
00070 #define GO_COLOR_MONO_INTERPOLATE(v1, v2, t) ((gint)go_rint((v2)*(t)+(v1)*(1-(t))))
00071 #define GO_COLOR_INTERPOLATE(c1, c2, t) \
00072   GO_COLOR_FROM_RGBA( GO_COLOR_MONO_INTERPOLATE(GO_COLOR_UINT_R(c1), GO_COLOR_UINT_R(c2), t), \
00073         GO_COLOR_MONO_INTERPOLATE(GO_COLOR_UINT_G(c1), GO_COLOR_UINT_G(c2), t), \
00074         GO_COLOR_MONO_INTERPOLATE(GO_COLOR_UINT_B(c1), GO_COLOR_UINT_B(c2), t), \
00075         GO_COLOR_MONO_INTERPOLATE(GO_COLOR_UINT_A(c1), GO_COLOR_UINT_A(c2), t) )
00076 
00077 #define GO_COLOR_DOUBLE_R(x) (GO_COLOR_UINT_R(x)/255.0)
00078 #define GO_COLOR_DOUBLE_G(x) (GO_COLOR_UINT_G(x)/255.0)
00079 #define GO_COLOR_DOUBLE_B(x) (GO_COLOR_UINT_B(x)/255.0)
00080 #define GO_COLOR_DOUBLE_A(x) (GO_COLOR_UINT_A(x)/255.0)
00081 
00082 #define GO_COLOR_TO_CAIRO(x) GO_COLOR_DOUBLE_R(x),GO_COLOR_DOUBLE_G(x),GO_COLOR_DOUBLE_B(x),GO_COLOR_DOUBLE_A(x)
00083 
00084 gboolean  go_color_from_str (char const *str, GOColor *res);
00085 gchar    *go_color_as_str   (GOColor color);
00086 PangoAttribute *go_color_to_pango (GOColor color, gboolean is_fore);
00087 #ifdef GOFFICE_WITH_GTK
00088 GdkRGBA *go_color_to_gdk_rgba   (GOColor color, GdkRGBA *res);
00089 #endif
00090 
00091 G_END_DECLS
00092 
00093 #endif /* GO_COLOR_H */

Generated on Wed Mar 5 2014 for AbiWord by  doxygen 1.7.1