diff --git a/cucul/cucul.h b/cucul/cucul.h index 3ad7179..02bf870 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -208,9 +208,11 @@ int cucul_set_dither_palette(cucul_dither_t *, unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[]); int cucul_set_dither_brightness(cucul_dither_t *, float); +float cucul_get_dither_brightness(cucul_dither_t *); int cucul_set_dither_gamma(cucul_dither_t *, float); +float cucul_get_dither_gamma(cucul_dither_t *); int cucul_set_dither_contrast(cucul_dither_t *, float); -int cucul_set_dither_invert(cucul_dither_t *, int); +float cucul_get_dither_contrast(cucul_dither_t *); int cucul_set_dither_antialias(cucul_dither_t *, char const *); char const * const * cucul_get_dither_antialias_list(cucul_dither_t const *); int cucul_set_dither_color(cucul_dither_t *, char const *); @@ -291,6 +293,7 @@ char const * const * cucul_get_export_list(void); cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *, char const *) CUCUL_DEPRECATED; int cucul_rotate(cucul_canvas_t *) CUCUL_DEPRECATED; + int cucul_set_dither_invert(cucul_dither_t *, int) CUCUL_DEPRECATED; # define CUCUL_COLOR_BLACK CUCUL_BLACK # define CUCUL_COLOR_BLUE CUCUL_BLUE # define CUCUL_COLOR_GREEN CUCUL_GREEN diff --git a/cucul/dither.c b/cucul/dither.c index 9951929..a0d89f6 100644 --- a/cucul/dither.c +++ b/cucul/dither.c @@ -418,9 +418,25 @@ int cucul_set_dither_brightness(cucul_dither_t *d, float brightness) return 0; } +/** \brief Get the brightness of a dither object. + * + * Get the brightness of the given dither object. + * + * This function never fails. + * + * \param d Dither object. + * \return Brightness value. + */ +float cucul_get_dither_brightness(cucul_dither_t *d) +{ + /* FIXME */ + return 0.0; +} + /** \brief Set the gamma of a dither object. * - * Set the gamma of dither. + * Set the gamma of the given dither object. A negative value causes + * colour inversion. * * If an error occurs, -1 is returned and \b errno is set accordingly: * - \c EINVAL Gamma value was out of range. @@ -432,11 +448,16 @@ int cucul_set_dither_brightness(cucul_dither_t *d, float brightness) int cucul_set_dither_gamma(cucul_dither_t *d, float gamma) { /* FIXME: we don't need 4096 calls to gammapow(), we could just compute - * 128 of them and do linear interpolation for the rest. This will + * a few of them and do linear interpolation for the rest. This will * probably speed up things a lot. */ int i; - if(gamma <= 0.0) + if(gamma < 0.0) + { + d->invert = 1; + gamma = -gamma; + } + else if(gamma == 0.0) { seterrno(EINVAL); return -1; @@ -450,21 +471,18 @@ int cucul_set_dither_gamma(cucul_dither_t *d, float gamma) return 0; } -/** \brief Invert colors of dither +/** \brief Get the gamma of a dither object. * - * Invert colors of dither. + * Get the gamma of the given dither object. * * This function never fails. * * \param d Dither object. - * \param value 0 for normal behaviour, 1 for invert - * \return This function always returns 0. + * \return Gamma value. */ -int cucul_set_dither_invert(cucul_dither_t *d, int value) +float cucul_get_dither_gamma(cucul_dither_t *d) { - d->invert = value ? 1 : 0; - - return 0; + return d->gamma; } /** \brief Set the contrast of a dither object. diff --git a/cucul/legacy.c b/cucul/legacy.c index 78d63d9..78d1f4d 100644 --- a/cucul/legacy.c +++ b/cucul/legacy.c @@ -62,6 +62,19 @@ int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) return cucul_set_color_argb(cv, fg, bg); } +/* + * Functions from dither.c + */ +int cucul_set_dither_invert(cucul_dither_t *d, int value) +{ + float gamma = cucul_get_dither_gamma(d); + + if(gamma * (value ? -1 : 1) < 0) + cucul_set_dither_gamma(d, -gamma); + + return 0; +} + /* * Functions from import.c */