aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile13
-rw-r--r--libgamma-error.cc238
-rw-r--r--libgamma-error.hh304
-rw-r--r--libgamma-facade.cc881
-rw-r--r--libgamma-facade.hh291
-rw-r--r--libgamma-method.cc1013
-rw-r--r--libgamma-method.hh1932
-rw-r--r--libgamma-native.hh3
-rw-r--r--libgamma.hh3
-rw-r--r--test.cc585
10 files changed, 2594 insertions, 2669 deletions
diff --git a/Makefile b/Makefile
index db413a0..e7e588d 100644
--- a/Makefile
+++ b/Makefile
@@ -13,11 +13,14 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
LIB_NAME = gammamm
-HDR =\
+LIBHDR =\
libgamma.hh\
libgamma-error.hh\
libgamma-facade.hh\
- libgamma-method.hh\
+ libgamma-method.hh
+
+HDR =\
+ $(LIBHDR)\
libgamma-native.hh
OBJ =\
@@ -31,7 +34,7 @@ LOBJ = $(OBJ:.o=.lo)
all: libgammamm.a libgammamm.$(LIBEXT)
$(OBJ): $(HDR)
$(LOBJ): $(HDR)
-test.o: test.cc $(HDR)
+test.o: test.cc $(LIBHDR)
libgammamm.a: $(OBJ)
@rm -f -- $@
@@ -59,7 +62,7 @@ install: libgammamm.a libgammamm.$(LIBEXT)
$(FIX_INSTALL_NAME) "$(DESTDIR)$(PREFIX)/lib/libgammamm.$(LIBMINOREXT)"
ln -sf -- libgammamm.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libgammamm.$(LIBMAJOREXT)"
ln -sf -- libgammamm.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libgammamm.$(LIBEXT)"
- cp -- $(HDR) "$(DESTDIR)$(PREFIX)/include/"
+ cp -- $(LIBHDR) "$(DESTDIR)$(PREFIX)/include/"
uninstall:
mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
@@ -68,7 +71,7 @@ uninstall:
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libgammamm.$(LIBMINOREXT)"
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libgammamm.$(LIBMAJOREXT)"
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libgammamm.$(LIBEXT)"
- -cd "$(DESTDIR)$(PREFIX)/include/" && rm -f -- $(HDR)
+ -cd "$(DESTDIR)$(PREFIX)/include/" && rm -f -- $(LIBHDR)
-rm -- "$(DESTDIR)$(PKGCONFIGDIR)/libgammamm.pc"
run-test:
diff --git a/libgamma-error.cc b/libgamma-error.cc
index db66bbe..f7cb5ee 100644
--- a/libgamma-error.cc
+++ b/libgamma-error.cc
@@ -1,134 +1,134 @@
/* See LICENSE file for copyright and license details. */
#include "libgamma-error.hh"
-
-#include <iostream>
#include <cstring>
+#include <iostream>
namespace libgamma
{
- /**
- * 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.
- */
- void perror(const std::string name, int error_code)
- {
- libgamma_perror(name.c_str(), error_code);
- }
-
- /**
- * Returns the name of the definition associated with a `nullptr` error code.
- *
- * @param value The error code.
- * @return The name of the definition associated with the error code,
- * `nullptr` if the error code does not exist.
- */
- std::string* name_of_error(int value)
- {
- const char* cstr = libgamma_name_of_error(value);
- if (cstr == nullptr)
- return nullptr;
- return new std::string(cstr);
- }
-
- /**
- * 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 `nullptr`
- * or does not refer to a `libgamma` error.
- */
- int value_of_error(const std::string* name)
- {
- const char* cstr = nullptr;
- if (name != nullptr)
- cstr = name->c_str();
- return libgamma_value_of_error(cstr);
- }
-
+ /**
+ * 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
+ */
+ void
+ perror(const std::string name, int error_code)
+ {
+ libgamma_perror(name.c_str(), error_code);
+ }
+
+ /**
+ * Returns the name of the definition associated with a `nullptr` error code
+ *
+ * @param value The error code
+ * @return The name of the definition associated with the error code,
+ * `nullptr` if the error code does not exist
+ */
+ std::string *
+ name_of_error(int value)
+ {
+ const char *cstr = libgamma_name_of_error(value);
+ if (cstr == nullptr)
+ return nullptr;
+ return new std::string(cstr);
+ }
-#ifdef __GNUC__
+ /**
+ * 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 `nullptr`
+ * or does not refer to a `libgamma` error
+ */
+ int
+ value_of_error(const std::string* name)
+ {
+ const char *cstr = nullptr;
+ if (name != nullptr)
+ cstr = name->c_str();
+ return libgamma_value_of_error(cstr);
+ }
+
+
+#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wshadow"
#endif
- /**
- * Constructor.
- *
- * @param error_code The error code.
- */
- LibgammaException::LibgammaException(int error_code) throw() :
- error_code(error_code)
- {
- /* Do nothing. */
- }
-
- /**
- * Destructor.
- */
- LibgammaException::~LibgammaException() throw()
- {
- /* Do nothing. */
- }
-
- /**
- * Get the error as a string.
- */
- const char* LibgammaException::what() const throw()
- {
- if (this->error_code < 0)
- return libgamma_name_of_error(this->error_code);
- else
- return strerror(this->error_code);
- }
-
-#ifdef __GNUC__
+ /**
+ * Constructor
+ *
+ * @param error_code The error code
+ */
+ LibgammaException::LibgammaException(int error_code) throw() : error_code(error_code)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Destructor
+ */
+ LibgammaException::~LibgammaException() throw()
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Get the error as a string
+ */
+ const char *
+ LibgammaException::what() const throw()
+ {
+ if (this->error_code < 0)
+ return libgamma_name_of_error(this->error_code);
+ else
+ return strerror(this->error_code);
+ }
+
+#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
-
-
- /**
- * Create an exception from an error code
- * that may come from `errno.h` or be a
- * `libgamma` error code.
- *
- * @param error_code The error code.
- * @return The error object.
- */
- LibgammaException create_error(int error_code)
- {
- if (error_code == LIBGAMMA_ERRNO_SET)
- error_code = errno;
- return LibgammaException(error_code);
- }
-
-
- /**
- * Group that the user needs to be a member of if
- * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned.
- */
- GroupGid group_gid;
-
- /**
- * Group that the user needs to be a member of if
- * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned,
- * `nullptr` if the name of the group
- * `libgamma::group_gid` cannot be determined.
- */
- GroupName group_name;
-
-}
+
+ /**
+ * Create an exception from an error code
+ * that may come from `errno.h` or be a
+ * `libgamma` error code
+ *
+ * @param error_code The error code
+ * @return The error object
+ */
+ LibgammaException create_error(int error_code)
+ {
+ if (error_code == LIBGAMMA_ERRNO_SET)
+ error_code = errno;
+ return LibgammaException(error_code);
+ }
+
+
+ /**
+ * Group that the user needs to be a member of if
+ * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned
+ */
+ GroupGid group_gid;
+
+ /**
+ * Group that the user needs to be a member of if
+ * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned,
+ * `nullptr` if the name of the group
+ * `libgamma::group_gid` cannot be determined
+ */
+ GroupName group_name;
+}
diff --git a/libgamma-error.hh b/libgamma-error.hh
index 5f65e86..ec252c7 100644
--- a/libgamma-error.hh
+++ b/libgamma-error.hh
@@ -2,176 +2,170 @@
#ifndef LIBGAMMA_ERROR_HH
#define LIBGAMMA_ERROR_HH
-
-#include <string>
#include <exception>
+#include <string>
#include "libgamma-native.hh"
-#ifndef __GNUC__
-# define __attribute__(X) /* emtpy */
+#if defined(__GNUC__)
+# define LIBGAMMAMM_PURE__ __attribute__((__pure__))
+#else
+# define LIBGAMMAMM_PURE__
#endif
-#ifndef __WIN32__
-# define libgamma_gid_t gid_t
+#if !defined(__WIN32__)
+# define libgamma_gid_t gid_t
#else
-# define libgamma_gid_t short
+# define libgamma_gid_t short
#endif
-
namespace libgamma
{
- /**
- * Class for `group_gid`.
- */
- class GroupGid;
-
- /**
- * Class for `group_name`.
- */
- class GroupName;
-
-
- /**
- * 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.
- */
- void perror(const std::string name, int error_code);
-
- /**
- * Returns the name of the definition associated with a `nullptr` error code.
- *
- * @param value The error code.
- * @return The name of the definition associated with the error code,
- * `nullptr` if the error code does not exist.
- */
- std::string* name_of_error(int value);
-
- /**
- * 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 `nullptr`
- * or does not refer to a `libgamma` error.
- */
- int value_of_error(const std::string* name) __attribute__((pure));
-
-
- /**
- * Class for `group_gid`.
- */
- class GroupGid
- {
- public:
- const GroupGid& operator =(const libgamma_gid_t& value) const
- {
- libgamma_group_gid = value;
- return *this;
- }
-
- operator libgamma_gid_t() const
- {
- return libgamma_group_gid;
- }
- };
-
- /**
- * Group that the user needs to be a member of if
- * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned.
- */
- extern GroupGid group_gid;
-
-
- /**
- * Class for `group_name`.
- */
- class GroupName
- {
- public:
- const GroupName& operator =(const char* value) const
- {
- libgamma_group_name = value;
- return *this;
- }
-
- operator const char*() const
- {
- return libgamma_group_name;
- }
- };
-
- /**
- * Group that the user needs to be a member of if
- * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned,
- * `nullptr` if the name of the group
- * `libgamma::group_gid` cannot be determined.
- */
- extern GroupName group_name;
-
-
- /**
- * Libgamma exception class.
- */
- class LibgammaException : public std::exception
- {
- public:
- /**
- * Constructor.
- *
- * @param error_code The error code.
- */
- LibgammaException(int error_code) throw();
-
- /**
- * Destructor.
- */
- virtual ~LibgammaException() throw();
-
- /**
- * Get the error as a string.
- */
- virtual const char* what() const throw();
-
- /**
- * The error code.
- */
- int error_code;
-
- };
-
-
- /**
- * Create an exception from an error code
- * that may come from `errno.h` or be a
- * `libgamma` error code.
- *
- * @param error_code The error code.
- * @return The error object.
- */
- LibgammaException create_error(int error_code);
-
-}
+ /**
+ * Class for `group_gid`
+ */
+ class GroupGid;
+ /**
+ * Class for `group_name`
+ */
+ class GroupName;
-#ifndef __GNUC__
-# undef __attribute__
-#endif
-#endif
+ /**
+ * 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
+ */
+ void perror(const std::string name, int error_code);
+
+ /**
+ * Returns the name of the definition associated with a `nullptr` error code
+ *
+ * @param value The error code
+ * @return The name of the definition associated with the error code,
+ * `nullptr` if the error code does not exist
+ */
+ std::string *name_of_error(int value);
+
+ /**
+ * 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 `nullptr`
+ * or does not refer to a `libgamma` error
+ */
+ LIBGAMMAMM_PURE__ int value_of_error(const std::string *name);
+
+
+ /**
+ * Class for `group_gid`
+ */
+ class GroupGid
+ {
+ public:
+ const GroupGid &
+ operator =(const libgamma_gid_t &value) const
+ {
+ libgamma_group_gid = value;
+ return *this;
+ }
+
+ operator libgamma_gid_t() const
+ {
+ return libgamma_group_gid;
+ }
+ };
+
+ /**
+ * Group that the user needs to be a member of if
+ * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned
+ */
+ extern GroupGid group_gid;
+
+ /**
+ * Class for `group_name`
+ */
+ class GroupName
+ {
+ public:
+ const GroupName &
+ operator =(const char *value) const
+ {
+ libgamma_group_name = value;
+ return *this;
+ }
+
+ operator const char *() const
+ {
+ return libgamma_group_name;
+ }
+ };
+
+ /**
+ * Group that the user needs to be a member of if
+ * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned,
+ * `nullptr` if the name of the group
+ * `libgamma::group_gid` cannot be determined
+ */
+ extern GroupName group_name;
+
+
+ /**
+ * Libgamma exception class
+ */
+ class LibgammaException : public std::exception
+ {
+ public:
+ /**
+ * Constructor
+ *
+ * @param error_code The error code
+ */
+ LibgammaException(int error_code) throw();
+
+ /**
+ * Destructor
+ */
+ virtual ~LibgammaException() throw();
+
+ /**
+ * Get the error as a string
+ */
+ virtual const char *what() const throw();
+
+ /**
+ * The error code
+ */
+ int error_code;
+ };
+
+
+ /**
+ * Create an exception from an error code
+ * that may come from `errno.h` or be a
+ * `libgamma` error code
+ *
+ * @param error_code The error code
+ * @return The error object
+ */
+ LibgammaException create_error(int error_code);
+}
+
+#endif
diff --git a/libgamma-facade.cc b/libgamma-facade.cc
index 9d74d6f..dfb07f3 100644
--- a/libgamma-facade.cc
+++ b/libgamma-facade.cc
@@ -1,443 +1,456 @@
/* See LICENSE file for copyright and license details. */
#include "libgamma-facade.hh"
-
#include "libgamma-error.hh"
-
#include <cstdlib>
namespace libgamma
{
- /**
- * 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 Array of methods.
- */
- std::vector<int> list_methods(int operation)
- {
- int* methods = (int*)malloc(LIBGAMMA_METHOD_COUNT * sizeof(int));
- size_t n, i;
- std::vector<int> rc;
-
- n = libgamma_list_methods(methods, LIBGAMMA_METHOD_COUNT, operation);
- if (n > LIBGAMMA_METHOD_COUNT)
- {
- free(methods);
- methods = (int*)malloc(n * sizeof(int));
- libgamma_list_methods(methods, n, operation);
- }
-
- for (i = 0; i < n; i++)
- rc.push_back(methods[i]);
-
- free(methods);
- return rc;
- }
-
- /**
- * 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.
- */
- int is_method_available(int method)
- {
- return libgamma_is_method_available(method);
- }
-
- /**
- * Return the capabilities of an adjustment method.
- *
- * @param output The data structure to fill with the method's capabilities,
- * @param method The adjustment method (display server and protocol).
- */
- void method_capabilities(MethodCapabilities* output, int method)
- {
- libgamma_method_capabilities_t caps;
- libgamma_method_capabilities(&caps, method);
- *output = MethodCapabilities(&caps);
- }
-
- /**
- * Return the default site for an adjustment method.
- *
- * @param method The adjustment method (display server and protocol.)
- * @return The default site, `nullptr` if it cannot be determined or if
- * multiple sites are not supported by the adjustment method.
- */
- std::string* method_default_site(int method)
- {
- char* cstr = libgamma_method_default_site(method);
- if (cstr == nullptr)
- return nullptr;
- return new std::string(cstr);
- }
-
- /**
- * 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. `nullptr` if there is none, that is, if
- * the method does not support multiple sites.
- * This value should not be `free`:d.
- */
- std::string* method_default_site_variable(int method)
- {
- const char* cstr = libgamma_method_default_site_variable(method);
- if (cstr == nullptr)
- return nullptr;
- return new std::string(cstr);
- }
-
-
- /**
- * Convert a raw representation of an EDID to a lowercase hexadecimal representation.
- *
- * @param edid The EDID in raw representation.
- * @param length The length of `edid`.
- * @return The EDID in lowercase hexadecimal representation.
- */
- std::string behex_edid(const unsigned char* edid, size_t length)
- {
- return behex_edid_lowercase(edid, length);
- }
-
- /**
- * Convert a raw representation of an EDID to a lowercase hexadecimal representation.
- *
- * @param edid The EDID in raw representation.
- * @param length The length of `edid`.
- * @return The EDID in lowercase hexadecimal representation.
- */
- std::string behex_edid_lowercase(const unsigned char* edid, size_t length)
- {
- char* cstr = libgamma_behex_edid_lowercase(edid, length);
- std::string rc = std::string(cstr);
- free(cstr);
- return rc;
- }
-
- /**
- * Convert a raw representation of an EDID to an uppercase hexadecimal representation.
- *
- * @param edid The EDID in raw representation.
- * @param length The length of `edid`.
- * @return The EDID in uppercase hexadecimal representation.
- */
- std::string behex_edid_uppercase(const unsigned char* edid, size_t length)
- {
- char* cstr = libgamma_behex_edid_uppercase(edid, length);
- std::string rc = std::string(cstr);
- free(cstr);
- return rc;
- }
-
- /**
- * Convert an hexadecimal representation of an EDID to a raw representation.
- *
- * @param edid The EDID in hexadecimal representation.
- * @return The EDID in raw representation, it will be half the length
- * of `edid` (the input value).
- */
- unsigned char* unhex_edid(const std::string edid)
- {
- const char* cstr = edid.c_str();
- return libgamma_unhex_edid(cstr);
- }
-
-
- /**
- * Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
- *
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- */
- void gamma_ramps8_initialise(GammaRamps<uint8_t>* ramps, size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps8_t native;
- int r;
- native.red_size = ramps->red.size = red;
- native.green_size = ramps->green.size = green;
- native.blue_size = ramps->blue.size = blue;
- ramps->depth = 8;
- r = libgamma_gamma_ramps8_initialise(&native);
- if (r != 0)
- throw create_error(r);
- ramps->red.ramp = native.red;
- ramps->green.ramp = native.green;
- ramps->blue.ramp = native.blue;
- }
-
- /**
- * Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
- *
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- */
- void gamma_ramps16_initialise(GammaRamps<uint16_t>* ramps, size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps16_t native;
- int r;
- native.red_size = ramps->red.size = red;
- native.green_size = ramps->green.size = green;
- native.blue_size = ramps->blue.size = blue;
- ramps->depth = 16;
- r = libgamma_gamma_ramps16_initialise(&native);
- if (r != 0)
- throw create_error(r);
- ramps->red.ramp = native.red;
- ramps->green.ramp = native.green;
- ramps->blue.ramp = native.blue;
- }
-
- /**
- * Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
- *
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- */
- void gamma_ramps32_initialise(GammaRamps<uint32_t>* ramps, size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps32_t native;
- int r;
- native.red_size = ramps->red.size = red;
- native.green_size = ramps->green.size = green;
- native.blue_size = ramps->blue.size = blue;
- ramps->depth = 32;
- r = libgamma_gamma_ramps32_initialise(&native);
- if (r != 0)
- throw create_error(r);
- ramps->red.ramp = native.red;
- ramps->green.ramp = native.green;
- ramps->blue.ramp = native.blue;
- }
-
- /**
- * Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
- *
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- */
- void gamma_ramps64_initialise(GammaRamps<uint64_t>* ramps, size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps64_t native;
- int r;
- native.red_size = ramps->red.size = red;
- native.green_size = ramps->green.size = green;
- native.blue_size = ramps->blue.size = blue;
- ramps->depth = 64;
- r = libgamma_gamma_ramps64_initialise(&native);
- if (r != 0)
- throw create_error(r);
- ramps->red.ramp = native.red;
- ramps->green.ramp = native.green;
- ramps->blue.ramp = native.blue;
- }
-
- /**
- * Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
- *
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- */
- void gamma_rampsf_initialise(GammaRamps<float>* ramps, size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_rampsf_t native;
- int r;
- native.red_size = ramps->red.size = red;
- native.green_size = ramps->green.size = green;
- native.blue_size = ramps->blue.size = blue;
- ramps->depth = -1;
- r = libgamma_gamma_rampsf_initialise(&native);
- if (r != 0)
- throw create_error(r);
- ramps->red.ramp = native.red;
- ramps->green.ramp = native.green;
- ramps->blue.ramp = native.blue;
- }
-
- /**
- * Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
- *
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- */
- void gamma_rampsd_initialise(GammaRamps<double>* ramps, size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_rampsd_t native;
- int r;
- native.red_size = ramps->red.size = red;
- native.green_size = ramps->green.size = green;
- native.blue_size = ramps->blue.size = blue;
- ramps->depth = -2;
- r = libgamma_gamma_rampsd_initialise(&native);
- if (r != 0)
- throw create_error(r);
- ramps->red.ramp = native.red;
- ramps->green.ramp = native.green;
- ramps->blue.ramp = native.blue;
- }
-
-
- /**
- * 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 The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
- */
- GammaRamps<uint8_t>* gamma_ramps8_create(size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps8_t ramps;
- int r;
- ramps.red_size = red;
- ramps.green_size = green;
- ramps.blue_size = blue;
- r = libgamma_gamma_ramps8_initialise(&ramps);
- if (r != 0)
- throw create_error(r);
- return new GammaRamps<uint8_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 8);
- }
-
- /**
- * 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 The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
- */
- GammaRamps<uint16_t>* gamma_ramps16_create(size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps16_t ramps;
- int r;
- ramps.red_size = red;
- ramps.green_size = green;
- ramps.blue_size = blue;
- r = libgamma_gamma_ramps16_initialise(&ramps);
- if (r != 0)
- throw create_error(r);
- return new GammaRamps<uint16_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 16);
- }
-
- /**
- * 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 The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
- */
- GammaRamps<uint32_t>* gamma_ramps32_create(size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps32_t ramps;
- int r;
- ramps.red_size = red;
- ramps.green_size = green;
- ramps.blue_size = blue;
- r = libgamma_gamma_ramps32_initialise(&ramps);
- if (r != 0)
- throw create_error(r);
- return new GammaRamps<uint32_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 32);
- }
-
- /**
- * 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 The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
- */
- GammaRamps<uint64_t>* gamma_ramps64_create(size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_ramps64_t ramps;
- int r;
- ramps.red_size = red;
- ramps.green_size = green;
- ramps.blue_size = blue;
- r = libgamma_gamma_ramps64_initialise(&ramps);
- if (r != 0)
- throw create_error(r);
- return new GammaRamps<uint64_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 64);
- }
-
- /**
- * 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 The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
- */
- GammaRamps<float>* gamma_rampsf_create(size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_rampsf_t ramps;
- int r;
- ramps.red_size = red;
- ramps.green_size = green;
- ramps.blue_size = blue;
- r = libgamma_gamma_rampsf_initialise(&ramps);
- if (r != 0)
- throw create_error(r);
- return new GammaRamps<float>(ramps.red, ramps.green, ramps.blue, red, green, blue, -1);
- }
-
- /**
- * 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 The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
- */
- GammaRamps<double>* gamma_rampsd_create(size_t red, size_t blue, size_t green)
- {
- libgamma_gamma_rampsd_t ramps;
- int r;
- ramps.red_size = red;
- ramps.green_size = green;
- ramps.blue_size = blue;
- r = libgamma_gamma_rampsd_initialise(&ramps);
- if (r != 0)
- throw create_error(r);
- return new GammaRamps<double>(ramps.red, ramps.green, ramps.blue, red, green, blue, -2);
- }
-
-}
+ /**
+ * 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 Array of methods
+ */
+ std::vector<int>
+ list_methods(int operation)
+ {
+ int *methods = (int*)malloc(LIBGAMMA_METHOD_COUNT * sizeof(int));
+ size_t n, i;
+ std::vector<int> rc;
+
+ n = libgamma_list_methods(methods, LIBGAMMA_METHOD_COUNT, operation);
+ if (n > LIBGAMMA_METHOD_COUNT) {
+ free(methods);
+ methods = (int*)malloc(n * sizeof(int));
+ libgamma_list_methods(methods, n, operation);
+ }
+
+ for (i = 0; i < n; i++)
+ rc.push_back(methods[i]);
+
+ free(methods);
+ return rc;
+ }
+
+ /**
+ * 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
+ */
+ int
+ is_method_available(int method)
+ {
+ return libgamma_is_method_available(method);
+ }
+
+ /**
+ * Return the capabilities of an adjustment method
+ *
+ * @param output The data structure to fill with the method's capabilities
+ * @param method The adjustment method (display server and protocol)
+ */
+ void
+ method_capabilities(MethodCapabilities *output, int method)
+ {
+ libgamma_method_capabilities_t caps;
+ libgamma_method_capabilities(&caps, method);
+ *output = MethodCapabilities(&caps);
+ }
+
+ /**
+ * Return the default site for an adjustment method
+ *
+ * @param method The adjustment method (display server and protocol)
+ * @return The default site, `nullptr` if it cannot be determined or if
+ * multiple sites are not supported by the adjustment method
+ */
+ std::string *
+ method_default_site(int method)
+ {
+ char *cstr = libgamma_method_default_site(method);
+ if (cstr == nullptr)
+ return nullptr;
+ return new std::string(cstr);
+ }
+
+ /**
+ * 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. `nullptr` if there is none, that is, if
+ * the method does not support multiple sites.
+ * This value should not be `free`:d.
+ */
+ std::string *
+ method_default_site_variable(int method)
+ {
+ const char *cstr = libgamma_method_default_site_variable(method);
+ if (cstr == nullptr)
+ return nullptr;
+ return new std::string(cstr);
+ }
+
+ /**
+ * Convert a raw representation of an EDID to a lowercase hexadecimal representation
+ *
+ * @param edid The EDID in raw representation
+ * @param length The length of `edid`
+ * @return The EDID in lowercase hexadecimal representation
+ */
+ std::string
+ behex_edid(const unsigned char *edid, size_t length)
+ {
+ return behex_edid_lowercase(edid, length);
+ }
+
+ /**
+ * Convert a raw representation of an EDID to a lowercase hexadecimal representation
+ *
+ * @param edid The EDID in raw representation
+ * @param length The length of `edid`
+ * @return The EDID in lowercase hexadecimal representation
+ */
+ std::string
+ behex_edid_lowercase(const unsigned char *edid, size_t length)
+ {
+ char *cstr = libgamma_behex_edid_lowercase(edid, length);
+ std::string rc = std::string(cstr);
+ free(cstr);
+ return rc;
+ }
+
+ /**
+ * Convert a raw representation of an EDID to an uppercase hexadecimal representation
+ *
+ * @param edid The EDID in raw representation
+ * @param length The length of `edid`
+ * @return The EDID in uppercase hexadecimal representation
+ */
+ std::string
+ behex_edid_uppercase(const unsigned char *edid, size_t length)
+ {
+ char *cstr = libgamma_behex_edid_uppercase(edid, length);
+ std::string rc = std::string(cstr);
+ free(cstr);
+ return rc;
+ }
+ /**
+ * Convert an hexadecimal representation of an EDID to a raw representation
+ *
+ * @param edid The EDID in hexadecimal representation
+ * @return The EDID in raw representation, it will be half the length
+ * of `edid` (the input value)
+ */
+ unsigned char *
+ unhex_edid(const std::string edid)
+ {
+ const char *cstr = edid.c_str();
+ return libgamma_unhex_edid(cstr);
+ }
+
+ /**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ */
+ void
+ gamma_ramps8_initialise(GammaRamps<uint8_t> *ramps, size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps8_t native;
+ int r;
+ native.red_size = ramps->red.size = red;
+ native.green_size = ramps->green.size = green;
+ native.blue_size = ramps->blue.size = blue;
+ ramps->depth = 8;
+ r = libgamma_gamma_ramps8_initialise(&native);
+ if (r)
+ throw create_error(r);
+ ramps->red.ramp = native.red;
+ ramps->green.ramp = native.green;
+ ramps->blue.ramp = native.blue;
+ }
+
+ /**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ */
+ void
+ gamma_ramps16_initialise(GammaRamps<uint16_t> *ramps, size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps16_t native;
+ int r;
+ native.red_size = ramps->red.size = red;
+ native.green_size = ramps->green.size = green;
+ native.blue_size = ramps->blue.size = blue;
+ ramps->depth = 16;
+ r = libgamma_gamma_ramps16_initialise(&native);
+ if (r)
+ throw create_error(r);
+ ramps->red.ramp = native.red;
+ ramps->green.ramp = native.green;
+ ramps->blue.ramp = native.blue;
+ }
+
+ /**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ */
+ void
+ gamma_ramps32_initialise(GammaRamps<uint32_t> *ramps, size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps32_t native;
+ int r;
+ native.red_size = ramps->red.size = red;
+ native.green_size = ramps->green.size = green;
+ native.blue_size = ramps->blue.size = blue;
+ ramps->depth = 32;
+ r = libgamma_gamma_ramps32_initialise(&native);
+ if (r)
+ throw create_error(r);
+ ramps->red.ramp = native.red;
+ ramps->green.ramp = native.green;
+ ramps->blue.ramp = native.blue;
+ }
+
+ /**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ */
+ void
+ gamma_ramps64_initialise(GammaRamps<uint64_t> *ramps, size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps64_t native;
+ int r;
+ native.red_size = ramps->red.size = red;
+ native.green_size = ramps->green.size = green;
+ native.blue_size = ramps->blue.size = blue;
+ ramps->depth = 64;
+ r = libgamma_gamma_ramps64_initialise(&native);
+ if (r)
+ throw create_error(r);
+ ramps->red.ramp = native.red;
+ ramps->green.ramp = native.green;
+ ramps->blue.ramp = native.blue;
+ }
+
+ /**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation.
+ *
+ * @param ramps The gamma ramp to initialise.
+ * @param red The size of the gamma ramp for the red channel.
+ * @param green The size of the gamma ramp for the green channel.
+ * @param blue The size of the gamma ramp for the blue channel.
+ */
+ void
+ gamma_rampsf_initialise(GammaRamps<float> *ramps, size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_rampsf_t native;
+ int r;
+ native.red_size = ramps->red.size = red;
+ native.green_size = ramps->green.size = green;
+ native.blue_size = ramps->blue.size = blue;
+ ramps->depth = -1;
+ r = libgamma_gamma_rampsf_initialise(&native);
+ if (r)
+ throw create_error(r);
+ ramps->red.ramp = native.red;
+ ramps->green.ramp = native.green;
+ ramps->blue.ramp = native.blue;
+ }
+
+ /**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ */
+ void
+ gamma_rampsd_initialise(GammaRamps<double> *ramps, size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_rampsd_t native;
+ int r;
+ native.red_size = ramps->red.size = red;
+ native.green_size = ramps->green.size = green;
+ native.blue_size = ramps->blue.size = blue;
+ ramps->depth = -2;
+ r = libgamma_gamma_rampsd_initialise(&native);
+ if (r)
+ throw create_error(r);
+ ramps->red.ramp = native.red;
+ ramps->green.ramp = native.green;
+ ramps->blue.ramp = native.blue;
+ }
+
+ /**
+ * 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 The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
+ */
+ GammaRamps<uint8_t> *
+ gamma_ramps8_create(size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps8_t ramps;
+ int r;
+ ramps.red_size = red;
+ ramps.green_size = green;
+ ramps.blue_size = blue;
+ r = libgamma_gamma_ramps8_initialise(&ramps);
+ if (r)
+ throw create_error(r);
+ return new GammaRamps<uint8_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 8);
+ }
+
+ /**
+ * 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 The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
+ */
+ GammaRamps<uint16_t> *
+ gamma_ramps16_create(size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps16_t ramps;
+ int r;
+ ramps.red_size = red;
+ ramps.green_size = green;
+ ramps.blue_size = blue;
+ r = libgamma_gamma_ramps16_initialise(&ramps);
+ if (r)
+ throw create_error(r);
+ return new GammaRamps<uint16_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 16);
+ }
+
+ /**
+ * 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 The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
+ */
+ GammaRamps<uint32_t> *
+ gamma_ramps32_create(size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps32_t ramps;
+ int r;
+ ramps.red_size = red;
+ ramps.green_size = green;
+ ramps.blue_size = blue;
+ r = libgamma_gamma_ramps32_initialise(&ramps);
+ if (r)
+ throw create_error(r);
+ return new GammaRamps<uint32_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 32);
+ }
+
+ /**
+ * 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 The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
+ */
+ GammaRamps<uint64_t> *
+ gamma_ramps64_create(size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_ramps64_t ramps;
+ int r;
+ ramps.red_size = red;
+ ramps.green_size = green;
+ ramps.blue_size = blue;
+ r = libgamma_gamma_ramps64_initialise(&ramps);
+ if (r)
+ throw create_error(r);
+ return new GammaRamps<uint64_t>(ramps.red, ramps.green, ramps.blue, red, green, blue, 64);
+ }
+
+ /**
+ * 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 The size of the gamma ramp for the red channel.
+ * @param green The size of the gamma ramp for the green channel.
+ * @param blue The size of the gamma ramp for the blue channel.
+ * @return The gamma ramp.
+ */
+ GammaRamps<float> *
+ gamma_rampsf_create(size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_rampsf_t ramps;
+ int r;
+ ramps.red_size = red;
+ ramps.green_size = green;
+ ramps.blue_size = blue;
+ r = libgamma_gamma_rampsf_initialise(&ramps);
+ if (r)
+ throw create_error(r);
+ return new GammaRamps<float>(ramps.red, ramps.green, ramps.blue, red, green, blue, -1);
+ }
+
+ /**
+ * 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 The size of the gamma ramp for the red channel.
+ * @param green The size of the gamma ramp for the green channel.
+ * @param blue The size of the gamma ramp for the blue channel.
+ * @return The gamma ramp.
+ */
+ GammaRamps<double> *
+ gamma_rampsd_create(size_t red, size_t blue, size_t green)
+ {
+ libgamma_gamma_rampsd_t ramps;
+ int r;
+ ramps.red_size = red;
+ ramps.green_size = green;
+ ramps.blue_size = blue;
+ r = libgamma_gamma_rampsd_initialise(&ramps);
+ if (r)
+ throw create_error(r);
+ return new GammaRamps<double>(ramps.red, ramps.green, ramps.blue, red, green, blue, -2);
+ }
+}
diff --git a/libgamma-facade.hh b/libgamma-facade.hh
index 3ac3321..331cad9 100644
--- a/libgamma-facade.hh
+++ b/libgamma-facade.hh
@@ -2,7 +2,6 @@
#ifndef LIBGAMMA_FACADE_HH
#define LIBGAMMA_FACADE_HH
-
#include <string>
#include <vector>
@@ -10,242 +9,236 @@
#include "libgamma-method.hh"
-#ifndef __GNUC__
-# define __attribute__(X) /* emtpy */
+#if defined(__GNUC__)
+# define LIBGAMMAMM_CONST__ __attribute__((__const__))
+#else
+# define LIBGAMMAMM_CONST__
#endif
-
namespace libgamma
{
/**
- * List available adjustment methods by their order of preference based on the environment.
+ * 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 Array of methods.
+ * 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 Array of methods
*/
std::vector<int> list_methods(int operation);
-
+
/**
* 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.
+ * 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.
+ * @param method The adjustment method
+ * @return Whether the adjustment method is available
*/
- int is_method_available(int method) __attribute__((const));
-
+ LIBGAMMAMM_CONST__ int is_method_available(int method);
+
/**
- * Return the capabilities of an adjustment method.
+ * Return the capabilities of an adjustment method
*
- * @param output The data structure to fill with the method's capabilities,
- * @param method The adjustment method (display server and protocol).
+ * @param output The data structure to fill with the method's capabilities
+ * @param method The adjustment method (display server and protocol)
*/
- void method_capabilities(MethodCapabilities* output, int method);
-
+ void method_capabilities(MethodCapabilities *output, int method);
+
/**
- * Return the default site for an adjustment method.
+ * Return the default site for an adjustment method
*
- * @param method The adjustment method (display server and protocol.)
+ * @param method The adjustment method (display server and protocol)
* @return The default site, `nullptr` if it cannot be determined or if
- * multiple sites are not supported by the adjustment method.
+ * multiple sites are not supported by the adjustment method
*/
- std::string* method_default_site(int method);
-
+ std::string *method_default_site(int method);
+
/**
* Return the default variable that determines
- * the default site for an adjustment method.
+ * the default site for an adjustment method
*
- * @param method The adjustment method (display server and protocol.)
+ * @param method The adjustment method (display server and protocol)
* @return The environ variables that is used to determine the
* default site. `nullptr` if there is none, that is, if
- * the method does not support multiple sites.
+ * the method does not support multiple sites
*/
- std::string* method_default_site_variable(int method);
-
-
+ std::string *method_default_site_variable(int method);
+
+
/**
- * Convert a raw representation of an EDID to a lowercase hexadecimal representation.
+ * Convert a raw representation of an EDID to a lowercase hexadecimal representation
*
- * @param edid The EDID in raw representation.
- * @param length The length of `edid`.
- * @return The EDID in lowercase hexadecimal representation.
+ * @param edid The EDID in raw representation
+ * @param length The length of `edid`
+ * @return The EDID in lowercase hexadecimal representation
*/
- std::string behex_edid(const unsigned char* edid, size_t length);
-
+ std::string behex_edid(const unsigned char *edid, size_t length);
+
/**
- * Convert a raw representation of an EDID to a lowercase hexadecimal representation.
+ * Convert a raw representation of an EDID to a lowercase hexadecimal representation
*
- * @param edid The EDID in raw representation.
- * @param length The length of `edid`.
- * @return The EDID in lowercase hexadecimal representation.
+ * @param edid The EDID in raw representation
+ * @param length The length of `edid`
+ * @return The EDID in lowercase hexadecimal representation
*/
- std::string behex_edid_lowercase(const unsigned char* edid, size_t length);
-
+ std::string behex_edid_lowercase(const unsigned char *edid, size_t length);
+
/**
- * Convert a raw representation of an EDID to an uppercase hexadecimal representation.
+ * Convert a raw representation of an EDID to an uppercase hexadecimal representation
*
- * @param edid The EDID in raw representation.
- * @param length The length of `edid`.
- * @return The EDID in uppercase hexadecimal representation.
+ * @param edid The EDID in raw representation
+ * @param length The length of `edid`
+ * @return The EDID in uppercase hexadecimal representation
*/
- std::string behex_edid_uppercase(const unsigned char* edid, size_t length);
-
+ std::string behex_edid_uppercase(const unsigned char *edid, size_t length);
+
/**
- * Convert an hexadecimal representation of an EDID to a raw representation.
+ * Convert an hexadecimal representation of an EDID to a raw representation
*
- * @param edid The EDID in hexadecimal representation.
+ * @param edid The EDID in hexadecimal representation
* @return The EDID in raw representation, it will be half the length
- * of `edid` (the input value).
+ * of `edid` (the input value)
*/
- unsigned char* unhex_edid(const std::string edid);
-
-
+ unsigned char *unhex_edid(const std::string edid);
+
+
/**
* Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
*/
- void gamma_ramps8_initialise(GammaRamps<uint8_t>* ramps, size_t red, size_t blue, size_t green);
-
+ void gamma_ramps8_initialise(GammaRamps<uint8_t> *ramps, size_t red, size_t blue, size_t green);
+
/**
* Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
*/
- void gamma_ramps16_initialise(GammaRamps<uint16_t>* ramps, size_t red, size_t blue, size_t green);
-
+ void gamma_ramps16_initialise(GammaRamps<uint16_t> *ramps, size_t red, size_t blue, size_t green);
+
/**
* Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
*/
- void gamma_ramps32_initialise(GammaRamps<uint32_t>* ramps, size_t red, size_t blue, size_t green);
-
+ void gamma_ramps32_initialise(GammaRamps<uint32_t> *ramps, size_t red, size_t blue, size_t green);
+
/**
* Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
*/
- void gamma_ramps64_initialise(GammaRamps<uint64_t>* ramps, size_t red, size_t blue, size_t green);
-
+ void gamma_ramps64_initialise(GammaRamps<uint64_t> *ramps, size_t red, size_t blue, size_t green);
+
/**
* Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
*/
- void gamma_rampsf_initialise(GammaRamps<float>* ramps, size_t red, size_t blue, size_t green);
-
+ void gamma_rampsf_initialise(GammaRamps<float> *ramps, size_t red, size_t blue, size_t green);
+
/**
* Initialise a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param ramps The gamma ramp to initialise.
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
+ * @param ramps The gamma ramp to initialise
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
*/
- void gamma_rampsd_initialise(GammaRamps<double>* ramps, size_t red, size_t blue, size_t green);
-
-
+ void gamma_rampsd_initialise(GammaRamps<double> *ramps, size_t red, size_t blue, size_t green);
+
+
/**
* Create a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
*/
- GammaRamps<uint8_t>* gamma_ramps8_create(size_t red, size_t blue, size_t green);
-
+ GammaRamps<uint8_t> *gamma_ramps8_create(size_t red, size_t blue, size_t green);
+
/**
* Create a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
*/
- GammaRamps<uint16_t>* gamma_ramps16_create(size_t red, size_t blue, size_t green);
-
+ GammaRamps<uint16_t> *gamma_ramps16_create(size_t red, size_t blue, size_t green);
+
/**
* Create a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
*/
- GammaRamps<uint32_t>* gamma_ramps32_create(size_t red, size_t blue, size_t green);
-
+ GammaRamps<uint32_t> *gamma_ramps32_create(size_t red, size_t blue, size_t green);
+
/**
* Create a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
*/
- GammaRamps<uint64_t>* gamma_ramps64_create(size_t red, size_t blue, size_t green);
-
+ GammaRamps<uint64_t> *gamma_ramps64_create(size_t red, size_t blue, size_t green);
+
/**
* Create a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
*/
- GammaRamps<float>* gamma_rampsf_create(size_t red, size_t blue, size_t green);
-
+ GammaRamps<float> *gamma_rampsf_create(size_t red, size_t blue, size_t green);
+
/**
* Create a gamma ramp in the proper way that allows all adjustment
- * methods to read from and write to it without causing segmentation violation.
+ * methods to read from and write to it without causing segmentation violation
*
- * @param red The size of the gamma ramp for the red channel.
- * @param green The size of the gamma ramp for the green channel.
- * @param blue The size of the gamma ramp for the blue channel.
- * @return The gamma ramp.
+ * @param red The size of the gamma ramp for the red channel
+ * @param green The size of the gamma ramp for the green channel
+ * @param blue The size of the gamma ramp for the blue channel
+ * @return The gamma ramp
*/
- GammaRamps<double>* gamma_rampsd_create(size_t red, size_t blue, size_t green);
-
+ GammaRamps<double> *gamma_rampsd_create(size_t red, size_t blue, size_t green);
}
-
-#ifndef __GNUC__
-# undef __attribute__
#endif
-
-#endif
-
diff --git a/libgamma-method.cc b/libgamma-method.cc
index 79230f2..2dfee76 100644
--- a/libgamma-method.cc
+++ b/libgamma-method.cc
@@ -1,535 +1,512 @@
/* See LICENSE file for copyright and license details. */
#include "libgamma-method.hh"
-
#include "libgamma-error.hh"
-
+#include <cerrno>
#include <cstdlib>
#include <cstring>
-#include <cerrno>
namespace libgamma
{
- /**
- * Constructor.
- */
- MethodCapabilities::MethodCapabilities() :
- crtc_information(0),
- default_site_known(false),
- multiple_sites(false),
- multiple_partitions(false),
- multiple_crtcs(false),
- partitions_are_graphics_cards(false),
- site_restore(false),
- partition_restore(false),
- crtc_restore(false),
- identical_gamma_sizes(false),
- fixed_gamma_size(false),
- fixed_gamma_depth(false),
- real(false),
- fake(false)
- {
- /* Do nothing. */
- }
-
-
- /**
- * Constructor.
- *
- * @param caps The information in the native structure.
- */
- MethodCapabilities::MethodCapabilities(libgamma_method_capabilities_t* caps) :
- crtc_information(caps->crtc_information),
- default_site_known(caps->default_site_known),
- multiple_sites(caps->multiple_sites),
- multiple_partitions(caps->multiple_partitions),
- multiple_crtcs(caps->multiple_crtcs),
- partitions_are_graphics_cards(caps->partitions_are_graphics_cards),
- site_restore(caps->site_restore),
- partition_restore(caps->partition_restore),
- crtc_restore(caps->crtc_restore),
- identical_gamma_sizes(caps->identical_gamma_sizes),
- fixed_gamma_size(caps->fixed_gamma_size),
- fixed_gamma_depth(caps->fixed_gamma_depth),
- real(caps->real),
- fake(caps->fake)
- {
- /* Do nothing. */
- }
-
-
- /**
- * Copy constructor.
- *
- * @param other The information to copy.
- */
- MethodCapabilities::MethodCapabilities(const MethodCapabilities& other) :
- crtc_information(other.crtc_information),
- default_site_known(other.default_site_known),
- multiple_sites(other.multiple_sites),
- multiple_partitions(other.multiple_partitions),
- multiple_crtcs(other.multiple_crtcs),
- partitions_are_graphics_cards(other.partitions_are_graphics_cards),
- site_restore(other.site_restore),
- partition_restore(other.partition_restore),
- crtc_restore(other.crtc_restore),
- identical_gamma_sizes(other.identical_gamma_sizes),
- fixed_gamma_size(other.fixed_gamma_size),
- fixed_gamma_depth(other.fixed_gamma_depth),
- real(other.real),
- fake(other.fake)
- {
- /* Do nothing. */
- }
-
-
- /**
- * Destructor.
- */
- MethodCapabilities::~MethodCapabilities()
- {
- /* Do nothing. */
- }
-
-
- /**
- * Copy operator.
- *
- * @param other The information to copy.
- */
- MethodCapabilities& MethodCapabilities::operator =(const MethodCapabilities& other)
- {
- this->crtc_information = other.crtc_information;
- this->default_site_known = other.default_site_known;
- this->multiple_sites = other.multiple_sites;
- this->multiple_partitions = other.multiple_partitions;
- this->multiple_crtcs = other.multiple_crtcs;
- this->partitions_are_graphics_cards = other.partitions_are_graphics_cards;
- this->site_restore = other.site_restore;
- this->partition_restore = other.partition_restore;
- this->crtc_restore = other.crtc_restore;
- this->identical_gamma_sizes = other.identical_gamma_sizes;
- this->fixed_gamma_size = other.fixed_gamma_size;
- this->fixed_gamma_depth = other.fixed_gamma_depth;
- this->real = other.real;
- this->fake = other.fake;
-
- return *this;
- }
-
-
-
-
-
- /**
- * Constructor.
- */
- CRTCInformation::CRTCInformation() :
- edid(nullptr),
- edid_length(0),
- edid_error(0),
- width_mm(0),
- width_mm_error(0),
- height_mm(0),
- height_mm_error(0),
- width_mm_edid(0),
- width_mm_edid_error(0),
- height_mm_edid(0),
- height_mm_edid_error(0),
- red_gamma_size(0),
- green_gamma_size(0),
- blue_gamma_size(0),
- gamma_size_error(0),
- gamma_depth(0),
- gamma_depth_error(0),
- gamma_support(0),
- gamma_support_error(0),
- subpixel_order((SubpixelOrder)0),
- subpixel_order_error(0),
- active(0),
- active_error(0),
- connector_name(nullptr),
- connector_name_error(0),
- connector_type((ConnectorType)0),
- connector_type_error(0),
- gamma_red(0),
- gamma_green(0),
- gamma_blue(0),
- gamma_error(0)
- {
- /* Do nothing. */
- }
-
-
- /**
- * Constructor.
- *
- * @param info The information in the native structure.
- */
- CRTCInformation::CRTCInformation(libgamma_crtc_information_t* info) :
- edid(info->edid),
- edid_length(info->edid_length),
- edid_error(info->edid_error),
- width_mm(info->width_mm),
- width_mm_error(info->width_mm_error),
- height_mm(info->height_mm),
- height_mm_error(info->height_mm_error),
- width_mm_edid(info->width_mm_edid),
- width_mm_edid_error(info->width_mm_edid_error),
- height_mm_edid(info->height_mm_edid),
- height_mm_edid_error(info->height_mm_edid_error),
- red_gamma_size(info->red_gamma_size),
- green_gamma_size(info->green_gamma_size),
- blue_gamma_size(info->blue_gamma_size),
- gamma_size_error(info->gamma_size_error),
- gamma_depth(info->gamma_depth),
- gamma_depth_error(info->gamma_depth_error),
- gamma_support(info->gamma_support),
- gamma_support_error(info->gamma_support_error),
- subpixel_order(info->subpixel_order),
- subpixel_order_error(info->subpixel_order_error),
- active(info->active),
- active_error(info->active_error),
- connector_name(nullptr),
- connector_name_error(info->connector_name_error),
- connector_type(info->connector_type),
- connector_type_error(info->connector_type_error),
- gamma_red(info->gamma_red),
- gamma_green(info->gamma_green),
- gamma_blue(info->gamma_blue),
- gamma_error(info->gamma_error)
- {
- if (info->connector_name != nullptr)
- {
- this->connector_name = new std::string(info->connector_name);
- free(info->connector_name);
- }
- }
-
-
- /**
- * Copy constructor.
- *
- * @param other The information to copy.
- */
- CRTCInformation::CRTCInformation(const CRTCInformation& other) :
- edid(nullptr),
- edid_length(other.edid_length),
- edid_error(other.edid_error),
- width_mm(other.width_mm),
- width_mm_error(other.width_mm_error),
- height_mm(other.height_mm),
- height_mm_error(other.height_mm_error),
- width_mm_edid(other.width_mm_edid),
- width_mm_edid_error(other.width_mm_edid_error),
- height_mm_edid(other.height_mm_edid),
- height_mm_edid_error(other.height_mm_edid_error),
- red_gamma_size(other.red_gamma_size),
- green_gamma_size(other.green_gamma_size),
- blue_gamma_size(other.blue_gamma_size),
- gamma_size_error(other.gamma_size_error),
- gamma_depth(other.gamma_depth),
- gamma_depth_error(other.gamma_depth_error),
- gamma_support(other.gamma_support),
- gamma_support_error(other.gamma_support_error),
- subpixel_order(other.subpixel_order),
- subpixel_order_error(other.subpixel_order_error),
- active(other.active),
- active_error(other.active_error),
- connector_name(nullptr),
- connector_name_error(other.connector_name_error),
- connector_type(other.connector_type),
- connector_type_error(other.connector_type_error),
- gamma_red(other.gamma_red),
- gamma_green(other.gamma_green),
- gamma_blue(other.gamma_blue),
- gamma_error(other.gamma_error)
- {
- if (other.edid != nullptr)
- {
- this->edid = (unsigned char*)malloc(this->edid_length * sizeof(unsigned char));
- memcpy(this->edid, other.edid, this->edid_length * sizeof(unsigned char));
- }
- if (other.connector_name != nullptr)
- this->connector_name = new std::string(*(other.connector_name));
- }
-
-
- /**
- * Destructor.
- */
- CRTCInformation::~CRTCInformation()
- {
- if (this->connector_name != nullptr)
- delete this->connector_name;
- free(this->edid);
- }
-
-
- /**
- * Copy operator.
- *
- * @param other The information to copy.
- */
- CRTCInformation& CRTCInformation::operator =(const CRTCInformation& other)
- {
- this->edid = nullptr;
- this->edid_length = other.edid_length;
- this->edid_error = other.edid_error;
- this->width_mm = other.width_mm;
- this->width_mm_error = other.width_mm_error;
- this->height_mm = other.height_mm;
- this->height_mm_error = other.height_mm_error;
- this->width_mm_edid = other.width_mm_edid;
- this->width_mm_edid_error = other.width_mm_edid_error;
- this->height_mm_edid = other.height_mm_edid;
- this->height_mm_edid_error = other.height_mm_edid_error;
- this->red_gamma_size = other.red_gamma_size;
- this->green_gamma_size = other.green_gamma_size;
- this->blue_gamma_size = other.blue_gamma_size;
- this->gamma_size_error = other.gamma_size_error;
- this->gamma_depth = other.gamma_depth;
- this->gamma_depth_error = other.gamma_depth_error;
- this->gamma_support = other.gamma_support;
- this->gamma_support_error = other.gamma_support_error;
- this->subpixel_order = other.subpixel_order;
- this->subpixel_order_error = other.subpixel_order_error;
- this->active = other.active;
- this->active_error = other.active_error;
- this->connector_name = nullptr;
- this->connector_name_error = other.connector_name_error;
- this->connector_type = other.connector_type;
- this->connector_type_error = other.connector_type_error;
- this->gamma_red = other.gamma_red;
- this->gamma_green = other.gamma_green;
- this->gamma_blue = other.gamma_blue;
- this->gamma_error = other.gamma_error;
-
- if (other.edid != nullptr)
- {
- this->edid = (unsigned char*)malloc(this->edid_length * sizeof(unsigned char));
- memcpy(this->edid, other.edid, this->edid_length * sizeof(unsigned char));
- }
- if (other.connector_name != nullptr)
- this->connector_name = new std::string(*(other.connector_name));
-
- return *this;
- }
-
+ /**
+ * Constructor
+ */
+ MethodCapabilities::MethodCapabilities() :
+ crtc_information(0),
+ default_site_known(false),
+ multiple_sites(false),
+ multiple_partitions(false),
+ multiple_crtcs(false),
+ partitions_are_graphics_cards(false),
+ site_restore(false),
+ partition_restore(false),
+ crtc_restore(false),
+ identical_gamma_sizes(false),
+ fixed_gamma_size(false),
+ fixed_gamma_depth(false),
+ real(false),
+ fake(false)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Constructor
+ *
+ * @param caps The information in the native structure
+ */
+ MethodCapabilities::MethodCapabilities(libgamma_method_capabilities_t *caps) :
+ crtc_information(caps->crtc_information),
+ default_site_known(caps->default_site_known),
+ multiple_sites(caps->multiple_sites),
+ multiple_partitions(caps->multiple_partitions),
+ multiple_crtcs(caps->multiple_crtcs),
+ partitions_are_graphics_cards(caps->partitions_are_graphics_cards),
+ site_restore(caps->site_restore),
+ partition_restore(caps->partition_restore),
+ crtc_restore(caps->crtc_restore),
+ identical_gamma_sizes(caps->identical_gamma_sizes),
+ fixed_gamma_size(caps->fixed_gamma_size),
+ fixed_gamma_depth(caps->fixed_gamma_depth),
+ real(caps->real),
+ fake(caps->fake)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param other The information to copy.
+ */
+ MethodCapabilities::MethodCapabilities(const MethodCapabilities &other) :
+ crtc_information(other.crtc_information),
+ default_site_known(other.default_site_known),
+ multiple_sites(other.multiple_sites),
+ multiple_partitions(other.multiple_partitions),
+ multiple_crtcs(other.multiple_crtcs),
+ partitions_are_graphics_cards(other.partitions_are_graphics_cards),
+ site_restore(other.site_restore),
+ partition_restore(other.partition_restore),
+ crtc_restore(other.crtc_restore),
+ identical_gamma_sizes(other.identical_gamma_sizes),
+ fixed_gamma_size(other.fixed_gamma_size),
+ fixed_gamma_depth(other.fixed_gamma_depth),
+ real(other.real),
+ fake(other.fake)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Destructor
+ */
+ MethodCapabilities::~MethodCapabilities()
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Copy operator
+ *
+ * @param other The information to copy
+ */
+ MethodCapabilities &
+ MethodCapabilities::operator =(const MethodCapabilities &other)
+ {
+ this->crtc_information = other.crtc_information;
+ this->default_site_known = other.default_site_known;
+ this->multiple_sites = other.multiple_sites;
+ this->multiple_partitions = other.multiple_partitions;
+ this->multiple_crtcs = other.multiple_crtcs;
+ this->partitions_are_graphics_cards = other.partitions_are_graphics_cards;
+ this->site_restore = other.site_restore;
+ this->partition_restore = other.partition_restore;
+ this->crtc_restore = other.crtc_restore;
+ this->identical_gamma_sizes = other.identical_gamma_sizes;
+ this->fixed_gamma_size = other.fixed_gamma_size;
+ this->fixed_gamma_depth = other.fixed_gamma_depth;
+ this->real = other.real;
+ this->fake = other.fake;
+
+ return *this;
+ }
+
+
+
+ /**
+ * Constructor
+ */
+ CRTCInformation::CRTCInformation() :
+ edid(nullptr),
+ edid_length(0),
+ edid_error(0),
+ width_mm(0),
+ width_mm_error(0),
+ height_mm(0),
+ height_mm_error(0),
+ width_mm_edid(0),
+ width_mm_edid_error(0),
+ height_mm_edid(0),
+ height_mm_edid_error(0),
+ red_gamma_size(0),
+ green_gamma_size(0),
+ blue_gamma_size(0),
+ gamma_size_error(0),
+ gamma_depth(0),
+ gamma_depth_error(0),
+ gamma_support(0),
+ gamma_support_error(0),
+ subpixel_order((SubpixelOrder)0),
+ subpixel_order_error(0),
+ active(0),
+ active_error(0),
+ connector_name(nullptr),
+ connector_name_error(0),
+ connector_type((ConnectorType)0),
+ connector_type_error(0),
+ gamma_red(0),
+ gamma_green(0),
+ gamma_blue(0),
+ gamma_error(0)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Constructor
+ *
+ * @param info The information in the native structure
+ */
+ CRTCInformation::CRTCInformation(libgamma_crtc_information_t *info) :
+ edid(info->edid),
+ edid_length(info->edid_length),
+ edid_error(info->edid_error),
+ width_mm(info->width_mm),
+ width_mm_error(info->width_mm_error),
+ height_mm(info->height_mm),
+ height_mm_error(info->height_mm_error),
+ width_mm_edid(info->width_mm_edid),
+ width_mm_edid_error(info->width_mm_edid_error),
+ height_mm_edid(info->height_mm_edid),
+ height_mm_edid_error(info->height_mm_edid_error),
+ red_gamma_size(info->red_gamma_size),
+ green_gamma_size(info->green_gamma_size),
+ blue_gamma_size(info->blue_gamma_size),
+ gamma_size_error(info->gamma_size_error),
+ gamma_depth(info->gamma_depth),
+ gamma_depth_error(info->gamma_depth_error),
+ gamma_support(info->gamma_support),
+ gamma_support_error(info->gamma_support_error),
+ subpixel_order(info->subpixel_order),
+ subpixel_order_error(info->subpixel_order_error),
+ active(info->active),
+ active_error(info->active_error),
+ connector_name(nullptr),
+ connector_name_error(info->connector_name_error),
+ connector_type(info->connector_type),
+ connector_type_error(info->connector_type_error),
+ gamma_red(info->gamma_red),
+ gamma_green(info->gamma_green),
+ gamma_blue(info->gamma_blue),
+ gamma_error(info->gamma_error)
+ {
+ if (info->connector_name != nullptr) {
+ this->connector_name = new std::string(info->connector_name);
+ free(info->connector_name);
+ }
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param other The information to copy
+ */
+ CRTCInformation::CRTCInformation(const CRTCInformation &other) :
+ edid(nullptr),
+ edid_length(other.edid_length),
+ edid_error(other.edid_error),
+ width_mm(other.width_mm),
+ width_mm_error(other.width_mm_error),
+ height_mm(other.height_mm),
+ height_mm_error(other.height_mm_error),
+ width_mm_edid(other.width_mm_edid),
+ width_mm_edid_error(other.width_mm_edid_error),
+ height_mm_edid(other.height_mm_edid),
+ height_mm_edid_error(other.height_mm_edid_error),
+ red_gamma_size(other.red_gamma_size),
+ green_gamma_size(other.green_gamma_size),
+ blue_gamma_size(other.blue_gamma_size),
+ gamma_size_error(other.gamma_size_error),
+ gamma_depth(other.gamma_depth),
+ gamma_depth_error(other.gamma_depth_error),
+ gamma_support(other.gamma_support),
+ gamma_support_error(other.gamma_support_error),
+ subpixel_order(other.subpixel_order),
+ subpixel_order_error(other.subpixel_order_error),
+ active(other.active),
+ active_error(other.active_error),
+ connector_name(nullptr),
+ connector_name_error(other.connector_name_error),
+ connector_type(other.connector_type),
+ connector_type_error(other.connector_type_error),
+ gamma_red(other.gamma_red),
+ gamma_green(other.gamma_green),
+ gamma_blue(other.gamma_blue),
+ gamma_error(other.gamma_error)
+ {
+ if (other.edid != nullptr) {
+ this->edid = (unsigned char *)malloc(this->edid_length * sizeof(unsigned char));
+ memcpy(this->edid, other.edid, this->edid_length * sizeof(unsigned char));
+ }
+ if (other.connector_name != nullptr)
+ this->connector_name = new std::string(*(other.connector_name));
+ }
+
+ /**
+ * Destructor
+ */
+ CRTCInformation::~CRTCInformation()
+ {
+ if (this->connector_name != nullptr)
+ delete this->connector_name;
+ free(this->edid);
+ }
+
+ /**
+ * Copy operator
+ *
+ * @param other The information to copy
+ */
+ CRTCInformation &
+ CRTCInformation::operator =(const CRTCInformation &other)
+ {
+ this->edid = nullptr;
+ this->edid_length = other.edid_length;
+ this->edid_error = other.edid_error;
+ this->width_mm = other.width_mm;
+ this->width_mm_error = other.width_mm_error;
+ this->height_mm = other.height_mm;
+ this->height_mm_error = other.height_mm_error;
+ this->width_mm_edid = other.width_mm_edid;
+ this->width_mm_edid_error = other.width_mm_edid_error;
+ this->height_mm_edid = other.height_mm_edid;
+ this->height_mm_edid_error = other.height_mm_edid_error;
+ this->red_gamma_size = other.red_gamma_size;
+ this->green_gamma_size = other.green_gamma_size;
+ this->blue_gamma_size = other.blue_gamma_size;
+ this->gamma_size_error = other.gamma_size_error;
+ this->gamma_depth = other.gamma_depth;
+ this->gamma_depth_error = other.gamma_depth_error;
+ this->gamma_support = other.gamma_support;
+ this->gamma_support_error = other.gamma_support_error;
+ this->subpixel_order = other.subpixel_order;
+ this->subpixel_order_error = other.subpixel_order_error;
+ this->active = other.active;
+ this->active_error = other.active_error;
+ this->connector_name = nullptr;
+ this->connector_name_error = other.connector_name_error;
+ this->connector_type = other.connector_type;
+ this->connector_type_error = other.connector_type_error;
+ this->gamma_red = other.gamma_red;
+ this->gamma_green = other.gamma_green;
+ this->gamma_blue = other.gamma_blue;
+ this->gamma_error = other.gamma_error;
+
+ if (other.edid != nullptr) {
+ this->edid = (unsigned char *)malloc(this->edid_length * sizeof(unsigned char));
+ memcpy(this->edid, other.edid, this->edid_length * sizeof(unsigned char));
+ }
+ if (other.connector_name != nullptr)
+ this->connector_name = new std::string(*(other.connector_name));
+
+ return *this;
+ }
+
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wshadow"
#endif
-
- /**
- * Constructor.
- */
- Site::Site() :
- method(0),
- site(nullptr),
- partitions_available(0),
- native(nullptr)
- {
- /* Do nothing. */
- }
-
- /**
- * Constructor.
- *
- * @param method The adjustment method of the site.
- * @param site The site identifier, will be moved into
- * the structure, must be `delete`:able.
- */
- Site::Site(int method, std::string* site) :
- method(method),
- site(site),
- partitions_available(0),
- native(nullptr)
- {
- char* cstr = nullptr;
- int r;
-
- if (site != nullptr)
- {
- const char* cstr_ = site->c_str();
- cstr = (char*)malloc((strlen(cstr_) + 1) * sizeof(char));
- memcpy(cstr, cstr_, (strlen(cstr_) + 1) * sizeof(char));
- }
- this->native = (libgamma_site_state_t*)malloc(sizeof(libgamma_site_state_t));
- r = libgamma_site_initialise(this->native, method, cstr);
- if (r < 0)
- {
- int saved_errno = errno;
- free(this->native);
- this->native = nullptr;
- errno = saved_errno;
- throw create_error(r);
- }
- this->partitions_available = this->native->partitions_available;
- }
-
- /**
- * Destructor.
- */
- Site::~Site()
- {
- if (this->site != nullptr)
- delete this->site;
- if (this->native != nullptr)
- libgamma_site_free(this->native);
- }
-
- /**
- * Restore the gamma ramps all CRTC:s with a site to
- * the system settings.
- */
- void Site::restore()
- {
- int r;
- r = libgamma_site_restore(this->native);
- if (r != 0)
- throw create_error(r);
- }
-
-
-
- /**
- * Constructor.
- */
- Partition::Partition() :
- site(nullptr),
- partition(0),
- crtcs_available(0),
- native(nullptr)
- {
- /* Do nothing. */
- }
-
- /**
- * Constructor.
- *
- * @param site The site of the partition.
- * @param partition The index of the partition.
- */
- Partition::Partition(Site* site, size_t partition) :
- site(site),
- partition(partition),
- crtcs_available(0),
- native(nullptr)
- {
- int r;
- this->native = (libgamma_partition_state_t*)malloc(sizeof(libgamma_partition_state_t));
- r = libgamma_partition_initialise(this->native, site->native, partition);
- if (r < 0)
- {
- int saved_errno = errno;
- free(this->native);
- this->native = nullptr;
- errno = saved_errno;
- throw create_error(r);
- }
- this->crtcs_available = this->native->crtcs_available;
- }
-
- /**
- * Destructor.
- */
- Partition::~Partition()
- {
- if (this->native != nullptr)
- libgamma_partition_free(this->native);
- }
-
- /**
- * Restore the gamma ramps all CRTC:s with a partition
- * to the system settings.
- */
- void Partition::restore()
- {
- int r;
- r = libgamma_partition_restore(this->native);
- if (r != 0)
- throw create_error(r);
- }
-
-
-
- /**
- * Constructor.
- */
- CRTC::CRTC() :
- partition(nullptr),
- crtc(0),
- native(nullptr)
- {
- /* Do nothing. */
- }
-
- /**
- * Constructor.
- *
- * @param partition The partition of the CRTC.
- * @param crtc The index of the CRTC.
- */
- CRTC::CRTC(Partition* partition, size_t crtc) :
- partition(partition),
- crtc(crtc),
- native(nullptr)
- {
- int r;
- this->native = (libgamma_crtc_state_t*)malloc(sizeof(libgamma_crtc_state_t));
- r = libgamma_crtc_initialise(this->native, partition->native, crtc);
- if (r < 0)
- {
- int saved_errno = errno;
- free(this->native);
- this->native = nullptr;
- errno = saved_errno;
- throw create_error(r);
- }
- }
-
- /**
- * Destructor.
- */
- CRTC::~CRTC()
- {
- if (this->native != nullptr)
- libgamma_crtc_free(this->native);
- }
-
- /**
- * Restore the gamma ramps for a CRTC to the system
- * settings for that CRTC.
- */
- void CRTC::restore()
- {
- int r;
- r = libgamma_crtc_restore(this->native);
- if (r != 0)
- throw create_error(r);
- }
-
- /**
- * Read information about a CRTC.
- *
- * @param output Instance of a data structure to fill with the information about the CRTC.
- * @param fields OR:ed identifiers for the information about the CRTC that should be read.
- * @return Whether an error has occurred and is stored in a `*_error` field.
- */
- bool CRTC::information(CRTCInformation* output, int32_t fields)
- {
- libgamma_crtc_information_t info;
- int r;
-
- r = libgamma_get_crtc_information(&info, this->native, fields);
- *output = CRTCInformation(&info);
- return r != 0;
- }
-
+
+ /**
+ * Constructor
+ */
+ Site::Site() :
+ method(0),
+ site(nullptr),
+ partitions_available(0),
+ native(nullptr)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Constructor
+ *
+ * @param method The adjustment method of the site
+ * @param site The site identifier, will be moved into
+ * the structure, must be `delete`:able
+ */
+ Site::Site(int method, std::string *site) :
+ method(method),
+ site(site),
+ partitions_available(0),
+ native(nullptr)
+ {
+ char *cstr = nullptr;
+ int r;
+
+ if (site != nullptr) {
+ const char *cstr_ = site->c_str();
+ cstr = (char *)malloc((strlen(cstr_) + 1) * sizeof(char));
+ memcpy(cstr, cstr_, (strlen(cstr_) + 1) * sizeof(char));
+ }
+ this->native = (libgamma_site_state_t*)malloc(sizeof(libgamma_site_state_t));
+ r = libgamma_site_initialise(this->native, method, cstr);
+ if (r < 0) {
+ int saved_errno = errno;
+ free(this->native);
+ this->native = nullptr;
+ errno = saved_errno;
+ throw create_error(r);
+ }
+ this->partitions_available = this->native->partitions_available;
+ }
+
+ /**
+ * Destructor
+ */
+ Site::~Site()
+ {
+ if (this->site != nullptr)
+ delete this->site;
+ if (this->native != nullptr)
+ libgamma_site_free(this->native);
+ }
+
+ /**
+ * Restore the gamma ramps all CRTC:s with a site to
+ * the system settings
+ */
+ void Site::restore()
+ {
+ int r = libgamma_site_restore(this->native);
+ if (r)
+ throw create_error(r);
+ }
+
+
+ /**
+ * Constructor
+ */
+ Partition::Partition() :
+ site(nullptr),
+ partition(0),
+ crtcs_available(0),
+ native(nullptr)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Constructor
+ *
+ * @param site The site of the partition
+ * @param partition The index of the partition
+ */
+ Partition::Partition(Site *site, size_t partition) :
+ site(site),
+ partition(partition),
+ crtcs_available(0),
+ native(nullptr)
+ {
+ int r;
+ this->native = (libgamma_partition_state_t*)malloc(sizeof(libgamma_partition_state_t));
+ r = libgamma_partition_initialise(this->native, site->native, partition);
+ if (r < 0) {
+ int saved_errno = errno;
+ free(this->native);
+ this->native = nullptr;
+ errno = saved_errno;
+ throw create_error(r);
+ }
+ this->crtcs_available = this->native->crtcs_available;
+ }
+
+ /**
+ * Destructor
+ */
+ Partition::~Partition()
+ {
+ if (this->native != nullptr)
+ libgamma_partition_free(this->native);
+ }
+
+ /**
+ * Restore the gamma ramps all CRTC:s with a partition
+ * to the system settings
+ */
+ void
+ Partition::restore()
+ {
+ int r = libgamma_partition_restore(this->native);
+ if (r)
+ throw create_error(r);
+ }
+
+
+ /**
+ * Constructor
+ */
+ CRTC::CRTC() :
+ partition(nullptr),
+ crtc(0),
+ native(nullptr)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Constructor
+ *
+ * @param partition The partition of the CRTC
+ * @param crtc The index of the CRTC
+ */
+ CRTC::CRTC(Partition *partition, size_t crtc) :
+ partition(partition),
+ crtc(crtc),
+ native(nullptr)
+ {
+ int r;
+ this->native = (libgamma_crtc_state_t *)malloc(sizeof(libgamma_crtc_state_t));
+ r = libgamma_crtc_initialise(this->native, partition->native, crtc);
+ if (r < 0) {
+ int saved_errno = errno;
+ free(this->native);
+ this->native = nullptr;
+ errno = saved_errno;
+ throw create_error(r);
+ }
+ }
+
+ /**
+ * Destructor
+ */
+ CRTC::~CRTC()
+ {
+ if (this->native != nullptr)
+ libgamma_crtc_free(this->native);
+ }
+
+ /**
+ * Restore the gamma ramps for a CRTC to the system
+ * settings for that CRTC
+ */
+ void
+ CRTC::restore()
+ {
+ int r = libgamma_crtc_restore(this->native);
+ if (r)
+ throw create_error(r);
+ }
+
+ /**
+ * Read information about a CRTC
+ *
+ * @param output Instance of a data structure to fill with the information about the CRTC
+ * @param fields OR:ed identifiers for the information about the CRTC that should be read
+ * @return Whether an error has occurred and is stored in a `*_error` field
+ */
+ bool
+ CRTC::information(CRTCInformation *output, int32_t fields)
+ {
+ libgamma_crtc_information_t info;
+ int r = libgamma_get_crtc_information(&info, this->native, fields);
+ *output = CRTCInformation(&info);
+ return r != 0;
+ }
+
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
-
}
-
diff --git a/libgamma-method.hh b/libgamma-method.hh
index 43b4983..4f9339d 100644
--- a/libgamma-method.hh
+++ b/libgamma-method.hh
@@ -2,1005 +2,969 @@
#ifndef LIBGAMMA_METHOD_HH
#define LIBGAMMA_METHOD_HH
-
-#include <string>
#include <cstdlib>
+#include <string>
#include "libgamma-native.hh"
#include "libgamma-error.hh"
-#ifndef __GNUC__
-# define __attribute__(X) /* emtpy */
-#endif
+namespace libgamma
+{
+ /**
+ * Cathode ray tube controller information data structure
+ */
+ class CRTCInformation;
+ /**
+ * Capabilities of adjustment methods
+ */
+ class MethodCapabilities;
+
+ /**
+ * Site state
+ *
+ * On operating systems that integrate a graphical environment
+ * there is usually just one site. However, one systems with
+ * pluggable graphics, like Unix-like systems such as GNU/Linux
+ * and the BSD:s, there can usually be any (feasible) number of
+ * sites. In X.org parlance they are called displays.
+ */
+ class Site;
+
+ /**
+ * Partition state
+ *
+ * Probably the majority of display server only one partition
+ * per site. However, X.org can, and traditional used to have
+ * on multi-headed environments, multiple partitions per site.
+ * In X.org partitions are called 'screens'. It is not to be
+ * confused with monitor. A screen is a collection of monitors,
+ * and the mapping from monitors to screens is a surjection.
+ * On hardware-level adjustment methods, such as Direct
+ * Rendering Manager, a partition is a graphics card.
+ */
+ class Partition;
+
+ /**
+ * Cathode ray tube controller state
+ *
+ * The CRTC controls the gamma ramps for the
+ * monitor that is plugged in to the connector
+ * that the CRTC belongs to
+ */
+ class CRTC;
+
+
+ /**
+ * Capabilities of adjustment methods
+ */
+ class MethodCapabilities
+ {
+ public:
+ /**
+ * Constructor
+ */
+ MethodCapabilities();
+
+ /**
+ * Constructor
+ *
+ * @param caps The information in the native structure
+ */
+ MethodCapabilities(libgamma_method_capabilities_t *caps);
+
+ /**
+ * Copy constructor
+ *
+ * @param other The information to copy
+ */
+ MethodCapabilities(const MethodCapabilities &other);
+
+ /**
+ * Destructor
+ */
+ ~MethodCapabilities();
+
+ /**
+ * Copy operator
+ *
+ * @param other The information to copy
+ */
+ MethodCapabilities &operator =(const MethodCapabilities &other);
+
+
+ /**
+ * OR of the CRTC information fields in `libgamma_crtc_information_t`
+ * that may (but can fail) be read successfully
+ */
+ int32_t crtc_information;
+
+ /**
+ * Whether the default site is known, if true the site is integrated
+ * to the system or can be determined using environment variables
+ */
+ bool default_site_known;
+
+ /**
+ * Whether the adjustment method supports multiple sites rather
+ * than just the default site
+ */
+ bool multiple_sites;
+
+ /**
+ * Whether the adjustment method supports multiple partitions
+ * per site
+ */
+ bool multiple_partitions;
+
+ /**
+ * Whether the adjustment method supports multiple CRTC:s
+ * per partition per site
+ */
+ bool multiple_crtcs;
+
+ /**
+ * Whether the partition to graphics card is a bijection.
+ */
+ bool partitions_are_graphics_cards;
+
+ /**
+ * Whether the adjustment method supports `libgamma_site_restore`
+ */
+ bool site_restore;
+
+ /**
+ * Whether the adjustment method supports `libgamma_partition_restore`
+ */
+ bool partition_restore;
+
+ /**
+ * Whether the adjustment method supports `libgamma_crtc_restore`
+ */
+ bool crtc_restore;
+
+ /**
+ * Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
+ * fields in `libgamma_crtc_information_t` will always have the same
+ * values as each other for the adjustment method
+ */
+ bool identical_gamma_sizes;
+
+ /**
+ * Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
+ * fields in `libgamma_crtc_information_t` will always be filled with the
+ * same value for the adjustment method
+ */
+ bool fixed_gamma_size;
+
+ /**
+ * Whether the `gamma_depth` field in `libgamma_crtc_information_t`
+ * will always be filled with the same value for the adjustment method
+ */
+ bool fixed_gamma_depth;
+
+ /**
+ * Whether the adjustment method will actually perform adjustments
+ */
+ bool real;
+
+ /**
+ * Whether the adjustment method is implement using a translation layer
+ */
+ bool fake;
+ };
+
+
+ /**
+ * Types for connectors
+ */
+ typedef libgamma_connector_type_t ConnectorType;
+
+ /**
+ * Orders for subpixels; currently the possible values are
+ * very biased to LCD, Plasma and monochrome monitors
+ */
+ typedef libgamma_subpixel_order_t SubpixelOrder;
+
+
+ /**
+ * Cathode ray tube controller information data structure
+ */
+ class CRTCInformation
+ {
+ public:
+ /**
+ * Constructor
+ */
+ CRTCInformation();
+
+ /**
+ * Constructor
+ *
+ * @param info The information in the native structure
+ */
+ CRTCInformation(libgamma_crtc_information_t *info);
+
+ /**
+ * Copy constructor
+ *
+ * @param other The information to copy
+ */
+ CRTCInformation(const CRTCInformation &other);
+
+ /**
+ * Destructor
+ */
+ ~CRTCInformation();
+
+ /**
+ * Copy operator
+ *
+ * @param other The information to copy
+ */
+ CRTCInformation &operator =(const CRTCInformation &other);
+
+
+ /**
+ * The Extended Display Identification Data associated with
+ * the attached monitor. This is raw byte array that is usually
+ * 128 bytes long. It is not NUL-terminate, rather its length
+ * is stored in `edid_length`.
+ */
+ unsigned char *edid;
+
+ /**
+ * The length of `edid`
+ */
+ size_t edid_length;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int edid_error;
+
+ /**
+ * The phyical width, in millimetres, of the viewport of the
+ * attached monitor, as reported by the adjustment method. This
+ * value may be incorrect, which is a known issue with the X
+ * server where it is the result of the X server attempting
+ * the estimate the size on its own.
+ * Zero means that its is not applicable, which is the case
+ * for projectors.
+ */
+ size_t width_mm;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int width_mm_error;
+
+ /**
+ * The phyical height, in millimetres, of the viewport of the
+ * attached monitor, as reported by the adjustment method. This
+ * value may be incorrect, which is a known issue with the X
+ * server where it is the result of the X server attempting
+ * the estimate the size on its own.
+ * Zero means that its is not applicable, which is the case
+ * for projectors.
+ */
+ size_t height_mm;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int height_mm_error;
+
+ /**
+ * The phyical width, in millimetres, of the viewport of the
+ * attached monitor, as reported by it the monitor's Extended
+ * Display Information Data. This value can only contain whole
+ * centimetres, which means that the result is always zero
+ * modulus ten. However, this could change with revisions of
+ * the EDID structure.
+ * Zero means that its is not applicable, which is the case
+ * for projectors.
+ */
+ size_t width_mm_edid;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int width_mm_edid_error;
+
+ /**
+ * The phyical height, in millimetres, of the viewport of the
+ * attached monitor, as reported by it the monitor's Extended
+ * Display Information Data. This value can only contain whole
+ * centimetres, which means that the result is always zero
+ * modulus ten. However, this could change with revisions of
+ * the EDID structure.
+ * Zero means that its is not applicable, which is the case
+ * for projectors.
+ */
+ size_t height_mm_edid;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int height_mm_edid_error;
+
+ /**
+ * The size of the encoding axis of the red gamma ramp
+ */
+ size_t red_gamma_size;
+
+ /**
+ * The size of the encoding axis of the green gamma ramp
+ */
+ size_t green_gamma_size;
+
+ /**
+ * The size of the encoding axis of the blue gamma ramp
+ */
+ size_t blue_gamma_size;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int gamma_size_error;
+
+ /**
+ * The bit-depth of the value axes of gamma ramps,
+ * -1 for single precision floating point, and -2 for
+ * double precision floating point
+ */
+ signed gamma_depth;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int gamma_depth_error;
+
+ /**
+ * Non-zero gamma ramp adjustments are supported
+ */
+ int gamma_support;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int gamma_support_error;
+
+ /**
+ * The layout of the subpixels.
+ * You cannot count on this value — especially for CRT:s —
+ * but it is provided anyway as a means of distinguishing monitors.
+ */
+ SubpixelOrder subpixel_order;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int subpixel_order_error;
+
+ /**
+ * Whether there is a monitors connected to the CRTC
+ */
+ int active;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int active_error;
+
+ /**
+ * The name of the connector as designated by the display
+ * server or as give by this library in case the display
+ * server lacks this feature
+ */
+ std::string *connector_name;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int connector_name_error;
+
+ /**
+ * The type of the connector that is associated with the CRTC
+ */
+ ConnectorType connector_type;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library
+ */
+ int connector_type_error;
+
+ /**
+ * The gamma characteristics of the monitor as reported
+ * in its Extended Display Information Data. The value
+ * holds the value for the red channel. If you do not have
+ * and more accurate measurement of the gamma for the
+ * monitor this could be used to give a rought gamma
+ * correction; simply divide the value with 2.2 and use
+ * the result for the red channel in the gamma correction.
+ */
+ float gamma_red;
+
+ /**
+ * The gamma characteristics of the monitor as reported
+ * in its Extended Display Information Data. The value
+ * holds the value for the green channel. If you do not have
+ * and more accurate measurement of the gamma for the
+ * monitor this could be used to give a rought gamma
+ * correction; simply divide the value with 2.2 and use
+ * the result for the green channel in the gamma correction.
+ */
+ float gamma_green;
+
+ /**
+ * The gamma characteristics of the monitor as reported
+ * in its Extended Display Information Data. The value
+ * holds the value for the blue channel. If you do not have
+ * and more accurate measurement of the gamma for the
+ * monitor this could be used to give a rought gamma
+ * correction; simply divide the value with 2.2 and use
+ * the result for the blue channel in the gamma correction.
+ */
+ float gamma_blue;
+
+ /**
+ * Zero on success, positive it holds the value `errno` had
+ * when the reading failed, otherwise (negative) the value
+ * of an error identifier provided by this library.
+ */
+ int gamma_error;
+
+ };
-namespace libgamma
-{
- /**
- * Cathode ray tube controller information data structure.
- */
- class CRTCInformation;
-
- /**
- * Capabilities of adjustment methods.
- */
- class MethodCapabilities;
-
- /**
- * Site state.
- *
- * On operating systems that integrate a graphical environment
- * there is usually just one site. However, one systems with
- * pluggable graphics, like Unix-like systems such as GNU/Linux
- * and the BSD:s, there can usually be any (feasible) number of
- * sites. In X.org parlance they are called displays.
- */
- class Site;
-
- /**
- * Partition state.
- *
- * Probably the majority of display server only one partition
- * per site. However, X.org can, and traditional used to have
- * on multi-headed environments, multiple partitions per site.
- * In X.org partitions are called 'screens'. It is not to be
- * confused with monitor. A screen is a collection of monitors,
- * and the mapping from monitors to screens is a surjection.
- * On hardware-level adjustment methods, such as Direct
- * Rendering Manager, a partition is a graphics card.
- */
- class Partition;
-
- /**
- * Cathode ray tube controller state.
- *
- * The CRTC controls the gamma ramps for the
- * monitor that is plugged in to the connector
- * that the CRTC belongs to.
- */
- class CRTC;
-
-
-
- /**
- * Capabilities of adjustment methods.
- */
- class MethodCapabilities
- {
- public:
- /**
- * Constructor.
- */
- MethodCapabilities();
-
- /**
- * Constructor.
- *
- * @param caps The information in the native structure.
- */
- MethodCapabilities(libgamma_method_capabilities_t* caps);
-
- /**
- * Copy constructor.
- *
- * @param other The information to copy.
- */
- MethodCapabilities(const MethodCapabilities& other);
-
- /**
- * Destructor.
- */
- ~MethodCapabilities();
-
- /**
- * Copy operator.
- *
- * @param other The information to copy.
- */
- MethodCapabilities& operator =(const MethodCapabilities& other);
-
-
-
-
- /**
- * OR of the CRTC information fields in `libgamma_crtc_information_t`
- * that may (but can fail) be read successfully.
- */
- int32_t crtc_information;
-
- /**
- * Whether the default site is known, if true the site is integrated
- * to the system or can be determined using environment variables.
- */
- bool default_site_known;
-
- /**
- * Whether the adjustment method supports multiple sites rather
- * than just the default site.
- */
- bool multiple_sites;
-
- /**
- * Whether the adjustment method supports multiple partitions
- * per site.
- */
- bool multiple_partitions;
-
- /**
- * Whether the adjustment method supports multiple CRTC:s
- * per partition per site.
- */
- bool multiple_crtcs;
-
- /**
- * Whether the partition to graphics card is a bijection.
- */
- bool partitions_are_graphics_cards;
-
- /**
- * Whether the adjustment method supports `libgamma_site_restore`.
- */
- bool site_restore;
-
- /**
- * Whether the adjustment method supports `libgamma_partition_restore`.
- */
- bool partition_restore;
-
- /**
- * Whether the adjustment method supports `libgamma_crtc_restore`.
- */
- bool crtc_restore;
-
- /**
- * Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
- * fields in `libgamma_crtc_information_t` will always have the same
- * values as each other for the adjustment method.
- */
- bool identical_gamma_sizes;
-
- /**
- * Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
- * fields in `libgamma_crtc_information_t` will always be filled with the
- * same value for the adjustment method.
- */
- bool fixed_gamma_size;
-
- /**
- * Whether the `gamma_depth` field in `libgamma_crtc_information_t`
- * will always be filled with the same value for the adjustment method.
- */
- bool fixed_gamma_depth;
-
- /**
- * Whether the adjustment method will actually perform adjustments.
- */
- bool real;
-
- /**
- * Whether the adjustment method is implement using a translation layer.
- */
- bool fake;
-
- };
-
-
- /**
- * Types for connectors.
- */
- typedef libgamma_connector_type_t ConnectorType;
-
- /**
- * Orders for subpixels. Currently the possible values are
- * very biased to LCD, Plasma and monochrome monitors.
- */
- typedef libgamma_subpixel_order_t SubpixelOrder;
-
-
- /**
- * Cathode ray tube controller information data structure.
- */
- class CRTCInformation
- {
- public:
- /**
- * Constructor.
- */
- CRTCInformation();
-
- /**
- * Constructor.
- *
- * @param info The information in the native structure.
- */
- CRTCInformation(libgamma_crtc_information_t* info);
-
- /**
- * Copy constructor.
- *
- * @param other The information to copy.
- */
- CRTCInformation(const CRTCInformation& other);
-
- /**
- * Destructor.
- */
- ~CRTCInformation();
-
- /**
- * Copy operator.
- *
- * @param other The information to copy.
- */
- CRTCInformation& operator =(const CRTCInformation& other);
-
-
-
- /**
- * The Extended Display Identification Data associated with
- * the attached monitor. This is raw byte array that is usually
- * 128 bytes long. It is not NUL-terminate, rather its length
- * is stored in `edid_length`.
- */
- unsigned char* edid;
-
- /**
- * The length of `edid`.
- */
- size_t edid_length;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int edid_error;
-
-
- /**
- * The phyical width, in millimetres, of the viewport of the
- * attached monitor, as reported by the adjustment method. This
- * value may be incorrect, which is a known issue with the X
- * server where it is the result of the X server attempting
- * the estimate the size on its own.
- * Zero means that its is not applicable, which is the case
- * for projectors.
- */
- size_t width_mm;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int width_mm_error;
-
-
- /**
- * The phyical height, in millimetres, of the viewport of the
- * attached monitor, as reported by the adjustment method. This
- * value may be incorrect, which is a known issue with the X
- * server where it is the result of the X server attempting
- * the estimate the size on its own.
- * Zero means that its is not applicable, which is the case
- * for projectors.
- */
- size_t height_mm;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int height_mm_error;
-
-
- /**
- * The phyical width, in millimetres, of the viewport of the
- * attached monitor, as reported by it the monitor's Extended
- * Display Information Data. This value can only contain whole
- * centimetres, which means that the result is always zero
- * modulus ten. However, this could change with revisions of
- * the EDID structure.
- * Zero means that its is not applicable, which is the case
- * for projectors.
- */
- size_t width_mm_edid;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int width_mm_edid_error;
-
-
- /**
- * The phyical height, in millimetres, of the viewport of the
- * attached monitor, as reported by it the monitor's Extended
- * Display Information Data. This value can only contain whole
- * centimetres, which means that the result is always zero
- * modulus ten. However, this could change with revisions of
- * the EDID structure.
- * Zero means that its is not applicable, which is the case
- * for projectors.
- */
- size_t height_mm_edid;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int height_mm_edid_error;
-
-
- /**
- * The size of the encoding axis of the red gamma ramp.
- */
- size_t red_gamma_size;
-
- /**
- * The size of the encoding axis of the green gamma ramp.
- */
- size_t green_gamma_size;
-
- /**
- * The size of the encoding axis of the blue gamma ramp.
- */
- size_t blue_gamma_size;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int gamma_size_error;
-
-
- /**
- * The bit-depth of the value axes of gamma ramps,
- * -1 for single precision floating point, and -2 for
- * double precision floating point.
- */
- signed gamma_depth;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int gamma_depth_error;
-
-
- /**
- * Non-zero gamma ramp adjustments are supported.
- */
- int gamma_support;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int gamma_support_error;
-
-
- /**
- * The layout of the subpixels.
- * You cannot count on this value --- especially for CRT:s ---
- * but it is provided anyway as a means of distinguishing monitors.
- */
- SubpixelOrder subpixel_order;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int subpixel_order_error;
-
-
- /**
- * Whether there is a monitors connected to the CRTC.
- */
- int active;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int active_error;
-
-
- /**
- * The name of the connector as designated by the display
- * server or as give by this library in case the display
- * server lacks this feature.
- */
- std::string* connector_name;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int connector_name_error;
-
-
- /**
- * The type of the connector that is associated with the CRTC.
- */
- ConnectorType connector_type;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int connector_type_error;
-
-
- /**
- * The gamma characteristics of the monitor as reported
- * in its Extended Display Information Data. The value
- * holds the value for the red channel. If you do not have
- * and more accurate measurement of the gamma for the
- * monitor this could be used to give a rought gamma
- * correction; simply divide the value with 2.2 and use
- * the result for the red channel in the gamma correction.
- */
- float gamma_red;
-
- /**
- * The gamma characteristics of the monitor as reported
- * in its Extended Display Information Data. The value
- * holds the value for the green channel. If you do not have
- * and more accurate measurement of the gamma for the
- * monitor this could be used to give a rought gamma
- * correction; simply divide the value with 2.2 and use
- * the result for the green channel in the gamma correction.
- */
- float gamma_green;
-
- /**
- * The gamma characteristics of the monitor as reported
- * in its Extended Display Information Data. The value
- * holds the value for the blue channel. If you do not have
- * and more accurate measurement of the gamma for the
- * monitor this could be used to give a rought gamma
- * correction; simply divide the value with 2.2 and use
- * the result for the blue channel in the gamma correction.
- */
- float gamma_blue;
-
- /**
- * Zero on success, positive it holds the value `errno` had
- * when the reading failed, otherwise (negative) the value
- * of an error identifier provided by this library.
- */
- int gamma_error;
-
- };
-
-
-
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Weffc++"
- /* Lets ignore that we do not override the copy constructor
- * and the copy operator. */
+ /* Lets ignore that we do not override the copy constructor
+ * and the copy operator */
#endif
-
- /**
- * One single Gamma ramp.
- */
- template <typename T>
- class Ramp
- {
- public:
- /**
- * Constructor.
- *
- * @param native_ramp The ramp.
- * @param ramp_size The size of the ramp.
- */
- Ramp(T* native_ramp, size_t ramp_size)
- {
- this->ramp = native_ramp;
- this->size = ramp_size;
- }
-
- /**
- * Destructor.
- */
- ~Ramp()
- {
- /* Do nothing */
- }
-
- /**
- * Subscript operator.
- *
- * @param index The index of the stop to set or get.
- * @return A reference to the stop's value.
- */
- T& operator [](size_t index)
- {
- return this->ramp[index];
- }
-
- /**
- * Subscript operator.
- *
- * @param index The index of the stop to get.
- * @return The value of the stop.
- */
- const T& operator [](size_t index) const
- {
- return this->ramp[index];
- }
-
-
-
- /**
- * The size of the ramp.
- */
- size_t size;
-
- /**
- * The ramp (internal data).
- */
- T* ramp;
-
- };
-
-
- /**
- * Gamma ramp structure.
- */
- template <typename T>
- class GammaRamps
- {
- public:
- /**
- * Constructor.
- */
- GammaRamps() :
- red(Ramp<T>(nullptr, 0)),
- green(Ramp<T>(nullptr, 0)),
- blue(Ramp<T>(nullptr, 0)),
- depth(0)
- {
- /* Do nothing. */
- }
-
- /**
- * Constructor.
- *
- * @param red_ramp The red gamma ramp.
- * @param green_ramp The green gamma ramp.
- * @param blue_ramp The blue gamma ramp.
- * @param red_size The size of the gamma ramp for the red channel.
- * @param green_size The size of the gamma ramp for the green channel.
- * @param blue_size The size of the gamma ramp for the blue channel.
- * @param gamma_depth The bit-depth of the gamma ramps, -1 for single precision
- * floating point, and -2 for double precision floating point.
- */
- GammaRamps(T* red_ramp, T* green_ramp, T* blue_ramp,
- size_t red_size, size_t green_size, size_t blue_size, signed gamma_depth) :
- red(Ramp<T>(red_ramp, red_size)),
- green(Ramp<T>(green_ramp, green_size)),
- blue(Ramp<T>(blue_ramp, blue_size)),
- depth(gamma_depth)
- {
- /* Do nothing. */
- }
-
- /**
- * Destructor.
- */
- ~GammaRamps()
- {
- free(this->red.ramp);
- }
-
-
-
- /**
- * The red gamma ramp.
- */
- Ramp<T> red;
-
- /**
- * The green gamma ramp.
- */
- Ramp<T> green;
-
- /**
- * The blue gamma ramp.
- */
- Ramp<T> blue;
-
- /**
- * The bit-depth of the gamma ramps, -1 for single precision
- * floating point, and -2 for double precision floating point.
- */
- signed depth;
-
- };
-
-
-
- /**
- * Site state.
- *
- * On operating systems that integrate a graphical environment
- * there is usually just one site. However, one systems with
- * pluggable graphics, like Unix-like systems such as GNU/Linux
- * and the BSD:s, there can usually be any (feasible) number of
- * sites. In X.org parlance they are called displays.
- */
- class Site
- {
- public:
- /**
- * Constructor.
- */
- Site();
-
- /**
- * Constructor.
- *
- * @param method The adjustment method of the site.
- * @param site The site identifier, will be moved into
- * the structure, must be `delete`:able.
- */
- Site(int method, std::string* site = nullptr);
-
- /**
- * Destructor.
- */
- ~Site();
-
- /**
- * Restore the gamma ramps all CRTC:s with a site to
- * the system settings.
- */
- void restore();
-
-
-
- /**
- * This field specifies, for the methods if this library,
- * which adjustment method (display server and protocol)
- * is used to adjust the gamma ramps.
- */
- int method;
-
- /**
- * The site identifier. It can either be `nullptr` or a string.
- * `nullptr` indicates the default site. On systems like the
- * Unix-like systems, where the graphics are pluggable, this
- * is usually resolved by an environment variable, such as
- * "DISPLAY" for X.org.
- */
- std::string* site;
-
- /**
- * The number of partitions that is available on this site.
- * Probably the majority of display server only one partition
- * per site. However, X.org can, and traditional used to have
- * on multi-headed environments, multiple partitions per site.
- * In X.org partitions are called 'screens'. It is not to be
- * confused with monitor. A screen is a collection of monitors,
- * and the mapping from monitors to screens is a surjection.
- * On hardware-level adjustment methods, such as Direct
- * Rendering Manager, a partition is a graphics card.
- */
- size_t partitions_available;
-
- /**
- * The state in the native structure.
- */
- libgamma_site_state_t* native;
-
- };
-
-
-
- /**
- * Partition state.
- *
- * Probably the majority of display server only one partition
- * per site. However, X.org can, and traditional used to have
- * on multi-headed environments, multiple partitions per site.
- * In X.org partitions are called 'screens'. It is not to be
- * confused with monitor. A screen is a collection of monitors,
- * and the mapping from monitors to screens is a surjection.
- * On hardware-level adjustment methods, such as Direct
- * Rendering Manager, a partition is a graphics card.
- */
- class Partition
- {
- public:
- /**
- * Constructor.
- */
- Partition();
-
- /**
- * Constructor.
- *
- * @param site The site of the partition.
- * @param partition The index of the partition.
- */
- Partition(Site* site, size_t partition);
-
- /**
- * Destructor.
- */
- ~Partition();
-
- /**
- * Restore the gamma ramps all CRTC:s with a partition
- * to the system settings.
- */
- void restore();
-
-
-
- /**
- * The site this partition belongs to.
- */
- Site* site;
-
- /**
- * The index of the partition.
- */
- size_t partition;
-
- /**
- * The number of CRTC:s that are available under this
- * partition. Note that the CRTC:s are not necessarily
- * online.
- */
- size_t crtcs_available;
-
- /**
- * The state in the native structure.
- */
- libgamma_partition_state_t* native;
-
- };
-
-
-
- /**
- * Cathode ray tube controller state.
- *
- * The CRTC controls the gamma ramps for the
- * monitor that is plugged in to the connector
- * that the CRTC belongs to.
- */
- class CRTC
- {
- public:
- /**
- * Constructor.
- */
- CRTC();
-
- /**
- * Constructor.
- *
- * @param partition The partition of the CRTC.
- * @param crtc The index of the CRTC.
- */
- CRTC(Partition* partition, size_t crtc);
-
- /**
- * Destructor.
- */
- ~CRTC();
-
- /**
- * Restore the gamma ramps for a CRTC to the system
- * settings for that CRTC.
- */
- void restore();
-
- /**
- * Read information about a CRTC.
- *
- * @param output Instance of a data structure to fill with the information about the CRTC.
- * @param fields OR:ed identifiers for the information about the CRTC that should be read.
- * @return Whether an error has occurred and is stored in a `*_error` field.
- */
- bool information(CRTCInformation* output, int32_t fields);
-
-#define __LIBGAMMA_GET_GAMMA(AFFIX) \
- libgamma_gamma_ramps ## AFFIX ## _t ramps_; \
- int r; \
- ramps_.red = ramps->red.ramp; \
- ramps_.green = ramps->green.ramp; \
- ramps_.blue = ramps->blue.ramp; \
- ramps_.red_size = ramps->red.size; \
- ramps_.green_size = ramps->green.size; \
- ramps_.blue_size = ramps->blue.size; \
- r = libgamma_crtc_get_gamma_ramps ## AFFIX(this->native, &ramps_); \
- if (r != 0) \
- throw create_error(r)
-
- /**
- * Get the current gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void get_gamma(GammaRamps<uint8_t>* ramps)
- {
- __LIBGAMMA_GET_GAMMA(8);
- }
-
- /**
- * Get the current gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void get_gamma(GammaRamps<uint16_t>* ramps)
- {
- __LIBGAMMA_GET_GAMMA(16);
- }
-
- /**
- * Get the current gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void get_gamma(GammaRamps<uint32_t>* ramps)
- {
- __LIBGAMMA_GET_GAMMA(32);
- }
-
- /**
- * Get the current gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void get_gamma(GammaRamps<uint64_t>* ramps)
- {
- __LIBGAMMA_GET_GAMMA(64);
- }
-
- /**
- * Get the current gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void get_gamma(GammaRamps<float>* ramps)
- {
- __LIBGAMMA_GET_GAMMA(f);
- }
-
- /**
- * Get the current gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void get_gamma(GammaRamps<double>* ramps)
- {
- __LIBGAMMA_GET_GAMMA(d);
- }
-
-#undef __LIBGAMMA_GET_GAMMA
-
-#define __LIBGAMMA_SET_GAMMA(AFFIX) \
- libgamma_gamma_ramps ## AFFIX ## _t ramps_; \
- int r; \
- ramps_.red = ramps->red.ramp; \
- ramps_.green = ramps->green.ramp; \
- ramps_.blue = ramps->blue.ramp; \
- ramps_.red_size = ramps->red.size; \
- ramps_.green_size = ramps->green.size; \
- ramps_.blue_size = ramps->blue.size; \
- r = libgamma_crtc_set_gamma_ramps ## AFFIX(this->native, ramps_); \
- if (r != 0) \
- throw create_error(r)
-
- /**
- * Set gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void set_gamma(GammaRamps<uint8_t>* ramps)
- {
- __LIBGAMMA_SET_GAMMA(8);
- }
-
- /**
- * Set gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void set_gamma(GammaRamps<uint16_t>* ramps)
- {
- __LIBGAMMA_SET_GAMMA(16);
- }
-
- /**
- * Set gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void set_gamma(GammaRamps<uint32_t>* ramps)
- {
- __LIBGAMMA_SET_GAMMA(32);
- }
-
- /**
- * Set gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void set_gamma(GammaRamps<uint64_t>* ramps)
- {
- __LIBGAMMA_SET_GAMMA(64);
- }
-
- /**
- * Set gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void set_gamma(GammaRamps<float>* ramps)
- {
- __LIBGAMMA_SET_GAMMA(f);
- }
-
- /**
- * Set gamma ramps for the CRTC.
- *
- * @param ramps The gamma ramps to fill with the current values.
- */
- void set_gamma(GammaRamps<double>* ramps)
- {
- __LIBGAMMA_SET_GAMMA(d);
- }
-
-#undef __LIBGAMMA_SET_GAMMA
-
-
-
- /**
- * The partition this CRTC belongs to.
- */
- Partition* partition;
-
- /**
- * The index of the CRTC within its partition.
- */
- size_t crtc;
-
- /**
- * The state in the native structure.
- */
- libgamma_crtc_state_t* native;
-
- };
-
+
+ /**
+ * One single Gamma ramp
+ */
+ template <typename T>
+ class Ramp
+ {
+ public:
+ /**
+ * Constructor
+ *
+ * @param native_ramp The ramp
+ * @param ramp_size The size of the ramp
+ */
+ Ramp(T *native_ramp, size_t ramp_size)
+ {
+ this->ramp = native_ramp;
+ this->size = ramp_size;
+ }
+
+ /**
+ * Destructor
+ */
+ ~Ramp()
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Subscript operator
+ *
+ * @param index The index of the stop to set or get
+ * @return A reference to the stop's value
+ */
+ T &
+ operator [](size_t index)
+ {
+ return this->ramp[index];
+ }
+
+ /**
+ * Subscript operator
+ *
+ * @param index The index of the stop to get
+ * @return The value of the stop
+ */
+ const T &
+ operator [](size_t index) const
+ {
+ return this->ramp[index];
+ }
+
+ /**
+ * The size of the ramp
+ */
+ size_t size;
+
+ /**
+ * The ramp (internal data)
+ */
+ T *ramp;
+ };
+
+
+ /**
+ * Gamma ramp structure
+ */
+ template <typename T>
+ class GammaRamps
+ {
+ public:
+ /**
+ * Constructor
+ */
+ GammaRamps() :
+ red(Ramp<T>(nullptr, 0)),
+ green(Ramp<T>(nullptr, 0)),
+ blue(Ramp<T>(nullptr, 0)),
+ depth(0)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Constructor
+ *
+ * @param red_ramp The red gamma ramp
+ * @param green_ramp The green gamma ramp
+ * @param blue_ramp The blue gamma ramp
+ * @param red_size The size of the gamma ramp for the red channel
+ * @param green_size The size of the gamma ramp for the green channel
+ * @param blue_size The size of the gamma ramp for the blue channel
+ * @param gamma_depth The bit-depth of the gamma ramps, -1 for single precision
+ * floating point, and -2 for double precision floating point
+ */
+ GammaRamps(T *red_ramp, T *green_ramp, T *blue_ramp, size_t red_size,
+ size_t green_size, size_t blue_size, signed gamma_depth) :
+ red(Ramp<T>(red_ramp, red_size)),
+ green(Ramp<T>(green_ramp, green_size)),
+ blue(Ramp<T>(blue_ramp, blue_size)),
+ depth(gamma_depth)
+ {
+ /* do nothing */
+ }
+
+ /**
+ * Destructor
+ */
+ ~GammaRamps()
+ {
+ free(this->red.ramp);
+ }
+
+
+ /**
+ * The red gamma ramp
+ */
+ Ramp<T> red;
+
+ /**
+ * The green gamma ramp
+ */
+ Ramp<T> green;
+
+ /**
+ * The blue gamma ramp
+ */
+ Ramp<T> blue;
+
+ /**
+ * The bit-depth of the gamma ramps, -1 for single precision
+ * floating point, and -2 for double precision floating point
+ */
+ signed depth;
+ };
+
+
+ /**
+ * Site state
+ *
+ * On operating systems that integrate a graphical environment
+ * there is usually just one site. However, one systems with
+ * pluggable graphics, like Unix-like systems such as GNU/Linux
+ * and the BSD:s, there can usually be any (feasible) number of
+ * sites. In X.org parlance they are called displays.
+ */
+ class Site
+ {
+ public:
+ /**
+ * Constructor
+ */
+ Site();
+
+ /**
+ * Constructor
+ *
+ * @param method The adjustment method of the site
+ * @param site The site identifier, will be moved into
+ * the structure, must be `delete`:able
+ */
+ Site(int method, std::string *site = nullptr);
+
+ /**
+ * Destructor
+ */
+ ~Site();
+
+ /**
+ * Restore the gamma ramps all CRTC:s with a site to
+ * the system settings
+ */
+ void restore();
+
+ /**
+ * This field specifies, for the methods if this library,
+ * which adjustment method (display server and protocol)
+ * is used to adjust the gamma ramps
+ */
+ int method;
+
+ /**
+ * The site identifier. It can either be `nullptr` or a string.
+ * `nullptr` indicates the default site. On systems like the
+ * Unix-like systems, where the graphics are pluggable, this
+ * is usually resolved by an environment variable, such as
+ * "DISPLAY" for X.org.
+ */
+ std::string *site;
+
+ /**
+ * The number of partitions that is available on this site.
+ * Probably the majority of display server only one partition
+ * per site. However, X.org can, and traditional used to have
+ * on multi-headed environments, multiple partitions per site.
+ * In X.org partitions are called 'screens'. It is not to be
+ * confused with monitor. A screen is a collection of monitors,
+ * and the mapping from monitors to screens is a surjection.
+ * On hardware-level adjustment methods, such as Direct
+ * Rendering Manager, a partition is a graphics card.
+ */
+ size_t partitions_available;
+
+ /**
+ * The state in the native structure
+ */
+ libgamma_site_state_t *native;
+ };
+
+
+ /**
+ * Partition state
+ *
+ * Probably the majority of display server only one partition
+ * per site. However, X.org can, and traditional used to have
+ * on multi-headed environments, multiple partitions per site.
+ * In X.org partitions are called 'screens'. It is not to be
+ * confused with monitor. A screen is a collection of monitors,
+ * and the mapping from monitors to screens is a surjection.
+ * On hardware-level adjustment methods, such as Direct
+ * Rendering Manager, a partition is a graphics card.
+ */
+ class Partition
+ {
+ public:
+ /**
+ * Constructor
+ */
+ Partition();
+
+ /**
+ * Constructor
+ *
+ * @param site The site of the partition
+ * @param partition The index of the partition
+ */
+ Partition(Site *site, size_t partition);
+
+ /**
+ * Destructor
+ */
+ ~Partition();
+
+ /**
+ * Restore the gamma ramps all CRTC:s with a partition
+ * to the system settings
+ */
+ void restore();
+
+ /**
+ * The site this partition belongs to
+ */
+ Site *site;
+
+ /**
+ * The index of the partition
+ */
+ size_t partition;
+
+ /**
+ * The number of CRTC:s that are available under this
+ * partition. Note that the CRTC:s are not necessarily
+ * online.
+ */
+ size_t crtcs_available;
+
+ /**
+ * The state in the native structure
+ */
+ libgamma_partition_state_t *native;
+ };
+
+
+ /**
+ * Cathode ray tube controller state
+ *
+ * The CRTC controls the gamma ramps for the
+ * monitor that is plugged in to the connector
+ * that the CRTC belongs to
+ */
+ class CRTC
+ {
+ public:
+ /**
+ * Constructor
+ */
+ CRTC();
+
+ /**
+ * Constructor
+ *
+ * @param partition The partition of the CRTC
+ * @param crtc The index of the CRTC
+ */
+ CRTC(Partition *partition, size_t crtc);
+
+ /**
+ * Destructor
+ */
+ ~CRTC();
+
+ /**
+ * Restore the gamma ramps for a CRTC to the system
+ * settings for that CRTC
+ */
+ void restore();
+
+ /**
+ * Read information about a CRTC
+ *
+ * @param output Instance of a data structure to fill with the information about the CRTC
+ * @param fields OR:ed identifiers for the information about the CRTC that should be read
+ * @return Whether an error has occurred and is stored in a `*_error` field
+ */
+ bool information(CRTCInformation *output, int32_t fields);
+
+#define LIBGAMMAMM_GET_GAMMA__(AFFIX)\
+ libgamma_gamma_ramps##AFFIX##_t ramps_;\
+ int r;\
+ ramps_.red = ramps->red.ramp;\
+ ramps_.green = ramps->green.ramp;\
+ ramps_.blue = ramps->blue.ramp;\
+ ramps_.red_size = ramps->red.size;\
+ ramps_.green_size = ramps->green.size;\
+ ramps_.blue_size = ramps->blue.size;\
+ r = libgamma_crtc_get_gamma_ramps##AFFIX(this->native, &ramps_);\
+ if (r)\
+ throw create_error(r)
+
+ /**
+ * Get the current gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ get_gamma(GammaRamps<uint8_t> *ramps)
+ {
+ LIBGAMMAMM_GET_GAMMA__(8);
+ }
+
+ /**
+ * Get the current gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ get_gamma(GammaRamps<uint16_t> *ramps)
+ {
+ LIBGAMMAMM_GET_GAMMA__(16);
+ }
+
+ /**
+ * Get the current gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ get_gamma(GammaRamps<uint32_t> *ramps)
+ {
+ LIBGAMMAMM_GET_GAMMA__(32);
+ }
+
+ /**
+ * Get the current gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ get_gamma(GammaRamps<uint64_t> *ramps)
+ {
+ LIBGAMMAMM_GET_GAMMA__(64);
+ }
+
+ /**
+ * Get the current gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void get_gamma(GammaRamps<float> *ramps)
+ {
+ LIBGAMMAMM_GET_GAMMA__(f);
+ }
+
+ /**
+ * Get the current gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void get_gamma(GammaRamps<double> *ramps)
+ {
+ LIBGAMMAMM_GET_GAMMA__(d);
+ }
+
+#undef LIBGAMMAMM_GET_GAMMA__
+
+#define LIBGAMMAMM_SET_GAMMA__(AFFIX)\
+ libgamma_gamma_ramps##AFFIX##_t ramps_;\
+ int r;\
+ ramps_.red = ramps->red.ramp;\
+ ramps_.green = ramps->green.ramp;\
+ ramps_.blue = ramps->blue.ramp;\
+ ramps_.red_size = ramps->red.size;\
+ ramps_.green_size = ramps->green.size;\
+ ramps_.blue_size = ramps->blue.size;\
+ r = libgamma_crtc_set_gamma_ramps##AFFIX(this->native, ramps_);\
+ if (r)\
+ throw create_error(r)
+
+ /**
+ * Set gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ set_gamma(GammaRamps<uint8_t> *ramps)
+ {
+ LIBGAMMAMM_SET_GAMMA__(8);
+ }
+
+ /**
+ * Set gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ set_gamma(GammaRamps<uint16_t> *ramps)
+ {
+ LIBGAMMAMM_SET_GAMMA__(16);
+ }
+
+ /**
+ * Set gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ set_gamma(GammaRamps<uint32_t> *ramps)
+ {
+ LIBGAMMAMM_SET_GAMMA__(32);
+ }
+
+ /**
+ * Set gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ set_gamma(GammaRamps<uint64_t> *ramps)
+ {
+ LIBGAMMAMM_SET_GAMMA__(64);
+ }
+
+ /**
+ * Set gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ set_gamma(GammaRamps<float> *ramps)
+ {
+ LIBGAMMAMM_SET_GAMMA__(f);
+ }
+
+ /**
+ * Set gamma ramps for the CRTC
+ *
+ * @param ramps The gamma ramps to fill with the current values
+ */
+ void
+ set_gamma(GammaRamps<double> *ramps)
+ {
+ LIBGAMMAMM_SET_GAMMA__(d);
+ }
+
+#undef LIBGAMMAMM_SET_GAMMA__
+
+
+ /**
+ * The partition this CRTC belongs to
+ */
+ Partition *partition;
+
+ /**
+ * The index of the CRTC within its partition
+ */
+ size_t crtc;
+
+ /**
+ * The state in the native structure
+ */
+ libgamma_crtc_state_t *native;
+ };
+
#ifdef __GNUC__
# pragma GCC diagnostic pop
-#endif
-
+#endif
}
-
-#ifndef __GNUC__
-# undef __attribute__
-#endif
-
#endif
-
diff --git a/libgamma-native.hh b/libgamma-native.hh
index f9ded22..81b8e78 100644
--- a/libgamma-native.hh
+++ b/libgamma-native.hh
@@ -2,7 +2,6 @@
#ifndef LIBGAMMA_NATIVE_HH
#define LIBGAMMA_NATIVE_HH
-
extern "C"
{
# ifdef __GNUC__
@@ -21,6 +20,4 @@ extern "C"
# endif
}
-
#endif
-
diff --git a/libgamma.hh b/libgamma.hh
index 0577902..63a8036 100644
--- a/libgamma.hh
+++ b/libgamma.hh
@@ -2,11 +2,8 @@
#ifndef LIBGAMMA_HH
#define LIBGAMMA_HH
-
#include "libgamma-error.hh"
#include "libgamma-method.hh"
#include "libgamma-facade.hh"
-
#endif
-
diff --git a/test.cc b/test.cc
index b8984fb..448741b 100644
--- a/test.cc
+++ b/test.cc
@@ -1,307 +1,294 @@
/* See LICENSE file for copyright and license details. */
#include "libgamma.hh"
-
-#include <iostream>
#include <cstdlib>
+#include <iostream>
#include <unistd.h>
-int main(void)
+int
+main(void)
{
- libgamma::Site* site;
- libgamma::Partition* partition;
- libgamma::CRTC* crtc;
- libgamma::CRTCInformation info;
- libgamma::MethodCapabilities caps;
- libgamma::GammaRamps<uint16_t>* ramps;
- int method;
- size_t i;
-
- uint16_t* saved_red;
- uint16_t* saved_green;
- uint16_t* saved_blue;
-
- std::string* str;
- char* cstr;
- unsigned char* edid;
-
- libgamma::perror("test", 0);
- libgamma::perror("test", 2);
- libgamma::perror("test", -2);
- libgamma::perror("test", LIBGAMMA_ERRNO_SET);
- std::cout << std::endl;
-
- str = libgamma::name_of_error(-2);
- std::cout << *str << std::endl;
- std::cout << libgamma::value_of_error(str) << std::endl;
- delete str;
- str = new std::string("LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD");
- std::cout << libgamma::value_of_error(str) << std::endl;
- delete str;
- std::cout << std::endl;
-
- for (int m : libgamma::list_methods(0))
- std::cout << m << " ";
- std::cout << std::endl;
- for (int m : libgamma::list_methods(1))
- std::cout << m << " ";
- std::cout << std::endl;
- for (int m : libgamma::list_methods(2))
- std::cout << m << " ";
- std::cout << std::endl;
- for (int m : libgamma::list_methods(3))
- std::cout << m << " ";
- std::cout << std::endl;
- for (int m : libgamma::list_methods(4))
- std::cout << m << " ";
- std::cout << std::endl;
- std::cout << std::endl;
- method = libgamma::list_methods(0)[0];
-
- std::cout << libgamma::is_method_available(LIBGAMMA_METHOD_X_RANDR) << std::endl;
- str = libgamma::method_default_site(LIBGAMMA_METHOD_X_RANDR);
- if (str == nullptr)
- std::cout << "(nullptr)" << std::endl;
- else
- std::cout << *str << std::endl;
- delete str;
- str = libgamma::method_default_site_variable(LIBGAMMA_METHOD_X_RANDR);
- if (str == nullptr)
- std::cout << "(nullptr)" << std::endl;
- else
- std::cout << *str << std::endl;
- delete str;
- std::cout << std::endl;
-
- edid = libgamma::unhex_edid("0123456789abcdef");
- cstr = libgamma_behex_edid(edid, 8);
- std::cout << cstr << std::endl;
- free(cstr);
- std::cout << libgamma::behex_edid(edid, 8) << std::endl;
- std::cout << libgamma::behex_edid_lowercase(edid, 8) << std::endl;
- std::cout << libgamma::behex_edid_uppercase(edid, 8) << std::endl;
- free(edid);
- std::cout << std::endl;
-
- site = new libgamma::Site(method, new std::string(":0"));
- std::cout << site->partitions_available << std::endl;
- partition = new libgamma::Partition(site, 0);
- std::cout << partition->crtcs_available << std::endl;
- crtc = new libgamma::CRTC(partition, 0);
- std::cout << crtc->information(&info, ~0) << std::endl;
- std::cout << std::endl;
-
- cstr = libgamma_behex_edid(info.edid, info.edid_length);
- std::cout << "edid: " << cstr << std::endl;
- free(cstr);
- std::cout << "edid_length: " << info.edid_length << std::endl;
- std::cout << "edid_error: " << info.edid_error << std::endl;
- std::cout << "width_mm: " << info.width_mm << std::endl;
- std::cout << "width_mm_error: " << info.width_mm_error << std::endl;
- std::cout << "height_mm: " << info.height_mm << std::endl;
- std::cout << "height_mm_error: " << info.height_mm_error << std::endl;
- std::cout << "width_mm_edid: " << info.width_mm_edid << std::endl;
- std::cout << "width_mm_edid_error: " << info.width_mm_edid_error << std::endl;
- std::cout << "height_mm_edid: " << info.height_mm_edid << std::endl;
- std::cout << "height_mm_edid_error: " << info.height_mm_edid_error << std::endl;
- std::cout << "red_gamma_size: " << info.red_gamma_size << std::endl;
- std::cout << "green_gamma_size: " << info.green_gamma_size << std::endl;
- std::cout << "blue_gamma_size: " << info.blue_gamma_size << std::endl;
- std::cout << "gamma_size_error: " << info.gamma_size_error << std::endl;
- std::cout << "gamma_depth: " << info.gamma_depth << std::endl;
- std::cout << "gamma_depth_error: " << info.gamma_depth_error << std::endl;
- std::cout << "gamma_support: " << info.gamma_support << std::endl;
- std::cout << "gamma_support_error: " << info.gamma_support_error << std::endl;
- std::cout << "subpixel_order: " << info.subpixel_order << std::endl;
- std::cout << "subpixel_order_error: " << info.subpixel_order_error << std::endl;
- std::cout << "active: " << info.active << std::endl;
- std::cout << "active_error: " << info.active_error << std::endl;
- if (info.connector_name == nullptr)
- std::cout << "connector_name: " << "(nullptr)" << std::endl;
- else
- std::cout << "connector_name: " << *(info.connector_name) << std::endl;
- std::cout << "connector_name_error: " << info.connector_name_error << std::endl;
- std::cout << "connector_type: " << info.connector_type << std::endl;
- std::cout << "connector_type_error: " << info.connector_type_error << std::endl;
- std::cout << "gamma_red: " << info.gamma_red << std::endl;
- std::cout << "gamma_green: " << info.gamma_green << std::endl;
- std::cout << "gamma_blue: " << info.gamma_blue << std::endl;
- std::cout << "gamma_error: " << info.gamma_error << std::endl;
- std::cout << std::endl;
-
- libgamma::method_capabilities(&caps, method);
- std::cout << "crtc_information: " << caps.crtc_information << std::endl;
- std::cout << "default_site_known: " << caps.default_site_known << std::endl;
- std::cout << "multiple_sites: " << caps.multiple_sites << std::endl;
- std::cout << "multiple_partitions: " << caps.multiple_partitions << std::endl;
- std::cout << "multiple_crtcs: " << caps.multiple_crtcs << std::endl;
- std::cout << "partitions_are_graphics_cards: " << caps.partitions_are_graphics_cards << std::endl;
- std::cout << "site_restore: " << caps.site_restore << std::endl;
- std::cout << "partition_restore: " << caps.partition_restore << std::endl;
- std::cout << "crtc_restore: " << caps.crtc_restore << std::endl;
- std::cout << "identical_gamma_sizes: " << caps.identical_gamma_sizes << std::endl;
- std::cout << "fixed_gamma_size: " << caps.fixed_gamma_size << std::endl;
- std::cout << "fixed_gamma_depth: " << caps.fixed_gamma_depth << std::endl;
- std::cout << "real: " << caps.real << std::endl;
- std::cout << "fake: " << caps.fake << std::endl;
- std::cout << std::endl;
-
- std::cout << libgamma::group_gid << std::endl;
- libgamma::group_gid = 10;
- std::cout << libgamma::group_gid << std::endl;
- std::cout << std::endl;
-
- if (libgamma::group_name == nullptr)
- std::cout << "(nullptr)" << std::endl;
- else
- std::cout << libgamma::group_name << std::endl;
- libgamma::group_name = "test-group";
- if (libgamma::group_name == nullptr)
- std::cout << "(nullptr)" << std::endl;
- else
- std::cout << libgamma::group_name << std::endl;
- std::cout << std::endl;
-
- ramps = libgamma::gamma_ramps16_create(info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size);
- std::cout << ramps->red.size << " "
- << ramps->green.size << " "
- << ramps->blue.size << std::endl;
- std::cout << ramps->depth << std::endl;
- std::cout << std::endl;
-
- saved_red = new uint16_t[ramps->red.size];
- saved_green = new uint16_t[ramps->green.size];
- saved_blue = new uint16_t[ramps->blue.size];
-
- crtc->get_gamma(ramps);
-
- for (i = 0; i < ramps->red.size; i++)
- {
- std::cout << ramps->red[i] << " ";
- saved_red[i] = ramps->red[i];
- ramps->red[i] /= 2;
- }
- std::cout << std::endl;
- std::cout << std::endl;
-
- for (i = 0; i < ramps->green.size; i++)
- {
- std::cout << ramps->green[i] << " ";
- saved_green[i] = ramps->green[i];
- ramps->green[i] /= 2;
- }
- std::cout << std::endl;
- std::cout << std::endl;
-
- for (i = 0; i < ramps->blue.size; i++)
- {
- std::cout << ramps->blue[i] << " ";
- saved_blue[i] = ramps->blue[i];
- ramps->blue[i] /= 2;
- }
- std::cout << std::endl;
- std::cout << std::endl;
-
- crtc->set_gamma(ramps);
-
- sleep(1);
-
- for (i = 0; i < ramps->red.size; i++)
- ramps->red[i] = saved_red[i];
- for (i = 0; i < ramps->green.size; i++)
- ramps->green[i] = saved_green[i];
- for (i = 0; i < ramps->blue.size; i++)
- ramps->blue[i] = saved_blue[i];
-
- crtc->set_gamma(ramps);
-
- delete [] saved_red;
- delete [] saved_green;
- delete [] saved_blue;
- delete ramps;
-
- sleep(1);
-
- ramps = new libgamma::GammaRamps<uint16_t>();
- libgamma::gamma_ramps16_initialise(ramps, info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size);
- std::cout << ramps->red.size << " "
- << ramps->green.size << " "
- << ramps->blue.size << std::endl;
- std::cout << ramps->depth << std::endl;
- std::cout << std::endl;
-
- saved_red = new uint16_t[ramps->red.size];
- saved_green = new uint16_t[ramps->green.size];
- saved_blue = new uint16_t[ramps->blue.size];
-
- crtc->get_gamma(ramps);
-
- for (i = 0; i < ramps->red.size; i++)
- {
- std::cout << ramps->red[i] << " ";
- saved_red[i] = ramps->red[i];
- ramps->red[i] /= 2;
- }
- std::cout << std::endl;
- std::cout << std::endl;
-
- for (i = 0; i < ramps->green.size; i++)
- {
- std::cout << ramps->green[i] << " ";
- saved_green[i] = ramps->green[i];
- ramps->green[i] /= 2;
- }
- std::cout << std::endl;
- std::cout << std::endl;
-
- for (i = 0; i < ramps->blue.size; i++)
- {
- std::cout << ramps->blue[i] << " ";
- saved_blue[i] = ramps->blue[i];
- ramps->blue[i] /= 2;
- }
- std::cout << std::endl;
- std::cout << std::endl;
-
- crtc->set_gamma(ramps);
-
- sleep(1);
-
- for (i = 0; i < ramps->red.size; i++)
- ramps->red[i] = saved_red[i];
- for (i = 0; i < ramps->green.size; i++)
- ramps->green[i] = saved_green[i];
- for (i = 0; i < ramps->blue.size; i++)
- ramps->blue[i] = saved_blue[i];
-
- crtc->set_gamma(ramps);
-
- delete [] saved_red;
- delete [] saved_green;
- delete [] saved_blue;
- delete ramps;
-
- delete crtc;
- delete partition;
- delete site;
-
- try
- {
- throw libgamma::create_error(EIO);
- }
- catch (const libgamma::LibgammaException& err)
- {
- std::cout << err.what() << std::endl;
- }
- try
- {
- throw libgamma::create_error(LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD);
- }
- catch (const libgamma::LibgammaException& err)
- {
- std::cout << err.what() << std::endl;
- }
-
- return 0;
-}
+ libgamma::Site *site;
+ libgamma::Partition *partition;
+ libgamma::CRTC *crtc;
+ libgamma::CRTCInformation info;
+ libgamma::MethodCapabilities caps;
+ libgamma::GammaRamps<uint16_t> *ramps;
+ int method;
+ size_t i;
+
+ uint16_t *saved_red;
+ uint16_t *saved_green;
+ uint16_t *saved_blue;
+
+ std::string *str;
+ char *cstr;
+ unsigned char *edid;
+
+ libgamma::perror("test", 0);
+ libgamma::perror("test", 2);
+ libgamma::perror("test", -2);
+ libgamma::perror("test", LIBGAMMA_ERRNO_SET);
+ std::cout << std::endl;
+
+ str = libgamma::name_of_error(-2);
+ std::cout << *str << std::endl;
+ std::cout << libgamma::value_of_error(str) << std::endl;
+ delete str;
+ str = new std::string("LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD");
+ std::cout << libgamma::value_of_error(str) << std::endl;
+ delete str;
+ std::cout << std::endl;
+
+ for (int m : libgamma::list_methods(0))
+ std::cout << m << " ";
+ std::cout << std::endl;
+ for (int m : libgamma::list_methods(1))
+ std::cout << m << " ";
+ std::cout << std::endl;
+ for (int m : libgamma::list_methods(2))
+ std::cout << m << " ";
+ std::cout << std::endl;
+ for (int m : libgamma::list_methods(3))
+ std::cout << m << " ";
+ std::cout << std::endl;
+ for (int m : libgamma::list_methods(4))
+ std::cout << m << " ";
+ std::cout << std::endl;
+ std::cout << std::endl;
+ method = libgamma::list_methods(0)[0];
+
+ std::cout << libgamma::is_method_available(LIBGAMMA_METHOD_X_RANDR) << std::endl;
+ str = libgamma::method_default_site(LIBGAMMA_METHOD_X_RANDR);
+ if (str == nullptr)
+ std::cout << "(nullptr)" << std::endl;
+ else
+ std::cout << *str << std::endl;
+ delete str;
+ str = libgamma::method_default_site_variable(LIBGAMMA_METHOD_X_RANDR);
+ if (str == nullptr)
+ std::cout << "(nullptr)" << std::endl;
+ else
+ std::cout << *str << std::endl;
+ delete str;
+ std::cout << std::endl;
+
+ edid = libgamma::unhex_edid("0123456789abcdef");
+ cstr = libgamma_behex_edid(edid, 8);
+ std::cout << cstr << std::endl;
+ free(cstr);
+ std::cout << libgamma::behex_edid(edid, 8) << std::endl;
+ std::cout << libgamma::behex_edid_lowercase(edid, 8) << std::endl;
+ std::cout << libgamma::behex_edid_uppercase(edid, 8) << std::endl;
+ free(edid);
+ std::cout << std::endl;
+
+ site = new libgamma::Site(method, new std::string(":0"));
+ std::cout << site->partitions_available << std::endl;
+ partition = new libgamma::Partition(site, 0);
+ std::cout << partition->crtcs_available << std::endl;
+ crtc = new libgamma::CRTC(partition, 0);
+ std::cout << crtc->information(&info, ~0) << std::endl;
+ std::cout << std::endl;
+
+ cstr = libgamma_behex_edid(info.edid, info.edid_length);
+ std::cout << "edid: " << cstr << std::endl;
+ free(cstr);
+ std::cout << "edid_length: " << info.edid_length << std::endl;
+ std::cout << "edid_error: " << info.edid_error << std::endl;
+ std::cout << "width_mm: " << info.width_mm << std::endl;
+ std::cout << "width_mm_error: " << info.width_mm_error << std::endl;
+ std::cout << "height_mm: " << info.height_mm << std::endl;
+ std::cout << "height_mm_error: " << info.height_mm_error << std::endl;
+ std::cout << "width_mm_edid: " << info.width_mm_edid << std::endl;
+ std::cout << "width_mm_edid_error: " << info.width_mm_edid_error << std::endl;
+ std::cout << "height_mm_edid: " << info.height_mm_edid << std::endl;
+ std::cout << "height_mm_edid_error: " << info.height_mm_edid_error << std::endl;
+ std::cout << "red_gamma_size: " << info.red_gamma_size << std::endl;
+ std::cout << "green_gamma_size: " << info.green_gamma_size << std::endl;
+ std::cout << "blue_gamma_size: " << info.blue_gamma_size << std::endl;
+ std::cout << "gamma_size_error: " << info.gamma_size_error << std::endl;
+ std::cout << "gamma_depth: " << info.gamma_depth << std::endl;
+ std::cout << "gamma_depth_error: " << info.gamma_depth_error << std::endl;
+ std::cout << "gamma_support: " << info.gamma_support << std::endl;
+ std::cout << "gamma_support_error: " << info.gamma_support_error << std::endl;
+ std::cout << "subpixel_order: " << info.subpixel_order << std::endl;
+ std::cout << "subpixel_order_error: " << info.subpixel_order_error << std::endl;
+ std::cout << "active: " << info.active << std::endl;
+ std::cout << "active_error: " << info.active_error << std::endl;
+ if (info.connector_name == nullptr)
+ std::cout << "connector_name: " << "(nullptr)" << std::endl;
+ else
+ std::cout << "connector_name: " << *(info.connector_name) << std::endl;
+ std::cout << "connector_name_error: " << info.connector_name_error << std::endl;
+ std::cout << "connector_type: " << info.connector_type << std::endl;
+ std::cout << "connector_type_error: " << info.connector_type_error << std::endl;
+ std::cout << "gamma_red: " << info.gamma_red << std::endl;
+ std::cout << "gamma_green: " << info.gamma_green << std::endl;
+ std::cout << "gamma_blue: " << info.gamma_blue << std::endl;
+ std::cout << "gamma_error: " << info.gamma_error << std::endl;
+ std::cout << std::endl;
+
+ libgamma::method_capabilities(&caps, method);
+ std::cout << "crtc_information: " << caps.crtc_information << std::endl;
+ std::cout << "default_site_known: " << caps.default_site_known << std::endl;
+ std::cout << "multiple_sites: " << caps.multiple_sites << std::endl;
+ std::cout << "multiple_partitions: " << caps.multiple_partitions << std::endl;
+ std::cout << "multiple_crtcs: " << caps.multiple_crtcs << std::endl;
+ std::cout << "partitions_are_graphics_cards: " << caps.partitions_are_graphics_cards << std::endl;
+ std::cout << "site_restore: " << caps.site_restore << std::endl;
+ std::cout << "partition_restore: " << caps.partition_restore << std::endl;
+ std::cout << "crtc_restore: " << caps.crtc_restore << std::endl;
+ std::cout << "identical_gamma_sizes: " << caps.identical_gamma_sizes << std::endl;
+ std::cout << "fixed_gamma_size: " << caps.fixed_gamma_size << std::endl;
+ std::cout << "fixed_gamma_depth: " << caps.fixed_gamma_depth << std::endl;
+ std::cout << "real: " << caps.real << std::endl;
+ std::cout << "fake: " << caps.fake << std::endl;
+ std::cout << std::endl;
+
+ std::cout << libgamma::group_gid << std::endl;
+ libgamma::group_gid = 10;
+ std::cout << libgamma::group_gid << std::endl;
+ std::cout << std::endl;
+
+ if (libgamma::group_name == nullptr)
+ std::cout << "(nullptr)" << std::endl;
+ else
+ std::cout << libgamma::group_name << std::endl;
+ libgamma::group_name = "test-group";
+ if (libgamma::group_name == nullptr)
+ std::cout << "(nullptr)" << std::endl;
+ else
+ std::cout << libgamma::group_name << std::endl;
+ std::cout << std::endl;
+
+ ramps = libgamma::gamma_ramps16_create(info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size);
+ std::cout << ramps->red.size << " "
+ << ramps->green.size << " "
+ << ramps->blue.size << std::endl;
+ std::cout << ramps->depth << std::endl;
+ std::cout << std::endl;
+
+ saved_red = new uint16_t[ramps->red.size];
+ saved_green = new uint16_t[ramps->green.size];
+ saved_blue = new uint16_t[ramps->blue.size];
+
+ crtc->get_gamma(ramps);
+
+ for (i = 0; i < ramps->red.size; i++) {
+ std::cout << ramps->red[i] << " ";
+ saved_red[i] = ramps->red[i];
+ ramps->red[i] /= 2;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ for (i = 0; i < ramps->green.size; i++) {
+ std::cout << ramps->green[i] << " ";
+ saved_green[i] = ramps->green[i];
+ ramps->green[i] /= 2;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+ for (i = 0; i < ramps->blue.size; i++) {
+ std::cout << ramps->blue[i] << " ";
+ saved_blue[i] = ramps->blue[i];
+ ramps->blue[i] /= 2;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ crtc->set_gamma(ramps);
+
+ sleep(1);
+
+ for (i = 0; i < ramps->red.size; i++)
+ ramps->red[i] = saved_red[i];
+ for (i = 0; i < ramps->green.size; i++)
+ ramps->green[i] = saved_green[i];
+ for (i = 0; i < ramps->blue.size; i++)
+ ramps->blue[i] = saved_blue[i];
+
+ crtc->set_gamma(ramps);
+
+ delete[] saved_red;
+ delete[] saved_green;
+ delete[] saved_blue;
+ delete ramps;
+
+ sleep(1);
+
+ ramps = new libgamma::GammaRamps<uint16_t>();
+ libgamma::gamma_ramps16_initialise(ramps, info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size);
+ std::cout << ramps->red.size << " "
+ << ramps->green.size << " "
+ << ramps->blue.size << std::endl;
+ std::cout << ramps->depth << std::endl;
+ std::cout << std::endl;
+
+ saved_red = new uint16_t[ramps->red.size];
+ saved_green = new uint16_t[ramps->green.size];
+ saved_blue = new uint16_t[ramps->blue.size];
+
+ crtc->get_gamma(ramps);
+
+ for (i = 0; i < ramps->red.size; i++) {
+ std::cout << ramps->red[i] << " ";
+ saved_red[i] = ramps->red[i];
+ ramps->red[i] /= 2;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ for (i = 0; i < ramps->green.size; i++) {
+ std::cout << ramps->green[i] << " ";
+ saved_green[i] = ramps->green[i];
+ ramps->green[i] /= 2;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ for (i = 0; i < ramps->blue.size; i++) {
+ std::cout << ramps->blue[i] << " ";
+ saved_blue[i] = ramps->blue[i];
+ ramps->blue[i] /= 2;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ crtc->set_gamma(ramps);
+
+ sleep(1);
+
+ for (i = 0; i < ramps->red.size; i++)
+ ramps->red[i] = saved_red[i];
+ for (i = 0; i < ramps->green.size; i++)
+ ramps->green[i] = saved_green[i];
+ for (i = 0; i < ramps->blue.size; i++)
+ ramps->blue[i] = saved_blue[i];
+
+ crtc->set_gamma(ramps);
+
+ delete[] saved_red;
+ delete[] saved_green;
+ delete[] saved_blue;
+ delete ramps;
+
+ delete crtc;
+ delete partition;
+ delete site;
+
+ try {
+ throw libgamma::create_error(EIO);
+ } catch (const libgamma::LibgammaException &err) {
+ std::cout << err.what() << std::endl;
+ }
+ try {
+ throw libgamma::create_error(LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD);
+ } catch (const libgamma::LibgammaException &err) {
+ std::cout << err.what() << std::endl;
+ }
+
+ return 0;
+}