blob: 7b36b8649e631b89aa96ff7b1d406cd5703f62bb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* See LICENSE file for copyright and license details. */
#define IN_LIBGAMMA_DUMMY
#include "common.h"
/**
* Initialise an allocated CRTC state
*
* @param this The CRTC state to initialise
* @param partition The partition state for the partition that the CRTC belongs to
* @param crtc The the index of the CRTC within the site
* @return Zero on success, otherwise (negative) the value of an
* error identifier provided by this library
*/
int
libgamma_dummy_crtc_initialise(struct libgamma_crtc_state *restrict this,
struct libgamma_partition_state *restrict partition, size_t crtc)
{
struct libgamma_dummy_partition *partition_data = partition->data;
struct libgamma_dummy_crtc *data = &partition_data->crtcs[crtc];
size_t stop_size;
this->data = NULL;
if (crtc >= partition_data->crtc_count)
return LIBGAMMA_NO_SUCH_CRTC;
this->data = data;
data->state = this;
if (data->info.gamma_depth == -1)
stop_size = sizeof(float);
else if (data->info.gamma_depth == -2)
stop_size = sizeof(double);
else
stop_size = (size_t)data->info.gamma_depth / 8;
data->gamma_red = NULL;
data->gamma_green = NULL;
data->gamma_blue = NULL;
if (data->info.red_gamma_size > SIZE_MAX / stop_size ||
data->info.green_gamma_size > SIZE_MAX / stop_size ||
data->info.blue_gamma_size > SIZE_MAX / stop_size) {
errno = ENOMEM;
goto fail;
}
if (data->info.red_gamma_size) {
data->gamma_red = malloc(data->info.red_gamma_size * stop_size);
if (!data->gamma_red)
goto fail;
}
if (data->info.green_gamma_size) {
data->gamma_green = malloc(data->info.green_gamma_size * stop_size);
if (!data->gamma_green)
goto fail;
}
if (data->info.blue_gamma_size) {
data->gamma_blue = malloc(data->info.blue_gamma_size * stop_size);
if (!data->gamma_blue)
goto fail;
}
return libgamma_dummy_internal_crtc_restore_forced(data);
fail:
free(data->gamma_red);
data->gamma_red = NULL;
free(data->gamma_green);
data->gamma_green = NULL;
free(data->gamma_blue);
data->gamma_blue = NULL;
return LIBGAMMA_ERRNO_SET;
}
|