Browse Source

* Added Null driver and html3 exporter.

tags/v0.99.beta14
Jean-Yves Lamoureux jylam 19 years ago
parent
commit
1715754261
6 changed files with 178 additions and 1 deletions
  1. +8
    -0
      configure.ac
  2. +27
    -0
      src/caca.c
  3. +2
    -0
      src/caca.h
  4. +3
    -0
      src/caca_internals.h
  5. +7
    -0
      src/event.c
  6. +131
    -1
      src/graphics.c

+ 8
- 0
configure.ac View File

@@ -37,6 +37,8 @@ AC_ARG_ENABLE(x11,
[ --enable-x11 X11 support (autodetected)])
AC_ARG_ENABLE(gl,
[ --enable-gl OpenGL support (autodetected)])
AC_ARG_ENABLE(null,
[ --enable-null Null driver support (autodetected)])

dnl example programs features
AC_ARG_ENABLE(imlib2,
@@ -138,6 +140,12 @@ if test "${enable_gl}" != "no"; then
fi
fi

if test "${enable_null}" != "no"; then
ac_cv_my_have_null="yes"
AC_DEFINE(USE_NULL, 1, Define to activate the Null backend driver)
CACA_DRIVERS="${CACA_DRIVERS} null"
fi

if test "${enable_ncurses}" != "no"; then
ac_cv_my_have_ncurses="no"
AC_CHECK_HEADERS(curses.h ncurses.h,


+ 27
- 0
src/caca.c View File

@@ -203,6 +203,13 @@ int caca_init(void)
/* Nothing to do */
}
else
#endif
#if defined(USE_NULL)
if(_caca_driver == CACA_DRIVER_NULL)
{
/* Nothing to do */
}
else
#endif
{
/* Dummy */
@@ -441,6 +448,13 @@ void caca_end(void)
/* Nothing to do */
}
else
#endif
#if defined(USE_NULL)
if(_caca_driver == CACA_DRIVER_NULL)
{
/* Nothing to do */
}
else
#endif
{
/* Dummy */
@@ -489,6 +503,14 @@ static void caca_init_driver(void)
_caca_driver = CACA_DRIVER_NCURSES;
else
#endif
#if defined(USE_NULL)
if(!strcasecmp(var, "null"))
{
_caca_driver = CACA_DRIVER_NULL;
}
else
#endif

_caca_driver = CACA_DRIVER_NONE;

return;
@@ -524,6 +546,11 @@ static void caca_init_driver(void)
_caca_driver = CACA_DRIVER_NCURSES;
return;
#endif
#if defined(USE_NULL)
_caca_driver = CACA_DRIVER_NULL;
return;
#endif

_caca_driver = CACA_DRIVER_NONE;
return;
}


+ 2
- 0
src/caca.h View File

@@ -63,6 +63,7 @@
* - \c slang uses the S-Lang library.
* - \c x11 uses the native X11 driver.
* - \c gl uses freeglut and opengl libraries.
* - \c null uses nothing at all, and will display nothing as well.
*
* \li \b CACA_GEOMETRY: set the video display size. The format of this
* variable must be XxY, with X and Y being integer values. This option
@@ -360,6 +361,7 @@ void caca_free_bitmap(struct caca_bitmap *);
*
* @{ */
char* caca_get_html(void);
char* caca_get_html3(void);
char* caca_get_irc(void);
/* @} */



+ 3
- 0
src/caca_internals.h View File

@@ -50,6 +50,9 @@ enum caca_driver
#endif
#if defined(USE_GL)
CACA_DRIVER_GL = 6,
#endif
#if defined(USE_NULL)
CACA_DRIVER_NULL = 7,
#endif
CACA_DRIVER_NONE = 0
};


+ 7
- 0
src/event.c View File

@@ -194,6 +194,13 @@ static unsigned int _get_next_event(void)
static unsigned int last_key = 0;
unsigned int ticks;
#endif
#if defined(USE_NULL)
{
if(_caca_driver == CACA_DRIVER_NULL)
return CACA_EVENT_NONE;
}
#endif

unsigned int event = _lowlevel_event();

#if defined(USE_SLANG)


+ 131
- 1
src/graphics.c View File

@@ -402,6 +402,11 @@ void caca_set_color(enum caca_color fgcolor, enum caca_color bgcolor)
case CACA_DRIVER_GL:
/* Nothing to do */
break;
#endif
#if defined(USE_NULL)
case CACA_DRIVER_NULL:
/* Nothing to do */
break;
#endif
default:
break;
@@ -491,6 +496,10 @@ void caca_putchar(int x, int y, char c)
#if defined(USE_GL)
case CACA_DRIVER_GL:
break;
#endif
#if defined(USE_NULL)
case CACA_DRIVER_NULL:
break;
#endif
default:
break;
@@ -590,6 +599,10 @@ void caca_putstr(int x, int y, char const *s)
#if defined(USE_GL)
case CACA_DRIVER_GL:
break;
#endif
#if defined(USE_NULL)
case CACA_DRIVER_NULL:
break;
#endif
default:
break;
@@ -1047,7 +1060,19 @@ int _caca_init_graphics(void)
}
else
#endif

