commit dd85241b670a1e3b849df12b44c93597bfd62ae2
parent 5f4579d1537ad409b0abee401d70abc03d31c0b7
Author: kocotian <kocotian@kocotian.pl>
Date: Wed, 27 Jan 2021 09:39:43 +0100
bilinear scaling, added patches
Diffstat:
4 files changed, 248 insertions(+), 17 deletions(-)
diff --git a/patches/sent-bilinearscaling-1.0.diff b/patches/sent-bilinearscaling-1.0.diff
@@ -0,0 +1,88 @@
+diff --git a/sent.c b/sent.c
+index 0da2bff..d92cf3b 100644
+--- a/sent.c
++++ b/sent.c
+@@ -282,27 +282,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;
+ }
diff --git a/patches/sent-invertedcolors-72d33d4.diff b/patches/sent-invertedcolors-72d33d4.diff
@@ -0,0 +1,73 @@
+diff --git a/config.def.h b/config.def.h
+index 60eb376..ccea9a6 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -13,6 +13,11 @@ static const char *colors[] = {
+ "#FFFFFF", /* background color */
+ };
+
++static const char *inverted_colors[] = {
++ "#FFFFFF", /* foreground color */
++ "#000000", /* background color */
++};
++
+ static const float linespacing = 1.4;
+
+ /* how much screen estate is to be used at max for the content */
+diff --git a/sent.1 b/sent.1
+index fabc614..f74d583 100644
+--- a/sent.1
++++ b/sent.1
+@@ -6,6 +6,7 @@
+ .Sh SYNOPSIS
+ .Nm
+ .Op Fl v
++.Op Fl i
+ .Op Ar file
+ .Sh DESCRIPTION
+ .Nm
+@@ -21,6 +22,8 @@ few minutes.
+ .Bl -tag -width Ds
+ .It Fl v
+ Print version information to stdout and exit.
++.It Fl i
++Use the colors from the inverted color array.
+ .El
+ .Sh USAGE
+ .Bl -tag -width Ds
+diff --git a/sent.c b/sent.c
+index c50a572..c31f772 100644
+--- a/sent.c
++++ b/sent.c
+@@ -25,6 +25,8 @@
+
+ char *argv0;
+
++int use_inverted_colors = 0;
++
+ /* macros */
+ #define LEN(a) (sizeof(a) / sizeof(a)[0])
+ #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
+@@ -586,7 +588,11 @@ xinit()
+
+ if (!(d = drw_create(xw.dpy, xw.scr, xw.win, xw.w, xw.h)))
+ die("sent: Unable to create drawing context");
+- sc = drw_scm_create(d, colors, 2);
++ if (use_inverted_colors) {
++ sc = drw_scm_create(d, inverted_colors, 2);
++ } else {
++ sc = drw_scm_create(d, colors, 2);
++ }
+ drw_setscheme(d, sc);
+ XSetWindowBackground(xw.dpy, xw.win, sc[ColBg].pixel);
+
+@@ -687,6 +693,9 @@ main(int argc, char *argv[])
+ case 'v':
+ fprintf(stderr, "sent-"VERSION"\n");
+ return 0;
++ case 'i':
++ use_inverted_colors = 1;
++ break;
+ default:
+ usage();
+ } ARGEND
diff --git a/patches/sent-progress-bar-1.0.diff b/patches/sent-progress-bar-1.0.diff
@@ -0,0 +1,31 @@
+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/sent.c b/sent.c
+index c50a572..046466e 100644
+--- a/sent.c
++++ b/sent.c
+@@ -533,6 +533,12 @@ xdraw()
+ 0,
+ slides[idx].lines[i],
+ 0);
++ if (idx != 0 && progressheight != 0) {
++ drw_rect(d,
++ 0, xw.h - progressheight,
++ (xw.w * idx)/(slidecount - 1), progressheight,
++ 1, 0);
++ }
+ drw_map(d, xw.win, 0, 0, xw.w, xw.h);
+ } else {
+ if (!(im->state & SCALED))
diff --git a/sent.c b/sent.c
@@ -282,27 +282,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;
}