summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-04-12 15:42:04 +0000
committerTavian Barnes <tavianator@gmail.com>2009-04-12 15:42:04 +0000
commit4f9f95a05a41bfbcc9965eaaf7f2d14c6af9f261 (patch)
treec5d3d649d36e6102708d0f86edb87499e1ff8c3e /libdimension
parent510c9a95fb5f3f4a40a19ce66c95344c2013085f (diff)
downloaddimension-4f9f95a05a41bfbcc9965eaaf7f2d14c6af9f261.tar.xz
Write C++ libdimension-png wrapper.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/color.c16
-rw-r--r--libdimension/dimension.h3
-rw-r--r--libdimension/dimension/color.h1
-rw-r--r--libdimension/error.c14
4 files changed, 25 insertions, 9 deletions
diff --git a/libdimension/color.c b/libdimension/color.c
index 4caf53b..e2a4df9 100644
--- a/libdimension/color.c
+++ b/libdimension/color.c
@@ -19,7 +19,7 @@
*************************************************************************/
#include "dimension.h"
-#include <math.h> /* For pow() */
+#include <math.h> /* For pow(), sqrt() */
/* sRGB white point (D50) */
const dmnsn_CIE_XYZ dmnsn_whitepoint = { .X = 0.9504060171449392,
@@ -253,3 +253,17 @@ dmnsn_color_add(dmnsn_color color1, dmnsn_color color2)
return ret;
}
+
+double
+dmnsn_color_difference(dmnsn_color color1, dmnsn_color color2)
+{
+ dmnsn_CIE_Lab Lab, Lab1, Lab2;
+ dmnsn_color ret;
+
+ Lab1 = dmnsn_Lab_from_color(color1, dmnsn_whitepoint);
+ Lab2 = dmnsn_Lab_from_color(color2, dmnsn_whitepoint);
+
+ return sqrt((Lab1.L - Lab2.L)*(Lab1.L - Lab2.L)
+ + (Lab1.a - Lab2.a)*(Lab1.a - Lab2.a)
+ + (Lab1.b - Lab2.b)*(Lab1.b - Lab2.b));
+}
diff --git a/libdimension/dimension.h b/libdimension/dimension.h
index 22fb700..df50524 100644
--- a/libdimension/dimension.h
+++ b/libdimension/dimension.h
@@ -36,7 +36,8 @@ typedef enum {
DMNSN_SEVERITY_HIGH /* Always die */
} dmnsn_severity;
-#define dmnsn_error(severity, str) dmnsn_report_error(severity, __func__, str)
+#define dmnsn_error(severity, str) \
+ dmnsn_report_error(severity, __PRETTY_FUNCTION__, str)
void dmnsn_report_error(dmnsn_severity severity,
const char *func, const char *str);
diff --git a/libdimension/dimension/color.h b/libdimension/dimension/color.h
index 5567628..0e64875 100644
--- a/libdimension/dimension/color.h
+++ b/libdimension/dimension/color.h
@@ -80,6 +80,7 @@ dmnsn_CIE_Luv dmnsn_Luv_from_color(dmnsn_color color, dmnsn_CIE_XYZ white);
dmnsn_sRGB dmnsn_sRGB_from_color(dmnsn_color color);
dmnsn_color dmnsn_color_add(dmnsn_color color1, dmnsn_color color2);
+double dmnsn_color_difference(dmnsn_color color1, dmnsn_color color2);
#ifdef __cplusplus
}
diff --git a/libdimension/error.c b/libdimension/error.c
index 9dae673..6edf577 100644
--- a/libdimension/error.c
+++ b/libdimension/error.c
@@ -30,10 +30,10 @@ void
dmnsn_report_error(dmnsn_severity severity, const char *func, const char *str)
{
if (severity >= dmnsn_get_resilience()) {
- fprintf(stderr, "Dimension ERROR: %s(): %s\n", func, str);
+ fprintf(stderr, "Dimension ERROR: %s: %s\n", func, str);
exit(EXIT_FAILURE);
} else {
- fprintf(stderr, "Dimension WARNING: %s(): %s\n", func, str);
+ fprintf(stderr, "Dimension WARNING: %s: %s\n", func, str);
}
}
@@ -42,12 +42,12 @@ dmnsn_get_resilience()
{
dmnsn_severity resilience;
if (pthread_mutex_lock(&dmnsn_resilience_mutex) != 0) {
- fprintf(stderr, "Dimension WARNING: %s(): %s\n", __func__,
+ fprintf(stderr, "Dimension WARNING: %s: %s\n", __PRETTY_FUNCTION__,
"Couldn't lock resilience mutex.");
}
resilience = dmnsn_resilience;
if (pthread_mutex_unlock(&dmnsn_resilience_mutex) != 0) {
- fprintf(stderr, "Dimension WARNING: %s(): %s\n", __func__,
+ fprintf(stderr, "Dimension WARNING: %s: %s\n", __PRETTY_FUNCTION__,
"Couldn't unlock resilience mutex.");
}
return resilience;
@@ -57,18 +57,18 @@ void
dmnsn_set_resilience(dmnsn_severity resilience)
{
if (resilience > DMNSN_SEVERITY_HIGH) {
- fprintf(stderr, "Dimension ERROR: %s(): %s\n", __func__,
+ fprintf(stderr, "Dimension ERROR: %s: %s\n", __PRETTY_FUNCTION__,
"Resilience has wrong value.");
exit(EXIT_FAILURE);
}
if (pthread_mutex_lock(&dmnsn_resilience_mutex) != 0) {
- fprintf(stderr, "Dimension WARNING: %s(): %s\n", __func__,
+ fprintf(stderr, "Dimension WARNING: %s: %s\n", __PRETTY_FUNCTION__,
"Couldn't lock resilience mutex.");
}
dmnsn_resilience = resilience;
if (pthread_mutex_unlock(&dmnsn_resilience_mutex) != 0) {
- fprintf(stderr, "Dimension WARNING: %s(): %s\n", __func__,
+ fprintf(stderr, "Dimension WARNING: %s: %s\n", __PRETTY_FUNCTION__,
"Couldn't unlock resilience mutex.");
}
}