diff options
author | Mattias Andrée <maandree@kth.se> | 2019-10-06 09:36:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-10-06 09:36:23 +0200 |
commit | 1be48c64b4e5df9e9b1ad69b3bb30b867b0abf9e (patch) | |
tree | 697f6c2fb5f3f91ab64e6ed32c45e483bf31e442 /parse_10deg.c | |
parent | Add golden hour and blue hour (diff) | |
download | libred-1be48c64b4e5df9e9b1ad69b3bb30b867b0abf9e.tar.gz libred-1be48c64b4e5df9e9b1ad69b3bb30b867b0abf9e.tar.bz2 libred-1be48c64b4e5df9e9b1ad69b3bb30b867b0abf9e.tar.xz |
Clean up
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'parse_10deg.c')
-rw-r--r-- | parse_10deg.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/parse_10deg.c b/parse_10deg.c new file mode 100644 index 0000000..4cdfd61 --- /dev/null +++ b/parse_10deg.c @@ -0,0 +1,55 @@ +/* See LICENSE file for copyright and license details. */ +#include "libred.h" +#include "macros.h" +#include <stdio.h> +#include <math.h> +#include <sys/stat.h> + + + +/** + * The number of measured temperatures. + */ +#define TEMPERATURES ((LIBRED_HIGHEST_TEMPERATURE - LIBRED_LOWEST_TEMPERATURE) / LIBRED_DELTA_TEMPERATURE + 1) + + + +#define LIBRED_COMPILING_PARSER +#include "blackbody.c" + + + +/** + * Create the lookup table of temperatures. + * + * Standard input should be the file '10deg', + * standard output should be the table file + * and must be a regular file. + * + * @param argc Should be 1. + * @param argv Should only contain the name of the process. + * @return 0 on success, 1 on error. + */ +int +main(int argc, char *argv[]) +{ +#define x (xyrgb[0]) +#define y (xyrgb[1]) +#define r (xyrgb[2]) +#define g (xyrgb[3]) +#define b (xyrgb[4]) + + double xyrgb[5]; + struct stat attr; + long int temp = LIBRED_LOWEST_TEMPERATURE; + + for (; fscanf(stdin, "%lf %lf\n", &x, &y) == 2; temp += LIBRED_DELTA_TEMPERATURE) { + (temp == 6500) ? (r = g = b = 1.0) : ciexyy_to_srgb(x, y, 1.0, &r, &g, &b); + xwrite(STDOUT_FILENO, xyrgb, sizeof(xyrgb)); + } + xwrite(STDOUT_FILENO, xyrgb, sizeof(xyrgb)); /* sugar */ + t (fstat(STDOUT_FILENO, &attr)); + return ((size_t)(attr.st_size) != (TEMPERATURES + 1) * 5 * sizeof(double)); +fail: + return perror(argc ? *argv : "parse_10deg"), 1; +} |