Browse Source

* Replace _cucul_attr_to_ansi8() with a now documented cucul_attr_to_ansi()

function.
tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
8c43b304c9
7 changed files with 39 additions and 29 deletions
  1. +2
    -2
      caca/driver_conio.c
  2. +1
    -1
      caca/driver_ncurses.c
  3. +2
    -2
      caca/driver_slang.c
  4. +2
    -2
      caca/driver_vga.c
  5. +26
    -14
      cucul/attr.c
  6. +1
    -0
      cucul/cucul.h
  7. +5
    -8
      cucul/cucul_internals.h

+ 2
- 2
caca/driver_conio.c View File

@@ -107,13 +107,13 @@ static void conio_display(caca_display_t *dp)
if(n && *chars == CUCUL_MAGIC_FULLWIDTH) if(n && *chars == CUCUL_MAGIC_FULLWIDTH)
{ {
*screen++ = '['; *screen++ = '[';
*screen++ = _cucul_attr_to_ansi8(*attrs++);
*screen++ = cucul_attr_to_ansi(*attrs++);
ch = ']'; ch = ']';
chars++; chars++;
n--; n--;
} }
*screen++ = ch; *screen++ = ch;
*screen++ = _cucul_attr_to_ansi8(*attrs++);
*screen++ = cucul_attr_to_ansi(*attrs++);
} }
# if defined(SCREENUPDATE_IN_PC_H) # if defined(SCREENUPDATE_IN_PC_H)
ScreenUpdate(dp->drv.p->screen); ScreenUpdate(dp->drv.p->screen);


+ 1
- 1
caca/driver_ncurses.c View File

@@ -203,7 +203,7 @@ static void ncurses_display(caca_display_t *dp)
move(y, 0); move(y, 0);
for(x = dp->cv->width; x--; ) for(x = dp->cv->width; x--; )
{ {
attrset(dp->drv.p->attr[_cucul_attr_to_ansi8(*attrs++)]);
attrset(dp->drv.p->attr[cucul_attr_to_ansi(*attrs++)]);
ncurses_write_utf32(*chars++); ncurses_write_utf32(*chars++);
} }
} }


+ 2
- 2
caca/driver_slang.c View File

@@ -242,11 +242,11 @@ static void slang_display(caca_display_t *dp)
else else
#endif #endif
{ {
SLsmg_set_color(slang_assoc[_cucul_attr_to_ansi8(*attrs++)]);
SLsmg_set_color(slang_assoc[cucul_attr_to_ansi(*attrs++)]);
slang_write_utf32(ch); slang_write_utf32(ch);
} }
#else #else
SLsmg_set_color(_cucul_attr_to_ansi8(*attrs++));
SLsmg_set_color(cucul_attr_to_ansi(*attrs++));
slang_write_utf32(ch); slang_write_utf32(ch);
#endif #endif
} }


+ 2
- 2
caca/driver_vga.c View File

@@ -125,13 +125,13 @@ static void vga_display(caca_display_t *dp)
if(n && *chars == CUCUL_MAGIC_FULLWIDTH) if(n && *chars == CUCUL_MAGIC_FULLWIDTH)
{ {
*screen++ = '['; *screen++ = '[';
*screen++ = _cucul_attr_to_ansi8(*attrs++);
*screen++ = cucul_attr_to_ansi(*attrs++);
ch = ']'; ch = ']';
chars++; chars++;
n--; n--;
} }
*screen++ = ch; *screen++ = ch;
*screen++ = _cucul_attr_to_ansi8(*attrs++);
*screen++ = cucul_attr_to_ansi(*attrs++);
} }
} }




+ 26
- 14
cucul/attr.c View File

@@ -234,6 +234,32 @@ int cucul_set_color_argb(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
return 0; return 0;
} }


