forked from uobikiemukot/recterm
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpseudo.c
131 lines (110 loc) · 4.35 KB
/
pseudo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2014 haru <uobikiemukot at gmail dot com>
* Copyright (C) 2014 Hayaki Saito <user@zuse.jp>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "yaft.h"
#include "util.h"
#include "pseudo.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#if !defined(HAVE_MEMCPY)
# define memcpy(d, s, n) (bcopy ((s), (d), (n)))
#endif
static void draw_sixel(struct pseudobuffer *pb, int line, int col, uint8_t *bitmap)
{
int h, w, src_offset, dst_offset;
uint32_t pixel, color = 0;
for (h = 0; h < CELL_HEIGHT; h++) {
for (w = 0; w < CELL_WIDTH; w++) {
src_offset = BYTES_PER_PIXEL * (h * CELL_WIDTH + w);
memcpy(&color, bitmap + src_offset, BYTES_PER_PIXEL);
dst_offset = (line * CELL_HEIGHT + h) * pb->line_length + (col * CELL_WIDTH + w) * pb->bytes_per_pixel;
//pixel = color2pixel(&pb->vinfo, color);
pixel = color;
memcpy(pb->buf + dst_offset, &pixel, pb->bytes_per_pixel);
}
}
}
static void draw_line(struct pseudobuffer *pb, struct terminal *term, int line)
{
int pos, bdf_padding, glyph_width, margin_right;
int col, w, h;
uint32_t pixel;
struct color_pair_t color_pair;
struct cell_t *cellp;
for (col = term->cols - 1; col >= 0; col--) {
margin_right = (term->cols - 1 - col) * CELL_WIDTH;
/* target cell */
cellp = &term->cells[col + line * term->cols];
/* draw sixel bitmap */
if (cellp->has_bitmap) {
draw_sixel(pb, line, col, cellp->bitmap);
continue;
}
/* copy current color_pair (maybe changed) */
color_pair = cellp->color_pair;
/* check wide character or not */
glyph_width = (cellp->width == HALF) ? CELL_WIDTH: CELL_WIDTH * 2;
bdf_padding = my_ceil(glyph_width, BITS_PER_BYTE) * BITS_PER_BYTE - glyph_width;
if (cellp->width == WIDE)
bdf_padding += CELL_WIDTH;
/* check cursor positon */
if ((term->mode & MODE_CURSOR && line == term->cursor.y)
&& (col == term->cursor.x
|| (cellp->width == WIDE && (col + 1) == term->cursor.x)
|| (cellp->width == NEXT_TO_WIDE && (col - 1) == term->cursor.x))) {
color_pair.fg = term->default_bg;
color_pair.bg = term->cursor_color;
}
for (h = 0; h < CELL_HEIGHT; h++) {
/* if UNDERLINE attribute on, swap bg/fg */
if ((h == (CELL_HEIGHT - 1)) && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
color_pair.bg = color_pair.fg;
for (w = 0; w < CELL_WIDTH; w++) {
pos = (term->width - 1 - margin_right - w) * pb->bytes_per_pixel
+ (line * CELL_HEIGHT + h) * pb->line_length;
/* set color palette */
if (cellp->glyphp->bitmap[h] & (0x01 << (bdf_padding + w)))
pixel = color_list[color_pair.fg];
else
pixel = color_list[color_pair.bg];
/* update copy buffer only */
memcpy(pb->buf + pos, &pixel, pb->bytes_per_pixel);
}
}
}
term->line_dirty[line] = ((term->mode & MODE_CURSOR) && term->cursor.y == line) ? true: false;
}
void refresh(struct pseudobuffer *pb, struct terminal *term)
{
int line;
if (term->mode & MODE_CURSOR)
term->line_dirty[term->cursor.y] = true;
for (line = 0; line < term->lines; line++) {
if (term->line_dirty[line])
draw_line(pb, term, line);
}
}
/* emacs Local Variables: */
/* emacs mode: c */
/* emacs tab-width: 4 */
/* emacs indent-tabs-mode: nil */
/* emacs c-basic-offset: 4 */
/* emacs End: */
/* vim: set expandtab ts=4 : */
/* EOF */