aboutsummaryrefslogblamecommitdiffstats
path: root/src/libgamma_native_facade.pyx
blob: de15bd6dc9ffe26e373494863277ec9e95ba15c5 (plain) (tree)
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
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
464
465
466
467
468
469
470
471
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
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                              
# -*- python -*-
'''
pylibgamma — Python 3 wrapper for libgamma
Copyright © 2014  Mattias Andrée (maandree@member.fsf.org)

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this library.  If not, see <http://www.gnu.org/licenses/>.
'''

cimport cython

from libc.stddef cimport size_t
from libc.stdlib cimport malloc, free
from libc.stdint cimport int32_t, uint8_t, uint16_t, uint32_t, uint64_t


ctypedef int libgamma_subpixel_order_t
ctypedef int libgamma_connector_type_t


cdef extern from "libgamma/libgamma-method.h":
    
    ctypedef struct libgamma_method_capabilities_t:
        # Capabilities of adjustment methods.
        
        int32_t crtc_information
        # OR of the CRTC information fields in `libgamma_crtc_information_t`
        # that may (but can fail) be read successfully.
        
        unsigned default_site_known # : 1
        # Whether the default site is known, if true the site is integrated
        # to the system or can be determined using environment variables.
        
        unsigned multiple_sites # : 1
        # Whether the adjustment method supports multiple sites rather
        # than just the default site.
        
        unsigned multiple_partitions # : 1
        # Whether the adjustment method supports multiple partitions
        # per site.
        
        unsigned multiple_crtcs # : 1
        # Whether the adjustment method supports multiple CRTC:s
        # per partition per site.
        
        unsigned partitions_are_graphics_cards # : 1
        # Whether the partition to graphics card is a bijection.
        
        unsigned site_restore # : 1
        # Whether the adjustment method supports `libgamma_site_restore`.
        
        unsigned partition_restore # : 1
        # Whether the adjustment method supports `libgamma_partition_restore`.
        
        unsigned crtc_restore # : 1
        # Whether the adjustment method supports `libgamma_crtc_restore`.
        
        unsigned identical_gamma_sizes # : 1
        # 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.
        
        unsigned fixed_gamma_size # : 1
        # 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.
        
        unsigned fixed_gamma_depth # : 1
        # Whether the `gamma_depth` field in `libgamma_crtc_information_t`
        # will always be filled with the same value for the adjustment method.
        
        unsigned real # : 1
        # Whether the adjustment method will actually perform adjustments.
        
        unsigned fake # : 1
        # Whether the adjustment method is implement using a translation layer.
    
    
    ctypedef struct libgamma_site_state_t:
        # 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.
        
        void* data
        # Adjustment method implementation specific data.
        # You as a user of this library should not touch this.
        
        int method
        # This field specifies, for the methods if this library,
        # which adjustment method (display server and protocol)
        # is used to adjust the gamma ramps.
        
        char* site
        # The site identifier. It can either be `NULL` or a string.
        # `NULL` 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.
        
        size_t partitions_available
        # 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.
    
    
    ctypedef struct libgamma_partition_state_t:
        # 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.
        
        void* data
        # Adjustment method implementation specific data.
        # You as a user of this library should not touch this.
        
        libgamma_site_state_t* site
        # The site this partition belongs to.
        
        size_t partition
        # The index of the partition.
        
        size_t crtcs_available
        # The number of CRTC:s that are available under this
        # partition. Note that the CRTC:s are not necessarily
        # online.
    
    
    ctypedef struct libgamma_crtc_state_t:
        # 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.
        
        void* data
        # Adjustment method implementation specific data.
        # You as a user of this library should not touch this.
        
        libgamma_partition_state_t* partition
        # The partition this CRTC belongs to.
        
        size_t crtc
        #* The index of the CRTC within its partition.
    
    
    ctypedef struct libgamma_crtc_information_t:
        # Cathode ray tube controller information data structure.
        
        unsigned char* edid
        # 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`.
        
        size_t edid_length
        # The length of `edid`.
        
        int edid_error
        # 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.
        
        
        size_t width_mm
        # 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.
        
        int width_mm_error
        # 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.
        
        
        size_t height_mm
        # 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.
        
        int height_mm_error
        # 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.
        
        
        size_t width_mm_edid
        # 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.
        
        int width_mm_edid_error
        # 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.
        
        
        size_t height_mm_edid
        # 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.
        
        int height_mm_edid_error
        # 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.
        
        
        size_t red_gamma_size
        # The size of the encoding axis of the red gamma ramp.
        
        size_t green_gamma_size
        # The size of the encoding axis of the green gamma ramp.
        
        size_t blue_gamma_size
        # The size of the encoding axis of the blue gamma ramp.
        
        int gamma_size_error
        # 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.
        
        
        signed gamma_depth
        # The bit-depth of the value axes of gamma ramps,
        # -1 for single precision floating point, and -2 for
        # double precision floating point.
        
        int gamma_depth_error
        # 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
        # Non-zero gamma ramp adjustments are supported.
        
        int gamma_support_error
        # 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.
        
        
        libgamma_subpixel_order_t subpixel_order
        # 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.
        
        int subpixel_order_error
        # 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
        # Whether there is a monitors connected to the CRTC.
        
        int active_error
        # 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.
        
        
        char* connector_name
        # 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.
        
        int connector_name_error
        # 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.
        
        
        libgamma_connector_type_t connector_type
        # The type of the connector that is associated with the CRTC.
        
        int connector_type_error
        # 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.
        
        
        float gamma_red
        # 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_green
        # 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_blue
        # 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.
        
        int gamma_error
        # 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.
    
    
    ctypedef struct libgamma_gamma_ramps8_t:
        # Gamma ramp structure for 8-bit gamma ramps.
        size_t red_size
        # The size of `red`.
        size_t green_size
        # The size of `green`.
        size_t blue_size
        # The size of `blue`.
        uint8_t* red
        # The gamma ramp for the red channel.
        uint8_t* green
        # The gamma ramp for the green channel.
        uint8_t* blue
        # The gamma ramp for the blue channel.
    
    ctypedef struct libgamma_gamma_ramps16_t:
        # Gamma ramp structure for 16-bit gamma ramps.
        size_t red_size
        # The size of `red`.
        size_t green_size
        # The size of `green`.
        size_t blue_size
        # The size of `blue`.
        uint16_t* red
        # The gamma ramp for the red channel.
        uint16_t* green
        # The gamma ramp for the green channel.
        uint16_t* blue
        # The gamma ramp for the blue channel.
    
    ctypedef struct libgamma_gamma_ramps32_t:
        # Gamma ramp structure for 32-bit gamma ramps.
        size_t red_size
        # The size of `red`.
        size_t green_size
        # The size of `green`.
        size_t blue_size
        # The size of `blue`.
        uint32_t* red
        # The gamma ramp for the red channel.
        uint32_t* green
        # The gamma ramp for the green channel.
        uint32_t* blue
        # The gamma ramp for the blue channel.
    
    ctypedef struct libgamma_gamma_ramps64_t:
        # Gamma ramp structure for 64-bit gamma ramps.
        size_t red_size
        # The size of `red`.
        size_t green_size
        # The size of `green`.
        size_t blue_size
        # The size of `blue`.
        uint64_t* red
        # The gamma ramp for the red channel.
        uint64_t* green
        # The gamma ramp for the green channel.
        uint64_t* blue
        # The gamma ramp for the blue channel.
    
    ctypedef struct libgamma_gamma_rampsf_t:
        # Gamma ramp structure for `float` gamma ramps.
        size_t red_size
        # The size of `red`.
        size_t green_size
        # The size of `green`.
        size_t blue_size
        # The size of `blue`.
        float* red
        # The gamma ramp for the red channel.
        float* green
        # The gamma ramp for the green channel.
        float* blue
        # The gamma ramp for the blue channel.
    
    ctypedef struct libgamma_gamma_rampsd_t:
        # Gamma ramp structure for `double` gamma ramps.
        size_t red_size
        # The size of `red`.
        size_t green_size
        # The size of `green`.
        size_t blue_size
        # The size of `blue`.
        double* red
        # The gamma ramp for the red channel.
        double* green
        # The gamma ramp for the green channel.
        double* blue
        # The gamma ramp for the blue channel.


