Add pseudoteletypewriter to emulator

https://justine.storage.googleapis.com/emulator628.mp4
This commit is contained in:
Justine Tunney 2020-08-26 23:08:08 -07:00
parent e86cff8ba0
commit 5aabacb361
94 changed files with 3245 additions and 2179 deletions

View file

@ -1,41 +0,0 @@
#ifndef COSMOPOLITAN_TOOL_VIZ_LIB_ANSITRINSICS_H_
#define COSMOPOLITAN_TOOL_VIZ_LIB_ANSITRINSICS_H_
#include "libc/limits.h"
#include "libc/macros.h"
#include "libc/str/str.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
static unsigned char avgb(unsigned char a, unsigned char b) {
return (a + b + 1) / 2;
}
static void pavgb(const unsigned char *restrict c,
const unsigned char *restrict b, unsigned char *restrict a) {
unsigned i;
for (i = 0; i < 16; ++i) a[i] = avgb(c[i], b[i]);
}
static void vpavgb(const unsigned char *restrict c,
const unsigned char *restrict b, unsigned char *restrict a) {
unsigned i;
for (i = 0; i < 32; ++i) a[i] = avgb(c[i], b[i]);
}
static void paddsw(const short c[8], const short b[8], short a[8]) {
size_t j;
for (j = 0; j < 8; ++j) {
a[j] = MIN(SHRT_MAX, MAX(SHRT_MIN, b[j] + c[j]));
}
}
static void vpaddsw(const short c[16], const short b[16], short a[16]) {
size_t j;
for (j = 0; j < 16; ++j) {
a[j] = MAX(SHRT_MIN, MIN(SHRT_MAX, b[j] + c[j]));
}
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_TOOL_VIZ_LIB_ANSITRINSICS_H_ */

View file

@ -1,12 +0,0 @@
#ifndef COSMOPOLITAN_TOOL_VIZ_LIB_SCALE_H_
#define COSMOPOLITAN_TOOL_VIZ_LIB_SCALE_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void *Scale(long dcw, long dyw, long dxw, float dst[dcw][dyw][dxw], long scw,
long syw, long sxw, const float src[scw][syw][sxw], long, long,
long, long, long, long, double, double, double, double);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_TOOL_VIZ_LIB_SCALE_H_ */

View file

@ -49,7 +49,6 @@
#include "third_party/avir/lanczos.h"
#include "tool/viz/lib/graphic.h"
#include "tool/viz/lib/knobs.h"
#include "tool/viz/lib/scale.h"
#include "tool/viz/lib/ycbcr.h"
#define M 15

View file

@ -48,7 +48,6 @@
#include "third_party/stb/stb_image.h"
#include "tool/viz/lib/bilinearscale.h"
#include "tool/viz/lib/graphic.h"
#include "tool/viz/lib/scale.h"
#define LONG long
#define CHAR char

View file

@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "dsp/core/half.h"
#include "dsp/core/twixt8.h"
#include "dsp/scale/scale.h"
#include "dsp/tty/quant.h"
@ -59,6 +60,7 @@ static struct Flags {
bool unsharp;
bool dither;
bool ruler;
bool trailingnewline;
long half;
bool full;
long width;
@ -129,9 +131,11 @@ static void GetOpts(int *argc, char *argv[]) {
g_flags.unsharp = true;
break;
case 'w':
g_flags.trailingnewline = true;
g_flags.width = ParseNumberOption(optarg);
break;
case 'h':
g_flags.trailingnewline = true;
g_flags.height = ParseNumberOption(optarg);
break;
case 'f':
@ -202,19 +206,19 @@ static unsigned char OutOfBoundsBackground(unsigned y, unsigned x) {
static void PrintRulerRight(long yn, long xn, long y, long x,
bool *inout_didhalfy) {
if (y == 0) {
printf("\e[0m‾0");
printf("‾0");
} else if (yn / 2 <= y && y <= yn / 2 + 1 && !*inout_didhalfy) {
printf("\e[0m‾%s%s", "yn/2", y % 2 ? "+1" : "");
printf("‾%s%s", "yn/2", y % 2 ? "+1" : "");
*inout_didhalfy = true;
} else if (y + 1 == yn / 2 && !*inout_didhalfy) {
printf("\e[0m⎯yn/2");
printf("⎯yn/2");
*inout_didhalfy = true;
} else if (y + 1 == yn) {
printf("\e[0m⎯yn");
printf("⎯yn");
} else if (y + 2 == yn) {
printf("\e[0m_yn");
printf("_yn");
} else if (!(y % 10)) {
printf("\e[0m‾%,u", y);
printf("‾%,u", y);
}
}
@ -243,11 +247,12 @@ static void PrintImageImpl(long syn, long sxn, unsigned char RGB[3][syn][sxn],
b[2], dy > 1 ? u'' : u'');
didfirstx = true;
}
printf("\e[0m");
if (g_flags.ruler) {
PrintRulerRight(yn, xn, y, x, &didhalfy);
}
}
printf("\e[0m\n");
printf("\n");
}
static void PrintImage(long syn, long sxn, unsigned char RGB[3][syn][sxn],
@ -334,7 +339,9 @@ static void PrintImageSerious(long yn, long xn, unsigned char RGB[3][yn][xn],
}
}
p = ttyraster(vt, (void *)TTY, yn, xn, bg, fg);
p = stpcpy(p, "\r\e[0m");
*p++ = '\r';
if (g_flags.trailingnewline) *p++ = '\n';
p = stpcpy(p, "\e[0m");
ttywrite(STDOUT_FILENO, vt, p - vt);
}