blind-colour-srgb.c - blind - suckless command-line video editing utility
 (HTM) git clone git://git.suckless.org/blind
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       blind-colour-srgb.c (1000B)
       ---
            1 /* See LICENSE file for copyright and license details. */
            2 #include "common.h"
            3 
            4 USAGE("[-% format] [-d depth] [-l] red green blue")
            5 
            6 int
            7 main(int argc, char *argv[])
            8 {
            9         unsigned long long int max;
           10         double red, green, blue, X, Y, Z;
           11         int depth = 8, linear = 0;
           12         const char *fmt = NULL;
           13 
           14         ARGBEGIN {
           15         case 'd':
           16                 depth = etoi_flag('d', UARGF(), 1, 64);
           17                 break;
           18         case 'l':
           19                 linear = 1;
           20                 break;
           21         case '%':
           22                 fmt = UARGF();
           23                 break;
           24         default:
           25                 usage();
           26         } ARGEND;
           27 
           28         if (argc != 3)
           29                 usage();
           30 
           31         fmt = select_print_format("%! %! %!\n", DOUBLE, fmt);
           32 
           33         max   = 1ULL << (depth - 1);
           34         max  |= max - 1;
           35         red   = etolf_arg("the red value",   argv[0]) / (double)max;
           36         green = etolf_arg("the green value", argv[1]) / (double)max;
           37         blue  = etolf_arg("the blue value",  argv[2]) / (double)max;
           38         if (!linear) {
           39                 red   = srgb_decode(red);
           40                 green = srgb_decode(green);
           41                 blue  = srgb_decode(blue);
           42         }
           43 
           44         srgb_to_ciexyz(red, green, blue, &X, &Y, &Z);
           45         printf(fmt, X, Y, Z);
           46         efshut(stdout, "<stdout>");
           47         return 0;
           48 }