summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Trzeciak <jptrzy@gmail.com>2023-09-12 08:38:07 +0200
committerJakub Trzeciak <jptrzy@gmail.com>2023-09-12 08:38:07 +0200
commitcd52c2c7cdf3a03f2c4624589d9888bf819e9df3 (patch)
treeaea2ec21553b3d79dafdd7446b802161ca85c1c7
parent882d54c225b83c762acf5bb3967f4890c3ecef86 (diff)
downloadsent-cd52c2c7cdf3a03f2c4624589d9888bf819e9df3.tar.gz
sent-cd52c2c7cdf3a03f2c4624589d9888bf819e9df3.tar.bz2
sent-cd52c2c7cdf3a03f2c4624589d9888bf819e9df3.zip
Jptrzy's patchesHEADmaster
-rw-r--r--README.md64
-rw-r--r--config.def.h3
-rw-r--r--nyan.pngbin901 -> 4822 bytes
-rw-r--r--sent.111
-rw-r--r--sent.c100
5 files changed, 99 insertions, 79 deletions
diff --git a/README.md b/README.md
index c1e9385..0fb3820 100644
--- a/README.md
+++ b/README.md
@@ -1,59 +1,5 @@
-sent is a simple plaintext presentation tool.
-
-sent does not need latex, libreoffice or any other fancy file format, it uses
-plaintext files to describe the slides and can include images via farbfeld.
-Every paragraph represents a slide in the presentation.
-
-The presentation is displayed in a simple X11 window. The content of each slide
-is automatically scaled to fit the window and centered so you also don't have to
-worry about alignment. Instead you can really concentrate on the content.
-
-
-Dependencies
-
-You need Xlib and Xft to build sent and the farbfeld[0] tools installed to use
-images in your presentations.
-
-Demo
-
-To get a little demo, just type
-
- make && ./sent example
-
-You can navigate with the arrow keys and quit with `q`.
-
-
-Usage
-
- sent [FILE]
-
-If FILE is omitted or equals `-`, stdin will be read. Produce image slides by
-prepending a `@` in front of the filename as a single paragraph. Lines starting
-with `#` will be ignored. A `\` at the beginning of the line escapes `@` and
-`#`. A presentation file could look like this:
-
- sent
-
- @nyan.png
-
- depends on
- - Xlib
- - Xft
- - farbfeld
-
- sent FILENAME
- one slide per paragraph
- # This is a comment and will not be part of the presentation
- \# This and the next line start with backslashes
-
- \@FILE.png
-
- thanks / questions?
-
-
-Development
-
-sent is developed at http://tools.suckless.org/sent
-
-
-0: http://tools.suckless.org/farbfeld/
+# Jptrzy's sent
+## Patches:
+* Bilinear Scaling
+* Commandline Options
+* Progress Bar - with small tweaks
diff --git a/config.def.h b/config.def.h
index 60eb376..25d89e0 100644
--- a/config.def.h
+++ b/config.def.h
@@ -19,6 +19,9 @@ static const float linespacing = 1.4;
static const float usablewidth = 0.75;
static const float usableheight = 0.75;
+/* height of the presentation progress bar */
+static const int progressheight = 5;
+
static Mousekey mshortcuts[] = {
/* button function argument */
{ Button1, advance, {.i = +1} },
diff --git a/nyan.png b/nyan.png
index 377b9d0..67d63d5 100644
--- a/nyan.png
+++ b/nyan.png
Binary files differ
diff --git a/sent.1 b/sent.1
index e5a7d25..5476c83 100644
--- a/sent.1
+++ b/sent.1
@@ -6,6 +6,9 @@
.Nd simple plaintext presentation tool
.Sh SYNOPSIS
.Nm
+.Op Fl f Ar font
+.Op Fl c Ar fgcolor
+.Op Fl b Ar bgcolor
.Op Fl v
.Op Ar file
.Sh DESCRIPTION
@@ -23,6 +26,14 @@ minutes.
.Bl -tag -width Ds
.It Fl v
Print version information to stdout and exit.
+.It Fl f Ar font
+Defines the
+.Ar font
+when sent is run.
+.It Fl c Ar fgcolor
+Defines the foreground color when sent is run.
+.It Fl b Ar bgcolor
+Defines the background color when sent is run.
.El
.Sh USAGE
.Bl -tag -width Ds
diff --git a/sent.c b/sent.c
index dfadd3a..1185452 100644
--- a/sent.c
+++ b/sent.c
@@ -284,27 +284,66 @@ ffprepare(Image *img)
img->state |= SCALED;
}
+static unsigned char double_to_uchar_clamp255(double dbl)
+{
+ dbl = round(dbl);
+
+ return
+ (dbl < 0.0) ? 0 :
+ (dbl > 255.0) ? 255 : (unsigned char)dbl;
+}
+
+static int int_clamp(int integer, int lower, int upper)
+{
+ if (integer < lower)
+ return lower;
+ else if (integer >= upper)
+ return upper - 1;
+ else
+ return integer;
+}
+
void
ffscale(Image *img)
{
- unsigned int x, y;
- unsigned int width = img->ximg->width;
- unsigned int height = img->ximg->height;
- char* newBuf = img->ximg->data;
- unsigned char* ibuf;
- unsigned int jdy = img->ximg->bytes_per_line / 4 - width;
- unsigned int dx = (img->bufwidth << 10) / width;
-
- for (y = 0; y < height; y++) {
- unsigned int bufx = img->bufwidth / width;
- ibuf = &img->buf[y * img->bufheight / height * img->bufwidth * 3];
-
- for (x = 0; x < width; x++) {
- *newBuf++ = (ibuf[(bufx >> 10)*3+2]);
- *newBuf++ = (ibuf[(bufx >> 10)*3+1]);
- *newBuf++ = (ibuf[(bufx >> 10)*3+0]);
+ const unsigned width = img->ximg->width;
+ const unsigned height = img->ximg->height;
+ unsigned char* newBuf = (unsigned char*)img->ximg->data;
+ const unsigned jdy = img->ximg->bytes_per_line / 4 - width;
+
+ const double x_scale = ((double)img->bufwidth/(double)width);
+ const double y_scale = ((double)img->bufheight/(double)height);
+
+ for (unsigned y = 0; y < height; ++y) {
+ const double old_y = (double)y * y_scale;
+ const double y_factor = ceil(old_y) - old_y;
+ const int old_y_int_0 = int_clamp((int)floor(old_y), 0, img->bufheight);
+ const int old_y_int_1 = int_clamp((int)ceil(old_y), 0, img->bufheight);
+
+ for (unsigned x = 0; x < width; ++x) {
+ const double old_x = (double)x * x_scale;
+ const double x_factor = ceil(old_x) - old_x;
+ const int old_x_int_0 = int_clamp((int)floor(old_x), 0, img->bufwidth);
+ const int old_x_int_1 = int_clamp((int)ceil(old_x), 0, img->bufwidth);
+
+ const unsigned c00_pos = 3*((old_x_int_0) + ((old_y_int_0)*img->bufwidth));
+ const unsigned c01_pos = 3*((old_x_int_0) + ((old_y_int_1)*img->bufwidth));
+ const unsigned c10_pos = 3*((old_x_int_1) + ((old_y_int_0)*img->bufwidth));
+ const unsigned c11_pos = 3*((old_x_int_1) + ((old_y_int_1)*img->bufwidth));
+
+ for (int i = 2; i >= 0 ; --i) {
+ const unsigned char c00 = img->buf[c00_pos + i];
+ const unsigned char c01 = img->buf[c01_pos + i];
+ const unsigned char c10 = img->buf[c10_pos + i];
+ const unsigned char c11 = img->buf[c11_pos + i];
+
+ const double x_result_0 = (double)c00*x_factor + (double)c10*(1.0 - x_factor);
+ const double x_result_1 = (double)c01*x_factor + (double)c11*(1.0 - x_factor);
+ const double result = x_result_0*y_factor + x_result_1*(1.0 - y_factor);
+
+ *newBuf++ = double_to_uchar_clamp255(result);
+ }
newBuf++;
- bufx += dx;
}
newBuf += jdy;
}
@@ -528,8 +567,15 @@ xdraw(void)
getfontsize(&slides[idx], &width, &height);
XClearWindow(xw.dpy, xw.win);
+ drw_rect(d, 0, 0, xw.w, xw.h, 1, 1);
+
+ if (idx != 0 && progressheight != 0) {
+ drw_rect(d,
+ 0, xw.h - progressheight,
+ (xw.w * idx)/(slidecount - 1), progressheight,
+ 1, 0);
+ }
if (!im) {
- drw_rect(d, 0, 0, xw.w, xw.h, 1, 1);
for (i = 0; i < slides[idx].linecount; i++)
drw_text(d,
(xw.w - width) / 2,
@@ -539,12 +585,17 @@ xdraw(void)
0,
slides[idx].lines[i],
0);
- drw_map(d, xw.win, 0, 0, xw.w, xw.h);
+
+ drw_map(d, xw.win, 0, 0, xw.w, xw.h);
} else {
+ drw_map(d, xw.win, 0, 0, xw.w, xw.h);
+
if (!(im->state & SCALED))
ffprepare(im);
ffdraw(im);
}
+
+
}
void
@@ -680,7 +731,7 @@ configure(XEvent *e)
void
usage(void)
{
- die("usage: %s [file]", argv0);
+ die("usage: %s [-c fgcolor] [-b bgcolor] [-f font] [file]", argv0);
}
int
@@ -692,6 +743,15 @@ main(int argc, char *argv[])
case 'v':
fprintf(stderr, "sent-"VERSION"\n");
return 0;
+ case 'f':
+ fontfallbacks[0] = EARGF(usage());
+ break;
+ case 'c':
+ colors[0] = EARGF(usage());
+ break;
+ case 'b':
+ colors[1] = EARGF(usage());
+ break;
default:
usage();
} ARGEND
Software created with 💖