cdef extern size_t libgamma_list_methods(int* methods, size_t buf_size, int operation)
'''
List available adjustment methods by their order of preference based on the environment.

@param  methods    Output array of methods, should be able to hold `LIBGAMMA_METHOD_COUNT` elements.
@param  buf_size   The number of elements that fits in `methods`, it should be `LIBGAMMA_METHOD_COUNT`,
                   This is used to avoid writing outside the output buffer if this library adds new
                   adjustment methods without the users of the library recompiling.
@param  operation  Allowed values:
                     0: Methods that the environment suggests will work, excluding fake.
                     1: Methods that the environment suggests will work, including fake.
                     2: All real non-fake methods.
                     3: All real methods.
                     4: All methods.
                   Other values invoke undefined behaviour.
@return            The number of element that have been stored in `methods`, or should
                   have been stored if the buffer was large enough.
'''


cdef extern int libgamma_is_method_available(int method)
'''
Check whether an adjustment method is available, non-existing (invalid) methods will be
identified as not available under the rationale that the library may be out of date.

@param   method  The adjustment method.
@return          Whether the adjustment method is available.
'''


cdef extern void libgamma_method_capabilities(libgamma_method_capabilities_t* this, int method)
'''
Return the capabilities of an adjustment method.

@param  this    The data structure to fill with the method's capabilities
@param  method  The adjustment method (display server and protocol).
'''


