[gnome-color-manager: 1/80] Split off a library, libcolor-glib that we can install and use in the future



commit cd73874d435a23edf3f21d8806a64e5bb98ee6ab
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jul 17 22:08:03 2010 +0100

    Split off a library, libcolor-glib that we can install and use in the future

 Makefile.am                       |    2 +
 configure.ac                      |   58 ++++++++-
 docs/.gitignore                   |    1 +
 docs/Makefile.am                  |    2 +
 docs/api/.gitignore               |   25 ++++
 docs/api/Makefile.am              |   76 +++++++++++
 docs/api/libcolor-glib-docs.sgml  |   35 +++++
 docs/api/version.xml.in           |    1 +
 libcolor-glib/Makefile.am         |  102 ++++++++++++++
 libcolor-glib/gcm-common.c        |  271 +++++++++++++++++++++++++++++++++++++
 libcolor-glib/gcm-common.h        |  104 ++++++++++++++
 libcolor-glib/gcm-self-test.c     |  124 +++++++++++++++++
 libcolor-glib/gcm-version.h.in    |   44 ++++++
 libcolor-glib/libcolor-glib.h     |   36 +++++
 libcolor-glib/libcolor-glib.pc.in |   12 ++
 15 files changed, 892 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 11feb0e..2b98185 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,6 @@
 SUBDIRS = 						\
+	libcolor-glib					\
+	docs						\
 	data						\
 	help						\
 	man						\
diff --git a/configure.ac b/configure.ac
index 36dbe81..52d8be3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,14 +1,48 @@
+# Copyright (C) 2010 Richard Hughes <richard hughsie com>
 AC_PREREQ(2.63)
 
-AC_INIT([gnome-color-manager],[2.31.5],[http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-color-manager])
+m4_define([gcm_major_version], [2])
+m4_define([gcm_minor_version], [31])
+m4_define([gcm_micro_version], [5])
+m4_define([gcm_version],
+          [gcm_major_version.gcm_minor_version.gcm_micro_version])
+
+AC_INIT([gnome-color-manager],[gcm_version],[http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-color-manager])
 AC_CONFIG_SRCDIR(src)
 AM_INIT_AUTOMAKE([1.9 tar-ustar dist-bzip2])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 
+GOBJECT_INTROSPECTION_CHECK([0.6.7])
+
 # enable nice build output on automake1.11
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
+GCM_MAJOR_VERSION=gcm_major_version
+GCM_MINOR_VERSION=gcm_minor_version
+GCM_MICRO_VERSION=gcm_micro_version
+GCM_VERSION=gcm_version
+AC_SUBST(GCM_MAJOR_VERSION)
+AC_SUBST(GCM_MINOR_VERSION)
+AC_SUBST(GCM_MICRO_VERSION)
+AC_SUBST(GCM_VERSION)
+
+# libtool versioning - this applies to libcolor-glib
+#
+# See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details
+#
+# increment;
+# CURRENT	If the API or ABI interface has changed (reset REVISION to 0)
+# REVISION	If the API and ABI remains the same, but bugs are fixed.
+# AGE		If libgcm can be linked into executables which can be
+# 		built with previous versions of this library. Don't use.
+LT_CURRENT=1
+LT_REVISION=0
+LT_AGE=0
+AC_SUBST(LT_CURRENT)
+AC_SUBST(LT_REVISION)
+AC_SUBST(LT_AGE)
+
 AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_INSTALL
@@ -194,6 +228,22 @@ if test "x$HAVE_CUPS" != "xyes"; then
 fi
 
 dnl ---------------------------------------------------------------------------
+dnl - Generate man pages ? (default enabled)
+dnl ---------------------------------------------------------------------------
+AC_ARG_ENABLE(man_pages, AS_HELP_STRING([--disable-man-pages],[Disable man pages generation]), enable_man_pages=$enableval)
+if test x$enable_man_pages != xno; then
+	AC_PATH_PROG(XSLTPROC, xsltproc, no)
+	if test x$enable_man_pages = xyes; then
+		if test "$XSLTPROC" = "no" ; then
+			AC_MSG_ERROR([xsltproc not found, it's needod to build man pages])
+		fi
+	fi
+else
+	XSLTPROC=no
+fi
+AM_CONDITIONAL(HAVE_XSLTPROC, [test "$XSLTPROC" != "no"])
+
+dnl ---------------------------------------------------------------------------
 dnl - Make paths available for source files
 dnl ---------------------------------------------------------------------------
 AC_SUBST(DATADIR, $datadir)
@@ -264,6 +314,12 @@ policy/Makefile
 po/Makefile.in
 rules/Makefile
 src/Makefile
+docs/Makefile
+docs/api/Makefile
+docs/api/version.xml
+libcolor-glib/Makefile
+libcolor-glib/gcm-version.h
+libcolor-glib/libcolor-glib.pc
 ])
 AC_OUTPUT
 
