aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_dummy_internal_crtc_restore_forced.c
blob: ab4cf50107029055fd7e94fa2c66f41d6748a5d0 (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
/* See LICENSE file for copyright and license details. */
#define IN_LIBGAMMA_DUMMY
#include "common.h"


/**
 * Restore the gamma ramps for a CRTC to the system settings for that CRTC
 * and ignore the method's capabilities
 * 
 * @param   this  The CRTC data
 * @return        Zero on success, otherwise (negative) the value of an
 *                error identifier provided by this library
 */
int
libgamma_dummy_internal_crtc_restore_forced(libgamma_dummy_crtc_t *restrict data)
{
	size_t rn = data->info.  red_gamma_size;
	size_t gn = data->info.green_gamma_size;
	size_t bn = data->info. blue_gamma_size;
	size_t i;

	if (!data->gamma_red)
		return 0;

#define __reset_ramps(TYPE, MAX)\
	do {\
		TYPE *red   = data->gamma_red;\
		TYPE *green = data->gamma_green;\
		TYPE *blue  = data->gamma_blue;\
		for (i = 0; i < rn; i++) red  [i] = (TYPE)((double)(MAX) * ((double)i / (double)(rn - 1)));\
		for (i = 0; i < gn; i++) green[i] = (TYPE)((double)(MAX) * ((double)i / (double)(gn - 1)));\
		for (i = 0; i < bn; i++) blue [i] = (TYPE)((double)(MAX) * ((double)i / (double)(bn - 1)));\
	} while (0)

	if      (data->info.gamma_depth ==  8) __reset_ramps(uint8_t,  INT8_MAX);
	else if (data->info.gamma_depth == 16) __reset_ramps(uint16_t, INT16_MAX);
	else if (data->info.gamma_depth == 32) __reset_ramps(uint32_t, INT32_MAX);
	else if (data->info.gamma_depth == 64) __reset_ramps(uint64_t, INT64_MAX);
	else if (data->info.gamma_depth == -1) __reset_ramps(float,    1);
	else                                   __reset_ramps(double,   1);

#undef __reset_ramps

	return 0;
}