瀏覽代碼

* Get rid of cucul_set_attr_ansi() and cucul_set_attr_argb and merge the

functionality into cucul_set_attr().
  * Add cucul_ansi_to_attr() and cucul_argb_to_attr().
  * Rename CUCUL_COLOR_* to CUCUL_*.
tags/v0.99.beta14
Sam Hocevar sam 18 年之前
父節點
當前提交
0b37a307dd
共有 32 個檔案被更改,包括 362 行新增361 行删除
  1. +4
    -4
      caca/caca0.c
  2. +17
    -17
      caca/caca0.h
  3. +1
    -1
      caca/driver_gl.c
  4. +6
    -6
      caca/driver_slang.c
  5. +90
    -104
      cucul/colour.c
  6. +1
    -1
      cucul/cucul.c
  7. +46
    -29
      cucul/cucul.h
  8. +10
    -10
      cucul/dither.c
  9. +4
    -4
      cucul/export.c
  10. +19
    -21
      cucul/import.c
  11. +1
    -1
      cucul/sprite.c
  12. +1
    -1
      src/aafire.c
  13. +13
    -14
      src/cacademo.c
  14. +1
    -1
      src/cacadraw.c
  15. +13
    -13
      src/cacaview.c
  16. +1
    -1
      src/img2irc.c
  17. +3
    -3
      test/colors.c
  18. +34
    -29
      test/demo.c
  19. +3
    -7
      test/dithering.c
  20. +4
    -4
      test/event.c
  21. +5
    -4
      test/export.c
  22. +3
    -3
      test/font.c
  23. +1
    -1
      test/font2tga.c
  24. +3
    -3
      test/frames.c
  25. +6
    -6
      test/fullwidth.c
  26. +3
    -3
      test/gamma.c
  27. +4
    -4
      test/input.c
  28. +3
    -3
      test/spritedit.c
  29. +8
    -8
      test/transform.c
  30. +2
    -2
      test/truecolor.c
  31. +14
    -11
      test/unicode.c
  32. +38
    -42
      tools/optipal.c

+ 4
- 4
caca/caca0.c 查看文件

@@ -29,8 +29,8 @@
/* These variables are needed to emulate old non-thread safe behaviour */
cucul_canvas_t *__caca0_cv = NULL;
caca_display_t *__caca0_dp = NULL;
unsigned char __caca0_fg = CUCUL_COLOR_LIGHTGRAY;
unsigned char __caca0_bg = CUCUL_COLOR_BLACK;
unsigned char __caca0_fg = CUCUL_LIGHTGRAY;
unsigned char __caca0_bg = CUCUL_BLACK;
char __caca0_utf8[2] = " ";

/* These functions are needed, too */
@@ -60,8 +60,8 @@ int __caca0_init(void)
__caca0_cv = NULL;
return -1;
}
__caca0_fg = CUCUL_COLOR_LIGHTGRAY;
__caca0_bg = CUCUL_COLOR_BLACK;
__caca0_fg = CUCUL_LIGHTGRAY;
__caca0_bg = CUCUL_BLACK;
return 0;
}



+ 17
- 17
caca/caca0.h 查看文件

@@ -50,22 +50,22 @@ extern char __caca0_utf8[];
/* These enums and macros changed names or values */
enum caca_color
{
CACA_COLOR_BLACK = CUCUL_COLOR_BLACK,
CACA_COLOR_BLUE = CUCUL_COLOR_BLUE,
CACA_COLOR_GREEN = CUCUL_COLOR_GREEN,
CACA_COLOR_CYAN = CUCUL_COLOR_CYAN,
CACA_COLOR_RED = CUCUL_COLOR_RED,
CACA_COLOR_MAGENTA = CUCUL_COLOR_MAGENTA,
CACA_COLOR_BROWN = CUCUL_COLOR_BROWN,
CACA_COLOR_LIGHTGRAY = CUCUL_COLOR_LIGHTGRAY,
CACA_COLOR_DARKGRAY = CUCUL_COLOR_DARKGRAY,
CACA_COLOR_LIGHTBLUE = CUCUL_COLOR_LIGHTBLUE,
CACA_COLOR_LIGHTGREEN = CUCUL_COLOR_LIGHTGREEN,
CACA_COLOR_LIGHTCYAN = CUCUL_COLOR_LIGHTCYAN,
CACA_COLOR_LIGHTRED = CUCUL_COLOR_LIGHTRED,
CACA_COLOR_LIGHTMAGENTA = CUCUL_COLOR_LIGHTMAGENTA,
CACA_COLOR_YELLOW = CUCUL_COLOR_YELLOW,
CACA_COLOR_WHITE = CUCUL_COLOR_WHITE,
CACA_COLOR_BLACK = CUCUL_BLACK,
CACA_COLOR_BLUE = CUCUL_BLUE,
CACA_COLOR_GREEN = CUCUL_GREEN,
CACA_COLOR_CYAN = CUCUL_CYAN,
CACA_COLOR_RED = CUCUL_RED,
CACA_COLOR_MAGENTA = CUCUL_MAGENTA,
CACA_COLOR_BROWN = CUCUL_BROWN,
CACA_COLOR_LIGHTGRAY = CUCUL_LIGHTGRAY,
CACA_COLOR_DARKGRAY = CUCUL_DARKGRAY,
CACA_COLOR_LIGHTBLUE = CUCUL_LIGHTBLUE,
CACA_COLOR_LIGHTGREEN = CUCUL_LIGHTGREEN,
CACA_COLOR_LIGHTCYAN = CUCUL_LIGHTCYAN,
CACA_COLOR_LIGHTRED = CUCUL_LIGHTRED,
CACA_COLOR_LIGHTMAGENTA = CUCUL_LIGHTMAGENTA,
CACA_COLOR_YELLOW = CUCUL_YELLOW,
CACA_COLOR_WHITE = CUCUL_WHITE,
};

enum caca_feature
@@ -131,7 +131,7 @@ enum caca_feature

#define caca_set_color(x, y) \
(__caca0_fg = (x), __caca0_bg = (y), \
cucul_set_attr_ansi(__caca0_cv, x, y, 0))
cucul_set_attr(__caca0_cv, cucul_ansi_to_attr(x, y)))
#define caca_get_fg_color() __caca0_fg
#define caca_get_bg_color() __caca0_bg
#define caca_get_color_name cucul_get_color_name


+ 1
- 1
caca/driver_gl.c 查看文件

@@ -512,7 +512,7 @@ static void gl_compute_font(caca_display_t *dp)

/* Allocate a libcucul canvas and print all the glyphs on it */
cv = cucul_create_canvas(1, b);
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLACK));

for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2)
{


+ 6
- 6
caca/driver_slang.c 查看文件

@@ -222,13 +222,13 @@ static void slang_display(caca_display_t *dp)

if(fgcolor == bgcolor)
{
if(fgcolor == CUCUL_COLOR_BLACK)
fgcolor = CUCUL_COLOR_WHITE;
else if(fgcolor == CUCUL_COLOR_WHITE
|| fgcolor <= CUCUL_COLOR_LIGHTGRAY)
fgcolor = CUCUL_COLOR_BLACK;
if(fgcolor == CUCUL_BLACK)
fgcolor = CUCUL_WHITE;
else if(fgcolor == CUCUL_WHITE
|| fgcolor <= CUCUL_LIGHTGRAY)
fgcolor = CUCUL_BLACK;
else
fgcolor = CUCUL_COLOR_WHITE;
fgcolor = CUCUL_WHITE;
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
SLsmg_write_char(' ');
attrs++;


+ 90
- 104
cucul/colour.c 查看文件

@@ -30,15 +30,6 @@
int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char);
int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int);

/* RGB colours for the ANSI palette. There is no real standard, so we
* use the same values as gnome-terminal. The 7th colour (brown) is a bit
* special: 0xfa50 instead of 0xfaa0. */
static const uint16_t ansitab[16] =
{
0xf000, 0xf00a, 0xf0a0, 0xf0aa, 0xfa00, 0xfa0a, 0xfa50, 0xfaaa,
0xf555, 0xf55f, 0xf5f5, 0xf5ff, 0xff55, 0xff5f, 0xfff5, 0xffff,
};

