2 * Copyright © 2013 Richard Hughes
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include "compositor.h"
38 #include "cms-helper.h"
42 weston_cms_gamma_clear(struct weston_output *o)
50 red = calloc(o->gamma_size, sizeof(uint16_t));
51 for (i = 0; i < o->gamma_size; i++)
52 red[i] = (uint32_t) 0xffff * (uint32_t) i / (uint32_t) (o->gamma_size - 1);
53 o->set_gamma(o, o->gamma_size, red, red, red);
59 weston_cms_set_color_profile(struct weston_output *o,
60 struct weston_color_profile *p)
64 const cmsToneCurve **vcgt;
68 uint16_t *green = NULL;
69 uint16_t *blue = NULL;
74 weston_cms_gamma_clear(o);
78 weston_log("Using ICC profile %s\n", p->filename);
79 vcgt = cmsReadTag (p->lcms_handle, cmsSigVcgtTag);
80 if (vcgt == NULL || vcgt[0] == NULL) {
81 weston_cms_gamma_clear(o);
86 red = calloc(size, sizeof(uint16_t));
87 green = calloc(size, sizeof(uint16_t));
88 blue = calloc(size, sizeof(uint16_t));
89 for (i = 0; i < size; i++) {
90 in = (cmsFloat32Number) i / (cmsFloat32Number) (size - 1);
91 red[i] = cmsEvalToneCurveFloat(vcgt[0], in) * (double) 0xffff;
92 green[i] = cmsEvalToneCurveFloat(vcgt[1], in) * (double) 0xffff;
93 blue[i] = cmsEvalToneCurveFloat(vcgt[2], in) * (double) 0xffff;
95 o->set_gamma(o, size, red, green, blue);
103 weston_cms_destroy_profile(struct weston_color_profile *p)
108 cmsCloseProfile(p->lcms_handle);
114 struct weston_color_profile *
115 weston_cms_create_profile(const char *filename,
118 struct weston_color_profile *p;
119 p = zalloc(sizeof(struct weston_color_profile));
120 p->filename = strdup(filename);
121 p->lcms_handle = lcms_profile;
125 struct weston_color_profile *
126 weston_cms_load_profile(const char *filename)
128 struct weston_color_profile *p = NULL;
130 cmsHPROFILE lcms_profile;
131 lcms_profile = cmsOpenProfileFromFile(filename, "r");
133 p = weston_cms_create_profile(filename, lcms_profile);