diff options
Diffstat (limited to 'src/lib/libgamma-method.c')
-rw-r--r-- | src/lib/libgamma-method.c | 281 |
1 files changed, 141 insertions, 140 deletions
diff --git a/src/lib/libgamma-method.c b/src/lib/libgamma-method.c index 40b4013..cf9a23b 100644 --- a/src/lib/libgamma-method.c +++ b/src/lib/libgamma-method.c @@ -1,20 +1,4 @@ -/** - * libgamma -- Display server abstraction layer for gamma ramp adjustments - * Copyright (C) 2014, 2015 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/>. - */ +/* See LICENSE file for copyright and license details. */ #include "libgamma-method.h" @@ -26,34 +10,36 @@ /** * 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 * - * The input must have `red_size`, `green_size` and `blue_size` set to the - * sizes of the gamma ramps that should be allocated. + * The input must have `red_size`, `green_size`, and `blue_size` set to the + * sizes of the gamma ramps that should be allocated * - * @param this The gamma ramps. - * @return Zero on success, -1 on allocation error, `errno` will be set accordingly. + * @param this The gamma ramps + * @return Zero on success, -1 on allocation error, `errno` will be set accordingly */ -int libgamma_gamma_ramps8_initialise(libgamma_gamma_ramps8_t* restrict this) +int +libgamma_gamma_ramps8_initialise(libgamma_gamma_ramps8_t *restrict this) { - size_t n = this->red_size + this->green_size + this->blue_size; - this->red = malloc(n * sizeof(uint8_t)); - this->green = this-> red + this-> red_size; - this->blue = this->green + this->green_size; - return this->red == NULL ? -1 : 0; + size_t n = this->red_size + this->green_size + this->blue_size; + this->red = malloc(n * sizeof(uint8_t)); + this->green = &this-> red[this-> red_size]; + this->blue = &this->green[this->green_size]; + return this->red ? 0 : -1; } /** * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps8_initialise` or otherwise - * initialises in the proper manner. + * initialises in the proper manner * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps8_destroy(libgamma_gamma_ramps8_t* restrict this) +void +libgamma_gamma_ramps8_destroy(libgamma_gamma_ramps8_t *restrict this) { - free(this->red); + free(this->red); } @@ -61,53 +47,56 @@ void libgamma_gamma_ramps8_destroy(libgamma_gamma_ramps8_t* restrict this) * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps8_initialise` or otherwise * initialises in the proper manner, as well as release the pointer - * to the structure. + * to the structure * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t* restrict this) +void +libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t *restrict this) { - free(this->red); - free(this); + free(this->red); + free(this); } /** * 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 * - * The input must have `red_size`, `green_size` and `blue_size` set to the - * sizes of the gamma ramps that should be allocated. + * The input must have `red_size`, `green_size`, and `blue_size` set to the + * sizes of the gamma ramps that should be allocated * - * @param this The gamma ramps. - * @return Zero on success, -1 on allocation error, `errno` will be set accordingly. + * @param this The gamma ramps + * @return Zero on success, -1 on allocation error, `errno` will be set accordingly */ -int libgamma_gamma_ramps16_initialise(libgamma_gamma_ramps16_t* restrict this) +int +libgamma_gamma_ramps16_initialise(libgamma_gamma_ramps16_t *restrict this) { - size_t n = this->red_size + this->green_size + this->blue_size; + size_t n = this->red_size + this->green_size + this->blue_size; #ifdef HAVE_LIBGAMMA_METHOD_LINUX_DRM - /* Valgrind complains about us reading uninitialize memory if we just use malloc. */ - this->red = calloc(n, sizeof(uint16_t)); + /* Valgrind complains about us reading uninitialize memory if we just use malloc */ + this->red = calloc(n, sizeof(uint16_t)); #else - this->red = malloc(n * sizeof(uint16_t)); + this->red = malloc(n * sizeof(uint16_t)); #endif - this->green = this-> red + this-> red_size; - this->blue = this->green + this->green_size; - return this->red == NULL ? -1 : 0; + this->green = &this-> red[this-> red_size]; + this->blue = &this->green[this->green_size]; + return this->red ? 0 : -1; } /** * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps_initialise` or otherwise - * initialises in the proper manner. + * initialises in the proper manner * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps16_destroy(libgamma_gamma_ramps16_t* restrict this) +void +libgamma_gamma_ramps16_destroy(libgamma_gamma_ramps16_t *restrict this) { - free(this->red); + free(this->red); } @@ -115,48 +104,51 @@ void libgamma_gamma_ramps16_destroy(libgamma_gamma_ramps16_t* restrict this) * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps_initialise` or otherwise * initialises in the proper manner, as well as release the pointer - * to the structure. + * to the structure * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps16_free(libgamma_gamma_ramps16_t* restrict this) +void +libgamma_gamma_ramps16_free(libgamma_gamma_ramps16_t *restrict this) { - free(this->red); - free(this); + free(this->red); + free(this); } /** * 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 * - * The input must have `red_size`, `green_size` and `blue_size` set to the - * sizes of the gamma ramps that should be allocated. + * The input must have `red_size`, `green_size`, and `blue_size` set to the + * sizes of the gamma ramps that should be allocated * - * @param this The gamma ramps. - * @return Zero on success, -1 on allocation error, `errno` will be set accordingly. + * @param this The gamma ramps + * @return Zero on success, -1 on allocation error, `errno` will be set accordingly */ -int libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t* restrict this) +int +libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t *restrict this) { - size_t n = this->red_size + this->green_size + this->blue_size; - this->red = malloc(n * sizeof(uint32_t)); - this->green = this-> red + this-> red_size; - this->blue = this->green + this->green_size; - return this->red == NULL ? -1 : 0; + size_t n = this->red_size + this->green_size + this->blue_size; + this->red = malloc(n * sizeof(uint32_t)); + this->green = &this-> red[this-> red_size]; + this->blue = &this->green[this->green_size]; + return this->red ? 0 : -1; } /** * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise - * initialises in the proper manner. + * initialises in the proper manner * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps32_destroy(libgamma_gamma_ramps32_t* restrict this) +void +libgamma_gamma_ramps32_destroy(libgamma_gamma_ramps32_t *restrict this) { - free(this->red); + free(this->red); } @@ -164,48 +156,51 @@ void libgamma_gamma_ramps32_destroy(libgamma_gamma_ramps32_t* restrict this) * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise * initialises in the proper manner, as well as release the pointer - * to the structure. + * to the structure * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t* restrict this) +void +libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t *restrict this) { - free(this->red); - free(this); + free(this->red); + free(this); } /** * 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 * - * The input must have `red_size`, `green_size` and `blue_size` set to the - * sizes of the gamma ramps that should be allocated. + * The input must have `red_size`, `green_size`, and `blue_size` set to the + * sizes of the gamma ramps that should be allocated * - * @param this The gamma ramps. - * @return Zero on success, -1 on allocation error, `errno` will be set accordingly. + * @param this The gamma ramps + * @return Zero on success, -1 on allocation error, `errno` will be set accordingly */ -int libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t* restrict this) +int +libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t *restrict this) { - size_t n = this->red_size + this->green_size + this->blue_size; - this->red = malloc(n * sizeof(uint64_t)); - this->green = this-> red + this-> red_size; - this->blue = this->green + this->green_size; - return this->red == NULL ? -1 : 0; + size_t n = this->red_size + this->green_size + this->blue_size; + this->red = malloc(n * sizeof(uint64_t)); + this->green = &this-> red[this-> red_size]; + this->blue = &this->green[this->green_size]; + return this->red ? 0 : -1; } /** * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise - * initialises in the proper manner. + * initialises in the proper manner * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps64_destroy(libgamma_gamma_ramps64_t* restrict this) +void +libgamma_gamma_ramps64_destroy(libgamma_gamma_ramps64_t *restrict this) { - free(this->red); + free(this->red); } @@ -213,48 +208,51 @@ void libgamma_gamma_ramps64_destroy(libgamma_gamma_ramps64_t* restrict this) * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise * initialises in the proper manner, as well as release the pointer - * to the structure. + * to the structure * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t* restrict this) +void +libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t *restrict this) { - free(this->red); - free(this); + free(this->red); + free(this); } /** * 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 * - * The input must have `red_size`, `green_size` and `blue_size` set to the - * sizes of the gamma ramps that should be allocated. + * The input must have `red_size`, `green_size`, and `blue_size` set to the + * sizes of the gamma ramps that should be allocated * - * @param this The gamma ramps. - * @return Zero on success, -1 on allocation error, `errno` will be set accordingly. + * @param this The gamma ramps + * @return Zero on success, -1 on allocation error, `errno` will be set accordingly */ -int libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t* restrict this) +int +libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t *restrict this) { - size_t n = this->red_size + this->green_size + this->blue_size; - this->red = malloc(n * sizeof(float)); - this->green = this-> red + this-> red_size; - this->blue = this->green + this->green_size; - return this->red == NULL ? -1 : 0; + size_t n = this->red_size + this->green_size + this->blue_size; + this->red = malloc(n * sizeof(float)); + this->green = &this-> red[this-> red_size]; + this->blue = &this->green[this->green_size]; + return this->red ? 0 : -1; } /** * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise - * initialises in the proper manner. + * initialises in the proper manner * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_rampsf_destroy(libgamma_gamma_rampsf_t* restrict this) +void +libgamma_gamma_rampsf_destroy(libgamma_gamma_rampsf_t *restrict this) { - free(this->red); + free(this->red); } @@ -262,48 +260,51 @@ void libgamma_gamma_rampsf_destroy(libgamma_gamma_rampsf_t* restrict this) * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise * initialises in the proper manner, as well as release the pointer - * to the structure. + * to the structure * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t* restrict this) +void +libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t *restrict this) { - free(this->red); - free(this); + free(this->red); + free(this); } /** * 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 * - * The input must have `red_size`, `green_size` and `blue_size` set to the - * sizes of the gamma ramps that should be allocated. + * The input must have `red_size`, `green_size`, and `blue_size` set to the + * sizes of the gamma ramps that should be allocated * - * @param this The gamma ramps. - * @return Zero on success, -1 on allocation error, `errno` will be set accordingly. + * @param this The gamma ramps + * @return Zero on success, -1 on allocation error, `errno` will be set accordingly */ -int libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t* restrict this) +int +libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t *restrict this) { - size_t n = this->red_size + this->green_size + this->blue_size; - this->red = malloc(n * sizeof(double)); - this->green = this-> red + this-> red_size; - this->blue = this->green + this->green_size; - return this->red == NULL ? -1 : 0; + size_t n = this->red_size + this->green_size + this->blue_size; + this->red = malloc(n * sizeof(double)); + this->green = &this-> red[this-> red_size]; + this->blue = &this->green[this->green_size]; + return this->red ? 0 : -1; } /** * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise - * initialises in the proper manner. + * initialises in the proper manner * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_rampsd_destroy(libgamma_gamma_rampsd_t* restrict this) +void +libgamma_gamma_rampsd_destroy(libgamma_gamma_rampsd_t *restrict this) { - free(this->red); + free(this->red); } @@ -311,13 +312,13 @@ void libgamma_gamma_rampsd_destroy(libgamma_gamma_rampsd_t* restrict this) * Release resources that are held by a gamma ramp strcuture that * has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise * initialises in the proper manner, as well as release the pointer - * to the structure. + * to the structure * - * @param this The gamma ramps. + * @param this The gamma ramps */ -void libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t* restrict this) +void +libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t *restrict this) { - free(this->red); - free(this); + free(this->red); + free(this); } - |