/** \brief Set the default character attribute.
*
* Set the default character attribute for drawing. Attributes define
@@ -47,9 +38,9 @@ static const uint16_t ansitab[16] =
* caca_printf() and graphical primitive functions such as caca_draw_line()
* will use this attribute.
*
* The attribute value is a 32-bit integer as returned by cucul_get_attr().
* For more user-friendly versions of this function, see cucul_set_attr_ansi()
* and cucul_set_attr_argb().
* The attribute value is a 32-bit integer as returned by cucul_get_attr()
* or created using cucul_ansi_to_attr() and cucul_argb_to_attr(), optionally
* ORed with style values such as CUCUL_UNDERLINE or CUCUL_BLINK.
*
* If an error occurs, -1 is returned and \b errno is set accordingly:
* - \c EINVAL The attribute value is out of the 32-bit range.
@@ -79,14 +70,14 @@ int cucul_set_attr(cucul_canvas_t *cv, unsigned long int attr)
* functions such as caca_printf() and graphical primitive functions such as
* caca_draw_line() will use these attributes.
*
* Color values are those defined in cucul.h, such as CUCUL_COLOR_RED
* or CUCUL_COLOR_TRANSPARENT.
* Color values are those defined in cucul.h, such as CUCUL_RED
* or CUCUL_TRANSPARENT.
*
* Style values are those defined in cucul.h, such as CUCUL_STYLE_UNDERLINE
* or CUCUL_STYLE_BLINK. The values can be ORed to set several styles at
* Style values are those defined in cucul.h, such as CUCUL_UNDERLINE
* or CUCUL_BLINK. The values can be ORed to set several styles at
* the same time.
*
* If an error occurs, -1 is returned and \b errno is set accordingly:
* If an error occurs, 0 is returned and \b errno is set accordingly:
* - \c EINVAL The colour values and/or the style mask are invalid.
*
* \param cv A handle to the libcucul canvas.
@@ -95,33 +86,23 @@ int cucul_set_attr(cucul_canvas_t *cv, unsigned long int attr)
* \param style The requested text styles.
* \return 0 in case of success, -1 if an error occurred.
*/
int cucul_set_attr_ansi(cucul_canvas_t *cv, unsigned char fg, unsigned char bg,
unsigned char style)
unsigned long int cucul_ansi_to_attr(unsigned char fg, unsigned char bg)
{
uint32_t attr;

if(fg > 0x20 || bg > 0x20 || style > 0x0f)
if(fg > 0x20 || bg > 0x20)
{
#if defined(HAVE_ERRNO_H)
errno = EINVAL;
#endif
return -1;
return 0;
}

attr = ((uint32_t)bg << 20) | ((uint32_t)fg << 4);

if(style)
attr |= (0x02004801 * style) & 0x10011001;

cv->curattr = attr;

return 0;
return ((unsigned long int)bg << 18) | ((unsigned long int)fg << 4);
}

/* Legacy function for old programs */
int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
{
return cucul_set_attr_ansi(cv, fg, bg, 0);
return cucul_set_attr(cv, cucul_ansi_to_attr(fg, bg));
}