/** \brief Get DOS ANSI information from attribute.
*
* Get the ANSI colour pair for a given attribute. The returned value is
* an 8-bit value whose higher 4 bits are the background colour and lower
* 4 bits are the foreground colour.
*
* If the attribute has ARGB colours, the nearest colour is used. Special
* attributes such as \e CUCUL_DEFAULT and \e CUCUL_TRANSPARENT are not
* handled and are both replaced with \e CUCUL_LIGHTGRAY for the foreground
* colour and \e CUCUL_BLACK for the background colour.
*
* This function never fails. If the attribute value is outside the expected
* 32-bit range, higher order bits are simply ignored.
*
* \param attr The requested attribute value.
* \return The corresponding DOS ANSI value.
*/
unsigned char cucul_attr_to_ansi(unsigned long int attr)
{
uint8_t fg = nearest_ansi((attr >> 4) & 0x3fff);
uint8_t bg = nearest_ansi(attr >> 18);

return (fg < 0x10 ? fg : CUCUL_LIGHTGRAY)
| ((bg < 0x10 ? bg : CUCUL_BLACK) << 4);
}

/** \brief Get ANSI foreground information from attribute. /** \brief Get ANSI foreground information from attribute.
* *
* Get the ANSI foreground colour value for a given attribute. The returned * Get the ANSI foreground colour value for a given attribute. The returned
@@ -336,20 +362,6 @@ static uint8_t nearest_ansi(uint16_t argb14)
return best; return best;
} }


uint8_t _cucul_attr_to_ansi8(uint32_t attr)
{
uint8_t fg = nearest_ansi((attr >> 4) & 0x3fff);
uint8_t bg = nearest_ansi(attr >> 18);

if(fg == CUCUL_DEFAULT || fg == CUCUL_TRANSPARENT)
fg = CUCUL_LIGHTGRAY;

if(bg == CUCUL_DEFAULT || bg == CUCUL_TRANSPARENT)
bg = CUCUL_BLACK;

return fg | (bg << 4);
}

uint16_t _cucul_attr_to_rgb12fg(uint32_t attr) uint16_t _cucul_attr_to_rgb12fg(uint32_t attr)
{ {
uint16_t fg = (attr >> 4) & 0x3fff; uint16_t fg = (attr >> 4) & 0x3fff;


+ 1
- 0
cucul/cucul.h View File

@@ -121,6 +121,7 @@ int cucul_rotate(cucul_canvas_t *);
* These functions perform conversions between attribute values. * These functions perform conversions between attribute values.
* *
* @{ */ * @{ */
unsigned char cucul_attr_to_ansi(unsigned long int);
unsigned char cucul_attr_to_ansi_fg(unsigned long int); unsigned char cucul_attr_to_ansi_fg(unsigned long int);
unsigned char cucul_attr_to_ansi_bg(unsigned long int); unsigned char cucul_attr_to_ansi_bg(unsigned long int);
/* @} */ /* @} */


+ 5
- 8
cucul/cucul_internals.h View File

@@ -57,13 +57,10 @@ extern unsigned int _cucul_strlen_utf8(char const *);
extern char const *_cucul_skip_utf8(char const *, unsigned int); extern char const *_cucul_skip_utf8(char const *, unsigned int);


/* Colour functions */ /* Colour functions */
uint8_t _cucul_attr_to_ansi8(uint32_t);
uint8_t _cucul_attr_to_ansi4fg(uint32_t);
uint8_t _cucul_attr_to_ansi4bg(uint32_t);
uint16_t _cucul_attr_to_rgb12fg(uint32_t);
uint16_t _cucul_attr_to_rgb12bg(uint32_t);
uint32_t _cucul_attr_to_rgb24fg(uint32_t);
uint32_t _cucul_attr_to_rgb24bg(uint32_t);
void _cucul_attr_to_argb4(uint32_t, uint8_t[8]);
extern uint16_t _cucul_attr_to_rgb12fg(uint32_t);
extern uint16_t _cucul_attr_to_rgb12bg(uint32_t);
extern uint32_t _cucul_attr_to_rgb24fg(uint32_t);
extern uint32_t _cucul_attr_to_rgb24bg(uint32_t);
extern void _cucul_attr_to_argb4(uint32_t, uint8_t[8]);


#endif /* __CUCUL_INTERNALS_H__ */ #endif /* __CUCUL_INTERNALS_H__ */

Loading…
Cancel
Save