ソースを参照

* TODO:

+ A few updates.
  * src/blit.c:
    + Split blit() into caca_create_bitmap() and caca_draw_bitmap().
    + Started removing hardcoded bitmask and pitch values.
  * examples/demo.c:
    + Do something with mouse clicks.
tags/v0.99.beta14
Sam Hocevar sam 21年前
コミット
24409d793b
4個のファイルの変更91行の追加11行の削除
  1. +4
    -0
      TODO
  2. +9
    -0
      examples/demo.c
  3. +54
    -8
      src/blit.c
  4. +24
    -3
      src/caca.h

+ 4
- 0
TODO ファイルの表示

@@ -21,11 +21,15 @@ High level stuff

o Fix the thin ellipse rendering

o Support more colour depths, more bitmask orderings


Misc

o Draw a nicer logo sprite

o Text edit widget


Documentation



+ 9
- 0
examples/demo.c ファイルの表示

@@ -183,6 +183,13 @@ fprintf(stderr, "w %i, h %i, stride %i\n", bufx, bufy, bufpitch);

caca_refresh();
}
else if(event & CACA_EVENT_MOUSE_CLICK)
{
display_menu();
caca_set_color(CACA_COLOR_RED);
caca_putstr((event & 0xff00) >> 8, event & 0xff, "|\\");
caca_refresh();
}

if(demo)
{
@@ -485,7 +492,9 @@ static void demo_sprites(void)

static void demo_blit(void)
{
#if 0
caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4,
pixels, bufx, bufy);
#endif
}


+ 54
- 8
src/blit.c ファイルの表示

@@ -83,13 +83,64 @@ void caca_set_dithering(enum caca_dithering dither)
_caca_dithering = dither;
}

void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
struct caca_bitmap
{
int bpp;
int w, h, pitch;
int rmask, gmask, bmask;
};

struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch,
int rmask, int gmask, int bmask)
{
struct caca_bitmap *bitmap;

/* Currently only this format is supported. Will improve later. */
if(!w || !h || !pitch || bpp != 32 ||
rmask != 0x00ff0000 || gmask != 0x0000ff00 || bmask != 0x000000ff)
return NULL;

bitmap = malloc(sizeof(struct caca_bitmap));
if(!bitmap)
return NULL;

bitmap->bpp = bpp;

bitmap->w = w;
bitmap->h = h;
bitmap->pitch = pitch;

bitmap->rmask = rmask;
bitmap->gmask = gmask;
bitmap->bmask = bmask;

return bitmap;
}

void caca_free_bitmap(struct caca_bitmap *bitmap)
{
if(!bitmap)
return;

free(bitmap);
}

void caca_draw_bitmap(int x1, int y1, int x2, int y2,
struct caca_bitmap *bitmap, char *pixels)
{
/* FIXME: this code is shite! */
static int white_colors[] = {CACA_COLOR_DARKGRAY, CACA_COLOR_LIGHTGRAY, CACA_COLOR_WHITE};
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};
static char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' };
int x, y, pitch;
int x, y, w, h, pitch;

if(!bitmap || !pixels)
return;

w = bitmap->w;
h = bitmap->h;
pitch = bitmap->pitch;

if(x1 > x2)
{
@@ -101,9 +152,6 @@ void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
int tmp = y2; y2 = y1; y1 = tmp;
}

//pitch = (3 * w + 3) / 4 * 4;
pitch = 4 * w;

for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++)
{
/* Initialize dither tables for the current line */
@@ -114,9 +162,7 @@ void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
{
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];
/* FIXME: bwahaaa, we don't even respect masks */
int b = ((unsigned char *)pixels)[4 * fromx + pitch * fromy];
int g = ((unsigned char *)pixels)[4 * fromx + 1 + pitch * fromy];
int r = ((unsigned char *)pixels)[4 * fromx + 2 + pitch * fromy];


+ 24
- 3
src/caca.h ファイルの表示

@@ -101,12 +101,13 @@ enum caca_key
};

/*
* Types
* Internal types
*/
struct caca_sprite;
struct caca_bitmap;

/*
* Prototypes
* Basic functions
*/
int caca_init(void);
void caca_set_delay(unsigned int);
@@ -118,8 +119,14 @@ const char *caca_get_color_name(unsigned int);
void caca_refresh(void);
void caca_end(void);

/*
* Events
*/
int caca_get_event(void);

/*
* Character graphics
*/
void caca_set_color(enum caca_color);
enum caca_color caca_get_color(void);
void caca_putchar(int, int, char);
@@ -127,6 +134,9 @@ void caca_putstr(int, int, const char *);
void caca_printf(int, int, const char *, ...);
void caca_clear(void);

/*
* Graphics primitives
*/
void caca_draw_line(int, int, int, int, char);
void caca_draw_polyline(const int[], const int[], int, char);
void caca_draw_thin_line(int, int, int, int);
@@ -145,9 +155,15 @@ void caca_draw_triangle(int, int, int, int, int, int, char);
void caca_draw_thin_triangle(int, int, int, int, int, int);
void caca_fill_triangle(int, int, int, int, int, int, char);

/*
* Maths
*/
int caca_rand(int, int);
unsigned int caca_sqrt(unsigned int);

/*
* Sprite handling
*/
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);
@@ -157,7 +173,12 @@ int caca_get_sprite_dy(struct caca_sprite *, int);
void caca_draw_sprite(int, int, struct caca_sprite *, int);
void caca_free_sprite(struct caca_sprite *);

void caca_blit(int, int, int, int, void *, int, int);
/*
* Bitmap handling
*/
struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int);
void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *);
void caca_free_bitmap(struct caca_bitmap *);

#ifdef __cplusplus
}


読み込み中…
キャンセル
保存