/** \brief Set the default colour pair and text style (truecolor version).
@@ -134,11 +115,7 @@ int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
* instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is
* white with 50% alpha (A=8 R=15 G=15 B=15).
*
* Style values are those defined in cucul.h, such as CUCUL_STYLE_UNDERLINE
* or CUCUL_STYLE_BLINK. The values can be ORed to set several styles at
* the same time.
*
* If an error occurs, -1 is returned and \b errno is set accordingly:
* If an error occurs, 0 is returned and \b errno is set accordingly:
* - \c EINVAL At least one of the colour values is invalid.
*
* \param cv A handle to the libcucul canvas.
@@ -147,12 +124,9 @@ int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
* \param style The requested text styles.
* \return 0 in case of success, -1 if an error occurred.
*/
int cucul_set_attr_argb(cucul_canvas_t *cv, unsigned int fg, unsigned int bg,
unsigned char style)
unsigned long int cucul_argb_to_attr(unsigned int fg, unsigned int bg)
{
uint32_t attr;

if(fg > 0xffff || bg > 0xffff || style > 0x0f)
if(fg > 0xffff || bg > 0xffff)
{
#if defined(HAVE_ERRNO_H)
errno = EINVAL;
@@ -166,20 +140,16 @@ int cucul_set_attr_argb(cucul_canvas_t *cv, unsigned int fg, unsigned int bg,
if(bg < 0x100)
bg += 0x100;

attr = (((uint32_t)bg << 16) | (uint32_t)fg) & 0xeffeeffe;
fg = ((fg >> 1) & 0x7ff) | ((fg >> 13) << 11);
bg = ((bg >> 1) & 0x7ff) | ((bg >> 13) << 11);

if(style)
attr |= (0x02004801 * style) & 0x10011001;

cv->curattr = attr;

return 0;
return ((unsigned long int)bg << 18) | ((unsigned long int)fg << 4);
}

/* Legacy function for old programs */
int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
{
return cucul_set_attr_argb(cv, fg, bg, 0);
return cucul_set_attr(cv, cucul_argb_to_attr(fg, bg));
}

/** \brief Get the text attribute at the given coordinates.
@@ -188,17 +158,14 @@ int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
* given coordinates. The attribute value has 32 significant bits,
* organised as follows from MSB to LSB:
* - 3 bits for the background alpha
* - 1 bit for the blink flag
* - 4 bits for the background red component
* - 4 bits for the background green component
* - 3 bits for the background blue component
* - 1 bit for the underline flag
* - 3 bits for the foreground alpha
* - 1 bit for the italics flag
* - 4 bits for the foreground red component
* - 4 bits for the foreground green component
* - 3 bits for the foreground blue component
* - 1 bit for the bold flag
* - 4 bits for the bold, italics, underline and blink flags
*
* If the coordinates are outside the canvas boundaries, the current
* attribute is returned.
@@ -222,37 +189,52 @@ unsigned long int cucul_get_attr(cucul_canvas_t *cv, int x, int y)
* XXX: the following functions are local
*/

static uint8_t nearest_ansi(uint16_t argb16, uint8_t def)
/* RGB colours for the ANSI palette. There is no real standard, so we
* use the same values as gnome-terminal. The 7th colour (brown) is a bit
* special: 0xfa50 instead of 0xfaa0. */
static const uint16_t ansitab16[16] =
{
0xf000, 0xf00a, 0xf0a0, 0xf0aa, 0xfa00, 0xfa0a, 0xfa50, 0xfaaa,
0xf555, 0xf55f, 0xf5f5, 0xf5ff, 0xff55, 0xff5f, 0xfff5, 0xffff,
};

/* Same table, except on 14 bits (3-4-4-3) */
static const uint16_t ansitab14[16] =
{
0x3800, 0x3805, 0x3850, 0x3855, 0x3d00, 0x3d05, 0x3d28, 0x3d55,
0x3aaa, 0x3aaf, 0x3afa, 0x3aff, 0x3faa, 0x3faf, 0x3ffa, 0x3fff,
};

static uint8_t nearest_ansi(uint16_t argb14, uint8_t def)
{
unsigned int i, best, dist;

if(argb16 == (argb16 & 0x00f0))
return argb16 >> 4;
if(argb14 < 0x0010)
return argb14;

if(argb16 == (CUCUL_COLOR_DEFAULT << 4)
|| argb16 == (CUCUL_COLOR_TRANSPARENT << 4))
if(argb14 == CUCUL_DEFAULT || argb14 == CUCUL_TRANSPARENT)
return def;

if(argb16 < 0x6fff) /* too transparent, return default colour */
if(argb14 < 0x0fff) /* too transparent, return default colour */
return def;

best = def;
dist = 0xffff;
dist = 0x3fff;
for(i = 0; i < 16; i++)
{
unsigned int d = 0;
int a, b;

a = (ansitab[i] >> 8) & 0xf;
b = (argb16 >> 8) & 0xf;
a = (ansitab14[i] >> 7) & 0xf;
b = (argb14 >> 7) & 0xf;
d += (a - b) * (a - b);

a = (ansitab[i] >> 4) & 0xf;
b = (argb16 >> 4) & 0xf;
a = (ansitab14[i] >> 3) & 0xf;
b = (argb14 >> 3) & 0xf;
d += (a - b) * (a - b);

a = ansitab[i] & 0xf;
b = argb16 & 0xf;
a = (ansitab14[i] << 1) & 0xf;
b = (argb14 << 1) & 0xf;
d += (a - b) * (a - b);

if(d < dist)
@@ -267,53 +249,53 @@ static uint8_t nearest_ansi(uint16_t argb16, uint8_t def)

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

return nearest_ansi(fg, CUCUL_COLOR_LIGHTGRAY)
| (nearest_ansi(bg, CUCUL_COLOR_BLACK) << 4);
return nearest_ansi(fg, CUCUL_LIGHTGRAY)
| (nearest_ansi(bg, CUCUL_BLACK) << 4);
}

uint8_t _cucul_attr_to_ansi4fg(uint32_t attr)
{
return nearest_ansi(attr & 0xeffe, CUCUL_COLOR_LIGHTGRAY);
return nearest_ansi((attr >> 4) & 0x3fff, CUCUL_LIGHTGRAY);
}

uint8_t _cucul_attr_to_ansi4bg(uint32_t attr)
{
return nearest_ansi((attr >> 16) & 0xeffe, CUCUL_COLOR_BLACK);
return nearest_ansi(attr >> 18, CUCUL_BLACK);
}

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

if(fg == (fg & 0x00f0))
return ansitab[fg >> 4] & 0x0fff;
if(fg < 0x0010)
return ansitab16[fg] & 0x0fff;

if(fg == (CUCUL_COLOR_DEFAULT << 4))
return ansitab[CUCUL_COLOR_LIGHTGRAY] & 0x0fff;
if(fg == CUCUL_DEFAULT)
return ansitab16[CUCUL_LIGHTGRAY] & 0x0fff;

if(fg == (CUCUL_COLOR_TRANSPARENT << 4))
return ansitab[CUCUL_COLOR_LIGHTGRAY] & 0x0fff;
if(fg == CUCUL_TRANSPARENT)
return ansitab16[CUCUL_LIGHTGRAY] & 0x0fff;

return fg & 0x0fff;
return (fg << 1) & 0x0fff;
}

uint16_t _cucul_attr_to_rgb12bg(uint32_t attr)
{
uint16_t bg = (attr >> 16) & 0xeffe;
uint16_t bg = attr >> 18;

if(bg == (bg & 0x00f0))
return ansitab[bg >> 4] & 0x0fff;
if(bg < 0x0010)
return ansitab16[bg] & 0x0fff;

if(bg == (CUCUL_COLOR_DEFAULT << 4))
return ansitab[CUCUL_COLOR_BLACK] & 0x0fff;
if(bg == CUCUL_DEFAULT)
return ansitab16[CUCUL_BLACK] & 0x0fff;

if(bg == (CUCUL_COLOR_TRANSPARENT << 4))
return ansitab[CUCUL_COLOR_BLACK] & 0x0fff;
if(bg == CUCUL_TRANSPARENT)
return ansitab16[CUCUL_BLACK] & 0x0fff;

return bg & 0x0fff;
return (bg << 1) & 0x0fff;
}

#define RGB12TO24(i) \
@@ -333,28 +315,32 @@ uint32_t _cucul_attr_to_rgb24bg(uint32_t attr)

void _cucul_attr_to_argb4(uint32_t attr, uint8_t argb[8])
{
uint16_t fg = attr & 0xeffe;
uint16_t bg = (attr >> 16) & 0xeffe;

if(fg == (fg & 0x00f0))
fg = ansitab[fg >> 4];
else if(fg == (CUCUL_COLOR_DEFAULT << 4))
fg = ansitab[CUCUL_COLOR_LIGHTGRAY];
else if(fg == (CUCUL_COLOR_TRANSPARENT << 4))
fg = 0x0fff;

if(bg == (bg & 0x00f0))
bg = ansitab[bg >> 4];
else if(bg == (CUCUL_COLOR_DEFAULT << 4))
bg = ansitab[CUCUL_COLOR_BLACK];
else if(bg == (CUCUL_COLOR_TRANSPARENT << 4))
uint16_t fg = (attr >> 4) & 0x3fff;
uint16_t bg = attr >> 18;

if(bg < 0x0010)
bg = ansitab16[bg];
else if(bg == CUCUL_DEFAULT)
bg = ansitab16[CUCUL_BLACK];
else if(bg == CUCUL_TRANSPARENT)
bg = 0x0fff;
else
bg = ((bg << 2) & 0xf000) | ((bg << 1) & 0x0fff);

argb[0] = bg >> 12;
argb[1] = (bg >> 8) & 0xf;
argb[2] = (bg >> 4) & 0xf;
argb[3] = bg & 0xf;

if(fg < 0x0010)
fg = ansitab16[fg];
else if(fg == CUCUL_DEFAULT)
fg = ansitab16[CUCUL_LIGHTGRAY];
else if(fg == CUCUL_TRANSPARENT)
fg = 0x0fff;
else
fg = ((fg << 2) & 0xf000) | ((fg << 1) & 0x0fff);

argb[4] = fg >> 12;
argb[5] = (fg >> 8) & 0xf;
argb[6] = (fg >> 4) & 0xf;


+ 1
- 1
cucul/cucul.c 查看文件

@@ -59,7 +59,7 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height)

cv->refcount = 0;

cv->curattr = (CUCUL_COLOR_DEFAULT << 20) | (CUCUL_COLOR_TRANSPARENT < 4);
cv->curattr = (CUCUL_DEFAULT << 20) | (CUCUL_TRANSPARENT < 4);

cv->width = cv->height = 0;
cv->chars = NULL;


+ 46
- 29
cucul/cucul.h 查看文件

@@ -42,33 +42,32 @@ typedef struct cucul_font cucul_font_t;

/** \defgroup attributes libcucul attribute definitions
*
* Colours and styles that can be used with cucul_set_attr_ansi() and
* cucul_set_attr_argb().
* Colours and styles that can be used with cucul_set_attr().
*
* @{ */
#define CUCUL_COLOR_BLACK 0x00 /**< The colour index for black. */
#define CUCUL_COLOR_BLUE 0x01 /**< The colour index for blue. */
#define CUCUL_COLOR_GREEN 0x02 /**< The colour index for green. */
#define CUCUL_COLOR_CYAN 0x03 /**< The colour index for cyan. */
#define CUCUL_COLOR_RED 0x04 /**< The colour index for red. */
#define CUCUL_COLOR_MAGENTA 0x05 /**< The colour index for magenta. */
#define CUCUL_COLOR_BROWN 0x06 /**< The colour index for brown. */
#define CUCUL_COLOR_LIGHTGRAY 0x07 /**< The colour index for light gray. */
#define CUCUL_COLOR_DARKGRAY 0x08 /**< The colour index for dark gray. */
#define CUCUL_COLOR_LIGHTBLUE 0x09 /**< The colour index for blue. */
#define CUCUL_COLOR_LIGHTGREEN 0x0a /**< The colour index for light green. */
#define CUCUL_COLOR_LIGHTCYAN 0x0b /**< The colour index for light cyan. */
#define CUCUL_COLOR_LIGHTRED 0x0c /**< The colour index for light red. */
#define CUCUL_COLOR_LIGHTMAGENTA 0x0d /**< The colour index for light magenta. */
#define CUCUL_COLOR_YELLOW 0x0e /**< The colour index for yellow. */
#define CUCUL_COLOR_WHITE 0x0f /**< The colour index for white. */
#define CUCUL_COLOR_DEFAULT 0x10 /**< The output driver's default colour. */
#define CUCUL_COLOR_TRANSPARENT 0x20 /**< The transparent colour. */
#define CUCUL_STYLE_BOLD 0x01 /**< The style mask for bold. */
#define CUCUL_STYLE_ITALICS 0x02 /**< The style mask for italics. */
#define CUCUL_STYLE_UNDERLINE 0x04 /**< The style mask for underline. */
#define CUCUL_STYLE_BLINK 0x08 /**< The style mask for blink. */
#define CUCUL_BLACK 0x00 /**< The colour index for black. */
#define CUCUL_BLUE 0x01 /**< The colour index for blue. */
#define CUCUL_GREEN 0x02 /**< The colour index for green. */
#define CUCUL_CYAN 0x03 /**< The colour index for cyan. */
#define CUCUL_RED 0x04 /**< The colour index for red. */
#define CUCUL_MAGENTA 0x05 /**< The colour index for magenta. */
#define CUCUL_BROWN 0x06 /**< The colour index for brown. */
#define CUCUL_LIGHTGRAY 0x07 /**< The colour index for light gray. */
#define CUCUL_DARKGRAY 0x08 /**< The colour index for dark gray. */
#define CUCUL_LIGHTBLUE 0x09 /**< The colour index for blue. */
#define CUCUL_LIGHTGREEN 0x0a /**< The colour index for light green. */
#define CUCUL_LIGHTCYAN 0x0b /**< The colour index for light cyan. */
#define CUCUL_LIGHTRED 0x0c /**< The colour index for light red. */
#define CUCUL_LIGHTMAGENTA 0x0d /**< The colour index for light magenta. */
#define CUCUL_YELLOW 0x0e /**< The colour index for yellow. */
#define CUCUL_WHITE 0x0f /**< The colour index for white. */
#define CUCUL_DEFAULT 0x10 /**< The output driver's default colour. */
#define CUCUL_TRANSPARENT 0x20 /**< The transparent colour. */
#define CUCUL_BOLD 0x01 /**< The style mask for bold. */
#define CUCUL_ITALICS 0x02 /**< The style mask for italics. */
#define CUCUL_UNDERLINE 0x04 /**< The style mask for underline. */
#define CUCUL_BLINK 0x08 /**< The style mask for blink. */
/* @} */

/** \defgroup cucul libcucul basic functions
@@ -105,11 +104,9 @@ int cucul_free_buffer(cucul_buffer_t *);
* @{ */
#define CUCUL_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */
int cucul_set_attr(cucul_canvas_t *, unsigned long int);
int cucul_set_attr_ansi(cucul_canvas_t *, unsigned char, unsigned char,
unsigned char);
int cucul_set_attr_argb(cucul_canvas_t *, unsigned int, unsigned int,
unsigned char);
unsigned long int cucul_get_attr(cucul_canvas_t *, int, int);
unsigned long int cucul_ansi_to_attr(unsigned char, unsigned char);
unsigned long int cucul_argb_to_attr(unsigned int, unsigned int);
char const *cucul_get_color_name(unsigned int);
int cucul_putchar(cucul_canvas_t *, int, int, unsigned long int);
unsigned long int cucul_getchar(cucul_canvas_t *, int, int);
@@ -240,6 +237,26 @@ cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *, char const *);
char const * const * cucul_get_import_list(void);
/* @} */

/* Legacy macros */
#define CUCUL_COLOR_BLACK CUCUL_BLACK
#define CUCUL_COLOR_BLUE CUCUL_BLUE
#define CUCUL_COLOR_GREEN CUCUL_GREEN
#define CUCUL_COLOR_CYAN CUCUL_CYAN
#define CUCUL_COLOR_RED CUCUL_RED
#define CUCUL_COLOR_MAGENTA CUCUL_MAGENTA
#define CUCUL_COLOR_BROWN CUCUL_BROWN
#define CUCUL_COLOR_LIGHTGRAY CUCUL_LIGHTGRAY
#define CUCUL_COLOR_DARKGRAY CUCUL_DARKGRAY
#define CUCUL_COLOR_LIGHTBLUE CUCUL_LIGHTBLUE
#define CUCUL_COLOR_LIGHTGREEN CUCUL_LIGHTGREEN
#define CUCUL_COLOR_LIGHTCYAN CUCUL_LIGHTCYAN
#define CUCUL_COLOR_LIGHTRED CUCUL_LIGHTRED
#define CUCUL_COLOR_LIGHTMAGENTA CUCUL_LIGHTMAGENTA
#define CUCUL_COLOR_YELLOW CUCUL_YELLOW
#define CUCUL_COLOR_WHITE CUCUL_YELLOW
#define CUCUL_COLOR_DEFAULT CUCUL_DEFAULT
#define CUCUL_COLOR_TRANSPARENT CUCUL_TRANSPARENT

#ifdef __cplusplus
}
#endif


