aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-02 09:47:48 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-02 09:47:48 +0200
commit19241f627259fef20231a505230c19e63ae807a0 (patch)
treea91dba6b4808e754d63b34b12d287ee7e694f7d9
parentmisc (diff)
downloadpylibgamma-19241f627259fef20231a505230c19e63ae807a0.tar.gz
pylibgamma-19241f627259fef20231a505230c19e63ae807a0.tar.bz2
pylibgamma-19241f627259fef20231a505230c19e63ae807a0.tar.xz
fix misc errors + write test
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--src/include-libgamma.h19
-rw-r--r--src/libgamma_error.py72
-rw-r--r--src/libgamma_facade.py23
-rw-r--r--src/libgamma_method.py453
-rw-r--r--src/libgamma_native_error.pyx2
-rw-r--r--src/libgamma_native_facade.pyx12
-rw-r--r--src/libgamma_native_method.pyx56
-rwxr-xr-xsrc/test.py111
9 files changed, 509 insertions, 241 deletions
diff --git a/.gitignore b/.gitignore
index 1c52b5a..70874ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,9 @@ __pycache__/
*.o
*.out
*.su
+*.so
*.gch
*.py[co]
src/*_native_*.c
+src/c.c
diff --git a/src/include-libgamma.h b/src/include-libgamma.h
new file mode 100644
index 0000000..eb857e1
--- /dev/null
+++ b/src/include-libgamma.h
@@ -0,0 +1,19 @@
+/**
+ * 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_error.py b/src/libgamma_error.py
index 865d666..0012a21 100644
--- a/src/libgamma_error.py
+++ b/src/libgamma_error.py
@@ -19,71 +19,65 @@ along with this library. If not, see <http://www.gnu.org/licenses/>.
-class LibgammaGroupGid:
+class LibgammaGroup:
'''
- Data descriptor for accessing the
- `libgamma_group_gid` variable.
+ Class for `group`
'''
- def __init__(self):
- '''
- Constructor.
- '''
- pass
-
- def __get__(self, obj, obj_type = None) -> int:
+ @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()
- def __set__(self, obj, value : int):
+ @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
- return libgamma_native_set_group_gid(value)
-
-group_gid = LibgammaGroupGid()
-'''
-Group that the user needs to be a member of if
-`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned.
-'''
-
-
-class LibgammaGroupName:
- '''
- Data descriptor for accessing the
- `libgamma_group_name` variable.
- '''
+ libgamma_native_set_group_gid(value)
- def __init__(self):
- '''
- Constructor.
- '''
- pass
- def __get__(self, obj, obj_type = None) -> str:
+ @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()
- def __set__(self, obj, value : str):
+ @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
- return libgamma_native_set_group_name()
+ libgamma_native_set_group_name(value)
-group_name = LibgammaGroupName()
+
+group = LibgammaGroup()
'''
-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.
+ Group that the user needs to be a member of if
+`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned.
'''
@@ -262,7 +256,7 @@ 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
+`group.gid` (named by `group.name` (can be
`None`, if so `errno` may have been set to
tell why)) is required.
'''
diff --git a/src/libgamma_facade.py b/src/libgamma_facade.py
index 830a0b9..5920a5b 100644
--- a/src/libgamma_facade.py
+++ b/src/libgamma_facade.py
@@ -22,7 +22,7 @@ from libgamma_method import MethodCapabilities
-def list_methods(operation : int) -> list
+def list_methods(operation : int) -> list:
'''
List available adjustment methods by their order of preference based on the environment.
@@ -35,8 +35,8 @@ def list_methods(operation : int) -> list
Other values invoke undefined behaviour.
@return :list<int> A list of available adjustment methods.
'''
- from libgamma_native_method import libgamma_native_list_methods
- return libgamma_native_list_methods(method)
+ from libgamma_native_facade import libgamma_native_list_methods
+ return libgamma_native_list_methods(operation)
def is_method_available(method : int) -> bool:
@@ -47,7 +47,7 @@ def is_method_available(method : int) -> bool:
@param method The adjustment method.
@return Whether the adjustment method is available.
'''
- from libgamma_native_method import libgamma_native_is_method_available
+ from libgamma_native_facade import libgamma_native_is_method_available
return not libgamma_native_is_method_available(method) == 0
@@ -58,34 +58,35 @@ def method_capabilities(method : int) -> MethodCapabilities:
@param this The data structure to fill with the method's capabilities
@param method The adjustment method (display server and protocol).
'''
- from libgamma_native_method import libgamma_native_method_capabilities
+ from libgamma_native_facade import libgamma_native_method_capabilities
caps = libgamma_native_method_capabilities(method)
- MethodCapabilities(*caps)
+ return MethodCapabilities(*caps)
def method_default_site(method : int) -> str:
'''
- Return the capabilities of an adjustment method.
+ 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_method import libgamma_native_method_default_site
+ 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 capabilities of an adjustment method.
+ 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_method import libgamma_native_method_default_site_variable
+ from libgamma_native_facade import libgamma_native_method_default_site_variable
return libgamma_native_method_default_site_variable(method)
@@ -136,7 +137,7 @@ def unhex_edid(edid : str) -> bytes:
@return The EDID in raw representation.
'''
rc = []
- edid = edid.lowercase()
+ edid = edid.lower()
for i in range(0, len(edid), 2):
a, b = edid[i + 0], edid[i + 1]
a = '0123456789abcdef'.find(a) << 4
diff --git a/src/libgamma_method.py b/src/libgamma_method.py
index ffdf5f0..1c14049 100644
--- a/src/libgamma_method.py
+++ b/src/libgamma_method.py
@@ -548,7 +548,7 @@ The number of `LIBGAMMA_CRTC_INFO_*` values defined.
-LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID |
+LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID | \
LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID
'''
Macro for both `CRTCInformation` fields
@@ -557,8 +557,8 @@ 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_MACRO_EDID = LIBGAMMA_CRTC_INFO_EDID | \
+ LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT | \
LIBGAMMA_CRTC_INFO_GAMMA
'''
Macro for all `CRTCInformation` fields
@@ -567,7 +567,7 @@ support for reading the monitors' Extended Display
Information Data.
'''
-LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM |
+LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM | \
LIBGAMMA_CRTC_INFO_HEIGHT_MM
'''
Macro for both `CRTCInformation` fields
@@ -577,7 +577,7 @@ library having to parse the monitor's Extended Display
Information Data.
'''
-LIBGAMMA_CRTC_INFO_MACRO_RAMP = LIBGAMMA_CRTC_INFO_GAMMA_SIZE |
+LIBGAMMA_CRTC_INFO_MACRO_RAMP = LIBGAMMA_CRTC_INFO_GAMMA_SIZE | \
LIBGAMMA_CRTC_INFO_GAMMA_DEPTH
'''
Macro for the `CRTCInformation` fields
@@ -585,7 +585,7 @@ 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_MACRO_CONNECTOR = LIBGAMMA_CRTC_INFO_CONNECTOR_NAME | \
LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE
'''
Macro for the `CRTCInformation` fields
@@ -593,9 +593,9 @@ 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_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
@@ -609,6 +609,147 @@ 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):
'''
@@ -622,159 +763,110 @@ class GammaRamps:
if green_size is ...: green_size = red_size
if blue_size is ...: blue_size = green_size
- self.__depth = depth
- if depth not in (8, 16, 32, 64, -1, -2):
- raise ValueError('invalid gamma ramp depth')
+ 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 c
error = OSError()
error.errno = ramp_struct
error.strerror = c.strerror(error.errno)
raise error
- (self.__ramps, red, green, blue) = ramp_struct
+ (self._ramps, red, green, blue) = ramp_struct
- 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.
- '''
- 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 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))
-
- self.red = Ramp(red, red_size, depth)
- self.green = Ramp(green, green_size, depth)
- self.blue = Ramp(blue, blue_size, depth)
+ 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.
'''
- 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)
+ 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
@@ -784,7 +876,7 @@ class GammaRamps:
@return :(red:int, green:int, blue:int) The size of each individual ramp.
'''
- return (self.red.size, self.green.size, self.blue.size)
+ return (self._red.size, self._green.size, self._blue.size)
@size.setter
@@ -804,10 +896,10 @@ class GammaRamps:
@return :int The ramps' depth in bits and -1 for single precision floating
point and -2 for doublesingle precision floating point
'''
- return self.__depth
+ return self._depth
- @size.setter
+ @depth.setter
def depth(self, value):
'''
It is not possible to change this attribute, but a setter is
@@ -840,8 +932,8 @@ class 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:
+ (self._state, n) = libgamma_native_site_create(method, site)
+ if self._state == 0:
raise create_error(n)
self.partitions_available = n
self.method = method
@@ -853,7 +945,8 @@ class Site:
This function is called when the object is not longer in use.
'''
from libgamma_native_facade import libgamma_native_site_free
- libgamma_native_site_free(self.__state)
+ if not self._state == 0:
+ libgamma_native_site_free(self._state)
def restore(self):
@@ -861,7 +954,7 @@ class Site:
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)
+ r = libgamma_native_site_restore(self._state)
if not r == 0:
raise create_error(r)
@@ -892,8 +985,8 @@ class 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, partition)
- if self.__state == 0:
+ (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
@@ -905,7 +998,8 @@ class Partition:
This function is called when the object is not longer in use.
'''
from libgamma_native_facade import libgamma_native_partition_free
- libgamma_native_partition_free(self.__state)
+ if not self._state == 0:
+ libgamma_native_partition_free(self._state)
def restore(self):
@@ -913,7 +1007,7 @@ class Partition:
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)
+ r = libgamma_native_partition_restore(self._state)
if not r == 0:
raise create_error(r)
@@ -938,8 +1032,8 @@ class 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, crtc)
- if self.__state == 0:
+ (self._state, n) = libgamma_native_crtc_create(partition._state, crtc)
+ if self._state == 0:
raise create_error(n)
self.partition = partition
self.crtc = crtc
@@ -950,7 +1044,8 @@ class CRTC:
This function is called when the object is not longer in use.
'''
from libgamma_native_facade import libgamma_native_crtc_free
- libgamma_native_crtc_free(self.__state)
+ if not self._state == 0:
+ libgamma_native_crtc_free(self._state)
def restore(self):
@@ -958,12 +1053,12 @@ class CRTC:
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)
+ r = libgamma_native_crtc_restore(self._state)
if not r == 0:
raise create_error(r)
- def information(fields : int) -> tuple:
+ def information(self, fields : int) -> tuple:
'''
Read information about a CRTC.
@@ -973,38 +1068,50 @@ class CRTC:
whether no errors occurred.
'''
from libgamma_native_facade import libgamma_native_get_crtc_information
- (data, e) = libgamma_native_get_crtc_information(self.__state, fields)
+ (data, e) = libgamma_native_get_crtc_information(self._state, fields)
return (CRTCInformation(data), e == 0)
- def get_gamma(ramps : GammaRamps):
+ 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.
'''
- if ramps.depth == 8: r = libgamma_native_crtc_get_gamma_ramps8(self.__state, ramps.__ramp)
- elif ramps.depth == 16: r = libgamma_native_crtc_get_gamma_ramps16(self.__state, ramps.__ramp)
- elif ramps.depth == 32: r = libgamma_native_crtc_get_gamma_ramps32(self.__state, ramps.__ramp)
- elif ramps.depth == 64: r = libgamma_native_crtc_get_gamma_ramps64(self.__state, ramps.__ramp)
- elif ramps.depth == -1: r = libgamma_native_crtc_get_gamma_rampsf(self.__state, ramps.__ramp)
- elif ramps.depth == -2: r = libgamma_native_crtc_get_gamma_rampsd(self.__state, ramps.__ramp)
+ 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(ramps : GammaRamps):
+ def set_gamma(self, ramps : GammaRamps):
'''
Set gamma ramps for the CRTC.
@param ramps The gamma ramps to apply.
'''
- if ramps.depth == 8: r = libgamma_native_crtc_set_gamma_ramps8(self.__state, ramps.__ramp)
- elif ramps.depth == 16: r = libgamma_native_crtc_set_gamma_ramps16(self.__state, ramps.__ramp)
- elif ramps.depth == 32: r = libgamma_native_crtc_set_gamma_ramps32(self.__state, ramps.__ramp)
- elif ramps.depth == 64: r = libgamma_native_crtc_set_gamma_ramps64(self.__state, ramps.__ramp)
- elif ramps.depth == -1: r = libgamma_native_crtc_set_gamma_rampsf(self.__state, ramps.__ramp)
- elif ramps.depth == -2: r = libgamma_native_crtc_set_gamma_rampsd(self.__state, ramps.__ramp)
+ 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
index b10dc5a..d88f7fe 100644
--- a/src/libgamma_native_error.pyx
+++ b/src/libgamma_native_error.pyx
@@ -93,6 +93,7 @@ def libgamma_native_set_group_gid(gid : int):
Group that the user needs to be a member of if
`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned.
'''
+ global libgamma_group_gid
libgamma_group_gid = <int>gid
@@ -120,6 +121,7 @@ def libgamma_native_set_group_name(name : str):
`None` if the name of the group `libgamma_group_gid`
cannot be determined.
'''
+ global libgamma_group_name
cdef bytes bs
if name is None:
libgamma_group_name = <char*>NULL
diff --git a/src/libgamma_native_facade.pyx b/src/libgamma_native_facade.pyx
index 41ab169..48bec73 100644
--- a/src/libgamma_native_facade.pyx
+++ b/src/libgamma_native_facade.pyx
@@ -29,7 +29,7 @@ ctypedef int libgamma_subpixel_order_t
ctypedef int libgamma_connector_type_t
-cdef extern from "libgamma/libgamma-method.h":
+cdef extern from "include-libgamma.h":
ctypedef struct libgamma_method_capabilities_t:
# Capabilities of adjustment methods.
@@ -490,7 +490,7 @@ Return the capabilities of an adjustment method.
cdef extern char* libgamma_method_default_site(int method)
'''
-Return the capabilities of an adjustment method.
+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
@@ -501,7 +501,8 @@ Return the capabilities of an adjustment method.
cdef extern const char* libgamma_method_default_site_variable(int method)
'''
-Return the capabilities of an adjustment method.
+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
@@ -846,7 +847,7 @@ def libgamma_native_method_capabilities(method : int) -> tuple:
def libgamma_native_method_default_site(method : int) -> str:
'''
- Return the capabilities of an adjustment method.
+ 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
@@ -862,7 +863,8 @@ def libgamma_native_method_default_site(method : int) -> str:
def libgamma_native_method_default_site_variable(method : int) -> str:
'''
- Return the capabilities of an adjustment method.
+ 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
diff --git a/src/libgamma_native_method.pyx b/src/libgamma_native_method.pyx
index 58ab1a3..0fd27ec 100644
--- a/src/libgamma_native_method.pyx
+++ b/src/libgamma_native_method.pyx
@@ -25,7 +25,7 @@ from libc.stddef cimport size_t
from libc.errno cimport errno
-cdef extern from "libgamma/libgamma-method.h":
+cdef extern from "include-libgamma.h":
ctypedef struct libgamma_gamma_ramps8_t:
# Gamma ramp structure for 8-bit gamma ramps.
size_t red_size
@@ -274,11 +274,16 @@ def libgamma_native_gamma_ramps8_create(red_size : int, green_size : int, blue_s
cdef libgamma_gamma_ramps8_t* item = <libgamma_gamma_ramps8_t*>allocation
cdef size_t red, green, blue
if item is NULL:
- return errno
+ 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(blue), int(blue))
+ return (int(<size_t>allocation), int(red), int(green), int(blue))
def libgamma_native_gamma_ramps8_free(this : int):
@@ -340,11 +345,16 @@ def libgamma_native_gamma_ramps16_create(red_size : int, green_size : int, blue_
cdef libgamma_gamma_ramps16_t* item = <libgamma_gamma_ramps16_t*>allocation
cdef size_t red, green, blue
if item is NULL:
- return errno
+ 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(blue), int(blue))
+ return (int(<size_t>allocation), int(red), int(green), int(blue))
def libgamma_native_gamma_ramps16_free(this : int):
@@ -406,11 +416,16 @@ def libgamma_native_gamma_ramps32_create(red_size : int, green_size : int, blue_
cdef libgamma_gamma_ramps32_t* item = <libgamma_gamma_ramps32_t*>allocation
cdef size_t red, green, blue
if item is NULL:
- return errno
+ 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(blue), int(blue))
+ return (int(<size_t>allocation), int(red), int(green), int(blue))
def libgamma_native_gamma_ramps32_free(this : int):
@@ -472,11 +487,16 @@ def libgamma_native_gamma_ramps64_create(red_size : int, green_size : int, blue_
cdef libgamma_gamma_ramps64_t* item = <libgamma_gamma_ramps64_t*>allocation
cdef size_t red, green, blue
if item is NULL:
- return errno
+ 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(blue), int(blue))
+ return (int(<size_t>allocation), int(red), int(green), int(blue))
def libgamma_native_gamma_ramps64_free(this : int):
@@ -538,11 +558,16 @@ def libgamma_native_gamma_rampsf_create(red_size : int, green_size : int, blue_s
cdef libgamma_gamma_rampsf_t* item = <libgamma_gamma_rampsf_t*>allocation
cdef size_t red, green, blue
if item is NULL:
- return errno
+ 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(blue), int(blue))
+ return (int(<size_t>allocation), int(red), int(green), int(blue))
def libgamma_native_gamma_rampsf_free(this : int):
@@ -604,11 +629,16 @@ def libgamma_native_gamma_rampsd_create(red_size : int, green_size : int, blue_s
cdef libgamma_gamma_rampsd_t* item = <libgamma_gamma_rampsd_t*>allocation
cdef size_t red, green, blue
if item is NULL:
- return errno
+ 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(blue), int(blue))
+ return (int(<size_t>allocation), int(red), int(green), int(blue))
def libgamma_native_gamma_rampsd_free(this : int):
diff --git a/src/test.py b/src/test.py
new file mode 100755
index 0000000..ca70072
--- /dev/null
+++ b/src/test.py
@@ -0,0 +1,111 @@
+#!/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(libgamma.method_capabilities(method).__dict__)
+print()
+
+print(repr(libgamma.method_default_site_variable(method)))
+print(repr(libgamma.method_default_site(method)))
+print
+
+print(repr(libgamma.unhex_edid('0123456789ABCDEF')))
+print(repr(libgamma.unhex_edid('0123456789abcdef')))
+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(libgamma.group.gid)
+libgamma.group.gid = 10
+print(libgamma.group.gid)
+print()
+
+print(repr(libgamma.group.name))
+libgamma.group.name = 'group'
+print(repr(libgamma.group.name))
+print()
+
+libgamma.perror('test', 0)
+libgamma.perror('test', libgamma.LIBGAMMA_ERRNO_SET)
+libgamma.perror('test', libgamma.LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD)
+print()
+
+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(libgamma.create_error(1))
+print(libgamma.create_error(0))
+print(libgamma.create_error(-1))
+print(libgamma.create_error(-2))
+print()
+
+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(list(ramps.red))
+print()
+print(list(ramps.green))
+print()
+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
+