diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-09-03 19:12:59 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-09-03 19:12:59 +0200 |
commit | ae6072ece6ac02a0d2438d110af90cf6ca2f3f50 (patch) | |
tree | b27c31cfe1cb02cf865e23d639c7c06a234b2f56 | |
parent | libgamma_group_gid and libgamma_group_name (diff) | |
download | libgammamm-ae6072ece6ac02a0d2438d110af90cf6ca2f3f50.tar.gz libgammamm-ae6072ece6ac02a0d2438d110af90cf6ca2f3f50.tar.bz2 libgammamm-ae6072ece6ac02a0d2438d110af90cf6ca2f3f50.tar.xz |
gamma ramps and exception class
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/libgamma-error.cc | 49 | ||||
-rw-r--r-- | src/libgamma-error.hh | 43 | ||||
-rw-r--r-- | src/libgamma-facade.cc | 291 | ||||
-rw-r--r-- | src/libgamma-facade.hh | 135 | ||||
-rw-r--r-- | src/libgamma-method.cc | 12 | ||||
-rw-r--r-- | src/libgamma-method.hh | 291 | ||||
-rw-r--r-- | src/test.cc | 17 |
7 files changed, 824 insertions, 14 deletions
diff --git a/src/libgamma-error.cc b/src/libgamma-error.cc index 86ad1fd..951db22 100644 --- a/src/libgamma-error.cc +++ b/src/libgamma-error.cc @@ -16,7 +16,9 @@ * along with this library. If not, see <http://www.gnu.org/licenses/>. */ #include "libgamma-error.hh" + #include <iostream> +#include <cstring> namespace libgamma @@ -73,5 +75,52 @@ namespace libgamma return libgamma_value_of_error(cstr); } + + /** + * 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); + } + + + /** + * 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); + } + } diff --git a/src/libgamma-error.hh b/src/libgamma-error.hh index 5fe1cbc..12550f2 100644 --- a/src/libgamma-error.hh +++ b/src/libgamma-error.hh @@ -20,6 +20,7 @@ #include <string> +#include <exception> #include "libgamma-native.hh" @@ -135,6 +136,48 @@ namespace libgamma */ 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); + } diff --git a/src/libgamma-facade.cc b/src/libgamma-facade.cc index 4937e78..bd6ee28 100644 --- a/src/libgamma-facade.cc +++ b/src/libgamma-facade.cc @@ -17,6 +17,8 @@ */ #include "libgamma-facade.hh" +#include "libgamma-error.hh" + #include <cstdlib> @@ -55,7 +57,6 @@ namespace libgamma 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. @@ -68,7 +69,6 @@ namespace libgamma return libgamma_is_method_available(method); } - /** * Return the capabilities of an adjustment method. * @@ -82,7 +82,6 @@ namespace libgamma *output = MethodCapabilities(&caps); } - /** * Return the default site for an adjustment method. * @@ -98,7 +97,6 @@ namespace libgamma return new std::string(cstr); } - /** * Return the default variable that determines * the default site for an adjustment method. @@ -117,6 +115,7 @@ namespace libgamma return new std::string(cstr); } + /** * Convert a raw representation of an EDID to a lowercase hexadecimal representation. * @@ -172,5 +171,289 @@ namespace libgamma 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); + } + } diff --git a/src/libgamma-facade.hh b/src/libgamma-facade.hh index 98ee78e..c52d7d8 100644 --- a/src/libgamma-facade.hh +++ b/src/libgamma-facade.hh @@ -79,6 +79,7 @@ namespace libgamma */ std::string* method_default_site_variable(int method); + /** * Convert a raw representation of an EDID to a lowercase hexadecimal representation. * @@ -115,6 +116,140 @@ namespace libgamma */ 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. + * + * @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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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); + } diff --git a/src/libgamma-method.cc b/src/libgamma-method.cc index a52c455..18bb9bb 100644 --- a/src/libgamma-method.cc +++ b/src/libgamma-method.cc @@ -17,21 +17,13 @@ */ #include "libgamma-method.hh" +#include "libgamma-error.hh" + #include <cstdlib> #include <cstring> #include <cerrno> -/** - * TODO temporary - */ -std::string create_error(int error_code) -{ - (void) error_code; - return nullptr; -} - - namespace libgamma { /** diff --git a/src/libgamma-method.hh b/src/libgamma-method.hh index 9bec563..aedf6f6 100644 --- a/src/libgamma-method.hh +++ b/src/libgamma-method.hh @@ -20,8 +20,10 @@ #include <string> +#include <cstdlib> #include "libgamma-native.hh" +#include "libgamma-error.hh" namespace libgamma @@ -504,6 +506,145 @@ namespace libgamma #endif /** + * One single Gamma ramp. + */ + template <typename T> + class Ramp + { + public: + /** + * Constructor. + * + * @param ramp The ramp. + * @param size The size of the ramp. + */ + Ramp(T* ramp, size_t size) + { + this->ramp = ramp; + this->size = 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 The red gamma ramp. + * @param green The green gamma ramp. + * @param blue 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 depth The bit-depth of the gamma ramps, -1 for single precision + * floating point, and -2 for double precision floating point. + */ + GammaRamps(T* red, T* green, T* blue, size_t red_size, size_t green_size, size_t blue_size, signed depth) : + red(Ramp<T>(red, red_size)), + green(Ramp<T>(green, green_size)), + blue(Ramp<T>(blue, blue_size)), + depth(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 @@ -690,6 +831,156 @@ namespace libgamma */ bool information(CRTCInformation* output, int32_t fields); +#define __LIBGAMMA_GET_GAMMA(AFFIX) \ + libgamma_gamma_ramps ## AFFIX ## _t native; \ + int r; \ + native.red = ramps->red.ramp; \ + native.green = ramps->green.ramp; \ + native.blue = ramps->blue.ramp; \ + native.red_size = ramps->red.size; \ + native.green_size = ramps->green.size; \ + native.blue_size = ramps->blue.size; \ + r = libgamma_crtc_get_gamma_ramps ## AFFIX(this->native, &native); \ + 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 native; \ + int r; \ + native.red = ramps->red.ramp; \ + native.green = ramps->green.ramp; \ + native.blue = ramps->blue.ramp; \ + native.red_size = ramps->red.size; \ + native.green_size = ramps->green.size; \ + native.blue_size = ramps->blue.size; \ + r = libgamma_crtc_set_gamma_ramps ## AFFIX(this->native, native); \ + 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 + /** diff --git a/src/test.cc b/src/test.cc index c802c71..45806a3 100644 --- a/src/test.cc +++ b/src/test.cc @@ -175,6 +175,23 @@ int main(void) 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; } |