+ 10
- 10
cucul/dither.c 查看文件

@@ -1000,7 +1000,7 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
if(rgba[1] > lum) lum = rgba[1];
if(rgba[2] > lum) lum = rgba[2];
outfg = outbg;
outbg = CUCUL_COLOR_BLACK;
outbg = CUCUL_BLACK;

ch = lum * dchmax / 0x1000;
if(ch < 0)
@@ -1042,7 +1042,7 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
}

/* Now output the character */
cucul_set_attr_ansi(cv, outfg, outbg, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(outfg, outbg));
cucul_putchar(cv, x, y, outch);

d->increment_dither();
@@ -1378,16 +1378,16 @@ int _cucul_init_dither(void)
unsigned int v, s, h;

/* These ones are constant */
lookup_colors[0] = CUCUL_COLOR_BLACK;
lookup_colors[1] = CUCUL_COLOR_DARKGRAY;
lookup_colors[2] = CUCUL_COLOR_LIGHTGRAY;
lookup_colors[3] = CUCUL_COLOR_WHITE;
lookup_colors[0] = CUCUL_BLACK;
lookup_colors[1] = CUCUL_DARKGRAY;
lookup_colors[2] = CUCUL_LIGHTGRAY;
lookup_colors[3] = CUCUL_WHITE;

/* These ones will be overwritten */
lookup_colors[4] = CUCUL_COLOR_MAGENTA;
lookup_colors[5] = CUCUL_COLOR_LIGHTMAGENTA;
lookup_colors[6] = CUCUL_COLOR_RED;
lookup_colors[7] = CUCUL_COLOR_LIGHTRED;
lookup_colors[4] = CUCUL_MAGENTA;
lookup_colors[5] = CUCUL_LIGHTMAGENTA;
lookup_colors[6] = CUCUL_RED;
lookup_colors[7] = CUCUL_LIGHTRED;

for(v = 0; v < LOOKUP_VAL; v++)
for(s = 0; s < LOOKUP_SAT; s++)


+ 4
- 4
cucul/export.c 查看文件

@@ -230,9 +230,9 @@ static int export_utf8(cucul_canvas_t *cv, cucul_buffer_t *ex)
if(ch == CUCUL_MAGIC_FULLWIDTH)
continue;

fg = ((attr & 0xeffe) == (CUCUL_COLOR_DEFAULT << 4)) ?
fg = (((attr >> 4) & 0x7ffe) == (CUCUL_DEFAULT << 4)) ?
0x10 : palette[_cucul_attr_to_ansi4fg(attr)];
bg = (((attr >> 16) & 0xeffe) == (CUCUL_COLOR_TRANSPARENT << 4)) ?
bg = (((attr >> 18) & 0x7ffe) == (CUCUL_TRANSPARENT << 4)) ?
0x10 : palette[_cucul_attr_to_ansi4bg(attr)];

/* TODO: the [0 could be omitted in some cases */
@@ -537,10 +537,10 @@ static int export_irc(cucul_canvas_t *cv, cucul_buffer_t *ex)
if(ch == CUCUL_MAGIC_FULLWIDTH)
continue;

if((attr & 0xeffe) == (CUCUL_COLOR_DEFAULT << 4))
if(((attr >> 4) & 0x7ffe) == (CUCUL_DEFAULT << 4))
fg = 0x10;

if(((attr >> 16) & 0xeffe) == (CUCUL_COLOR_TRANSPARENT << 4))
if(((attr >> 18) & 0x7ffe) == (CUCUL_TRANSPARENT << 4))
bg = 0x10;

/* TODO: optimise series of same fg / same bg


+ 19
- 21
cucul/import.c 查看文件

@@ -202,7 +202,7 @@ static cucul_canvas_t *import_text(void const *data, unsigned int size)
return NULL;
}

cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT, CUCUL_TRANSPARENT));

for(i = 0; i < size; i++)
{
@@ -384,8 +384,8 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size,
break;
case 'K': /* EL - Erase In Line */
if(width < 80)
cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT,
CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT,
CUCUL_TRANSPARENT));
cucul_set_canvas_size(cv, width = 80, height);
for(j = x; j < 80; j++)
cucul_putchar(cv, j, y, ' ');
@@ -435,28 +435,28 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size,
/* Make sure the canvas is big enough. */
if((unsigned int)x + wch > width)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT,
CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT,
CUCUL_TRANSPARENT));
cucul_set_canvas_size(cv, width = x + wch, height);
}

if((unsigned int)y >= height)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT,
CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT,
CUCUL_TRANSPARENT));
cucul_set_canvas_size(cv, width, height = y + 1);
}

/* Now paste our character */
cucul_set_attr_ansi(cv, grcm.efg, grcm.ebg, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(grcm.efg, grcm.ebg));
cucul_putchar(cv, x, y, ch);
x += wch;
}

if((unsigned int)y > height)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT,
CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT,
CUCUL_TRANSPARENT));
cucul_set_canvas_size(cv, width, height = y);
}

@@ -470,10 +470,8 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct ansi_grcm *g,
{
static uint8_t const ansi2cucul[] =
{
CUCUL_COLOR_BLACK, CUCUL_COLOR_RED,
CUCUL_COLOR_GREEN, CUCUL_COLOR_BROWN,
CUCUL_COLOR_BLUE, CUCUL_COLOR_MAGENTA,
CUCUL_COLOR_CYAN, CUCUL_COLOR_LIGHTGRAY
CUCUL_BLACK, CUCUL_RED, CUCUL_GREEN, CUCUL_BROWN,
CUCUL_BLUE, CUCUL_MAGENTA, CUCUL_CYAN, CUCUL_LIGHTGRAY
};

unsigned int j;
@@ -492,8 +490,8 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct ansi_grcm *g,
else switch(argv[j])
{
case 0: /* default rendition */
g->fg = CUCUL_COLOR_DEFAULT;
g->bg = CUCUL_COLOR_TRANSPARENT;
g->fg = CUCUL_DEFAULT;
g->bg = CUCUL_TRANSPARENT;
g->bold = g->negative = g->concealed = 0;
break;
case 1: /* bold or increased intensity */
@@ -516,10 +514,10 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct ansi_grcm *g,
g->concealed = 0;
break;
case 39: /* default display colour (implementation-defined) */
g->fg = CUCUL_COLOR_DEFAULT;
g->fg = CUCUL_DEFAULT;
break;
case 49: /* default background colour (implementation-defined) */
g->bg = CUCUL_COLOR_TRANSPARENT;
g->bg = CUCUL_TRANSPARENT;
break;
default:
fprintf(stderr, "unknown sgr %i\n", argv[j]);
@@ -529,7 +527,7 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct ansi_grcm *g,

if(g->concealed)
{
g->efg = g->ebg = CUCUL_COLOR_TRANSPARENT;
g->efg = g->ebg = CUCUL_TRANSPARENT;
}
else
{
@@ -540,8 +538,8 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct ansi_grcm *g,
{
if(g->efg < 8)
g->efg += 8;
else if(g->efg == CUCUL_COLOR_DEFAULT)
g->efg = CUCUL_COLOR_WHITE;
else if(g->efg == CUCUL_DEFAULT)
g->efg = CUCUL_WHITE;
}
}
}


+ 1
- 1
cucul/sprite.c 查看文件

@@ -48,7 +48,7 @@ unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
*
* Set the active canvas frame. All subsequent drawing operations will
* be performed on that frame. The current painting context set by
* cucul_set_attr_ansi() or cucul_set_attr_argb() is inherited.
* cucul_set_attr() is inherited.
*
* If the frame index is outside the canvas' frame range, nothing happens.
*


+ 1
- 1
src/aafire.c 查看文件

@@ -240,7 +240,7 @@ drawfire (void)
paused:
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), cucul_dither, bitmap);
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
if (sloop < 100)
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30,
cucul_get_canvas_height(cv) - 2,