cdef extern char* libgamma_method_default_site(int method)
'''
Return the capabilities of an adjustment method.

@param   method  The adjustment method (display server and protocol.)
@return          The default site, `NULL` if it cannot be determined or
                 if multiple sites are not supported by the adjustment
                 method. This value should not be `free`:d.
'''


cdef extern const char* libgamma_method_default_site_variable(int method)
'''
Return the capabilities of an adjustment method.

@param   method  The adjustment method (display server and protocol.)
@return          The environ variables that is used to determine the
                 default site. `NULL` if there is none, that is, if
                 the method does not support multiple sites.
                 This value should not be `free`:d.
'''



cdef extern int libgamma_site_initialise(libgamma_site_state_t* this, int method, char* site)
'''
Initialise an allocated site state.

@param   this    The site state to initialise.
@param   method  The adjustment method (display server and protocol.)
@param   site    The site identifier, unless it is `NULL` it must a
                 `free`:able. One the state is destroyed the library
                 will attempt to free it. There you should not free
                 it yourself, and it must not be a string constant
                 or allocate on the stack. Note however that it will
                 not be `free`:d if this function fails.
@return          Zero on success, otherwise (negative) the value of an
                 error identifier provided by this library.
'''


cdef extern void libgamma_site_free(libgamma_site_state_t* this)
'''
Release all resources held by a site state
and free the site state pointer.

@param  this  The site state.
'''


cdef extern int libgamma_site_restore(libgamma_site_state_t* this)
'''
Restore the gamma ramps all CRTC:s with a site to the system settings.

@param   this  The site state.
@return        Zero on success, otherwise (negative) the value of an
               error identifier provided by this library.
'''



cdef extern int libgamma_partition_initialise(libgamma_partition_state_t* this, libgamma_site_state_t* site, size_t partition)
'''
Initialise an allocated partition state.

@param   this       The partition state to initialise.
@param   site       The site state for the site that the partition belongs to.
@param   partition  The index of the partition within the site.
@return             Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
'''


cdef extern void libgamma_partition_free(libgamma_partition_state_t* this)
'''
Release all resources held by a partition state
and free the partition state pointer.

@param  this  The partition state.
'''


cdef extern int libgamma_partition_restore(libgamma_partition_state_t* this)
'''
Restore the gamma ramps all CRTC:s with a partition to the system settings.

@param   this  The partition state.
@return        Zero on success, otherwise (negative) the value of an
               error identifier provided by this library.
'''



cdef extern int libgamma_crtc_initialise(libgamma_crtc_state_t* this, libgamma_partition_state_t* partition, size_t crtc)
'''
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 index of the CRTC within the partition.
@return             Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
'''


cdef extern void libgamma_crtc_free(libgamma_crtc_state_t* this)
'''
Release all resources held by a CRTC state
and free the CRTC state pointer.

@param  this  The CRTC state.
'''


cdef extern int libgamma_crtc_restore(libgamma_crtc_state_t* this)
'''
Restore the gamma ramps for a CRTC to the system settings for that CRTC.

@param   this  The CRTC state
@return        Zero on success, otherwise (negative) the value of an
               error identifier provided by this library.
'''



cdef extern int libgamma_get_crtc_information(libgamma_crtc_information_t* this, libgamma_crtc_state_t* crtc, int32_t fields)
'''
Read information about a CRTC.

@param   this    Instance of a data structure to fill with the information about the CRTC.
@param   crtc    The state of the CRTC whose information should be read.
@param   fields  OR:ed identifiers for the information about the CRTC that should be read.
@return          Zero on success, -1 on error. On error refer to the error reports in `this`.
'''


