Przeglądaj źródła

* Added truecolor support to the X11 and GL drivers.

tags/v0.99.beta14
Sam Hocevar sam 18 lat temu
rodzic
commit
3fa0bbbd7c
2 zmienionych plików z 19 dodań i 60 usunięć
  1. +8
    -27
      caca/driver_gl.c
  2. +11
    -33
      caca/driver_x11.c

+ 8
- 27
caca/driver_gl.c Wyświetl plik

@@ -41,31 +41,6 @@
* Global variables
*/

/* Ok, I just suck. */
static GLbyte const gl_bgpal[][4] =
{
{ 0x00, 0x00, 0x00, 0x7f },
{ 0x00, 0x00, 0x3f, 0x7f },
{ 0x00, 0x3f, 0x00, 0x7f },
{ 0x00, 0x3f, 0x3f, 0x7f },
{ 0x3f, 0x00, 0x00, 0x7f },
{ 0x3f, 0x00, 0x3f, 0x7f },
{ 0x3f, 0x3f, 0x00, 0x7f },
{ 0x3f, 0x3f, 0x3f, 0x7f },
// + intensity
// >.
// ()
// ^^
{ 0x1f, 0x1f, 0x1f, 0x7f },
{ 0x1f, 0x1f, 0x7f, 0x7f },
{ 0x1f, 0x7f, 0x1f, 0x7f },
{ 0x1f, 0x7f, 0x7f, 0x7f },
{ 0x7f, 0x1f, 0x1f, 0x7f },
{ 0x7f, 0x1f, 0x7f, 0x7f },
{ 0x7f, 0x7f, 0x1f, 0x7f },
{ 0x7f, 0x7f, 0x7f, 0x7f }
};

static caca_t *gl_kk; /* FIXME: we ought to get rid of this */

/*
@@ -247,8 +222,11 @@ static void gl_display(caca_t *kk)

for(x = 0; x < kk->drv.p->width; x += kk->drv.p->font_width)
{
uint16_t bg = _cucul_argb32_to_rgb12bg(*attr++);
glDisable(GL_TEXTURE_2D);
glColor4bv(gl_bgpal[_cucul_argb32_to_ansi4bg(*attr++)]);
glColor3b(((bg & 0xf00) >> 8) * 8,
((bg & 0x0f0) >> 4) * 8,
(bg & 0x00f) * 8);
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + kk->drv.p->font_width, y);
@@ -278,8 +256,11 @@ static void gl_display(caca_t *kk)

if(c > 0x00000020 && c < 0x00000080)
{
uint16_t fg = _cucul_argb32_to_rgb12fg(*attr);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[c - 32]);
glColor4bv(gl_bgpal[_cucul_argb32_to_ansi4fg(*attr)]);
glColor3b(((fg & 0xf00) >> 8) * 8,
((fg & 0x0f0) >> 4) * 8,
(fg & 0x00f) * 8);
glBegin(GL_QUADS);
glTexCoord2f(0, kk->drv.p->sh);
glVertex2f(x, y);


+ 11
- 33
caca/driver_x11.c Wyświetl plik

@@ -47,7 +47,7 @@ struct driver_private
GC gc;
long int event_mask;
int font_width, font_height;
int colors[16];
int colors[4096];
Font font;
XFontStruct *font_struct;
int font_offset;
@@ -59,28 +59,6 @@ struct driver_private

static int x11_init_graphics(caca_t *kk)
{
static int const x11_palette[] =
{
/* Standard curses colours */
0x0, 0x0, 0x0,
0x0, 0x0, 0x8000,
0x0, 0x8000, 0x0,
0x0, 0x8000, 0x8000,
0x8000, 0x0, 0x0,
0x8000, 0x0, 0x8000,
0x8000, 0x8000, 0x0,
0x8000, 0x8000, 0x8000,
/* Extra values for xterm-16color */
0x4000, 0x4000, 0x4000,
0x4000, 0x4000, 0xffff,
0x4000, 0xffff, 0x4000,
0x4000, 0xffff, 0xffff,
0xffff, 0x4000, 0x4000,
0xffff, 0x4000, 0xffff,
0xffff, 0xffff, 0x4000,
0xffff, 0xffff, 0xffff,
};

Colormap colormap;
XSetWindowAttributes x11_winattr;
int (*old_error_handler)(Display *, XErrorEvent *);
@@ -148,18 +126,18 @@ static int x11_init_graphics(caca_t *kk)
kk->drv.p->font_offset = kk->drv.p->font_struct->max_bounds.descent;

colormap = DefaultColormap(kk->drv.p->dpy, DefaultScreen(kk->drv.p->dpy));
for(i = 0; i < 16; i++)
for(i = 0x000; i < 0x1000; i++)
{
XColor color;
color.red = x11_palette[i * 3];
color.green = x11_palette[i * 3 + 1];
color.blue = x11_palette[i * 3 + 2];
color.red = ((i & 0xf00) >> 8) * 0x1111;
color.green = ((i & 0x0f0) >> 4) * 0x1111;
color.blue = (i & 0x00f) * 0x1111;
XAllocColor(kk->drv.p->dpy, colormap, &color);
kk->drv.p->colors[i] = color.pixel;
}

x11_winattr.backing_store = Always;
x11_winattr.background_pixel = kk->drv.p->colors[0];
x11_winattr.background_pixel = kk->drv.p->colors[0x000];
x11_winattr.event_mask = ExposureMask | StructureNotifyMask;

kk->drv.p->window =
@@ -176,7 +154,7 @@ static int x11_init_graphics(caca_t *kk)
XMapWindow(kk->drv.p->dpy, kk->drv.p->window);

kk->drv.p->gc = XCreateGC(kk->drv.p->dpy, kk->drv.p->window, 0, NULL);
XSetForeground(kk->drv.p->dpy, kk->drv.p->gc, kk->drv.p->colors[15]);
XSetForeground(kk->drv.p->dpy, kk->drv.p->gc, kk->drv.p->colors[0x888]);
XSetFont(kk->drv.p->dpy, kk->drv.p->gc, kk->drv.p->font);

for(;;)
@@ -258,15 +236,15 @@ static void x11_display(caca_t *kk)
for(x = 0; x < kk->qq->width; x += len)
{
uint32_t *attr = kk->qq->attr + x + y * kk->qq->width;
uint8_t bg = _cucul_argb32_to_ansi4bg(*attr);
uint16_t bg = _cucul_argb32_to_rgb12bg(*attr);

len = 1;
while(x + len < kk->qq->width
&& _cucul_argb32_to_ansi4bg(attr[len]) == bg)
&& _cucul_argb32_to_rgb12bg(attr[len]) == bg)
len++;

XSetForeground(kk->drv.p->dpy, kk->drv.p->gc,
kk->drv.p->colors[_cucul_argb32_to_ansi4bg(*attr)]);
kk->drv.p->colors[bg]);
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->gc,
x * kk->drv.p->font_width, y * kk->drv.p->font_height,
len * kk->drv.p->font_width, kk->drv.p->font_height);
@@ -289,7 +267,7 @@ static void x11_display(caca_t *kk)
continue;

XSetForeground(kk->drv.p->dpy, kk->drv.p->gc,
kk->drv.p->colors[_cucul_argb32_to_ansi4fg(*attr)]);
kk->drv.p->colors[_cucul_argb32_to_rgb12fg(*attr)]);

/* Plain ASCII, no problem. */
if(*chars > 0x00000020 && *chars < 0x00000080)


Ładowanie…
Anuluj
Zapisz