aboutsummaryrefslogblamecommitdiffstats
path: root/libgamma-method.hh
blob: 4f9339d68876173de1a2324699071f711a403637 (plain) (tree)
1
2
3
4
5
6
7
8
9
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
                                                         


                          
                  
                 

                             
                            

 





                                                                 
 




























































































































































































































































































































































































































































                                                                                         

 
               

                                          

                                                                   
      












































































































































































































































































































































































































































































































                                                                                                            
               
                           
        

 
      
/* See LICENSE file for copyright and license details. */
#ifndef LIBGAMMA_METHOD_HH
#define LIBGAMMA_METHOD_HH

#include <cstdlib>
#include <string>

#include "libgamma-native.hh"
#include "libgamma-error.hh"


namespace libgamma
{
	/**
	 * Cathode ray tube controller information data structure
	 */
	class CRTCInformation;

	/**
	 * Capabilities of adjustment methods
	 */
	class MethodCapabilities;

	/**
	 * Site state
	 * 
	 * On operating systems that integrate a graphical environment
	 * there is usually just one site. However, one systems with
	 * pluggable graphics, like Unix-like systems such as GNU/Linux
	 * and the BSD:s, there can usually be any (feasible) number of
	 * sites. In X.org parlance they are called displays.
	 */
	class Site;

	/**
	 * Partition state
	 * 
	 * Probably the majority of display server only one partition
	 * per site. However, X.org can, and traditional used to have
	 * on multi-headed environments, multiple partitions per site.
	 * In X.org partitions are called 'screens'. It is not to be
	 * confused with monitor. A screen is a collection of monitors,
	 * and the mapping from monitors to screens is a surjection.
	 * On hardware-level adjustment methods, such as Direct
	 * Rendering Manager, a partition is a graphics card.
	 */
	class Partition;

	/**
	 * Cathode ray tube controller state
	 * 
	 * The CRTC controls the gamma ramps for the
	 * monitor that is plugged in to the connector
	 * that the CRTC belongs to
	 */
	class CRTC;


	/**
	 * Capabilities of adjustment methods
	 */
	class MethodCapabilities
	{
	public:
		/**
		 * Constructor
		 */
		MethodCapabilities();

		/**
		 * Constructor
		 * 
		 * @param  caps  The information in the native structure
		 */
		MethodCapabilities(libgamma_method_capabilities_t *caps);

		/**
		 * Copy constructor
		 * 
		 * @param  other  The information to copy
		 */
		MethodCapabilities(const MethodCapabilities &other);

		/**
		 * Destructor
		 */
		~MethodCapabilities();

		/**
		 * Copy operator
		 * 
		 * @param  other  The information to copy
		 */
		MethodCapabilities &operator =(const MethodCapabilities &other);


		/**
		 * OR of the CRTC information fields in `libgamma_crtc_information_t`
		 * that may (but can fail) be read successfully
		 */
		int32_t crtc_information;

		/**
		 * Whether the default site is known, if true the site is integrated
		 * to the system or can be determined using environment variables
		 */
		bool default_site_known;

		/**
		 * Whether the adjustment method supports multiple sites rather
		 * than just the default site
		 */
		bool multiple_sites;

		/**
		 * Whether the adjustment method supports multiple partitions
		 * per site
		 */
		bool multiple_partitions;

		/**
		 * Whether the adjustment method supports multiple CRTC:s
		 * per partition per site
		 */
		bool multiple_crtcs;

		/**
		 * Whether the partition to graphics card is a bijection.
		 */
		bool partitions_are_graphics_cards;

		/**
		 * Whether the adjustment method supports `libgamma_site_restore`
		 */
		bool site_restore;

		/**
		 * Whether the adjustment method supports `libgamma_partition_restore`
		 */
		bool partition_restore;

		/**
		 * Whether the adjustment method supports `libgamma_crtc_restore`
		 */
		bool crtc_restore;

		/**
		 * Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
		 * fields in `libgamma_crtc_information_t` will always have the same
		 * values as each other for the adjustment method
		 */
		bool identical_gamma_sizes;

		/**
		 * Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
		 * fields in `libgamma_crtc_information_t` will always be filled with the
		 * same value for the adjustment method
		 */
		bool fixed_gamma_size;

