Changeset 778


Ignore:
Timestamp:
Apr 16, 2006, 11:26:25 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Moved cucul_set_color() from canvas.c to colour.c.
  • Added cucul_set_truecolor() for non-ANSI colours.
  • Added new argb32 -> rgb12 conversion functions.
Location:
libcaca/trunk/cucul
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/canvas.c

    r773 r778  
    3737#include "cucul.h"
    3838#include "cucul_internals.h"
    39 
    40 /** \brief Set the default colour pair.
    41  *
    42  *  This function sets the default colour pair. String functions such as
    43  *  caca_printf() and graphical primitive functions such as caca_draw_line()
    44  *  will use these colour pairs.
    45  *
    46  *  \param qq A handle to the libcucul canvas.
    47  *  \param fgcolor The requested foreground colour.
    48  *  \param bgcolor The requested background colour.
    49  */
    50 void cucul_set_color(cucul_t *qq, unsigned int fgcolor, unsigned int bgcolor)
    51 {
    52     /* FIXME */
    53     if(fgcolor < 0 || fgcolor > 15 || bgcolor < 0 || bgcolor > 15)
    54         return;
    55 
    56     qq->fgcolor = fgcolor;
    57     qq->bgcolor = bgcolor;
    58 }
    5939
    6040/** \brief Print an ASCII character.
  • libcaca/trunk/cucul/colour.c

    r769 r778  
    2727    0xf444, 0xf44f, 0xf4f4, 0xf4ff, 0xff44, 0xff4f, 0xfff4, 0xffff,
    2828};
     29
     30/** \brief Set the default colour pair.
     31 *
     32 *  This function sets the default ANSI colour pair. String functions such as
     33 *  caca_printf() and graphical primitive functions such as caca_draw_line()
     34 *  will use these colours.
     35 *
     36 *  Color values are those defined in \e cucul.h, such as CUCUL_COLOR_RED
     37 *  or CUCUL_COLOR_TRANSPARENT.
     38 *
     39 *  \param qq A handle to the libcucul canvas.
     40 *  \param fg The requested foreground colour.
     41 *  \param bg The requested background colour.
     42 */
     43void cucul_set_color(cucul_t *qq, unsigned char fg, unsigned char bg)
     44{
     45    if(fg > 0x20 || bg > 0x20)
     46        return;
     47
     48    qq->fgcolor = fg;
     49    qq->bgcolor = bg;
     50}
     51
     52/** \brief Set the default colour pair (truecolor version).
     53 *
     54 *  This function sets the default colour pair. String functions such as
     55 *  caca_printf() and graphical primitive functions such as caca_draw_line()
     56 *  will use these colours.
     57 *
     58 *  Colors are 16-bit ARGB values, each component being coded on 4 bits. For
     59 *  instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is
     60 *  white with 50% alpha (A=8 R=15 G=15 B=15).
     61 *
     62 *  \param qq A handle to the libcucul canvas.
     63 *  \param fg The requested foreground colour.
     64 *  \param bg The requested background colour.
     65 */
     66void cucul_set_truecolor(cucul_t *qq, unsigned int fg, unsigned int bg)
     67{
     68    if(fg > 0xffff || bg > 0xffff)
     69        return;
     70
     71    if(fg < 0x100)
     72        fg += 0x100;
     73
     74    if(bg < 0x100)
     75        bg += 0x100;
     76
     77    qq->fgcolor = fg;
     78    qq->bgcolor = bg;
     79}
     80
     81/*
     82 * XXX: the following functions are local
     83 */
    2984
    3085static uint8_t nearest_ansi(uint16_t argb16, uint8_t def)
     
    89144}
    90145
     146uint16_t _cucul_argb32_to_rgb12fg(uint32_t c)
     147{
     148    uint16_t fg = c & 0xffff;
     149
     150    if(fg < CUCUL_COLOR_DEFAULT)
     151        return ansitab[fg] & 0x0fff;
     152
     153    if(fg == CUCUL_COLOR_DEFAULT)
     154        return ansitab[CUCUL_COLOR_LIGHTGRAY] & 0x0fff;
     155
     156    if(fg == CUCUL_COLOR_TRANSPARENT)
     157        return 0x0fff;
     158
     159    return fg & 0x0fff;
     160}
     161
     162uint16_t _cucul_argb32_to_rgb12bg(uint32_t c)
     163{
     164    uint16_t bg = c >> 16;
     165
     166    if(bg < CUCUL_COLOR_DEFAULT)
     167        return ansitab[bg] & 0x0fff;
     168
     169    if(bg == CUCUL_COLOR_DEFAULT)
     170        return ansitab[CUCUL_COLOR_BLACK] & 0x0fff;
     171
     172    if(bg == CUCUL_COLOR_TRANSPARENT)
     173        return 0x0fff;
     174
     175    return bg & 0x0fff;
     176}
     177
    91178void _cucul_argb32_to_argb4(uint32_t c, uint8_t argb[8])
    92179{
  • libcaca/trunk/cucul/cucul.h

    r777 r778  
    9898 *
    9999 *  @{ */
    100 void cucul_set_color(cucul_t *, unsigned int, unsigned int);
     100void cucul_set_color(cucul_t *, unsigned char, unsigned char);
     101void cucul_set_truecolor(cucul_t *, unsigned int, unsigned int);
    101102char const *cucul_get_color_name(unsigned int);
    102103void cucul_putchar(cucul_t *, int, int, char);
  • libcaca/trunk/cucul/cucul_internals.h

    r777 r778  
    6666uint8_t _cucul_argb32_to_ansi4fg(uint32_t);
    6767uint8_t _cucul_argb32_to_ansi4bg(uint32_t);
     68uint16_t _cucul_argb32_to_rgb12fg(uint32_t);
     69uint16_t _cucul_argb32_to_rgb12bg(uint32_t);
    6870void _cucul_argb32_to_argb4(uint32_t, uint8_t[8]);
    6971
Note: See TracChangeset for help on using the changeset viewer.