+ Internally cache screen width and height. * src/bitmap.c: + Added alpha support to caca_draw_bitmap(). For now, we only treat 0% alpha as fully transparent, and any other value as fully opaque. + Slightly tuned colour weights in the renderer. + caca_set_bitmap_palette() takes unsigned ints. * examples/demo.c: + Added a crap render demo. * examples/aafire.c: + Set a 20ms delay. + Added alpha values to the palette. * examples/view.c: + Draw a gray checkered grid below the image so that transparent images look a lot nicer. + 'f' toggles "fullscreen" mode.tags/v0.99.beta14
@@ -95,7 +95,7 @@ initialize (void) | |||||
{ | { | ||||
int i; | int i; | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
int r[256], g[256], b[256]; | |||||
int r[256], g[256], b[256], a[256]; | |||||
#endif | #endif | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
@@ -104,6 +104,7 @@ initialize (void) | |||||
printf ("Failed to initialize libcaca\n"); | printf ("Failed to initialize libcaca\n"); | ||||
exit (1); | exit (1); | ||||
} | } | ||||
caca_set_delay(20000); | |||||
#else | #else | ||||
context = aa_autoinit (&aa_defparams); | context = aa_autoinit (&aa_defparams); | ||||
if (context == NULL) | if (context == NULL) | ||||
@@ -121,6 +122,7 @@ initialize (void) | |||||
r[i] = pal[i * 3] * 64; | r[i] = pal[i * 3] * 64; | ||||
g[i] = pal[i * 3 + 1] * 64; | g[i] = pal[i * 3 + 1] * 64; | ||||
b[i] = pal[i * 3 + 2] * 64; | b[i] = pal[i * 3 + 2] * 64; | ||||
a[i] = 0xfff; | |||||
} | } | ||||
#else | #else | ||||
aa_setpalette (palette, i, pal[i * 3] * 4, | aa_setpalette (palette, i, pal[i * 3] * 4, | ||||
@@ -128,14 +130,13 @@ initialize (void) | |||||
#endif | #endif | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
caca_bitmap = caca_create_bitmap(8, XSIZ, YSIZ - 4, XSIZ, 0, 0, 0); | |||||
caca_set_bitmap_palette(caca_bitmap, r, g, b); | |||||
caca_bitmap = caca_create_bitmap(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0); | |||||
caca_set_bitmap_palette(caca_bitmap, r, g, b, a); | |||||
bitmap = malloc(XSIZ * YSIZ * sizeof(char)); | bitmap = malloc(XSIZ * YSIZ * sizeof(char)); | ||||
caca_set_dithering(CACA_DITHERING_ORDERED8); | caca_set_dithering(CACA_DITHERING_ORDERED8); | ||||
#else | #else | ||||
aa_hidecursor (context); | aa_hidecursor (context); | ||||
#endif | #endif | ||||
fprintf(stderr, "%i %i\n", XSIZ, YSIZ); | |||||
} | } | ||||
static void | static void | ||||
uninitialize (void) | uninitialize (void) | ||||
@@ -40,6 +40,7 @@ static void demo_boxes(void); | |||||
static void demo_ellipses(void); | static void demo_ellipses(void); | ||||
static void demo_triangles(void); | static void demo_triangles(void); | ||||
static void demo_sprites(void); | static void demo_sprites(void); | ||||
static void demo_render(void); | |||||
int bounds = 0; | int bounds = 0; | ||||
int outline = 0; | int outline = 0; | ||||
@@ -130,6 +131,9 @@ int main(int argc, char **argv) | |||||
case 'S': | case 'S': | ||||
if(sprite) | if(sprite) | ||||
demo = demo_sprites; | demo = demo_sprites; | ||||
case 'r': | |||||
case 'R': | |||||
demo = demo_render; | |||||
break; | break; | ||||
} | } | ||||
@@ -193,8 +197,9 @@ static void display_menu(void) | |||||
caca_putstr(4, 11, "'4': triangles"); | caca_putstr(4, 11, "'4': triangles"); | ||||
caca_putstr(4, 12, "'5': ellipses"); | caca_putstr(4, 12, "'5': ellipses"); | ||||
caca_putstr(4, 13, "'c': colour"); | caca_putstr(4, 13, "'c': colour"); | ||||
caca_putstr(4, 14, "'r': render"); | |||||
if(sprite) | if(sprite) | ||||
caca_putstr(4, 14, "'s': sprites"); | |||||
caca_putstr(4, 15, "'s': sprites"); | |||||
caca_putstr(4, 16, "settings:"); | caca_putstr(4, 16, "settings:"); | ||||
caca_printf(4, 17, "'o': outline: %s", | caca_printf(4, 17, "'o': outline: %s", | ||||
@@ -460,3 +465,103 @@ static void demo_sprites(void) | |||||
caca_rand(0, caca_get_height() - 1), sprite, 0); | caca_rand(0, caca_get_height() - 1), sprite, 0); | ||||
} | } | ||||
#if 0 | |||||
static void demo_render(void) | |||||
{ | |||||
struct caca_bitmap *bitmap; | |||||
//short buffer[256*256]; | |||||
//short *dest = buffer; | |||||
int buffer[256*256]; | |||||
int *dest = buffer; | |||||
int x, y, z; | |||||
static int i = 0; | |||||
i = (i + 1) % 512; | |||||
z = i < 256 ? i : 511 - i; | |||||
for(x = 0; x < 256; x++) | |||||
for(y = 0; y < 256; y++) | |||||
{ | |||||
//*dest++ = ((x >> 3) << 11) | ((y >> 2) << 5) | ((z >> 3)); | |||||
*dest++ = (x << 16) | (y << 8) | (z); | |||||
} | |||||
//bitmap = caca_create_bitmap(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000); | |||||
bitmap = caca_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); | |||||
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | |||||
bitmap, buffer); | |||||
caca_free_bitmap(bitmap); | |||||
} | |||||
#endif | |||||
static void draw_circle(int *buffer, int xo, int yo, int r, int mask, int val); | |||||
static void demo_render(void) | |||||
{ | |||||
struct caca_bitmap *bitmap; | |||||
int buffer[256*256]; | |||||
int *dest; | |||||
int x, y, z, t, xo, yo; | |||||
static int i = 0; | |||||
i++; | |||||
dest = buffer; | |||||
for(x = 0; x < 256; x++) | |||||
for(y = 0; y < 256; y++) | |||||
{ | |||||
*dest++ = 0; | |||||
} | |||||
/* red */ | |||||
xo = 128 + 48 * sin(0.02 * i); | |||||
yo = 128 + 48 * cos(0.03 * i); | |||||
t = 256 * (2.0 + sin(4 + 0.017 * i)) / 3; | |||||
for(z = 0; z < 240; z++) | |||||
draw_circle(buffer, xo, yo, z, 0x00ff0000, | |||||
((255 - z) * t / 256) << 16); | |||||
/* green */ | |||||
xo = 128 + 48 * sin(2 + 0.06 * i); | |||||
yo = 128 + 48 * cos(2 + 0.05 * i); | |||||
t = 256 * (2.0 + sin(8 + 0.021 * i)) / 3; | |||||
for(z = 0; z < 240; z++) | |||||
draw_circle(buffer, xo, yo, z, 0x0000ff00, | |||||
((255 - z) * t / 256) << 8); | |||||
/* blue */ | |||||
xo = 128 + 48 * sin(1 + 0.04 * i); | |||||
yo = 128 + 48 * cos(1 + 0.03 * i); | |||||
t = 256 * (2.0 + sin(3 + 0.033 * i)) / 3; | |||||
for(z = 0; z < 240; z++) | |||||
draw_circle(buffer, xo, yo, z, 0x000000ff, (255 - z) * t / 256); | |||||
bitmap = caca_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); | |||||
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | |||||
bitmap, (char *)buffer); | |||||
caca_free_bitmap(bitmap); | |||||
} | |||||
static void draw_circle(int *buffer, int x, int y, int r, int mask, int val) | |||||
{ | |||||
int t, dx, dy; | |||||
#define POINT(X,Y) \ | |||||
buffer[(X) + 256 * (Y)] = (buffer[(X) + 256 * (Y)] & ~mask) | val; | |||||
for(t = 0, dx = 0, dy = r; dx <= dy; dx++) | |||||
{ | |||||
POINT(x - dx / 3, y - dy / 3); | |||||
POINT(x + dx / 3, y - dy / 3); | |||||
POINT(x - dx / 3, y + dy / 3); | |||||
POINT(x + dx / 3, y + dy / 3); | |||||
POINT(x - dy / 3, y - dx / 3); | |||||
POINT(x + dy / 3, y - dx / 3); | |||||
POINT(x - dy / 3, y + dx / 3); | |||||
POINT(x + dy / 3, y + dx / 3); | |||||
t += t > 0 ? dx - dy-- : dx; | |||||
} | |||||
} | |||||
@@ -32,23 +32,25 @@ | |||||
#include "caca.h" | #include "caca.h" | ||||
/* Local functions */ | |||||
static void load_image(const char *); | |||||
static void draw_checkers(unsigned int, unsigned int, | |||||
unsigned int, unsigned int); | |||||
/* Local variables */ | |||||
Imlib_Image image = NULL; | Imlib_Image image = NULL; | ||||
char *pixels = NULL; | char *pixels = NULL; | ||||
struct caca_bitmap *bitmap = NULL; | struct caca_bitmap *bitmap = NULL; | ||||
int x, y, w, h; | int x, y, w, h; | ||||
const unsigned int rmask = 0x00ff0000, gmask = 0x0000ff00, bmask = 0x000000ff; | |||||
int dithering = CACA_DITHERING_ORDERED4; | |||||
static void load_image(const char *); | |||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
{ | { | ||||
int quit = 0, update = 1, help = 0, reload = 0; | |||||
int i, zoom = 0; | |||||
int quit = 0, update = 1, help = 0, reload = 0, fullscreen = 0, zoom = 0; | |||||
int dithering = CACA_DITHERING_ORDERED4; | |||||
char **list = NULL; | char **list = NULL; | ||||
int current = 0, items = 0, opts = 1; | int current = 0, items = 0, opts = 1; | ||||
int i; | |||||
/* Initialise libcaca */ | /* Initialise libcaca */ | ||||
if(caca_init()) | if(caca_init()) | ||||
@@ -101,6 +103,11 @@ int main(int argc, char **argv) | |||||
if(items) current = (items + current - 1) % items; | if(items) current = (items + current - 1) % items; | ||||
reload = 1; | reload = 1; | ||||
break; | break; | ||||
case CACA_EVENT_KEY_PRESS | 'f': | |||||
case CACA_EVENT_KEY_PRESS | 'F': | |||||
fullscreen = ~fullscreen; | |||||
update = 1; | |||||
break; | |||||
case CACA_EVENT_KEY_PRESS | 'd': | case CACA_EVENT_KEY_PRESS | 'd': | ||||
dithering = (dithering + 1) % 5; | dithering = (dithering + 1) % 5; | ||||
update = 1; | update = 1; | ||||
@@ -203,6 +210,7 @@ int main(int argc, char **argv) | |||||
int yo = (wh - 1) / 2; | int yo = (wh - 1) / 2; | ||||
int xn = (ww - 1) / (2 - zoom); | int xn = (ww - 1) / (2 - zoom); | ||||
int yn = (wh - 1) / (2 - zoom); | int yn = (wh - 1) / (2 - zoom); | ||||
draw_checkers(xo - xn, yo - yn, xo + xn, yo + yn); | |||||
caca_draw_bitmap(xo - xn, yo - yn, xo + xn, yo + yn, | caca_draw_bitmap(xo - xn, yo - yn, xo + xn, yo + yn, | ||||
bitmap, pixels); | bitmap, pixels); | ||||
} | } | ||||
@@ -216,27 +224,40 @@ int main(int argc, char **argv) | |||||
if(xn + x > w) x = w - xn; | if(xn + x > w) x = w - xn; | ||||
if(yn + y > h) y = h - yn; | if(yn + y > h) y = h - yn; | ||||
newbitmap = caca_create_bitmap(32, 2 * xn, 2 * yn, 4 * w, | newbitmap = caca_create_bitmap(32, 2 * xn, 2 * yn, 4 * w, | ||||
rmask, gmask, bmask); | |||||
caca_draw_bitmap(0, 0, ww - 1, wh - 1, newbitmap, | |||||
0x00ff0000, 0x0000ff00, 0x000000ff, | |||||
0xff000000); | |||||
draw_checkers(0, fullscreen ? 0 : 1, | |||||
ww - 1, fullscreen ? wh - 1 : wh - 2); | |||||
caca_draw_bitmap(0, fullscreen ? 0 : 1, | |||||
ww - 1, fullscreen ? wh - 1 : wh - 2, | |||||
newbitmap, | |||||
pixels + 4 * (x - xn) + 4 * w * (y - yn)); | pixels + 4 * (x - xn) + 4 * w * (y - yn)); | ||||
caca_free_bitmap(newbitmap); | caca_free_bitmap(newbitmap); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
caca_draw_bitmap(0, 0, ww - 1, wh - 1, bitmap, pixels); | |||||
draw_checkers(0, fullscreen ? 0 : 1, | |||||
ww - 1, fullscreen ? wh - 1 : wh - 2); | |||||
caca_draw_bitmap(0, fullscreen ? 0 : 1, | |||||
ww - 1, fullscreen ? wh - 1 : wh - 2, | |||||
bitmap, pixels); | |||||
} | } | ||||
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); | caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); | ||||
caca_draw_line(0, 0, ww - 1, 0, ' '); | |||||
caca_draw_line(0, wh - 1, ww - 1, wh - 1, '-'); | |||||
caca_putstr(0, 0, "q:Quit n/p:Next/Prev +/-/x:Zoom " | |||||
"h/j/k/l: Move d:Dithering"); | |||||
caca_putstr(ww - strlen("?:Help"), 0, "?:Help"); | |||||
caca_printf(3, wh - 1, "cacaview %s", VERSION); | |||||
caca_printf(ww / 2 - 5, wh - 1, "(%s dithering)", | |||||
caca_get_dithering_name(dithering)); | |||||
caca_printf(ww - 14, wh - 1, | |||||
"(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); | |||||
if(!fullscreen) | |||||
{ | |||||
caca_draw_line(0, 0, ww - 1, 0, ' '); | |||||
caca_draw_line(0, wh - 1, ww - 1, wh - 1, '-'); | |||||
caca_putstr(0, 0, "q:Quit n/p:Next/Prev +/-/x:Zoom " | |||||
"h/j/k/l: Move d:Dithering"); | |||||
caca_putstr(ww - strlen("?:Help"), 0, "?:Help"); | |||||
caca_printf(3, wh - 1, "cacaview %s", VERSION); | |||||
caca_printf(ww / 2 - 5, wh - 1, "(%s dithering)", | |||||
caca_get_dithering_name(dithering)); | |||||
caca_printf(ww - 14, wh - 1, | |||||
"(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); | |||||
} | |||||
if(help) | if(help) | ||||
{ | { | ||||
@@ -298,7 +319,8 @@ static void load_image(const char *name) | |||||
y = h / 2; | y = h / 2; | ||||
/* Create the libcaca bitmap */ | /* Create the libcaca bitmap */ | ||||
bitmap = caca_create_bitmap(32, w, h, 4 * w, rmask, gmask, bmask); | |||||
bitmap = caca_create_bitmap(32, w, h, 4 * w, 0x00ff0000, 0x0000ff00, | |||||
0x000000ff, 0xff000000); | |||||
if(!bitmap) | if(!bitmap) | ||||
{ | { | ||||
imlib_free_image(); | imlib_free_image(); | ||||
@@ -306,3 +328,19 @@ static void load_image(const char *name) | |||||
} | } | ||||
} | } | ||||
static void draw_checkers(unsigned int x1, unsigned int y1, | |||||
unsigned int x2, unsigned int y2) | |||||
{ | |||||
unsigned int xn, yn; | |||||
for(yn = y1; yn <= y2; yn++) | |||||
for(xn = x1; xn <= x2; xn++) | |||||
{ | |||||
if(((xn / 4) ^ (yn / 2)) & 1) | |||||
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_DARKGRAY); | |||||
else | |||||
caca_set_color(CACA_COLOR_DARKGRAY, CACA_COLOR_LIGHTGRAY); | |||||
caca_putchar(xn, yn, ' '); | |||||
} | |||||
} | |||||
@@ -50,8 +50,9 @@ typedef unsigned int uint32_t; | |||||
static void mask2shift(unsigned int, int *, int *); | static void mask2shift(unsigned int, int *, int *); | ||||
static void get_rgb_default(struct caca_bitmap *, uint8_t *, int, int, | |||||
unsigned int *, unsigned int *, unsigned int *); | |||||
static void get_rgba_default(const struct caca_bitmap *, uint8_t *, int, int, | |||||
unsigned int *, unsigned int *, unsigned int *, | |||||
unsigned int *); | |||||
static void rgb2hsv_default(int, int, int, int *, int *, int *); | static void rgb2hsv_default(int, int, int, int *, int *, int *); | ||||
/* Dithering methods */ | /* Dithering methods */ | ||||
@@ -127,11 +128,11 @@ struct caca_bitmap | |||||
{ | { | ||||
int bpp, palette; | int bpp, palette; | ||||
int w, h, pitch; | int w, h, pitch; | ||||
int rmask, gmask, bmask; | |||||
int rright, gright, bright; | |||||
int rleft, gleft, bleft; | |||||
int rmask, gmask, bmask, amask; | |||||
int rright, gright, bright, aright; | |||||
int rleft, gleft, bleft, aleft; | |||||
void (*get_hsv)(struct caca_bitmap *, char *, int, int); | void (*get_hsv)(struct caca_bitmap *, char *, int, int); | ||||
int red[256], green[256], blue[256]; | |||||
int red[256], green[256], blue[256], alpha[256]; | |||||
}; | }; | ||||
static void mask2shift(unsigned int mask, int *right, int *left) | static void mask2shift(unsigned int mask, int *right, int *left) | ||||
@@ -160,7 +161,8 @@ static void mask2shift(unsigned int mask, int *right, int *left) | |||||
} | } | ||||
struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, | struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, | ||||
int rmask, int gmask, int bmask) | |||||
int rmask, int gmask, int bmask, | |||||
int amask) | |||||
{ | { | ||||
struct caca_bitmap *bitmap; | struct caca_bitmap *bitmap; | ||||
@@ -182,13 +184,15 @@ struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, | |||||
bitmap->rmask = rmask; | bitmap->rmask = rmask; | ||||
bitmap->gmask = gmask; | bitmap->gmask = gmask; | ||||
bitmap->bmask = bmask; | bitmap->bmask = bmask; | ||||
bitmap->amask = amask; | |||||
/* Load bitmasks */ | /* Load bitmasks */ | ||||
if(rmask || gmask || bmask) | |||||
if(rmask || gmask || bmask || amask) | |||||
{ | { | ||||
mask2shift(rmask, &bitmap->rright, &bitmap->rleft); | mask2shift(rmask, &bitmap->rright, &bitmap->rleft); | ||||
mask2shift(gmask, &bitmap->gright, &bitmap->gleft); | mask2shift(gmask, &bitmap->gright, &bitmap->gleft); | ||||
mask2shift(bmask, &bitmap->bright, &bitmap->bleft); | mask2shift(bmask, &bitmap->bright, &bitmap->bleft); | ||||
mask2shift(amask, &bitmap->aright, &bitmap->aleft); | |||||
} | } | ||||
/* In 8 bpp mode, default to a grayscale palette */ | /* In 8 bpp mode, default to a grayscale palette */ | ||||
@@ -198,9 +202,10 @@ struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, | |||||
bitmap->palette = 1; | bitmap->palette = 1; | ||||
for(i = 0; i < 256; i++) | for(i = 0; i < 256; i++) | ||||
{ | { | ||||
bitmap->red[i] = i * 0x10; | |||||
bitmap->green[i] = i * 0x10; | |||||
bitmap->blue[i] = i * 0x10; | |||||
bitmap->red[i] = i * 0xfff / 256; | |||||
bitmap->green[i] = i * 0xfff / 256; | |||||
bitmap->blue[i] = i * 0xfff / 256; | |||||
bitmap->alpha[i] = 0xfff; | |||||
} | } | ||||
} | } | ||||
@@ -208,7 +213,8 @@ struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, | |||||
} | } | ||||
void caca_set_bitmap_palette(struct caca_bitmap *bitmap, | void caca_set_bitmap_palette(struct caca_bitmap *bitmap, | ||||
int red[], int green[], int blue[]) | |||||
unsigned int red[], unsigned int green[], | |||||
unsigned int blue[], unsigned int alpha[]) | |||||
{ | { | ||||
int i; | int i; | ||||
@@ -219,11 +225,13 @@ void caca_set_bitmap_palette(struct caca_bitmap *bitmap, | |||||
{ | { | ||||
if(red[i] >= 0 && red[i] < 0x1000 && | if(red[i] >= 0 && red[i] < 0x1000 && | ||||
green[i] >= 0 && green[i] < 0x1000 && | green[i] >= 0 && green[i] < 0x1000 && | ||||
blue[i] >= 0 && blue[i] < 0x1000) | |||||
blue[i] >= 0 && blue[i] < 0x1000 && | |||||
alpha[i] >= 0 && alpha[i] < 0x1000) | |||||
{ | { | ||||
bitmap->red[i] = red[i]; | bitmap->red[i] = red[i]; | ||||
bitmap->green[i] = green[i]; | bitmap->green[i] = green[i]; | ||||
bitmap->blue[i] = blue[i]; | bitmap->blue[i] = blue[i]; | ||||
bitmap->alpha[i] = alpha[i]; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -236,9 +244,9 @@ void caca_free_bitmap(struct caca_bitmap *bitmap) | |||||
free(bitmap); | free(bitmap); | ||||
} | } | ||||
static void get_rgb_default(struct caca_bitmap *bitmap, uint8_t *pixels, | |||||
int x, int y, unsigned int *r, | |||||
unsigned int *g, unsigned int *b) | |||||
static void get_rgba_default(const struct caca_bitmap *bitmap, uint8_t *pixels, | |||||
int x, int y, unsigned int *r, unsigned int *g, | |||||
unsigned int *b, unsigned int *a) | |||||
{ | { | ||||
uint32_t bits; | uint32_t bits; | ||||
@@ -254,8 +262,9 @@ static void get_rgb_default(struct caca_bitmap *bitmap, uint8_t *pixels, | |||||
#ifdef HAVE_ENDIAN_H | #ifdef HAVE_ENDIAN_H | ||||
if(__BYTE_ORDER == __BIG_ENDIAN) | if(__BYTE_ORDER == __BIG_ENDIAN) | ||||
#else | #else | ||||
static const uint32_t rmask = 0x12345678; | |||||
if(*(uint8_t *)&rmask == 0x12) | |||||
/* This is compile-time optimised with at least -O1 or -Os */ | |||||
const uint32_t rmask = 0x12345678; | |||||
if(*(const uint8_t *)&rmask == 0x12) | |||||
#endif | #endif | ||||
bits = ((uint32_t)pixels[0] << 16) | | bits = ((uint32_t)pixels[0] << 16) | | ||||
((uint32_t)pixels[1] << 8) | | ((uint32_t)pixels[1] << 8) | | ||||
@@ -280,12 +289,14 @@ static void get_rgb_default(struct caca_bitmap *bitmap, uint8_t *pixels, | |||||
*r = bitmap->red[bits]; | *r = bitmap->red[bits]; | ||||
*g = bitmap->green[bits]; | *g = bitmap->green[bits]; | ||||
*b = bitmap->blue[bits]; | *b = bitmap->blue[bits]; | ||||
*a = bitmap->alpha[bits]; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
*r = ((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft; | *r = ((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft; | ||||
*g = ((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft; | *g = ((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft; | ||||
*b = ((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft; | *b = ((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft; | ||||
*a = ((bits & bitmap->amask) >> bitmap->aright) << bitmap->aleft; | |||||
} | } | ||||
} | } | ||||
@@ -320,7 +331,7 @@ static void rgb2hsv_default(int r, int g, int b, int *hue, int *sat, int *val) | |||||
} | } | ||||
void caca_draw_bitmap(int x1, int y1, int x2, int y2, | void caca_draw_bitmap(int x1, int y1, int x2, int y2, | ||||
struct caca_bitmap *bitmap, char *pixels) | |||||
const struct caca_bitmap *bitmap, char *pixels) | |||||
{ | { | ||||
#if !NEW_RENDERER | #if !NEW_RENDERER | ||||
static const int white_colors[] = | static const int white_colors[] = | ||||
@@ -358,18 +369,18 @@ void caca_draw_bitmap(int x1, int y1, int x2, int y2, | |||||
# define DENSITY_CHARS 13 | # define DENSITY_CHARS 13 | ||||
static const char density_chars[] = | static const char density_chars[] = | ||||
" " | " " | ||||
" " | |||||
".` " | |||||
",`.'" | |||||
"i:-^" | |||||
"|=+;" | |||||
"ox/\\" | |||||
"<>x%" | |||||
"&$zw" | |||||
"WXKM" | |||||
"#8##" | |||||
"8@8#" | |||||
"@8@8" | |||||
". " | |||||
".. " | |||||
"...." | |||||
"::::" | |||||
";=;=" | |||||
"tftf" | |||||
"%$%$" | |||||
"&KSZ" | |||||
"WXGM" | |||||
"@@@@" | |||||
"8888" | |||||
"####" | |||||
"????"; | "????"; | ||||
int x, y, w, h, pitch; | int x, y, w, h, pitch; | ||||
@@ -391,13 +402,13 @@ void caca_draw_bitmap(int x1, int y1, int x2, int y2, | |||||
int tmp = y2; y2 = y1; y1 = tmp; | int tmp = y2; y2 = y1; y1 = tmp; | ||||
} | } | ||||
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++) | |||||
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)_caca_height; y++) | |||||
for(x = x1 > 0 ? x1 : 0, _init_dither(y); | for(x = x1 > 0 ? x1 : 0, _init_dither(y); | ||||
x <= x2 && x <= (int)caca_get_width(); | |||||
x <= x2 && x <= (int)_caca_width; | |||||
x++) | x++) | ||||
{ | { | ||||
int ch; | int ch; | ||||
unsigned int r, g, b, R, G, B; | |||||
unsigned int r, g, b, a, R, G, B; | |||||
int hue, sat, val; | int hue, sat, val; | ||||
int fromx = w * (x - x1) / (x2 - x1 + 1); | int fromx = w * (x - x1) / (x2 - x1 + 1); | ||||
int fromy = h * (y - y1) / (y2 - y1 + 1); | int fromy = h * (y - y1) / (y2 - y1 + 1); | ||||
@@ -413,18 +424,20 @@ void caca_draw_bitmap(int x1, int y1, int x2, int y2, | |||||
/* First get RGB */ | /* First get RGB */ | ||||
R = 0, G = 0, B = 0; | R = 0, G = 0, B = 0; | ||||
get_rgb_default(bitmap, pixels, fromx, fromy, &r, &g, &b); | |||||
get_rgba_default(bitmap, pixels, fromx, fromy, &r, &g, &b, &a); | |||||
if(a == 0) | |||||
continue; | |||||
#if 1 | #if 1 | ||||
R += r; G += g; B += b; | R += r; G += g; B += b; | ||||
#else | #else | ||||
R += r; G += g; B += b; | R += r; G += g; B += b; | ||||
get_rgb_default(bitmap, pixels, fromx - 1, fromy, &r, &g, &b); | |||||
get_rgba_default(bitmap, pixels, fromx - 1, fromy, &r, &g, &b, &a); | |||||
R += r; G += g; B += b; | R += r; G += g; B += b; | ||||
get_rgb_default(bitmap, pixels, fromx, fromy - 1, &r, &g, &b); | |||||
get_rgba_default(bitmap, pixels, fromx, fromy - 1, &r, &g, &b, &a); | |||||
R += r; G += g; B += b; | R += r; G += g; B += b; | ||||
get_rgb_default(bitmap, pixels, fromx + 1, fromy, &r, &g, &b); | |||||
get_rgba_default(bitmap, pixels, fromx + 1, fromy, &r, &g, &b, &a); | |||||
R += r; G += g; B += b; | R += r; G += g; B += b; | ||||
get_rgb_default(bitmap, pixels, fromx, fromy + 1, &r, &g, &b); | |||||
get_rgba_default(bitmap, pixels, fromx, fromy + 1, &r, &g, &b, &a); | |||||
R += r; G += g; B += b; | R += r; G += g; B += b; | ||||
R /= 5; G /= 5; B /= 5; | R /= 5; G /= 5; B /= 5; | ||||
#endif | #endif | ||||
@@ -443,6 +456,7 @@ void caca_draw_bitmap(int x1, int y1, int x2, int y2, | |||||
/* distance to black */ | /* distance to black */ | ||||
distbg = XRATIO * val * val; | distbg = XRATIO * val * val; | ||||
distbg += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; | distbg += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; | ||||
distbg = distbg * 2 / 4; | |||||
outbg = CACA_COLOR_BLACK; | outbg = CACA_COLOR_BLACK; | ||||
/* distance to 30% */ | /* distance to 30% */ | ||||
@@ -509,7 +523,7 @@ void caca_draw_bitmap(int x1, int y1, int x2, int y2, | |||||
+ YRATIO * (sat - 0x1000) * (sat - 0x1000) | + YRATIO * (sat - 0x1000) * (sat - 0x1000) | ||||
+ HRATIO * (hue - hue2) * (hue - hue2); | + HRATIO * (hue - hue2) * (hue - hue2); | ||||
dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; | dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; | ||||
dist = dist * 3 / 4; | |||||
// dist = dist * 3 / 4; | |||||
if(dist <= distbg) | if(dist <= distbg) | ||||
{ | { | ||||
outfg = outbg; | outfg = outbg; | ||||
@@ -528,7 +542,8 @@ void caca_draw_bitmap(int x1, int y1, int x2, int y2, | |||||
+ YRATIO * (sat - 0x1000) * (sat - 0x1000) | + YRATIO * (sat - 0x1000) * (sat - 0x1000) | ||||
+ HRATIO * (hue - hue2) * (hue - hue2); | + HRATIO * (hue - hue2) * (hue - hue2); | ||||
dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; | dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; | ||||
dist = dist / 2; | |||||
//dist = dist * 3 / 4; | |||||
//dist = dist / 2; | |||||
if(dist <= distbg) | if(dist <= distbg) | ||||
{ | { | ||||
outfg = outbg; | outfg = outbg; | ||||
@@ -58,8 +58,8 @@ void caca_draw_thin_box(int x1, int y1, int x2, int y2) | |||||
y1 = y2; y2 = tmp; | y1 = y2; y2 = tmp; | ||||
} | } | ||||
xmax = caca_get_width() - 1; | |||||
ymax = caca_get_height() - 1; | |||||
xmax = _caca_width - 1; | |||||
ymax = _caca_height - 1; | |||||
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | ||||
return; | return; | ||||
@@ -111,8 +111,8 @@ void caca_fill_box(int x1, int y1, int x2, int y2, char c) | |||||
y1 = y2; y2 = tmp; | y1 = y2; y2 = tmp; | ||||
} | } | ||||
xmax = caca_get_width() - 1; | |||||
ymax = caca_get_height() - 1; | |||||
xmax = _caca_width - 1; | |||||
ymax = _caca_height - 1; | |||||
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | ||||
return; | return; | ||||
@@ -38,9 +38,6 @@ | |||||
#elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
# include <dos.h> | # include <dos.h> | ||||
# include <conio.h> | # include <conio.h> | ||||
# if defined(SCREENUPDATE_IN_PC_H) | |||||
# include <pc.h> | |||||
# endif | |||||
#else | #else | ||||
# error "no graphics library detected" | # error "no graphics library detected" | ||||
#endif | #endif | ||||
@@ -62,7 +59,6 @@ int _caca_attr[16*16]; | |||||
#endif | #endif | ||||
#if defined(USE_CONIO) | #if defined(USE_CONIO) | ||||
static struct text_info ti; | |||||
char *_caca_screen; | char *_caca_screen; | ||||
#endif | #endif | ||||
@@ -132,24 +128,12 @@ int caca_init(void) | |||||
unsigned int caca_get_width(void) | unsigned int caca_get_width(void) | ||||
{ | { | ||||
#if defined(USE_SLANG) | |||||
return SLtt_Screen_Cols; | |||||
#elif defined(USE_NCURSES) | |||||
return COLS; | |||||
#elif defined(USE_CONIO) | |||||
return ti.screenwidth; | |||||
#endif | |||||
return _caca_width; | |||||
} | } | ||||
unsigned int caca_get_height(void) | unsigned int caca_get_height(void) | ||||
{ | { | ||||
#if defined(USE_SLANG) | |||||
return SLtt_Screen_Rows; | |||||
#elif defined(USE_NCURSES) | |||||
return LINES; | |||||
#else | |||||
return ti.screenheight; | |||||
#endif | |||||
return _caca_height; | |||||
} | } | ||||
const char *caca_get_color_name(enum caca_color color) | const char *caca_get_color_name(enum caca_color color) | ||||
@@ -212,7 +196,7 @@ void caca_end(void) | |||||
_wscroll = 1; | _wscroll = 1; | ||||
textcolor((enum COLORS)WHITE); | textcolor((enum COLORS)WHITE); | ||||
textbackground((enum COLORS)BLACK); | textbackground((enum COLORS)BLACK); | ||||
gotoxy(caca_get_width(), caca_get_height()); | |||||
gotoxy(_caca_width, _caca_height); | |||||
cputs("\r\n"); | cputs("\r\n"); | ||||
_setcursortype(_NORMALCURSOR); | _setcursortype(_NORMALCURSOR); | ||||
#endif | #endif | ||||
@@ -200,21 +200,22 @@ unsigned int caca_sqrt(unsigned int); | |||||
*/ | */ | ||||
struct caca_sprite; | struct caca_sprite; | ||||
struct caca_sprite * caca_load_sprite(const char *); | struct caca_sprite * caca_load_sprite(const char *); | ||||
int caca_get_sprite_frames(struct caca_sprite *); | |||||
int caca_get_sprite_width(struct caca_sprite *, int); | |||||
int caca_get_sprite_height(struct caca_sprite *, int); | |||||
int caca_get_sprite_dx(struct caca_sprite *, int); | |||||
int caca_get_sprite_dy(struct caca_sprite *, int); | |||||
void caca_draw_sprite(int, int, struct caca_sprite *, int); | |||||
int caca_get_sprite_frames(const struct caca_sprite *); | |||||
int caca_get_sprite_width(const struct caca_sprite *, int); | |||||
int caca_get_sprite_height(const struct caca_sprite *, int); | |||||
int caca_get_sprite_dx(const struct caca_sprite *, int); | |||||
int caca_get_sprite_dy(const struct caca_sprite *, int); | |||||
void caca_draw_sprite(int, int, const struct caca_sprite *, int); | |||||
void caca_free_sprite(struct caca_sprite *); | void caca_free_sprite(struct caca_sprite *); | ||||
/* | /* | ||||
* Bitmap handling | * Bitmap handling | ||||
*/ | */ | ||||
struct caca_bitmap; | struct caca_bitmap; | ||||
struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int); | |||||
void caca_set_bitmap_palette(struct caca_bitmap *, int[], int[], int[]); | |||||
void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *); | |||||
struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int, int); | |||||
void caca_set_bitmap_palette(struct caca_bitmap *, unsigned int[], | |||||
unsigned int[], unsigned int[], unsigned int[]); | |||||
void caca_draw_bitmap(int, int, int, int, const struct caca_bitmap *, char *); | |||||
void caca_free_bitmap(struct caca_bitmap *); | void caca_free_bitmap(struct caca_bitmap *); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
@@ -37,9 +37,13 @@ extern int _caca_attr[]; | |||||
#endif | #endif | ||||
#if defined(USE_CONIO) | #if defined(USE_CONIO) | ||||
extern struct text_info _ti; | |||||
extern char *_caca_screen; | extern char *_caca_screen; | ||||
#endif | #endif | ||||
extern unsigned int _caca_width; | |||||
extern unsigned int _caca_height; | |||||
extern char *_caca_empty_line; | extern char *_caca_empty_line; | ||||
extern char *_caca_scratch_line; | extern char *_caca_scratch_line; | ||||
@@ -191,13 +191,13 @@ static void ellipsepoints(int xo, int yo, int x, int y, char c) | |||||
{ | { | ||||
uint8_t b = 0; | uint8_t b = 0; | ||||
if(xo + x >= 0 && xo + x < (int)caca_get_width()) | |||||
if(xo + x >= 0 && xo + x < (int)_caca_width) | |||||
b |= 0x1; | b |= 0x1; | ||||
if(xo - x >= 0 && xo - x < (int)caca_get_width()) | |||||
if(xo - x >= 0 && xo - x < (int)_caca_width) | |||||
b |= 0x2; | b |= 0x2; | ||||
if(yo + y >= 0 && yo + y < (int)caca_get_height()) | |||||
if(yo + y >= 0 && yo + y < (int)_caca_height) | |||||
b |= 0x4; | b |= 0x4; | ||||
if(yo - y >= 0 && yo - y < (int)caca_get_height()) | |||||
if(yo - y >= 0 && yo - y < (int)_caca_height) | |||||
b |= 0x8; | b |= 0x8; | ||||
if((b & (0x1|0x4)) == (0x1|0x4)) | if((b & (0x1|0x4)) == (0x1|0x4)) | ||||
@@ -35,6 +35,9 @@ | |||||
# include <curses.h> | # include <curses.h> | ||||
#elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
# include <conio.h> | # include <conio.h> | ||||
# if defined(SCREENUPDATE_IN_PC_H) | |||||
# include <pc.h> | |||||
# endif | |||||
#else | #else | ||||
# error "no graphics library detected" | # error "no graphics library detected" | ||||
#endif | #endif | ||||
@@ -54,6 +57,13 @@ | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#ifdef USE_CONIO | |||||
static struct text_info ti; | |||||
#endif | |||||
unsigned int _caca_width; | |||||
unsigned int _caca_height; | |||||
static unsigned int _caca_delay; | static unsigned int _caca_delay; | ||||
static unsigned int _caca_rendertime; | static unsigned int _caca_rendertime; | ||||
@@ -92,8 +102,8 @@ void caca_putchar(int x, int y, char c) | |||||
#if defined(USE_CONIO) | #if defined(USE_CONIO) | ||||
char *data; | char *data; | ||||
#endif | #endif | ||||
if(x < 0 || x >= (int)caca_get_width() || | |||||
y < 0 || y >= (int)caca_get_height()) | |||||
if(x < 0 || x >= (int)_caca_width || | |||||
y < 0 || y >= (int)_caca_height) | |||||
return; | return; | ||||
#if defined(USE_SLANG) | #if defined(USE_SLANG) | ||||
@@ -103,7 +113,7 @@ void caca_putchar(int x, int y, char c) | |||||
move(y, x); | move(y, x); | ||||
addch(c); | addch(c); | ||||
#elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
data = _caca_screen + 2 * (x + y * caca_get_width()); | |||||
data = _caca_screen + 2 * (x + y * _caca_width); | |||||
data[0] = c; | data[0] = c; | ||||
data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; | data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; | ||||
// gotoxy(x + 1, y + 1); | // gotoxy(x + 1, y + 1); | ||||
@@ -115,7 +125,7 @@ void caca_putstr(int x, int y, const char *s) | |||||
{ | { | ||||
unsigned int len; | unsigned int len; | ||||
if(y < 0 || y >= (int)caca_get_height() || x >= (int)caca_get_width()) | |||||
if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width) | |||||
return; | return; | ||||
len = strlen(s); | len = strlen(s); | ||||
@@ -129,10 +139,10 @@ void caca_putstr(int x, int y, const char *s) | |||||
x = 0; | x = 0; | ||||
} | } | ||||
if(x + len >= caca_get_width()) | |||||
if(x + len >= _caca_width) | |||||
{ | { | ||||
memcpy(_caca_scratch_line, s, caca_get_width() - x); | |||||
_caca_scratch_line[caca_get_width() - x] = '\0'; | |||||
memcpy(_caca_scratch_line, s, _caca_width - x); | |||||
_caca_scratch_line[_caca_width - x] = '\0'; | |||||
s = _caca_scratch_line; | s = _caca_scratch_line; | ||||
} | } | ||||
@@ -143,7 +153,7 @@ void caca_putstr(int x, int y, const char *s) | |||||
move(y, x); | move(y, x); | ||||
addstr(s); | addstr(s); | ||||
#elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
char *buf = _caca_screen + 2 * (x + y * caca_get_width()); | |||||
char *buf = _caca_screen + 2 * (x + y * _caca_width); | |||||
while(*s) | while(*s) | ||||
{ | { | ||||
*buf++ = *s++; | *buf++ = *s++; | ||||
@@ -160,19 +170,19 @@ void caca_printf(int x, int y, const char *format, ...) | |||||
char *buf = tmp; | char *buf = tmp; | ||||
va_list args; | va_list args; | ||||
if(y < 0 || y >= (int)caca_get_height() || x >= (int)caca_get_width()) | |||||
if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width) | |||||
return; | return; | ||||
if(caca_get_width() - x + 1 > BUFSIZ) | |||||
buf = malloc(caca_get_width() - x + 1); | |||||
if(_caca_width - x + 1 > BUFSIZ) | |||||
buf = malloc(_caca_width - x + 1); | |||||
va_start(args, format); | va_start(args, format); | ||||
#if defined(HAVE_VSNPRINTF) | #if defined(HAVE_VSNPRINTF) | ||||
vsnprintf(buf, caca_get_width() - x + 1, format, args); | |||||
vsnprintf(buf, _caca_width - x + 1, format, args); | |||||
#else | #else | ||||
vsprintf(buf, format, args); | vsprintf(buf, format, args); | ||||
#endif | #endif | ||||
buf[caca_get_width() - x] = '\0'; | |||||
buf[_caca_width - x] = '\0'; | |||||
va_end(args); | va_end(args); | ||||
caca_putstr(x, y, buf); | caca_putstr(x, y, buf); | ||||
@@ -185,7 +195,7 @@ void caca_clear(void) | |||||
{ | { | ||||
enum caca_color oldfg = caca_get_fg_color(); | enum caca_color oldfg = caca_get_fg_color(); | ||||
enum caca_color oldbg = caca_get_bg_color(); | enum caca_color oldbg = caca_get_bg_color(); | ||||
int y = caca_get_height(); | |||||
int y = _caca_height; | |||||
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); | caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); | ||||
@@ -234,6 +244,9 @@ int _caca_init_graphics(void) | |||||
/* Disable alt charset support so that we get all 256 colour pairs */ | /* Disable alt charset support so that we get all 256 colour pairs */ | ||||
SLtt_Has_Alt_Charset = 0; | SLtt_Has_Alt_Charset = 0; | ||||
_caca_width = SLtt_Screen_Cols; | |||||
_caca_height = SLtt_Screen_Rows; | |||||
#elif defined(USE_NCURSES) | #elif defined(USE_NCURSES) | ||||
static int curses_colors[] = | static int curses_colors[] = | ||||
{ | { | ||||
@@ -292,6 +305,9 @@ int _caca_init_graphics(void) | |||||
} | } | ||||
} | } | ||||
_caca_width = COLS; | |||||
_caca_height = LINES; | |||||
#elif defined(USE_CONIO) | #elif defined(USE_CONIO) | ||||
gettextinfo(&ti); | gettextinfo(&ti); | ||||
_caca_screen = malloc(2 * ti.screenwidth * ti.screenheight); | _caca_screen = malloc(2 * ti.screenwidth * ti.screenheight); | ||||
@@ -302,13 +318,15 @@ int _caca_init_graphics(void) | |||||
# else | # else | ||||
/* FIXME */ | /* FIXME */ | ||||
# endif | # endif | ||||
_caca_width = ti.screenwidth; | |||||
_caca_height = ti.screenheight; | |||||
#endif | #endif | ||||
_caca_empty_line = malloc(caca_get_width() + 1); | |||||
memset(_caca_empty_line, ' ', caca_get_width()); | |||||
_caca_empty_line[caca_get_width()] = '\0'; | |||||
_caca_empty_line = malloc(_caca_width + 1); | |||||
memset(_caca_empty_line, ' ', _caca_width); | |||||
_caca_empty_line[_caca_width] = '\0'; | |||||
_caca_scratch_line = malloc(caca_get_width() + 1); | |||||
_caca_scratch_line = malloc(_caca_width + 1); | |||||
_caca_delay = 0; | _caca_delay = 0; | ||||
_caca_rendertime = 0; | _caca_rendertime = 0; | ||||
@@ -171,7 +171,7 @@ static void clip_line(struct line* s) | |||||
} | } | ||||
else if(bits1 & (1<<1)) | else if(bits1 & (1<<1)) | ||||
{ | { | ||||
int xmax = caca_get_width() - 1; | |||||
int xmax = _caca_width - 1; | |||||
s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); | s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); | ||||
s->x1 = xmax; | s->x1 = xmax; | ||||
} | } | ||||
@@ -182,7 +182,7 @@ static void clip_line(struct line* s) | |||||
} | } | ||||
else if(bits1 & (1<<3)) | else if(bits1 & (1<<3)) | ||||
{ | { | ||||
int ymax = caca_get_height() - 1; | |||||
int ymax = _caca_height - 1; | |||||
s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); | s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); | ||||
s->y1 = ymax; | s->y1 = ymax; | ||||
} | } | ||||
@@ -203,12 +203,12 @@ static uint8_t clip_bits(int x, int y) | |||||
if(x < 0) | if(x < 0) | ||||
b |= (1<<0); | b |= (1<<0); | ||||
else if(x >= (int)caca_get_width()) | |||||
else if(x >= (int)_caca_width) | |||||
b |= (1<<1); | b |= (1<<1); | ||||
if(y < 0) | if(y < 0) | ||||
b |= (1<<2); | b |= (1<<2); | ||||
else if(y >= (int)caca_get_height()) | |||||
else if(y >= (int)_caca_height) | |||||
b |= (1<<3); | b |= (1<<3); | ||||
return b; | return b; | ||||
@@ -165,7 +165,7 @@ sprite_alloc_failed: | |||||
return NULL; | return NULL; | ||||
} | } | ||||
int caca_get_sprite_frames(struct caca_sprite *sprite) | |||||
int caca_get_sprite_frames(const struct caca_sprite *sprite) | |||||
{ | { | ||||
if(sprite == NULL) | if(sprite == NULL) | ||||
return 0; | return 0; | ||||
@@ -173,7 +173,7 @@ int caca_get_sprite_frames(struct caca_sprite *sprite) | |||||
return sprite->nf; | return sprite->nf; | ||||
} | } | ||||
int caca_get_sprite_width(struct caca_sprite *sprite, int f) | |||||
int caca_get_sprite_width(const struct caca_sprite *sprite, int f) | |||||
{ | { | ||||
if(sprite == NULL) | if(sprite == NULL) | ||||
return 0; | return 0; | ||||
@@ -184,7 +184,7 @@ int caca_get_sprite_width(struct caca_sprite *sprite, int f) | |||||
return sprite->frames[f].w; | return sprite->frames[f].w; | ||||
} | } | ||||
int caca_get_sprite_height(struct caca_sprite *sprite, int f) | |||||
int caca_get_sprite_height(const struct caca_sprite *sprite, int f) | |||||
{ | { | ||||
if(sprite == NULL) | if(sprite == NULL) | ||||
return 0; | return 0; | ||||
@@ -195,7 +195,7 @@ int caca_get_sprite_height(struct caca_sprite *sprite, int f) | |||||
return sprite->frames[f].h; | return sprite->frames[f].h; | ||||
} | } | ||||
int caca_get_sprite_dx(struct caca_sprite *sprite, int f) | |||||
int caca_get_sprite_dx(const struct caca_sprite *sprite, int f) | |||||
{ | { | ||||
if(sprite == NULL) | if(sprite == NULL) | ||||
return 0; | return 0; | ||||
@@ -206,7 +206,7 @@ int caca_get_sprite_dx(struct caca_sprite *sprite, int f) | |||||
return sprite->frames[f].dx; | return sprite->frames[f].dx; | ||||
} | } | ||||
int caca_get_sprite_dy(struct caca_sprite *sprite, int f) | |||||
int caca_get_sprite_dy(const struct caca_sprite *sprite, int f) | |||||
{ | { | ||||
if(sprite == NULL) | if(sprite == NULL) | ||||
return 0; | return 0; | ||||
@@ -217,7 +217,7 @@ int caca_get_sprite_dy(struct caca_sprite *sprite, int f) | |||||
return sprite->frames[f].dy; | return sprite->frames[f].dy; | ||||
} | } | ||||
void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f) | |||||
void caca_draw_sprite(int x, int y, const struct caca_sprite *sprite, int f) | |||||
{ | { | ||||
int i, j; | int i, j; | ||||
enum caca_color oldfg, oldbg; | enum caca_color oldfg, oldbg; | ||||
@@ -70,8 +70,8 @@ void caca_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c) | |||||
x2 *= 4; | x2 *= 4; | ||||
x3 *= 4; | x3 *= 4; | ||||
xmax = caca_get_width() - 1; | |||||
ymax = caca_get_height() - 1; | |||||
xmax = _caca_width - 1; | |||||
ymax = _caca_height - 1; | |||||
/* Rasterize our triangle */ | /* Rasterize our triangle */ | ||||
for(y = y1 < 0 ? 0 : y1; y <= y3 && y <= ymax; y++) | for(y = y1 < 0 ? 0 : y1; y <= y3 && y <= ymax; y++) | ||||