4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU General Public License.
11 #include "images/images.h"
12 #include "images/color.h"
24 Usage: color-tool input-color-space output-color-space\n\
29 static char *shortopts = "";
30 static struct option longopts[] =
35 static const struct color_space_info *
36 parse_color_space(byte *s)
38 if (!strcasecmp(s, "sRGB"))
39 return &color_srgb_info;
40 else if (!strcasecmp(s, "AdobeRGB") || !strcasecmp(s, "Adobe RGB"))
41 return &color_adobe_rgb_info;
42 else if (!strcasecmp(s, "CIERGB") || strcasecmp(s, "CIE RGB"))
43 return &color_cie_rgb_info;
45 die("Unknown color space");
49 print_matrix(double m[9])
51 for (uns j = 0; j < 3; j++)
53 for (uns i = 0; i < 3; i++)
54 printf(" %12.8f", m[i + j * 3]);
60 main(int argc, char **argv)
64 while ((opt = getopt_long(argc, argv, shortopts, longopts, NULL)) >= 0)
71 if (argc == optind + 1)
73 const struct color_space_info *a = parse_color_space(argv[optind]);
74 double a_to_xyz[9], xyz_to_a[9];
75 color_compute_color_space_to_xyz_matrix(a_to_xyz, &a->chromacity);
76 color_invert_matrix(xyz_to_a, a_to_xyz);
77 printf("linear %s -> XYZ:\n", a->name);
78 print_matrix(a_to_xyz);
79 printf("XYZ -> linear %s:\n", a->name);
80 print_matrix(xyz_to_a);
81 printf("Simple gamma: %.8f\n", a->gamma.simple_gamma);
82 printf("Detailed gamma: g=%.8f o=%.8f t=%.8f s=%.8f\n", a->gamma.detailed_gamma, a->gamma.offset, a->gamma.transition, a->gamma.slope);
84 else if (argc == optind + 2)
86 const struct color_space_info *a = parse_color_space(argv[optind++]);
87 const struct color_space_info *b = parse_color_space(argv[optind]);
89 color_compute_color_spaces_conversion_matrix(a_to_b, &a->chromacity, &b->chromacity);
90 printf("linear %s -> linear %s:\n", a->name, b->name);