diff --git a/docs/.gitignore b/docs/.gitignore
new file mode 100644
index 0000000..a136337
--- /dev/null
+++ b/docs/.gitignore
@@ -0,0 +1 @@
+*.pdf
diff --git a/docs/Makefile.am b/docs/Makefile.am
new file mode 100644
index 0000000..265f2ec
--- /dev/null
+++ b/docs/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = 						\
+	api
diff --git a/docs/api/.gitignore b/docs/api/.gitignore
new file mode 100644
index 0000000..eb3e7dc
--- /dev/null
+++ b/docs/api/.gitignore
@@ -0,0 +1,25 @@
+Makefile.in
+Makefile.libs
+.libs
+*.bak
+*.gcno
+*.out
+*.txt
+tmpl
+xml
+html
+html-build.stamp
+html.stamp
+*-docs.xml
+*.args
+*.hierarchy
+*.interfaces
+*.prerequisites
+*.signals
+*.types
+scan-build.stamp
+sgml-build.stamp
+sgml.stamp
+tmpl-build.stamp
+tmpl.stamp
+version.xml
diff --git a/docs/api/Makefile.am b/docs/api/Makefile.am
new file mode 100644
index 0000000..f0e83cd
--- /dev/null
+++ b/docs/api/Makefile.am
@@ -0,0 +1,76 @@
+## Process this file with automake to produce Makefile.in
+
+# We require automake 1.6 at least.
+AUTOMAKE_OPTIONS = 1.6
+
+# The name of the module, e.g. 'glib'.
+DOC_MODULE=libcolor-glib
+
+# The top-level SGML file.
+DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
+
+# The directory containing the source code. Relative to $(srcdir).
+# gtk-doc will search all .c & .h files beneath here for inline comments
+# documenting the functions and macros.
+DOC_SOURCE_DIR=../../libcolor-glib
+
+# Extra options to pass to gtkdoc-scangobj. Not normally needed.
+SCANGOBJ_OPTIONS=
+
+# Extra options to supply to gtkdoc-scan.
+SCAN_OPTIONS=
+
+# Extra options to supply to gtkdoc-mkdb.
+MKDB_OPTIONS=--sgml-mode --output-format=xml
+
+# Extra options to supply to gtkdoc-mktmpl
+MKTMPL_OPTIONS=
+
+# Extra options to supply to gtkdoc-fixref. Not normally needed.
+FIXXREF_OPTIONS=
+
+# Used for dependencies. The docs will be rebuilt if any of these change.
+HFILE_GLOB=$(top_srcdir)/libcolor-glib/gcm-*.h
+CFILE_GLOB=$(top_srcdir)/libcolor-glib/gcm-*.c
+
+# Header files to ignore when scanning.
+IGNORE_HFILES =						\
+	config.h					\
+	gcm-marshal.h					\
+	$(NULL)
+
+# Images to copy into HTML directory.
+HTML_IMAGES =
+
+# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
+content_files =						\
+	version.xml					\
+	$(NULL)
+
+# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded
+# These files must be listed here *and* in content_files
+expand_content_files=
+
+# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
+# Only needed if you are using gtkdoc-scangobj to dynamically query widget
+# signals and properties.
+INCLUDES =						\
+	$(POLKIT_CFLAGS)				\
+	$(DBUS_CFLAGS)					\
+	$(GLIB_CFLAGS)					\
+	-I$(top_builddir)/libcolor-glib			\
+	-I$(top_srcdir)/libcolor-glib
+
+GCM_GLIB_LIBS =					\
+	$(top_builddir)/libcolor-glib/libcolor-glib.la
+
+GTKDOC_LIBS =						\
+	$(GLIB_LIBS)					\
+	$(GCM_GLIB_LIBS)
+
+# This includes the standard gtk-doc make rules, copied by gtkdocize.
+include $(top_srcdir)/gtk-doc.make
+
+# Other files to distribute
+EXTRA_DIST += version.xml.in
+
diff --git a/docs/api/libcolor-glib-docs.sgml b/docs/api/libcolor-glib-docs.sgml
new file mode 100644
index 0000000..3ebca55
--- /dev/null
+++ b/docs/api/libcolor-glib-docs.sgml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd";
+[
+  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
+]>
+<book id="index">
+  <bookinfo>
+    <title>gcm Reference Manual</title>
+    <releaseinfo>
+      for gcm [VERSION].
+      The latest version of this documentation can be found on-line at
+      <ulink role="online-location" url="http://[SERVER]/gcm/index.html";>http://[SERVER]/gcm/</ulink>.
+    </releaseinfo>
+  </bookinfo>
+
+  <chapter>
+    <title>[Insert title here]</title>
+    <xi:include href="xml/gcm-device.xml"/>
+    <xi:include href="xml/gcm-client.xml"/>
+    <xi:include href="xml/gcm-version.xml"/>
+    <xi:include href="xml/gcm-common.xml"/>
+
+  </chapter>
+  <chapter id="object-tree">
+    <title>Object Hierarchy</title>
+     <xi:include href="xml/tree_index.sgml"/>
+  </chapter>
+  <index id="api-index-full">
+    <title>API Index</title>
+    <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
+  </index>
+
+  <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
+</book>
diff --git a/docs/api/version.xml.in b/docs/api/version.xml.in
new file mode 100644
index 0000000..d78bda9
--- /dev/null
+++ b/docs/api/version.xml.in
@@ -0,0 +1 @@
+ VERSION@
diff --git a/libcolor-glib/Makefile.am b/libcolor-glib/Makefile.am
new file mode 100644
index 0000000..1819424
--- /dev/null
+++ b/libcolor-glib/Makefile.am
@@ -0,0 +1,102 @@
+NULL =
+
+-include $(INTROSPECTION_MAKEFILE)
+INTROSPECTION_GIRS =
+INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir)
+INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
+
+INCLUDES = \
+	$(GLIB_CFLAGS)						\
+	$(USB_CFLAGS)						\
+	-I$(top_srcdir)/libcolor-glib				\
+	-I$(top_builddir)/libcolor-glib				\
+	-I.							\
+	-DGCM_COMPILATION					\
+	-DLOCALSTATEDIR=\""$(localstatedir)"\" 			\
+	-DTESTDATADIR=\""$(top_srcdir)/data/tests"\"		\
+	-DI_KNOW_THE_GCM_GLIB_API_IS_SUBJECT_TO_CHANGE		\
+	-DPACKAGE_DATA_DIR=\""$(datadir)"\"			\
+	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = 						\
+	libcolor-glib.pc
+
+lib_LTLIBRARIES =						\
+	libcolor-glib.la
+
+libcolor_glib_includedir = $(includedir)/libcolor-glib
+
+libcolor_glib_include_HEADERS =					\
+	libcolor-glib.h						\
+	gcm-version.h						\
+	gcm-common.h						\
+	$(NULL)
+
+libcolor_glib_la_SOURCES =					\
+	libcolor-glib.h						\
+	gcm-common.h						\
+	gcm-common.c						\
+	gcm-version.h						\
+	$(NULL)
+
+libcolor_glib_la_LIBADD =					\
+	$(USB_LIBS)						\
+	$(GLIB_LIBS)
+
+libcolor_glib_la_LDFLAGS =					\
+	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)	\
+	-export-dynamic						\
+	-no-undefined						\
+	-export-symbols-regex '^gcm_.*'				\
+	$(NULL)
+
+libcolor_glib_la_CFLAGS =					\
+	$(WARNINGFLAGS_C)					\
+	$(NULL)
+
+if HAVE_TESTS
+check_PROGRAMS =						\
+	gcm-self-test
+
+gcm_self_test_SOURCES =						\
+	gcm-self-test.c
+
+gcm_self_test_LDADD =						\
+	libcolor-glib.la					\
+	$(GLIB_LIBS)
+
+gcm_self_test_CFLAGS = $(AM_CFLAGS) $(WARNINGFLAGS_C)
+
+TESTS = gcm-self-test
+endif
+
+EXTRA_DIST =							\
+	libcolor-glib.pc.in					\
+	gcm-version.h.in
+
+CLEANFILES = $(BUILT_SOURCES)
+
+if FALSE
+introspection_sources = $(libcolor_glib_la_SOURCES)
+
+gcmGlib-1.0.gir: libcolor-glib.la
+gcmGlib_1_0_gir_INCLUDES = GObject-2.0
+gcmGlib_1_0_gir_CFLAGS = $(INCLUDES) -DI_KNOW_THE_GCM_GLIB_API_IS_SUBJECT_TO_CHANGE
+gcmGlib_1_0_gir_LIBS = libcolor-glib.la
+gcmGlib_1_0_gir_FILES = $(addprefix $(srcdir)/,$(introspection_sources))
+INTROSPECTION_GIRS += gcmGlib-1.0.gir
+
+girdir = $(datadir)/gir-1.0
+dist_gir_DATA = $(INTROSPECTION_GIRS)
+
+typelibdir = $(libdir)/girepository-1.0
+typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
+
+CLEANFILES += $(dist_gir_DATA) $(typelib_DATA)
+endif
+
+clean-local:
+	rm -f *~
+	rm -f $(CLEANFILES)
+
diff --git a/libcolor-glib/gcm-common.c b/libcolor-glib/gcm-common.c
new file mode 100644
index 0000000..f6217fd
--- /dev/null
+++ b/libcolor-glib/gcm-common.c
@@ -0,0 +1,271 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+/**
+ * SECTION:gcm-common
+ * @short_description: Common functionality
+ *
+ * A GObject to use for common shizzle.
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <glib-object.h>
+
+#include <gcm-common.h>
+
+/**
+ * gcm_convert_rgb_int_to_rgb:
+ **/
+void
+gcm_convert_rgb_int_to_rgb (GcmColorRgbInt *rgb_int, GcmColorRgb *rgb)
+{
+	rgb->red = (gdouble) rgb_int->red / 255.0f;
+	rgb->green = (gdouble) rgb_int->green / 255.0f;
+	rgb->blue = (gdouble) rgb_int->blue / 255.0f;
+}
+
+/**
+ * gcm_convert_rgb_to_rgb_int:
+ **/
+void
+gcm_convert_rgb_to_rgb_int (GcmColorRgb *rgb, GcmColorRgbInt *rgb_int)
+{
+	rgb_int->red = (gdouble) rgb->red * 255.0f;
+	rgb_int->green = (gdouble) rgb->green * 255.0f;
+	rgb_int->blue = (gdouble) rgb->blue * 255.0f;
+}
+
+/**
+ * gcm_convert_Yxy_to_XYZ:
+ **/
+void
+gcm_convert_Yxy_to_XYZ (GcmColorYxy *src, GcmColorXYZ *dest)
+{
+	g_assert (src->Y >= 0.0f);
+	g_assert (src->x >= 0.0f);
+	g_assert (src->y >= 0.0f);
+	g_assert (src->Y <= 100.0f);
+	g_assert (src->x <= 1.0f);
+	g_assert (src->y <= 1.0f);
+
+	/* very small luminance */
+	if (src->Y < 1e-6) {
+		dest->X = 0.0f;
+		dest->Y = 0.0f;
+		dest->Z = 0.0f;
+		return;
+	}
+
+	dest->X = (src->x * src->Y) / src->y;
+	dest->Y = src->Y;
+	dest->Z = (1.0f - src->x - src->y) * src->Y / src->y;
+}
+
+/**
+ * gcm_convert_XYZ_to_Yxy:
+ **/
+void
+gcm_convert_XYZ_to_Yxy (GcmColorXYZ *src, GcmColorYxy *dest)
+{
+	gdouble sum;
+
+	g_assert (src->X >= 0.0f);
+	g_assert (src->Y >= 0.0f);
+	g_assert (src->Z >= 0.0f);
+	g_assert (src->X < 96.0f);
+	g_assert (src->Y < 100.0f);
+	g_assert (src->Z < 109.0f);
+
+	/* prevent division by zero */
+	sum = src->X + src->Y + src->Z;
+	if (fabs (sum) < 1e-6) {
+		dest->Y = 0.0f;
+		dest->x = 0.0f;
+		dest->y = 0.0f;
+		return;
+	}
+
+	dest->Y = src->Y;
+	dest->x = src->X / sum;
+	dest->y = src->Y / sum;
+}
+
+/**
+ * gcm_vec3_clear:
+ **/
+void
+gcm_vec3_clear (GcmVec3 *src)
+{
+	src->v0 = 0.0f;
+	src->v1 = 0.0f;
+	src->v2 = 0.0f;
+}
+
+/**
+ * gcm_vec3_scalar_multiply:
+ **/
+void
+gcm_vec3_scalar_multiply (GcmVec3 *src, gdouble value, GcmVec3 *dest)
+{
+	dest->v0 = src->v0 * value;
+	dest->v1 = src->v1 * value;
+	dest->v2 = src->v2 * value;
+}
+
+/**
+ * gcm_vec3_to_string:
+ **/
+gchar *
+gcm_vec3_to_string (GcmVec3 *src)
+{
+	return g_strdup_printf ("\n/ %0 .3f \\\n"
+				"| %0 .3f |\n"
+				"\\ %0 .3f /\n",
+				src->v0, src->v1, src->v2);
+}
+
+/**
+ * gcm_vec3_get_data:
+ **/
+gdouble *
+gcm_vec3_get_data (GcmVec3 *src)
+{
+	return (gdouble *) src;
+}
+
+/**
+ * gcm_mat33_clear:
+ **/
+void
+gcm_mat33_clear (GcmMat3x3 *dest)
+{
+	guint i;
+	gdouble *temp = (gdouble *) dest;
+	for (i=0; i<3*3; i++)
+		temp[i] = 0.0f;
+}
+
+/**
+ * gcm_mat33_to_string:
+ **/
+gchar *
+gcm_mat33_to_string (GcmMat3x3 *src)
+{
+	return g_strdup_printf ("\n/ %0 .3f  %0 .3f  %0 .3f \\\n"
+				"| %0 .3f  %0 .3f  %0 .3f |\n"
+				"\\ %0 .3f  %0 .3f  %0 .3f /\n",
+				src->m00, src->m01, src->m02,
+				src->m10, src->m11, src->m12,
+				src->m20, src->m21, src->m22);
+}
+
+/**
+ * gcm_mat33_get_data:
+ **/
+gdouble *
+gcm_mat33_get_data (GcmMat3x3 *src)
+{
+	return (gdouble *) src;
+}
+
+/**
+ * gcm_mat33_set_identity:
+ **/
+void
+gcm_mat33_set_identity (GcmMat3x3 *dest)
+{
+	gcm_mat33_clear (dest);
+	dest->m00 = 1.0f;
+	dest->m11 = 1.0f;
+	dest->m22 = 1.0f;
+}
+
+/**
+ * gcm_mat33_vector_multiply:
+ **/
+void
+gcm_mat33_vector_multiply (GcmMat3x3 *mat_src, GcmVec3 *vec_src, GcmVec3 *vec_dest)
+{
+	vec_dest->v0 = mat_src->m00 * vec_src->v0 +
+		       mat_src->m01 * vec_src->v1 +
+		       mat_src->m02 * vec_src->v2;
+	vec_dest->v1 = mat_src->m10 * vec_src->v0 +
+		       mat_src->m11 * vec_src->v1 +
+		       mat_src->m12 * vec_src->v2;
+	vec_dest->v2 = mat_src->m20 * vec_src->v0 +
+		       mat_src->m21 * vec_src->v1 +
+		       mat_src->m22 * vec_src->v2;
+}
+
+/**
+ * gcm_mat33_matrix_multiply:
+ **/
+void
+gcm_mat33_matrix_multiply (GcmMat3x3 *mat_src1, GcmMat3x3 *mat_src2, GcmMat3x3 *mat_dest)
+{
+	guint8 i, j, k;
+	gdouble *src1 = gcm_mat33_get_data (mat_src1);
+	gdouble *src2 = gcm_mat33_get_data (mat_src2);
+	gdouble *dest = gcm_mat33_get_data (mat_dest);
+
+	for (i=0; i<3; i++) {
+		for (j=0; j<3; j++) {
+			for (k=0; k<3; k++) {
+				dest[3 * i + j] += src1[i * 3 + k] * src2[k * 3 + j];
+			}
+		}
+	}
+}
+
+/**
+ * gcm_mat33_reciprocal:
+ *
+ * Return value: FALSE if det is zero (singular)
+ **/
+gboolean
+gcm_mat33_reciprocal (GcmMat3x3 *src, GcmMat3x3 *dest)
+{
+	double det = 0;
+
+	det  = src->m00 * (src->m11 * src->m22 - src->m12 * src->m21);
+	det -= src->m01 * (src->m10 * src->m22 - src->m12 * src->m20);
+	det += src->m02 * (src->m10 * src->m21 - src->m11 * src->m20);
+
+	/* division by zero */
+	if (fabs (det) < 1e-6)
+		return FALSE;
+
+	dest->m00 = (src->m11 * src->m22 - src->m12 * src->m21) / det;
+	dest->m01 = (src->m02 * src->m21 - src->m01 * src->m22) / det;
+	dest->m02 = (src->m01 * src->m12 - src->m02 * src->m11) / det;
+
+	dest->m10 = (src->m12 * src->m20 - src->m10 * src->m22) / det;
+	dest->m11 = (src->m00 * src->m22 - src->m02 * src->m20) / det;
+	dest->m12 = (src->m02 * src->m10 - src->m00 * src->m12) / det;
+
+	dest->m20 = (src->m10 * src->m21 - src->m11 * src->m20) / det;
+	dest->m21 = (src->m01 * src->m20 - src->m00 * src->m21) / det;
+	dest->m22 = (src->m00 * src->m11 - src->m01 * src->m10) / det;
+
+	return TRUE;
+}
diff --git a/libcolor-glib/gcm-common.h b/libcolor-glib/gcm-common.h
new file mode 100644
index 0000000..21c65bd
--- /dev/null
+++ b/libcolor-glib/gcm-common.h
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#if !defined (__GCM_H_INSIDE__) && !defined (GCM_COMPILATION)
+#error "Only <gcm.h> can be included directly."
+#endif
+
+#ifndef __GCM_COMMON_H__
+#define __GCM_COMMON_H__
+
+#define __GCM_COMMON_H_INSIDE__
+
+typedef struct {
+	guint8	 red;
+	guint8	 green;
+	guint8	 blue;
+} GcmColorRgbInt;
+
+typedef struct {
+	gdouble	 L;
+	gdouble	 a;
+	gdouble	 b;
+} GcmColorLab;
+
+typedef struct {
+	gdouble	 Y;
+	gdouble	 x;
+	gdouble	 y;
+} GcmColorYxy;
+
+typedef struct {
+	gdouble	 X;
+	gdouble	 Y;
+	gdouble	 Z;
+} GcmColorXYZ;
+
+typedef struct {
+	gdouble	 red;
+	gdouble	 green;
+	gdouble	 blue;
+} GcmColorRgb;
+
+typedef struct {
+	gdouble	 m00, m01, m02;
+	gdouble	 m10, m11, m12;
+	gdouble	 m20, m21, m22;
+	/* any addition fields go *after* the data */
+} GcmMat3x3;
+
+typedef struct {
+	double	 v0, v1, v2;
+	/* any addition fields go *after* the data */
+} GcmVec3;
+
+void		 gcm_convert_rgb_int_to_rgb	(GcmColorRgbInt		*rgb_int,
+						 GcmColorRgb		*rgb);
+void		 gcm_convert_rgb_to_rgb_int	(GcmColorRgb		*rgb,
+						 GcmColorRgbInt		*rgb_int);
+void		 gcm_convert_Yxy_to_XYZ		(GcmColorYxy		*src,
+						 GcmColorXYZ		*dest);
+void		 gcm_convert_XYZ_to_Yxy		(GcmColorXYZ		*src,
+						 GcmColorYxy		*dest);
+void		 gcm_vec3_clear			(GcmVec3		*src);
+void		 gcm_vec3_scalar_multiply	(GcmVec3		*src,
+						 gdouble		 value,
+						 GcmVec3		*dest);
+gchar		*gcm_vec3_to_string		(GcmVec3		*src);
+gdouble		*gcm_vec3_get_data		(GcmVec3		*src);
+void		 gcm_mat33_clear		(GcmMat3x3		*dest);
+gchar		*gcm_mat33_to_string		(GcmMat3x3		*src);
+gdouble		*gcm_mat33_get_data		(GcmMat3x3		*src);
+void		 gcm_mat33_set_identity		(GcmMat3x3		*dest);
+void		 gcm_mat33_vector_multiply	(GcmMat3x3		*mat_src,
+						 GcmVec3		*vec_src,
+						 GcmVec3		*vec_dest);
+void		 gcm_mat33_matrix_multiply	(GcmMat3x3		*mat_src1,
+						 GcmMat3x3		*mat_src2,
+						 GcmMat3x3		*mat_dest);
+gboolean	 gcm_mat33_reciprocal		(GcmMat3x3		*src,
+						 GcmMat3x3		*dest);
+
+
+#undef __GCM_COMMON_H_INSIDE__
+
+#endif /* __GCM_COMMON_H__ */
+
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
new file mode 100644
index 0000000..db59fdc
--- /dev/null
+++ b/libcolor-glib/gcm-self-test.c
@@ -0,0 +1,124 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+
+#include "gcm-common.h"
+
+static void
+gcm_test_common_func (void)
+{
+	GcmColorRgbInt rgb_int;
+	GcmColorRgb rgb;
+	GcmColorYxy Yxy;
+	GcmColorXYZ XYZ;
+	GcmMat3x3 mat;
+	GcmMat3x3 matsrc;
+
+	/* black */
+	rgb_int.red = 0x00; rgb_int.green = 0x00; rgb_int.blue = 0x00;
+	gcm_convert_rgb_int_to_rgb (&rgb_int, &rgb);
+	g_assert_cmpfloat (rgb.red, <, 0.01);
+	g_assert_cmpfloat (rgb.green, <, 0.01);
+	g_assert_cmpfloat (rgb.blue, <, 0.01);
+	g_assert_cmpfloat (rgb.red, >, -0.01);
+	g_assert_cmpfloat (rgb.green, >, -0.01);
+	g_assert_cmpfloat (rgb.blue, >, -0.01);
+
+	/* white */
+	rgb_int.red = 0xff; rgb_int.green = 0xff; rgb_int.blue = 0xff;
+	gcm_convert_rgb_int_to_rgb (&rgb_int, &rgb);
+	g_assert_cmpfloat (rgb.red, <, 1.01);
+	g_assert_cmpfloat (rgb.green, <, 1.01);
+	g_assert_cmpfloat (rgb.blue, <, 1.01);
+	g_assert_cmpfloat (rgb.red, >, 0.99);
+	g_assert_cmpfloat (rgb.green, >, 0.99);
+	g_assert_cmpfloat (rgb.blue, >, 0.99);
+
+	/* and back */
+	gcm_convert_rgb_to_rgb_int (&rgb, &rgb_int);
+	g_assert_cmpint (rgb_int.red, ==, 0xff);
+	g_assert_cmpint (rgb_int.green, ==, 0xff);
+	g_assert_cmpint (rgb_int.blue, ==, 0xff);
+
+	/* black */
+	rgb.red = 0.0f; rgb.green = 0.0f; rgb.blue = 0.0f;
+	gcm_convert_rgb_to_rgb_int (&rgb, &rgb_int);
+	g_assert_cmpint (rgb_int.red, ==, 0x00);
+	g_assert_cmpint (rgb_int.green, ==, 0x00);
+	g_assert_cmpint (rgb_int.blue, ==, 0x00);
+
+	/* Yxy -> XYZ */
+	Yxy.Y = 21.5;
+	Yxy.x = 0.31;
+	Yxy.y = 0.32;
+	gcm_convert_Yxy_to_XYZ (&Yxy, &XYZ);
+	g_assert_cmpfloat (XYZ.X, <, 21.0);
+	g_assert_cmpfloat (XYZ.X, >, 20.5);
+	g_assert_cmpfloat (XYZ.Y, <, 22.0);
+	g_assert_cmpfloat (XYZ.Y, >, 21.0);
+	g_assert_cmpfloat (XYZ.Z, <, 25.0);
+	g_assert_cmpfloat (XYZ.Z, >, 24.5);
+
+	/* and back */
+	gcm_convert_XYZ_to_Yxy (&XYZ, &Yxy);
+	g_assert_cmpfloat (Yxy.Y, <, 22.0);
+	g_assert_cmpfloat (Yxy.Y, >, 21.0);
+	g_assert_cmpfloat (Yxy.x, <, 0.35);
+	g_assert_cmpfloat (Yxy.x, >, 0.25);
+	g_assert_cmpfloat (Yxy.y, <, 0.35);
+	g_assert_cmpfloat (Yxy.y, >, 0.25);
+
+	/* matrix */
+	mat.m00 = 1.00f;
+	gcm_mat33_clear (&mat);
+	g_assert_cmpfloat (mat.m00, <, 0.001f);
+	g_assert_cmpfloat (mat.m00, >, -0.001f);
+	g_assert_cmpfloat (mat.m22, <, 0.001f);
+	g_assert_cmpfloat (mat.m22, >, -0.001f);
+
+	/* multiply two matrices */
+	gcm_mat33_clear (&matsrc);
+	matsrc.m01 = matsrc.m10 = 2.0f;
+	gcm_mat33_matrix_multiply (&matsrc, &matsrc, &mat);
+	g_assert_cmpfloat (mat.m00, <, 4.1f);
+	g_assert_cmpfloat (mat.m00, >, 3.9f);
+	g_assert_cmpfloat (mat.m11, <, 4.1f);
+	g_assert_cmpfloat (mat.m11, >, 3.9f);
+	g_assert_cmpfloat (mat.m22, <, 0.001f);
+	g_assert_cmpfloat (mat.m22, >, -0.001f);
+}
+
+int
+main (int argc, char **argv)
+{
+	g_type_init ();
+
+	g_test_init (&argc, &argv, NULL);
+
+	/* tests go here */
+	g_test_add_func ("/libcolor-glib/common", gcm_test_common_func);
+
+	return g_test_run ();
+}
+
diff --git a/libcolor-glib/gcm-version.h.in b/libcolor-glib/gcm-version.h.in
new file mode 100644
index 0000000..a61a7fd
--- /dev/null
+++ b/libcolor-glib/gcm-version.h.in
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#if !defined (__GCM_H_INSIDE__) && !defined (GCM_COMPILATION)
+#error "Only <gcm.h> can be included directly."
+#endif
+
+#ifndef __GCM_VERSION_H
+#define __GCM_VERSION_H
+
+/* compile time version
+ */
+#define GCM_MAJOR_VERSION				(@GCM_MAJOR_VERSION@)
+#define GCM_MINOR_VERSION				(@GCM_MINOR_VERSION@)
+#define GCM_MICRO_VERSION				(@GCM_MICRO_VERSION@)
+
+/* check whether a gcm version equal to or greater than
+ * major.minor.micro.
+ */
+#define GCM_CHECK_VERSION(major,minor,micro)    \
+    (GCM_MAJOR_VERSION > (major) || \
+     (GCM_MAJOR_VERSION == (major) && GCM_MINOR_VERSION > (minor)) || \
+     (GCM_MAJOR_VERSION == (major) && GCM_MINOR_VERSION == (minor) && \
+      GCM_MICRO_VERSION >= (micro)))
+
+#endif /* __GCM_VERSION_H */
diff --git a/libcolor-glib/libcolor-glib.h b/libcolor-glib/libcolor-glib.h
new file mode 100644
index 0000000..c26a71b
--- /dev/null
+++ b/libcolor-glib/libcolor-glib.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __LIBCOLOR_GLIB_H__
+#define __LIBCOLOR_GLIB_H__
+
+#ifndef I_KNOW_THE_GCM_GLIB_API_IS_SUBJECT_TO_CHANGE
+#error You have to define I_KNOW_THE_GCM_GLIB_API_IS_SUBJECT_TO_CHANGE
+#endif
+
+#define __GCM_H_INSIDE__
+
+#include <gcm-common.h>
+
+#undef __GCM_H_INSIDE__
+
+#endif /* __LIBCOLOR_GLIB_H__ */
+
diff --git a/libcolor-glib/libcolor-glib.pc.in b/libcolor-glib/libcolor-glib.pc.in
new file mode 100644
index 0000000..0fa719b
--- /dev/null
+++ b/libcolor-glib/libcolor-glib.pc.in
@@ -0,0 +1,12 @@
+prefix= prefix@
+exec_prefix= exec_prefix@
+libdir= libdir@
+includedir= includedir@
+
+Name: libcolor-glib
+Description: libcolor-glib is a userspace color library.
+Version: @VERSION@
+Requires.private: gthread-2.0
+Requires: glib-2.0, gobject-2.0, libusb-1.0
+Libs: -L${libdir} -llibcolor-glib
+Cflags: -I${includedir}/libcolor-glib



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]