From 5a9b82bc5b9c5973ac9bda6c0ec4701c7fb88271 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 28 Aug 2014 15:32:01 +0200 Subject: add 8-bit ramps (good for software gamma) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- info/libgamma.texinfo | 26 +++++++++++---- src/lib/gamma-dummy.c | 29 +++++++++++++++++ src/lib/gamma-dummy.h | 23 ++++++++++++++ src/lib/gamma-helper.h | 5 +++ src/lib/libgamma-facade.c.gpp | 40 ++++++++++++++++++++++- src/lib/libgamma-facade.h | 48 ++++++++++++++++++++++++++++ src/lib/libgamma-method.c | 49 ++++++++++++++++++++++++++++ src/lib/libgamma-method.h | 74 +++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 284 insertions(+), 10 deletions(-) diff --git a/info/libgamma.texinfo b/info/libgamma.texinfo index d764cab..1903144 100644 --- a/info/libgamma.texinfo +++ b/info/libgamma.texinfo @@ -1043,6 +1043,10 @@ other than what the adjustment method uses, it will be converted. @table @asis +@item @code{libgamma_gamma_ramps8_t} (@code{struct libgamma_gamma_ramps8}) +8-bit integer (@code{uint8_t}). +Currently no adjustment method. + @item @code{libgamma_gamma_ramps16_t} (@code{struct libgamma_gamma_ramps16}) 16-bit integer (@code{uint16_t}). This is by far the most common. @@ -1110,7 +1114,8 @@ functions to create and destroy gamma ramp structures. @table @asis -@item @code{libgamma_gamma_ramps16_initialise} [@code{int *(libgamma_gamma_ramps16_t*)}] +@item @code{libgamma_gamma_ramps8_initialise} [@code{int *(libgamma_gamma_ramps8_t*)}] +@itemx @code{libgamma_gamma_ramps16_initialise} [@code{int *(libgamma_gamma_ramps16_t*)}] @itemx @code{libgamma_gamma_ramps32_initialise} [@code{int *(libgamma_gamma_ramps32_t*)}] @itemx @code{libgamma_gamma_ramps64_initialise} [@code{int *(libgamma_gamma_ramps64_t*)}] @itemx @code{libgamma_gamma_rampsf_initialise} [@code{int *(libgamma_gamma_rampsf_t*)}] @@ -1130,7 +1135,8 @@ Zero is returned on success. On error is set accordingly. These functions can only fail on @code{malloc} error. -@item @code{libgamma_gamma_ramps16_destroy} [@code{void *(libgamma_gamma_ramps16_t*)}] +@item @code{libgamma_gamma_ramps8_destroy} [@code{void *(libgamma_gamma_ramps8_t*)}] +@itemx @code{libgamma_gamma_ramps16_destroy} [@code{void *(libgamma_gamma_ramps16_t*)}] @itemx @code{libgamma_gamma_ramps32_destroy} [@code{void *(libgamma_gamma_ramps32_t*)}] @itemx @code{libgamma_gamma_ramps64_destroy} [@code{void *(libgamma_gamma_ramps64_t*)}] @itemx @code{libgamma_gamma_rampsf_destroy} [@code{void *(libgamma_gamma_rampsf_t*)}] @@ -1140,7 +1146,8 @@ ramp structure that has been allocated by @code{libgamma_gamma_ramps_initialise} or otherwise initialises in the proper manner. -@item @code{libgamma_gamma_ramps16_free} [@code{void *(libgamma_gamma_ramps16_t*)}] +@item @code{libgamma_gamma_ramps8_free} [@code{void *(libgamma_gamma_ramps8_t*)}] +@itemx @code{libgamma_gamma_ramps16_free} [@code{void *(libgamma_gamma_ramps16_t*)}] @itemx @code{libgamma_gamma_ramps32_free} [@code{void *(libgamma_gamma_ramps32_t*)}] @itemx @code{libgamma_gamma_ramps64_free} [@code{void *(libgamma_gamma_ramps64_t*)}] @itemx @code{libgamma_gamma_rampsf_free} [@code{void *(libgamma_gamma_rampsf_t*)}] @@ -1218,23 +1225,28 @@ type gamma ramps. But it is possible to use other element types as well: @table @code +@item uint8_t +Substitute all @code{ramps16} for @code{ramps8} +in the the function names and date type +definition names. + @item uint32_t -Substitute all @code{ramps} for @code{ramps32} +Substitute all @code{ramps16} for @code{ramps32} in the the function names and date type definition names. @item uint64_t -Substitute all @code{ramps} for @code{ramps64} +Substitute all @code{ramps16} for @code{ramps64} in the the function names and date type definition names. @item float -Substitute all @code{ramps} for @code{rampsf} +Substitute all @code{ramps16} for @code{rampsf} in the the function names and date type definition names. @item double -Substitute all @code{ramps} for @code{rampsd} +Substitute all @code{ramps16} for @code{rampsd} in the the function names and date type definition names. @end table diff --git a/src/lib/gamma-dummy.c b/src/lib/gamma-dummy.c index ccde8cc..84e6df0 100644 --- a/src/lib/gamma-dummy.c +++ b/src/lib/gamma-dummy.c @@ -721,6 +721,35 @@ int libgamma_dummy_get_crtc_information(libgamma_crtc_information_t* restrict th } +/** + * Get current the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to fill with the current values. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_dummy_crtc_get_gamma_ramps8(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_t* restrict ramps) +{ +} + + +/** + * Set the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to apply. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_dummy_crtc_set_gamma_ramps8(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_t ramps) +{ +} + + + /** * Get current the gamma ramps for a CRTC, 16-bit gamma-depth version. * diff --git a/src/lib/gamma-dummy.h b/src/lib/gamma-dummy.h index e64dc02..931e0ff 100644 --- a/src/lib/gamma-dummy.h +++ b/src/lib/gamma-dummy.h @@ -135,6 +135,29 @@ int libgamma_dummy_crtc_restore(libgamma_crtc_state_t* restrict this); int libgamma_dummy_get_crtc_information(libgamma_crtc_information_t* restrict this, libgamma_crtc_state_t* restrict crtc, int32_t fields); +/** + * Get current the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to fill with the current values. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_dummy_crtc_get_gamma_ramps8(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_t* restrict ramps); + +/** + * Set the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to apply. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_dummy_crtc_set_gamma_ramps8(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_t ramps); + + /** * Get current the gamma ramps for a CRTC, 16-bit gamma-depth version. * diff --git a/src/lib/gamma-helper.h b/src/lib/gamma-helper.h index 48f4de5..6bc8fd2 100644 --- a/src/lib/gamma-helper.h +++ b/src/lib/gamma-helper.h @@ -27,6 +27,11 @@ */ typedef union libgamma_gamma_ramps_any { + /** + * 8-bit gamma ramps. + */ + libgamma_gamma_ramps8_t bits8; + /** * 16-bit gamma ramps. */ diff --git a/src/lib/libgamma-facade.c.gpp b/src/lib/libgamma-facade.c.gpp index 8527b3b..a1e8538 100644 --- a/src/lib/libgamma-facade.c.gpp +++ b/src/lib/libgamma-facade.c.gpp @@ -762,7 +762,7 @@ $>done * * @param 1 Either `get` or `set`, for the action that the name of value implies. * @param 2 The `ramp*` pattern for the ramp structure and function to call. - * @param 3 Either of `bit16`, `bit32`, `bit64`, `float_single`, `float_double`; + * @param 3 Either of `bit8`, `bit16`, `bit32`, `bit64`, `float_single`, `float_double`; * rather self-explanatory. * @param 4 The number of bits in the gamma depth, -1 for single precision float, * (`float`) and -2 for double percition float (`double`). @@ -819,6 +819,29 @@ $>} +/** + * Get current the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to fill with the current values. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +$>crtc_set_get_gamma_ramps get ramps8 bits8 8 + + +/** + * Set the gamma ramps for a CRTC, 32-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to apply. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +$>crtc_set_get_gamma_ramps set ramps8 bits8 8 + + + /** * Get current the gamma ramps for a CRTC, 32-bit gamma-depth version. * @@ -976,6 +999,21 @@ int libgamma_crtc_set_gamma_${2}_f(libgamma_crtc_state_t* restrict this, $>} +/** + * Set the gamma ramps for a CRTC, 8-bit gamma-depth function version. + * + * Note that this will probably involve the library allocating temporary data. + * + * @param this The CRTC state. + * @param red_function The function that generates the the gamma ramp for the red channel. + * @param green_function The function that generates the the gamma ramp for the green channel. + * @param blue_function The function that generates the the gamma ramp for the blue channel. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +$>crtc_set_gamma_ramps_f uint8_t ramps8 + + /** * Set the gamma ramps for a CRTC, 16-bit gamma-depth function version. * diff --git a/src/lib/libgamma-facade.h b/src/lib/libgamma-facade.h index cfcf085..92a2b42 100644 --- a/src/lib/libgamma-facade.h +++ b/src/lib/libgamma-facade.h @@ -30,6 +30,14 @@ +/** + * Mapping function from [0, 1] float encoding value to [0, 2⁸ − 1] integer output value. + * + * @param encoding [0, 1] float encoding value. + * @return [0, 2⁸ − 1] integer output value. + */ +typedef uint8_t libgamma_gamma_ramps8_fun(float encoding); + /** * Mapping function from [0, 1] float encoding value to [0, 2¹⁶ − 1] integer output value. * @@ -315,6 +323,29 @@ char* libgamma_behex_edid_uppercase(const unsigned char* restrict edid, size_t l unsigned char* libgamma_unhex_edid(const char* restrict edid); +/** + * Get current the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to fill with the current values + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_crtc_get_gamma_ramps8(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_t* restrict ramps); + +/** + * Set the gamma ramps for a CRTC, 8-bit gamma-depth version. + * + * @param this The CRTC state. + * @param ramps The gamma ramps to apply. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_crtc_set_gamma_ramps8(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_t ramps) __attribute__((hot)); + + /** * Get current the gamma ramps for a CRTC, 16-bit gamma-depth version. * @@ -430,6 +461,23 @@ int libgamma_crtc_set_gamma_rampsd(libgamma_crtc_state_t* restrict this, libgamma_gamma_rampsd_t ramps); +/** + * Set the gamma ramps for a CRTC, 8-bit gamma-depth function version. + * + * Note that this will probably involve the library allocating temporary data. + * + * @param this The CRTC state. + * @param red_function The function that generates the the gamma ramp for the red channel. + * @param green_function The function that generates the the gamma ramp for the green channel. + * @param blue_function The function that generates the the gamma ramp for the blue channel. + * @return Zero on success, otherwise (negative) the value of an + * error identifier provided by this library. + */ +int libgamma_crtc_set_gamma_ramps8_f(libgamma_crtc_state_t* restrict this, + libgamma_gamma_ramps8_fun* red_function, + libgamma_gamma_ramps8_fun* green_function, + libgamma_gamma_ramps8_fun* blue_function) __attribute__((cold)); + /** * Set the gamma ramps for a CRTC, 16-bit gamma-depth function version. * diff --git a/src/lib/libgamma-method.c b/src/lib/libgamma-method.c index 7311de4..0fa76c3 100644 --- a/src/lib/libgamma-method.c +++ b/src/lib/libgamma-method.c @@ -24,6 +24,55 @@ +/** + * Initialise a gamma ramp in the proper way that allows all adjustment + * 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. + * + * @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) +{ + 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; +} + + +/** + * 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. + * + * @param this The gamma ramps. + */ +void libgamma_gamma_ramps8_destroy(libgamma_gamma_ramps8_t* restrict this) +{ + free(this->red); +} + + +/** + * 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. + * + * @param this The gamma ramps. + */ +void libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t* restrict 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. diff --git a/src/lib/libgamma-method.h b/src/lib/libgamma-method.h index b549a5d..c342b43 100644 --- a/src/lib/libgamma-method.h +++ b/src/lib/libgamma-method.h @@ -861,6 +861,44 @@ typedef struct libgamma_crtc_information +/** + * Gamma ramp structure for 8-bit gamma ramps. + */ +typedef struct libgamma_gamma_ramps8 +{ + /** + * The size of `red`. + */ + size_t red_size; + + /** + * The size of `green`. + */ + size_t green_size; + + /** + * The size of `blue`. + */ + size_t blue_size; + + /** + * The gamma ramp for the red channel. + */ + uint8_t* red; + + /** + * The gamma ramp for the green channel. + */ + uint8_t* green; + + /** + * The gamma ramp for the blue channel. + */ + uint8_t* blue; + +} libgamma_gamma_ramps8_t; + + /** * Gamma ramp structure for 16-bit gamma ramps. */ @@ -1052,6 +1090,38 @@ typedef struct libgamma_gamma_rampsd +/** + * Initialise a gamma ramp in the proper way that allows all adjustment + * 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. + * + * @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); + +/** + * 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. + * + * @param this The gamma ramps. + */ +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. + * + * @param this The gamma ramps. + */ +void libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t* restrict 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. @@ -1066,7 +1136,7 @@ int libgamma_gamma_ramps16_initialise(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 + * has been allocated by `libgamma_gamma_ramps16_initialise` or otherwise * initialises in the proper manner. * * @param this The gamma ramps. @@ -1075,7 +1145,7 @@ 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 + * has been allocated by `libgamma_gamma_ramps16_initialise` or otherwise * initialises in the proper manner, as well as release the pointer * to the structure. * -- cgit v1.2.3-70-g09d2