+ 13
- 14
src/cacademo.c 查看文件

@@ -161,17 +161,16 @@ paused:
if(next != -1)
{
fn[next](RENDER, backcv);
cucul_set_attr_ansi(mask, CUCUL_COLOR_LIGHTGRAY,
CUCUL_COLOR_BLACK, 0);
cucul_set_attr(mask, cucul_ansi_to_attr(CUCUL_LIGHTGRAY,
CUCUL_BLACK));
cucul_clear_canvas(mask);
cucul_set_attr_ansi(mask, CUCUL_COLOR_WHITE,
CUCUL_COLOR_WHITE, 0);
cucul_set_attr(mask, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_WHITE));
transition(mask, tmode,
100 * (frame - next_transition) / TRANSITION_FRAMES);
cucul_blit(frontcv, 0, 0, backcv, mask);
}

cucul_set_attr_ansi(frontcv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(frontcv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
if(frame < 100)
cucul_putstr(frontcv, cucul_get_canvas_width(frontcv) - 30,
cucul_get_canvas_height(frontcv) - 2,
@@ -694,10 +693,10 @@ void langton(enum action action, cucul_canvas_t *cv)
uint8_t p = screen[x + width * y];

if(p & 0x0f)
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, p >> 4, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, p >> 4));
else
cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK,
CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK,
CUCUL_BLACK));
cucul_putchar(cv, x, y, gradient[p & 0x0f]);
}
}
@@ -761,7 +760,7 @@ void matrix(enum action action, cucul_canvas_t *cv)
w = cucul_get_canvas_width(cv);
h = cucul_get_canvas_height(cv);

cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_BLACK));
cucul_clear_canvas(cv);

for(i = 0; i < MAXDROPS && i < (w * h / 32); i++)
@@ -776,14 +775,14 @@ void matrix(enum action action, cucul_canvas_t *cv)
unsigned int fg;

if(j < 2)
fg = CUCUL_COLOR_WHITE;
fg = CUCUL_WHITE;
else if(j < drop[i].len / 4)
fg = CUCUL_COLOR_LIGHTGREEN;
fg = CUCUL_LIGHTGREEN;
else if(j < drop[i].len * 4 / 5)
fg = CUCUL_COLOR_GREEN;
fg = CUCUL_GREEN;
else
fg = CUCUL_COLOR_DARKGRAY;
cucul_set_attr_ansi(cv, fg, CUCUL_COLOR_BLACK, 0);
fg = CUCUL_DARKGRAY;
cucul_set_attr(cv, cucul_ansi_to_attr(fg, CUCUL_BLACK));

cucul_putchar(cv, x, y - j,
drop[i].str[(y - j) % drop[i].len]);


+ 1
- 1
src/cacadraw.c 查看文件

@@ -151,7 +151,7 @@ quit:

static int refresh_screen(void)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_DEFAULT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT, CUCUL_DEFAULT));
cucul_clear_canvas(cv);

cucul_blit(cv, - x, - y, image, NULL);


+ 13
- 13
src/cacaview.c 查看文件

@@ -304,7 +304,7 @@ int main(int argc, char **argv)

sprintf(buffer, " Loading `%s'... ", list[current]);
buffer[ww] = '\0';
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(cv, (ww - strlen(buffer)) / 2, wh / 2, buffer);
caca_refresh_display(dp);
ww = cucul_get_canvas_width(cv);
@@ -324,12 +324,12 @@ int main(int argc, char **argv)
free(buffer);
}

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLACK));
cucul_clear_canvas(cv);

if(!items)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_printf(cv, ww / 2 - 5, wh / 2, " No image. ");
}
else if(!im)
@@ -349,7 +349,7 @@ int main(int argc, char **argv)

sprintf(buffer, ERROR_STRING, list[current]);
buffer[ww] = '\0';
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(cv, (ww - strlen(buffer)) / 2, wh / 2, buffer);
free(buffer);
}
@@ -379,8 +379,8 @@ int main(int argc, char **argv)
print_status();

#if 0 /* FIXME */
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY,
CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY,
CUCUL_BLACK));
switch(status)
{
case STATUS_ANTIALIASING:
@@ -419,7 +419,7 @@ int main(int argc, char **argv)

static void print_status(void)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_draw_line(cv, 0, 0, ww - 1, 0, " ");
cucul_draw_line(cv, 0, wh - 2, ww - 1, wh - 2, "-");
cucul_putstr(cv, 0, 0, "q:Quit np:Next/Prev +-x:Zoom gG:Gamma "
@@ -429,7 +429,7 @@ static void print_status(void)
cucul_printf(cv, ww - 30, wh - 2, "(gamma: %#.3g)", GAMMA(g));
cucul_printf(cv, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom);

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_draw_line(cv, 0, wh - 1, ww - 1, wh - 1, " ");
}

@@ -457,7 +457,7 @@ static void print_help(int x, int y)

int i;

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));

for(i = 0; help[i]; i++)
cucul_putstr(cv, x, y + i, help[i]);
@@ -518,11 +518,11 @@ static void draw_checkers(int x, int y, int w, int h)
for(xn = x > 0 ? x : 0; xn < x + w; xn++)
{
if((((xn - x) / 5) ^ ((yn - y) / 3)) & 1)
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY,
CUCUL_COLOR_DARKGRAY, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY,
CUCUL_DARKGRAY));
else
cucul_set_attr_ansi(cv, CUCUL_COLOR_DARKGRAY,
CUCUL_COLOR_LIGHTGRAY, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DARKGRAY,
CUCUL_LIGHTGRAY));
cucul_putchar(cv, xn, yn, ' ');
}
}


+ 1
- 1
src/img2irc.c 查看文件

@@ -56,7 +56,7 @@ int main(int argc, char **argv)
lines = cols * i->h * 6 / i->w / 10;

cucul_set_canvas_size(cv, cols, lines);
cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT, CUCUL_TRANSPARENT));
cucul_clear_canvas(cv);
cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels);



+ 3
- 3
test/colors.c 查看文件

@@ -35,16 +35,16 @@ int main(int argc, char **argv)
if(!dp)
return 1;

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(cv);
for(i = 0; i < 16; i++)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_printf(cv, 4, i + (i >= 8 ? 4 : 3), "'%cv': %i (%s)",
'a' + i, i, cucul_get_color_name(i));
for(j = 0; j < 16; j++)
{
cucul_set_attr_ansi(cv, i, j, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(i, j));
cucul_putstr(cv, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3),
"Aa");
}


+ 34
- 29
test/demo.c 查看文件

@@ -150,8 +150,8 @@ int main(int argc, char **argv)

if(demo)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY,
CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY,
CUCUL_BLACK));
cucul_clear_canvas(cv);
}
}
@@ -172,7 +172,7 @@ int main(int argc, char **argv)
display_menu();
if(mouse && !demo)
{
cucul_set_attr_ansi(cv, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_RED, CUCUL_BLACK));
cucul_putstr(cv, xmouse, ymouse, ".");
cucul_putstr(cv, xmouse, ymouse + 1, "|\\");
}
@@ -184,8 +184,8 @@ int main(int argc, char **argv)
{
demo();

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY,
CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY,
CUCUL_BLACK));
cucul_draw_thin_box(cv, 1, 1, cucul_get_canvas_width(cv) - 2,
cucul_get_canvas_height(cv) - 2);
cucul_printf(cv, 4, 1, "[%i.%i fps]----",
@@ -210,7 +210,7 @@ static void display_menu(void)
int xo = cucul_get_canvas_width(cv) - 2;
int yo = cucul_get_canvas_height(cv) - 2;

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(cv);
cucul_draw_thin_box(cv, 1, 1, xo, yo);

@@ -252,11 +252,11 @@ static void demo_all(void)

i++;

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(cv);

/* Draw the sun */
cucul_set_attr_ansi(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_BLACK));
xo = cucul_get_canvas_width(cv) / 4;
yo = cucul_get_canvas_height(cv) / 4 + 5 * sin(0.03*i);

