Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Compare Revisions
fe022fecc758985541b9c457de948af082db1c93...59053de5e06c260d968f7b5f0df23c8abf209fca
Commits (2)
Optimize pixel calculations.
· 2e41ce25
Deucе
authored
May 04, 2021
2e41ce25
Make some changes
· 59053de5
Deucе
authored
May 04, 2021
Mostly tightening things up and fixed some text things.
59053de5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
175 additions
and
64 deletions
+175
-64
src/conio/x_events.c
src/conio/x_events.c
+23
-19
src/syncterm/ripper.c
src/syncterm/ripper.c
+152
-45
No files found.
src/conio/x_events.c
View file @
59053de5
...
...
@@ -456,6 +456,7 @@ static void local_draw_rect(struct rectlist *rect)
int
ctop
=
rect
->
rect
.
height
;
int
cbottom
=
-
1
;
int
idx
;
uint32_t
last_pixel
=
0x55555555
;
if
(
bitmap_width
!=
cleft
||
bitmap_height
!=
ctop
)
return
;
...
...
@@ -487,8 +488,8 @@ static void local_draw_rect(struct rectlist *rect)
continue
;
}
}
for
(
yscale
=
0
;
yscale
<
x_cvstat
.
scaling
*
x_cvstat
.
vmultiplier
;
yscale
++
)
{
for
(
xscale
=
0
;
xscale
<
x_cvstat
.
scaling
;
xscale
++
)
{
if
(
last_pixel
!=
rect
->
data
[
idx
]
)
{
last_pixel
=
rect
->
data
[
idx
];
r
=
rect
->
data
[
idx
]
>>
16
&
0xff
;
g
=
rect
->
data
[
idx
]
>>
8
&
0xff
;
b
=
rect
->
data
[
idx
]
&
0xff
;
...
...
@@ -508,6 +509,9 @@ static void local_draw_rect(struct rectlist *rect)
pixel
|=
(
b
<<
b_shift
)
&
visual
.
blue_mask
;
else
pixel
|=
(
b
>>
(
0
-
b_shift
))
&
visual
.
blue_mask
;
}
for
(
yscale
=
0
;
yscale
<
x_cvstat
.
scaling
*
x_cvstat
.
vmultiplier
;
yscale
++
)
{
for
(
xscale
=
0
;
xscale
<
x_cvstat
.
scaling
;
xscale
++
)
{
#ifdef XPutPixel
XPutPixel
(
xim
,(
x
+
rect
->
rect
.
x
)
*
x_cvstat
.
scaling
+
xscale
,(
y
+
rect
->
rect
.
y
)
*
x_cvstat
.
scaling
*
x_cvstat
.
vmultiplier
+
yscale
,
pixel
);
#else
...
...
src/syncterm/ripper.c
View file @
59053de5
...
...
@@ -268,6 +268,9 @@ static struct {
int clipx;
int clipy;
struct mouse_field *saved_mfields;
struct {
int sx, sy, ex, ey, xpos, ypos;
} text_region;
} rip = {
RIP_STATE_BOL,
RIP_STATE_FLUSHING,
...
...
@@ -301,6 +304,8 @@ static struct {
false,
ANSI_STATE_NONE,
0, 0,
NULL,
{0, 0, 0, 0, 0, 0},
};
static const uint16_t rip_line_patterns[4] = {
...
...
@@ -7752,6 +7757,13 @@ map_rip_x(int x)
{
int i;
if (x < 0 || x >= rip.x_dim) {
double dx = x;
dx *= rip.x_max;
dx /= rip.x_dim;
return roundl(dx);
}
if (rip.xmap == NULL) {
rip.xmap = malloc(rip.x_dim * sizeof(int));
if (rip.xmap == NULL) {
...
...
@@ -7773,6 +7785,13 @@ map_rip_y(int y)
{
int i;
if (y < 0 || y >= rip.y_dim) {
double dy = y;
dy *= rip.y_max;
dy /= rip.y_dim;
return roundl(dy);
}
if (rip.ymap == NULL) {
rip.ymap = malloc(rip.y_dim * sizeof(int));
if (rip.ymap == NULL) {
...
...
@@ -8056,7 +8075,7 @@ buffer_data(const BYTE *buf, unsigned len)
static int
next_char(const char *buf, size_t *pos)
{
if
(buf[*pos] == '\\') {
while
(buf[*pos] == '\\') {
(*pos)++;
if (buf[*pos] == '\r') {
(*pos)++;
...
...
@@ -8065,7 +8084,11 @@ next_char(const char *buf, size_t *pos)
}
else if (buf[*pos] == '\n')
(*pos)++;
else
return (uint8_t)buf[*pos];
}
if (buf[*pos] == '!')
return -1;
else if (buf[*pos] == '|')
return -1;
else if (buf[*pos] == '\r')
...
...
@@ -8249,6 +8272,17 @@ char_top_bottom(char ch, int *top, int *bottom)
}
}
static int
font_height()
{
int mult = stroke_mults[rip.font.size];
int div = stroke_divs[rip.font.size];
if (rip.font.num == 0)
return 8 * rip.font.size;
return (((char)rip_fonts[rip.font.num - 1][0x88]) - ((char)rip_fonts[rip.font.num - 1][0x8a])) * mult / div;
}
static void
write_char(char ch)
{
...
...
@@ -8289,7 +8323,7 @@ write_char(char ch)
if (this_font[fontoffset] & (0x80 >> x)) {
// NOTE: Bitmap fonts don't use write mode...
//draw_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys);
set_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys,
ega
_colo
urs[
rip.color
]
);
set_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys,
map_rip
_colo
r(
rip.color
)
);
}
}
}
...
...
@@ -8766,14 +8800,14 @@ draw_button(struct rip_button_style *but, bool inverted)
cc = ega_colours[0x0f ^ but->ccorner];
}
else {
fg =
ega
_colo
urs[
but->cfore
]
;
fg =
map_rip
_colo
r(
but->cfore
)
;
bg = ega_colours[0];
ds =
ega
_colo
urs[
but->cdshadow
]
;
ch =
ega
_colo
urs[
but->chighlight
]
;
cs =
ega
_colo
urs[
but->cshadow
]
;
su =
ega
_colo
urs[
but->csurface
]
;
ul =
ega
_colo
urs[
but->culine
]
;
cc =
ega
_colo
urs[
but->ccorner
]
;
ds =
map_rip
_colo
r(
but->cdshadow
)
;
ch =
map_rip
_colo
r(
but->chighlight
)
;
cs =
map_rip
_colo
r(
but->cshadow
)
;
su =
map_rip
_colo
r(
but->csurface
)
;
ul =
map_rip
_colo
r(
but->culine
)
;
cc =
map_rip
_colo
r(
but->ccorner
)
;
}
ox = but->box.x1;
...
...
@@ -9592,7 +9626,7 @@ draw_ellipse(int x1, int y1, int arg1, int arg2, int x2, int y2)
y1 - nearbyint(sin((M_PI / 180.0) * arg3) * y2),
x1 + nearbyint(cos((1.0 + arg3) * (M_PI / 180.0)) * x2),
y1 - nearbyint(sin((1.0 + arg3) * (M_PI / 180.0)) * y2),
ega
_colo
urs[
rip.color
]
, 0xffff, rip.line_width);
map_rip
_colo
r(
rip.color
)
, 0xffff, rip.line_width);
}
}
...
...
@@ -10023,10 +10057,16 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
GET_XY2();
arg1 = parse_mega(&args[8], 2);
pthread_mutex_lock(&vstatlock);
arg3 = ceil((arg1 * vstat.scrnheight) / (((double)(vstat.scrnwidth)) * 3 / 4));
if (vstat.scale_numerator == 729 && vstat.scale_denominator == 1000) {
// Detect EGA mode and use the same value as RIPterm did.
arg3 = (arg1 * 7750 / 10000);
}
else {
arg3 = arg1 * vstat.scale_numerator / vstat.scale_denominator;
}
pthread_mutex_unlock(&vstatlock);
if (abs(arg3 - arg1) == 360)
full_ellipse(x1, y
2
, x2, y2, false);
full_ellipse(x1, y
1
, x2, y2, false);
else
draw_ellipse(x1, y1, x2, y2, arg1, arg3);
break;
...
...
@@ -10134,9 +10174,9 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
struct ciolib_pixels *pix = getpixels(rip.viewport.sx, rip.viewport.sy, rip.viewport.ex, arg2, false);
FREE_AND_NULL(pix->pixelsb);
// Blammo goes the stack!
fg =
ega
_colo
urs[
arg1
]
;
fg =
map_rip
_colo
r(
arg1
)
;
uint32_t ffg, fbg;
ffg =
ega
_colo
urs[
rip.fill_color
]
;
ffg =
map_rip
_colo
r(
rip.fill_color
)
;
fbg = ega_colours[0];
if (x1 < pix->width && y1 < pix->height)
broken_flood_fill(pix, x1, y1, fg, ffg, fbg, rip.fill_color == 0, y1);
...
...
@@ -10165,6 +10205,27 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
* current drawing color and line thickness. The Line Pattern feature
* does not apply to this command.
*/
handled = true;
if (no_viewport())
break;
GET_XY2();
arg1 = parse_mega(&args[8], 2);
pthread_mutex_lock(&vstatlock);
if (vstat.scale_numerator == 729 && vstat.scale_denominator == 1000) {
// Detect EGA mode and use the same value as RIPterm did.
arg3 = (arg1 * 7750 / 10000);
}
else {
arg3 = arg1 * vstat.scale_numerator / vstat.scale_denominator;
}
pthread_mutex_unlock(&vstatlock);
if (abs(arg3 - arg1) == 360)
full_ellipse(x1, y1, x2, y2, false);
else
draw_ellipse(x1, y1, x2, y2, arg1, arg3);
draw_line(x1, y1, x1 + nearbyint(cos(M_PI / 180.0) * arg1) * x2, y1 + nearbyint(sin(M_PI / 180.0) * arg1) * y2);
draw_line(x1, y1, x1 + nearbyint(cos(M_PI / 180.0) * arg3) * x2, y1 + nearbyint(sin(M_PI / 180.0) * arg3) * y2);
puts("TODO: Needs to fill...");
break;
case 'L': // RIP_LINE !|L <x0> <y0> <x1> <y1>
/* This command will draw a line in the current drawing color, using the
...
...
@@ -10249,7 +10310,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
handled = true;
if (no_viewport())
break;
fg =
ega
_colo
urs[
rip.color
]
;
fg =
map_rip
_colo
r(
rip.color
)
;
arg1 = parse_mega(&args[0], 2);
for (i = 0; i < arg1; i++) {
if (i == 0) {
...
...
@@ -10407,7 +10468,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
if (no_viewport())
break;
GET_XY();
set_pixel(x1, y1,
ega
_colo
urs[
rip.color
]
);
set_pixel(x1, y1,
map_rip
_colo
r(
rip.color
)
);
break;
case 'Y': // RIP_FONT_STYLE !|Y <font> <direction> <size> <res>
/*
...
...
@@ -10561,6 +10622,8 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
curr_ega_palette[arg1] = arg2;
attr2palette(arg1, &fg, NULL);
setpalette(fg, ega_palette[arg2][0], ega_palette[arg2][1], ega_palette[arg2][2]);
// TODO: Extended palette.
if (arg1 < 16)
ega_colours[arg1] = fg;
break;
case 'c': // RIP_COLOR !|c <color>
...
...
@@ -10647,7 +10710,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
arg2 += 360;
// TODO: Use 'o' command ellipse when possible...
puts("TODO: Needs to fill...");
fg =
ega
_colo
urs[
rip.color
]
;
fg =
map_rip
_colo
r(
rip.color
)
;
set_line(x1, y1, x1 + (x2 * cos(arg1 * (M_PI / 180.0))),
y1 - (y2 * sin(arg1 * (M_PI / 180.0))), fg, 0xffff, rip.line_width);
for (arg3 = arg1; arg3 < arg2; arg3++) {
...
...
@@ -12082,7 +12145,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
co |= (((planes[(row * 2) + (j / 8)] >> (7 - (j & 7))) & 1) << 1);
co |= (((planes[(row * 1) + (j / 8)] >> (7 - (j & 7))) & 1) << 2);
co |= (((planes[(row * 0) + (j / 8)] >> (7 - (j & 7))) & 1) << 3);
*(op++) =
ega
_colo
urs[
co
]
;
*(op++) =
map_rip
_colo
r(
co
)
;
}
}
if (pix) {
...
...
@@ -12339,7 +12402,14 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
* NOTE: The "res" parameter is two bytes wide and is RESERVED for
* future use.
*/
// TODO: Justify things.
handled = true;
GET_XY2();
rip.text_region.sx = x1;
rip.text_region.sy = y1;
rip.text_region.ex = x2;
rip.text_region.ey = y2;
rip.text_region.xpos = 0;
rip.text_region.ypos = 0;
break;
case 't': // RIP_REGION_TEXT !|1t <justify> <text-string>
/* A number of these commands may come sandwiched between the
...
...
@@ -12375,6 +12445,36 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
* formatted text block.
*/
// TODO: The things that are justified...
handled = true;
arg1 = parse_mega(&args[0], 1);
if (arg1) {
printf("TODO: Justify %d\n", arg1);
}
{
int oldsx = rip.viewport.sx;
int oldsy = rip.viewport.sy;
int oldex = rip.viewport.ex;
int oldey = rip.viewport.ey;
int oldx = rip.x;
int oldy = rip.y;
rip.viewport.sx = rip.text_region.sx;
rip.viewport.sy = rip.text_region.sy;
rip.viewport.ex = rip.text_region.ex;
rip.viewport.ey = rip.text_region.ey;
rip.x = rip.text_region.xpos;
rip.y = rip.text_region.ypos;
write_text(&args[1]);
rip.text_region.ypos += font_height();
rip.viewport.sx = oldsx;
rip.viewport.sy = oldsy;
rip.viewport.ex = oldex;
rip.viewport.ey = oldey;
rip.x = oldx;
rip.y = oldy;
}
break;
case 'U': // RIP_BUTTON !|1U <x0> <y0> <x1> <y1> <hotkey> <flags> <res> <text>
/* This command physically creates a new Button using the previously
...
...
@@ -12658,16 +12758,17 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
}
break;
}
free(args);
if (!handled) {
printf("Unhandled command: Level: %d, SubLevel: %d, cmd: %d, args: %s\n", level, sublevel, cmd, args);
fflush(stdout);
}
free(args);
}
static void
do_rip_string(const char *buf, size_t len)
{
enum do_states rs = NEED_BANG; // Reset state...
enum do_states ds = NEED_BANG;
int ch;
size_t pos;
...
...
@@ -12680,54 +12781,56 @@ do_rip_string(const char *buf, size_t len)
switch (ds) {
case NEED_BANG:
ch = next_char(buf, &pos);
if (ch == '!' || ch == '\x01' || ch == '\x02')
if
(
(ch ==
-1 && buf[pos] ==
'!'
)
|| ch == '\x01' || ch == '\x02')
ds = NEED_PIPE;
break;
case NEED_PIPE:
if (next_char(buf, &pos) == -1) {
if (next_char(buf, &pos) == -1
&& buf[pos] == '|'
) {
level = 0;
sublevel = 0;
cmd = -1;
ds = NEED_LEVEL;
break;
}
ds = rs;
break;
case NEED_LEVEL:
ch = next_char(buf, &pos);
if (ch == -1)
break;
if (ch >= '1' && ch <= '9') {
level = ch - '0';
ds = NEED_SUBLEVEL;
break;
}
else if (ch == -1) {
ds = rs;
break;
}
else {
level = 0;
sublevel = 0;
cmd = ch;
arg_start = 0;
ds = ARGUMENTS;
}
break;
case NEED_SUBLEVEL:
ch = next_char(buf, &pos);
if (ch == -1) {
ds = NEED_LEVEL;
break;
}
if (ch >= '1' && ch <= '9') {
sublevel = ch - '0';
ds = NEED_COMMAND;
break;
}
else if (ch == -1) {
ds = rs;
break;
}
else {
sublevel = 0;
cmd = ch;
arg_start = 0;
ds = ARGUMENTS;
}
break;
case NEED_COMMAND:
ch = next_char(buf, &pos);
if (ch == -1) {
ds =
NEED_LEVEL
;
ds =
rs
;
break;
}
cmd = ch;
...
...
@@ -12738,9 +12841,13 @@ do_rip_string(const char *buf, size_t len)
ch = next_char(buf, &pos);
if (arg_start == 0)
arg_start = pos;
if (ch == -1 || ch == '
\r
') {
if (ch == -1 || ch == '
!' || ch == '|
') {
do_rip_command(level, sublevel, cmd, &buf[arg_start]);
if (buf[pos] == '|')
ds = NEED_LEVEL;
else
ds = NEED_PIPE;
rs = NEED_PIPE;
}
break;
}
...
...
@@ -13693,8 +13800,6 @@ init_rip(int version)
rip.y = 0;
rip.viewport.sx = 0;
rip.viewport.sy = 0;
rip.viewport.ex = rip.x_dim - 1;
rip.viewport.ey = rip.y_dim - 1;
rip.color = 7;
rip.font.num = 0;
rip.font.vertical = 0;
...
...
@@ -13714,6 +13819,8 @@ init_rip(int version)
if (rip.y_max > rip.y_dim)
rip.y_max = rip.y_dim;
pthread_mutex_unlock(&vstatlock);
rip.viewport.ex = rip.x_dim - 1;
rip.viewport.ey = rip.y_dim - 1;
pending_len = 0;
if (pending)
...
...