#if defined(USE_NULL)
if(_caca_driver == CACA_DRIVER_NULL)
{
if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY")))
sscanf(getenv("CACA_GEOMETRY"),
"%ux%u", &_caca_width, &_caca_height);
if(!_caca_width)
_caca_width = 80;
if(!_caca_height)
_caca_height = 32;
}
else
#endif
{
/* Dummy */
}
@@ -1128,6 +1153,15 @@ int _caca_end_graphics(void)
glutDestroyWindow(gl_window);
}
else
#endif
#if defined(USE_NULL)
if(_caca_driver == CACA_DRIVER_NULL)
{
/* I'm bored to write 'nothing to do'.
* So I don't.
*/
}
else
#endif
{
/* Dummy */
@@ -1508,6 +1542,12 @@ void caca_refresh(void)
glutPostRedisplay();
}
else
#endif
#if defined(USE_NULL)
if(_caca_driver == CACA_DRIVER_NULL)
{
/* Do I told you about my cat ? */
}
#endif
{
/* Dummy */
@@ -1629,6 +1669,15 @@ static void caca_handle_resize(void)

}
else
#endif
#if defined(USE_NULL)
if(_caca_driver == CACA_DRIVER_NULL)
{
/* \_o< pOaK */
/* By the way, we should never reach this,
* as events are not handled
*/
}
#endif
{
/* Dummy */
@@ -1842,6 +1891,87 @@ char* caca_get_html(void)
return buffer;
}

/** \brief Generate HTML3 representation of current image.
*
* This function generates and returns the HTML3 representation of
* the current image. It is way bigger than caca_get_html(), but
* permits viewing in old browsers (or limited ones such as links)
*
*/
char* caca_get_html3(void)
{
char *buffer;
unsigned int x,y;

/* 13000 -> css palette
40 -> max size used for a pixel (plus 10, never know)*/

buffer = malloc((13000 + ((_caca_width*_caca_height)*40))*sizeof(char));

/* Table */
sprintf(buffer, "<table cols='%d' cellpadding='0' cellspacing='0'>\n", caca_get_height());

for(y=0;y<_caca_height;y++)
{
sprintf(buffer,
"%s<tr>",buffer);

for(x=0;x<_caca_width;x++)
{
int len;
int i;
uint8_t *attr = cache_attr + x + y * _caca_width;

/* Use colspan option to factorize cells with same attributes
(see below) */
len=1;
while(x + len < _caca_width
&& (attr[len]>>4) == (attr[0]>>4) &&
(attr[len]&0x0f) == (attr[0]&0x0f))
len++;
if(len==1)
{
sprintf(buffer,
"%s<td bgcolor=#%06X ><font color='#%06X'>%c</font></td>", buffer,
html_palette[cache_attr[x+y*caca_get_width()]>>4],
html_palette[cache_attr[x+y*caca_get_width()]&0x0f],
cache_char[x+y*caca_get_width()]);
}
else
{
sprintf(buffer,
"%s<td bgcolor=#%06X colspan=%d><font color='#%06X'>",buffer,
html_palette[cache_attr[x+y*caca_get_width()]>> 4],
len+1,
html_palette[cache_attr[x+y*caca_get_width()]&0x0f]);
for(i=0;i<len;i++)
{
if(cache_char[x+y*caca_get_width()]!=' ')
sprintf(buffer, "%s%c", buffer, cache_char[x+y*caca_get_width()]);
else
sprintf(buffer, "%s&nbsp;", buffer);
x++;
}
sprintf(buffer, "%s</font></td>", buffer);
}

}
sprintf(buffer, "%s</tr>\n",buffer);
}

/* Footer */
sprintf(buffer, "%s</table>\n",buffer);

/* Crop to really used size */
buffer = realloc(buffer, (strlen(buffer)+1) * sizeof(char));

return buffer;
}


static int const irc_palette[] =
{


Loading…
Cancel
Save