1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[line] union in place of struct (sixel)

Chars are accessible via ch.chars not chars as before.
This commit is contained in:
Witold Filipczyk 2023-05-18 11:12:05 +02:00
parent c1d954ab0a
commit ee29a8877b
10 changed files with 73 additions and 65 deletions

View File

@ -279,7 +279,7 @@ reset_document(struct document *document)
int pos;
for (pos = 0; pos < document->height; pos++)
mem_free_if(document->data[pos].chars);
mem_free_if(document->data[pos].ch.chars);
mem_free_set(&document->data, NULL);
document->height = 0;
@ -351,7 +351,7 @@ done_document(struct document *document)
int pos;
for (pos = 0; pos < document->height; pos++)
mem_free_if(document->data[pos].chars);
mem_free_if(document->data[pos].ch.chars);
mem_free(document->data);
}

View File

@ -32,11 +32,19 @@ struct node {
struct el_box box;
};
struct sixel {
char *pixels;
unsigned int width;
unsigned int height;
};
/** The document line consisting of the chars ready to be copied to
* the terminal screen. */
struct line {
struct screen_char *chars;
union {
struct screen_char *chars;
struct sixel *sixel;
} ch;
unsigned int length:30;
unsigned int kind:1;
};

View File

@ -84,17 +84,17 @@ realloc_line(struct document *document, int x, int y)
if (!line) return NULL;
if (x > line->length) {
if (!ALIGN_LINE(&line->chars, line->length, x))
if (!ALIGN_LINE(&line->ch.chars, line->length, x))
return NULL;
for (; line->length < x; line->length++) {
line->chars[line->length].data = ' ';
line->ch.chars[line->length].data = ' ';
}
if (x > document->width) document->width = x;
}
return line->chars;
return line->ch.chars;
}
static struct node *
@ -111,7 +111,7 @@ add_search_node(struct dom_renderer *renderer, int width)
return node;
}
#define POS(renderer) (&(renderer)->document->data[Y(renderer)].chars[X(renderer)])
#define POS(renderer) (&(renderer)->document->data[Y(renderer)].ch.chars[X(renderer)])
#define WIDTH(renderer, add) ((renderer)->canvas_x + (add))
static void

View File