		/**
		 * Whether the `gamma_depth` field in `libgamma_crtc_information_t`
		 * will always be filled with the same value for the adjustment method
		 */
		bool fixed_gamma_depth;

		/**
		 * Whether the adjustment method will actually perform adjustments
		 */
		bool real;

		/**
		 * Whether the adjustment method is implement using a translation layer
		 */
		bool fake;
	};


	/**
	 * Types for connectors
	 */
	typedef libgamma_connector_type_t ConnectorType;

	/**
	 * Orders for subpixels; currently the possible values are
	 * very biased to LCD, Plasma and monochrome monitors
	 */
	typedef libgamma_subpixel_order_t SubpixelOrder;


	/**
	 * Cathode ray tube controller information data structure
	 */
	class CRTCInformation
	{
	public:
		/**
		 * Constructor
		 */
		CRTCInformation();

		/**
		 * Constructor
		 * 
		 * @param  info  The information in the native structure
		 */
		CRTCInformation(libgamma_crtc_information_t *info);

		/**
		 * Copy constructor
		 * 
		 * @param  other  The information to copy
		 */
		CRTCInformation(const CRTCInformation &other);

		/**
		 * Destructor
		 */
		~CRTCInformation();

		/**
		 * Copy operator
		 * 
		 * @param  other  The information to copy
		 */
		CRTCInformation &operator =(const CRTCInformation &other);


		/**
		 * The Extended Display Identification Data associated with
		 * the attached monitor. This is raw byte array that is usually
		 * 128 bytes long. It is not NUL-terminate, rather its length
		 * is stored in `edid_length`.
		 */
		unsigned char *edid;

		/**
		 * The length of `edid`
		 */
		size_t edid_length;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int edid_error;

		/**
		 * The phyical width, in millimetres, of the viewport of the
		 * attached monitor, as reported by the adjustment method. This
		 * value may be incorrect, which is a known issue with the X
		 * server where it is the result of the X server attempting
		 * the estimate the size on its own.
		 * Zero means that its is not applicable, which is the case
		 * for projectors.
		 */
		size_t width_mm;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int width_mm_error;

		/**
		 * The phyical height, in millimetres, of the viewport of the
		 * attached monitor, as reported by the adjustment method. This
		 * value may be incorrect, which is a known issue with the X
		 * server where it is the result of the X server attempting
		 * the estimate the size on its own.
		 * Zero means that its is not applicable, which is the case
		 * for projectors.
		 */
		size_t height_mm;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int height_mm_error;

		/**
		 * The phyical width, in millimetres, of the viewport of the
		 * attached monitor, as reported by it the monitor's Extended
		 * Display Information Data. This value can only contain whole
		 * centimetres, which means that the result is always zero
		 * modulus ten. However, this could change with revisions of
		 * the EDID structure.
		 * Zero means that its is not applicable, which is the case
		 * for projectors.
		 */
		size_t width_mm_edid;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int width_mm_edid_error;

		/**
		 * The phyical height, in millimetres, of the viewport of the
		 * attached monitor, as reported by it the monitor's Extended
		 * Display Information Data. This value can only contain whole
		 * centimetres, which means that the result is always zero
		 * modulus ten. However, this could change with revisions of
		 * the EDID structure.
		 * Zero means that its is not applicable, which is the case
		 * for projectors.
		 */
		size_t height_mm_edid;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int height_mm_edid_error;

		/**
		 * The size of the encoding axis of the red gamma ramp
		 */
		size_t red_gamma_size;

		/**
		 * The size of the encoding axis of the green gamma ramp
		 */
		size_t green_gamma_size;

		/**
		 * The size of the encoding axis of the blue gamma ramp
		 */
		size_t blue_gamma_size;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int gamma_size_error;

		/**
		 * The bit-depth of the value axes of gamma ramps,
		 * -1 for single precision floating point, and -2 for
		 * double precision floating point
		 */
		signed gamma_depth;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int gamma_depth_error;

		/**
		 * Non-zero gamma ramp adjustments are supported
		 */
		int gamma_support;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int gamma_support_error;

		/**
		 * The layout of the subpixels.
		 * You cannot count on this value — especially for CRT:s —
		 * but it is provided anyway as a means of distinguishing monitors.
		 */
		SubpixelOrder subpixel_order;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int subpixel_order_error;

		/**
		 * Whether there is a monitors connected to the CRTC
		 */
		int active;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int active_error;