cdef extern void libgamma_crtc_information_destroy(libgamma_crtc_information_t* this)
'''
Release all resources in an information data structure for a CRTC.

@param  this  The CRTC information.
'''



cdef extern int libgamma_crtc_get_gamma_ramps8(libgamma_crtc_state_t* this, libgamma_gamma_ramps8_t* ramps)
'''
Get current the gamma ramps for a CRTC, 8-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to fill with the current values
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''


cdef extern int libgamma_crtc_set_gamma_ramps8(libgamma_crtc_state_t* this, libgamma_gamma_ramps8_t ramps)
'''
Set the gamma ramps for a CRTC, 8-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to apply.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''



cdef extern int libgamma_crtc_get_gamma_ramps16(libgamma_crtc_state_t* this, libgamma_gamma_ramps16_t* ramps)
'''
Get current the gamma ramps for a CRTC, 16-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to fill with the current values
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''


cdef extern int libgamma_crtc_set_gamma_ramps16(libgamma_crtc_state_t* this, libgamma_gamma_ramps16_t ramps)
'''
Set the gamma ramps for a CRTC, 16-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to apply.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''



cdef extern int libgamma_crtc_get_gamma_ramps32(libgamma_crtc_state_t* this, libgamma_gamma_ramps32_t* ramps)
'''
Get current the gamma ramps for a CRTC, 32-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to fill with the current values.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''


cdef extern int libgamma_crtc_set_gamma_ramps32(libgamma_crtc_state_t* this, libgamma_gamma_ramps32_t ramps)
'''
Set the gamma ramps for a CRTC, 32-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to apply.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''



cdef extern int libgamma_crtc_get_gamma_ramps64(libgamma_crtc_state_t* this, libgamma_gamma_ramps64_t* ramps)
'''
Get current the gamma ramps for a CRTC, 64-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to fill with the current values.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''


cdef extern int libgamma_crtc_set_gamma_ramps64(libgamma_crtc_state_t* this, libgamma_gamma_ramps64_t ramps)
'''
Set the gamma ramps for a CRTC, 64-bit gamma-depth version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to apply.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''



cdef extern int libgamma_crtc_set_gamma_rampsf(libgamma_crtc_state_t* this, libgamma_gamma_rampsf_t ramps)
'''
Set the gamma ramps for a CRTC, `float` version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to apply.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''


cdef extern int libgamma_crtc_get_gamma_rampsf(libgamma_crtc_state_t* this, libgamma_gamma_rampsf_t* ramps)
'''
Get current the gamma ramps for a CRTC, `float` version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to fill with the current values.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''



cdef extern int libgamma_crtc_get_gamma_rampsd(libgamma_crtc_state_t* this, libgamma_gamma_rampsd_t* ramps)
'''
Get current the gamma ramps for a CRTC, `double` version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to fill with the current values.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''


cdef extern int libgamma_crtc_set_gamma_rampsd(libgamma_crtc_state_t* this, libgamma_gamma_rampsd_t ramps)
'''
Set the gamma ramps for a CRTC, `double` version.

@param   this   The CRTC state.
@param   ramps  The gamma ramps to apply.
@return         Zero on success, otherwise (negative) the value of an
                error identifier provided by this library.
