Selaa lähdekoodia

* src/graphics.c: cleaned caca_get_html()

tags/v0.99.beta14
Sam Hocevar sam 19 vuotta sitten
vanhempi
commit
1f699f7923
1 muutettua tiedostoa jossa 82 lisäystä ja 116 poistoa
  1. +82
    -116
      src/graphics.c

+ 82
- 116
src/graphics.c Näytä tiedosto

@@ -1801,94 +1801,61 @@ static int const html_palette[] =
*/
char* caca_get_html(void)
{
char *buffer;
unsigned int x,y;
int f,b;
/* 13000 -> css palette
40 -> max size used for a pixel (plus 10, never know)*/
buffer = malloc((13000 + ((_caca_width*_caca_height)*40))*sizeof(char));
/* HTML header */
sprintf(buffer, "<html>\n<head>\n<title>Generated by libcaca "VERSION"</title>\n");
/* CSS */
sprintf(buffer, "%s<style>\n", buffer);
sprintf(buffer, "%s.caca { font-family: monospace, fixed; font-weight: bold; }\n", buffer);
for(f=0;f<0x0f+1;f++)
char *buffer, *cur;
unsigned int x, y, len;
/* 13000 -> css palette
* 40 -> max size used for a pixel (plus 10, never know)*/
/* FIXME: Check this value */
buffer = malloc((13000 + ((_caca_width*_caca_height) * 40)) * sizeof(char));
cur = buffer;
/* HTML header */
cur += sprintf(cur, "<html>\n<head>\n<title>Generated by libcaca %s</title>\n", VERSION);
/* CSS */
cur += sprintf(cur, "<style>\n");
cur += sprintf(cur, ".caca { font-family: monospace, fixed; font-weight: bold; }");
for(x = 0; x < 0x100; x++)
{
for(b=0;b<0x0f+1;b++)
{
sprintf(buffer,
"%s.b%x%x { color:#%03x; background-color:#%03x;}\n",buffer,
b, f, html_palette[f], html_palette[b]);

}
cur += sprintf(cur, ".b%02x { color:#%03x; background-color:#%03x; }\n",
x, html_palette[x & 0xf ], html_palette[x >> 4]);
}
sprintf(buffer, "%s</style>\n</head>\n<body>\n",buffer);
cur += sprintf(cur, "</style>\n</head>\n<body>\n");

/* Table */
sprintf(buffer, "%s<table class='caca' cols='%d' cellpadding='0' cellspacing='0'>\n", buffer,caca_get_height());
cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
"font-family: monospace, fixed; font-weight: bold;");

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

for(x=0;x<_caca_width;x++)
for(x = 0; x < _caca_width; x += len)
{
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 class=b%x%x>%c</td>",buffer,
cache_attr[x+y*caca_get_width()]>>4,
cache_attr[x+y*caca_get_width()]&0x0f,
cache_char[x+y*caca_get_width()]);
}
else
uint8_t *cur_attr = cache_attr + y * _caca_width;
uint8_t *cur_char = cache_char + y * _caca_width;

cur += sprintf(cur, "<span class='b%02x'>", cur_attr[x]);

for(len = 0;
x + len < _caca_width && cur_attr[x + len] == cur_attr[x];
len++)
{
sprintf(buffer,
"%s<td class=b%x%x colspan=%d>",buffer,
cache_attr[x+y*caca_get_width()]>> 4,
cache_attr[x+y*caca_get_width()]&0x0f,
len+1);
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</td>",buffer);
if(cur_char[x + len] == ' ')
cur += sprintf(cur, "&nbsp;");
else
cur += sprintf(cur, "%c", cur_char[x + len]);
}
cur += sprintf(cur, "</span>");
}
sprintf(buffer, "%s</tr>\n",buffer);
/* New line */
cur += sprintf(cur, "<br />\n");
}

/* Footer */
sprintf(buffer, "%s</table>\n</body>\n</html>\n",buffer);
cur += sprintf(cur, "</div></body></html>\n");

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

return buffer;
return buffer;
}

/** \brief Generate HTML3 representation of current image.
@@ -1900,52 +1867,51 @@ char* caca_get_html(void)
*/
char* caca_get_html3(void)
{
char *buffer, *cur;
unsigned int x, y, len;
char *buffer, *cur;
unsigned int x, y, len;

/* 13000 -> css palette
* 40 -> max size used for a pixel (plus 10, never know)*/
/* FIXME: Check this value */
buffer = malloc((13000 + ((_caca_width*_caca_height) * 40)) * sizeof(char));
cur = buffer;
/* 13000 -> css palette
* 40 -> max size used for a pixel (plus 10, never know)*/
/* FIXME: Check this value */
buffer = malloc((13000 + ((_caca_width*_caca_height) * 40)) * sizeof(char));
cur = buffer;

/* Table */
cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
"font-family: monospace, fixed; font-weight: bold;");
cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
"font-family: monospace, fixed; font-weight: bold;");

for(y = 0; y < _caca_height; y++)
{
for(x = 0; x < _caca_width; x += len)
{
uint8_t *cur_attr = cache_attr + y * _caca_width;
uint8_t *cur_char = cache_char + y * _caca_width;

cur += sprintf(cur,
"<span style=\"color: #%03X; background-color: #%03X\">",
html_palette[cur_attr[x] & 0x0f],
html_palette[cur_attr[x] >> 4]);

for(len = 0;
x + len < _caca_width && cur_attr[x + len] == cur_attr[x];
len++)
{
if(cur_char[x + len] == ' ')
cur += sprintf(cur, "&nbsp;");
else
cur += sprintf(cur, "%c", cur_char[x + len]);
}
cur += sprintf(cur, "</span>");
}
cur += sprintf(cur, "<br />\n");
}

/* Footer */
cur += sprintf(cur, "</div>\n");
for(y = 0; y < _caca_height; y++)
{
for(x = 0; x < _caca_width; x += len)
{
uint8_t *cur_attr = cache_attr + y * _caca_width;
uint8_t *cur_char = cache_char + y * _caca_width;

/* Crop to really used size */
buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
cur += sprintf(cur,
"<span style=\"color: #%03X; background-color: #%03X\">",
html_palette[cur_attr[x] & 0x0f],
html_palette[cur_attr[x] >> 4]);

return buffer;
for(len = 0;
x + len < _caca_width && cur_attr[x + len] == cur_attr[x];
len++)
{
if(cur_char[x + len] == ' ')
cur += sprintf(cur, "&nbsp;");
else
cur += sprintf(cur, "%c", cur_char[x + len]);
}
cur += sprintf(cur, "</span>");
}
/* New line */
cur += sprintf(cur, "<br />\n");
}

cur += sprintf(cur, "</div>\n");

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

return buffer;
}

static int const irc_palette[] =


Ladataan…
Peruuta
Tallenna