@@ -268,9 +268,9 @@ static void demo_all(void)
}

j = 15 + sin(0.03*i) * 8;
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLACK));
cucul_fill_ellipse(cv, xo, yo, j, j / 2, "#");
cucul_set_attr_ansi(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_BLACK));
cucul_draw_ellipse(cv, xo, yo, j, j / 2, "#");

/* Draw the pyramid */
@@ -286,19 +286,19 @@ static void demo_all(void)
xc = cucul_get_canvas_width(cv) / 4 - sin(0.02*i) * 5;
yc = cucul_get_canvas_height(cv) * 3 / 4 + cos(0.02*i) * 5;

cucul_set_attr_ansi(cv, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_GREEN, CUCUL_BLACK));
cucul_fill_triangle(cv, xo, yo, xb, yb, xa, ya, "%");
cucul_set_attr_ansi(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_BLACK));
cucul_draw_thin_triangle(cv, xo, yo, xb, yb, xa, ya);

cucul_set_attr_ansi(cv, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_RED, CUCUL_BLACK));
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, "#");
cucul_set_attr_ansi(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_BLACK));
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);

cucul_set_attr_ansi(cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLUE, CUCUL_BLACK));
cucul_fill_triangle(cv, xo, yo, xb, yb, xc, yc, "%");
cucul_set_attr_ansi(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_BLACK));
cucul_draw_thin_triangle(cv, xo, yo, xb, yb, xc, yc);

/* Draw a background triangle */
@@ -311,7 +311,7 @@ static void demo_all(void)
xc = cucul_get_canvas_width(cv) / 3;
yc = cucul_get_canvas_height(cv) - 3;

cucul_set_attr_ansi(cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_CYAN, CUCUL_BLACK));
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);

xo = cucul_get_canvas_width(cv) / 2 + cos(0.027*i) * cucul_get_canvas_width(cv) / 3;
@@ -330,7 +330,8 @@ static void demo_all(void)
for(j = i - 60; j < i; j++)
{
int delta = cucul_rand(-5, 6);
cucul_set_attr_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16), 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16),
cucul_rand(0, 16)));
cucul_putchar(cv, cucul_get_canvas_width(cv) / 2
+ cos(0.02*j) * (delta + cucul_get_canvas_width(cv) / 4),
cucul_get_canvas_height(cv) / 2
@@ -359,7 +360,8 @@ static void demo_dots(void)
for(i = 1000; i--;)
{
/* Putpixel */
cucul_set_attr_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16), 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16),
cucul_rand(0, 16)));
cucul_putchar(cv, cucul_rand(0, xmax), cucul_rand(0, ymax),
chars[cucul_rand(0, 9)]);
}
@@ -370,16 +372,16 @@ static void demo_color(void)
int i, j;
char buf[BUFSIZ];

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(cv);
for(i = 0; i < 16; i++)
{
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, cucul_get_color_name(i));
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_putstr(cv, 4, i + (i >= 8 ? 4 : 3), buf);
for(j = 0; j < 16; j++)
{
cucul_set_attr_ansi(cv, i, j, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(i, j));
cucul_putstr(cv, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# ");
}
}
@@ -402,7 +404,7 @@ static void demo_lines(void)
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
}

cucul_set_attr_ansi(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16), CUCUL_BLACK));
if(outline > 1)
cucul_draw_thin_line(cv, xa, ya, xb, yb);
else
@@ -426,10 +428,11 @@ static void demo_boxes(void)
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
}

cucul_set_attr_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16), 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16),
cucul_rand(0, 16)));
cucul_fill_box(cv, xa, ya, xb, yb, "#");

cucul_set_attr_ansi(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16), CUCUL_BLACK));
if(outline == 2)
cucul_draw_thin_box(cv, xa, ya, xb, yb);
else if(outline == 1)
@@ -457,10 +460,11 @@ static void demo_ellipses(void)
} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
}

cucul_set_attr_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16), 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16),
cucul_rand(0, 16)));
cucul_fill_ellipse(cv, x, y, a, b, "#");

cucul_set_attr_ansi(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16), CUCUL_BLACK));
if(outline == 2)
cucul_draw_thin_ellipse(cv, x, y, a, b);
else if(outline == 1)
@@ -487,10 +491,11 @@ static void demo_triangles(void)
xc = cucul_rand(0, w); yc = cucul_rand(0, h);
}

cucul_set_attr_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16), 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16),
cucul_rand(0, 16)));
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, "#");

cucul_set_attr_ansi(cv, cucul_rand(0, 16), CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(cucul_rand(0, 16), CUCUL_BLACK));
if(outline == 2)
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
else if(outline == 1)


+ 3
- 7
test/dithering.c 查看文件

@@ -27,12 +27,8 @@

unsigned int points[] =
{
CUCUL_COLOR_BLACK,
CUCUL_COLOR_DARKGRAY,
CUCUL_COLOR_LIGHTGRAY,
CUCUL_COLOR_WHITE,
CUCUL_COLOR_RED,
CUCUL_COLOR_LIGHTRED
CUCUL_BLACK, CUCUL_DARKGRAY, CUCUL_LIGHTGRAY,
CUCUL_WHITE, CUCUL_RED, CUCUL_LIGHTRED
};

char density[] = " ',+:;o&%w$W@#";
@@ -120,7 +116,7 @@ int main(int argc, char *argv[])
ch = density[distb * 2 * 13 / (dista + distb)];
else
ch = density[dista * 2 * 13 / (dista + distb)];
cucul_set_attr_ansi(cv, points[nearb], points[neara], 0);
cucul_set_attr(cv, cucul_ansi_to_attr(points[nearb], points[neara]));

cucul_putchar(cv, x * cucul_get_canvas_width(cv) / 100,
(100 - y) * cucul_get_canvas_height(cv) / 100, ch);


+ 4
- 4
test/event.c 查看文件

@@ -41,7 +41,7 @@ int main(int argc, char **argv)

h = cucul_get_canvas_height(cv) - 1;

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, " ");

cucul_draw_line(cv, 0, h, cucul_get_canvas_width(cv) - 1, h, " ");
@@ -83,11 +83,11 @@ int main(int argc, char **argv)
}
while(ret);

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(cv);

/* Print current event */
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, " ");
print_event(0, 0, events);

@@ -95,7 +95,7 @@ int main(int argc, char **argv)
cucul_printf(cv, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);

/* Print previous events */
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLACK));
for(i = 1; i < h && events[i].type; i++)
print_event(0, i, events + i);



+ 5
- 4
test/export.c 查看文件

@@ -115,10 +115,10 @@ int main(int argc, char *argv[])
cucul_get_canvas_height(cv), dither, pixels);
cucul_free_dither(dither);

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLACK));
cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);

cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_WHITE));
cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
WIDTH / 4, HEIGHT / 4, " ");
cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 5, "(\") \\o/ <&>");
@@ -126,12 +126,13 @@ int main(int argc, char *argv[])
cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_LIGHTBLUE));
cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");

for(x = 0; x < 16; x++)
{
cucul_set_attr_argb(cv, 0xff00 | x, 0xf00f | (x << 4), 0);
cucul_set_attr(cv, cucul_argb_to_attr(0xff00 | x,
0xf00f | (x << 4)));
cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
}
}


+ 3
- 3
test/font.c 查看文件

@@ -45,11 +45,11 @@ int main(int argc, char *argv[])
cv = cucul_create_canvas(8, 2);

/* Draw stuff on our canvas */
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLACK));
cucul_putstr(cv, 0, 0, "ABcde");
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTRED, CUCUL_BLACK));
cucul_putstr(cv, 5, 0, "\\o/");
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(cv, 0, 1, "&$âøÿØ?!");

/* Load a libcucul internal font */


+ 1
- 1
test/font2tga.c 查看文件

@@ -58,7 +58,7 @@ int main(int argc, char *argv[])

/* Create a canvas */
cv = cucul_create_canvas(WIDTH, (glyphs + WIDTH - 1) / WIDTH);
cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_WHITE));

/* Put all glyphs on the canvas */
x = y = 0;


+ 3
- 3
test/frames.c 查看文件

