aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-set-saturation.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-05-07 16:11:31 +0200
committerMattias Andrée <maandree@kth.se>2017-05-07 16:11:31 +0200
commit4df594b3f48679f594e6f738981cb3baca8a42d9 (patch)
tree6d25bcd5ce62af2537687eff9cce67fa197ec65d /src/blind-set-saturation.c
parentBump version to 1.1 (diff)
downloadblind-4df594b3f48679f594e6f738981cb3baca8a42d9.tar.gz
blind-4df594b3f48679f594e6f738981cb3baca8a42d9.tar.bz2
blind-4df594b3f48679f594e6f738981cb3baca8a42d9.tar.xz
Add support for floats
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-set-saturation.c')
-rw-r--r--src/blind-set-saturation.c81
1 files changed, 43 insertions, 38 deletions
diff --git a/src/blind-set-saturation.c b/src/blind-set-saturation.c
index ce0dd40..472863f 100644
--- a/src/blind-set-saturation.c
+++ b/src/blind-set-saturation.c
@@ -9,45 +9,48 @@
USAGE("[-w] saturation-stream")
-static void
-process_xyza(struct stream *colour, struct stream *satur, size_t n)
-{
- size_t i;
- double s, *x, y, *z;
- for (i = 0; i < n; i += colour->pixel_size) {
- s = ((double *)(satur->buf + i))[1];
- s *= ((double *)(satur->buf + i))[3];
- x = ((double *)(colour->buf + i)) + 0;
- y = ((double *)(colour->buf + i))[1];
- z = ((double *)(colour->buf + i)) + 2;
- *x = ((*x / D65_XYZ_X - y) * s + y) * D65_XYZ_X;
- *z = ((*z / D65_XYZ_Z - y) * s + y) * D65_XYZ_Z;
- /*
- * Explaination:
- * Y is the luma and ((X / Xn - Y / Yn), (Z / Zn - Y / Yn))
- * is the chroma (according to CIELAB), where (Xn, Yn, Zn)
- * is the white point.
- */
- }
-}
+#define PROCESS(TYPE)\
+ do {\
+ size_t i;\
+ TYPE s, *x, y, *z;\
+ for (i = 0; i < n; i += colour->pixel_size) {\
+ s = ((TYPE *)(satur->buf + i))[1];\
+ s *= ((TYPE *)(satur->buf + i))[3];\
+ x = ((TYPE *)(colour->buf + i)) + 0;\
+ y = ((TYPE *)(colour->buf + i))[1];\
+ z = ((TYPE *)(colour->buf + i)) + 2;\
+ *x = ((*x / (TYPE)D65_XYZ_X - y) * s + y) * (TYPE)D65_XYZ_X;\
+ *z = ((*z / (TYPE)D65_XYZ_Z - y) * s + y) * (TYPE)D65_XYZ_Z;\
+ /*
+ * Explaination:
+ * Y is the luma and ((X / Xn - Y / Yn), (Z / Zn - Y / Yn))
+ * is the chroma (according to CIELAB), where (Xn, Yn, Zn)
+ * is the white point.
+ */\
+ }\
+ } while (0)
-static void
-process_xyza_w(struct stream *colour, struct stream *satur, size_t n)
-{
- size_t i;
- double s, *x, y, *z, X, Z;
- for (i = 0; i < n; i += colour->pixel_size) {
- X = ((double *)(satur->buf + i))[0];
- Z = ((double *)(satur->buf + i))[2];
- s = ((double *)(satur->buf + i))[1];
- s *= ((double *)(satur->buf + i))[3];
- x = ((double *)(colour->buf + i)) + 0;
- y = ((double *)(colour->buf + i))[1];
- z = ((double *)(colour->buf + i)) + 2;
- *x = ((*x / X - y) * s + y) * X;
- *z = ((*z / Z - y) * s + y) * Z;
- }
-}
+#define PROCESS_W(TYPE)\
+ do {\
+ size_t i;\
+ TYPE s, *x, y, *z, X, Z;\
+ for (i = 0; i < n; i += colour->pixel_size) {\
+ X = ((TYPE *)(satur->buf + i))[0];\
+ Z = ((TYPE *)(satur->buf + i))[2];\
+ s = ((TYPE *)(satur->buf + i))[1];\
+ s *= ((TYPE *)(satur->buf + i))[3];\
+ x = ((TYPE *)(colour->buf + i)) + 0;\
+ y = ((TYPE *)(colour->buf + i))[1];\
+ z = ((TYPE *)(colour->buf + i)) + 2;\
+ *x = ((*x / X - y) * s + y) * X;\
+ *z = ((*z / Z - y) * s + y) * Z;\
+ }\
+ } while (0)
+
+static void process_xyza (struct stream *colour, struct stream *satur, size_t n) {PROCESS(double);}
+static void process_xyza_w (struct stream *colour, struct stream *satur, size_t n) {PROCESS_W(double);}
+static void process_xyzaf (struct stream *colour, struct stream *satur, size_t n) {PROCESS(float);}
+static void process_xyzaf_w(struct stream *colour, struct stream *satur, size_t n) {PROCESS_W(float);}
int
main(int argc, char *argv[])
@@ -72,6 +75,8 @@ main(int argc, char *argv[])
if (!strcmp(colour.pixfmt, "xyza"))
process = whitepoint ? process_xyza_w : process_xyza;
+ else if (!strcmp(colour.pixfmt, "xyza f"))
+ process = whitepoint ? process_xyzaf_w : process_xyzaf;
else
eprintf("pixel format %s is not supported, try xyza\n", colour.pixfmt);