diff options
Diffstat (limited to '')
-rw-r--r-- | src/libgamma-method.cc | 333 | ||||
-rw-r--r-- | src/libgamma-method.hh | 468 | ||||
-rw-r--r-- | src/libgamma-native.hh | 1 | ||||
-rw-r--r-- | src/libgamma.hh | 1 |
4 files changed, 803 insertions, 0 deletions
diff --git a/src/libgamma-method.cc b/src/libgamma-method.cc new file mode 100644 index 0000000..4acd857 --- /dev/null +++ b/src/libgamma-method.cc @@ -0,0 +1,333 @@ +/** + * libgammamm -- C++ wrapper for libgamma + * Copyright (C) 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. + */ +#include "libgamma-method.hh" + +#include <cstdlib> +#include <cstring> + + +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((SubpixelOrder)(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((ConnectorType)(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; + } + +} + diff --git a/src/libgamma-method.hh b/src/libgamma-method.hh new file mode 100644 index 0000000..514ae31 --- /dev/null +++ b/src/libgamma-method.hh @@ -0,0 +1,468 @@ +/** + * libgammamm -- C++ wrapper for libgamma + * Copyright (C) 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef LIBGAMMA_METHOD_HH +#define LIBGAMMA_METHOD_HH + + +#include <string> + +#include "libgamma-native.hh" + + +namespace libgamma +{ + /** + * Cathode ray tube controller information data structure. + */ + class CRTCInformation; + + /** + * Capabilities of adjustment methods. + */ + class MethodCapabilities; + + + + /** + * 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; + + }; + + +} + + +#endif + diff --git a/src/libgamma-native.hh b/src/libgamma-native.hh index 84ab806..e1545a4 100644 --- a/src/libgamma-native.hh +++ b/src/libgamma-native.hh @@ -29,6 +29,7 @@ extern "C" # define this self # include <libgamma.h> # undef this +# undef restrict } diff --git a/src/libgamma.hh b/src/libgamma.hh index bd237f0..64ca221 100644 --- a/src/libgamma.hh +++ b/src/libgamma.hh @@ -20,6 +20,7 @@ #include "libgamma-error.hh" +#include "libgamma-method.hh" #endif |