@@ -48,9 +48,9 @@ int main(int argc, char *argv[])
for(frame = 0; frame < 16; frame++)
{
cucul_set_canvas_frame(cv, frame);
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, frame, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, frame));
cucul_fill_box(cv, 0, 0, 40, 15, ":");
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(cv, frame * 5 / 2, frame, "カカ");
}

@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "canvas shrinked, size is %ix%i\n",
cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));

cucul_set_attr_ansi(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_DEFAULT, CUCUL_TRANSPARENT));
dp = caca_create_display(cv);
caca_set_display_time(dp, 50000);



+ 6
- 6
test/fullwidth.c 查看文件

@@ -42,9 +42,9 @@ int main(int argc, char *argv[])
/* Line of x's */
for(i = 0; i < 10; i++)
{
cucul_set_attr_ansi(caca, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(caca, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(caca, 0, i, CACA);
cucul_set_attr_ansi(caca, CUCUL_COLOR_WHITE, CUCUL_COLOR_RED, 0);
cucul_set_attr(caca, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_RED));
cucul_putchar(caca, i - 2, i, 'x');
}

@@ -53,20 +53,20 @@ int main(int argc, char *argv[])
/* Line of ホ's */
for(i = 0; i < 10; i++)
{
cucul_set_attr_ansi(caca, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(caca, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(caca, 0, i, CACA);
cucul_set_attr_ansi(caca, CUCUL_COLOR_WHITE, CUCUL_COLOR_GREEN, 0);
cucul_set_attr(caca, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_GREEN));
cucul_putstr(caca, i - 2, i, "ホ");
}

cucul_blit(cv, 15, 1, caca, NULL);

/* Line of canvas */
cucul_set_attr_ansi(line, CUCUL_COLOR_WHITE, CUCUL_COLOR_MAGENTA, 0);
cucul_set_attr(line, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_MAGENTA));
cucul_putstr(line, 0, 0, "ほ");
for(i = 0; i < 10; i++)
{
cucul_set_attr_ansi(caca, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(caca, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(caca, 0, i, CACA);
cucul_blit(caca, i - 2, i, line, NULL);
}


+ 3
- 3
test/gamma.c 查看文件

@@ -86,9 +86,9 @@ int main(int argc, char *argv[])
cucul_get_canvas_height(cw), right, buffer);

/* Draw something on the mask */
cucul_set_attr_ansi(mask, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(mask, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(mask);
cucul_set_attr_ansi(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE, 0);
cucul_set_attr(mask, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_WHITE));
cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
* 0.5 * cucul_get_canvas_width(mask),
(1.0 + cos(0.05 * (float)x))
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
/* Blit the spare canvas onto the first one */
cucul_blit(cv, 0, 0, cw, mask);

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_printf(cv, 2, 1,
"gamma=%g - use arrows to change, Esc to quit", gam);



+ 4
- 4
test/input.c 查看文件

@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
cv = cucul_create_canvas(0, 0);
dp = caca_create_display(cv);

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(cv, 1, 1, "Text entries - press tab to cycle");

for(i = 0; i < TEXT_ENTRIES; i++)
@@ -61,8 +61,8 @@ int main(int argc, char *argv[])
{
unsigned int j, start, size;

cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK,
CUCUL_COLOR_LIGHTGRAY, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK,
CUCUL_LIGHTGRAY));
cucul_fill_box(cv, 2, 3 * i + 4, 2 + BUFFER_SIZE, 3 * i + 4, " ");

start = 0;
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
}

/* Put the cursor on the active textentry */
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTRED, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTRED, CUCUL_LIGHTRED));
cucul_putchar(cv, 2 + entries[e].cursor, 3 * e + 4, ' ');

caca_refresh_display(dp);


+ 3
- 3
test/spritedit.c 查看文件

@@ -102,7 +102,7 @@ int main(int argc, char **argv)
}


cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_clear_canvas(cv);

cucul_draw_thin_box(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
@@ -125,9 +125,9 @@ int main(int argc, char **argv)
ya = -1 - cucul_get_sprite_dy(sprite, frame);
xb = xa + 1 + cucul_get_sprite_width(sprite, frame);
yb = ya + 1 + cucul_get_sprite_height(sprite, frame);
cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_BLACK));
cucul_fill_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK));
cucul_draw_thin_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
cucul_draw_sprite(cv, 57, 10, sprite, frame);



+ 8
- 8
test/transform.c 查看文件

@@ -58,26 +58,26 @@ int main(int argc, char *argv[])
flop = cucul_create_canvas(70, 6);
rotate = cucul_create_canvas(70, 6);

cucul_set_attr_ansi(normal, CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_LIGHTMAGENTA, CUCUL_BLACK));
for(i = 0; pig[i]; i++)
cucul_putstr(normal, 55, i, pig[i]);

cucul_set_attr_ansi(normal, CUCUL_COLOR_LIGHTGREEN, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_LIGHTGREEN, CUCUL_BLACK));
for(i = 0; duck[i]; i++)
cucul_putstr(normal, 30, 1 + i, duck[i]);

cucul_set_attr_ansi(normal, CUCUL_COLOR_LIGHTCYAN, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_LIGHTCYAN, CUCUL_BLACK));
cucul_putstr(normal, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
cucul_set_attr_ansi(normal, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_LIGHTRED, CUCUL_BLACK));
cucul_putchar(normal, 38, 1, '|');

cucul_set_attr_ansi(normal, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_BLACK));
cucul_putstr(normal, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");

cucul_set_attr_ansi(normal, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTRED, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_LIGHTRED));
cucul_putstr(normal, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
cucul_putstr(normal, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
cucul_set_attr_ansi(normal, CUCUL_COLOR_BLACK, CUCUL_COLOR_LIGHTRED, 0);
cucul_set_attr(normal, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_LIGHTRED));
cucul_putstr(normal, 4, 3, "▓▒░");
cucul_putstr(normal, 4, 4, "▓▒░");
cucul_putstr(normal, 24, 3, "░▒▓");
@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
cucul_rotate(rotate);

/* Blit the transformed canvas onto the main canvas */
cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE));
cucul_putstr(cv, 0, 0, "normal");
cucul_blit(cv, 10, 0, normal, NULL);
cucul_putstr(cv, 0, 6, "flip");


+ 2
- 2
test/truecolor.c 查看文件

@@ -40,11 +40,11 @@ int main(int argc, char *argv[])
uint16_t bgcolor = 0xff00 | (y << 4) | x;
uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8);

cucul_set_attr_argb(cv, fgcolor, bgcolor, 0);
cucul_set_attr(cv, cucul_argb_to_attr(fgcolor, bgcolor));
cucul_putstr(cv, x * 2, y, "CA");
}

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_LIGHTBLUE));
cucul_putstr(cv, 2, 1, " truecolor libcaca ");

caca_refresh_display(dp);


+ 14
- 11
test/unicode.c 查看文件

@@ -24,6 +24,9 @@
#include "cucul.h"
#include "caca.h"

#define ATTR_WHITE_ON_BLUE cucul_ansi_to_attr(CUCUL_WHITE, CUCUL_BLUE)
#define ATTR_DEFAULT cucul_ansi_to_attr(CUCUL_DEFAULT, CUCUL_TRANSPARENT)

int main(int argc, char *argv[])
{
cucul_canvas_t *cv;
@@ -32,52 +35,52 @@ int main(int argc, char *argv[])
cv = cucul_create_canvas(0, 0);
dp = caca_create_display(cv);

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, ATTR_WHITE_ON_BLUE);
cucul_putstr(cv, 1, 1, "Basic Unicode support");

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, ATTR_DEFAULT);
cucul_putstr(cv, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
cucul_putstr(cv, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
cucul_putstr(cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");

cucul_putstr(cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, ATTR_WHITE_ON_BLUE);
cucul_putstr(cv, 1, 7, "Gradient glyphs");

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, ATTR_DEFAULT);
cucul_putstr(cv, 31, 8, " 0%");
cucul_putstr(cv, 31, 9, " 25%");
cucul_putstr(cv, 31, 10, " 50%");
cucul_putstr(cv, 31, 11, " 75%");
cucul_putstr(cv, 31, 12, "100%");

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTGREEN, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTRED, CUCUL_LIGHTGREEN));
cucul_putstr(cv, 1, 8, " ");
cucul_putstr(cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_putstr(cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_putstr(cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_putstr(cv, 1, 12, "█████████████████████████████");

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGREEN, CUCUL_COLOR_LIGHTRED, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGREEN, CUCUL_LIGHTRED));
cucul_putstr(cv, 36, 8, "█████████████████████████████");
cucul_putstr(cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_putstr(cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_putstr(cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_putstr(cv, 36, 12, " ");

cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, 0);
cucul_set_attr(cv, ATTR_WHITE_ON_BLUE);
cucul_putstr(cv, 1, 14, "Double width characters");

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTRED, CUCUL_TRANSPARENT));
cucul_putstr(cv, 1, 15, "| ドラゴン ボーレ |");
cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, ATTR_DEFAULT);
cucul_putstr(cv, 1, 16, "| ()()()() ()()() |");
cucul_set_attr_ansi(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_YELLOW, CUCUL_TRANSPARENT));
cucul_putstr(cv, 1, 17, "| ドラゴン");
cucul_putstr(cv, 12, 17, "ボーレ |");

