reason to keep a copy of them in the calling program.
* Deprecate cucul_set_dither_invert(). Inverting a dither's colours is now
done by setting a negative gamma value.
tags/v0.99.beta14
| @@ -208,9 +208,11 @@ int cucul_set_dither_palette(cucul_dither_t *, | |||||
| unsigned int r[], unsigned int g[], | unsigned int r[], unsigned int g[], | ||||
| unsigned int b[], unsigned int a[]); | unsigned int b[], unsigned int a[]); | ||||
| int cucul_set_dither_brightness(cucul_dither_t *, float); | 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); | 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_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 *); | int cucul_set_dither_antialias(cucul_dither_t *, char const *); | ||||
| char const * const * cucul_get_dither_antialias_list(cucul_dither_t const *); | char const * const * cucul_get_dither_antialias_list(cucul_dither_t const *); | ||||
| int cucul_set_dither_color(cucul_dither_t *, char 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 *, | cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *, | ||||
| char const *) CUCUL_DEPRECATED; | char const *) CUCUL_DEPRECATED; | ||||
| int cucul_rotate(cucul_canvas_t *) 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_BLACK CUCUL_BLACK | ||||
| # define CUCUL_COLOR_BLUE CUCUL_BLUE | # define CUCUL_COLOR_BLUE CUCUL_BLUE | ||||
| # define CUCUL_COLOR_GREEN CUCUL_GREEN | # define CUCUL_COLOR_GREEN CUCUL_GREEN | ||||
| @@ -418,9 +418,25 @@ int cucul_set_dither_brightness(cucul_dither_t *d, float brightness) | |||||
| return 0; | 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. | /** \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: | * If an error occurs, -1 is returned and \b errno is set accordingly: | ||||
| * - \c EINVAL Gamma value was out of range. | * - \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) | int cucul_set_dither_gamma(cucul_dither_t *d, float gamma) | ||||
| { | { | ||||
| /* FIXME: we don't need 4096 calls to gammapow(), we could just compute | /* 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. */ | * probably speed up things a lot. */ | ||||
| int i; | int i; | ||||
| if(gamma <= 0.0) | |||||
| if(gamma < 0.0) | |||||
| { | |||||
| d->invert = 1; | |||||
| gamma = -gamma; | |||||
| } | |||||
| else if(gamma == 0.0) | |||||
| { | { | ||||
| seterrno(EINVAL); | seterrno(EINVAL); | ||||
| return -1; | return -1; | ||||
| @@ -450,21 +471,18 @@ int cucul_set_dither_gamma(cucul_dither_t *d, float gamma) | |||||
| return 0; | 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. | * This function never fails. | ||||
| * | * | ||||
| * \param d Dither object. | * \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. | /** \brief Set the contrast of a dither object. | ||||
| @@ -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); | 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 | * Functions from import.c | ||||
| */ | */ | ||||