		/**
		 * The name of the connector as designated by the display
		 * server or as give by this library in case the display
		 * server lacks this feature
		 */
		std::string *connector_name;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int connector_name_error;

		/**
		 * The type of the connector that is associated with the CRTC
		 */
		ConnectorType connector_type;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library
		 */
		int connector_type_error;

		/**
		 * The gamma characteristics of the monitor as reported
		 * in its Extended Display Information Data. The value
		 * holds the value for the red channel. If you do not have
		 * and more accurate measurement of the gamma for the
		 * monitor this could be used to give a rought gamma
		 * correction; simply divide the value with 2.2 and use
		 * the result for the red channel in the gamma correction.
		 */
		float gamma_red;

		/**
		 * The gamma characteristics of the monitor as reported
		 * in its Extended Display Information Data. The value
		 * holds the value for the green channel. If you do not have
		 * and more accurate measurement of the gamma for the
		 * monitor this could be used to give a rought gamma
		 * correction; simply divide the value with 2.2 and use
		 * the result for the green channel in the gamma correction.
		 */
		float gamma_green;

		/**
		 * The gamma characteristics of the monitor as reported
		 * in its Extended Display Information Data. The value
		 * holds the value for the blue channel. If you do not have
		 * and more accurate measurement of the gamma for the
		 * monitor this could be used to give a rought gamma
		 * correction; simply divide the value with 2.2 and use
		 * the result for the blue channel in the gamma correction.
		 */
		float gamma_blue;

		/**
		 * Zero on success, positive it holds the value `errno` had
		 * when the reading failed, otherwise (negative) the value
		 * of an error identifier provided by this library.
		 */
		int gamma_error;

	};


#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Weffc++"
	/* Lets ignore that we do not override the copy constructor
	 * and the copy operator */
#endif

	/**
	 * One single Gamma ramp
	 */
	template <typename T>
	class Ramp
	{
	public:
		/**
		 * Constructor
		 * 
		 * @param  native_ramp  The ramp
		 * @param  ramp_size    The size of the ramp
		 */
		Ramp(T *native_ramp, size_t ramp_size)
		{
			this->ramp = native_ramp;
			this->size = ramp_size;
		}

		/**
		 * Destructor
		 */
		~Ramp()
		{
			/* do nothing */
		}

		/**
		 * Subscript operator
		 * 
		 * @param   index  The index of the stop to set or get
		 * @return         A reference to the stop's value
		 */
		T &
		operator [](size_t index)
		{
			return this->ramp[index];
		}

		/**
		 * Subscript operator
		 * 
		 * @param   index  The index of the stop to get
		 * @return         The value of the stop
		 */
		const T &
		operator [](size_t index) const
		{
			return this->ramp[index];
		}

		/**
		 * The size of the ramp
		 */
		size_t size;

		/**
		 * The ramp (internal data)
		 */
		T *ramp;
	};


	/**
	 * Gamma ramp structure
	 */
	template <typename T>
	class GammaRamps
	{
	public:
		/**
		 * Constructor
		 */
		GammaRamps() :
			red(Ramp<T>(nullptr, 0)),
			green(Ramp<T>(nullptr, 0)),
			blue(Ramp<T>(nullptr, 0)),
			depth(0)
		{
			/* do nothing */
		}
    
		/**
		 * Constructor
		 * 
		 * @param  red_ramp     The red gamma ramp
		 * @param  green_ramp   The green gamma ramp
		 * @param  blue_ramp    The blue gamma ramp
		 * @param  red_size     The size of the gamma ramp for the red channel
		 * @param  green_size   The size of the gamma ramp for the green channel
		 * @param  blue_size    The size of the gamma ramp for the blue channel
		 * @param  gamma_depth  The bit-depth of the gamma ramps, -1 for single precision
		 *                      floating point, and -2 for double precision floating point
		 */
		GammaRamps(T *red_ramp, T *green_ramp, T *blue_ramp, size_t red_size,
		           size_t green_size, size_t blue_size, signed gamma_depth) :
			red(Ramp<T>(red_ramp, red_size)),
			green(Ramp<T>(green_ramp, green_size)),
			blue(Ramp<T>(blue_ramp, blue_size)),
			depth(gamma_depth)
		{
			/* do nothing */
		}

