2 * Copyright © 2013 Richard Hughes
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33 #include "compositor.h"
34 #include "cms-helper.h"
38 weston_cms_gamma_clear(struct weston_output *o)
46 red = calloc(o->gamma_size, sizeof(uint16_t));
47 for (i = 0; i < o->gamma_size; i++)
48 red[i] = (uint32_t) 0xffff * (uint32_t) i / (uint32_t) (o->gamma_size - 1);
49 o->set_gamma(o, o->gamma_size, red, red, red);
55 weston_cms_set_color_profile(struct weston_output *o,
56 struct weston_color_profile *p)
60 const cmsToneCurve **vcgt;
64 uint16_t *green = NULL;
65 uint16_t *blue = NULL;
70 weston_cms_gamma_clear(o);
74 weston_log("Using ICC profile %s\n", p->filename);
75 vcgt = cmsReadTag (p->lcms_handle, cmsSigVcgtTag);
76 if (vcgt == NULL || vcgt[0] == NULL) {
77 weston_cms_gamma_clear(o);
82 red = calloc(size, sizeof(uint16_t));
83 green = calloc(size, sizeof(uint16_t));
84 blue = calloc(size, sizeof(uint16_t));
85 for (i = 0; i < size; i++) {
86 in = (cmsFloat32Number) i / (cmsFloat32Number) (size - 1);
87 red[i] = cmsEvalToneCurveFloat(vcgt[0], in) * (double) 0xffff;
88 green[i] = cmsEvalToneCurveFloat(vcgt[1], in) * (double) 0xffff;
89 blue[i] = cmsEvalToneCurveFloat(vcgt[2], in) * (double) 0xffff;
91 o->set_gamma(o, size, red, green, blue);
99 weston_cms_destroy_profile(struct weston_color_profile *p)
104 cmsCloseProfile(p->lcms_handle);
110 struct weston_color_profile *
111 weston_cms_create_profile(const char *filename,
114 struct weston_color_profile *p;
115 p = calloc(1, sizeof(struct weston_color_profile));
116 p->filename = strdup(filename);
117 p->lcms_handle = lcms_profile;
121 struct weston_color_profile *
122 weston_cms_load_profile(const char *filename)
124 struct weston_color_profile *p = NULL;
126 cmsHPROFILE lcms_profile;
127 lcms_profile = cmsOpenProfileFromFile(filename, "r");
129 p = weston_cms_create_profile(filename, lcms_profile);