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
36 #include "compositor.h"
37 #include "cms-helper.h"
41 weston_cms_gamma_clear(struct weston_output *o)
49 red = calloc(o->gamma_size, sizeof(uint16_t));
50 for (i = 0; i < o->gamma_size; i++)
51 red[i] = (uint32_t) 0xffff * (uint32_t) i / (uint32_t) (o->gamma_size - 1);
52 o->set_gamma(o, o->gamma_size, red, red, red);
58 weston_cms_set_color_profile(struct weston_output *o,
59 struct weston_color_profile *p)
63 const cmsToneCurve **vcgt;
67 uint16_t *green = NULL;
68 uint16_t *blue = NULL;
73 weston_cms_gamma_clear(o);
77 weston_log("Using ICC profile %s\n", p->filename);
78 vcgt = cmsReadTag (p->lcms_handle, cmsSigVcgtTag);
79 if (vcgt == NULL || vcgt[0] == NULL) {
80 weston_cms_gamma_clear(o);
85 red = calloc(size, sizeof(uint16_t));
86 green = calloc(size, sizeof(uint16_t));
87 blue = calloc(size, sizeof(uint16_t));
88 for (i = 0; i < size; i++) {
89 in = (cmsFloat32Number) i / (cmsFloat32Number) (size - 1);
90 red[i] = cmsEvalToneCurveFloat(vcgt[0], in) * (double) 0xffff;
91 green[i] = cmsEvalToneCurveFloat(vcgt[1], in) * (double) 0xffff;
92 blue[i] = cmsEvalToneCurveFloat(vcgt[2], in) * (double) 0xffff;
94 o->set_gamma(o, size, red, green, blue);
102 weston_cms_destroy_profile(struct weston_color_profile *p)
107 cmsCloseProfile(p->lcms_handle);
113 struct weston_color_profile *
114 weston_cms_create_profile(const char *filename,
117 struct weston_color_profile *p;
118 p = zalloc(sizeof(struct weston_color_profile));
119 p->filename = strdup(filename);
120 p->lcms_handle = lcms_profile;
124 struct weston_color_profile *
125 weston_cms_load_profile(const char *filename)
127 struct weston_color_profile *p = NULL;
129 cmsHPROFILE lcms_profile;
130 lcms_profile = cmsOpenProfileFromFile(filename, "r");
132 p = weston_cms_create_profile(filename, lcms_profile);