@ -135,20 +135,20 @@ realloc_line(struct html_context *html_context, struct document *document,
if (length < orig_length)
return orig_length;
if (!ALIGN_LINE(&line->chars, line->length, length + 1))
if (!ALIGN_LINE(&line->ch.chars, line->length, length + 1))
return -1;
/* We cannot rely on the aligned allocation to clear the members for us
* since for line splitting we simply trim the length. Question is if
* it is better to to clear the line after the splitting or here. */
end = &line->chars[length];
end = &line->ch.chars[length];
end->data = ' ';
end->attr = 0;
set_screen_char_color(end, par_elformat.color.background, 0x0,
COLOR_ENSURE_CONTRAST, /* for bug 461 */
document->options.color_mode);
for (pos = &line->chars[line->length]; pos < end; pos++) {
for (pos = &line->ch.chars[line->length]; pos < end; pos++) {
copy_screen_chars(pos, end, 1);
}
@ -177,7 +177,7 @@ realloc_spaces(struct part *part, int length)
#define LINE(y_) part->document->data[Y(y_)]
#define POS(x_, y_) LINE(y_).chars[X(x_)]
#define POS(x_, y_) LINE(y_).ch.chars[X(x_)]
#define LEN(y_) int_max(LINE(y_).length - part->box.x, 0)
@ -470,7 +470,7 @@ put_combined(struct part *part, int x)
if (prev != UCS_NO_CHAR)
document->data[document->comb_y]
.chars[document->comb_x].data = prev;
.ch.chars[document->comb_x].data = prev;
}
document->combi_length = 0;
}
@ -2250,7 +2250,7 @@ color_link_lines(struct html_context *html_context)
int x;
for (x = 0; x < document->data[y].length; x++) {
struct screen_char *schar = &document->data[y].chars[x];
struct screen_char *schar = &document->data[y].ch.chars[x];
set_term_color(schar, &colors, color_flags, color_mode);
@ -2641,7 +2641,7 @@ render_html_document(struct cache_entry *cached, struct document *document,
/* Drop empty allocated lines at end of document if any
* and adjust document height. */
while (document->height && !document->data[document->height - 1].length)
mem_free_if(document->data[--document->height].chars);
mem_free_if(document->data[--document->height].ch.chars);
/* Calculate document width. */
{

View File

@ -67,13 +67,13 @@ realloc_line(struct document *document, int x, int y)
if (!line) return NULL;
if (x != line->length) {
if (!ALIGN_LINE(&line->chars, line->length, x))
if (!ALIGN_LINE(&line->ch.chars, line->length, x))
return NULL;
line->length = x;
}
return line->chars;
return line->ch.chars;
}
static inline struct link *
@ -859,20 +859,20 @@ fixup_tables(struct plain_renderer *renderer)
for (x = 0; x < line->length; x++) {
int dir;
#ifdef CONFIG_UTF8
unicode_val_T ch = line->chars[x].data;
unicode_val_T ch = line->ch.chars[x].data;
unicode_val_T prev_char, next_char, up_char, down_char;
#else
unsigned char ch = line->chars[x].data;
unsigned char ch = line->ch.chars[x].data;
unsigned char prev_char, next_char, up_char, down_char;
#endif
if (ch != '+' && ch != '-' && ch != '|') {
continue;
}
prev_char = x > 0 ? line->chars[x - 1].data : ' ';
next_char = x < line->length - 1 ? line->chars[x + 1].data : ' ';
up_char = (prev_line && x < prev_line->length) ? prev_line->chars[x].data : ' ';
down_char = (next_line && x < next_line->length) ? next_line->chars[x].data : ' ';
prev_char = x > 0 ? line->ch.chars[x - 1].data : ' ';
next_char = x < line->length - 1 ? line->ch.chars[x + 1].data : ' ';
up_char = (prev_line && x < prev_line->length) ? prev_line->ch.chars[x].data : ' ';
down_char = (next_line && x < next_line->length) ? next_line->ch.chars[x].data : ' ';
switch (ch) {
case '+':
@ -884,40 +884,40 @@ fixup_tables(struct plain_renderer *renderer)
switch (dir) {
case 15:
line->chars[x].data = BORDER_SCROSS;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SCROSS;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 13:
line->chars[x].data = BORDER_SLTEE;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SLTEE;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 7:
line->chars[x].data = BORDER_SRTEE;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SRTEE;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 6:
line->chars[x].data = BORDER_SULCORNER;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SULCORNER;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 12:
line->chars[x].data = BORDER_SURCORNER;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SURCORNER;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 3:
line->chars[x].data = BORDER_SDLCORNER;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SDLCORNER;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 9:
line->chars[x].data = BORDER_SDRCORNER;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SDRCORNER;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 11:
line->chars[x].data = BORDER_SUTEE;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SUTEE;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
case 14:
line->chars[x].data = BORDER_SDTEE;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SDTEE;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
break;
default:
break;
@ -927,8 +927,8 @@ fixup_tables(struct plain_renderer *renderer)
if (prev_char == BORDER_SHLINE || prev_char == BORDER_SCROSS || prev_char == '+' || prev_char == '|'
|| prev_char == BORDER_SULCORNER || prev_char == BORDER_SDLCORNER || prev_char == BORDER_SRTEE
|| prev_char == BORDER_SUTEE || prev_char == BORDER_SDTEE) {
line->chars[x].data = BORDER_SHLINE;
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].data = BORDER_SHLINE;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
}
break;
case '|':
@ -936,13 +936,13 @@ fixup_tables(struct plain_renderer *renderer)
|| up_char == BORDER_SURCORNER || up_char == BORDER_SCROSS || up_char == BORDER_SRTEE || up_char == BORDER_SLTEE
|| up_char == BORDER_SDTEE) {
if (next_char == '-') {
line->chars[x].data = BORDER_SRTEE;
line->ch.chars[x].data = BORDER_SRTEE;
} else if (prev_char == BORDER_SHLINE || prev_char == '-') {
line->chars[x].data = BORDER_SLTEE;
line->ch.chars[x].data = BORDER_SLTEE;
} else {
line->chars[x].data = BORDER_SVLINE;
line->ch.chars[x].data = BORDER_SVLINE;
}
line->chars[x].attr = SCREEN_ATTR_FRAME;
line->ch.chars[x].attr = SCREEN_ATTR_FRAME;
}
break;
default:

View File

@ -78,23 +78,23 @@ DUMP_FUNCTION_SPECIALIZED(struct document *document, struct dump_output *out)
unsigned char c;
#endif /* !DUMP_CHARSET_UTF8 */
const unsigned char attr
= document->data[y].chars[x].attr;
= document->data[y].ch.chars[x].attr;
#ifdef DUMP_COLOR_MODE_16
const unsigned char color1
= document->data[y].chars[x].c.color[0];
= document->data[y].ch.chars[x].c.color[0];
#elif defined(DUMP_COLOR_MODE_256)
const unsigned char color1
= document->data[y].chars[x].c.color[0];
= document->data[y].ch.chars[x].c.color[0];
const unsigned char color2
= document->data[y].chars[x].c.color[1];
= document->data[y].ch.chars[x].c.color[1];
#elif defined(DUMP_COLOR_MODE_TRUE)
const unsigned char *const new_foreground
= &document->data[y].chars[x].c.color[0];
= &document->data[y].ch.chars[x].c.color[0];
const unsigned char *const new_background
= &document->data[y].chars[x].c.color[3];
= &document->data[y].ch.chars[x].c.color[3];
#endif /* DUMP_COLOR_MODE_TRUE */
c = document->data[y].chars[x].data;
c = document->data[y].ch.chars[x].data;
#ifdef DUMP_CHARSET_UTF8
if (c == UCS_NO_CHAR) {

View File

@ -422,19 +422,19 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
if (en - st > 0) {
draw_line(term, box->x + st - vx, box->y + y - vy,
en - st,
&doc_view->document->data[y].chars[st]);
&doc_view->document->data[y].ch.chars[st]);
for (i = en - 1; i >= 0; --i) {
if (doc_view->document->data[y].chars[i].data != ' ') {
last = &doc_view->document->data[y].chars[i];
if (doc_view->document->data[y].ch.chars[i].data != ' ') {
last = &doc_view->document->data[y].ch.chars[i];
last_index = i + 1;
break;
}
}
}
for (i = st; i < max; i++) {
if (doc_view->document->data[y].chars[i].data != ' ') {
first = &doc_view->document->data[y].chars[i];
if (doc_view->document->data[y].ch.chars[i].data != ' ') {
first = &doc_view->document->data[y].ch.chars[i];
break;
}
}

View File

@ -346,7 +346,7 @@ draw_link(struct terminal *term, struct document_view *doc_view,
struct screen_char *ch;
ch = get_char(term, x + xpos, y + ypos);
copy_struct(ch, &doc_view->document->data[y].chars[x]);
copy_struct(ch, &doc_view->document->data[y].ch.chars[x]);
set_screen_dirty(term->screen, y + ypos, y + ypos);
}
}

View File

@ -160,15 +160,15 @@ get_srch(struct document *document)
document->data[y].length);
for (x = node->box.x;
x < width && document->data[y].chars[x].data <= ' ';
x < width && document->data[y].ch.chars[x].data <= ' ';
x++);
for (; x < width; x++) {
UCHAR c = document->data[y].chars[x].data;
UCHAR c = document->data[y].ch.chars[x].data;
int count = 0;
int xx;
if (document->data[y].chars[x].attr & SCREEN_ATTR_UNSEARCHABLE)
if (document->data[y].ch.chars[x].attr & SCREEN_ATTR_UNSEARCHABLE)
continue;
#ifdef CONFIG_UTF8
@ -187,7 +187,7 @@ get_srch(struct document *document)
}
for (xx = x + 1; xx < width; xx++) {
if ((unsigned char)document->data[y].chars[xx].data < ' ')
if ((unsigned char)document->data[y].ch.chars[xx].data < ' ')
continue;
count = xx - x;
break;
@ -1536,7 +1536,7 @@ static inline UCHAR
get_document_char(struct document *document, int x, int y)
{
return (document->height > y && document->data[y].length > x)
? document->data[y].chars[x].data : 0;
? document->data[y].ch.chars[x].data : 0;
}
static void

View File

@ -1049,7 +1049,7 @@ copy_to_clipboard2(struct document_view *doc_view)
#else
unsigned char c;
#endif
c = document->data[y].chars[x].data;
c = document->data[y].ch.chars[x].data;
#ifdef CONFIG_UTF8
if (utf8 && c == UCS_NO_CHAR) {