+ Added caca_set_dithering() (unused yet). + Added random dithering. * src/caca.h: + Renamed legacy EE_* enums to CACA_*. * examples/demo.c examples/caca.txt: + Added a default sprite for libcaca.tags/v0.99.beta14
@@ -4,6 +4,8 @@ | |||
AM_CPPFLAGS = -I$(top_srcdir)/src | |||
EXTRA_DIST = caca.txt | |||
if USE_SLANG | |||
LDFLAGS_slang = -lslang | |||
endif | |||
@@ -0,0 +1,13 @@ | |||
12 6 0 0 | |||
, | |||
` ,_ , | |||
` _( )_ | |||
_( ` )_ | |||
( `-. ' ) | |||
`-.____,-' | |||
h | |||
h gg h | |||
h gggggg | |||
gggggggggg | |||
gggggggggggg | |||
gggggggggg |
@@ -66,13 +66,20 @@ int main(int argc, char **argv) | |||
caca_set_delay(40000); | |||
/* Initialize data */ | |||
sprite = caca_load_sprite("data/barboss.txt"); | |||
sprite = caca_load_sprite("caca.txt"); | |||
if(!sprite) | |||
sprite = caca_load_sprite("examples/caca.txt"); | |||
gdk_init (&argc, &argv); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gally4.jpeg", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/badge1.jpeg", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/union.png", NULL); | |||
pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/pikachu.jpeg", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/pikachu.jpeg", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gradient.png", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/artwork/aboire.png", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/web/sam.zoy.org/artwork/goret.png", NULL); | |||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/lilkim02.jpg", NULL); | |||
pixbuf = gdk_pixbuf_new_from_file("/home/sam/etw.bmp", NULL); | |||
if(!pixbuf) return -2; | |||
pixels = gdk_pixbuf_get_pixels(pixbuf); | |||
bufx = gdk_pixbuf_get_width(pixbuf); | |||
@@ -162,7 +169,7 @@ fprintf(stderr, "w %i, h %i, stride %i\n", bufx, bufy, bufpitch); | |||
{ | |||
demo(); | |||
caca_set_color(EE_WHITE); | |||
caca_set_color(CACA_COLOR_WHITE); | |||
caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2); | |||
caca_printf(4, 1, "[%i.%i fps]----", | |||
1000000 / caca_get_rendertime(), | |||
@@ -184,7 +191,7 @@ static void display_menu(void) | |||
int yo = caca_get_height() - 2; | |||
caca_clear(); | |||
caca_set_color(EE_WHITE); | |||
caca_set_color(CACA_COLOR_WHITE); | |||
caca_draw_thin_box(1, 1, xo, yo); | |||
caca_putstr((xo - strlen("libcaca demo")) / 2, 3, "libcaca demo"); | |||
@@ -221,7 +228,7 @@ static void demo_all(void) | |||
caca_clear(); | |||
/* Draw the sun */ | |||
caca_set_color(EE_YELLOW); | |||
caca_set_color(CACA_COLOR_YELLOW); | |||
xo = caca_get_width() / 4; | |||
yo = caca_get_height() / 4 + 5 * sin(0.03*i); | |||
@@ -233,9 +240,9 @@ static void demo_all(void) | |||
} | |||
j = 15 + sin(0.03*i) * 8; | |||
caca_set_color(EE_WHITE); | |||
caca_set_color(CACA_COLOR_WHITE); | |||
caca_fill_ellipse(xo, yo, j, j / 2, '#'); | |||
caca_set_color(EE_YELLOW); | |||
caca_set_color(CACA_COLOR_YELLOW); | |||
caca_draw_ellipse(xo, yo, j, j / 2, '#'); | |||
/* Draw the pyramid */ | |||
@@ -251,19 +258,19 @@ static void demo_all(void) | |||
xc = caca_get_width() / 4 - sin(0.02*i) * 5; | |||
yc = caca_get_height() * 3 / 4 + cos(0.02*i) * 5; | |||
caca_set_color(EE_GREEN); | |||
caca_set_color(CACA_COLOR_GREEN); | |||
caca_fill_triangle(xo, yo, xb, yb, xa, ya, '%'); | |||
caca_set_color(EE_YELLOW); | |||
caca_set_color(CACA_COLOR_YELLOW); | |||
caca_draw_thin_triangle(xo, yo, xb, yb, xa, ya); | |||
caca_set_color(EE_RED); | |||
caca_set_color(CACA_COLOR_RED); | |||
caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#'); | |||
caca_set_color(EE_YELLOW); | |||
caca_set_color(CACA_COLOR_YELLOW); | |||
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); | |||
caca_set_color(EE_BLUE); | |||
caca_set_color(CACA_COLOR_BLUE); | |||
caca_fill_triangle(xo, yo, xb, yb, xc, yc, '%'); | |||
caca_set_color(EE_YELLOW); | |||
caca_set_color(CACA_COLOR_YELLOW); | |||
caca_draw_thin_triangle(xo, yo, xb, yb, xc, yc); | |||
/* Draw a background triangle */ | |||
@@ -276,7 +283,7 @@ static void demo_all(void) | |||
xc = caca_get_width() / 3; | |||
yc = caca_get_height() - 3; | |||
caca_set_color(EE_CYAN); | |||
caca_set_color(CACA_COLOR_CYAN); | |||
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); | |||
xo = caca_get_width() / 2 + cos(0.027*i) * caca_get_width() / 3; | |||
@@ -330,7 +337,7 @@ static void demo_color(void) | |||
for(i = 0; i < 16; i++) | |||
{ | |||
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, caca_get_color_name(i)); | |||
caca_set_color(EE_WHITE); | |||
caca_set_color(CACA_COLOR_WHITE); | |||
caca_putstr(4, i + 3, buf); | |||
caca_set_color(i); | |||
caca_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------"); | |||
@@ -457,7 +464,6 @@ static void demo_sprites(void) | |||
static void demo_blit(void) | |||
{ | |||
caca_set_color(EE_LIGHTGRAY); | |||
caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4, pixels, bufx, bufy); | |||
} | |||
@@ -76,7 +76,7 @@ int main(int argc, char **argv) | |||
caca_clear(); | |||
caca_set_color(EE_WHITE); | |||
caca_set_color(CACA_COLOR_WHITE); | |||
caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1); | |||
caca_putstr(3, 0, "[ Sprite editor for libcaca ]"); | |||
@@ -96,9 +96,9 @@ int main(int argc, char **argv) | |||
ya = -1 - caca_get_sprite_dy(sprite, frame); | |||
xb = xa + 1 + caca_get_sprite_width(sprite, frame); | |||
yb = ya + 1 + caca_get_sprite_height(sprite, frame); | |||
caca_set_color(EE_BLACK); | |||
caca_set_color(CACA_COLOR_BLACK); | |||
caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' '); | |||
caca_set_color(EE_WHITE); | |||
caca_set_color(CACA_COLOR_WHITE); | |||
caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb); | |||
caca_draw_sprite(57, 10, sprite, frame); | |||
@@ -34,10 +34,19 @@ typedef unsigned char uint8_t; | |||
#include "caca.h" | |||
#include "caca_internals.h" | |||
#include <stdio.h> | |||
static enum caca_dithering _caca_dithering = CACA_DITHER_NONE; | |||
void caca_set_dithering(enum caca_dithering dither) | |||
{ | |||
if(dither < 0 || dither > 1) | |||
return; | |||
_caca_dithering = dither; | |||
} | |||
void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) | |||
{ | |||
char foo[] = { ' ', '.', ':', ';', '=', '$', '%', '@', '#', '8', 'W' }; | |||
char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' }; | |||
int x, y, pitch; | |||
if(x1 > x2) | |||
@@ -55,49 +64,45 @@ void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) | |||
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++) | |||
for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= (int)caca_get_width(); x++) | |||
{ | |||
static int light_colors[] = {CACA_COLOR_LIGHTMAGENTA, CACA_COLOR_LIGHTRED, CACA_COLOR_YELLOW, CACA_COLOR_LIGHTGREEN, CACA_COLOR_LIGHTCYAN, CACA_COLOR_LIGHTBLUE, CACA_COLOR_LIGHTMAGENTA}; | |||
static int dark_colors[] = {CACA_COLOR_MAGENTA, CACA_COLOR_RED, CACA_COLOR_BROWN, CACA_COLOR_GREEN, CACA_COLOR_CYAN, CACA_COLOR_BLUE, CACA_COLOR_MAGENTA}; | |||
int fromx = w * (x - x1) / (x2 - x1 + 1); | |||
int fromy = h * (y - y1) / (y2 - y1 + 1); | |||
int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy]; | |||
int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy]; | |||
int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy]; | |||
int hue, sat, val; | |||
int min = r, max = r, delta; | |||
if(min > g) min = g; if(max < g) max = g; | |||
if(min > b) min = b; if(max < b) max = b; | |||
if(r == g && g == b) | |||
delta = max - min; | |||
val = max; /* 0 - 255 */ | |||
sat = max ? 256 * delta / max : 0; /* 0 - 255 */ | |||
if(sat > caca_rand(64, 128)) | |||
{ | |||
caca_set_color(EE_LIGHTGRAY); | |||
/* XXX: Values are automatically clipped between 0 and 6 | |||
* because of delta/2 */ | |||
if( r == max ) | |||
hue = 1 + (float)(g - b + delta / 2 + caca_rand(-40, 40)) / delta; | |||
else if( g == max ) | |||
hue = 3 + (float)(b - r + delta / 2 + caca_rand(-40, 40)) / delta; | |||
else | |||
hue = 5 + (float)(r - g + delta / 2 + caca_rand(-40, 40)) / delta; | |||
if(val > caca_rand(128, 192)) | |||
caca_set_color(light_colors[hue]); | |||
else | |||
caca_set_color(dark_colors[hue]); | |||
} | |||
else | |||
{ | |||
static int foo_colors[6] = {EE_LIGHTRED, EE_YELLOW, EE_LIGHTGREEN, EE_LIGHTCYAN, EE_LIGHTBLUE, EE_LIGHTMAGENTA}; | |||
float min = r, max = r, delta, hue, sat; | |||
if(min > g) min = g; if(max < g) max = g; | |||
if(min > b) min = b; if(max < b) max = b; | |||
delta = max - min; | |||
sat = max / delta; | |||
if(delta > 20) | |||
{ | |||
if( r == max ) | |||
hue = (g - b) / delta; // between yellow & magenta | |||
else if( g == max ) | |||
hue = 2 + (b - r) / delta; // between cyan & yellow | |||
else | |||
hue = 4 + (r - g) / delta; // between magenta & cyan | |||
hue *= 60; // degrees | |||
if( hue < 0 ) | |||
hue += 360; | |||
caca_set_color(foo_colors[(int)(hue + 30) / 60]); | |||
} | |||
else | |||
{ | |||
caca_set_color(EE_LIGHTGRAY); | |||
} | |||
caca_set_color(CACA_COLOR_LIGHTGRAY); | |||
} | |||
caca_putchar(x, y, foo[(r + g + b) / 3 / 25]); | |||
caca_putchar(x, y, foo[(r + g + b + caca_rand(-10, 10)) / 3 / 25]); | |||
} | |||
} | |||
@@ -125,22 +125,22 @@ int caca_init(void) | |||
start_color(); | |||
init_pair(1 + EE_BLACK, COLOR_BLACK, COLOR_BLACK); | |||
init_pair(1 + EE_BLUE, COLOR_BLUE, COLOR_BLACK); | |||
init_pair(1 + EE_GREEN, COLOR_GREEN, COLOR_BLACK); | |||
init_pair(1 + EE_CYAN, COLOR_CYAN, COLOR_BLACK); | |||
init_pair(1 + EE_RED, COLOR_RED, COLOR_BLACK); | |||
init_pair(1 + EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); | |||
init_pair(1 + EE_BROWN, COLOR_YELLOW, COLOR_BLACK); | |||
init_pair(1 + EE_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK); | |||
init_pair(1 + EE_DARKGRAY, COLOR_BLACK, COLOR_BLACK); | |||
init_pair(1 + EE_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK); | |||
init_pair(1 + EE_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK); | |||
init_pair(1 + EE_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK); | |||
init_pair(1 + EE_LIGHTRED, COLOR_RED, COLOR_BLACK); | |||
init_pair(1 + EE_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK); | |||
init_pair(1 + EE_YELLOW, COLOR_YELLOW, COLOR_BLACK); | |||
init_pair(1 + EE_WHITE, COLOR_WHITE, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_RED, COLOR_RED, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_BROWN, COLOR_YELLOW, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_DARKGRAY, COLOR_BLACK, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_LIGHTRED, COLOR_RED, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); | |||
init_pair(1 + CACA_COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); | |||
for(i = 0; i < 8; i++) | |||
{ | |||
@@ -21,8 +21,8 @@ | |||
* 02111-1307 USA | |||
*/ | |||
#ifndef __EE_H__ | |||
#define __EE_H__ | |||
#ifndef __CACA_H__ | |||
#define __CACA_H__ | |||
#ifdef __cplusplus | |||
extern "C" | |||
@@ -32,24 +32,33 @@ extern "C" | |||
/* | |||
* Colors | |||
*/ | |||
enum caca_colors | |||
enum caca_color | |||
{ | |||
EE_BLACK = 0, | |||
EE_BLUE = 1, | |||
EE_GREEN = 2, | |||
EE_CYAN = 3, | |||
EE_RED = 4, | |||
EE_MAGENTA = 5, | |||
EE_BROWN = 6, | |||
EE_LIGHTGRAY = 7, | |||
EE_DARKGRAY = 8, | |||
EE_LIGHTBLUE = 9, | |||
EE_LIGHTGREEN = 10, | |||
EE_LIGHTCYAN = 11, | |||
EE_LIGHTRED = 12, | |||
EE_LIGHTMAGENTA = 13, | |||
EE_YELLOW = 14, | |||
EE_WHITE = 15 | |||
CACA_COLOR_BLACK = 0, | |||
CACA_COLOR_BLUE = 1, | |||
CACA_COLOR_GREEN = 2, | |||
CACA_COLOR_CYAN = 3, | |||
CACA_COLOR_RED = 4, | |||
CACA_COLOR_MAGENTA = 5, | |||
CACA_COLOR_BROWN = 6, | |||
CACA_COLOR_LIGHTGRAY = 7, | |||
CACA_COLOR_DARKGRAY = 8, | |||
CACA_COLOR_LIGHTBLUE = 9, | |||
CACA_COLOR_LIGHTGREEN = 10, | |||
CACA_COLOR_LIGHTCYAN = 11, | |||
CACA_COLOR_LIGHTRED = 12, | |||
CACA_COLOR_LIGHTMAGENTA = 13, | |||
CACA_COLOR_YELLOW = 14, | |||
CACA_COLOR_WHITE = 15 | |||
}; | |||
/* | |||
* Dithering modes | |||
*/ | |||
enum caca_dithering | |||
{ | |||
CACA_DITHER_NONE = 0, | |||
CACA_DITHER_RANDOM = 1 | |||
}; | |||
/* | |||
@@ -62,6 +71,7 @@ struct caca_sprite; | |||
*/ | |||
int caca_init(void); | |||
void caca_set_delay(unsigned int); | |||
void caca_set_dithering(enum caca_dithering); | |||
unsigned int caca_get_rendertime(void); | |||
unsigned int caca_get_width(void); | |||
unsigned int caca_get_height(void); | |||
@@ -71,8 +81,8 @@ void caca_end(void); | |||
char caca_get_key(void); | |||
void caca_set_color(int); | |||
int caca_get_color(void); | |||
void caca_set_color(enum caca_color); | |||
enum caca_color caca_get_color(void); | |||
void caca_putchar(int, int, char); | |||
void caca_putstr(int, int, const char *); | |||
void caca_printf(int, int, const char *, ...); | |||
@@ -114,4 +124,4 @@ void caca_blit(int, int, int, int, void *, int, int); | |||
} | |||
#endif | |||
#endif /* __EE_H__ */ | |||
#endif /* __CACA_H__ */ |
@@ -21,8 +21,8 @@ | |||
* 02111-1307 USA | |||
*/ | |||
#ifndef __EE_INTERNALS_H__ | |||
#define __EE_INTERNALS_H__ | |||
#ifndef __CACA_INTERNALS_H__ | |||
#define __CACA_INTERNALS_H__ | |||
#if defined(USE_NCURSES) | |||
extern int _caca_attr[]; | |||
@@ -35,4 +35,4 @@ extern char *_caca_screen; | |||
extern char *_caca_empty_line; | |||
extern char *_caca_scratch_line; | |||
#endif /* __EE_INTERNALS_H__ */ | |||
#endif /* __CACA_INTERNALS_H__ */ |
@@ -40,9 +40,9 @@ | |||
#include "caca.h" | |||
#include "caca_internals.h" | |||
static int _caca_color = 0; | |||
static enum caca_color _caca_color = CACA_COLOR_WHITE; | |||
void caca_set_color(int color) | |||
void caca_set_color(enum caca_color color) | |||
{ | |||
if(color < 0 || color > 15) | |||
return; | |||
@@ -57,7 +57,7 @@ void caca_set_color(int color) | |||
#endif | |||
} | |||
int caca_get_color(void) | |||
enum caca_color caca_get_color(void) | |||
{ | |||
return _caca_color; | |||
} | |||