'''



def libgamma_native_list_methods(operation : int) -> list:
    '''
    List available adjustment methods by their order of preference based on the environment.
    
    @param  operation    Allowed values:
                           0: Methods that the environment suggests will work, excluding fake.
                           1: Methods that the environment suggests will work, including fake.
                           2: All real non-fake methods.
                           3: All real methods.
                           4: All methods.
                         Other values invoke undefined behaviour.
    @return  :list<int>  A list of available adjustment methods.
    '''
    cdef int* methods
    cdef size_t buf_size
    cdef size_t r
    buf_size = 6
    methods = <int*>malloc(buf_size * sizeof(size_t))
    if methods == NULL:
        raise MemoryError()
    r = libgamma_list_methods(methods, buf_size, operation)
    if r > buf_size:
        buf_size = r
        free(methods)
        methods = <int*>malloc(buf_size * sizeof(size_t))
        if methods == NULL:
            raise MemoryError()
        libgamma_list_methods(methods, buf_size, operation)
    rc = []
    for i in range(r):
        rc.append(methods[i])
    free(methods)
    return rc


def libgamma_native_is_method_available(method : int) -> int:
    '''
    Check whether an adjustment method is available, non-existing (invalid) methods will be
    identified as not available under the rationale that the library may be out of date.
    
    @param   method  The adjustment method.
    @return          Whether the adjustment method is available.
    '''
    return int(libgamma_is_method_available(<int>method))


def libgamma_native_method_capabilities(method : int) -> tuple:
    '''
    Return the capabilities of an adjustment method.
    
    @param   method       The adjustment method (display server and protocol).
    @return  :(int, int)  Input parameters for `MethodCapabilities.__init__`
    '''
    cdef libgamma_method_capabilities_t caps
    libgamma_method_capabilities(&caps, <int>method)
    booleans = 0
    crtc_information = int(caps.crtc_information)
    booleans |= (0 if caps.default_site_known            == 0 else 1) <<  0
    booleans |= (0 if caps.multiple_sites                == 0 else 1) <<  1
    booleans |= (0 if caps.multiple_partitions           == 0 else 1) <<  2
    booleans |= (0 if caps.multiple_crtcs                == 0 else 1) <<  3
    booleans |= (0 if caps.partitions_are_graphics_cards == 0 else 1) <<  4
    booleans |= (0 if caps.site_restore                  == 0 else 1) <<  5
    booleans |= (0 if caps.partition_restore             == 0 else 1) <<  6
    booleans |= (0 if caps.crtc_restore                  == 0 else 1) <<  7
    booleans |= (0 if caps.identical_gamma_sizes         == 0 else 1) <<  8
    booleans |= (0 if caps.fixed_gamma_size              == 0 else 1) <<  9
    booleans |= (0 if caps.fixed_gamma_depth             == 0 else 1) << 10
    booleans |= (0 if caps.real                          == 0 else 1) << 11
    booleans |= (0 if caps.fake                          == 0 else 1) << 12
    return (crtc_information, booleans)


def libgamma_native_method_default_site(method : int) -> str:
    '''
    Return the capabilities of an adjustment method.
    
    @param   method  The adjustment method (display server and protocol.)
    @return          The default site, `None` if it cannot be determined or
                     if multiple sites are not supported by the adjustment
                     method.
    '''
    cdef char* var
    cdef bytes bs
    var = libgamma_method_default_site(<int>method)
    bs = var
    return bs.decode('utf-8', 'strict')


def libgamma_native_method_default_site_variable(method : int) -> str:
    '''
    Return the capabilities of an adjustment method.
    
    @param   method  The adjustment method (display server and protocol.)
    @return          The environ variables that is used to determine the
                     default site. `None` if there is none, that is, if
                     the method does not support multiple sites.
    '''
    cdef const char* var
    cdef bytes bs
    var = libgamma_method_default_site_variable(<int>method)
    bs = var
    return bs.decode('utf-8', 'strict')



#def int libgamma_native_site_initialise(libgamma_site_state_t* this, int method, char* site)
'''
Initialise an allocated site state.

@param   this    The site state to initialise.
@param   method  The adjustment method (display server and protocol.)
@param   site    The site identifier, unless it is `NULL` it must a
                 `free`:able. One the state is destroyed the library
                 will attempt to free it. There you should not free
                 it yourself, and it must not be a string constant
                 or allocate on the stack. Note however that it will
                 not be `free`:d if this function fails.
@return          Zero on success, otherwise (negative) the value of an
                 error identifier provided by this library.
'''


def void libgamma_native_site_destroy(this : int):
    '''
    Release all resources held by a site state.
    
    @param  this  The site state.
    '''
    cdef size_t this_address
    cdef libgamma_site_state_t* this_
    this_address = <size_t>this
    this_ = <libgamma_site_state_t*><void*>this_address
    libgamma_site_free(this_)


def int libgamma_native_site_restore(this : int) -> int:
    '''
    Restore the gamma ramps all CRTC:s with a site to the system settings.
    
    @param   this  The site state.
    @return        Zero on success, otherwise (negative) the value of an
                   error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef libgamma_site_state_t* this_
    this_address = <size_t>this
    this_ = <libgamma_site_state_t*><void*>this_address
    return int(libgamma_site_restore(this_))



#def int libgamma_native_partition_initialise(libgamma_partition_state_t* this, libgamma_site_state_t* site, size_t partition)
'''
Initialise an allocated partition state.

@param   this       The partition state to initialise.
@param   site       The site state for the site that the partition belongs to.
@param   partition  The index of the partition within the site.
@return             Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
'''