		/**
		 * Destructor
		 */
		~GammaRamps()
		{
			free(this->red.ramp);
		}


		/**
		 * The red gamma ramp
		 */
		Ramp<T> red;

		/**
		 * The green gamma ramp
		 */
		Ramp<T> green;

		/**
		 * The blue gamma ramp
		 */
		Ramp<T> blue;

		/**
		 * The bit-depth of the gamma ramps, -1 for single precision
		 * floating point, and -2 for double precision floating point
		 */
		signed depth;    
	};


	/**
	 * Site state
	 * 
	 * On operating systems that integrate a graphical environment
	 * there is usually just one site. However, one systems with
	 * pluggable graphics, like Unix-like systems such as GNU/Linux
	 * and the BSD:s, there can usually be any (feasible) number of
	 * sites. In X.org parlance they are called displays.
	 */
	class Site
	{
	public:
		/**
		 * Constructor
		 */
		Site();

		/**
		 * Constructor
		 * 
		 * @param  method  The adjustment method of the site
		 * @param  site    The site identifier, will be moved into
		 *                 the structure, must be `delete`:able
		 */
		Site(int method, std::string *site = nullptr);

		/**
		 * Destructor
		 */
		~Site();

		/**
		 * Restore the gamma ramps all CRTC:s with a site to
		 * the system settings
		 */
		void restore();

		/**
		 * This field specifies, for the methods if this library,
		 * which adjustment method (display server and protocol)
		 * is used to adjust the gamma ramps
		 */
		int method;

		/**
		 * The site identifier. It can either be `nullptr` or a string.
		 * `nullptr` indicates the default site. On systems like the
		 * Unix-like systems, where the graphics are pluggable, this
		 * is usually resolved by an environment variable, such as
		 * "DISPLAY" for X.org.
		 */
		std::string *site;

		/**
		 * The number of partitions that is available on this site.
		 * Probably the majority of display server only one partition
		 * per site. However, X.org can, and traditional used to have
		 * on multi-headed environments, multiple partitions per site.
		 * In X.org partitions are called 'screens'. It is not to be
		 * confused with monitor. A screen is a collection of monitors,
		 * and the mapping from monitors to screens is a surjection.
		 * On hardware-level adjustment methods, such as Direct
		 * Rendering Manager, a partition is a graphics card.
		 */
		size_t partitions_available;

		/**
		 * The state in the native structure
		 */
		libgamma_site_state_t *native;
	};


	/**
	 * Partition state
	 * 
	 * Probably the majority of display server only one partition
	 * per site. However, X.org can, and traditional used to have
	 * on multi-headed environments, multiple partitions per site.
	 * In X.org partitions are called 'screens'. It is not to be
	 * confused with monitor. A screen is a collection of monitors,
	 * and the mapping from monitors to screens is a surjection.
	 * On hardware-level adjustment methods, such as Direct
	 * Rendering Manager, a partition is a graphics card.
	 */
	class Partition
	{
	public:
		/**
		 * Constructor
		 */
		Partition();

		/**
		 * Constructor
		 * 
		 * @param  site       The site of the partition
		 * @param  partition  The index of the partition
		 */
		Partition(Site *site, size_t partition);

		/**
		 * Destructor
		 */
		~Partition();

		/**
		 * Restore the gamma ramps all CRTC:s with a partition
		 * to the system settings
		 */
		void restore();

		/**
		 * The site this partition belongs to
		 */
		Site *site;

		/**
		 * The index of the partition
		 */
		size_t partition;

		/**
		 * The number of CRTC:s that are available under this
		 * partition. Note that the CRTC:s are not necessarily
		 * online.
		 */
		size_t crtcs_available;

		/**
		 * The state in the native structure
		 */
		libgamma_partition_state_t *native;
	};


	/**
	 * Cathode ray tube controller state
	 * 
	 * The CRTC controls the gamma ramps for the
	 * monitor that is plugged in to the connector
	 * that the CRTC belongs to
	 */
	class CRTC
	{
	public:
		/**
		 * Constructor
		 */
		CRTC();

		/**
		 * Constructor
		 * 
		 * @param  partition  The partition of the CRTC
		 * @param  crtc       The index of the CRTC
		 */
		CRTC(Partition *partition, size_t crtc);

		/**
		 * Destructor
		 */
		~CRTC();

