summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/kit/math.h35
1 files changed, 24 insertions, 11 deletions
diff --git a/source/kit/math.h b/source/kit/math.h
index 8deff05..45508b7 100644
--- a/source/kit/math.h
+++ b/source/kit/math.h
@@ -3,12 +3,18 @@
#include "types.h"
-#define _USE_MATH_DEFINES
+#ifndef _USE_MATH_DEFINES
+# define _USE_MATH_DEFINES
+#endif
#include <math.h>
#include <assert.h>
#include <string.h>
+// TODO
+// - Gamma correction.
+//
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -25,7 +31,7 @@ extern "C" {
# define KIT_VEC_TYPE f32
#endif
-#define KIT_EPSILON .0001
+#define KIT_EPSILON .00001
#define KIT_COLOR_REF_X 95.047f
#define KIT_COLOR_REF_Y 100.0f
@@ -34,23 +40,14 @@ extern "C" {
typedef KIT_VEC_TYPE vec_t;
typedef union {
- struct {
- vec_t x, y;
- };
vec_t v[2];
} vec2_t;
typedef union {
- struct {
- vec_t x, y, z;
- };
vec_t v[3];
} vec3_t;
typedef struct {
- struct {
- vec_t x, y, z, w;
- };
vec_t v[4];
} vec4_t, quat_t;
@@ -594,6 +591,10 @@ static quat_t quat_slerp(quat_t q0, quat_t q1, vec_t t) {
}
static vec3_t rgb_to_xyz(vec3_t rgb) {
+ // FIXME
+ // Remove unnecessary x100 scaling.
+ //
+
vec_t red = rgb.v[0];
vec_t green = rgb.v[1];
vec_t blue = rgb.v[2];
@@ -627,6 +628,10 @@ static vec3_t rgb_to_xyz(vec3_t rgb) {
}
static vec3_t xyz_to_rgb(vec3_t xyz) {
+ // FIXME
+ // Remove unnecessary x100 scaling.
+ //
+
vec_t x = xyz.v[0] / 100.f;
vec_t y = xyz.v[1] / 100.f;
vec_t z = xyz.v[2] / 100.f;
@@ -659,6 +664,10 @@ static vec3_t xyz_to_rgb(vec3_t xyz) {
}
static vec3_t lab_to_xyz(vec3_t lab) {
+ // FIXME
+ // Remove unnecessary x100 scaling.
+ //
+
vec_t lightness = lab.v[0];
vec_t a = lab.v[1];
vec_t b = lab.v[2];
@@ -687,6 +696,10 @@ static vec3_t lab_to_xyz(vec3_t lab) {
}
static vec3_t xyz_to_lab(vec3_t xyz) {
+ // FIXME
+ // Remove unnecessary x100 scaling.
+ //
+
vec_t x = (xyz.v[0] / KIT_COLOR_REF_X);
vec_t y = (xyz.v[1] / KIT_COLOR_REF_Y);
vec_t z = (xyz.v[2] / KIT_COLOR_REF_Z);