diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-21 14:53:18 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-21 14:53:18 +0200 |
commit | 3be28b4e8f75190d30e311f0e69da714cac62cc5 (patch) | |
tree | 95374a0ac30802f838e0fee1d7c686b66dd26b11 /src | |
parent | Remove dist (diff) | |
download | pylibgamma-1.1.3.tar.gz pylibgamma-1.1.3.tar.bz2 pylibgamma-1.1.3.tar.xz |
Change license to ISC, change style, improve makefile1.1.3
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/include-libgamma.h | 19 | ||||
-rw-r--r-- | src/libgamma.py | 23 | ||||
-rw-r--r-- | src/libgamma_error.py | 476 | ||||
-rw-r--r-- | src/libgamma_facade.py | 147 | ||||
-rw-r--r-- | src/libgamma_method.py | 1117 | ||||
-rw-r--r-- | src/libgamma_native_error.pyx | 205 | ||||
-rw-r--r-- | src/libgamma_native_error.w32.pyx | 183 | ||||
-rw-r--r-- | src/libgamma_native_facade.pyx | 1389 | ||||
-rw-r--r-- | src/libgamma_native_method.pyx | 682 | ||||
-rwxr-xr-x | src/test.py | 124 |
10 files changed, 0 insertions, 4365 deletions
diff --git a/src/include-libgamma.h b/src/include-libgamma.h deleted file mode 100644 index eb857e1..0000000 --- a/src/include-libgamma.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * 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/>. - */ -#include <libgamma.h> - diff --git a/src/libgamma.py b/src/libgamma.py deleted file mode 100644 index 34c646c..0000000 --- a/src/libgamma.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- 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/>. -''' - -from libgamma_error import * -from libgamma_method import * -from libgamma_facade import * - diff --git a/src/libgamma_error.py b/src/libgamma_error.py deleted file mode 100644 index afefd5e..0000000 --- a/src/libgamma_error.py +++ /dev/null @@ -1,476 +0,0 @@ -# -*- 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/>. -''' - - - -class LibgammaGroup: - ''' - Class for `group` - ''' - - @property - def gid(self) -> int: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - from libgamma_native_error import libgamma_native_get_group_gid - return libgamma_native_get_group_gid() - - @gid.setter - def gid(self, value : int): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - from libgamma_native_error import libgamma_native_set_group_gid - libgamma_native_set_group_gid(value) - - - @property - def name(self) -> str: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `group.gid` - cannot be determined. - ''' - from libgamma_native_error import libgamma_native_get_group_name - return libgamma_native_get_group_name() - - @name.setter - def name(self, value : str): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `group.gid` - cannot be determined. - ''' - from libgamma_native_error import libgamma_native_set_group_name - libgamma_native_set_group_name(value) - - -group = LibgammaGroup() -''' - Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. -''' - - -def perror(name : str, error_code : int): - ''' - Prints an error to stderr in a `perror` fashion, - however this function will not translate the `libgamma` - errors into human-readable strings, it will simply - print the name of the error. If the value `error_code` - is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be - used to print the current error stored in `errno`. - If `error_code` is non-negative (an `errno` value`), that - value will be stored in `errno` and `perror` will be - used to print it. Additionally, if the `error_code` is - the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the - required group will be printed with its numerical value - and, if known, its name. - - @param name The text to add at the beginning. - @param value The error code, may be an `errno` value. - ''' - from libgamma_native_error import libgamma_native_perror - libgamma_native_perror(name, error_code) - - -def name_of_error(value : int) -> str: - ''' - Returns the name of the definition associated with a `libgamma` error code. - - @param value The error code. - @return The name of the definition associated with the error code, - `None` if the error code does not exist. - ''' - from libgamma_native_error import libgamma_native_name_of_error - return libgamma_native_name_of_error(value) - - -def value_of_error(name : str) -> int: - ''' - Return the value of a `libgamma` error definition refered to by name. - - @param name The name of the definition associated with the error code. - @return The error code, zero if the name is `None` - or does not refer to a `libgamma` error. - ''' - from libgamma_native_error import libgamma_native_value_of_error - return libgamma_native_value_of_error(name) - - - -LIBGAMMA_ERRNO_SET = -1 -''' -`errno` has be set with a standard error number -to indicate the what has gone wrong. -''' - -LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD = -2 -''' -The selected adjustment method does not exist -or has been excluded at compile-time. -''' - -LIBGAMMA_NO_SUCH_SITE = -3 -''' -The selected site does not exist. -''' - -LIBGAMMA_NO_SUCH_PARTITION = -4 -''' -The selected partition does not exist. -''' - -LIBGAMMA_NO_SUCH_CRTC = -5 -''' -The selected CRTC does not exist. -''' - -LIBGAMMA_IMPOSSIBLE_AMOUNT = -6 -''' -Counter overflowed when counting the number -of available items. -''' - -LIBGAMMA_CONNECTOR_DISABLED = -7 -''' -The selected connector is disabled, it does -not have a CRTC. -''' - -LIBGAMMA_OPEN_CRTC_FAILED = -8 -''' -The selected CRTC could not be opened, -reason unknown. -''' - -LIBGAMMA_CRTC_INFO_NOT_SUPPORTED = -9 -''' -The CRTC information field is not supported -by the adjustment method. -''' - -LIBGAMMA_GAMMA_RAMP_READ_FAILED = -10 -''' -Failed to read the current gamma ramps for -the selected CRTC, reason unknown. -''' - -LIBGAMMA_GAMMA_RAMP_WRITE_FAILED = -11 -''' -Failed to write the current gamma ramps for -the selected CRTC, reason unknown. -''' - -LIBGAMMA_GAMMA_RAMP_SIZE_CHANGED = -12 -''' -The specified ramp sizes does not match the -ramps sizes returned by the adjustment methods -in response to the query/command. -''' - -LIBGAMMA_MIXED_GAMMA_RAMP_SIZE = -13 -''' -The specified ramp sizes are not identical -which is required by the adjustment method. -(Only returned in debug mode.) -''' - -LIBGAMMA_WRONG_GAMMA_RAMP_SIZE = -14 -''' -The specified ramp sizes are not supported -by the adjustment method. -(Only returned in debug mode.) -''' - -LIBGAMMA_SINGLETON_GAMMA_RAMP = -15 -''' -The adjustment method reported that the gamma -ramps size is 1, or perhaps even zero or negative. -''' - -LIBGAMMA_LIST_CRTCS_FAILED = -16 -''' -The adjustment method failed to list -available CRTC:s, reason unknown. -''' - -LIBGAMMA_ACQUIRING_MODE_RESOURCES_FAILED = -17 -''' -Failed to acquire mode resources from the -adjustment method. -''' - -LIBGAMMA_NEGATIVE_PARTITION_COUNT = -18 -''' -The adjustment method reported that a negative -number of partitions exists in the site. -''' - -LIBGAMMA_NEGATIVE_CRTC_COUNT = -19 -''' -The adjustment method reported that a negative -number of CRTC:s exists in the partition. -''' - -LIBGAMMA_DEVICE_RESTRICTED = -20 -''' -Device cannot be access becauses of -insufficient permissions. -''' - -LIBGAMMA_DEVICE_ACCESS_FAILED = -21 -''' -Device cannot be access, reason unknown. -''' - -LIBGAMMA_DEVICE_REQUIRE_GROUP = -22 -''' -Device cannot be access, membership of the -`group.gid` (named by `group.name` (can be -`None`, if so `errno` may have been set to -tell why)) is required. -''' - -LIBGAMMA_GRAPHICS_CARD_REMOVED = -23 -''' -The graphics card appear to have been removed. -''' - -LIBGAMMA_STATE_UNKNOWN = -24 -''' -The state of the requested information is unknown. -''' - -LIBGAMMA_CONNECTOR_UNKNOWN = -25 -''' -Failed to determine which connector the -CRTC belongs to. -''' - -LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED = -26 -''' -The detected connector type is not listed -in this library and has to be updated. -''' - -LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED = -27 -''' -The detected subpixel order is not listed -in this library and has to be updated. -''' - -LIBGAMMA_EDID_LENGTH_UNSUPPORTED = -28 -''' -The length of the EDID does not match that -of any supported EDID structure revision. -''' - -LIBGAMMA_EDID_WRONG_MAGIC_NUMBER = -29 -''' -The magic number in the EDID does not match -that of any supported EDID structure revision. -''' - -LIBGAMMA_EDID_REVISION_UNSUPPORTED = -30 -''' -The EDID structure revision used by the -monitor is not supported. -''' - -LIBGAMMA_GAMMA_NOT_SPECIFIED = -31 -''' -The gamma characteristics field in the EDID -is left unspecified. -(This could be considered a non-error.) -''' - -LIBGAMMA_EDID_CHECKSUM_ERROR = -32 -''' -The checksum in the EDID is incorrect, all -request information has been provided -by you cannot count on it. -''' - -LIBGAMMA_GAMMA_NOT_SPECIFIED_AND_EDID_CHECKSUM_ERROR = -33 -''' -Both of the errors `LIBGAMMA_GAMMA_NOT_SPECIFIED` -and `LIBGAMMA_EDID_CHECKSUM_ERROR` have occurred. -''' - -LIBGAMMA_GAMMA_RAMPS_SIZE_QUERY_FAILED = -34 -''' -Failed to query the gamma ramps size from the -adjustment method, reason unknown. -''' - -LIBGAMMA_OPEN_PARTITION_FAILED = -35 -''' -The selected partition could not be opened, -reason unknown. -''' - -LIBGAMMA_OPEN_SITE_FAILED = -36 -''' -The selected site could not be opened, -reason unknown. -''' - -LIBGAMMA_PROTOCOL_VERSION_QUERY_FAILED = -37 -''' -Failed to query the adjustment method for -its protocol version, reason unknown. -''' - -LIBGAMMA_PROTOCOL_VERSION_NOT_SUPPORTED = -38 -''' -The adjustment method's version of its -protocol is not supported. -''' - -LIBGAMMA_LIST_PARTITIONS_FAILED = -39 -''' -The adjustment method failed to list -available partitions, reason unknown. -''' - -LIBGAMMA_NULL_PARTITION = -40 -''' -Partition exists by index, but the partition -at that index does not exist. -''' - -LIBGAMMA_NOT_CONNECTED = -41 -''' -There is not monitor connected to the -connector of the selected CRTC. -''' - -LIBGAMMA_REPLY_VALUE_EXTRACTION_FAILED = -42 -''' -Data extraction from a reply from the -adjustment method failed, reason unknown. -''' - -LIBGAMMA_EDID_NOT_FOUND = -43 -''' -No EDID property was found on the output. -''' - -LIBGAMMA_LIST_PROPERTIES_FAILED = -44 -''' -Failed to list properties on the output, -reason unknown. -''' - -LIBGAMMA_PROPERTY_VALUE_QUERY_FAILED = -45 -''' -Failed to query a property's value from -the output, reason unknown. -''' - -LIBGAMMA_OUTPUT_INFORMATION_QUERY_FAILED = -46 -''' -A request for information on an output -failed, reason unknown. -''' - - -LIBGAMMA_ERROR_MIN = -46 -''' -The number of the libgamma error with the -lowest number. If this is lower than the -number your program thinks it should be sould -update your program for new errors. -''' - - - -class LibgammaError(Exception): - ''' - libgamma error class. - - @variable errno The error code. - @variable strerror The name of the error. - ''' - - def __init__(self, errno : int, strerror : str): - ''' - Constructor. - - @param errno The error code. - @param strerror The name of the error. - ''' - self.errno = errno - self.strerror = strerror - - def __str__(self) -> str: - ''' - Return the name of the error. - - @return The name of the error. - ''' - return self.strerror - - - def __repr__(self) -> str: - ''' - Create a string representation of the error. - - @return A string representation of the error. - ''' - return 'LibgammaError(%i, %s)' % (self.errno, repr(self.strerror)) - - - -def create_error(error_code : int) -> Exception: - ''' - Create an exception from an error code. - - @param error_code The error code. - @return :OSError|LibgammaError The error as a throwable object. - ''' - if error_code == LIBGAMMA_ERRNO_SET: - import ctypes - error_code = ctypes.get_errno() - - if error_code >= 0: - import libgamma_native_error as c - e = OSError() - e.errno = error_code - e.strerror = c.strerror(e.errno) - else: - strerror = name_of_error(error_code) - e = LibgammaError(error_code, strerror) - - return e - diff --git a/src/libgamma_facade.py b/src/libgamma_facade.py deleted file mode 100644 index 5920a5b..0000000 --- a/src/libgamma_facade.py +++ /dev/null @@ -1,147 +0,0 @@ -# -*- 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/>. -''' - - -from libgamma_method import MethodCapabilities - - - -def 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. - ''' - from libgamma_native_facade import libgamma_native_list_methods - return libgamma_native_list_methods(operation) - - -def is_method_available(method : int) -> bool: - ''' - 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. - ''' - from libgamma_native_facade import libgamma_native_is_method_available - return not libgamma_native_is_method_available(method) == 0 - - -def method_capabilities(method : int) -> MethodCapabilities: - ''' - 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). - ''' - from libgamma_native_facade import libgamma_native_method_capabilities - caps = libgamma_native_method_capabilities(method) - return MethodCapabilities(*caps) - - -def method_default_site(method : int) -> str: - ''' - Return the default site for 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. - ''' - from libgamma_native_facade import libgamma_native_method_default_site - return libgamma_native_method_default_site(method) - - -def method_default_site_variable(method : int) -> str: - ''' - Return the default variable that determines - the default site for 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. - ''' - from libgamma_native_facade import libgamma_native_method_default_site_variable - return libgamma_native_method_default_site_variable(method) - - - -def behex_edid(edid : bytes) -> str: - ''' - Convert a raw representation of an EDID to a lowercase hexadecimal representation. - - @param edid The EDID in raw representation. - @return The EDID in lowercase hexadecimal representation. - ''' - return behex_edid_lowercase(edid) - - -def behex_edid_lowercase(edid : bytes) -> str: - ''' - Convert a raw representation of an EDID to a lowercase hexadecimal representation. - - @param edid The EDID in raw representation. - @return The EDID in lowercase hexadecimal representation. - ''' - rc = '' - for b in edid: - rc += '0123456789abcdef'[(b >> 4) & 15] - rc += '0123456789abcdef'[(b >> 0) & 15] - return rc - - -def behex_edid_uppercase(edid : bytes) -> str: - ''' - Convert a raw representation of an EDID to an uppercase hexadecimal representation. - - @param edid The EDID in raw representation. - @return The EDID in uppercase hexadecimal representation. - ''' - rc = '' - for b in edid: - rc += '0123456789ABCDEF'[(b >> 4) & 15] - rc += '0123456789ABCDEF'[(b >> 0) & 15] - return rc - - -def unhex_edid(edid : str) -> bytes: - ''' - Convert an hexadecimal representation of an EDID to a raw representation. - - @param edid The EDID in hexadecimal representation. - @return The EDID in raw representation. - ''' - rc = [] - edid = edid.lower() - for i in range(0, len(edid), 2): - a, b = edid[i + 0], edid[i + 1] - a = '0123456789abcdef'.find(a) << 4 - b = '0123456789abcdef'.find(b) << 0 - rc.append(a | b) - return bytes(rc) - diff --git a/src/libgamma_method.py b/src/libgamma_method.py deleted file mode 100644 index dcd4f6a..0000000 --- a/src/libgamma_method.py +++ /dev/null @@ -1,1117 +0,0 @@ -# -*- 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/>. -''' - -from libgamma_error import create_error - - - -LIBGAMMA_METHOD_DUMMY = 0 -''' -The identifier for the dummy adjustment method. -This method can be configured and is useful for -testing your program's ability to handle errors. -''' - -LIBGAMMA_METHOD_X_RANDR = 1 -''' -The identifier for the adjustment method with -uses the RandR protocol under the X display server. -''' - -LIBGAMMA_METHOD_X_VIDMODE = 2 -''' -The identifier for the adjustment method with -uses the VidMode protocol under the X display server. -This is an older alternative to RandR that can -work on some drivers that are not supported by RandR, -however it can only control the primary CRTC per -screen (partition). -''' - -LIBGAMMA_METHOD_LINUX_DRM = 3 -''' -The identifier for the Direct Rendering Manager -adjustment method that is available in Linux -(built in to the Linux kernel with a userland -library for access) and is a part of the -Direct Rendering Infrastructure. This adjustment -method all work when you are in non-graphical -mode; however a display server cannnot be -started while this is running, but it can be -started while a display server is running. -''' - -LIBGAMMA_METHOD_W32_GDI = 4 -''' -The identifier for the Graphics Device Interface -adjustment method that is available in Windows. -This method is not well tested; it can be compiled -to be available under X.org using a translation layer. -''' - -LIBGAMMA_METHOD_QUARTZ_CORE_GRAPHICS = 5 -''' -The identifier for the CoreGraphics adjustment -method that is available in Mac OS X that can -adjust gamma ramps under the Quartz display server. -This method is not well tested; it can be compiled -to be available under X.org using a translation layer. -''' - - -LIBGAMMA_METHOD_MAX = 5 -''' -The index of the last gamma method, neither it -nor any index before it may actually be supported -as it could have been disabled at compile-time -''' - -LIBGAMMA_METHOD_COUNT = (LIBGAMMA_METHOD_MAX + 1) -''' -The number adjustment methods provided by this library. -Note however that this includes adjstment methods that -have been removed at compile-time. -''' - - -class MethodCapabilities: - ''' - Capabilities of adjustment methods - - ---- Integer variables ---- - - @variable crtc_information OR of the CRTC information fields in `CRTCInformation` - that may (but can fail) be read successfully. - - ---- Boolean variables ---- - - @variable default_site_known Whether the default site is known, if true the site is integrated - to the system or can be determined using environment variables. - @variable multiple_sites Whether the adjustment method supports multiple sites rather - than just the default site. - @variable multiple_partitions Whether the adjustment method supports multiple partitions - per site. - @variable multiple_crtcs Whether the adjustment method supports multiple CRTC:s - per partition per site. - @variable partitions_are_graphics_cards Whether the partition to graphics card is a bijection. - @variable site_restore Whether the adjustment method supports `site_restore`. - @variable partition_restore Whether the adjustment method supports `partition_restore`. - @variable crtc_restore Whether the adjustment method supports `crtc_restore`. - @variable identical_gamma_sizes Whether the `red_gamma_size`, `green_gamma_size` and - `blue_gamma_size` fields in `CRTCInformation` will always - have the same values as each other for the adjustment method. - @variable fixed_gamma_size Whether the `red_gamma_size`, `green_gamma_size` and - `blue_gamma_size` fields in `CRTCInformation` will always be - filled with the same value for the adjustment method. - @variable fixed_gamma_depth Whether the `gamma_depth` field in `CRTCInformation` will - always be filled with the same value for the adjustment method. - @variable real Whether the adjustment method will actually perform adjustments. - @variable fake Whether the adjustment method is implement using a translation - layer. - ''' - - def __init__(self, crtc_information : int = 0, booleans : int = 0): - ''' - Constructor - - @param crtc_information The value for `CRTCInformation` - @param booleans The value for each booleanic variable - ''' - self.crtc_information = crtc_information - self.default_site_known = (booleans & (1 << 0)) != 0 - self.multiple_sites = (booleans & (1 << 1)) != 0 - self.multiple_partitions = (booleans & (1 << 2)) != 0 - self.multiple_crtcs = (booleans & (1 << 3)) != 0 - self.partitions_are_graphics_cards = (booleans & (1 << 4)) != 0 - self.site_restore = (booleans & (1 << 5)) != 0 - self.partition_restore = (booleans & (1 << 6)) != 0 - self.crtc_restore = (booleans & (1 << 7)) != 0 - self.identical_gamma_sizes = (booleans & (1 << 8)) != 0 - self.fixed_gamma_size = (booleans & (1 << 9)) != 0 - self.fixed_gamma_depth = (booleans & (1 << 10)) != 0 - self.real = (booleans & (1 << 11)) != 0 - self.fake = (booleans & (1 << 12)) != 0 - - -class CRTCInformation: - ''' - Cathode ray tube controller information data structure. - - @variable edid:bytes The Extended Display Identification Data associated with - the attached monitor. This is raw byte array that is usually - 128 bytes long. - @variable edid_error:int 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. - - @variable width_mm:int 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. - @variable width_mm_error:int 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. - @variable height_mm:int 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. - @variable height_mm_error:int 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. - - @variable width_mm_edid:int 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. - @variable width_mm_edid_error:int 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. - @variable height_mm_edid:int 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. - @variable height_mm_edid_error:int 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. - - @variable red_gamma_size:int The size of the encoding axis of the red gamma ramp. - @variable green_gamma_size:int The size of the encoding axis of the green gamma ramp. - @variable blue_gamma_size:int The size of the encoding axis of the blue gamma ramp. - @variable gamma_size_error:int 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. - - @variable gamma_depth:int The bit-depth of the value axes of gamma ramps, - -1 for single precision floating point, and -2 for - double precision floating point. - @variable gamma_depth_error:int 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. - - @variable gamma_support:int Non-zero gamma ramp adjustments are supported. - @variable gamma_support_error:int 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. - - @variable subpixel_order:int 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. - @variable subpixel_order_error:int 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. - - @variable active:bool Whether there is a monitors connected to the CRTC. - @variable active_error:int 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. - - @variable connector_name:str 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. - @variable connector_name_error:int 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. - - @variable connector_type:int The type of the connector that is associated with the CRTC. - @variable connector_type_error:int 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. - - @variable gamma_red:float 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. - @variable gamma_green:float 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. - @variable gamma_blue:float 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. - @variable gamma_error:int 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. - ''' - - def __init__(self, data): - ''' - Constructor - - @param data:list The value of each variable - ''' - self.edid = data[0] - self.edid_error = data[1] - self.width_mm = data[2] - self.width_mm_error = data[3] - self.height_mm = data[4] - self.height_mm_error = data[5] - self.width_mm_edid = data[6] - self.width_mm_edid_error = data[7] - self.height_mm_edid = data[8] - self.height_mm_edid_error = data[9] - self.red_gamma_size = data[10] - self.green_gamma_size = data[11] - self.blue_gamma_size = data[12] - self.gamma_size_error = data[13] - self.gamma_depth = data[14] - self.gamma_depth_error = data[15] - self.gamma_support = data[16] - self.gamma_support_error = data[17] - self.subpixel_order = data[18] - self.subpixel_order_error = data[19] - self.active = data[20] - self.active_error = data[21] - self.connector_name = data[22] - self.connector_name_error = data[23] - self.connector_type = data[24] - self.connector_type_error = data[25] - self.gamma_red = data[26] - self.gamma_green = data[27] - self.gamma_blue = data[28] - self.gamma_error = data[29] - - -LIBGAMMA_CONNECTOR_TYPE_Unknown = 0 -''' -The adjustment method does not know the connector's type -(This could be considered an error). -''' - -LIBGAMMA_CONNECTOR_TYPE_VGA = 1 -''' -Video Graphics Array (VGA). -''' - -LIBGAMMA_CONNECTOR_TYPE_DVI = 2 -''' -Digital Visual Interface, unknown type. -''' - -LIBGAMMA_CONNECTOR_TYPE_DVII = 3 -''' -Digital Visual Interface, integrated (DVI-I). -''' - -LIBGAMMA_CONNECTOR_TYPE_DVID = 4 -''' -Digital Visual Interface, digital only (DVI-D). -''' - -LIBGAMMA_CONNECTOR_TYPE_DVIA = 5 -''' -Digital Visual Interface, analogue only (DVI-A). -''' - -LIBGAMMA_CONNECTOR_TYPE_Composite = 6 -''' -Composite video. -''' - -LIBGAMMA_CONNECTOR_TYPE_SVIDEO = 7 -''' -Separate Video (S-video). -''' - -LIBGAMMA_CONNECTOR_TYPE_LVDS = 8 -''' -Low-voltage differential signaling (LVDS). -''' - -LIBGAMMA_CONNECTOR_TYPE_Component = 9 -''' -Component video, usually separate cables for each channel. -''' - -LIBGAMMA_CONNECTOR_TYPE_9PinDIN = 10 -''' -9 pin DIN (Deutsches Institut für Normung) connector. -''' - -LIBGAMMA_CONNECTOR_TYPE_DisplayPort = 11 -''' -DisplayPort. -''' - -LIBGAMMA_CONNECTOR_TYPE_HDMI = 12 -''' -High-Definition Multimedia Interface (HDMI), unknown type. -''' - -LIBGAMMA_CONNECTOR_TYPE_HDMIA = 13 -''' -High-Definition Multimedia Interface, type A (HDMI-A). -''' - -LIBGAMMA_CONNECTOR_TYPE_HDMIB = 14 -''' -High-Definition Multimedia Interface, type B (HDMI-B). -''' - -LIBGAMMA_CONNECTOR_TYPE_TV = 15 -''' -Television, unknown connector. -''' - -LIBGAMMA_CONNECTOR_TYPE_eDP = 16 -''' -Embedded DisplayPort (eDP). -''' - -LIBGAMMA_CONNECTOR_TYPE_VIRTUAL = 17 -''' -A virtual connector. -''' - -LIBGAMMA_CONNECTOR_TYPE_DSI = 18 -''' -Display Serial Interface (DSI). -''' - -LIBGAMMA_CONNECTOR_TYPE_LFP = 19 -''' -LFP connector. -(If you know what this is add it to Wikipedia.) -''' - - -LIBGAMMA_CONNECTOR_TYPE_COUNT = 20 -''' -The number of `LIBGAMMA_CONNECTOR_*` values defined. -''' - - - -LIBGAMMA_SUBPIXEL_ORDER_UNKNOWN = 0 -''' -The adjustment method does not know the order of the subpixels. -(This could be considered an error.) -''' - -LIBGAMMA_SUBPIXEL_ORDER_NONE = 1 -''' -There are no subpixels in the monitor. -''' - -LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB = 2 -''' -The subpixels are ordered red, green and then blue, from left to right. -''' - -LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_BGR = 3 -''' -The subpixels are ordered blue, green and then red, from left to right. -''' - -LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_RGB = 4 -''' -The subpixels are ordered red, green and then blue, from the top down. -''' - -LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_BGR = 5 -''' -The subpixels are ordered blue, green and then red, from the top down. -''' - - -LIBGAMMA_SUBPIXEL_ORDER_COUNT = 6 -''' -The number of `LIBGAMMA_SUBPIXEL_ORDER_*` values defined. -''' - - - -LIBGAMMA_CRTC_INFO_EDID = 1 << 0 -''' -For a `CRTCInformation` fill in the -values for `edid` and `edid_length` and report errors to `edid_error`. -''' - -LIBGAMMA_CRTC_INFO_WIDTH_MM = 1 << 1 -''' -For a `CRTCInformation` fill in the -value for `width_mm` and report errors to `width_mm_error`. -''' - -LIBGAMMA_CRTC_INFO_HEIGHT_MM = 1 << 2 -''' -For a `CRTCInformation` fill in the -value for `height_mm` and report errors to `height_mm_error`. -''' - -LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID = 1 << 3 -''' -For a `CRTCInformation` fill in the -value for `width_mm_edid` and report errors to `width_mm_edid_error`. -''' - -LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID = 1 << 4 -''' -For a `CRTCInformation` fill in the -value for `height_mm_edid` and report errors to `height_mm_edid_error`. -''' - -LIBGAMMA_CRTC_INFO_GAMMA_SIZE = 1 << 5 -''' -For a `CRTCInformation` fill in the -values for `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`. -and report errors to `gamma_size_error` -''' - -LIBGAMMA_CRTC_INFO_GAMMA_DEPTH = 1 << 6 -''' -For a `CRTCInformation` fill in the -value for `gamma_depth` and report errors to `gamma_depth_error`. -''' - -LIBGAMMA_CRTC_INFO_GAMMA_SUPPORT = 1 << 7 -''' -For a `CRTCInformation` fill in the -value for `gamma_support` and report errors to `gamma_support_error`. -''' - -LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER = 1 << 8 -''' -For a `CRTCInformation` fill in the -value for `subpixel_order` and report errors to `subpixel_order_error`. -''' - -LIBGAMMA_CRTC_INFO_ACTIVE = 1 << 9 -''' -For a `CRTCInformation` fill in the -value for `active` and report errors to `active_error`. -''' - -LIBGAMMA_CRTC_INFO_CONNECTOR_NAME = 1 << 10 -''' -For a `CRTCInformation` fill in the -value for `connector_name` and report errors to `connector_name_error`. -''' - -LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE = 1 << 11 -''' -For a `CRTCInformation` fill in the -value for `connector_type` and report errors to `connector_type_error`. -''' - -LIBGAMMA_CRTC_INFO_GAMMA = 1 << 12 -''' -For a `CRTCInformation` fill in the -values for `gamma_red`, `gamma_green` and `gamma_blue` -and report errors to `gamma_error`. -''' - - -LIBGAMMA_CRTC_INFO_COUNT = 13 -''' -The number of `LIBGAMMA_CRTC_INFO_*` values defined. -''' - - - -LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID | \ - LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID -''' -Macro for both `CRTCInformation` fields -that can specify the size of the monitor's viewport -as specified in the monitor's Extended Display -Information Data. -''' - -LIBGAMMA_CRTC_INFO_MACRO_EDID = LIBGAMMA_CRTC_INFO_EDID | \ - LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT | \ - LIBGAMMA_CRTC_INFO_GAMMA -''' -Macro for all `CRTCInformation` fields -that can be filled if the adjustment method have -support for reading the monitors' Extended Display -Information Data. -''' - -LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM | \ - LIBGAMMA_CRTC_INFO_HEIGHT_MM -''' -Macro for both `CRTCInformation` fields -that can specify the size of the monitor's viewport -as provided by the adjustment method without this -library having to parse the monitor's Extended Display -Information Data. -''' - -LIBGAMMA_CRTC_INFO_MACRO_RAMP = LIBGAMMA_CRTC_INFO_GAMMA_SIZE | \ - LIBGAMMA_CRTC_INFO_GAMMA_DEPTH -''' -Macro for the `CRTCInformation` fields -that specifies the CRTC's gamma ramp sizes and gamma -ramp depth. -''' - -LIBGAMMA_CRTC_INFO_MACRO_CONNECTOR = LIBGAMMA_CRTC_INFO_CONNECTOR_NAME | \ - LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE -''' -Macro for the `CRTCInformation` fields -that specifies the CRTC's connector type and the -partition unique name of the connector. -''' - -LIBGAMMA_CRTC_INFO_MACRO_ACTIVE = LIBGAMMA_CRTC_INFO_MACRO_EDID | \ - LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT | \ - LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER | \ - LIBGAMMA_CRTC_INFO_ACTIVE -''' -Macro for the `CRTCInformation` fields -that required there is a monitor attached to the connector, -and that status itself. -''' - - - -class GammaRamps: - ''' - Gamma ramp structure. - ''' - - class Ramp: - ''' - A gamma ramp for one single channel. - ''' - - def __init__(self, ramp, size : int, depth : int): - ''' - Constructor. - - @param ramp The gamma ramp. - @param size The number of stops in the gamma ramp. - @param depth The depth of the gamma ramp. - ''' - from libgamma_native_method import libgamma_native_gamma_ramps8_get - from libgamma_native_method import libgamma_native_gamma_ramps16_get - from libgamma_native_method import libgamma_native_gamma_ramps32_get - from libgamma_native_method import libgamma_native_gamma_ramps64_get - from libgamma_native_method import libgamma_native_gamma_rampsf_get - from libgamma_native_method import libgamma_native_gamma_rampsd_get - from libgamma_native_method import libgamma_native_gamma_ramps8_set - from libgamma_native_method import libgamma_native_gamma_ramps16_set - from libgamma_native_method import libgamma_native_gamma_ramps32_set - from libgamma_native_method import libgamma_native_gamma_ramps64_set - from libgamma_native_method import libgamma_native_gamma_rampsf_set - from libgamma_native_method import libgamma_native_gamma_rampsd_set - self._size = size - self._ramp = ramp - if depth == 8: fs = (libgamma_native_gamma_ramps8_get, libgamma_native_gamma_ramps8_set) - elif depth == 16: fs = (libgamma_native_gamma_ramps16_get, libgamma_native_gamma_ramps16_set) - elif depth == 32: fs = (libgamma_native_gamma_ramps32_get, libgamma_native_gamma_ramps32_set) - elif depth == 64: fs = (libgamma_native_gamma_ramps64_get, libgamma_native_gamma_ramps64_set) - elif depth == -1: fs = (libgamma_native_gamma_rampsf_get, libgamma_native_gamma_rampsf_set) - elif depth == -2: fs = (libgamma_native_gamma_rampsd_get, libgamma_native_gamma_rampsd_set) - (self._get, self._set) = fs - - - @property - def size(self) -> int: - ''' - Get the number of stops in the gamma ramp. - - @return The number of stops in the gamma ramp. - ''' - return self._size - - @size.setter - def size(self, value : int): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot resize ramp') - - def __len__(self) -> int: - ''' - Get the number of stops in the gamma ramp. - - @return The number of stops in the gamma ramp. - ''' - return self._size - - def __getitem__(self, indices): - ''' - Read the gamma ramp. - - @param indices:slice The stops to read. - @return :list<int|float> The values of the read stops. - - -- OR -- - - @param indices:int The index of the stop to read. - @return :int|float The value of the read stop. - ''' - if isinstance(indices, slice): - start = indices.start - stop = indices.stop - step = indices.step - if start is None: start = 0 - elif start < 0: start += self._size - if stop is None: stop = self._size - elif stop < 0: stop += self._size - if step is None: step = 1 - return [self._get(self._ramp, i) for i in range(start, stop, step)] - else: - if indices < 0: - indices += self._size - return self._get(self._ramp, indices) - - def __setitem__(self, indices, values): - ''' - Modify the gamma ramp. - - @param indices:slice The stops to modify. - @param values:itr<int|float> The values for the selected stops. - - -- OR -- - - @param indices:int The index of the stop to modify. - @param values:int|float The new value for the stop. - ''' - if isinstance(indices, slice): - start = indices.start - stop = indices.stop - step = indices.step - if start is None: start = 0 - elif start < 0: start += self._size - if stop is None: stop = self._size - elif stop < 0: stop += self._size - if step is None: step = 1 - indices = list(range(start, stop, step)) - if not len(indices) == len(values): - raise ValueError('cannot resize ramp') - for index, value in zip(indices, values): - self._set(self._ramp, index, value) - else: - if indices < 0: - indices += self._size - self._set(self._ramp, indices, values) - - def __iter__(self) -> iter: - ''' - Read the gamma ramp. - - @return :itr<int|float> The values of each stop. - ''' - for value in self[:]: - yield value - - def map(self, function): - ''' - Modify the entire ramp using a function that - maps encoding value to output value. - - @param function:(float)→int|float Function that takes the encoding value as a - [0, 1] floating point and returns its output - value as the format using in the gamma ramp. - ''' - max_i = self._size - 1 - for i in range(self._size): - self._set(self._ramp, i, function(i / max_i)) - - def __init__(self, red_size : int, green_size : int = ..., blue_size : int = ..., *, depth : int = 16): - ''' - Constructor. - - @param red_size The number of stops in the gamma ramp for the red channel. - @param green_size The number of stops in the gamma ramp for the green channel, `...` for `red_size`. - @param blue_size The number of stops in the gamma ramp for the blue channel, `...` for `green_size`. - @param depth The depth of the gamma ramps. - ''' - if green_size is ...: green_size = red_size - if blue_size is ...: blue_size = green_size - - self._depth = depth - - from libgamma_native_method import libgamma_native_gamma_ramps8_create - from libgamma_native_method import libgamma_native_gamma_ramps16_create - from libgamma_native_method import libgamma_native_gamma_ramps32_create - from libgamma_native_method import libgamma_native_gamma_ramps64_create - from libgamma_native_method import libgamma_native_gamma_rampsf_create - from libgamma_native_method import libgamma_native_gamma_rampsd_create - if depth == 8: ramp_struct = libgamma_native_gamma_ramps8_create (red_size, green_size, blue_size) - elif depth == 16: ramp_struct = libgamma_native_gamma_ramps16_create(red_size, green_size, blue_size) - elif depth == 32: ramp_struct = libgamma_native_gamma_ramps32_create(red_size, green_size, blue_size) - elif depth == 64: ramp_struct = libgamma_native_gamma_ramps64_create(red_size, green_size, blue_size) - elif depth == -1: ramp_struct = libgamma_native_gamma_rampsf_create (red_size, green_size, blue_size) - elif depth == -2: ramp_struct = libgamma_native_gamma_rampsd_create (red_size, green_size, blue_size) - else: - raise ValueError('invalid gamma ramp depth') - if isinstance(ramp_struct, int): - import libgamma_native_error as c - error = OSError() - error.errno = ramp_struct - error.strerror = c.strerror(error.errno) - raise error - (self._ramps, red, green, blue) = ramp_struct - - self._red = GammaRamps.Ramp(red, red_size, depth) - self._green = GammaRamps.Ramp(green, green_size, depth) - self._blue = GammaRamps.Ramp(blue, blue_size, depth) - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_method import libgamma_native_gamma_ramps8_free - from libgamma_native_method import libgamma_native_gamma_ramps16_free - from libgamma_native_method import libgamma_native_gamma_ramps32_free - from libgamma_native_method import libgamma_native_gamma_ramps64_free - from libgamma_native_method import libgamma_native_gamma_rampsf_free - from libgamma_native_method import libgamma_native_gamma_rampsd_free - if self._ramps == 0: - return - if self._depth == 8: libgamma_native_gamma_ramps8_free(self._ramps) - elif self._depth == 16: libgamma_native_gamma_ramps16_free(self._ramps) - elif self._depth == 32: libgamma_native_gamma_ramps32_free(self._ramps) - elif self._depth == 64: libgamma_native_gamma_ramps64_free(self._ramps) - elif self._depth == -1: libgamma_native_gamma_rampsf_free(self._ramps) - elif self._depth == -2: libgamma_native_gamma_rampsd_free(self._ramps) - - - @property - def red(self) -> Ramp: - ''' - Get the gamma ramp for the red channel. - - @return The gamma ramp for the red channel. - ''' - return self._red - - - @red.setter - def red(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change ramps') - - - @property - def green(self) -> Ramp: - ''' - Get the gamma ramp for the green channel. - - @return The gamma ramp for the green channel. - ''' - return self._green - - - @green.setter - def green(self, value) -> Ramp: - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change ramps') - - - @property - def blue(self): - ''' - Get the gamma ramp for the blue channel. - - @return The gamma ramp for the blue channel. - ''' - return self._blue - - - @blue.setter - def blue(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change ramps') - - - @property - def size(self) -> tuple: - ''' - Get the ramps' sizes. - - @return :(red:int, green:int, blue:int) The size of each individual ramp. - ''' - return (self._red.size, self._green.size, self._blue.size) - - - @size.setter - def size(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot resize ramps') - - - @property - def depth(self) -> int: - ''' - Get the depth of ramps. - - @return :int The ramps' depth in bits and -1 for single precision floating - point and -2 for doublesingle precision floating point. - ''' - return self._depth - - - @depth.setter - def depth(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change depth') - - - -class Site: - ''' - 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. - - @variable method:int The adjustment method of the site. - @variable site:str? The site identifier. - @variable partitions_available:int The number of paritions available in the site. - ''' - - def __init__(self, method : int, site : str = None): - ''' - Constructor. - - @param method:int The adjustment method of the site. - @param site:str? The site identifier. - ''' - from libgamma_native_facade import libgamma_native_site_create - (self._state, n) = libgamma_native_site_create(method, site) - if self._state == 0: - raise create_error(n) - self.partitions_available = n - self.method = method - self.site = site - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_facade import libgamma_native_site_free - if not self._state == 0: - libgamma_native_site_free(self._state) - - - def restore(self): - ''' - Restore the gamma ramps all CRTC:s with the site to the system settings. - ''' - from libgamma_native_facade import libgamma_native_site_restore - r = libgamma_native_site_restore(self._state) - if not r == 0: - raise create_error(r) - - -class Partition: - ''' - 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 - - @variable site:Site The site of the partition. - @variable partition:int The index of the partition. - @variable crtcs_available:int The number of CRTC:s available in the parition. - ''' - - def __init__(self, site : Site, partition : int): - ''' - Constructor. - - @param site The site of the partition. - @param partition The index of the partition. - ''' - from libgamma_native_facade import libgamma_native_partition_create - (self._state, n) = libgamma_native_partition_create(site._state, partition) - if self._state == 0: - raise create_error(n) - self.crtcs_available = n - self.site = site - self.partition = partition - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_facade import libgamma_native_partition_free - if not self._state == 0: - libgamma_native_partition_free(self._state) - - - def restore(self): - ''' - Restore the gamma ramps all CRTC:s with the partition to the system settings. - ''' - from libgamma_native_facade import libgamma_native_partition_restore - r = libgamma_native_partition_restore(self._state) - if not r == 0: - raise create_error(r) - - -class CRTC: - ''' - 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. - - @variable partition:Partition The partition of the CRTC. - @variable crtc:int The index of the CRTC. - ''' - - def __init__(self, partition : Partition, crtc : int): - ''' - Constructor. - - @param partition The partition the of the CRTC. - @param crtc The index of the CRTC. - ''' - from libgamma_native_facade import libgamma_native_crtc_create - (self._state, n) = libgamma_native_crtc_create(partition._state, crtc) - if self._state == 0: - raise create_error(n) - self.partition = partition - self.crtc = crtc - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_facade import libgamma_native_crtc_free - if not self._state == 0: - libgamma_native_crtc_free(self._state) - - - def restore(self): - ''' - Restore the gamma ramps for a CRTC to the system settings for that CRTC. - ''' - from libgamma_native_facade import libgamma_native_crtc_restore - r = libgamma_native_crtc_restore(self._state) - if not r == 0: - raise create_error(r) - - - def information(self, fields : int) -> tuple: - ''' - Read information about a CRTC. - - @param field OR:ed identifiers for the information - about the CRTC that should be read. - @return :(:CRTCInformation, :bool) The information about the CRTC and - whether no errors occurred. - ''' - from libgamma_native_facade import libgamma_native_get_crtc_information - (data, e) = libgamma_native_get_crtc_information(self._state, fields) - return (CRTCInformation(data), e == 0) - - - def get_gamma(self, ramps : GammaRamps): - ''' - Get the current gamma ramps for the CRTC. - - @param ramps The gamma ramps to fill with the current values. - ''' - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps8 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps16 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps32 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps64 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_rampsf - from libgamma_native_facade import libgamma_native_crtc_get_gamma_rampsd - if ramps.depth == 8: r = libgamma_native_crtc_get_gamma_ramps8(self._state, ramps._ramps) - elif ramps.depth == 16: r = libgamma_native_crtc_get_gamma_ramps16(self._state, ramps._ramps) - elif ramps.depth == 32: r = libgamma_native_crtc_get_gamma_ramps32(self._state, ramps._ramps) - elif ramps.depth == 64: r = libgamma_native_crtc_get_gamma_ramps64(self._state, ramps._ramps) - elif ramps.depth == -1: r = libgamma_native_crtc_get_gamma_rampsf(self._state, ramps._ramps) - elif ramps.depth == -2: r = libgamma_native_crtc_get_gamma_rampsd(self._state, ramps._ramps) - if not r == 0: - raise create_error(r) - - - def set_gamma(self, ramps : GammaRamps): - ''' - Set gamma ramps for the CRTC. - - @param ramps The gamma ramps to apply. - ''' - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps8 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps16 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps32 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps64 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_rampsf - from libgamma_native_facade import libgamma_native_crtc_set_gamma_rampsd - if ramps.depth == 8: r = libgamma_native_crtc_set_gamma_ramps8(self._state, ramps._ramps) - elif ramps.depth == 16: r = libgamma_native_crtc_set_gamma_ramps16(self._state, ramps._ramps) - elif ramps.depth == 32: r = libgamma_native_crtc_set_gamma_ramps32(self._state, ramps._ramps) - elif ramps.depth == 64: r = libgamma_native_crtc_set_gamma_ramps64(self._state, ramps._ramps) - elif ramps.depth == -1: r = libgamma_native_crtc_set_gamma_rampsf(self._state, ramps._ramps) - elif ramps.depth == -2: r = libgamma_native_crtc_set_gamma_rampsd(self._state, ramps._ramps) - if not r == 0: - raise create_error(r) - diff --git a/src/libgamma_native_error.pyx b/src/libgamma_native_error.pyx deleted file mode 100644 index 6963a44..0000000 --- a/src/libgamma_native_error.pyx +++ /dev/null @@ -1,205 +0,0 @@ -# -*- 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 posix.unistd cimport gid_t -from libc.string cimport strerror as c_strerror - - -cdef extern gid_t libgamma_group_gid_get() nogil -cdef extern void libgamma_group_gid_set(gid_t) nogil -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. -''' - -cdef extern const char* libgamma_group_name_get() nogil -cdef extern void libgamma_group_name_set(const char*) nogil -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, -`NULL` if the name of the group `libgamma_group_gid` -cannot be determined. -''' - - -cdef extern void libgamma_perror(const char* name, int error_code) nogil -''' -Prints an error to stderr in a `perror` fashion, -however this function will not translate the `libgamma` -errors into human-readable strings, it will simply -print the name of the error. If the value `error_code` -is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be -used to print the current error stored in `errno`. -If `error_code` is non-negative (an `errno` value`), that -value will be stored in `errno` and `perror` will be -used to print it. Additionally, if the `error_code` is -the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the -required group will be printed with its numerical value -and, if known, its name. - -@param name The text to add at the beginning. -@param value The error code, may be an `errno` value. -''' - -cdef extern const char* libgamma_name_of_error(int value) nogil -''' -Returns the name of the definition associated with a `libgamma` error code. - -@param value The error code. -@return The name of the definition associated with the error code, - `NULL` if the error code does not exist. The return string - should not be `free`:d. -''' - -cdef extern int libgamma_value_of_error(const char* name) nogil -''' -Return the value of a `libgamma` error definition refered to by name. - -@param name The name of the definition associated with the error code. -@return The error code, zero if the name does is `NULL` - or does not refer to a `libgamma` error. -''' - - - -def libgamma_native_get_group_gid() -> int: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - return int(libgamma_group_gid_get()) - -def libgamma_native_set_group_gid(gid : int): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - libgamma_group_gid_set(<int>gid) - - -def libgamma_native_get_group_name() -> str: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef const char* group_name - cdef bytes bs - group_name = libgamma_group_name_get() - if group_name is NULL: - return None - bs = group_name - return bs.decode('utf-8', 'strict') - -def libgamma_native_set_group_name(name : str): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef const char* group_name - cdef bytes bs - if name is None: - libgamma_group_name_set(<char*>NULL) - return - bs = name.encode('utf-8') + bytes([0]) - group_name = bs - libgamma_group_name_set(group_name) - - -def libgamma_native_perror(name : str, error_code : int): - ''' - Prints an error to stderr in a `perror` fashion, - however this function will not translate the `libgamma` - errors into human-readable strings, it will simply - print the name of the error. If the value `error_code` - is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be - used to print the current error stored in `errno`. - If `error_code` is non-negative (an `errno` value`), that - value will be stored in `errno` and `perror` will be - used to print it. Additionally, if the `error_code` is - the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the - required group will be printed with its numerical value - and, if known, its name. - - @param name The text to add at the beginning. - @param value The error code, may be an `errno` value. - ''' - cdef bytes bs - bs = name.encode('utf-8') + bytes([0]) - libgamma_perror(bs, <int>error_code) - - -def libgamma_native_name_of_error(value : int) -> str: - ''' - Returns the name of the definition associated with a `libgamma` error code. - - @param value The error code. - @return The name of the definition associated with the error code, - `None` if the error code does not exist. - ''' - cdef const char* name - cdef bytes bs - name = libgamma_name_of_error(<int>value) - if name is NULL: - return None - bs = name - return bs.decode('utf-8', 'strict') - - -def libgamma_native_value_of_error(name : str) -> int: - ''' - Return the value of a `libgamma` error definition refered to by name. - - @param name The name of the definition associated with the error code. - @return The error code, zero if the name is `None`, - or does not refer to a `libgamma` error. - ''' - cdef bytes bs - if name is None: - return 0 - bs = name.encode('utf-8') + bytes([0]) - return int(libgamma_value_of_error(bs)) - - -def strerror(error : int) -> str: - ''' - Get a textual description of an error. - - @param error The number of the error. - @return The description of the error. - ''' - cdef const char* text - cdef bytes bs - text = c_strerror(<int>error) - bs = text - return bs.decode('utf-8', 'strict') - diff --git a/src/libgamma_native_error.w32.pyx b/src/libgamma_native_error.w32.pyx deleted file mode 100644 index abef314..0000000 --- a/src/libgamma_native_error.w32.pyx +++ /dev/null @@ -1,183 +0,0 @@ -# -*- 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 - - -cdef extern short libgamma_group_gid -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. -''' - -cdef extern const char* libgamma_group_name -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, -`NULL` if the name of the group `libgamma_group_gid` -cannot be determined. -''' - - -cdef extern void libgamma_perror(const char* name, int error_code) nogil -''' -Prints an error to stderr in a `perror` fashion, -however this function will not translate the `libgamma` -errors into human-readable strings, it will simply -print the name of the error. If the value `error_code` -is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be -used to print the current error stored in `errno`. -If `error_code` is non-negative (an `errno` value`), that -value will be stored in `errno` and `perror` will be -used to print it. Additionally, if the `error_code` is -the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the -required group will be printed with its numerical value -and, if known, its name. - -@param name The text to add at the beginning. -@param value The error code, may be an `errno` value. -''' - -cdef extern const char* libgamma_name_of_error(int value) nogil -''' -Returns the name of the definition associated with a `libgamma` error code. - -@param value The error code. -@return The name of the definition associated with the error code, - `NULL` if the error code does not exist. The return string - should not be `free`:d. -''' - -cdef extern int libgamma_value_of_error(const char* name) nogil -''' -Return the value of a `libgamma` error definition refered to by name. - -@param name The name of the definition associated with the error code. -@return The error code, zero if the name does is `NULL` - or does not refer to a `libgamma` error. -''' - - - -def libgamma_native_get_group_gid() -> int: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - return int(libgamma_group_gid) - -def libgamma_native_set_group_gid(gid : int): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - libgamma_group_gid = <int>gid - - -def libgamma_native_get_group_name() -> str: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef bytes bs - if libgamma_group_name is NULL: - return None - bs = libgamma_group_name - return bs.decode('utf-8', 'strict') - -def libgamma_native_set_group_name(name : str): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef bytes bs - if name is None: - libgamma_group_name = <char*>NULL - return - bs = name.encode('utf-8') + bytes([0]) - libgamma_group_name = bs - - -def libgamma_native_perror(name : str, error_code : int): - ''' - Prints an error to stderr in a `perror` fashion, - however this function will not translate the `libgamma` - errors into human-readable strings, it will simply - print the name of the error. If the value `error_code` - is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be - used to print the current error stored in `errno`. - If `error_code` is non-negative (an `errno` value`), that - value will be stored in `errno` and `perror` will be - used to print it. Additionally, if the `error_code` is - the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the - required group will be printed with its numerical value - and, if known, its name. - - @param name The text to add at the beginning. - @param value The error code, may be an `errno` value. - ''' - cdef bytes bs - bs = name.encode('utf-8') + bytes([0]) - libgamma_perror(bs, <int>error_code) - - -def libgamma_native_name_of_error(value : int) -> str: - ''' - Returns the name of the definition associated with a `libgamma` error code. - - @param value The error code. - @return The name of the definition associated with the error code, - `None` if the error code does not exist. The return string - should not be `free`:d. - ''' - cdef const char* name - cdef bytes bs - name = libgamma_name_of_error(<int>value) - if name is NULL: - return None - bs = name - return bs.decode('utf-8', 'strict') - - -def libgamma_native_value_of_error(name : str) -> int: - ''' - Return the value of a `libgamma` error definition refered to by name. - - @param name The name of the definition associated with the error code. - @return The error code, zero if the name is `None`, - or does not refer to a `libgamma` error. - ''' - cdef bytes bs - if name is None: - return 0 - bs = name.encode('utf-8') + bytes([0]) - return int(libgamma_value_of_error(bs)) - diff --git a/src/libgamma_native_facade.pyx b/src/libgamma_native_facade.pyx deleted file mode 100644 index 32846e2..0000000 --- a/src/libgamma_native_facade.pyx +++ /dev/null @@ -1,1389 +0,0 @@ -# -*- 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 -from libc.errno cimport errno - - -ctypedef int libgamma_subpixel_order_t -ctypedef int libgamma_connector_type_t - - -cdef extern from "include-libgamma.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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -Return the default site for 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) nogil -''' -Return the default variable that determines -the default site for 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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -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) nogil -''' -Get the current 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) nogil -''' -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) nogil -''' -Get the current 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) nogil -''' -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) nogil -''' -Get the current 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) nogil -''' -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) nogil -''' -Get the current 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) nogil -''' -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) nogil -''' -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) nogil -''' -Get the current 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) nogil -''' -Get the current 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) nogil -''' -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 default site for 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) - if var is NULL: - return None - bs = var - return bs.decode('utf-8', 'strict') - - -def libgamma_native_method_default_site_variable(method : int) -> str: - ''' - Return the default variable that determines - the default site for 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) - if var is NULL: - return None - bs = var - return bs.decode('utf-8', 'strict') - - - -def libgamma_native_site_create(method : int, site : str) -> tuple: - ''' - Create an allocated site state. - - @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 :(site:int, partitions:int) First value: The created site, zero on error - Second value: The number of partitions in the site, - on error: the value of the error identifier - provided by this library or `errno`. - ''' - cdef libgamma_site_state_t* this - cdef char* site_ - cdef size_t this_address - this = <libgamma_site_state_t*>malloc(sizeof(libgamma_site_state_t)) - if this is NULL: - raise MemoryError() - this_address = <size_t><void*>this - site_ = NULL - if site is not None: - site_bs = site.encode('utf-8') + bytes([0]) - site_ = <char*>malloc(len(site_bs) * sizeof(char)) - if site_ is None: - free(this) - raise MemoryError() - for i in range(len(site_bs)): - site_[i] = <char>(site_bs[i]) - r = int(libgamma_site_initialise(this, <int>method, site_)) - if not r == 0: - libgamma_site_free(this) - return (0, int(errno) if r == -1 else r) - return (int(this_address), int(this.partitions_available)) - - -def libgamma_native_site_free(this : int): - ''' - Release all resources held by a site state - and free the CRTC state pointer. - - @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 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 the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef libgamma_site_state_t* this_ - this_address = <size_t>this - this_ = <libgamma_site_state_t*><void*>this_address - r = int(libgamma_site_restore(this_)) - return int(errno) if r == -1 else r - - - -def libgamma_native_partition_create(site : int, partition : int) -> tuple: - ''' - Create an allocated partition state. - - @param site The site state for the site that the partition belongs to. - @param partition The index of the partition within the site. - @return :(site:int, partitions:int) First value: The created partition, zero on error - Second value: The number of CRTC:s in the partition, - on error: the value of the error identifier - provided by this library or `errno`. - ''' - cdef libgamma_partition_state_t* this - cdef libgamma_site_state_t* site_ - cdef size_t this_address - cdef size_t site_address - site_address = <size_t>site - site_ = <libgamma_site_state_t*><void*>site_address - this = <libgamma_partition_state_t*>malloc(sizeof(libgamma_partition_state_t)) - if this is NULL: - raise MemoryError() - this_address = <size_t><void*>this - r = int(libgamma_partition_initialise(this, site_, <size_t>partition)) - if not r == 0: - libgamma_partition_free(this) - return (0, int(errno) if r == -1 else r) - return (int(this_address), int(this.crtcs_available)) - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef libgamma_partition_state_t* this_ - this_address = <size_t>this - this_ = <libgamma_partition_state_t*><void*>this_address - r = int(libgamma_partition_restore(this_)) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_create(partition : int, crtc : int) -> tuple: - ''' - Create an allocated CRTC state. - - @param partition The partition state for the partition that the CRTC belongs to. - @param crtc The index of the CRTC within the partition. - @return :(int, int) First value: The created CRTC, zero on error. - Second value: Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef libgamma_crtc_state_t* this - cdef libgamma_partition_state_t* partition_ - cdef size_t this_address - cdef size_t partition_address - partition_address = <size_t>partition - partition_ = <libgamma_partition_state_t*><void*>partition_address - this = <libgamma_crtc_state_t*>malloc(sizeof(libgamma_crtc_state_t)) - if this is NULL: - raise MemoryError() - this_address = <size_t><void*>this - r = int(libgamma_crtc_initialise(this, partition_, <size_t>crtc)) - if not r == 0: - libgamma_crtc_free(this) - return (0, int(errno) if r == -1 else r) - return (int(this_address), 0) - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef libgamma_crtc_state_t* this_ - this_address = <size_t>this - this_ = <libgamma_crtc_state_t*><void*>this_address - r = int(libgamma_crtc_restore(this_)) - return int(errno) if r == -1 else r - - - -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_crtc_information_destroy(&info) - return (rc, r) - - - -def libgamma_native_crtc_get_gamma_ramps8(this : int, ramps : int) -> int: - ''' - Get the current 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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_get_gamma_ramps8(this_, ramps_)) - return int(errno) if r == -1 else r - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_set_gamma_ramps8(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_ramps16(this : int, ramps : int) -> int: - ''' - Get the current 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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_get_gamma_ramps16(this_, ramps_)) - return int(errno) if r == -1 else r - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_set_gamma_ramps16(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_ramps32(this : int, ramps : int) -> int: - ''' - Get the current 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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_get_gamma_ramps32(this_, ramps_)) - return int(errno) if r == -1 else r - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_set_gamma_ramps32(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_ramps64(this : int, ramps : int) -> int: - ''' - Get the current 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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_get_gamma_ramps64(this_, ramps_)) - return int(errno) if r == -1 else r - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_set_gamma_ramps64(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_rampsf(this : int, ramps : int) -> int: - ''' - Get the current 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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_get_gamma_rampsf(this_, ramps_)) - return int(errno) if r == -1 else r - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_set_gamma_rampsf(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_rampsd(this : int, ramps : int) -> int: - ''' - Get the current 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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_get_gamma_rampsd(this_, ramps_)) - return int(errno) if r == -1 else r - - -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 the value of an error - identifier provided by this library or `errno`. - ''' - 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 - r = int(libgamma_crtc_set_gamma_rampsd(this_, ramps_[0])) - return int(errno) if r == -1 else r - diff --git a/src/libgamma_native_method.pyx b/src/libgamma_native_method.pyx deleted file mode 100644 index 1550caf..0000000 --- a/src/libgamma_native_method.pyx +++ /dev/null @@ -1,682 +0,0 @@ -# -*- 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.stdint cimport * -from libc.stdlib cimport malloc -from libc.stddef cimport size_t -from libc.errno cimport errno - - -cdef extern from "include-libgamma.h": - 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 int libgamma_gamma_ramps8_initialise(libgamma_gamma_ramps8_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps8_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_ramps16_initialise(libgamma_gamma_ramps16_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps16_free(libgamma_gamma_ramps16_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps16_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - - -def libgamma_native_gamma_ramps8_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @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 - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps8_t)) - cdef libgamma_gamma_ramps8_t* item = <libgamma_gamma_ramps8_t*>allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps8_initialise(item) < 0: - return int(errno) - red = <size_t><void*>(item.red) - green = <size_t><void*>(item.green) - blue = <size_t><void*>(item.blue) - return (int(<size_t>allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps8_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps8_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = <void*><size_t>this - cdef libgamma_gamma_ramps8_t* item = <libgamma_gamma_ramps8_t*>address - libgamma_gamma_ramps8_free(item) - - -def libgamma_native_gamma_ramps8_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint8_t* ramp = <uint8_t*>address - return int(ramp[<size_t>index]) - - -def libgamma_native_gamma_ramps8_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint8_t* ramp = <uint8_t*>address - ramp[<size_t>index] = <uint8_t>value - - - -def libgamma_native_gamma_ramps16_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @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 - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps16_t)) - cdef libgamma_gamma_ramps16_t* item = <libgamma_gamma_ramps16_t*>allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps16_initialise(item) < 0: - return int(errno) - red = <size_t><void*>(item.red) - green = <size_t><void*>(item.green) - blue = <size_t><void*>(item.blue) - return (int(<size_t>allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps16_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps16_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = <void*><size_t>this - cdef libgamma_gamma_ramps16_t* item = <libgamma_gamma_ramps16_t*>address - libgamma_gamma_ramps16_free(item) - - -def libgamma_native_gamma_ramps16_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint16_t* ramp = <uint16_t*>address - return int(ramp[<size_t>index]) - - -def libgamma_native_gamma_ramps16_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint16_t* ramp = <uint16_t*>address - ramp[<size_t>index] = <uint16_t>value - - - -def libgamma_native_gamma_ramps32_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @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 - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps32_t)) - cdef libgamma_gamma_ramps32_t* item = <libgamma_gamma_ramps32_t*>allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps32_initialise(item) < 0: - return int(errno) - red = <size_t><void*>(item.red) - green = <size_t><void*>(item.green) - blue = <size_t><void*>(item.blue) - return (int(<size_t>allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps32_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps32_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = <void*><size_t>this - cdef libgamma_gamma_ramps32_t* item = <libgamma_gamma_ramps32_t*>address - libgamma_gamma_ramps32_free(item) - - -def libgamma_native_gamma_ramps32_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint32_t* ramp = <uint32_t*>address - return int(ramp[<size_t>index]) - - -def libgamma_native_gamma_ramps32_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint32_t* ramp = <uint32_t*>address - ramp[<size_t>index] = <uint32_t>value - - - -def libgamma_native_gamma_ramps64_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @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 - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps64_t)) - cdef libgamma_gamma_ramps64_t* item = <libgamma_gamma_ramps64_t*>allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps64_initialise(item) < 0: - return int(errno) - red = <size_t><void*>(item.red) - green = <size_t><void*>(item.green) - blue = <size_t><void*>(item.blue) - return (int(<size_t>allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps64_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps64_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = <void*><size_t>this - cdef libgamma_gamma_ramps64_t* item = <libgamma_gamma_ramps64_t*>address - libgamma_gamma_ramps64_free(item) - - -def libgamma_native_gamma_ramps64_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint64_t* ramp = <uint64_t*>address - return int(ramp[<size_t>index]) - - -def libgamma_native_gamma_ramps64_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef uint64_t* ramp = <uint64_t*>address - ramp[<size_t>index] = <uint64_t>value - - - -def libgamma_native_gamma_rampsf_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @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 - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_rampsf_t)) - cdef libgamma_gamma_rampsf_t* item = <libgamma_gamma_rampsf_t*>allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_rampsf_initialise(item) < 0: - return int(errno) - red = <size_t><void*>(item.red) - green = <size_t><void*>(item.green) - blue = <size_t><void*>(item.blue) - return (int(<size_t>allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_rampsf_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_rampsf_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = <void*><size_t>this - cdef libgamma_gamma_rampsf_t* item = <libgamma_gamma_rampsf_t*>address - libgamma_gamma_rampsf_free(item) - - -def libgamma_native_gamma_rampsf_get(this : int, index : int) -> float: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef float* ramp = <float*>address - return float(ramp[<size_t>index]) - - -def libgamma_native_gamma_rampsf_set(this : int, index : int, value : float): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef float* ramp = <float*>address - ramp[<size_t>index] = <float>value - - - -def libgamma_native_gamma_rampsd_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @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 - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_rampsd_t)) - cdef libgamma_gamma_rampsd_t* item = <libgamma_gamma_rampsd_t*>allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_rampsd_initialise(item) < 0: - return int(errno) - red = <size_t><void*>(item.red) - green = <size_t><void*>(item.green) - blue = <size_t><void*>(item.blue) - return (int(<size_t>allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_rampsd_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_rampsd_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = <void*><size_t>this - cdef libgamma_gamma_rampsd_t* item = <libgamma_gamma_rampsd_t*>address - libgamma_gamma_rampsd_free(item) - - -def libgamma_native_gamma_rampsd_get(this : int, index : int) -> float: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef double* ramp = <double*>address - return float(ramp[<size_t>index]) - - -def libgamma_native_gamma_rampsd_set(this : int, index : int, value : float): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = <void*><size_t>this - cdef double* ramp = <double*>address - ramp[<size_t>index] = <double>value - diff --git a/src/test.py b/src/test.py deleted file mode 100755 index 58ed78e..0000000 --- a/src/test.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -# -*- 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/>. -''' - -import libgamma -from time import sleep - - -method = libgamma.list_methods(0)[0] -assert libgamma.is_method_available(method) == True - -print('\033[1mMethod capabilities\033[m') -print(libgamma.method_capabilities(method).__dict__) -print() - -print('\033[1mMethod default site variable and default site\033[m') -print(repr(libgamma.method_default_site_variable(method))) -print(repr(libgamma.method_default_site(method))) -print() - -print('\033[1mUnhexing b"0123456789ABCDEF" and b"0123456789abcdef"\033[m') -print(repr(libgamma.unhex_edid('0123456789ABCDEF'))) -print(repr(libgamma.unhex_edid('0123456789abcdef'))) -print('\033[1mUnhexing and rehexing "0123456789abcdef"\033[m') -print(repr(libgamma.behex_edid(libgamma.unhex_edid('0123456789abcdef')))) -print(repr(libgamma.behex_edid_lowercase(libgamma.unhex_edid('0123456789abcdef')))) -print(repr(libgamma.behex_edid_uppercase(libgamma.unhex_edid('0123456789abcdef')))) -print() - -print('\033[1mPrinting required group ID, setting to 10, and reprinting\033[m') -print(libgamma.group.gid) -libgamma.group.gid = 10 -print(libgamma.group.gid) -print() - -print('\033[1mPrinting required group name, setting to "group", and reprinting\033[m') -print(repr(libgamma.group.name)) -libgamma.group.name = 'group' -print(repr(libgamma.group.name)) -print() - -print('\033[1mPrint description for errors: 0, ERRNO_SET and NO_SUCH_ADJUSTMENT_METHOD\033[m') -libgamma.perror('test', 0) -libgamma.perror('test', libgamma.LIBGAMMA_ERRNO_SET) -libgamma.perror('test', libgamma.LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD) -print() - -print('\033[1mGetting name and value of error NO_SUCH_SITE\033[m') -print(repr(libgamma.name_of_error(libgamma.LIBGAMMA_NO_SUCH_SITE))) -print(repr(libgamma.value_of_error('LIBGAMMA_NO_SUCH_SITE'))) -print(libgamma.LIBGAMMA_NO_SUCH_SITE) -print() - -print('\033[1mCreating errors: 1, 0, -1 and -2\033[m') -print(libgamma.create_error(1)) -print(libgamma.create_error(0)) -print(libgamma.create_error(-1)) -print(libgamma.create_error(-2)) -print() - -print('\033[1mGetting partition count, crtc count for partition 0, and info for crtc 0.0\033[m') -site = libgamma.Site(method) -print(site.partitions_available) -partition = libgamma.Partition(site, 0) -print(partition.crtcs_available) -crtc = libgamma.CRTC(partition, 0) -info = crtc.information(~0)[0] -print(info.__dict__) -print() - -ramp_sizes = (info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size) -ramps = libgamma.GammaRamps(*ramp_sizes, depth = info.gamma_depth) -crtc.get_gamma(ramps) -print('\033[1mCurrent red gamma ramp\033[m') -print(list(ramps.red)) -print() -print('\033[1mCurrent green gamma ramp\033[m') -print(list(ramps.green)) -print() -print('\033[1mCurrent blue gamma ramp\033[m') -print(list(ramps.blue)) -print() - -saved_red = list(ramps.red) -saved_green = list(ramps.green) -saved_blue = list(ramps.blue) - -ramps.red[:] = list(map(lambda x : x // 2, saved_red)) -ramps.green[:] = list(map(lambda x : x // 2, saved_green)) -ramps.blue[:] = list(map(lambda x : x // 2, saved_blue)) - -crtc.set_gamma(ramps) - -sleep(1) - -ramps.red[:] = saved_red -ramps.green[:] = saved_green -ramps.blue[:] = saved_blue - -crtc.set_gamma(ramps) - -# If not done expressively, if in the root scope, -# we sometimes get ignored errors on exit -del site -del partition -del crtc -del ramps - |