		/**
		 * Restore the gamma ramps for a CRTC to the system
		 * settings for that CRTC
		 */
		void restore();

		/**
		 * Read information about a CRTC
		 * 
		 * @param   output  Instance of a data structure to fill with the information about the CRTC
		 * @param   fields  OR:ed identifiers for the information about the CRTC that should be read
		 * @return          Whether an error has occurred and is stored in a `*_error` field
		 */
		bool information(CRTCInformation *output, int32_t fields);

#define LIBGAMMAMM_GET_GAMMA__(AFFIX)\
		libgamma_gamma_ramps##AFFIX##_t ramps_;\
		int r;\
		ramps_.red = ramps->red.ramp;\
		ramps_.green = ramps->green.ramp;\
		ramps_.blue = ramps->blue.ramp;\
		ramps_.red_size = ramps->red.size;\
		ramps_.green_size = ramps->green.size;\
		ramps_.blue_size = ramps->blue.size;\
		r = libgamma_crtc_get_gamma_ramps##AFFIX(this->native, &ramps_);\
		if (r)\
			throw create_error(r)

		/**
		 * Get the current gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		get_gamma(GammaRamps<uint8_t> *ramps)
		{
			LIBGAMMAMM_GET_GAMMA__(8);
		}

		/**
		 * Get the current gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		get_gamma(GammaRamps<uint16_t> *ramps)
		{
			LIBGAMMAMM_GET_GAMMA__(16);
		}

		/**
		 * Get the current gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		get_gamma(GammaRamps<uint32_t> *ramps)
		{
			LIBGAMMAMM_GET_GAMMA__(32);
		}

		/**
		 * Get the current gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		get_gamma(GammaRamps<uint64_t> *ramps)
		{
			LIBGAMMAMM_GET_GAMMA__(64);
		}

		/**
		 * Get the current gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void get_gamma(GammaRamps<float> *ramps)
		{
			LIBGAMMAMM_GET_GAMMA__(f);
		}

		/**
		 * Get the current gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void get_gamma(GammaRamps<double> *ramps)
		{
			LIBGAMMAMM_GET_GAMMA__(d);
		}

#undef LIBGAMMAMM_GET_GAMMA__

#define LIBGAMMAMM_SET_GAMMA__(AFFIX)\
		libgamma_gamma_ramps##AFFIX##_t ramps_;\
		int r;\
		ramps_.red = ramps->red.ramp;\
		ramps_.green = ramps->green.ramp;\
		ramps_.blue = ramps->blue.ramp;\
		ramps_.red_size = ramps->red.size;\
		ramps_.green_size = ramps->green.size;\
		ramps_.blue_size = ramps->blue.size;\
		r = libgamma_crtc_set_gamma_ramps##AFFIX(this->native, ramps_);\
		if (r)\
			throw create_error(r)

		/**
		 * Set gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		set_gamma(GammaRamps<uint8_t> *ramps)
		{
			LIBGAMMAMM_SET_GAMMA__(8);
		}

		/**
		 * Set gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		set_gamma(GammaRamps<uint16_t> *ramps)
		{
			LIBGAMMAMM_SET_GAMMA__(16);
		}

		/**
		 * Set gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		set_gamma(GammaRamps<uint32_t> *ramps)
		{
			LIBGAMMAMM_SET_GAMMA__(32);
		}
    
		/**
		 * Set gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		set_gamma(GammaRamps<uint64_t> *ramps)
		{
			LIBGAMMAMM_SET_GAMMA__(64);
		}

		/**
		 * Set gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		set_gamma(GammaRamps<float> *ramps)
		{
			LIBGAMMAMM_SET_GAMMA__(f);
		}

		/**
		 * Set gamma ramps for the CRTC
		 * 
		 * @param  ramps  The gamma ramps to fill with the current values
		 */
		void
		set_gamma(GammaRamps<double> *ramps)
		{
			LIBGAMMAMM_SET_GAMMA__(d);
		}

#undef LIBGAMMAMM_SET_GAMMA__


		/**
		 * The partition this CRTC belongs to
		 */
		Partition *partition;

		/**
		 * The index of the CRTC within its partition
		 */
		size_t crtc;

		/**
		 * The state in the native structure
		 */
		libgamma_crtc_state_t *native;
	};

#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif  
}

#endif