cucul_set_attr_ansi(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK, 0);
cucul_set_attr(cv, ATTR_DEFAULT);
cucul_putstr(cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");

cucul_putstr(cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");


+ 38
- 42
tools/optipal.c 查看文件

@@ -29,12 +29,8 @@ static int slang_assoc[16*16], palette[16*16];
/* 6 colours in hue order */
static unsigned int const hue_list[] =
{
CUCUL_COLOR_RED,
CUCUL_COLOR_BROWN,
CUCUL_COLOR_GREEN,
CUCUL_COLOR_CYAN,
CUCUL_COLOR_BLUE,
CUCUL_COLOR_MAGENTA
CUCUL_RED, CUCUL_BROWN, CUCUL_GREEN,
CUCUL_CYAN, CUCUL_BLUE, CUCUL_MAGENTA
};

#define SETPAIR(_fg, _bg, _n) \
@@ -171,14 +167,14 @@ static void base_colors(void)

/* black background colour pairs that are needed for the old renderer */
for(i = 1; i < 16; i++)
SETPAIR(i, CUCUL_COLOR_BLACK, cur++);
SETPAIR(i, CUCUL_BLACK, cur++);

/* gray combinations used for grayscale dithering */
SETPAIR(CUCUL_COLOR_BLACK, CUCUL_COLOR_DARKGRAY, cur++);
SETPAIR(CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY, cur++);
SETPAIR(CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY, cur++);
SETPAIR(CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTGRAY, cur++);
SETPAIR(CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_WHITE, cur++);
SETPAIR(CUCUL_BLACK, CUCUL_DARKGRAY, cur++);
SETPAIR(CUCUL_DARKGRAY, CUCUL_LIGHTGRAY, cur++);
SETPAIR(CUCUL_LIGHTGRAY, CUCUL_DARKGRAY, cur++);
SETPAIR(CUCUL_WHITE, CUCUL_LIGHTGRAY, cur++);
SETPAIR(CUCUL_LIGHTGRAY, CUCUL_WHITE, cur++);

/* white/light, light/dark, lightgray/light, darkgray/dark, dark/black
* combinations often used for saturation/value dithering (the two
@@ -186,15 +182,15 @@ static void base_colors(void)
* not considered here) */
for(i = 1; i < 7; i++)
{
SETPAIR(CUCUL_COLOR_WHITE, i + 8, cur++);
SETPAIR(i + 8, CUCUL_COLOR_WHITE, cur++);
SETPAIR(CUCUL_WHITE, i + 8, cur++);
SETPAIR(i + 8, CUCUL_WHITE, cur++);
SETPAIR(i, i + 8, cur++);
SETPAIR(i + 8, i, cur++);
SETPAIR(CUCUL_COLOR_LIGHTGRAY, i + 8, cur++);
SETPAIR(i + 8, CUCUL_COLOR_LIGHTGRAY, cur++);
SETPAIR(CUCUL_COLOR_DARKGRAY, i, cur++);
SETPAIR(i, CUCUL_COLOR_DARKGRAY, cur++);
SETPAIR(CUCUL_COLOR_BLACK, i, cur++);
SETPAIR(CUCUL_LIGHTGRAY, i + 8, cur++);
SETPAIR(i + 8, CUCUL_LIGHTGRAY, cur++);
SETPAIR(CUCUL_DARKGRAY, i, cur++);
SETPAIR(i, CUCUL_DARKGRAY, cur++);
SETPAIR(CUCUL_BLACK, i, cur++);
}

/* next colour combinations for hue dithering (magenta/blue, blue/green
@@ -219,12 +215,12 @@ static void base_colors(void)

/* black on light gray, black on white, white on dark gray, dark gray
* on white, white on blue, light gray on blue (chosen arbitrarily) */
SETPAIR(CUCUL_COLOR_BLACK, CUCUL_COLOR_LIGHTGRAY, cur++);
SETPAIR(CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE, cur++);
SETPAIR(CUCUL_COLOR_WHITE, CUCUL_COLOR_DARKGRAY, cur++);
SETPAIR(CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_WHITE, cur++);
SETPAIR(CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE, cur++);
SETPAIR(CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLUE, cur++);
SETPAIR(CUCUL_BLACK, CUCUL_LIGHTGRAY, cur++);
SETPAIR(CUCUL_BLACK, CUCUL_WHITE, cur++);
SETPAIR(CUCUL_WHITE, CUCUL_DARKGRAY, cur++);
SETPAIR(CUCUL_DARKGRAY, CUCUL_WHITE, cur++);
SETPAIR(CUCUL_WHITE, CUCUL_BLUE, cur++);
SETPAIR(CUCUL_LIGHTGRAY, CUCUL_BLUE, cur++);
}

static void emulated_colors(void)
@@ -240,23 +236,23 @@ static void emulated_colors(void)
* dark colour on white: emulate with light colour on white */
for(i = 1; i < 7; i++)
{
if(i != CUCUL_COLOR_BLUE)
if(i != CUCUL_BLUE)
{
SETPAIR(CUCUL_COLOR_LIGHTGRAY, i, 128 +
SETPAIR(CUCUL_LIGHTGRAY, i, 128 +
slang_assoc[i + 8 + 16 * i]);
SETPAIR(CUCUL_COLOR_WHITE, i, 128 +
slang_assoc[CUCUL_COLOR_LIGHTGRAY + 16 * (i + 8)]);
SETPAIR(CUCUL_WHITE, i, 128 +
slang_assoc[CUCUL_LIGHTGRAY + 16 * (i + 8)]);
}
SETPAIR(CUCUL_COLOR_BLACK, i + 8,
128 + slang_assoc[CUCUL_COLOR_DARKGRAY + 16 * i]);
SETPAIR(CUCUL_COLOR_DARKGRAY, i + 8,
SETPAIR(CUCUL_BLACK, i + 8,
128 + slang_assoc[CUCUL_DARKGRAY + 16 * i]);
SETPAIR(CUCUL_DARKGRAY, i + 8,
128 + slang_assoc[i + 16 * (i + 8)]);
SETPAIR(i + 8, CUCUL_COLOR_DARKGRAY,
128 + slang_assoc[i + 16 * CUCUL_COLOR_DARKGRAY]);
SETPAIR(i, CUCUL_COLOR_LIGHTGRAY,
128 + slang_assoc[i + 8 + 16 * CUCUL_COLOR_LIGHTGRAY]);
SETPAIR(i, CUCUL_COLOR_WHITE,
128 + slang_assoc[i + 8 + 16 * CUCUL_COLOR_WHITE]);
SETPAIR(i + 8, CUCUL_DARKGRAY,
128 + slang_assoc[i + 16 * CUCUL_DARKGRAY]);
SETPAIR(i, CUCUL_LIGHTGRAY,
128 + slang_assoc[i + 8 + 16 * CUCUL_LIGHTGRAY]);
SETPAIR(i, CUCUL_WHITE,
128 + slang_assoc[i + 8 + 16 * CUCUL_WHITE]);
}

/* 120 degree hue pairs can be emulated as well; for instance blue on
@@ -290,13 +286,13 @@ static void emulated_colors(void)
for(i = 0; i < 6; i++)
{
SETPAIR(hue_list[i], hue_list[(i + 3) % 6],
128 + slang_assoc[hue_list[i] + 16 * CUCUL_COLOR_BLACK]);
128 + slang_assoc[hue_list[i] + 16 * CUCUL_BLACK]);
SETPAIR(hue_list[i] + 8, hue_list[(i + 3) % 6],
128 + slang_assoc[hue_list[i] + 8 + 16 * CUCUL_COLOR_BLACK]);
128 + slang_assoc[hue_list[i] + 8 + 16 * CUCUL_BLACK]);
SETPAIR(hue_list[(i + 3) % 6], hue_list[i] + 8,
128 + slang_assoc[CUCUL_COLOR_BLACK + 16 * hue_list[i]]);
128 + slang_assoc[CUCUL_BLACK + 16 * hue_list[i]]);
SETPAIR(hue_list[(i + 3) % 6] + 8, hue_list[i] + 8,
128 + slang_assoc[CUCUL_COLOR_WHITE + 16 * (hue_list[i] + 8)]);
128 + slang_assoc[CUCUL_WHITE + 16 * (hue_list[i] + 8)]);
}
}



Loading…
取消
儲存