def libgamma_native_partition_free(this : int):
    '''
    Release all resources held by a partition state
    and free the partition state pointer.
    
    @param  this  The partition state.
    '''
    cdef size_t this_address
    cdef libgamma_partition_state_t* this_
    this_address = <size_t>this
    this_ = <libgamma_partition_state_t*><void*>this_address
    libgamma_partition_free(this_)


def libgamma_native_partition_restore(this : int) -> int:
    '''
    Restore the gamma ramps all CRTC:s with a partition to the system settings.
    
    @param   this  The partition state.
    @return        Zero on success, otherwise (negative) the value of an
                   error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef libgamma_partition_state_t* this_
    this_address = <size_t>this
    this_ = <libgamma_partition_state_t*><void*>this_address
    return int(libgamma_partition_restore(this_))



#def int libgamma_native_crtc_initialise(libgamma_crtc_state_t* this, libgamma_partition_state_t* partition, size_t crtc)
'''
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 index of the CRTC within the partition.
@return             Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
'''


def libgamma_native_crtc_free(this : int):
    '''
    Release all resources held by a CRTC state
    and free the CRTC state pointer.
    
    @param  this  The CRTC state.
    '''
    cdef size_t this_address
    cdef libgamma_crtc_state_t* this_
    this_address = <size_t>this
    this_ = <libgamma_crtc_state_t*><void*>this_address
    libgamma_crtc_free(this_)


def libgamma_native_crtc_restore(this : int) -> int:
    '''
    Restore the gamma ramps for a CRTC to the system settings for that CRTC.
    
    @param   this  The CRTC state
    @return        Zero on success, otherwise (negative) the value of an
                   error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef libgamma_crtc_state_t* this_
    this_address = <size_t>this
    this_ = <libgamma_crtc_state_t*><void*>this_address
    return int(libgamma_crtc_restore(this_))



def libgamma_native_get_crtc_information(crtc : int, fields : int) -> tuple:
    '''
    Read information about a CRTC.
    
    @param   crtc           The state of the CRTC whose information should be read.
    @param   field          OR:ed identifiers for the information about the CRTC that should be read.
    @return  :(list, :int)  First value:   Input parametrs for `CRTCInformation.__init__`
                            Second value:  Zero on success, -1 on error. On error refer to the error reports in the return.
    '''
    cdef libgamma_crtc_information_t info
    cdef size_t crtc_address
    cdef libgamma_crtc_state_t* crtc_
    cdef bytes bs
    crtc_address = <size_t>crtc
    crtc_ = <libgamma_crtc_state_t*><void*>crtc_address
    r = int(libgamma_get_crtc_information(&info, crtc_, <int32_t>fields))
    rc = []
    connector_name = None
    if info.connector_name is not NULL:
        bs = info.connector_name
        connector_name = bs.decode('utf-8', 'strict')
    edid = None
    if info.edid is not NULL:
        bs = info.edid[:info.edid_length]
        edid = bs
    rc.append(edid)
    rc.append(int(info.edid_error))
    rc.append(int(info.width_mm))
    rc.append(int(info.width_mm_error))
    rc.append(int(info.height_mm))
    rc.append(int(info.height_mm_error))
    rc.append(int(info.width_mm_edid))
    rc.append(int(info.width_mm_edid_error))
    rc.append(int(info.height_mm_edid))
    rc.append(int(info.height_mm_edid_error))
    rc.append(int(info.red_gamma_size))
    rc.append(int(info.green_gamma_size))
    rc.append(int(info.blue_gamma_size))
    rc.append(int(info.gamma_size_error))
    rc.append(int(info.gamma_depth))
    rc.append(int(info.gamma_depth_error))
    rc.append(int(info.gamma_support))
    rc.append(int(info.gamma_support_error))
    rc.append(int(info.subpixel_order))
    rc.append(int(info.subpixel_order_error))
    rc.append(int(info.active))
    rc.append(int(info.active_error))
    rc.append(connector_name)
    rc.append(int(info.connector_name_error))
    rc.append(int(info.connector_type))
    rc.append(int(info.connector_type_error))
    rc.append(float(info.gamma_red))
    rc.append(float(info.gamma_green))
    rc.append(float(info.gamma_blue))
    rc.append(int(info.gamma_error))
    libgamma_get_crtc_destroy(&info)
    return (rc, r)



