Ignore:
Timestamp:
Sep 27, 2008, 3:12:46 PM (11 years ago)
Author:
Sam Hocevar
Message:

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/dither.c

    r2819 r2821  
    11/*
    2  *  libcucul      Canvas for ultrafast compositing of Unicode letters
     2 *  libcaca       Colour ASCII-Art library
    33 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
     
    2929#endif
    3030
    31 #include "cucul.h"
    32 #include "cucul_internals.h"
     31#include "caca.h"
     32#include "caca_internals.h"
    3333
    3434#define CP437 0
     
    116116};
    117117
    118 struct cucul_dither
     118struct caca_dither
    119119{
    120120    int bpp, has_palette, has_alpha;
     
    123123    int rright, gright, bright, aright;
    124124    int rleft, gleft, bleft, aleft;
    125     void (*get_hsv)(cucul_dither_t *, char *, int, int);
     125    void (*get_hsv)(caca_dither_t *, char *, int, int);
    126126    int red[256], green[256], blue[256], alpha[256];
    127127
     
    173173static float gammapow(float x, float y);
    174174
    175 static void get_rgba_default(cucul_dither_t const *, uint8_t *, int, int,
     175static void get_rgba_default(caca_dither_t const *, uint8_t *, int, int,
    176176                             unsigned int *);
    177177static int init_lookup(void);
     
    243243 *  pitch) and pixel mask values. If the depth is 8 bits per pixel, the mask
    244244 *  values are ignored and the colour palette should be set using the
    245  *  cucul_set_dither_palette() function. For depths greater than 8 bits per
     245 *  caca_set_dither_palette() function. For depths greater than 8 bits per
    246246 *  pixel, a zero alpha mask causes the alpha values to be ignored.
    247247 *
     
    261261 *  \return Dither object upon success, NULL if an error occurred.
    262262 */
    263 cucul_dither_t *cucul_create_dither(int bpp, int w, int h, int pitch,
     263caca_dither_t *caca_create_dither(int bpp, int w, int h, int pitch,
    264264                                    uint32_t rmask, uint32_t gmask,
    265265                                    uint32_t bmask, uint32_t amask)
    266266{
    267     cucul_dither_t *d;
     267    caca_dither_t *d;
    268268    int i;
    269269
     
    275275    }
    276276
    277     d = malloc(sizeof(cucul_dither_t));
     277    d = malloc(sizeof(caca_dither_t));
    278278    if(!d)
    279279    {
     
    372372 *  \return 0 in case of success, -1 if an error occurred.
    373373 */
    374 int cucul_set_dither_palette(cucul_dither_t *d,
     374int caca_set_dither_palette(caca_dither_t *d,
    375375                             uint32_t red[], uint32_t green[],
    376376                             uint32_t blue[], uint32_t alpha[])
     
    421421 *  \return 0 in case of success, -1 if an error occurred.
    422422 */
    423 int cucul_set_dither_brightness(cucul_dither_t *d, float brightness)
     423int caca_set_dither_brightness(caca_dither_t *d, float brightness)
    424424{
    425425    /* FIXME */
     
    438438 *  \return Brightness value.
    439439 */
    440 float cucul_get_dither_brightness(cucul_dither_t const *d)
     440float caca_get_dither_brightness(caca_dither_t const *d)
    441441{
    442442    return d->brightness;
     
    455455 *  \return 0 in case of success, -1 if an error occurred.
    456456 */
    457 int cucul_set_dither_gamma(cucul_dither_t *d, float gamma)
     457int caca_set_dither_gamma(caca_dither_t *d, float gamma)
    458458{
    459459    /* FIXME: we don't need 4096 calls to gammapow(), we could just compute
     
    490490 *  \return Gamma value.
    491491 */
    492 float cucul_get_dither_gamma(cucul_dither_t const *d)
     492float caca_get_dither_gamma(caca_dither_t const *d)
    493493{
    494494    return d->gamma;
     
    506506 *  \return 0 in case of success, -1 if an error occurred.
    507507 */
    508 int cucul_set_dither_contrast(cucul_dither_t *d, float contrast)
     508int caca_set_dither_contrast(caca_dither_t *d, float contrast)
    509509{
    510510    /* FIXME */
     
    523523 *  \return Contrast value.
    524524 */
    525 float cucul_get_dither_contrast(cucul_dither_t const *d)
     525float caca_get_dither_contrast(caca_dither_t const *d)
    526526{
    527527    return d->contrast;
     
    544544 *  \return 0 in case of success, -1 if an error occurred.
    545545 */
    546 int cucul_set_dither_antialias(cucul_dither_t *d, char const *str)
     546int caca_set_dither_antialias(caca_dither_t *d, char const *str)
    547547{
    548548    if(!strcasecmp(str, "none"))
     
    570570 *  list is a NULL-terminated array of strings, interleaving a string
    571571 *  containing the internal value for the antialiasing method to be used with
    572  *  cucul_set_dither_antialias(), and a string containing the natural
     572 *  caca_set_dither_antialias(), and a string containing the natural
    573573 *  language description for that antialiasing method.
    574574 *
     
    579579 */
    580580char const * const *
    581     cucul_get_dither_antialias_list(cucul_dither_t const *d)
     581    caca_get_dither_antialias_list(caca_dither_t const *d)
    582582{
    583583    static char const * const list[] =
     
    600600 *  \return A static string.
    601601 */
    602 char const * cucul_get_dither_antialias(cucul_dither_t const *d)
     602char const * caca_get_dither_antialias(caca_dither_t const *d)
    603603{
    604604    return d->antialias_name;
     
    628628 *  \return 0 in case of success, -1 if an error occurred.
    629629 */
    630 int cucul_set_dither_color(cucul_dither_t *d, char const *str)
     630int caca_set_dither_color(caca_dither_t *d, char const *str)
    631631{
    632632    if(!strcasecmp(str, "mono"))
     
    679679 *  is a NULL-terminated array of strings, interleaving a string containing
    680680 *  the internal value for the colour mode, to be used with
    681  *  cucul_set_dither_color(), and a string containing the natural
     681 *  caca_set_dither_color(), and a string containing the natural
    682682 *  language description for that colour mode.
    683683 *
     
    688688 */
    689689char const * const *
    690     cucul_get_dither_color_list(cucul_dither_t const *d)
     690    caca_get_dither_color_list(caca_dither_t const *d)
    691691{
    692692    static char const * const list[] =
     
    714714 *  \return A static string.
    715715 */
    716 char const * cucul_get_dither_color(cucul_dither_t const *d)
     716char const * caca_get_dither_color(caca_dither_t const *d)
    717717{
    718718    return d->color_name;
     
    739739 *  \return 0 in case of success, -1 if an error occurred.
    740740 */
    741 int cucul_set_dither_charset(cucul_dither_t *d, char const *str)
     741int caca_set_dither_charset(caca_dither_t *d, char const *str)
    742742{
    743743    if(!strcasecmp(str, "shades"))
     
    773773 *  is a NULL-terminated array of strings, interleaving a string containing
    774774 *  the internal value for the character set, to be used with
    775  *  cucul_set_dither_charset(), and a string containing the natural
     775 *  caca_set_dither_charset(), and a string containing the natural
    776776 *  language description for that character set.
    777777 *
     
    781781 *  \return An array of strings.
    782782 */
    783 char const * const * cucul_get_dither_charset_list(cucul_dither_t const *d)
     783char const * const * caca_get_dither_charset_list(caca_dither_t const *d)
    784784{
    785785    static char const * const list[] =
     
    803803 *  \return A static string.
    804804 */
    805 char const * cucul_get_dither_charset(cucul_dither_t const *d)
     805char const * caca_get_dither_charset(caca_dither_t const *d)
    806806{
    807807    return d->glyph_name;
     
    828828 *  \return 0 in case of success, -1 if an error occurred.
    829829 */
    830 int cucul_set_dither_algorithm(cucul_dither_t *d, char const *str)
     830int caca_set_dither_algorithm(caca_dither_t *d, char const *str)
    831831{
    832832    if(!strcasecmp(str, "none"))
     
    886886 *  list is a NULL-terminated array of strings, interleaving a string
    887887 *  containing the internal value for the dithering algorithm, to be used
    888  *  with cucul_set_dither_dithering(), and a string containing the natural
     888 *  with caca_set_dither_dithering(), and a string containing the natural
    889889 *  language description for that algorithm.
    890890 *
     
    894894 *  \return An array of strings.
    895895 */
    896 char const * const * cucul_get_dither_algorithm_list(cucul_dither_t const *d)
     896char const * const * caca_get_dither_algorithm_list(caca_dither_t const *d)
    897897{
    898898    static char const * const list[] =
     
    919919 *  \return A static string.
    920920 */
    921 char const * cucul_get_dither_algorithm(cucul_dither_t const *d)
     921char const * caca_get_dither_algorithm(caca_dither_t const *d)
    922922{
    923923    return d->algo_name;
     
    931931 *  This function never fails.
    932932 *
    933  *  \param cv A handle to the libcucul canvas.
     933 *  \param cv A handle to the libcaca canvas.
    934934 *  \param x X coordinate of the upper-left corner of the drawing area.
    935935 *  \param y Y coordinate of the upper-left corner of the drawing area.
     
    940940 *  \return This function always returns 0.
    941941 */
    942 int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
    943                         cucul_dither_t const *d, void *pixels)
     942int caca_dither_bitmap(caca_canvas_t *cv, int x, int y, int w, int h,
     943                        caca_dither_t const *d, void *pixels)
    944944{
    945945    int *floyd_steinberg, *fs_r, *fs_g, *fs_b;
     
    951951        return 0;
    952952
    953     savedattr = cucul_get_attr(cv, -1, -1);
     953    savedattr = caca_get_attr(cv, -1, -1);
    954954
    955955    x1 = x; x2 = x + w - 1;
     
    11281128            if(rgba[2] > lum) lum = rgba[2];
    11291129            outfg = outbg;
    1130             outbg = CUCUL_BLACK;
     1130            outbg = CACA_BLACK;
    11311131
    11321132            ch = lum * dchmax / 0x1000;
     
    11701170
    11711171        /* Now output the character */
    1172         cucul_set_color_ansi(cv, outfg, outbg);
    1173         cucul_put_char(cv, x, y, outch);
     1172        caca_set_color_ansi(cv, outfg, outbg);
     1173        caca_put_char(cv, x, y, outch);
    11741174
    11751175        d->increment_dither();
     
    11801180    free(floyd_steinberg);
    11811181
    1182     cucul_set_attr(cv, savedattr);
     1182    caca_set_attr(cv, savedattr);
    11831183
    11841184    return 0;
     
    11871187/** \brief Free the memory associated with a dither.
    11881188 *
    1189  *  Free the memory allocated by cucul_create_dither().
     1189 *  Free the memory allocated by caca_create_dither().
    11901190 *
    11911191 *  This function never fails.
     
    11941194 *  \return This function always returns 0.
    11951195 */
    1196 int cucul_free_dither(cucul_dither_t *d)
     1196int caca_free_dither(caca_dither_t *d)
    11971197{
    11981198    if(!d)
     
    12971297}
    12981298
    1299 static void get_rgba_default(cucul_dither_t const *d, uint8_t *pixels,
     1299static void get_rgba_default(caca_dither_t const *d, uint8_t *pixels,
    13001300                             int x, int y, unsigned int *rgba)
    13011301{
     
    14941494static int get_random_dither(void)
    14951495{
    1496     return cucul_rand(0x00, 0x100);
     1496    return caca_rand(0x00, 0x100);
    14971497}
    14981498
     
    15101510
    15111511    /* These ones are constant */
    1512     lookup_colors[0] = CUCUL_BLACK;
    1513     lookup_colors[1] = CUCUL_DARKGRAY;
    1514     lookup_colors[2] = CUCUL_LIGHTGRAY;
    1515     lookup_colors[3] = CUCUL_WHITE;
     1512    lookup_colors[0] = CACA_BLACK;
     1513    lookup_colors[1] = CACA_DARKGRAY;
     1514    lookup_colors[2] = CACA_LIGHTGRAY;
     1515    lookup_colors[3] = CACA_WHITE;
    15161516
    15171517    /* These ones will be overwritten */
    1518     lookup_colors[4] = CUCUL_MAGENTA;
    1519     lookup_colors[5] = CUCUL_LIGHTMAGENTA;
    1520     lookup_colors[6] = CUCUL_RED;
    1521     lookup_colors[7] = CUCUL_LIGHTRED;
     1518    lookup_colors[4] = CACA_MAGENTA;
     1519    lookup_colors[5] = CACA_LIGHTMAGENTA;
     1520    lookup_colors[6] = CACA_RED;
     1521    lookup_colors[7] = CACA_LIGHTRED;
    15221522
    15231523    for(v = 0; v < LOOKUP_VAL; v++)
Note: See TracChangeset for help on using the changeset viewer.