Kaynağa Gözat

* Use 32 bit integers for the character array. No visible difference for

now because we only do ASCII, but that will let us do Unicode later.
tags/v0.99.beta14
Sam Hocevar sam 19 yıl önce
ebeveyn
işleme
6c6beb3541
6 değiştirilmiş dosya ile 67 ekleme ve 46 silme
  1. +1
    -0
      src/caca.c
  2. +9
    -8
      src/char.c
  3. +12
    -7
      src/cucul.c
  4. +2
    -1
      src/cucul_internals.h
  5. +17
    -16
      src/export.c
  6. +26
    -14
      src/graphics.c

+ 1
- 0
src/caca.c Dosyayı Görüntüle

@@ -24,6 +24,7 @@
#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
# include <inttypes.h>
#else
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
#endif



+ 9
- 8
src/char.c Dosyayı Görüntüle

@@ -22,6 +22,7 @@
#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
# include <inttypes.h>
#else
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
#endif

@@ -101,7 +102,7 @@ void cucul_putchar(cucul_t *qq, int x, int y, char c)
y < 0 || y >= (int)qq->height)
return;

qq->chars[x + y * qq->width] = c;
qq->chars[x + y * qq->width] = c & 0x7f; /* FIXME: ASCII-only */
qq->attr[x + y * qq->width] = (qq->bgcolor << 4) | qq->fgcolor;
}

@@ -118,8 +119,8 @@ void cucul_putchar(cucul_t *qq, int x, int y, char c)
*/
void cucul_putstr(cucul_t *qq, int x, int y, char const *s)
{
unsigned char *charbuf;
unsigned char *attrbuf;
uint32_t *chars;
uint8_t *attr;
char const *t;
unsigned int len;

@@ -145,13 +146,13 @@ void cucul_putstr(cucul_t *qq, int x, int y, char const *s)
s = qq->scratch_line;
}

charbuf = qq->chars + x + y * qq->width;
attrbuf = qq->attr + x + y * qq->width;
chars = qq->chars + x + y * qq->width;
attr = qq->attr + x + y * qq->width;
t = s;
while(*t)
{
*charbuf++ = *t++;
*attrbuf++ = (qq->bgcolor << 4) | qq->fgcolor;
*chars++ = *t++ & 0x7f; /* FIXME: ASCII-only */
*attr++ = (qq->bgcolor << 4) | qq->fgcolor;
}
}

@@ -208,7 +209,7 @@ void cucul_get_screen(cucul_t *qq, char *buffer)
for(x = 0; x < qq->width; x++)
{
*buffer++ = qq->attr[x + y * qq->width];
*buffer++ = qq->chars[x + y * qq->width];
*buffer++ = qq->chars[x + y * qq->width] & 0x7f; /* FIXME: ASCII */
}
}
}


+ 12
- 7
src/cucul.c Dosyayı Görüntüle

@@ -23,6 +23,7 @@
#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
# include <inttypes.h>
#else
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
#endif

@@ -46,6 +47,7 @@ static void cucul_read_environment(cucul_t *qq);
cucul_t * cucul_init(void)
{
cucul_t *qq = malloc(sizeof(cucul_t));
int i;

cucul_read_environment(qq);

@@ -57,10 +59,11 @@ cucul_t * cucul_init(void)
qq->width = 80;
qq->height = 32;

qq->chars = malloc(qq->width * qq->height * sizeof(uint8_t));
qq->chars = malloc(qq->width * qq->height * sizeof(uint32_t));
qq->attr = malloc(qq->width * qq->height * sizeof(uint8_t));

memset(qq->chars, ' ', qq->width * qq->height * sizeof(uint8_t));
for(i = qq->width * qq->height; i--; )
qq->chars[i] = (uint32_t)' ';
memset(qq->attr, 0, qq->width * qq->height * sizeof(uint8_t));

qq->empty_line = malloc(qq->width + 1);
@@ -100,7 +103,7 @@ void cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height)
/* Step 1: if new area is bigger, resize the memory area now. */
if(new_size > old_size)
{
qq->chars = realloc(qq->chars, new_size * sizeof(uint8_t));
qq->chars = realloc(qq->chars, new_size * sizeof(uint32_t));
qq->attr = realloc(qq->attr, new_size * sizeof(uint8_t));
}

@@ -124,8 +127,8 @@ void cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height)
}