def libgamma_native_crtc_get_gamma_ramps8(this : int, ramps : int) -> int:
    '''
    Get current the gamma ramps for a CRTC, 8-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to fill with the current values.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps8_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps8_t*><void*>ramps_address
    return int(libgamma_crtc_get_gamma_ramps8(this_, ramps_))


def libgamma_native_crtc_set_gamma_ramps8(this : int, ramps : int) -> int:
    '''
    Set the gamma ramps for a CRTC, 8-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to apply.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps8_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps8_t*><void*>ramps_address
    return int(libgamma_crtc_set_gamma_ramps8(this_, ramps_[0]))



def libgamma_native_crtc_get_gamma_ramps16(this : int, ramps : int) -> int:
    '''
    Get current the gamma ramps for a CRTC, 16-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to fill with the current values.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps16_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps16_t*><void*>ramps_address
    return int(libgamma_crtc_get_gamma_ramps16(this_, ramps_))


def libgamma_native_crtc_set_gamma_ramps16(this : int, ramps : int) -> int:
    '''
    Set the gamma ramps for a CRTC, 16-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to apply.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps16_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps16_t*><void*>ramps_address
    return int(libgamma_crtc_set_gamma_ramps16(this_, ramps_[0]))



def libgamma_native_crtc_get_gamma_ramps32(this : int, ramps : int) -> int:
    '''
    Get current the gamma ramps for a CRTC, 32-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to fill with the current values.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps32_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps32_t*><void*>ramps_address
    return int(libgamma_crtc_get_gamma_ramps32(this_, ramps_))


def libgamma_native_crtc_set_gamma_ramps32(this : int, ramps : int) -> int:
    '''
    Set the gamma ramps for a CRTC, 32-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to apply.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps32_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps32_t*><void*>ramps_address
    return int(libgamma_crtc_set_gamma_ramps32(this_, ramps_[0]))



def libgamma_native_crtc_get_gamma_ramps64(this : int, ramps : int) -> int:
    '''
    Get current the gamma ramps for a CRTC, 64-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to fill with the current values.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps64_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps64_t*><void*>ramps_address
    return int(libgamma_crtc_get_gamma_ramps64(this_, ramps_))


def libgamma_native_crtc_set_gamma_ramps64(this : int, ramps : int) -> int:
    '''
    Set the gamma ramps for a CRTC, 64-bit gamma-depth version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to apply.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_ramps64_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_ramps64_t*><void*>ramps_address
    return int(libgamma_crtc_set_gamma_ramps64(this_, ramps_[0]))



def libgamma_native_crtc_get_gamma_rampsf(this : int, ramps : int) -> int:
    '''
    Get current the gamma ramps for a CRTC, `float` version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to fill with the current values.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_rampsf_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_rampsf_t*><void*>ramps_address
    return int(libgamma_crtc_get_gamma_rampsf(this_, ramps_))


def libgamma_native_crtc_set_gamma_rampsf(this : int, ramps : int) -> int:
    '''
    Set the gamma ramps for a CRTC, `float` version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to apply.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_rampsf_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_rampsf_t*><void*>ramps_address
    return int(libgamma_crtc_set_gamma_rampsf(this_, ramps_[0]))



def libgamma_native_crtc_get_gamma_rampsd(this : int, ramps : int) -> int:
    '''
    Get current the gamma ramps for a CRTC, `double` version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to fill with the current values.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_rampsd_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_rampsd_t*><void*>ramps_address
    return int(libgamma_crtc_get_gamma_rampsd(this_, ramps_))


def libgamma_native_crtc_set_gamma_rampsd(this : int, ramps : int) -> int:
    '''
    Set the gamma ramps for a CRTC, `double` version.
    
    @param   this   The CRTC state.
    @param   ramps  The gamma ramps to apply.
    @return         Zero on success, otherwise (negative) the value of an
                    error identifier provided by this library.
    '''
    cdef size_t this_address
    cdef size_t ramps_address
    cdef libgamma_crtc_state_t* this_
    cdef libgamma_gamma_rampsd_t* ramps_
    this_address = <size_t>this
    ramps_address = <size_t>ramps
    this_ = <libgamma_crtc_state_t*><void*>this_address
    ramps_ = <libgamma_gamma_rampsd_t*><void*>ramps_address
    return int(libgamma_crtc_set_gamma_rampsd(this_, ramps_[0]))