/* Zero the end of the line */
memset(qq->chars + y * width + old_width, ' ',
width - old_width);
for(x = width - old_width; x--; )
qq->chars[y * width + old_width + x] = (uint32_t)' ';
memset(qq->attr + y * width + old_width, 0,
width - old_width);
}
@@ -150,14 +153,16 @@ void cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height)
if(height > old_height)
{
/* Zero the bottom of the screen */
memset(qq->chars + old_height * width, ' ',
for(x = (height - old_height) * width; x--; )
qq->chars[old_height * width + x] = (uint32_t)' ';
memset(qq->attr + old_height * width, 0,
(height - old_height) * width);
}

/* Step 4: if new area is smaller, resize memory area now. */
if(new_size <= old_size)
{
qq->chars = realloc(qq->chars, new_size * sizeof(uint8_t));
qq->chars = realloc(qq->chars, new_size * sizeof(uint32_t));
qq->attr = realloc(qq->attr, new_size * sizeof(uint8_t));
}



+ 2
- 1
src/cucul_internals.h Dosyayı Görüntüle

@@ -25,7 +25,8 @@ struct cucul_context
/* Context size */
unsigned int width, height;

uint8_t *chars, *attr;
uint32_t *chars;
uint8_t *attr;
uint8_t *empty_line, *scratch_line;

enum cucul_color fgcolor;


+ 17
- 16
src/export.c Dosyayı Görüntüle

@@ -22,6 +22,7 @@
#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
# include <inttypes.h>
#else
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
#endif

@@ -74,7 +75,7 @@ char* cucul_get_html(cucul_t *qq)
for(y = 0; y < qq->height; y++)
{
uint8_t *lineattr = qq->attr + y * qq->width;
uint8_t *linechar = qq->chars + y * qq->width;
uint32_t *linechar = qq->chars + y * qq->width;

for(x = 0; x < qq->width; x += len)
{
@@ -84,10 +85,10 @@ char* cucul_get_html(cucul_t *qq)
x + len < qq->width && lineattr[x + len] == lineattr[x];
len++)
{
if(linechar[x + len] == ' ')
if(linechar[x + len] == (uint32_t)' ')
cur += sprintf(cur, "&nbsp;");
else
cur += sprintf(cur, "%c", linechar[x + len]);
cur += sprintf(cur, "%c", linechar[x + len] & 0x7f);
}
cur += sprintf(cur, "</span>");
}
@@ -135,7 +136,7 @@ char* cucul_get_html3(cucul_t *qq)
for(y = 0; y < qq->height; y++)
{
uint8_t *lineattr = qq->attr + y * qq->width;
uint8_t *linechar = qq->chars + y * qq->width;
uint32_t *linechar = qq->chars + y * qq->width;

cur += sprintf(cur, "<tr>");

@@ -159,10 +160,10 @@ char* cucul_get_html3(cucul_t *qq)

for(i = 0; i < len; i++)
{
if(linechar[x + i] == ' ')
if(linechar[x + i] == (uint32_t)' ')
cur += sprintf(cur, "&nbsp;");
else
cur += sprintf(cur, "%c", linechar[x + i]);
cur += sprintf(cur, "%c", linechar[x + i] & 0x7f);
}

cur += sprintf(cur, "</font></td>");
@@ -210,7 +211,7 @@ char* cucul_get_irc(cucul_t *qq)
for(y = 0; y < qq->height; y++)
{
uint8_t *lineattr = qq->attr + y * qq->width;
uint8_t *linechar = qq->chars + y * qq->width;
uint32_t *linechar = qq->chars + y * qq->width;

uint8_t prevfg = -1;
uint8_t prevbg = -1;
@@ -219,18 +220,18 @@ char* cucul_get_irc(cucul_t *qq)
{
uint8_t fg = palette[lineattr[x] & 0x0f];
uint8_t bg = palette[lineattr[x] >> 4];
uint8_t c = linechar[x];
uint32_t c = linechar[x];

if(bg == prevbg)
{
if(fg == prevfg)
; /* Same fg/bg, do nothing */
else if(c == ' ')
else if(c == (uint32_t)' ')
fg = prevfg; /* Hackety hack */
else
{
cur += sprintf(cur, "\x03%d", fg);
if(c >= '0' && c <= '9')
if(c >= (uint32_t)'0' && c <= (uint32_t)'9')
cur += sprintf(cur, "\x02\x02");
}
}
@@ -241,10 +242,10 @@ char* cucul_get_irc(cucul_t *qq)
else
cur += sprintf(cur, "\x03%d,%d", fg, bg);

if(c >= '0' && c <= '9')
if(c >= (uint32_t)'0' && c <= (uint32_t)'9')
cur += sprintf(cur, "\x02\x02");
}
*cur++ = c;
*cur++ = c & 0x7f;
prevfg = fg;
prevbg = bg;
}
@@ -289,7 +290,7 @@ char * cucul_get_ansi(cucul_t *qq, int trailing)
for(y = 0; y < qq->height; y++)
{
uint8_t *lineattr = qq->attr + y * qq->width;
uint8_t *linechar = qq->chars + y * qq->width;
uint32_t *linechar = qq->chars + y * qq->width;

uint8_t prevfg = -1;
uint8_t prevbg = -1;
@@ -298,7 +299,7 @@ char * cucul_get_ansi(cucul_t *qq, int trailing)
{
uint8_t fg = palette[lineattr[x] & 0x0f];
uint8_t bg = (palette[lineattr[x] >> 4])+10;
uint8_t c = linechar[x];
uint32_t c = linechar[x];

if(!trailing)
cur += sprintf(cur, "\033[");
@@ -309,9 +310,9 @@ char * cucul_get_ansi(cucul_t *qq, int trailing)
cur += sprintf(cur, "1;%d;%dm",fg,bg);
else
cur += sprintf(cur, "0;%d;%dm",fg,bg);
*cur++ = c;
*cur++ = c & 0x7f;
if((c == '%') && trailing)
*cur++ = c;
*cur++ = c & 0x7f;
prevfg = fg;
prevbg = bg;
}


+ 26
- 14
src/graphics.c Dosyayı Görüntüle

@@ -56,6 +56,7 @@
#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
# include <inttypes.h>
#else
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
#endif

@@ -879,7 +880,7 @@ void caca_display(caca_t *kk)
{
int x, y;
uint8_t *attr = kk->qq->attr;
uint8_t *chars = kk->qq->chars;
uint32_t *chars = kk->qq->chars;
for(y = 0; y < (int)kk->qq->height; y++)
{
SLsmg_gotorc(y, 0);
@@ -893,7 +894,7 @@ void caca_display(caca_t *kk)
if(fgcolor != bgcolor)
{
SLsmg_set_color(slang_assoc[*attr++]);
SLsmg_write_char(*chars++);
SLsmg_write_char(*chars++ & 0x7f);
}
else
{
@@ -911,7 +912,7 @@ void caca_display(caca_t *kk)
}
#else
SLsmg_set_color(*attr++);
SLsmg_write_char(*chars++);
SLsmg_write_char(*chars++ & 0x7f);
#endif
}
}
@@ -924,14 +925,14 @@ void caca_display(caca_t *kk)
{
int x, y;
uint8_t *attr = kk->qq->attr;
uint8_t *chars = kk->qq->chars;
uint32_t *chars = kk->qq->chars;
for(y = 0; y < (int)kk->qq->height; y++)
{
move(y, 0);
for(x = kk->qq->width; x--; )
{
attrset(kk->ncurses.attr[*attr++]);
addch(*chars++);
addch(*chars++ & 0x7f);
}
}
refresh();
@@ -944,10 +945,10 @@ void caca_display(caca_t *kk)
int n;
char *screen = kk->conio.screen;
uint8_t *attr = kk->qq->attr;
uint8_t *chars = kk->qq->chars;
uint32_t *chars = kk->qq->chars;
for(n = kk->qq->height * kk->qq->width; n--; )
{
*screen++ = *chars++;
*screen++ = *chars++ & 0x7f;
*screen++ = *attr++;
}
# if defined(SCREENUPDATE_IN_PC_H)
@@ -989,22 +990,30 @@ void caca_display(caca_t *kk)
{
for(x = 0; x < kk->qq->width; x += len)
{
char buffer[BUFSIZ]; /* FIXME: use a smaller buffer */
uint32_t *chars = kk->qq->chars + x + y * kk->qq->width;
uint8_t *attr = kk->qq->attr + x + y * kk->qq->width;

len = 1;

/* Skip spaces */
if(kk->qq->chars[x + y * kk->qq->width] == ' ')
if(chars[0] == ' ')
continue;

buffer[0] = chars[0] & 0x7f;

while(x + len < kk->qq->width
&& (attr[len] & 0xf) == (attr[0] & 0xf))
{
buffer[len] = chars[len] & 0x7f;
len++;
}

XSetForeground(kk->x11.dpy, kk->x11.gc, kk->x11.colors[attr[0] & 0xf]);
XDrawString(kk->x11.dpy, kk->x11.pixmap, kk->x11.gc, x * kk->x11.font_width,
XDrawString(kk->x11.dpy, kk->x11.pixmap, kk->x11.gc,
x * kk->x11.font_width,
(y + 1) * kk->x11.font_height - kk->x11.font_offset,
(char*)(kk->qq->chars + x + y * kk->qq->width), len);
buffer, len);
}
}

@@ -1025,7 +1034,7 @@ void caca_display(caca_t *kk)
/* Render everything to our back buffer */
for(i = 0; i < kk->qq->width * kk->qq->height; i++)
{
kk->win32.buffer[i].Char.AsciiChar = kk->qq->chars[i];
kk->win32.buffer[i].Char.AsciiChar = kk->qq->chars[i] & 0x7f;
kk->win32.buffer[i].Attributes =
win32_fg_palette[kk->qq->attr[i] & 0xf]
| win32_bg_palette[kk->qq->attr[i] >> 4];
@@ -1080,13 +1089,16 @@ void caca_display(caca_t *kk)
for(y = 0; y < kk->gl.height; y += kk->gl.font_height)
{
uint8_t *attr = kk->qq->attr + line * kk->qq->width;
unsigned char *chars = kk->qq->chars + line * kk->qq->width;
uint32_t *chars = kk->qq->chars + line * kk->qq->width;

for(x = 0; x < kk->gl.width; x += kk->gl.font_width)
{
if(chars[0] != ' ')
if(*chars != (uint32_t)' ')
{
glBindTexture(GL_TEXTURE_2D, kk->gl.id[chars[0]-32]);
char ch = *chars & 0x7f;

/* FIXME: check ch bounds */
glBindTexture(GL_TEXTURE_2D, kk->gl.id[ch - 32]);
glColor4bv(gl_bgpal[attr[0] & 0xf]);
glBegin(GL_QUADS);
glTexCoord2f(0, kk->gl.sh);


Yükleniyor…
İptal
Kaydet