Remove some dead code

This commit is contained in:
Justine Tunney 2023-07-03 02:47:05 -07:00
parent 168d1c157e
commit 73c0faa1b5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
66 changed files with 324 additions and 7705 deletions

View file

@ -1,315 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/lcg.internal.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "libc/x/x.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.internal.h"
#include "tool/viz/lib/formatstringtable.h"
typedef double (*round_f)(double);
typedef unsigned long (*rand_f)(void);
struct Range {
long double a;
long double b;
};
short xn_ = 8;
short yn_ = 8;
double digs_ = 6;
rand_f rand_;
round_f rounder_;
const char *path_ = "-";
const char *name_ = "M";
const char *type_ = "float";
struct Range r1_ = {LONG_MIN, LONG_MAX};
struct Range r2_ = {0, 1};
StringTableFormatter *formatter_ = FormatStringTableAsCode;
static wontreturn void PrintUsage(int rc, FILE *f) {
fprintf(f, "Usage: %s%s", program_invocation_name, "\
[FLAGS] [FILE]\n\
\n\
Flags:\n\
-u unsigned\n\
-c char\n\
-s short\n\
-i int\n\
-l long\n\
-d double\n\
-b bytes [-uc]\n\
-g non-deterministic rng\n\
-S output assembly\n\
-W output whitespace\n\
-o PATH output path\n\
-x FLEX\n\
-w FLEX width\n\
-y FLEX\n\
-h FLEX height\n\
-N NAME name\n\
-T NAME type name\n\
-A FLEX min value\n\
-B FLEX max value\n\
-R FUNC round function for indexing\n\
-D FLEX decimal digits to printout\n\
-v increases verbosity\n\
-? shows this information\n\
\n");
exit(rc);
}
static bool StringEquals(const char *a, const char *b) {
return strcasecmp(a, b) == 0;
}
static wontreturn void ShowInvalidArg(const char *name, const char *s,
const char *type) {
fprintf(stderr, "error: invalid %s %s: %s\n", type, name, s);
exit(EXIT_FAILURE);
}
static double ParseFlexidecimalOrDie(const char *name, const char *s,
double min, double max) {
double x;
s = firstnonnull(s, "NULL");
if (strchr(s, '.') || strchr(s, 'e')) {
x = strtod(s, NULL);
} else {
x = strtol(s, NULL, 0);
}
if (min <= x && x <= max) {
return x;
} else {
ShowInvalidArg(name, s, "flexidecimal");
}
}
static round_f ParseRoundingFunctionOrDie(const char *s) {
if (isempty(s) || StringEquals(s, "none") || StringEquals(s, "null")) {
return NULL;
} else if (StringEquals(s, "round")) {
return round;
} else if (StringEquals(s, "rint")) {
return rint;
} else if (StringEquals(s, "nearbyint")) {
return nearbyint;
} else if (StringEquals(s, "trunc")) {
return trunc;
} else if (StringEquals(s, "floor")) {
return floor;
} else if (StringEquals(s, "ceil")) {
return ceil;
} else {
ShowInvalidArg("round", s, "func");
}
}
static void ConfigureIntegralRange(const char *type, long min, long max) {
type_ = type;
r1_.a = min;
r1_.b = max;
r2_.a = min;
r2_.b = max;
if (!rounder_) rounder_ = round;
}
void GetOpts(int argc, char *argv[]) {
int opt;
bool want_unsigned, want_char, want_short, want_int, want_long, want_double;
want_unsigned = false;
want_char = false;
want_short = false;
want_int = false;
want_long = false;
want_double = false;
if (argc == 2 &&
(StringEquals(argv[1], "--help") || StringEquals(argv[1], "-help"))) {
PrintUsage(EXIT_SUCCESS, stdout);
}
while ((opt = getopt(argc, argv, "?vubcsildgSWo:x:w:y:h:N:A:B:C:E:T:R:D:")) !=
-1) {
switch (opt) {
case 'b':
want_unsigned = true;
want_char = true;
break;
case 'u':
want_unsigned = true;
break;
case 'c':
want_char = true;
break;
case 's':
want_short = true;
break;
case 'i':
want_int = true;
break;
case 'l':
want_long = true;
break;
case 'd':
want_double = true;
break;
case 'g':
rand_ = _rand64;
break;
case 'N':
name_ = optarg;
break;
case 'o':
path_ = optarg;
break;
case 'S':
formatter_ = FormatStringTableAsAssembly;
break;
case 'W':
formatter_ = FormatStringTableBasic;
break;
case 't':
type_ = optarg;
break;
case 'x':
case 'w':
xn_ = ParseFlexidecimalOrDie("width", optarg, 1, SHRT_MAX);
break;
case 'y':
case 'h':
yn_ = ParseFlexidecimalOrDie("height", optarg, 1, SHRT_MAX);
break;
case 'D':
digs_ = ParseFlexidecimalOrDie("digs", optarg, 0, 15.95);
break;
case 'r':
rounder_ = ParseRoundingFunctionOrDie(optarg);
break;
case 'A':
r1_.a = ParseFlexidecimalOrDie("r1_.a", optarg, INT_MIN, INT_MAX);
break;
case 'B':
r1_.b = ParseFlexidecimalOrDie("r1_.b", optarg, INT_MIN, INT_MAX);
break;
case 'C':
r2_.a = ParseFlexidecimalOrDie("r2_.a", optarg, INT_MIN, INT_MAX);
break;
case 'E':
r2_.b = ParseFlexidecimalOrDie("r2_.b", optarg, INT_MIN, INT_MAX);
break;
case '?':
PrintUsage(EXIT_SUCCESS, stdout);
default:
PrintUsage(EX_USAGE, stderr);
}
}
if (want_unsigned && want_char) {
ConfigureIntegralRange("unsigned char", 0, 255);
} else if (want_char) {
ConfigureIntegralRange("signed char", -128, 127);
} else if (want_unsigned && want_short) {
ConfigureIntegralRange("unsigned short", USHRT_MIN, USHRT_MAX);
} else if (want_short) {
ConfigureIntegralRange("short", SHRT_MIN, SHRT_MAX);
} else if (want_unsigned && want_int) {
ConfigureIntegralRange("unsigned", UINT_MIN, UINT_MAX);
} else if (want_int) {
ConfigureIntegralRange("int", INT_MIN, INT_MAX);
} else if (want_unsigned && want_long) {
ConfigureIntegralRange("unsigned long", ULONG_MIN, ULONG_MAX);
} else if (want_long) {
ConfigureIntegralRange("long", LONG_MIN, LONG_MAX);
} else if (want_double) {
type_ = "double";
r1_.a = LONG_MIN;
r1_.b = LONG_MAX;
digs_ = 19;
}
}
static void *SetRandom(long n, long p[n]) {
long i;
uint64_t r;
if (rand_) {
for (r = 1, i = 0; i < n; ++i) {
p[i] = rand_();
}
} else {
for (r = 1, i = 0; i < n; ++i) {
p[i] = KnuthLinearCongruentialGenerator(&r) >> 32 |
KnuthLinearCongruentialGenerator(&r) >> 32 << 32;
}
}
return p;
}
static long double ConvertRange(long double x, long double a, long double b,
long double c, long double d) {
return (d - c) / (b - a) * (x - a) + c;
}
static double Compand(long x, double a, double b, double c, double d) {
return ConvertRange(ConvertRange(x, LONG_MIN, LONG_MAX, a, b), a, b, c, d);
}
static void GenerateMatrixImpl(long I[yn_][xn_], double M[yn_][xn_], FILE *f) {
long y, x;
for (y = 0; y < yn_; ++y) {
for (x = 0; x < xn_; ++x) {
M[y][x] = Compand(I[y][x], r1_.a, r1_.b, r2_.a, r2_.b);
}
if (rounder_) {
for (x = 0; x < xn_; ++x) {
M[y][x] = rounder_(M[y][x]);
}
}
}
FormatMatrixDouble(yn_, xn_, M, fputs, f, formatter_, type_, name_, NULL,
digs_, round);
}
void GenerateMatrix(FILE *f) {
GenerateMatrixImpl(SetRandom(yn_ * xn_, gc(calloc(yn_ * xn_, sizeof(long)))),
gc(calloc(yn_ * xn_, sizeof(double))), f);
}
int main(int argc, char *argv[]) {
int i;
FILE *f;
ShowCrashReports();
GetOpts(argc, argv);
CHECK_NOTNULL((f = fopen(path_, "w")));
if (optind < argc) FATALF("TODO(jart): support input files");
GenerateMatrix(f);
return fclose(f);
}

View file

@ -1,116 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/log/check.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/getopt/getopt.internal.h"
static FILE *fi_, *fo_;
static char *inpath_, *outpath_;
wontreturn void usage(int rc, FILE *f) {
fprintf(f, "%s%s%s\n", "Usage: ", program_invocation_name,
" [-o FILE] [FILE...]\n");
exit(rc);
}
void getopts(int *argc, char *argv[]) {
int opt;
outpath_ = "-";
while ((opt = getopt(*argc, argv, "?ho:")) != -1) {
switch (opt) {
case 'o':
outpath_ = optarg;
break;
case '?':
case 'h':
usage(EXIT_SUCCESS, stdout);
default:
usage(EX_USAGE, stderr);
}
}
if (optind == *argc) {
argv[(*argc)++] = "-";
}
}
void processfile(void) {
wint_t wc;
while ((wc = fgetwc(fi_)) != -1) {
switch (wc) {
case L'':
wc = L' ';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
/* █ */
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
case L'':
wc = L'';
break;
default:
break;
}
fputwc(wc, fo_);
}
}
int main(int argc, char *argv[]) {
size_t i;
getopts(&argc, argv);
CHECK_NOTNULL((fo_ = fopen(outpath_, "w")));
for (i = optind; i < argc; ++i) {
CHECK_NOTNULL((fi_ = fopen((inpath_ = argv[i]), "r")));
processfile();
CHECK_NE(-1, fclose(fi_));
fi_ = 0;
}
CHECK_NE(-1, fclose(fo_));
fo_ = 0;
return 0;
}

View file

@ -1,642 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/core/c1331.h"
#include "dsp/core/c161.h"
#include "dsp/core/core.h"
#include "dsp/scale/scale.h"
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/fmt/conv.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "third_party/getopt/getopt.internal.h"
#include "third_party/stb/stb_image.h"
#include "tool/viz/lib/bilinearscale.h"
#include "tool/viz/lib/graphic.h"
#define LONG long
#define CHAR char
#define CLAMP(X) MIN(255, MAX(0, X))
#define C13(A, B) (((A) + 3 * (B) + 2) >> 2)
#define LERP(X, Y, P) ((X) + (((P) * ((Y) - (X))) >> 8))
static double r_;
static unsigned char ChessBoard(unsigned y, unsigned x, unsigned char a,
unsigned char b) {
return !((y ^ x) & (1u << 2)) ? a : b;
}
static unsigned char AlphaBackground(unsigned y, unsigned x) {
return ChessBoard(y, x, 255, 200);
}
static unsigned char OutOfBoundsBackground(unsigned y, unsigned x) {
return ChessBoard(y, x, 40, 80);
}
static unsigned char Opacify(CHAR w, const unsigned char P[1u << w][1u << w],
const unsigned char A[1u << w][1u << w], LONG yn,
LONG xn, long y, long x) {
if ((0 <= y && y < yn) && (0 <= x && x < xn)) {
return LERP(AlphaBackground(y, x), P[y][x], A[y][x]);
} else {
return OutOfBoundsBackground(y, x);
}
}
static void PrintImage(CHAR w, unsigned char R[1u << w][1u << w],
unsigned char G[1u << w][1u << w],
unsigned char B[1u << w][1u << w],
unsigned char A[1u << w][1u << w], LONG yn, LONG xn) {
bool didhalfy;
long y, x;
didhalfy = false;
for (y = 0; y < yn; y += 2) {
if (y) printf("\e[0m\n");
for (x = 0; x < xn; ++x) {
printf("\e[48;2;%d;%d;%d;38;2;%d;%d;%dm▄",
Opacify(w, R, A, yn, xn, y + 0, x),
Opacify(w, G, A, yn, xn, y + 0, x),
Opacify(w, B, A, yn, xn, y + 0, x),
Opacify(w, R, A, yn, xn, y + 1, x),
Opacify(w, G, A, yn, xn, y + 1, x),
Opacify(w, B, A, yn, xn, y + 1, x));
}
if (y == 0) {
printf("\e[0m‾0");
} else if (yn / 2 <= y && y <= yn / 2 + 1 && !didhalfy) {
printf("\e[0m‾%s%s", "yn/2", y % 2 ? "+1" : "");
didhalfy = true;
} else if (y + 1 == yn / 2 && !didhalfy) {
printf("\e[0m⎯yn/2");
didhalfy = true;
} else if (y + 1 == yn) {
printf("\e[0m⎯yn");
} else if (y + 2 == yn) {
printf("\e[0m_yn");
} else if (!(y % 10)) {
printf("\e[0m‾%,u", y);
}
}
printf("\e[0m\n");
}
static void DeblinterlaceRgba(CHAR w, unsigned char R[1u << w][1u << w],
unsigned char G[1u << w][1u << w],
unsigned char B[1u << w][1u << w],
unsigned char A[1u << w][1u << w], LONG yn,
LONG xn, const unsigned char src[yn][xn][4]) {
long y, x;
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
R[y][x] = src[y][x][0];
G[y][x] = src[y][x][1];
B[y][x] = src[y][x][2];
A[y][x] = src[y][x][3];
}
}
}
static void SharpenX(CHAR w, unsigned char dst[1u << w][1u << w],
const unsigned char src[1u << w][1u << w], char yw,
char xw) {
int y, x;
for (y = 0; y < (1u << yw); ++y) {
for (x = 0; x < (1u << xw); ++x) {
dst[y][x] = C161(src[y][MAX(0, x - 1)], src[y][x],
src[y][MIN((1u << xw) - 1, x + 1)]);
}
}
}
static void SharpenY(CHAR w, unsigned char dst[1u << w][1u << w],
const unsigned char src[1u << w][1u << w], char yw,
char xw) {
int y, x;
for (y = 0; y < (1u << yw); ++y) {
for (x = 0; x < (1u << xw); ++x) {
dst[y][x] = C161(src[MAX(0, y - 1)][x], src[y][x],
src[MIN((1u << yw) - 1, y + 1)][x]);
}
}
}
static void UpscaleX(CHAR w, unsigned char img[1u << w][1u << w], char yw,
char xw) {
long y, x;
for (y = (1u << yw); y--;) {
for (x = (1u << xw); --x;) {
img[y][x] =
C13(img[y][MIN(((1u << xw) >> 1) - 1, (x >> 1) - 1 + (x & 1) * 2)],
img[y][x >> 1]);
}
}
}
static void UpscaleY(CHAR w, unsigned char img[1u << w][1u << w], char yw,
char xw) {
long y, x;
for (y = (1u << yw); --y;) {
for (x = (1u << xw); x--;) {
img[y][x] =
C13(img[MIN(((1u << yw) >> 1) - 1, (y >> 1) - 1 + (y & 1) * 2)][x],
img[y >> 1][x]);
}
}
}
static void Upscale(CHAR w, unsigned char img[1u << w][1u << w],
unsigned char tmp[1u << w][1u << w], char yw, char xw) {
UpscaleY(w, img, yw, xw - 1);
SharpenY(w, tmp, img, yw, xw - 1);
UpscaleX(w, tmp, yw, xw);
SharpenX(w, img, tmp, yw, xw);
}
#if 0
static void *MagikarpY(CHAR w, unsigned char p[1u << w][1u << w], char yw,
char xw) {
long y, x, yn, xn, ym;
unsigned char(*t)[(1u << w) + 2][1u << w];
t = memalign(64, ((1u << w) + 2) * (1u << w));
bzero(t, ((1u << w) + 2) * (1u << w));
yn = 1u << yw;
xn = 1u << xw;
ym = yn >> 1;
for (y = 0; y < ym; ++y) {
for (x = 0; x < xn; ++x) {
(*t)[y + 1][x] =
C1331(y ? p[(y << 1) - 1][x] : 0, p[y << 1][x], p[(y << 1) + 1][x],
p[MIN(yn - 1, (y << 1) + 2)][x]);
}
}
for (y = 0; y < ym; ++y) {
for (x = 0; x < xn; ++x) {
p[y][x] =
C161((*t)[y + 1 - 1][x], (*t)[y + 1 + 0][x], (*t)[y + 1 + 1][x]);
}
}
free(t);
return p;
}
static void *MagikarpX(CHAR w, unsigned char p[1u << w][1u << w], char yw,
char xw) {
int y, x;
LONG yn, xn, xm;
yn = 1u << yw;
xn = 1u << xw;
xm = xn >> 1;
for (x = 0; x < xm; ++x) {
for (y = 0; y < yn; ++y) {
p[y][(xn - xm - 1) + (xm - x - 1)] =
C1331(p[y][MAX(00 + 0, xn - (x << 1) - 1 + (xn & 1) - 1)],
p[y][MIN(xn - 1, xn - (x << 1) - 1 + (xn & 1) + 0)],
p[y][MIN(xn - 1, xn - (x << 1) - 1 + (xn & 1) + 1)],
p[y][MIN(xn - 1, xn - (x << 1) - 1 + (xn & 1) + 2)]);
}
}
for (x = 0; x < xm; ++x) {
for (y = 0; y < yn; ++y) {
p[y][x] = C161(p[y][MAX(xn - 1 - xm, xn - xm - 1 + x - 1)],
p[y][MIN(xn - 1 - 00, xn - xm - 1 + x + 0)],
p[y][MIN(xn - 1 - 00, xn - xm - 1 + x + 1)]);
}
}
return p;
}
static void ProcessImageVerbatim(LONG yn, LONG xn,
unsigned char img[yn][xn][4]) {
CHAR w;
void *R, *G, *B, *A;
w = _roundup2log(MAX(yn, xn));
R = xvalloc((1u << w) * (1u << w));
G = xvalloc((1u << w) * (1u << w));
B = xvalloc((1u << w) * (1u << w));
A = xvalloc((1u << w) * (1u << w));
DeblinterlaceRgba(w, R, G, B, A, yn, xn, img);
PrintImage(w, R, G, B, A, yn, xn);
free(R);
free(G);
free(B);
free(A);
}
static void ProcessImageDouble(LONG yn, LONG xn, unsigned char img[yn][xn][4]) {
CHAR w;
void *t, *R, *G, *B, *A;
w = _roundup2log(MAX(yn, xn)) + 1;
t = xvalloc((1u << w) * (1u << w));
R = xvalloc((1u << w) * (1u << w));
G = xvalloc((1u << w) * (1u << w));
B = xvalloc((1u << w) * (1u << w));
A = xvalloc((1u << w) * (1u << w));
DeblinterlaceRgba(w, R, G, B, A, yn, xn, img);
Upscale(w, R, t, w, w);
Upscale(w, G, t, w, w);
Upscale(w, B, t, w, w);
Upscale(w, A, t, w, w);
free(t);
PrintImage(w, R, G, B, A, yn * 2, xn * 2);
free(R);
free(G);
free(B);
free(A);
}
static void ProcessImageHalf(LONG yn, LONG xn, unsigned char img[yn][xn][4]) {
CHAR w;
void *R, *G, *B, *A;
w = _roundup2log(MAX(yn, xn));
R = xvalloc((1u << w) * (1u << w));
G = xvalloc((1u << w) * (1u << w));
B = xvalloc((1u << w) * (1u << w));
A = xvalloc((1u << w) * (1u << w));
DeblinterlaceRgba(w, R, G, B, A, yn, xn, img);
MagikarpY(w, R, w, w);
MagikarpY(w, G, w, w);
MagikarpY(w, B, w, w);
MagikarpY(w, A, w, w);
MagikarpX(w, R, w - 1, w);
MagikarpX(w, G, w - 1, w);
MagikarpX(w, B, w - 1, w);
MagikarpX(w, A, w - 1, w);
PrintImage(w, R, G, B, A, yn >> 1, xn >> 1);
free(R);
free(G);
free(B);
free(A);
}
static void ProcessImageHalfY(LONG yn, LONG xn, unsigned char img[yn][xn][4]) {
CHAR w;
void *R, *G, *B, *A;
w = _roundup2log(MAX(yn, xn));
R = xvalloc((1u << w) * (1u << w));
G = xvalloc((1u << w) * (1u << w));
B = xvalloc((1u << w) * (1u << w));
A = xvalloc((1u << w) * (1u << w));
DeblinterlaceRgba(w, R, G, B, A, yn, xn, img);
MagikarpY(w, R, w, w);
MagikarpY(w, G, w, w);
MagikarpY(w, B, w, w);
MagikarpY(w, A, w, w);
PrintImage(w, R, G, B, A, yn >> 1, xn);
free(R);
free(G);
free(B);
free(A);
}
static void ProcessImageHalfLanczos(LONG yn, LONG xn,
unsigned char img[yn][xn][4]) {
CHAR w;
void *t, *R, *G, *B, *A;
t = xvalloc((yn >> 1) * (xn >> 1) * 4);
lanczos1b(yn >> 1, xn >> 1, t, yn, xn, &img[0][0][0]);
w = _roundup2log(MAX(yn >> 1, xn >> 1));
R = xvalloc((1u << w) * (1u << w));
G = xvalloc((1u << w) * (1u << w));
B = xvalloc((1u << w) * (1u << w));
A = xvalloc((1u << w) * (1u << w));
DeblinterlaceRgba(w, R, G, B, A, yn >> 1, xn >> 1, img);
free(t);
PrintImage(w, R, G, B, A, yn >> 1, xn >> 1);
free(R);
free(G);
free(B);
free(A);
}
static void ProcessImageWash(LONG yn, LONG xn, unsigned char img[yn][xn][4]) {
long w;
void *R, *G, *B, *A, *t;
w = _roundup2log(MAX(yn, xn)) + 1;
t = xvalloc((1u << w) * (1u << w));
R = xvalloc((1u << w) * (1u << w));
G = xvalloc((1u << w) * (1u << w));
B = xvalloc((1u << w) * (1u << w));
A = xvalloc((1u << w) * (1u << w));
DeblinterlaceRgba(w, R, G, B, A, yn, xn, img);
Upscale(w, R, t, w, w);
Upscale(w, G, t, w, w);
Upscale(w, B, t, w, w);
Upscale(w, A, t, w, w);
MagikarpY(w, R, w, w);
MagikarpY(w, G, w, w);
MagikarpY(w, B, w, w);
MagikarpY(w, A, w, w);
MagikarpX(w, R, w - 1, w);
MagikarpX(w, G, w - 1, w);
MagikarpX(w, B, w - 1, w);
MagikarpX(w, A, w - 1, w);
free(t);
PrintImage(w, R, G, B, A, yn, xn);
free(R);
free(G);
free(B);
free(A);
}
#endif
#if 0
static void *MagikarpY(size_t ys, size_t xs, unsigned char p[ys][xs], size_t yn,
size_t xn) {
int y, x, h, b;
b = yn % 2;
h = yn / 2;
if (b && yn < ys) yn++;
for (y = b; y < h + b; ++y) {
for (x = 0; x < xn; ++x) {
p[(yn - h - 1) + (h - y - 1)][x] =
C1331(p[MAX(00 + 0, yn - y * 2 - 1 - 1)][x],
p[MIN(yn - 1, yn - y * 2 - 1 + 0)][x],
p[MIN(yn - 1, yn - y * 2 - 1 + 1)][x],
p[MIN(yn - 1, yn - y * 2 - 1 + 2)][x]);
}
}
for (y = b; y < h + b; ++y) {
for (x = 0; x < xn; ++x) {
p[y][x] = C161(p[MAX(yn - 1 - h, yn - h - 1 + y - 1)][x],
p[MIN(yn - 1 - 0, yn - h - 1 + y + 0)][x],
p[MIN(yn - 1 - 0, yn - h - 1 + y + 1)][x]);
}
}
return p;
}
#endif
#if 0
static void *MagikarpX(size_t ys, size_t xs, unsigned char p[ys][xs], size_t yn,
size_t xn) {
int y, x, w, b;
b = xn % 2;
w = xn / 2;
if (b && xn < xs) xn++;
for (x = 0; x < w; ++x) {
for (y = b; y < yn + b; ++y) {
p[y][(xn - w - 1) + (w - x - 1)] =
C1331(p[y][MAX(00 + 0, xn - x * 2 - 1 - 1)],
p[y][MIN(xn - 1, xn - x * 2 - 1 + 0)],
p[y][MIN(xn - 1, xn - x * 2 - 1 + 1)],
p[y][MIN(xn - 1, xn - x * 2 - 1 + 2)]);
}
}
for (x = 0; x < w; ++x) {
for (y = b; y < yn + b; ++y) {
p[y][x] = C161(p[y][MAX(xn - 1 - w, xn - w - 1 + x - 1)],
p[y][MIN(xn - 1 - 0, xn - w - 1 + x + 0)],
p[y][MIN(xn - 1 - 0, xn - w - 1 + x + 1)]);
}
}
return p;
}
#endif
#if 0
static void ProcessImageMagikarpImpl(CHAR sw,
unsigned char src[5][1u << sw][1u << sw],
LONG syn, LONG sxn,
const unsigned char img[syn][sxn][4],
LONG dyn, LONG dxn) {
DeblinterlaceRgba2(sw, src, syn, sxn, img);
MagikarpY(sw, src[0], sw, sw);
MagikarpX(sw, src[0], sw - 1, sw);
MagikarpY(sw, src[1], sw, sw);
MagikarpX(sw, src[1], sw - 1, sw);
MagikarpY(sw, src[2], sw, sw);
MagikarpX(sw, src[2], sw - 1, sw);
BilinearScale(sw, src[4], sw, src[3], dyn, dxn, syn, sxn);
memcpy(src[3], src[4], syn * sxn);
PrintImage2(sw, src, dyn, dxn);
}
static void ProcessImageMagikarp(LONG syn, LONG sxn,
unsigned char img[syn][sxn][4]) {
CHAR sw;
LONG dyn, dxn;
dyn = syn >> 1;
dxn = sxn >> 1;
sw = _roundup2log(MAX(syn, sxn));
ProcessImageMagikarpImpl(sw, gc(xvalloc((1u << sw) * (1u << sw) * 5)), syn,
sxn, img, dyn, dxn);
}
#endif
/*
********************************************************************************
*/
static unsigned char Opacify2(unsigned yw, unsigned xw,
const unsigned char P[yw][xw],
const unsigned char A[yw][xw], unsigned yn,
unsigned xn, unsigned y, unsigned x) {
if ((0 <= y && y < yn) && (0 <= x && x < xn)) {
return LERP(AlphaBackground(y, x), P[y][x], A[y][x]);
} else {
return OutOfBoundsBackground(y, x);
}
}
static dontinline void PrintImage2(unsigned yw, unsigned xw,
unsigned char img[4][yw][xw], unsigned yn,
unsigned xn) {
bool didhalfy;
unsigned y, x;
didhalfy = false;
for (y = 0; y < yn; y += 2) {
if (y) printf("\e[0m\n");
for (x = 0; x < xn; ++x) {
printf("\e[48;2;%d;%d;%d;38;2;%d;%d;%dm▄",
Opacify2(yw, xw, img[0], img[3], yn, xn, y + 0, x),
Opacify2(yw, xw, img[1], img[3], yn, xn, y + 0, x),
Opacify2(yw, xw, img[2], img[3], yn, xn, y + 0, x),
Opacify2(yw, xw, img[0], img[3], yn, xn, y + 1, x),
Opacify2(yw, xw, img[1], img[3], yn, xn, y + 1, x),
Opacify2(yw, xw, img[2], img[3], yn, xn, y + 1, x));
}
if (y == 0) {
printf("\e[0m‾0");
} else if (yn / 2 <= y && y <= yn / 2 + 1 && !didhalfy) {
printf("\e[0m‾%s%s", "yn/2", y % 2 ? "+1" : "");
didhalfy = true;
} else if (y + 1 == yn / 2 && !didhalfy) {
printf("\e[0m⎯yn/2");
didhalfy = true;
} else if (y + 1 == yn) {
printf("\e[0m⎯yn");
} else if (y + 2 == yn) {
printf("\e[0m_yn");
} else if (!(y % 10)) {
printf("\e[0m‾%,u", y);
}
}
printf("\e[0m\n");
}
static dontinline void *DeblinterlaceRgba2(unsigned yn, unsigned xn,
unsigned char D[4][yn][xn],
const unsigned char S[yn][xn][4]) {
unsigned y, x;
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
D[0][y][x] = S[y][x][0];
D[1][y][x] = S[y][x][1];
D[2][y][x] = S[y][x][2];
D[3][y][x] = S[y][x][3];
}
}
return D;
}
void ProcessImageBilinearImpl(unsigned dyn, unsigned dxn,
unsigned char dst[4][dyn][dxn], unsigned syn,
unsigned sxn, unsigned char src[4][syn][sxn],
unsigned char img[syn][sxn][4]) {
DeblinterlaceRgba2(syn, sxn, src, img);
BilinearScale(4, dyn, dxn, dst, 4, syn, sxn, src, 0, 4, dyn, dxn, syn, sxn,
r_, r_, 0, 0);
PrintImage2(dyn, dxn, dst, dyn, dxn);
}
void ProcessImageBilinear(unsigned yn, unsigned xn,
unsigned char img[yn][xn][4]) {
unsigned dyn, dxn;
dyn = lround(yn / r_);
dxn = lround(xn / r_);
ProcessImageBilinearImpl(dyn, dxn, gc(xmalloc(dyn * dxn * 4)), yn, xn,
gc(xmalloc(yn * xn * 4)), img);
}
static void *b2f(long n, float dst[n], const unsigned char src[n]) {
long i;
float f;
for (i = 0; i < n; ++i) {
f = src[i];
f *= 1 / 255.;
dst[i] = f;
}
return dst;
}
static void *f2b(long n, unsigned char dst[n], const float src[n]) {
int x;
long i;
for (i = 0; i < n; ++i) {
x = lroundf(src[i] * 255);
dst[i] = MIN(255, MAX(0, x));
}
return dst;
}
void ProcessImageGyarados(unsigned yn, unsigned xn,
unsigned char img[yn][xn][4]) {
unsigned dyn, dxn;
dyn = lround(yn / r_);
dxn = lround(xn / r_);
PrintImage2(
dyn, dxn,
EzGyarados(4, dyn, dxn, gc(xmalloc(dyn * dxn * 4)), 4, yn, xn,
DeblinterlaceRgba2(yn, xn, gc(xmalloc(yn * xn * 4)), img), 0,
4, dyn, dxn, yn, xn, r_, r_, 0, 0),
dyn, dxn);
}
void MagikarpDecimate(int yw, int xw, unsigned char img[4][yw][xw], int yn,
int xn, int n) {
int c;
if (n <= 1) {
PrintImage2(yw, xw, img, yn, xn);
} else {
for (c = 0; c < 4; ++c) Magikarp2xY(yw, xw, img[c], yn, xn);
for (c = 0; c < 4; ++c) Magikarp2xX(yw, xw, img[c], (yn + 1) / 2, xn);
MagikarpDecimate(yw, xw, img, (yn + 1) / 2, (xn + 1) / 2, (n + 1) / 2);
}
}
void ProcessImageMagikarp(unsigned yn, unsigned xn,
unsigned char img[yn][xn][4]) {
MagikarpDecimate(yn, xn,
DeblinterlaceRgba2(yn, xn, gc(xmalloc(yn * xn * 4)), img),
yn, xn, lround(r_));
}
dontinline void WithImageFile(const char *path,
void fn(unsigned yn, unsigned xn,
unsigned char img[yn][xn][4])) {
struct stat st;
int fd, yn, xn;
void *map, *data;
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
CHECK_NE(-1, fstat(fd, &st));
CHECK_GT(st.st_size, 0);
CHECK_LE(st.st_size, INT_MAX);
fadvise(fd, 0, 0, MADV_WILLNEED | MADV_SEQUENTIAL);
CHECK_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
CHECK_NOTNULL(
(data = stbi_load_from_memory(map, st.st_size, &xn, &yn, NULL, 4)), "%s",
path);
CHECK_NE(-1, munmap(map, st.st_size));
CHECK_NE(-1, close(fd));
fn(yn, xn, data);
free(data);
}
int main(int argc, char *argv[]) {
int i, opt;
bool bilinear;
void (*scaler)(unsigned yn, unsigned xn, unsigned char[yn][xn][4]) =
ProcessImageMagikarp;
r_ = 2;
while ((opt = getopt(argc, argv, "mlsSybr:")) != -1) {
switch (opt) {
case 'r':
r_ = strtod(optarg, NULL);
break;
case 'm':
scaler = ProcessImageMagikarp;
break;
case 's':
case 'S':
scaler = ProcessImageGyarados;
break;
case 'b':
scaler = ProcessImageBilinear;
break;
default:
break;
}
}
ShowCrashReports();
for (i = optind; i < argc; ++i) {
WithImageFile(argv[i], scaler);
}
return 0;
}

View file

@ -1,95 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/calls/internal.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/macros.internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/stdio/stdio.h"
// clang-format off
struct WinArgs {
char *argv[4096];
char *envp[4092];
intptr_t auxv[2][2];
char argblock[ARG_MAX / 2];
char envblock[ARG_MAX / 2];
};
//#define INCREMENT _roundup2pow(kAutomapSize/16)
#define INCREMENT (64L*1024*1024*1024)
uint64_t last;
void plan2(uint64_t addr, uint64_t end, const char *name) {
char sz[32];
sizefmt(sz, end-addr+1, 1024);
printf("%08x-%08x %-6s %s\n", addr>>16, end>>16, sz, name);
}
void plan(uint64_t addr, uint64_t end, const char *name) {
uint64_t incr, next;
while (addr > last) {
if ((incr = last % INCREMENT)) {
incr = INCREMENT - incr;
} else {
incr = INCREMENT;
}
plan2(last,MIN(last+incr,addr)-1,"free");
last = MIN(last+incr,addr);
}
while (addr <= end) {
if (end-addr+1 <= INCREMENT) {
plan2(addr,end,name);
last = end + 1;
break;
}
if (!(addr % INCREMENT)) {
plan2(addr, addr + INCREMENT - 1, name);
last = addr + INCREMENT;
addr += INCREMENT;
} else {
next = INCREMENT - addr % INCREMENT + addr;
plan2(addr, next - 1, name);
last = next;
addr = next;
}
}
}
int main(int argc, char *argv[]) {
uint64_t x, y;
plan(0x00000000, 0x00200000-1, "null");
plan(0x00200000, 0x00400000-1, "loader");
if (!IsWindows() || IsAtLeastWindows10()) {
plan(0x00400000, 0x50000000-1, "image");
plan(0x50000000, 0x7ffdffff, "arena");
plan(0x7fff0000, 0x10007fffffff, "asan");
} else {
plan(0x00400000, 0x01000000-1, "image");
}
plan(kAutomapStart, kAutomapStart + kAutomapSize - 1, "automap");
plan(kMemtrackStart, kMemtrackStart + kMemtrackSize - 1, "memtrack");
plan(kFixedmapStart, kFixedmapStart + kFixedmapSize - 1, "fixedmap");
if (IsWindows() && !IsAtLeastWindows10()) {
plan(0x50000000, 0x7ffdffff, "arena");
}
x = GetStaticStackAddr(0);
y = ROUNDUP(sizeof(struct WinArgs), FRAMESIZE);
plan(x - y, x - 1, "winargs");
plan(x, x + GetStackSize() - 1, "stack");
if (!IsWindows() || IsAtLeastWindows10()) {
plan(0x7f0000000000, 0x800000000000 - 1, "kernel");
}
return 0;
}

View file

@ -1,83 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/x/xgetline.h"
#define DLL "iphlpapi"
/**
* @fileoverview Tool for adding rnew libraries to libc/nt/master.sh
*
* If provided with a /tmp/syms.txt file containing one symbol name per
* line, this tool will output the correctly tab indented shell code.
*/
int main(int argc, char *argv[]) {
FILE *f;
int i, n, t;
char *sym, tabs[64];
ShowCrashReports();
f = fopen("/tmp/syms.txt", "r");
memset(tabs, '\t', 64);
while ((sym = _chomp(xgetline(f)))) {
if (strlen(sym)) {
printf("imp\t");
/* what we call the symbol */
i = printf("'%s'", sym);
t = 0;
n = 56;
if (i % 8) ++t, i = ROUNDUP(i, 8);
t += (n - i) / 8;
printf("%.*s", t, tabs);
/* what the kernel dll calls the symbol */
i = printf("%s", sym);
t = 0;
n = 56;
if (i % 8) ++t, i = ROUNDUP(i, 8);
t += (n - i) / 8;
printf("%.*s", t, tabs);
/* dll short name */
i = printf("%s", DLL);
t = 0;
n = 16;
if (i % 8) ++t, i = ROUNDUP(i, 8);
t += (n - i) / 8;
printf("%.*s", t, tabs);
/* hint */
i = printf("0");
t = 0;
n = 8;
if (i % 8) ++t, i = ROUNDUP(i, 8);
t += (n - i) / 8;
printf("%.*s", t, tabs);
printf("\n");
}
free(sym);
}
return 0;
}

View file

@ -1,45 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/tty/quant.h"
#include "dsp/tty/xtermname.h"
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
int main(int argc, char *argv[]) {
int i;
struct TtyRgb tty;
unsigned rgb, r, g, b;
if (argc < 2) {
fprintf(stderr, "Usage: %s RRGGBB...\n", program_invocation_name);
exit(EX_USAGE);
}
for (i = 1; i < argc; ++i) {
rgb = strtol(argv[i], NULL, 16);
b = (rgb & 0x0000ff) >> 000;
g = (rgb & 0x00ff00) >> 010;
r = (rgb & 0xff0000) >> 020;
tty = rgb2tty(r, g, b);
printf("\e[48;5;%dm \e[0m %d \\e[48;5;%dm %s #%02x%02x%02x\n", tty.xt,
tty.xt, tty.xt, IndexDoubleNulString(kXtermName, tty.xt), r, g, b);
}
return 0;
}

View file

@ -1,135 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/tty/quant.h"
#include "libc/calls/calls.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/fileno.h"
#include "third_party/getopt/getopt.internal.h"
#define kUsage \
"Usage:\n\
\n\
%s [-cber] [-o FILE] [ARGS...]\n\
\n\
Flags:\n\
\n\
-e enable emphasis\n\
-b emit as background color\n\
-r print raw codes\n\
-c emit cleanup (reset) codes when done\n\
-o FILE redirects output [default: /dev/stdout]\n\
\n\
Arguments:\n\
\n\
- may be passed via ARGS or STDIN (one per line)\n\
- may be #RRGGBB or RRGGBB\n\
- may be #RGB or RGB (#123 #112233)\n\
- anything else is printed verbatim\n\
\n"
static FILE *fout_;
static size_t linecap_;
static char *outpath_, *line_;
static bool rawmode_, background_, emphasis_, cleanup_;
wontreturn void usage(int rc, FILE *f) {
fprintf(f, kUsage, program_invocation_name);
exit(rc);
}
void getopts(int *argc, char *argv[]) {
int opt;
outpath_ = "-";
while ((opt = getopt(*argc, argv, "?hrecbo:")) != -1) {
switch (opt) {
case 'r':
rawmode_ = true;
break;
case 'b':
background_ = true;
break;
case 'c':
cleanup_ = true;
break;
case 'e':
emphasis_ = true;
break;
case 'o':
outpath_ = optarg;
break;
case '?':
case 'h':
usage(EXIT_SUCCESS, stdout);
default:
usage(EX_USAGE, stderr);
}
}
}
void processarg(const char *arg) {
const char *p;
size_t r, g, b;
if (*(p = arg) == '#') p++;
if (strlen(p) == 3 && (isxdigit(p[0]) && isxdigit(p[1]) && isxdigit(p[2]))) {
r = hextoint(p[0]) << 4 | hextoint(p[0]);
g = hextoint(p[1]) << 4 | hextoint(p[1]);
b = hextoint(p[2]) << 4 | hextoint(p[2]);
} else if (strlen(p) == 6 &&
(isxdigit(p[0]) && isxdigit(p[1]) && isxdigit(p[2]) &&
isxdigit(p[3]) && isxdigit(p[4]) && isxdigit(p[5]))) {
r = hextoint(p[0]) << 4 | hextoint(p[1]);
g = hextoint(p[2]) << 4 | hextoint(p[3]);
b = hextoint(p[4]) << 4 | hextoint(p[5]);
} else {
fputs(arg, fout_);
return;
}
fprintf(fout_, "%s[%s%d;5;%hhum%s", rawmode_ ? "\e" : "\\e",
emphasis_ ? "1;" : "", background_ ? 48 : 38, rgb2tty(r, g, b).xt,
&"\n"[rawmode_]);
}
int main(int argc, char *argv[]) {
size_t i;
getopts(&argc, argv);
CHECK_NOTNULL((fout_ = fopen(outpath_, "w")));
if (optind < argc) {
for (i = optind; i < argc; ++i) {
processarg(argv[i]);
}
} else {
while ((getline(&line_, &linecap_, stdin)) != -1) {
processarg(_chomp(line_));
}
free(line_);
line_ = 0;
}
if (cleanup_) {
fprintf(fout_, "%s[0m\n", rawmode_ ? "\e" : "\\e");
}
CHECK_NE(-1, fclose(fout_));
fout_ = 0;
return 0;
}

View file

@ -1,34 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/math.h"
#include "libc/stdio/stdio.h"
int main(int argc, char *argv[]) {
int i, x, y;
for (i = 1; i < argc; ++i) {
x = atoi(argv[i]);
y = round(
(1.923 * cbrt(x * log(2)) * cbrt(log(x * log(2)) * log(x * log(2))) -
4.69) /
log(2));
printf("%4d %4d\n", x, y);
}
return 0;
}

View file

@ -1,177 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/arraylist.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/strwidth.h"
#include "libc/str/unicode.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/getopt/getopt.internal.h"
#define kOneTrueTabWidth 8
struct Pool {
size_t i, n;
char *p;
};
struct Lines {
size_t i, n;
struct Line {
uint16_t off;
uint16_t col;
int32_t line;
} * p;
};
static bool chunk_;
static FILE *fi_, *fo_;
static struct Pool pool_;
static struct Lines lines_;
static size_t mincol_, col_, maxcol_, linecap_;
static char *inpath_, *outpath_, *delim_, *line_;
wontreturn void usage(int rc, FILE *f) {
fprintf(f, "%s%s%s\n", "Usage: ", program_invocation_name,
" [-c] [-m MINCOL] [-M MAXCOL] [-F DELIM] [-o FILE] [FILE...]\n"
"\n"
" This program aligns monospace text. It's aware of tabs,\n"
" color codes, wide characters, combining characters etc.\n");
exit(rc);
}
void getopts(int *argc, char *argv[]) {
int opt;
delim_ = "#";
outpath_ = "-";
while ((opt = getopt(*argc, argv, "?hco:m:M:F:")) != -1) {
switch (opt) {
case 'm':
mincol_ = strtol(optarg, NULL, 0);
break;
case 'M':
maxcol_ = strtol(optarg, NULL, 0);
break;
case 'c':
chunk_ = true;
break;
case 'o':
outpath_ = optarg;
break;
case 'F':
delim_ = optarg;
break;
case '?':
case 'h':
usage(EXIT_SUCCESS, stdout);
default:
usage(EX_USAGE, stderr);
}
}
if (optind == *argc) {
argv[(*argc)++] = "-";
}
}
void flush(void) {
size_t i, j;
const char *s;
struct Line l;
col_ = roundup(col_ + 1, kOneTrueTabWidth);
if (maxcol_) col_ = min(col_, maxcol_);
for (i = 0; i < lines_.i; ++i) {
l = lines_.p[i];
s = &pool_.p[l.line];
if (l.off < USHRT_MAX) {
fwrite(s, l.off, 1, fo_);
for (j = l.col; j < col_;) {
fputc('\t', fo_);
if (j % kOneTrueTabWidth == 0) {
j += 8;
} else {
j += kOneTrueTabWidth - (j & (kOneTrueTabWidth - 1));
}
}
fwrite(s + l.off, strlen(s) - l.off, 1, fo_);
} else {
fwrite(s, strlen(s), 1, fo_);
}
fputc('\n', fo_);
}
col_ = mincol_;
pool_.i = 0;
lines_.i = 0;
}
void processfile(void) {
char *p;
int col, s;
size_t off, len;
while ((getline(&line_, &linecap_, fi_)) != -1) {
_chomp(line_);
len = strlen(line_);
s = concat(&pool_, line_, len + 1);
if (len < USHRT_MAX) {
if ((p = strstr(line_, delim_))) {
off = p - line_;
col = strnwidth(line_, off, 0);
if (col < USHRT_MAX) {
col_ = max(col_, col);
append(&lines_, &((struct Line){.line = s, .off = off, .col = col}));
continue;
}
} else {
if (chunk_) {
flush();
fputs(line_, fo_);
fputc('\n', fo_);
continue;
}
}
}
append(&lines_, &((struct Line){.line = s, .off = 0xffff, .col = 0xffff}));
}
}
int main(int argc, char *argv[]) {
size_t i;
getopts(&argc, argv);
CHECK_NOTNULL((fo_ = fopen(outpath_, "w")));
for (i = optind; i < argc; ++i) {
CHECK_NOTNULL((fi_ = fopen((inpath_ = argv[i]), "r")));
processfile();
CHECK_NE(-1, fclose(fi_));
fi_ = 0;
}
flush();
CHECK_NE(-1, fclose(fo_));
fo_ = 0;
free(lines_.p);
free(pool_.p);
free(line_);
return 0;
}

View file

@ -1,156 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/intrin/bits.h"
#include "libc/stdio/stdio.h"
// clang-format off
static char ip[] = "\
\x45\x00\x00\x3c\xc8\xbc\x40\x00\x40\x06\x48\xf6\x7f\x0a\x0a\x7a\
\x7f\x0a\x0a\x7c\xe2\x24\x1b\x58\xf6\xe9\xf2\x85\x00\x00\x00\x00\
\xa0\x02\xfa\xf0\x5f\xac\x00\x00\x02\x04\x05\xb4\x04\x02\x08\x0a\
\x4a\x43\x93\x29\x00\x00\x00\x00\x01\x03\x03\x07";
static const char *const kTcpOptionNames[] = {
[0] = "End of Option List",
[1] = "No-Operation",
[2] = "Maximum Segment Size",
[3] = "Window Scale",
[4] = "SACK Permitted",
[5] = "SACK",
[6] = "Echo (obsoleted by option 8)",
[7] = "Echo Reply (obsoleted by option 8)",
[8] = "Timestamps",
[9] = "Partial Order Connection Permitted (obsolete)",
[10] = "Partial Order Service Profile (obsolete)",
[11] = "CC (obsolete)",
[12] = "CC.NEW (obsolete)",
[13] = "CC.ECHO (obsolete)",
[14] = "TCP Alternate Checksum Request (obsolete)",
[15] = "TCP Alternate Checksum Data (obsolete)",
[16] = "Skeeter",
[17] = "Bubba",
[18] = "Trailer Checksum Option",
[19] = "MD5 Signature Option (obsoleted by option 29)",
[20] = "SCPS Capabilities",
[21] = "Selective Negative Acknowledgements",
[22] = "Record Boundaries",
[23] = "Corruption experienced",
[24] = "SNAP",
[25] = "Unassigned (released 2000-12-18)",
[26] = "TCP Compression Filter",
[27] = "Quick-Start Response",
[28] = "User Timeout Option",
[29] = "TCP Authentication Option (TCP-AO)",
[30] = "Multipath TCP (MPTCP)",
[31] = "Reserved (known unauthorized use without proper IANA assignm",
[32] = "Reserved (known unauthorized use without proper IANA assignm",
[33] = "Reserved (known unauthorized use without proper IANA assignm",
[34] = "variable TCP Fast Open Cookie",
[35] = "Reserved",
[69] = "Encryption Negotiation",
[253] = "RFC3692-1",
[254] = "RFC3692-2",
};
int main(int argc, char *argv[]) {
int version = (ip[0] & 0b11110000) >> 4;
int ihl = (ip[0] & 0b00001111) >> 0;
int dscp = (ip[1] & 0b11111100) >> 2;
int ecn = (ip[1] & 0b00000011) >> 0;
int lengthtotal = READ16BE(ip + 2);
int identification = READ16BE(ip + 4);
int flags = (ip[6] & 0b11100000) >> 5;
int fragmentoffset = (ip[6] & 0b00011111) << 8 | (ip[7] & 255);
int ttl = ip[8] & 255;
int protocol = ip[9] & 255;
int ipchecksum = (ip[10] & 255) << 8 | (ip[11] & 255);
int srcip = READ32BE(ip + 12);
int dstip = READ32BE(ip + 16);
printf("\n");
printf("// version = %u\n", version);
printf("// ihl = %u\n", ihl * 4);
printf("// dscp = %u\n", dscp);
printf("// ecn = %u\n", ecn);
printf("// lengthtotal = %u\n", lengthtotal);
printf("// identification = %u\n", identification);
printf("// flags = %u\n", flags);
printf("// fragmentoffset = %u\n", fragmentoffset);
printf("// ttl = %u\n", ttl);
printf("// protocol = %u\n", protocol);
printf("// ipchecksum = %u\n", ipchecksum);
printf("// srcip = %hhu.%hhu.%hhu.%hhu\n", srcip >> 24, srcip >> 16, srcip >> 8, srcip);
printf("// dstip = %hhu.%hhu.%hhu.%hhu\n", dstip >> 24, dstip >> 16, dstip >> 8, dstip);
printf("// \n");
char *tcp = ip + ihl * 4;
int srcport = READ16BE(tcp + 0);
int dstport = READ16BE(tcp + 2);
int sequence = READ32BE(tcp + 4);
int acknumber = READ32BE(tcp + 8);
int dataoffset = (tcp[12] & 0b11110000) >> 4;
bool ns = !!(tcp[12] & 0b00000001);
bool cwr = !!(tcp[13] & 0b10000000);
bool ece = !!(tcp[13] & 0b01000000);
bool urg = !!(tcp[13] & 0b00100000);
bool ack = !!(tcp[13] & 0b00010000);
bool psh = !!(tcp[13] & 0b00001000);
bool rst = !!(tcp[13] & 0b00000100);
bool syn = !!(tcp[13] & 0b00000010);
bool fin = !!(tcp[13] & 0b00000001);
int wsize = READ16BE(tcp + 14);
int tcpchecksum = READ16BE(tcp + 16);
int urgpointer = READ16BE(tcp + 18);
printf("// srcport = %u\n", srcport);
printf("// dstport = %u\n", dstport);
printf("// sequence = %u\n", sequence);
printf("// acknumber = %u\n", acknumber);
printf("// dataoffset = %u\n", dataoffset);
printf("// ns = %u\n", ns);
printf("// cwr = %u\n", cwr);
printf("// ece = %u\n", ece);
printf("// urg = %u\n", urg);
printf("// ack = %u\n", ack);
printf("// psh = %u\n", psh);
printf("// rst = %u\n", rst);
printf("// syn = %u\n", syn);
printf("// fin = %u\n", fin);
printf("// wsize = %u\n", wsize);
printf("// tcpchecksum = %u\n", tcpchecksum);
printf("// urgpointer = %u\n", urgpointer);
printf("// \n");
int c, i, j, n;
for (i = 20; i + 1 < dataoffset * 4;) {
printf("// option");
switch ((c = tcp[i] & 255)) {
case 0:
case 1:
printf(" %u", c);
++i;
break;
default:
n = tcp[i + 1] & 255;
printf(" %u %u", c, n);
for (j = 2; j < n; ++j) {
printf(" %u", tcp[i + j] & 255);
}
i += n;
break;
}
if (kTcpOptionNames[c]) {
printf(" (%s)", kTcpOptionNames[c]);
}
printf("\n");
}
return 0;
}

View file

@ -1,91 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/unicode.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/x/xasprintf.h"
int a, b, w, i;
char name[512];
void DisplayUnicodeCharacter(void) {
int c, cw;
c = i;
cw = wcwidth(c);
if (cw < 1) {
c = '?';
cw = 1;
}
if (w) {
if (w + 1 + cw > 80) {
printf("\n");
w = 0;
} else {
fputc(' ', stdout);
w += 1 + cw;
}
}
if (!w) {
printf("%08x ", i);
w = 9 + cw;
}
fputwc(c, stdout);
}
void DisplayUnicodeBlock(void) {
if (a == 0x10000) {
printf("\n\n\n\n\n\n\n "
"ASTRAL PLANES\n\n\n\n\n");
}
if (a == 0x0590 /* hebrew */) return;
if (a == 0x0600 /* arabic */) return;
if (a == 0x08a0 /* arabic */) return;
if (a == 0x0750 /* arabic */) return;
if (a == 0x0700 /* syriac */) return;
if (a == 0x10800 /* cypriot */) return;
printf("\n\n%-60s%20s\n"
"──────────────────────────────────────────────"
"──────────────────────────────────\n",
name, _gc(xasprintf("%04x .. %04x", a, b)));
w = 0;
for (i = a; i <= b; ++i) {
DisplayUnicodeCharacter();
}
}
int main(int argc, char *argv[]) {
FILE *f;
char *line;
size_t linesize;
printf("\n\n\n\n\n UNICODE PLANES\n\n\n\n");
f = fopen("libc/str/blocks.txt", "r");
line = NULL;
linesize = 0;
while (!feof(f)) {
if (getline(&line, &linesize, f) == -1) break;
if (sscanf(line, "%x..%x; %s", &a, &b, name) != 3) continue;
DisplayUnicodeBlock();
}
free(line);
fclose(f);
return 0;
}

View file

@ -1,212 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/x/x.h"
#include "third_party/stb/stb_image.h"
#define C13(A, B) (((A) + 3 * (B)) / 4)
#define S3T(A, B, C) MAX(0, ((24 * (B)) - (4 * ((A) + (C)))) / 16)
#define LERP(A, B, P) ((A) * (1 - (P)) + (B) * (P))
float ByteToFloat(int b) {
return 1 / 255.f * b;
}
int FloatToByte(float f) {
return MAX(0, MIN(255, roundf(255 * f)));
}
float ChessBoard(unsigned y, unsigned x, float a, float b) {
return !((y ^ x) & (1u << 2)) ? a : b;
}
float AlphaBackground(unsigned y, unsigned x) {
return ChessBoard(y, x, 1.f, .7f);
}
float OutOfBoundsBackground(unsigned y, unsigned x) {
return ChessBoard(y, x, .01f, .02f);
}
float Opacify(size_t yn, size_t xn, const float P[yn][xn],
const float A[yn][xn], long y, long x) {
if ((0 <= y && y < yn) && (0 <= x && x < xn)) {
return LERP(AlphaBackground(y, x), P[y][x], A[y][x]);
} else {
return OutOfBoundsBackground(y, x);
}
}
void PrintImage(size_t yn, size_t xn, float R[yn][xn], float G[yn][xn],
float B[yn][xn], float A[yn][xn]) {
unsigned y, x;
for (y = 0; y < yn; y += 2) {
if (y) printf("\e[0m\n");
for (x = 0; x < xn; ++x) {
printf("\e[48;2;%d;%d;%d;38;2;%d;%d;%dm▄",
FloatToByte(Opacify(yn, xn, R, A, y + 0, x)),
FloatToByte(Opacify(yn, xn, G, A, y + 0, x)),
FloatToByte(Opacify(yn, xn, B, A, y + 0, x)),
FloatToByte(Opacify(yn, xn, R, A, y + 1, x)),
FloatToByte(Opacify(yn, xn, G, A, y + 1, x)),
FloatToByte(Opacify(yn, xn, B, A, y + 1, x)));
}
}
printf("\e[0m\n");
}
void DeblinterlaceRgba(size_t dyn, size_t dxn, float R[dyn][dxn],
float G[dyn][dxn], float B[dyn][dxn], float A[dyn][dxn],
size_t syn, size_t sxn,
const unsigned char src[syn][sxn][4]) {
unsigned y, x;
for (y = 0; y < syn; ++y) {
for (x = 0; x < sxn; ++x) {
R[y][x] = ByteToFloat(src[y][x][0]);
G[y][x] = ByteToFloat(src[y][x][1]);
B[y][x] = ByteToFloat(src[y][x][2]);
A[y][x] = ByteToFloat(src[y][x][3]);
}
}
}
void SharpenX(size_t yw, size_t xw, float dst[yw][xw], const float src[yw][xw],
size_t yn, size_t xn) {
int y, x;
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
dst[y][x] =
S3T(src[y][MAX(0, x - 1)], src[y][x], src[y][MIN(xn - 1, x + 1)]);
}
}
}
void SharpenY(size_t yw, size_t xw, float dst[yw][xw], const float src[yw][xw],
size_t yn, size_t xn) {
int y, x;
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
dst[y][x] =
S3T(src[MAX(0, y - 1)][x], src[y][x], src[MIN(yn - 1, y + 1)][x]);
}
}
}
void UpscaleX(size_t yw, size_t xw, float img[yw][xw], size_t yn, size_t xn) {
unsigned y, x;
for (y = yn; y--;) {
for (x = xn; --x;) {
img[y][x] =
C13(img[y][MIN(xn / 2 - 1, x / 2 - 1 + x % 2 * 2)], img[y][x / 2]);
}
}
}
void UpscaleY(size_t yw, size_t xw, float img[yw][xw], size_t yn, size_t xn) {
unsigned y, x;
for (y = yn; --y;) {
for (x = xn; x--;) {
img[y][x] =
C13(img[MIN(yn / 2 - 1, y / 2 - 1 + y % 2 * 2)][x], img[y / 2][x]);
}
}
}
void Upscale(size_t yw, size_t xw, float img[yw][xw], float tmp[yw][xw],
size_t yn, size_t xn) {
UpscaleY(yw, xw, img, yn, xn / 2);
SharpenY(yw, xw, tmp, img, yn, xn / 2);
UpscaleX(yw, xw, tmp, yn, xn);
SharpenX(yw, xw, img, tmp, yn, xn);
}
void ProcessImageDouble(size_t yn, size_t xn, unsigned char img[yn][xn][4]) {
void *t = xmemalign(32, sizeof(float) * yn * 2 * xn * 2);
void *R = xmemalign(32, sizeof(float) * yn * 2 * xn * 2);
void *G = xmemalign(32, sizeof(float) * yn * 2 * xn * 2);
void *B = xmemalign(32, sizeof(float) * yn * 2 * xn * 2);
void *A = xmemalign(32, sizeof(float) * yn * 2 * xn * 2);
DeblinterlaceRgba(yn * 2, xn * 2, R, G, B, A, yn, xn, img);
Upscale(yn * 2, xn * 2, R, t, yn * 2, xn * 2);
Upscale(yn * 2, xn * 2, G, t, yn * 2, xn * 2);
Upscale(yn * 2, xn * 2, B, t, yn * 2, xn * 2);
Upscale(yn * 2, xn * 2, A, t, yn * 2, xn * 2);
free(t);
PrintImage(yn * 2, xn * 2, R, G, B, A);
free(R);
free(G);
free(B);
free(A);
}
void ProcessImage(size_t yn, size_t xn, unsigned char img[yn][xn][4]) {
void *R = xmemalign(32, sizeof(float) * yn * xn);
void *G = xmemalign(32, sizeof(float) * yn * xn);
void *B = xmemalign(32, sizeof(float) * yn * xn);
void *A = xmemalign(32, sizeof(float) * yn * xn);
DeblinterlaceRgba(yn, xn, R, G, B, A, yn, xn, img);
PrintImage(yn, xn, R, G, B, A);
free(R);
free(G);
free(B);
free(A);
}
void WithImageFile(const char *path, void fn(size_t yn, size_t xn,
unsigned char img[yn][xn][4])) {
struct stat st;
int fd, yn, xn;
void *map, *data;
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
CHECK_NE(-1, fstat(fd, &st));
CHECK_GT(st.st_size, 0);
CHECK_LE(st.st_size, INT_MAX);
fadvise(fd, 0, 0, MADV_WILLNEED | MADV_SEQUENTIAL);
CHECK_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
CHECK_NOTNULL(
(data = stbi_load_from_memory(map, st.st_size, &xn, &yn, NULL, 4)), "%s",
path);
CHECK_NE(-1, munmap(map, st.st_size));
CHECK_NE(-1, close(fd));
fn(yn, xn, data);
free(data);
}
int main(int argc, char *argv[]) {
int i;
for (i = 1; i < argc; ++i) {
WithImageFile(argv[i], ProcessImageDouble);
}
return 0;
}

View file

@ -1,209 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/x/x.h"
#include "third_party/stb/stb_image.h"
#define CLAMP(X) MAX(0, MIN(255, X))
#define C13(A, B) (((A) + 3 * (B) + 2) >> 2)
#define S3T(A, B, C) CLAMP(-((A) >> 2) + ((B) + ((B) >> 1)) + -((C) >> 2))
#define LERP(X, Y, P) ((X) + (((P) * ((Y) - (X))) >> 8))
static unsigned char ChessBoard(unsigned y, unsigned x, unsigned char a,
unsigned char b) {
return !((y ^ x) & (1u << 2)) ? a : b;
}
static unsigned char AlphaBackground(unsigned y, unsigned x) {
return ChessBoard(y, x, 255, 200);
}
static unsigned char OutOfBoundsBackground(unsigned y, unsigned x) {
return ChessBoard(y, x, 40, 80);
}
static unsigned char Opacify(size_t yn, size_t xn,
const unsigned char P[yn][xn],
const unsigned char A[yn][xn], long y, long x) {
if ((0 <= y && y < yn) && (0 <= x && x < xn)) {
return LERP(AlphaBackground(y, x), P[y][x], A[y][x]);
} else {
return OutOfBoundsBackground(y, x);
}
}
static void PrintImage(size_t yn, size_t xn, unsigned char R[yn][xn],
unsigned char G[yn][xn], unsigned char B[yn][xn],
unsigned char A[yn][xn]) {
unsigned y, x;
for (y = 0; y < yn; y += 2) {
if (y) printf("\e[0m\n");
for (x = 0; x < xn; ++x) {
printf("\e[48;2;%d;%d;%d;38;2;%d;%d;%dm▄",
Opacify(yn, xn, R, A, y + 0, x), Opacify(yn, xn, G, A, y + 0, x),
Opacify(yn, xn, B, A, y + 0, x), Opacify(yn, xn, R, A, y + 1, x),
Opacify(yn, xn, G, A, y + 1, x), Opacify(yn, xn, B, A, y + 1, x));
}
}
printf("\e[0m\n");
}
static void DeblinterlaceRgba(size_t dyn, size_t dxn, unsigned char R[dyn][dxn],
unsigned char G[dyn][dxn],
unsigned char B[dyn][dxn],
unsigned char A[dyn][dxn], size_t syn, size_t sxn,
const unsigned char src[syn][sxn][4]) {
unsigned y, x;
for (y = 0; y < syn; ++y) {
for (x = 0; x < sxn; ++x) {
R[y][x] = src[y][x][0];
G[y][x] = src[y][x][1];
B[y][x] = src[y][x][2];
A[y][x] = src[y][x][3];
}
}
}
static void SharpenX(size_t yw, size_t xw, unsigned char dst[yw][xw],
const unsigned char src[yw][xw], size_t yn, size_t xn) {
int y, x;
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
dst[y][x] =
S3T(src[y][MAX(0, x - 1)], src[y][x], src[y][MIN(xn - 1, x + 1)]);
}
}
}
static void SharpenY(size_t yw, size_t xw, unsigned char dst[yw][xw],
const unsigned char src[yw][xw], size_t yn, size_t xn) {
int y, x;
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
dst[y][x] =
S3T(src[MAX(0, y - 1)][x], src[y][x], src[MIN(yn - 1, y + 1)][x]);
}
}
}
static void UpscaleX(size_t yw, size_t xw, unsigned char img[yw][xw], size_t yn,
size_t xn) {
unsigned y, x;
for (y = yn; y--;) {
for (x = xn; --x;) {
img[y][x] =
C13(img[y][MIN(xn / 2 - 1, x / 2 - 1 + x % 2 * 2)], img[y][x / 2]);
}
}
}
static void UpscaleY(size_t yw, size_t xw, unsigned char img[yw][xw], size_t yn,
size_t xn) {
unsigned y, x;
for (y = yn; --y;) {
for (x = xn; x--;) {
img[y][x] =
C13(img[MIN(yn / 2 - 1, y / 2 - 1 + y % 2 * 2)][x], img[y / 2][x]);
}
}
}
static void Upscale(size_t yw, size_t xw, unsigned char img[yw][xw],
unsigned char tmp[yw][xw], size_t yn, size_t xn) {
UpscaleY(yw, xw, img, yn, xn / 2);
SharpenY(yw, xw, tmp, img, yn, xn / 2);
UpscaleX(yw, xw, tmp, yn, xn);
SharpenX(yw, xw, img, tmp, yn, xn);
}
static void ProcessImageDouble(size_t yn, size_t xn,
unsigned char img[yn][xn][4]) {
void *t = xmemalign(32, sizeof(unsigned char) * yn * 2 * xn * 2);
void *R = xmemalign(32, sizeof(unsigned char) * yn * 2 * xn * 2);
void *G = xmemalign(32, sizeof(unsigned char) * yn * 2 * xn * 2);
void *B = xmemalign(32, sizeof(unsigned char) * yn * 2 * xn * 2);
void *A = xmemalign(32, sizeof(unsigned char) * yn * 2 * xn * 2);
DeblinterlaceRgba(yn * 2, xn * 2, R, G, B, A, yn, xn, img);
Upscale(yn * 2, xn * 2, R, t, yn * 2, xn * 2);
Upscale(yn * 2, xn * 2, G, t, yn * 2, xn * 2);
Upscale(yn * 2, xn * 2, B, t, yn * 2, xn * 2);
Upscale(yn * 2, xn * 2, A, t, yn * 2, xn * 2);
free(t);
PrintImage(yn * 2, xn * 2, R, G, B, A);
free(R);
free(G);
free(B);
free(A);
}
static void ProcessImage(size_t yn, size_t xn, unsigned char img[yn][xn][4]) {
void *R = xmemalign(32, sizeof(unsigned char) * yn * xn);
void *G = xmemalign(32, sizeof(unsigned char) * yn * xn);
void *B = xmemalign(32, sizeof(unsigned char) * yn * xn);
void *A = xmemalign(32, sizeof(unsigned char) * yn * xn);
DeblinterlaceRgba(yn, xn, R, G, B, A, yn, xn, img);
PrintImage(yn, xn, R, G, B, A);
free(R);
free(G);
free(B);
free(A);
}
void WithImageFile(const char *path, void fn(size_t yn, size_t xn,
unsigned char img[yn][xn][4])) {
struct stat st;
int fd, yn, xn;
void *map, *data;
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
CHECK_NE(-1, fstat(fd, &st));
CHECK_GT(st.st_size, 0);
CHECK_LE(st.st_size, INT_MAX);
fadvise(fd, 0, 0, MADV_WILLNEED | MADV_SEQUENTIAL);
CHECK_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
CHECK_NOTNULL(
(data = stbi_load_from_memory(map, st.st_size, &xn, &yn, NULL, 4)), "%s",
path);
CHECK_NE(-1, munmap(map, st.st_size));
CHECK_NE(-1, close(fd));
fn(yn, xn, data);
free(data);
}
int main(int argc, char *argv[]) {
int i;
for (i = 1; i < argc; ++i) {
WithImageFile(argv[i], ProcessImageDouble);
}
return 0;
}

View file

@ -1,85 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/ucontext.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sig.h"
#include "third_party/xed/x86.h"
#ifdef __x86_64__
#define OUTPATH "vdso.elf"
volatile bool finished;
void OnSegmentationFault(int sig, siginfo_t *si, void *vctx) {
struct XedDecodedInst xedd;
ucontext_t *ctx = vctx;
xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64);
xed_instruction_length_decode(&xedd, (void *)ctx->uc_mcontext.rip, 15);
ctx->uc_mcontext.rip += xedd.length;
finished = true;
}
int main(int argc, char *argv[]) {
FILE *f;
int byte;
volatile unsigned char *vdso, *p;
vdso = (unsigned char *)getauxval(AT_SYSINFO_EHDR);
if (vdso) {
fprintf(stderr, "vdso found at address %p\n", vdso);
} else {
fprintf(stderr, "error: AT_SYSINFO_EHDR was not in auxiliary values\n");
return 1;
}
f = fopen(OUTPATH, "wb");
if (!f) {
fprintf(stderr, "error: fopen(%`'s) failed\n", OUTPATH);
return 1;
}
struct sigaction sa = {
.sa_sigaction = OnSegmentationFault,
.sa_flags = SA_SIGINFO,
};
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
p = vdso;
for (;;) {
byte = *p++;
if (!finished) {
fputc(byte, f);
} else {
break;
}
}
fclose(f);
fprintf(stderr, "%zu bytes dumped to %s\n", p - vdso, OUTPATH);
return 0;
}
#endif /* __x86_64__ */

View file

@ -1,166 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/elf/def.h"
#include "libc/elf/scalar.h"
#include "libc/elf/struct/ehdr.h"
#include "libc/elf/struct/phdr.h"
#include "libc/elf/struct/sym.h"
#include "libc/elf/struct/verdaux.h"
#include "libc/elf/struct/verdef.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h"
static inline void PrintDsoSymbolVersions(Elf64_Verdef *vd, int sym,
char *strtab) {
Elf64_Verdaux *aux;
for (;; vd = (Elf64_Verdef *)((char *)vd + vd->vd_next)) {
if (!(vd->vd_flags & VER_FLG_BASE) &&
(vd->vd_ndx & 0x7fff) == (sym & 0x7fff)) {
aux = (Elf64_Verdaux *)((char *)vd + vd->vd_aux);
kprintf(" %s", strtab + aux->vda_name);
}
if (!vd->vd_next) {
break;
}
}
}
int PrintVdsoSymbols(void) {
void *p;
size_t i;
Elf64_Ehdr *ehdr;
Elf64_Phdr *phdr;
char *strtab = 0;
size_t *dyn, base;
unsigned long *ap;
Elf64_Sym *symtab = 0;
uint16_t *versym = 0;
Elf_Symndx *hashtab = 0;
Elf64_Verdef *verdef = 0;
const char *typename, *bindname;
for (ehdr = 0, ap = __auxv; ap[0]; ap += 2) {
if (ap[0] == AT_SYSINFO_EHDR) {
ehdr = (void *)ap[1];
break;
}
}
if (!ehdr) {
kprintf("error: AT_SYSINFO_EHDR not found\n");
return 1;
}
phdr = (void *)((char *)ehdr + ehdr->e_phoff);
for (base = -1, dyn = 0, i = 0; i < ehdr->e_phnum;
i++, phdr = (void *)((char *)phdr + ehdr->e_phentsize)) {
switch (phdr->p_type) {
case PT_LOAD:
// modern linux uses the base address zero, but elders
// e.g. rhel7 uses the base address 0xffffffffff700000
base = (size_t)ehdr + phdr->p_offset - phdr->p_vaddr;
break;
case PT_DYNAMIC:
dyn = (void *)((char *)ehdr + phdr->p_offset);
break;
default:
break;
}
}
if (!dyn || base == -1) {
kprintf("error: missing program headers\n");
return 2;
}
for (i = 0; dyn[i]; i += 2) {
p = (void *)(base + dyn[i + 1]);
switch (dyn[i]) {
case DT_STRTAB:
strtab = p;
break;
case DT_SYMTAB:
symtab = p;
break;
case DT_HASH:
hashtab = p;
break;
case DT_VERSYM:
versym = p;
break;
case DT_VERDEF:
verdef = p;
break;
}
}
if (!verdef) {
versym = 0;
}
if (!strtab || !symtab || !hashtab) {
kprintf("error: strtab/symtab/hashtab not found\n");
return 3;
}
for (i = 0; i < hashtab[1]; i++) {
if (!symtab[i].st_shndx) {
continue;
}
switch (ELF64_ST_BIND(symtab[i].st_info)) {
case STB_LOCAL:
bindname = "locl";
break;
case STB_GLOBAL:
bindname = "glob";
break;
case STB_WEAK:
bindname = "weak";
break;
default:
bindname = "????";
break;
}
switch (ELF64_ST_TYPE(symtab[i].st_info)) {
case STT_FUNC:
typename = "func";
break;
case STT_OBJECT:
typename = " obj";
break;
case STT_NOTYPE:
typename = "none";
break;
default:
typename = "????";
break;
}
kprintf("%s %s %-40s", bindname, typename, strtab + symtab[i].st_name);
PrintDsoSymbolVersions(verdef, versym[i], strtab);
kprintf("\n");
}
return 0;
}
int main(int argc, char *argv[]) {
return PrintVdsoSymbols();
}

View file

@ -1,97 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/stdio/stdio.h"
#define DIST(X, Y) ((X) - (Y))
#define SQR(X) ((X) * (X))
#define SUM(X, Y, Z) ((X) + (Y) + (Z))
static const uint8_t kXtermCube[] = {0, 0137, 0207, 0257, 0327, 0377};
static int uncube(int x) {
return x < 48 ? 0 : x < 115 ? 1 : (x - 35) / 40;
}
static int rgb2xterm256(int r, int g, int b) {
unsigned av, ir, ig, ib, il, qr, qg, qb, ql;
av = (r + g + b) / 3;
ql = (il = av > 238 ? 23 : (av - 3) / 10) * 10 + 8;
qr = kXtermCube[(ir = uncube(r))];
qg = kXtermCube[(ig = uncube(g))];
qb = kXtermCube[(ib = uncube(b))];
if (SUM(SQR(DIST(qr, r)), SQR(DIST(qg, g)), SQR(DIST(qb, b))) <=
SUM(SQR(DIST(ql, r)), SQR(DIST(ql, g)), SQR(DIST(ql, b)))) {
return ir * 36 + ig * 6 + ib + 020;
} else {
return il + 0350;
}
}
bool IsUglyColorMixture(int rune, int y, int tone, bool toneisfg) {
assert(tone == 16 || (231 <= tone && tone <= 255));
return false;
}
int main(int argc, char *argv[]) {
unsigned y, z, x, k, w;
static const char16_t s[2][3] = {{u'', u'', u''}, {u'', u'', u''}};
printf("\npure\n");
for (y = 0; y < 6; ++y) {
for (z = 0; z < 6; ++z) {
for (x = 0; x < 6; ++x) {
printf("\033[48;5;%hhum ", 16 + x + y * 6 + z * 6 * 6);
}
printf("\033[0m ");
}
printf("\n");
}
#define MIX(NAME, COLOR) \
do { \
printf("\n%s %d ▓░/▒▒/░▓\n", NAME, COLOR); \
for (k = 0; k < 3; ++k) { \
for (y = 0; y < 6; ++y) { \
for (z = 0; z < 6; ++z) { \
for (x = 0; x < 6; ++x) { \
printf("\033[48;5;%hhu;38;5;%hhum%lc", COLOR, \
16 + x + y * 6 + z * 6 * 6, s[0][k]); \
printf("\033[48;5;%hhu;38;5;%hhum%lc", 16 + x + y * 6 + z * 6 * 6, \
COLOR, s[1][k]); \
} \
printf("\033[0m "); \
} \
printf("\n"); \
} \
} \
} while (0)
MIX("tint", 231);
MIX("tint", 255);
MIX("tint", 254);
MIX("tone", 240);
MIX("shade", 232);
for (w = 233; w < 254; ++w) {
MIX("gray", w);
}
return 0;
}

View file

@ -1,183 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/tty/quant.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/xchg.internal.h"
#include "libc/math.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
/* #define ROUND(x) x */
/* #define RT int */
/* #define R1 1 */
/* #define R2 2 */
/* #define R3 3 */
#define RT float
#define MUL(x, y) ((x) * (y))
#define RND(x) roundf(x)
#define R1 0.25f
#define R2 0.50f
#define R3 0.75f
#define rgb_t struct TtyRgb
forceinline RT lerp(RT x, RT y, RT d) {
return x * (1.0 - d) + y * d;
}
forceinline int lerp255(RT x, RT y, RT d) {
return lerp(x / 255.0, y / 255.0, d) * 255.0;
}
forceinline rgb_t rgblerp(rgb_t x, rgb_t y, RT d) {
return (rgb_t){lerp255(x.r, y.r, d), lerp255(x.g, y.g, d),
lerp255(x.b, y.b, d)};
}
forceinline rgb_t getquant(unsigned xt) {
return g_ansi2rgb_[xt];
}
forceinline unsigned dist(int x, int y) {
return x - y;
}
forceinline unsigned sqr(int x) {
return x * x;
}
forceinline unsigned rgbdist(rgb_t x, rgb_t y) {
return sqrt(sqr(dist(x.r, y.r)) + sqr(dist(x.g, y.g)) + sqr(dist(x.b, y.b)));
}
bool b;
rgb_t rgb, cc, c1, c2;
unsigned i, j, k, m, n, x, y;
char buf[128];
/* 0125 025 067-29 # '░' bg=0352 fg=0306 → ░░░ */
/* 0125 025 067-29 # '▓' bg=0306 fg=0352 → ▓▓▓ */
/* 0125 055 067-29 # '░' bg=0352 fg=0314 → ░░░ */
int main(int argc, char *argv[]) {
/* memcpy(g_ansi2rgb_, &kTangoPalette, sizeof(kTangoPalette)); */
/* i = 21; */
/* j = 22; */
/* c1 = getquant(i); */
/* c2 = getquant(j); */
/* cc = rgblerp(c1, c2, R1); */
/* printf("rgblerp((%3d,%3d,%3d), (%3d,%3d,%3d),4) → (%3d,%3d,%3d)\n", c1.r,
*/
/* c1.g, c1.b, c2.r, c2.g, c2.b, cc.r, cc.g, cc.b); */
/* exit(0); */
for (m = 16; m < 256; m += 6) {
for (n = 16; n < 256; n += 6) {
printf("------------------------------------------------------------\n");
i = m;
j = n;
b = false;
while (i < m + 6) {
printf("\n");
cc = getquant(i);
sprintf(buf, "\e[48;5;%dm ", i);
printf("0x%02x%02x%02x, %d,%d,0\t/* 0x%02x%02x%02x "
" + ' ' bg=%3d → %s \e[0m */\n",
cc.b, cc.g, cc.r, i, 0, getquant(i).r, getquant(i).g,
getquant(i).b, i, buf);
#if 0
sprintf(buf, "\e[38;5;%dm███", i);
printf("0x%08x 0x%02x%02x%02x\t"
" '█' fg=%3d → %s\e[0m\n",
cc.b, cc.g, cc.r, strlen(buf), i, buf);
#endif
for (x = i; x < i + 1; ++x) {
for (y = j; y < j + 1; ++y) {
for (k = 0; k < 2; ++k) {
if (x > y /* && */
/* rgbdist(getquant(x), getquant(y)) < 49744125 / 16 */ /* &&
((32
<= x && x <= 232) && (32 <= y && y <= 232))
&& */
/* (cc.r > 0137 && cc.g > 0137 && cc.b > 0137) */) {
sprintf(buf, "\e[48;5;%d;38;5;%dm░░░", x, y);
cc = rgblerp(getquant(x), getquant(y), R1);
printf("0x%02x%02x%02x, %d,%d,1\t/* 0x%02x%02x%02x + "
"0x%02x%02x%02x"
" + '░' bg=%3d fg=%3d → "
"\e[48;5;%dm \e[48;5;%dm "
"%s\e[48;2;%d;%d;%dm \e[0m */\n",
cc.b, cc.g, cc.r, x, y, getquant(x).r, getquant(x).g,
getquant(x).b, getquant(y).r, getquant(y).g,
getquant(y).b, x, y, x, y, buf, cc.r, cc.g, cc.b);
sprintf(buf, "\e[48;5;%d;38;5;%dm▒▒▒", x, y);
cc = rgblerp(getquant(x), getquant(y), R2);
printf("0x%02x%02x%02x, %d,%d,2\t/* 0x%02x%02x%02x + "
"0x%02x%02x%02x"
" + '▒' bg=%3d fg=%3d → "
"\e[48;5;%dm \e[48;5;%dm "
"%s\e[48;2;%d;%d;%dm \e[0m */\n",
cc.b, cc.g, cc.r, x, y, getquant(x).r, getquant(x).g,
getquant(x).b, getquant(y).r, getquant(y).g,
getquant(y).b, x, y, x, y, buf, cc.r, cc.g, cc.b);
sprintf(buf, "\e[48;5;%d;38;5;%dm▓▓▓", x, y);
cc = rgblerp(getquant(x), getquant(y), R3);
printf("0x%02x%02x%02x, %d,%d,3\t/* 0x%02x%02x%02x + "
"0x%02x%02x%02x"
" + '▓' bg=%3d fg=%3d → "
"\e[48;5;%dm \e[48;5;%dm "
"%s\e[48;2;%d;%d;%dm \e[0m */\n",
cc.b, cc.g, cc.r, x, y, getquant(x).r, getquant(x).g,
getquant(x).b, getquant(y).r, getquant(y).g,
getquant(y).b, x, y, x, y, buf, cc.r, cc.g, cc.b);
}
#if 0
sprintf(buf, "\e[48;5;%d;38;5;%dm▓▓▓", x, y);
cc = rgblerp((c1 = getquant(x)), (c2 = getquant(y)), R3);
printf("0%03o%03o%03o\t# '▓' bg=%3d fg=%3d → "
"%s\e[48;2;%d;%d;%dm \e[0m\n",
cc.b, cc.g, cc.r, strlen(buf), x, y, buf,
lerp255(c1.r, c2.r, R3), lerp255(c1.g, c2.g, R3),
lerp255(c1.b, c2.b, R3));
#endif
xchg(&x, &y);
}
}
}
++i;
++j;
}
}
}
/* for (i = 0; i < 255; ++i) { */
/* for (j = 0; j < 255; ++j) { */
/* for (k = 0; k < 255; ++k) { */
/* printf("0%03o%03o%03o\n", i, j, k); */
/* } */
/* } */
/* } */
return 0;
}

View file

@ -1,186 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/tty/quant.h"
#include "libc/fmt/fmt.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/getopt/getopt.internal.h"
#define USAGE \
" [FLAGS] [PATH...]\n\
\n\
Flags:\n\
-o PATH output path\n\
-h shows this information\n\
\n"
static size_t linecap_;
static FILE *in_, *out_;
static char *inpath_, *outpath_, *line_;
void PrintUsage(int rc, FILE *f) {
fputs("Usage: ", f);
fputs(program_invocation_name, f);
fputs(USAGE, f);
exit(rc);
}
void GetOpts(int *argc, char *argv[]) {
int opt;
outpath_ = "-";
while ((opt = getopt(*argc, argv, "?ho:")) != -1) {
switch (opt) {
case 'o':
outpath_ = optarg;
break;
case '?':
case 'h':
PrintUsage(EXIT_SUCCESS, stdout);
default:
PrintUsage(EX_USAGE, stderr);
}
}
if (optind == *argc) {
argv[(*argc)++] = "-";
}
}
#define U256F1(X) ((float)((X)&0xffu) * 256.0f)
#define F1U256(X) MAX(MIN((int)rintl(roundl(256.0f * (X))), 255), 0)
forceinline struct TtyRgb getquant(unsigned xt) {
return g_ansi2rgb_[xt];
}
forceinline unsigned dist(int x, int y) {
return x - y;
}
forceinline unsigned sqr(int x) {
return x * x;
}
static unsigned rgb2hsl(unsigned rgba) {
/* this is broken */
unsigned h8, s8, l8;
float r, g, b, h, s, d, l, cmax, cmin;
r = U256F1(rgba);
g = U256F1(rgba >> 010);
b = U256F1(rgba >> 020);
cmax = MAX(MAX(r, g), b);
cmin = MIN(MIN(r, g), b);
h = 0.0f;
s = 0.0f;
d = cmax - cmin;
l = (cmax + cmin) / 2.0f;
if (cmax != cmin) {
s = l > 0.5L ? d / (2.0f - cmax - cmin) : d / (cmax + cmin);
if (cmax == r) {
h = (g - b) / d + (g < b ? 6.0f : 0.0f);
} else if (cmax == g) {
h = (b - r) / d + 2.0f;
} else if (cmax == b) {
h = (r - g) / d + 4.0f;
}
h /= 6.0f;
}
h8 = F1U256(h);
s8 = F1U256(s);
l8 = F1U256(l);
return ((rgba >> 030) & 255) << 030 | l8 << 020 | s8 << 010 | h8;
}
static struct TtyRgb rgb2hsl2(struct TtyRgb rgb) {
unsigned x =
(unsigned)rgb.b << 020 | (unsigned)rgb.g << 010 | (unsigned)rgb.r;
unsigned y = rgb2hsl(x);
return (struct TtyRgb){
.r = y & 0xff, .g = (y >> 010) & 0xff, .b = (y >> 020) & 0xff};
}
static unsigned rgbdist(struct TtyRgb x, struct TtyRgb y) {
x = rgb2hsl2(x);
y = rgb2hsl2(y);
return sqrt(sqr(dist(x.r, y.r)) + sqr(dist(x.g, y.g)) + sqr(dist(x.b, y.b)));
}
static unsigned xtdist(unsigned x, unsigned y) {
return rgbdist(getquant(x), getquant(y));
}
void Show(unsigned color, unsigned bg, unsigned fg, unsigned glyph) {
uint8_t r, g, b;
b = (color >> 020) & 0xff;
g = (color >> 010) & 0xff;
r = color & 0xff;
printf("\tmix\t0x%04x,%3d,%3d,%3d,%3d,%3d,%3d\t# \e[48;2;%d;%d;%dm \e[0m\n",
rgbdist((struct TtyRgb){r, g, b, 0}, (struct TtyRgb){0, 0, 0, 0}), r,
g, b, bg, fg, glyph, r, g, b);
}
void ProcessFile(void) {
char *p;
unsigned color1, bg1, fg1, glyph1;
unsigned color, bg, fg, glyph;
color1 = -1u;
bg1 = -1u;
fg1 = -1u;
glyph1 = -1u;
while ((getline(&line_, &linecap_, in_)) != -1) {
p = _chomp(line_);
sscanf(p, "%x, %u,%u,%u", &color, &bg, &fg, &glyph);
if (color != color1) {
if (color1 != -1u) {
Show(color1, bg1, fg1, glyph1);
}
color1 = color;
bg1 = bg;
fg1 = fg;
glyph1 = glyph;
}
if ((fg1 && !fg) || (fg && fg1 && xtdist(fg, bg) < xtdist(fg1, bg1))) {
color1 = color;
bg1 = bg;
fg1 = fg;
glyph1 = glyph;
}
}
Show(color1, bg1, fg1, glyph1);
}
int main(int argc, char *argv[]) {
size_t i;
GetOpts(&argc, argv);
CHECK_NOTNULL((out_ = fopen(outpath_, "w")));
for (i = optind; i < argc; ++i) {
CHECK_NOTNULL((in_ = fopen((inpath_ = argv[i]), "r")));
ProcessFile();
CHECK_NE(-1, fclose(in_));
in_ = 0;
}
CHECK_NE(-1, fclose(out_));
out_ = 0;
free(line_);
return 0;
}

View file

@ -1,77 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/math.h"
#include "libc/stdio/stdio.h"
#define N 8
#define SQR(X) ((X) * (X))
static const uint8_t kXtermCube[6] = {0, 0137, 0207, 0257, 0327, 0377};
static int rgb2xterm256(int r, int g, int b) {
int cerr, gerr, ir, ig, ib, gray, grai, cr, cg, cb, gv;
gray = round(r * .299 + g * .587 + b * .114);
grai = gray > 238 ? 23 : (gray - 3) / 10;
ir = r < 48 ? 0 : r < 115 ? 1 : (r - 35) / 40;
ig = g < 48 ? 0 : g < 115 ? 1 : (g - 35) / 40;
ib = b < 48 ? 0 : b < 115 ? 1 : (b - 35) / 40;
cr = kXtermCube[ir];
cg = kXtermCube[ig];
cb = kXtermCube[ib];
gv = 8 + 10 * grai;
cerr = SQR(cr - r) + SQR(cg - g) + SQR(cb - b);
gerr = SQR(gv - r) + SQR(gv - g) + SQR(gv - b);
if (cerr <= gerr) {
return 16 + 36 * ir + 6 * ig + ib;
} else {
return 232 + grai;
}
}
int main(int argc, char *argv[]) {
double d;
int i, j, x;
int r, g, b;
double G[N][3];
double rgb[2][3] = {
{1, 0, 0},
{0, 1, 0},
};
for (i = 0; i < N; ++i) {
for (j = 0; j < 3; ++j) {
d = (rgb[1][j] - rgb[0][j]) / (N - 1);
G[i][j] = rgb[0][j] + d * i;
}
}
for (i = 0; i < N; ++i) {
r = round(G[i][0] * 255);
g = round(G[i][1] * 255);
b = round(G[i][2] * 255);
x = rgb2xterm256(r, g, b);
printf("\e[38;5;232;48;5;%dmabcdefg \e[0m %3d "
"\e[38;5;232;48;2;%d;%d;%dmabcdgefg \e[0m "
"%3d %3d %3d %f %f %f\n",
x, x, r, g, b, r, g, b, G[i][0], G[i][1], G[i][2]);
}
return 0;
}

View file

@ -1,706 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/tty/xtermname.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
struct Rgb {
uint8_t r, g, b;
};
const struct Rgb kTango[16] = {
{0x00, 0x00, 0x00}, {0x80, 0x00, 0x00}, {0x00, 0x80, 0x00},
{0x80, 0x80, 0x00}, {0x00, 0x00, 0x80}, {0x80, 0x00, 0x80},
{0x00, 0x80, 0x80}, {0xc0, 0xc0, 0xc0}, {0x80, 0x80, 0x80},
{0xff, 0x00, 0x00}, {0x00, 0xff, 0x00}, {0xff, 0xff, 0x00},
{0x00, 0x00, 0xff}, {0xff, 0x00, 0xff}, {0x00, 0xff, 0xff},
{0xff, 0xff, 0xff},
};
const struct Rgb kXtermRgb[] = {
/* 0..15: ansi 16-color palette */
{0x00, 0x00, 0x00},
{0x80, 0x00, 0x00},
{0x00, 0x80, 0x00},
{0x80, 0x80, 0x00},
{0x00, 0x00, 0x80},
{0x80, 0x00, 0x80},
{0x00, 0x80, 0x80},
{0xc0, 0xc0, 0xc0},
{0x80, 0x80, 0x80},
{0xff, 0x00, 0x00},
{0x00, 0xff, 0x00},
{0xff, 0xff, 0x00},
{0x00, 0x00, 0xff},
{0xff, 0x00, 0xff},
{0x00, 0xff, 0xff},
{0xff, 0xff, 0xff},
/* 16..231: xterm256 color cubes */
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x5f},
{0x00, 0x00, 0x87},
{0x00, 0x00, 0xaf},
{0x00, 0x00, 0xd7},
{0x00, 0x00, 0xff},
{0x00, 0x5f, 0x00},
{0x00, 0x5f, 0x5f},
{0x00, 0x5f, 0x87},
{0x00, 0x5f, 0xaf},
{0x00, 0x5f, 0xd7},
{0x00, 0x5f, 0xff},
{0x00, 0x87, 0x00},
{0x00, 0x87, 0x5f},
{0x00, 0x87, 0x87},
{0x00, 0x87, 0xaf},
{0x00, 0x87, 0xd7},
{0x00, 0x87, 0xff},
{0x00, 0xaf, 0x00},
{0x00, 0xaf, 0x5f},
{0x00, 0xaf, 0x87},
{0x00, 0xaf, 0xaf},
{0x00, 0xaf, 0xd7},
{0x00, 0xaf, 0xff},
{0x00, 0xd7, 0x00},
{0x00, 0xd7, 0x5f},
{0x00, 0xd7, 0x87},
{0x00, 0xd7, 0xaf},
{0x00, 0xd7, 0xd7},
{0x00, 0xd7, 0xff},
{0x00, 0xff, 0x00},
{0x00, 0xff, 0x5f},
{0x00, 0xff, 0x87},
{0x00, 0xff, 0xaf},
{0x00, 0xff, 0xd7},
{0x00, 0xff, 0xff},
{0x5f, 0x00, 0x00},
{0x5f, 0x00, 0x5f},
{0x5f, 0x00, 0x87},
{0x5f, 0x00, 0xaf},
{0x5f, 0x00, 0xd7},
{0x5f, 0x00, 0xff},
{0x5f, 0x5f, 0x00},
{0x5f, 0x5f, 0x5f},
{0x5f, 0x5f, 0x87},
{0x5f, 0x5f, 0xaf},
{0x5f, 0x5f, 0xd7},
{0x5f, 0x5f, 0xff},
{0x5f, 0x87, 0x00},
{0x5f, 0x87, 0x5f},
{0x5f, 0x87, 0x87},
{0x5f, 0x87, 0xaf},
{0x5f, 0x87, 0xd7},
{0x5f, 0x87, 0xff},
{0x5f, 0xaf, 0x00},
{0x5f, 0xaf, 0x5f},
{0x5f, 0xaf, 0x87},
{0x5f, 0xaf, 0xaf},
{0x5f, 0xaf, 0xd7},
{0x5f, 0xaf, 0xff},
{0x5f, 0xd7, 0x00},
{0x5f, 0xd7, 0x5f},
{0x5f, 0xd7, 0x87},
{0x5f, 0xd7, 0xaf},
{0x5f, 0xd7, 0xd7},
{0x5f, 0xd7, 0xff},
{0x5f, 0xff, 0x00},
{0x5f, 0xff, 0x5f},
{0x5f, 0xff, 0x87},
{0x5f, 0xff, 0xaf},
{0x5f, 0xff, 0xd7},
{0x5f, 0xff, 0xff},
{0x87, 0x00, 0x00},
{0x87, 0x00, 0x5f},
{0x87, 0x00, 0x87},
{0x87, 0x00, 0xaf},
{0x87, 0x00, 0xd7},
{0x87, 0x00, 0xff},
{0x87, 0x5f, 0x00},
{0x87, 0x5f, 0x5f},
{0x87, 0x5f, 0x87},
{0x87, 0x5f, 0xaf},
{0x87, 0x5f, 0xd7},
{0x87, 0x5f, 0xff},
{0x87, 0x87, 0x00},
{0x87, 0x87, 0x5f},
{0x87, 0x87, 0x87},
{0x87, 0x87, 0xaf},
{0x87, 0x87, 0xd7},
{0x87, 0x87, 0xff},
{0x87, 0xaf, 0x00},
{0x87, 0xaf, 0x5f},
{0x87, 0xaf, 0x87},
{0x87, 0xaf, 0xaf},
{0x87, 0xaf, 0xd7},
{0x87, 0xaf, 0xff},
{0x87, 0xd7, 0x00},
{0x87, 0xd7, 0x5f},
{0x87, 0xd7, 0x87},
{0x87, 0xd7, 0xaf},
{0x87, 0xd7, 0xd7},
{0x87, 0xd7, 0xff},
{0x87, 0xff, 0x00},
{0x87, 0xff, 0x5f},
{0x87, 0xff, 0x87},
{0x87, 0xff, 0xaf},
{0x87, 0xff, 0xd7},
{0x87, 0xff, 0xff},
{0xaf, 0x00, 0x00},
{0xaf, 0x00, 0x5f},
{0xaf, 0x00, 0x87},
{0xaf, 0x00, 0xaf},
{0xaf, 0x00, 0xd7},
{0xaf, 0x00, 0xff},
{0xaf, 0x5f, 0x00},
{0xaf, 0x5f, 0x5f},
{0xaf, 0x5f, 0x87},
{0xaf, 0x5f, 0xaf},
{0xaf, 0x5f, 0xd7},
{0xaf, 0x5f, 0xff},
{0xaf, 0x87, 0x00},
{0xaf, 0x87, 0x5f},
{0xaf, 0x87, 0x87},
{0xaf, 0x87, 0xaf},
{0xaf, 0x87, 0xd7},
{0xaf, 0x87, 0xff},
{0xaf, 0xaf, 0x00},
{0xaf, 0xaf, 0x5f},
{0xaf, 0xaf, 0x87},
{0xaf, 0xaf, 0xaf},
{0xaf, 0xaf, 0xd7},
{0xaf, 0xaf, 0xff},
{0xaf, 0xd7, 0x00},
{0xaf, 0xd7, 0x5f},
{0xaf, 0xd7, 0x87},
{0xaf, 0xd7, 0xaf},
{0xaf, 0xd7, 0xd7},
{0xaf, 0xd7, 0xff},
{0xaf, 0xff, 0x00},
{0xaf, 0xff, 0x5f},
{0xaf, 0xff, 0x87},
{0xaf, 0xff, 0xaf},
{0xaf, 0xff, 0xd7},
{0xaf, 0xff, 0xff},
{0xd7, 0x00, 0x00},
{0xd7, 0x00, 0x5f},
{0xd7, 0x00, 0x87},
{0xd7, 0x00, 0xaf},
{0xd7, 0x00, 0xd7},
{0xd7, 0x00, 0xff},
{0xd7, 0x5f, 0x00},
{0xd7, 0x5f, 0x5f},
{0xd7, 0x5f, 0x87},
{0xd7, 0x5f, 0xaf},
{0xd7, 0x5f, 0xd7},
{0xd7, 0x5f, 0xff},
{0xd7, 0x87, 0x00},
{0xd7, 0x87, 0x5f},
{0xd7, 0x87, 0x87},
{0xd7, 0x87, 0xaf},
{0xd7, 0x87, 0xd7},
{0xd7, 0x87, 0xff},
{0xd7, 0xaf, 0x00},
{0xd7, 0xaf, 0x5f},
{0xd7, 0xaf, 0x87},
{0xd7, 0xaf, 0xaf},
{0xd7, 0xaf, 0xd7},
{0xd7, 0xaf, 0xff},
{0xd7, 0xd7, 0x00},
{0xd7, 0xd7, 0x5f},
{0xd7, 0xd7, 0x87},
{0xd7, 0xd7, 0xaf},
{0xd7, 0xd7, 0xd7},
{0xd7, 0xd7, 0xff},
{0xd7, 0xff, 0x00},
{0xd7, 0xff, 0x5f},
{0xd7, 0xff, 0x87},
{0xd7, 0xff, 0xaf},
{0xd7, 0xff, 0xd7},
{0xd7, 0xff, 0xff},
{0xff, 0x00, 0x00},
{0xff, 0x00, 0x5f},
{0xff, 0x00, 0x87},
{0xff, 0x00, 0xaf},
{0xff, 0x00, 0xd7},
{0xff, 0x00, 0xff},
{0xff, 0x5f, 0x00},
{0xff, 0x5f, 0x5f},
{0xff, 0x5f, 0x87},
{0xff, 0x5f, 0xaf},
{0xff, 0x5f, 0xd7},
{0xff, 0x5f, 0xff},
{0xff, 0x87, 0x00},
{0xff, 0x87, 0x5f},
{0xff, 0x87, 0x87},
{0xff, 0x87, 0xaf},
{0xff, 0x87, 0xd7},
{0xff, 0x87, 0xff},
{0xff, 0xaf, 0x00},
{0xff, 0xaf, 0x5f},
{0xff, 0xaf, 0x87},
{0xff, 0xaf, 0xaf},
{0xff, 0xaf, 0xd7},
{0xff, 0xaf, 0xff},
{0xff, 0xd7, 0x00},
{0xff, 0xd7, 0x5f},
{0xff, 0xd7, 0x87},
{0xff, 0xd7, 0xaf},
{0xff, 0xd7, 0xd7},
{0xff, 0xd7, 0xff},
{0xff, 0xff, 0x00},
{0xff, 0xff, 0x5f},
{0xff, 0xff, 0x87},
{0xff, 0xff, 0xaf},
{0xff, 0xff, 0xd7},
{0xff, 0xff, 0xff},
/* 232..255: xterm256 grayscale */
{0x08, 0x08, 0x08}, /* 8 */
{0x12, 0x12, 0x12}, /* 10 */
{0x1c, 0x1c, 0x1c}, /* 10 */
{0x26, 0x26, 0x26}, /* 10 */
{0x30, 0x30, 0x30}, /* .. */
{0x3a, 0x3a, 0x3a},
{0x44, 0x44, 0x44},
{0x4e, 0x4e, 0x4e},
{0x58, 0x58, 0x58},
{0x62, 0x62, 0x62},
{0x6c, 0x6c, 0x6c},
{0x76, 0x76, 0x76},
{0x80, 0x80, 0x80},
{0x8a, 0x8a, 0x8a},
{0x94, 0x94, 0x94},
{0x9e, 0x9e, 0x9e},
{0xa8, 0xa8, 0xa8},
{0xb2, 0xb2, 0xb2},
{0xbc, 0xbc, 0xbc},
{0xc6, 0xc6, 0xc6},
{0xd0, 0xd0, 0xd0},
{0xda, 0xda, 0xda},
{0xe4, 0xe4, 0xe4},
{0xee, 0xee, 0xee},
};
const struct Rgb kXtermRgbAppleFg[] = {
{0, 0, 0}, {192, 55, 41}, {48, 187, 49}, {173, 172, 53},
{73, 76, 224}, {209, 65, 209}, {60, 187, 199}, {203, 204, 205},
{154, 155, 156}, {249, 59, 44}, {62, 229, 55}, {234, 234, 62},
{89, 63, 251}, {247, 67, 245}, {48, 239, 239}, {233, 235, 235},
{47, 49, 49}, {60, 46, 142}, {67, 51, 180}, {74, 56, 218},
{82, 62, 248}, {89, 63, 251}, {46, 127, 43}, {46, 127, 127},
{49, 127, 167}, {60, 127, 207}, {63, 127, 241}, {70, 126, 251},
{57, 161, 50}, {47, 161, 122}, {50, 161, 161}, {60, 161, 200},
{53, 161, 237}, {65, 160, 252}, {45, 194, 51}, {58, 194, 118},
{51, 194, 156}, {59, 194, 194}, {48, 194, 233}, {63, 194, 252},
{62, 227, 55}, {55, 227, 115}, {48, 227, 151}, {63, 227, 189},
{52, 227, 227}, {66, 227, 253}, {51, 252, 57}, {53, 252, 111},
{63, 252, 147}, {58, 252, 184}, {59, 252, 222}, {62, 253, 251},
{138, 49, 43}, {134, 55, 134}, {134, 58, 174}, {133, 61, 213},
{134, 67, 244}, {134, 65, 251}, {125, 124, 46}, {124, 125, 125},
{122, 125, 165}, {123, 126, 205}, {124, 126, 243}, {125, 125, 251},
{120, 159, 47}, {118, 159, 121}, {118, 159, 160}, {117, 160, 199},
{118, 160, 238}, {119, 160, 252}, {115, 193, 53}, {113, 193, 117},
{114, 193, 155}, {111, 193, 193}, {113, 194, 232}, {112, 193, 252},
{110, 226, 53}, {108, 226, 114}, {110, 226, 151}, {106, 226, 189},
{105, 227, 227}, {105, 226, 252}, {99, 251, 59}, {103, 251, 111},
{104, 251, 146}, {97, 252, 184}, {102, 252, 221}, {98, 254, 250},
{175, 54, 40}, {172, 58, 130}, {170, 61, 170}, {170, 66, 210},
{169, 67, 245}, {168, 69, 251}, {164, 123, 47}, {162, 123, 124},
{161, 124, 163}, {161, 124, 203}, {160, 125, 238}, {160, 125, 251},
{158, 157, 47}, {157, 158, 120}, {157, 158, 159}, {155, 158, 198},
{155, 159, 236}, {155, 158, 252}, {153, 192, 55}, {152, 192, 117},
{151, 192, 154}, {151, 192, 193}, {150, 192, 231}, {150, 192, 251},
{148, 225, 53}, {147, 225, 114}, {146, 225, 150}, {147, 226, 188},
{145, 226, 226}, {145, 226, 250}, {142, 251, 61}, {141, 251, 111},
{141, 252, 146}, {142, 253, 183}, {139, 254, 221}, {138, 255, 249},
{211, 59, 40}, {209, 63, 126}, {207, 63, 166}, {206, 64, 206},
{205, 69, 243}, {204, 72, 252}, {202, 121, 45}, {201, 122, 122},
{200, 122, 161}, {199, 123, 200}, {199, 124, 238}, {197, 124, 252},
{197, 156, 51}, {195, 156, 119}, {195, 157, 157}, {194, 157, 196},
{193, 157, 234}, {193, 157, 252}, {191, 190, 54}, {190, 190, 116},
{189, 191, 153}, {190, 191, 191}, {188, 191, 229}, {187, 191, 251},
{186, 224, 55}, {185, 224, 113}, {184, 224, 150}, {184, 224, 187},
{184, 225, 225}, {182, 224, 251}, {180, 253, 62}, {180, 253, 111},
{179, 253, 146}, {179, 253, 183}, {179, 254, 220}, {177, 252, 249},
{244, 59, 43}, {243, 62, 123}, {241, 65, 162}, {241, 69, 202},
{240, 70, 238}, {238, 69, 252}, {239, 119, 50}, {238, 120, 120},
{236, 121, 159}, {235, 121, 198}, {235, 123, 236}, {234, 123, 252},
{234, 154, 53}, {233, 154, 118}, {232, 155, 156}, {231, 155, 194},
{231, 156, 233}, {230, 156, 252}, {229, 188, 53}, {228, 189, 115},
{227, 189, 152}, {227, 189, 190}, {226, 189, 228}, {225, 189, 253},
{223, 222, 60}, {223, 223, 113}, {222, 223, 149}, {222, 223, 186},
{222, 223, 224}, {220, 223, 252}, {218, 251, 61}, {217, 251, 109},
{217, 251, 145}, {217, 251, 182}, {216, 251, 219}, {216, 251, 250},
{252, 63, 43}, {252, 64, 120}, {252, 64, 159}, {252, 65, 198},
{252, 67, 236}, {252, 72, 252}, {253, 117, 47}, {253, 118, 118},
{253, 119, 156}, {253, 120, 194}, {253, 120, 233}, {252, 121, 252},
{253, 152, 49}, {252, 152, 116}, {252, 153, 153}, {253, 153, 192},
{252, 154, 229}, {251, 154, 251}, {253, 186, 56}, {251, 187, 114},
{251, 187, 151}, {252, 187, 188}, {252, 188, 226}, {251, 188, 251},
{251, 221, 61}, {250, 221, 112}, {250, 221, 148}, {250, 221, 185},
{251, 222, 222}, {251, 222, 251}, {251, 250, 58}, {250, 250, 109},
{249, 250, 144}, {247, 251, 181}, {247, 253, 218}, {254, 255, 255},
{52, 53, 53}, {57, 58, 59}, {66, 67, 67}, {75, 76, 76},
{84, 85, 85}, {92, 93, 94}, {101, 102, 102}, {109, 111, 111},
{118, 119, 119}, {126, 127, 128}, {134, 136, 136}, {143, 144, 145},
{151, 152, 153}, {159, 161, 161}, {167, 169, 169}, {176, 177, 177},
{184, 185, 186}, {192, 193, 194}, {200, 201, 202}, {208, 209, 210},
{216, 218, 218}, {224, 226, 226}, {232, 234, 234}, {240, 242, 242},
};
const struct Rgb kXtermRgbAppleBg[] = {
{0, 0, 0}, {151, 4, 12}, {23, 164, 26}, {153, 152, 29},
{8, 43, 181}, {177, 25, 176}, {26, 166, 177}, {191, 191, 191},
{132, 132, 132}, {227, 10, 23}, {33, 215, 38}, {229, 228, 49},
{11, 36, 251}, {227, 35, 227}, {39, 229, 228}, {230, 229, 230},
{0, 0, 0}, {1, 7, 93}, {3, 14, 133}, {5, 21, 172},
{7, 28, 211}, {11, 36, 251}, {8, 94, 11}, {10, 95, 95},
{11, 96, 133}, {13, 97, 173}, {15, 99, 212}, {18, 101, 251},
{17, 134, 20}, {18, 134, 96}, {18, 135, 134}, {20, 136, 173},
{21, 137, 212}, {23, 138, 251}, {25, 173, 29}, {26, 174, 98},
{26, 174, 136}, {27, 175, 174}, {28, 175, 213}, {30, 176, 252},
{33, 213, 38}, {34, 213, 101}, {34, 214, 137}, {35, 214, 175},
{36, 215, 214}, {37, 215, 253}, {41, 253, 47}, {42, 253, 104},
{42, 253, 140}, {43, 253, 177}, {44, 254, 215}, {45, 255, 254},
{94, 2, 4}, {94, 8, 94}, {94, 15, 133}, {94, 22, 172},
{95, 29, 211}, {95, 36, 251}, {95, 94, 14}, {95, 95, 95},
{95, 96, 134}, {95, 97, 173}, {96, 99, 212}, {96, 101, 251},
{96, 134, 22}, {96, 134, 96}, {96, 135, 135}, {97, 136, 173},
{97, 137, 212}, {97, 138, 252}, {98, 173, 30}, {98, 174, 98},
{98, 174, 136}, {98, 175, 174}, {98, 176, 213}, {99, 177, 252},
{100, 213, 39}, {100, 213, 101}, {100, 214, 138}, {100, 214, 176},
{101, 215, 214}, {101, 215, 253}, {102, 253, 48}, {103, 253, 104},
{103, 253, 140}, {103, 253, 177}, {103, 254, 215}, {104, 255, 254},
{133, 3, 9}, {133, 10, 94}, {134, 16, 133}, {134, 23, 172},
{134, 30, 212}, {134, 37, 251}, {134, 94, 18}, {134, 95, 96},
{134, 96, 134}, {134, 97, 173}, {135, 99, 212}, {135, 101, 251},
{135, 134, 25}, {135, 134, 97}, {135, 135, 135}, {135, 136, 174},
{135, 137, 213}, {136, 138, 252}, {136, 173, 32}, {136, 174, 99},
{136, 174, 136}, {136, 175, 175}, {136, 176, 213}, {137, 177, 252},
{137, 213, 40}, {137, 213, 102}, {138, 214, 138}, {138, 214, 176},
{138, 215, 214}, {138, 216, 253}, {139, 253, 49}, {139, 253, 105},
{139, 253, 140}, {139, 254, 178}, {140, 254, 216}, {140, 255, 254},
{173, 6, 15}, {173, 12, 95}, {173, 18, 134}, {173, 24, 173},
{173, 31, 212}, {174, 38, 251}, {173, 95, 22}, {174, 95, 96},
{174, 96, 135}, {174, 98, 173}, {174, 99, 212}, {174, 101, 252},
{174, 134, 28}, {174, 135, 98}, {174, 135, 136}, {174, 136, 174},
{174, 137, 213}, {175, 139, 252}, {175, 174, 35}, {175, 174, 100},
{175, 174, 137}, {175, 175, 175}, {175, 176, 214}, {175, 177, 253},
{176, 213, 43}, {176, 213, 102}, {176, 214, 139}, {176, 214, 176},
{176, 215, 215}, {176, 216, 253}, {177, 253, 51}, {177, 253, 105},
{177, 253, 141}, {177, 254, 178}, {178, 254, 216}, {178, 255, 254},
{213, 9, 21}, {213, 15, 96}, {213, 20, 135}, {241, 69, 202},
{213, 32, 212}, {213, 39, 251}, {213, 95, 27}, {213, 96, 97},
{213, 97, 135}, {213, 98, 174}, {213, 100, 213}, {213, 102, 252},
{213, 134, 32}, {213, 135, 99}, {213, 135, 136}, {214, 136, 175},
{214, 137, 213}, {214, 139, 252}, {214, 174, 38}, {214, 174, 101},
{214, 175, 138}, {214, 175, 176}, {214, 176, 214}, {214, 177, 253},
{215, 213, 45}, {215, 214, 103}, {215, 214, 139}, {215, 214, 177},
{215, 215, 215}, {215, 216, 254}, {216, 253, 53}, {216, 253, 106},
{216, 253, 141}, {216, 254, 178}, {216, 254, 216}, {216, 255, 255},
{252, 13, 27}, {252, 18, 98}, {252, 22, 135}, {252, 28, 174},
{252, 34, 213}, {252, 40, 252}, {252, 96, 32}, {252, 96, 99},
{252, 97, 136}, {253, 99, 175}, {253, 100, 213}, {253, 102, 252},
{253, 135, 36}, {253, 135, 100}, {253, 136, 137}, {253, 137, 175},
{253, 138, 214}, {253, 139, 253}, {253, 174, 42}, {253, 174, 102},
{253, 175, 138}, {253, 175, 176}, {253, 176, 215}, {254, 177, 253},
{254, 213, 48}, {254, 214, 105}, {254, 214, 140}, {254, 215, 177},
{254, 215, 216}, {254, 216, 254}, {255, 253, 56}, {255, 253, 108},
{255, 253, 142}, {255, 254, 179}, {255, 254, 217}, {255, 255, 255},
{8, 8, 8}, {18, 18, 18}, {28, 28, 28}, {38, 38, 38},
{48, 48, 48}, {58, 58, 58}, {68, 68, 68}, {78, 78, 78},
{88, 88, 88}, {98, 98, 98}, {108, 108, 108}, {118, 118, 118},
{128, 128, 128}, {138, 138, 138}, {148, 148, 148}, {158, 158, 158},
{168, 168, 168}, {178, 178, 178}, {188, 188, 188}, {198, 198, 198},
{208, 208, 208}, {218, 218, 218}, {228, 228, 228}, {238, 238, 238},
};
const struct XtermDb {
struct Rgb rgb;
const char *text;
} kXtermDb[] = {
{{0x00, 0x00, 0x00}, "0 Black #000000"},
{{0x80, 0x00, 0x00}, "1 Maroon #800000"},
{{0x00, 0x80, 0x00}, "2 Green #008000"},
{{0x80, 0x80, 0x00}, "3 Olive #808000"},
{{0x00, 0x00, 0x80}, "4 Navy #000080"},
{{0x80, 0x00, 0x80}, "5 Purple #800080"},
{{0x00, 0x80, 0x80}, "6 Teal #008080"},
{{0xc0, 0xc0, 0xc0}, "7 Silver #c0c0c0"},
{{0x80, 0x80, 0x80}, "8 Grey #808080"},
{{0xff, 0x00, 0x00}, "9 Red #ff0000"},
{{0x00, 0xff, 0x00}, "10 Lime #00ff00"},
{{0xff, 0xff, 0x00}, "11 Yellow #ffff00"},
{{0x00, 0x00, 0xff}, "12 Blue #0000ff"},
{{0xff, 0x00, 0xff}, "13 Fuchsia #ff00ff"},
{{0x00, 0xff, 0xff}, "14 Aqua #00ffff"},
{{0xff, 0xff, 0xff}, "15 White #ffffff"},
{{0x00, 0x00, 0x00}, "16 Grey0 #000000"},
{{0x00, 0x00, 0x5f}, "17 NavyBlue #00005f"},
{{0x00, 0x00, 0x87}, "18 DarkBlue #000087"},
{{0x00, 0x00, 0xaf}, "19 Blue3 #0000af"},
{{0x00, 0x00, 0xd7}, "20 Blue3 #0000d7"},
{{0x00, 0x00, 0xff}, "21 Blue1 #0000ff"},
{{0x00, 0x5f, 0x00}, "22 DarkGreen #005f00"},
{{0x00, 0x5f, 0x5f}, "23 DeepSkyBlue4 #005f5f"},
{{0x00, 0x5f, 0x87}, "24 DeepSkyBlue4 #005f87"},
{{0x00, 0x5f, 0xaf}, "25 DeepSkyBlue4 #005faf"},
{{0x00, 0x5f, 0xd7}, "26 DodgerBlue3 #005fd7"},
{{0x00, 0x5f, 0xff}, "27 DodgerBlue2 #005fff"},
{{0x00, 0x87, 0x00}, "28 Green4 #008700"},
{{0x00, 0x87, 0x5f}, "29 SpringGreen4 #00875f"},
{{0x00, 0x87, 0x87}, "30 Turquoise4 #008787"},
{{0x00, 0x87, 0xaf}, "31 DeepSkyBlue3 #0087af"},
{{0x00, 0x87, 0xd7}, "32 DeepSkyBlue3 #0087d7"},
{{0x00, 0x87, 0xff}, "33 DodgerBlue1 #0087ff"},
{{0x00, 0xaf, 0x00}, "34 Green3 #00af00"},
{{0x00, 0xaf, 0x5f}, "35 SpringGreen3 #00af5f"},
{{0x00, 0xaf, 0x87}, "36 DarkCyan #00af87"},
{{0x00, 0xaf, 0xaf}, "37 LightSeaGreen #00afaf"},
{{0x00, 0xaf, 0xd7}, "38 DeepSkyBlue2 #00afd7"},
{{0x00, 0xaf, 0xff}, "39 DeepSkyBlue1 #00afff"},
{{0x00, 0xd7, 0x00}, "40 Green3 #00d700"},
{{0x00, 0xd7, 0x5f}, "41 SpringGreen3 #00d75f"},
{{0x00, 0xd7, 0x87}, "42 SpringGreen2 #00d787"},
{{0x00, 0xd7, 0xaf}, "43 Cyan3 #00d7af"},
{{0x00, 0xd7, 0xd7}, "44 DarkTurquoise #00d7d7"},
{{0x00, 0xd7, 0xff}, "45 Turquoise2 #00d7ff"},
{{0x00, 0xff, 0x00}, "46 Green1 #00ff00"},
{{0x00, 0xff, 0x5f}, "47 SpringGreen2 #00ff5f"},
{{0x00, 0xff, 0x87}, "48 SpringGreen1 #00ff87"},
{{0x00, 0xff, 0xaf}, "49 MediumSpringGreen #00ffaf"},
{{0x00, 0xff, 0xd7}, "50 Cyan2 #00ffd7"},
{{0x00, 0xff, 0xff}, "51 Cyan1 #00ffff"},
{{0x5f, 0x00, 0x00}, "52 DarkRed #5f0000"},
{{0x5f, 0x00, 0x5f}, "53 DeepPink4 #5f005f"},
{{0x5f, 0x00, 0x87}, "54 Purple4 #5f0087"},
{{0x5f, 0x00, 0xaf}, "55 Purple4 #5f00af"},
{{0x5f, 0x00, 0xd7}, "56 Purple3 #5f00d7"},
{{0x5f, 0x00, 0xff}, "57 BlueViolet #5f00ff"},
{{0x5f, 0x5f, 0x00}, "58 Orange4 #5f5f00"},
{{0x5f, 0x5f, 0x5f}, "59 Grey37 #5f5f5f"},
{{0x5f, 0x5f, 0x87}, "60 MediumPurple4 #5f5f87"},
{{0x5f, 0x5f, 0xaf}, "61 SlateBlue3 #5f5faf"},
{{0x5f, 0x5f, 0xd7}, "62 SlateBlue3 #5f5fd7"},
{{0x5f, 0x5f, 0xff}, "63 RoyalBlue1 #5f5fff"},
{{0x5f, 0x87, 0x00}, "64 Chartreuse4 #5f8700"},
{{0x5f, 0x87, 0x5f}, "65 DarkSeaGreen4 #5f875f"},
{{0x5f, 0x87, 0x87}, "66 PaleTurquoise4 #5f8787"},
{{0x5f, 0x87, 0xaf}, "67 SteelBlue #5f87af"},
{{0x5f, 0x87, 0xd7}, "68 SteelBlue3 #5f87d7"},
{{0x5f, 0x87, 0xff}, "69 CornflowerBlue #5f87ff"},
{{0x5f, 0xaf, 0x00}, "70 Chartreuse3 #5faf00"},
{{0x5f, 0xaf, 0x5f}, "71 DarkSeaGreen4 #5faf5f"},
{{0x5f, 0xaf, 0x87}, "72 CadetBlue #5faf87"},
{{0x5f, 0xaf, 0xaf}, "73 CadetBlue #5fafaf"},
{{0x5f, 0xaf, 0xd7}, "74 SkyBlue3 #5fafd7"},
{{0x5f, 0xaf, 0xff}, "75 SteelBlue1 #5fafff"},
{{0x5f, 0xd7, 0x00}, "76 Chartreuse3 #5fd700"},
{{0x5f, 0xd7, 0x5f}, "77 PaleGreen3 #5fd75f"},
{{0x5f, 0xd7, 0x87}, "78 SeaGreen3 #5fd787"},
{{0x5f, 0xd7, 0xaf}, "79 Aquamarine3 #5fd7af"},
{{0x5f, 0xd7, 0xd7}, "80 MediumTurquoise #5fd7d7"},
{{0x5f, 0xd7, 0xff}, "81 SteelBlue1 #5fd7ff"},
{{0x5f, 0xff, 0x00}, "82 Chartreuse2 #5fff00"},
{{0x5f, 0xff, 0x5f}, "83 SeaGreen2 #5fff5f"},
{{0x5f, 0xff, 0x87}, "84 SeaGreen1 #5fff87"},
{{0x5f, 0xff, 0xaf}, "85 SeaGreen1 #5fffaf"},
{{0x5f, 0xff, 0xd7}, "86 Aquamarine1 #5fffd7"},
{{0x5f, 0xff, 0xff}, "87 DarkSlateGray2 #5fffff"},
{{0x87, 0x00, 0x00}, "88 DarkRed #870000"},
{{0x87, 0x00, 0x5f}, "89 DeepPink4 #87005f"},
{{0x87, 0x00, 0x87}, "90 DarkMagenta #870087"},
{{0x87, 0x00, 0xaf}, "91 DarkMagenta #8700af"},
{{0x87, 0x00, 0xd7}, "92 DarkViolet #8700d7"},
{{0x87, 0x00, 0xff}, "93 Purple #8700ff"},
{{0x87, 0x5f, 0x00}, "94 Orange4 #875f00"},
{{0x87, 0x5f, 0x5f}, "95 LightPink4 #875f5f"},
{{0x87, 0x5f, 0x87}, "96 Plum4 #875f87"},
{{0x87, 0x5f, 0xaf}, "97 MediumPurple3 #875faf"},
{{0x87, 0x5f, 0xd7}, "98 MediumPurple3 #875fd7"},
{{0x87, 0x5f, 0xff}, "99 SlateBlue1 #875fff"},
{{0x87, 0x87, 0x00}, "100 Yellow4 #878700"},
{{0x87, 0x87, 0x5f}, "101 Wheat4 #87875f"},
{{0x87, 0x87, 0x87}, "102 Grey53 #878787"},
{{0x87, 0x87, 0xaf}, "103 LightSlateGrey #8787af"},
{{0x87, 0x87, 0xd7}, "104 MediumPurple #8787d7"},
{{0x87, 0x87, 0xff}, "105 LightSlateBlue #8787ff"},
{{0x87, 0xaf, 0x00}, "106 Yellow4 #87af00"},
{{0x87, 0xaf, 0x5f}, "107 DarkOliveGreen3 #87af5f"},
{{0x87, 0xaf, 0x87}, "108 DarkSeaGreen #87af87"},
{{0x87, 0xaf, 0xaf}, "109 LightSkyBlue3 #87afaf"},
{{0x87, 0xaf, 0xd7}, "110 LightSkyBlue3 #87afd7"},
{{0x87, 0xaf, 0xff}, "111 SkyBlue2 #87afff"},
{{0x87, 0xd7, 0x00}, "112 Chartreuse2 #87d700"},
{{0x87, 0xd7, 0x5f}, "113 DarkOliveGreen3 #87d75f"},
{{0x87, 0xd7, 0x87}, "114 PaleGreen3 #87d787"},
{{0x87, 0xd7, 0xaf}, "115 DarkSeaGreen3 #87d7af"},
{{0x87, 0xd7, 0xd7}, "116 DarkSlateGray3 #87d7d7"},
{{0x87, 0xd7, 0xff}, "117 SkyBlue1 #87d7ff"},
{{0x87, 0xff, 0x00}, "118 Chartreuse1 #87ff00"},
{{0x87, 0xff, 0x5f}, "119 LightGreen #87ff5f"},
{{0x87, 0xff, 0x87}, "120 LightGreen #87ff87"},
{{0x87, 0xff, 0xaf}, "121 PaleGreen1 #87ffaf"},
{{0x87, 0xff, 0xd7}, "122 Aquamarine1 #87ffd7"},
{{0x87, 0xff, 0xff}, "123 DarkSlateGray1 #87ffff"},
{{0xaf, 0x00, 0x00}, "124 Red3 #af0000"},
{{0xaf, 0x00, 0x5f}, "125 DeepPink4 #af005f"},
{{0xaf, 0x00, 0x87}, "126 MediumVioletRed #af0087"},
{{0xaf, 0x00, 0xaf}, "127 Magenta3 #af00af"},
{{0xaf, 0x00, 0xd7}, "128 DarkViolet #af00d7"},
{{0xaf, 0x00, 0xff}, "129 Purple #af00ff"},
{{0xaf, 0x5f, 0x00}, "130 DarkOrange3 #af5f00"},
{{0xaf, 0x5f, 0x5f}, "131 IndianRed #af5f5f"},
{{0xaf, 0x5f, 0x87}, "132 HotPink3 #af5f87"},
{{0xaf, 0x5f, 0xaf}, "133 MediumOrchid3 #af5faf"},
{{0xaf, 0x5f, 0xd7}, "134 MediumOrchid #af5fd7"},
{{0xaf, 0x5f, 0xff}, "135 MediumPurple2 #af5fff"},
{{0xaf, 0x87, 0x00}, "136 DarkGoldenrod #af8700"},
{{0xaf, 0x87, 0x5f}, "137 LightSalmon3 #af875f"},
{{0xaf, 0x87, 0x87}, "138 RosyBrown #af8787"},
{{0xaf, 0x87, 0xaf}, "139 Grey63 #af87af"},
{{0xaf, 0x87, 0xd7}, "140 MediumPurple2 #af87d7"},
{{0xaf, 0x87, 0xff}, "141 MediumPurple1 #af87ff"},
{{0xaf, 0xaf, 0x00}, "142 Gold3 #afaf00"},
{{0xaf, 0xaf, 0x5f}, "143 DarkKhaki #afaf5f"},
{{0xaf, 0xaf, 0x87}, "144 NavajoWhite3 #afaf87"},
{{0xaf, 0xaf, 0xaf}, "145 Grey69 #afafaf"},
{{0xaf, 0xaf, 0xd7}, "146 LightSteelBlue3 #afafd7"},
{{0xaf, 0xaf, 0xff}, "147 LightSteelBlue #afafff"},
{{0xaf, 0xd7, 0x00}, "148 Yellow3 #afd700"},
{{0xaf, 0xd7, 0x5f}, "149 DarkOliveGreen3 #afd75f"},
{{0xaf, 0xd7, 0x87}, "150 DarkSeaGreen3 #afd787"},
{{0xaf, 0xd7, 0xaf}, "151 DarkSeaGreen2 #afd7af"},
{{0xaf, 0xd7, 0xd7}, "152 LightCyan3 #afd7d7"},
{{0xaf, 0xd7, 0xff}, "153 LightSkyBlue1 #afd7ff"},
{{0xaf, 0xff, 0x00}, "154 GreenYellow #afff00"},
{{0xaf, 0xff, 0x5f}, "155 DarkOliveGreen2 #afff5f"},
{{0xaf, 0xff, 0x87}, "156 PaleGreen1 #afff87"},
{{0xaf, 0xff, 0xaf}, "157 DarkSeaGreen2 #afffaf"},
{{0xaf, 0xff, 0xd7}, "158 DarkSeaGreen1 #afffd7"},
{{0xaf, 0xff, 0xff}, "159 PaleTurquoise1 #afffff"},
{{0xd7, 0x00, 0x00}, "160 Red3 #d70000"},
{{0xd7, 0x00, 0x5f}, "161 DeepPink3 #d7005f"},
{{0xd7, 0x00, 0x87}, "162 DeepPink3 #d70087"},
{{0xd7, 0x00, 0xaf}, "163 Magenta3 #d700af"},
{{0xd7, 0x00, 0xd7}, "164 Magenta3 #d700d7"},
{{0xd7, 0x00, 0xff}, "165 Magenta2 #d700ff"},
{{0xd7, 0x5f, 0x00}, "166 DarkOrange3 #d75f00"},
{{0xd7, 0x5f, 0x5f}, "167 IndianRed #d75f5f"},
{{0xd7, 0x5f, 0x87}, "168 HotPink3 #d75f87"},
{{0xd7, 0x5f, 0xaf}, "169 HotPink2 #d75faf"},
{{0xd7, 0x5f, 0xd7}, "170 Orchid #d75fd7"},
{{0xd7, 0x5f, 0xff}, "171 MediumOrchid1 #d75fff"},
{{0xd7, 0x87, 0x00}, "172 Orange3 #d78700"},
{{0xd7, 0x87, 0x5f}, "173 LightSalmon3 #d7875f"},
{{0xd7, 0x87, 0x87}, "174 LightPink3 #d78787"},
{{0xd7, 0x87, 0xaf}, "175 Pink3 #d787af"},
{{0xd7, 0x87, 0xd7}, "176 Plum3 #d787d7"},
{{0xd7, 0x87, 0xff}, "177 Violet #d787ff"},
{{0xd7, 0xaf, 0x00}, "178 Gold3 #d7af00"},
{{0xd7, 0xaf, 0x5f}, "179 LightGoldenrod3 #d7af5f"},
{{0xd7, 0xaf, 0x87}, "180 Tan #d7af87"},
{{0xd7, 0xaf, 0xaf}, "181 MistyRose3 #d7afaf"},
{{0xd7, 0xaf, 0xd7}, "182 Thistle3 #d7afd7"},
{{0xd7, 0xaf, 0xff}, "183 Plum2 #d7afff"},
{{0xd7, 0xd7, 0x00}, "184 Yellow3 #d7d700"},
{{0xd7, 0xd7, 0x5f}, "185 Khaki3 #d7d75f"},
{{0xd7, 0xd7, 0x87}, "186 LightGoldenrod2 #d7d787"},
{{0xd7, 0xd7, 0xaf}, "187 LightYellow3 #d7d7af"},
{{0xd7, 0xd7, 0xd7}, "188 Grey84 #d7d7d7"},
{{0xd7, 0xd7, 0xff}, "189 LightSteelBlue1 #d7d7ff"},
{{0xd7, 0xff, 0x00}, "190 Yellow2 #d7ff00"},
{{0xd7, 0xff, 0x5f}, "191 DarkOliveGreen1 #d7ff5f"},
{{0xd7, 0xff, 0x87}, "192 DarkOliveGreen1 #d7ff87"},
{{0xd7, 0xff, 0xaf}, "193 DarkSeaGreen1 #d7ffaf"},
{{0xd7, 0xff, 0xd7}, "194 Honeydew2 #d7ffd7"},
{{0xd7, 0xff, 0xff}, "195 LightCyan1 #d7ffff"},
{{0xff, 0x00, 0x00}, "196 Red1 #ff0000"},
{{0xff, 0x00, 0x5f}, "197 DeepPink2 #ff005f"},
{{0xff, 0x00, 0x87}, "198 DeepPink1 #ff0087"},
{{0xff, 0x00, 0xaf}, "199 DeepPink1 #ff00af"},
{{0xff, 0x00, 0xd7}, "200 Magenta2 #ff00d7"},
{{0xff, 0x00, 0xff}, "201 Magenta1 #ff00ff"},
{{0xff, 0x5f, 0x00}, "202 OrangeRed1 #ff5f00"},
{{0xff, 0x5f, 0x5f}, "203 IndianRed1 #ff5f5f"},
{{0xff, 0x5f, 0x87}, "204 IndianRed1 #ff5f87"},
{{0xff, 0x5f, 0xaf}, "205 HotPink #ff5faf"},
{{0xff, 0x5f, 0xd7}, "206 HotPink #ff5fd7"},
{{0xff, 0x5f, 0xff}, "207 MediumOrchid1 #ff5fff"},
{{0xff, 0x87, 0x00}, "208 DarkOrange #ff8700"},
{{0xff, 0x87, 0x5f}, "209 Salmon1 #ff875f"},
{{0xff, 0x87, 0x87}, "210 LightCoral #ff8787"},
{{0xff, 0x87, 0xaf}, "211 PaleVioletRed1 #ff87af"},
{{0xff, 0x87, 0xd7}, "212 Orchid2 #ff87d7"},
{{0xff, 0x87, 0xff}, "213 Orchid1 #ff87ff"},
{{0xff, 0xaf, 0x00}, "214 Orange1 #ffaf00"},
{{0xff, 0xaf, 0x5f}, "215 SandyBrown #ffaf5f"},
{{0xff, 0xaf, 0x87}, "216 LightSalmon1 #ffaf87"},
{{0xff, 0xaf, 0xaf}, "217 LightPink1 #ffafaf"},
{{0xff, 0xaf, 0xd7}, "218 Pink1 #ffafd7"},
{{0xff, 0xaf, 0xff}, "219 Plum1 #ffafff"},
{{0xff, 0xd7, 0x00}, "220 Gold1 #ffd700"},
{{0xff, 0xd7, 0x5f}, "221 LightGoldenrod2 #ffd75f"},
{{0xff, 0xd7, 0x87}, "222 LightGoldenrod2 #ffd787"},
{{0xff, 0xd7, 0xaf}, "223 NavajoWhite1 #ffd7af"},
{{0xff, 0xd7, 0xd7}, "224 MistyRose1 #ffd7d7"},
{{0xff, 0xd7, 0xff}, "225 Thistle1 #ffd7ff"},
{{0xff, 0xff, 0x00}, "226 Yellow1 #ffff00"},
{{0xff, 0xff, 0x5f}, "227 LightGoldenrod1 #ffff5f"},
{{0xff, 0xff, 0x87}, "228 Khaki1 #ffff87"},
{{0xff, 0xff, 0xaf}, "229 Wheat1 #ffffaf"},
{{0xff, 0xff, 0xd7}, "230 Cornsilk1 #ffffd7"},
{{0xff, 0xff, 0xff}, "231 Grey100 #ffffff"},
{{0x08, 0x08, 0x08}, "232 Grey3 #080808"},
{{0x12, 0x12, 0x12}, "233 Grey7 #121212"},
{{0x1c, 0x1c, 0x1c}, "234 Grey11 #1c1c1c"},
{{0x26, 0x26, 0x26}, "235 Grey15 #262626"},
{{0x30, 0x30, 0x30}, "236 Grey19 #303030"},
{{0x3a, 0x3a, 0x3a}, "237 Grey23 #3a3a3a"},
{{0x44, 0x44, 0x44}, "238 Grey27 #444444"},
{{0x4e, 0x4e, 0x4e}, "239 Grey30 #4e4e4e"},
{{0x58, 0x58, 0x58}, "240 Grey35 #585858"},
{{0x62, 0x62, 0x62}, "241 Grey39 #626262"},
{{0x6c, 0x6c, 0x6c}, "242 Grey42 #6c6c6c"},
{{0x76, 0x76, 0x76}, "243 Grey46 #767676"},
{{0x80, 0x80, 0x80}, "244 Grey50 #808080"},
{{0x8a, 0x8a, 0x8a}, "245 Grey54 #8a8a8a"},
{{0x94, 0x94, 0x94}, "246 Grey58 #949494"},
{{0x9e, 0x9e, 0x9e}, "247 Grey62 #9e9e9e"},
{{0xa8, 0xa8, 0xa8}, "248 Grey66 #a8a8a8"},
{{0xb2, 0xb2, 0xb2}, "249 Grey70 #b2b2b2"},
{{0xbc, 0xbc, 0xbc}, "250 Grey74 #bcbcbc"},
{{0xc6, 0xc6, 0xc6}, "251 Grey78 #c6c6c6"},
{{0xd0, 0xd0, 0xd0}, "252 Grey82 #d0d0d0"},
{{0xda, 0xda, 0xda}, "253 Grey85 #dadada"},
{{0xe4, 0xe4, 0xe4}, "254 Grey89 #e4e4e4"},
{{0xee, 0xee, 0xee}, "255 Grey93 #eeeeee"},
};
int main(int argc, char *argv[]) {
size_t i;
printf("BG FG BB BF XTERM NAME HEX\n");
for (i = 0; i < 256; ++i) {
printf("\e[48;5;%dm \e[0m \e[38;5;%dm██\e[0m \e[1;48;5;%dm "
"\e[0m \e[1;38;5;%dm██\e[0m %-6hhu%-18s#%02hhx%02hhx%02hhx\n",
i, i, i, i, i, IndexDoubleNulString(kXtermName, i), kXtermRgb[i].r,
kXtermRgb[i].g, kXtermRgb[i].b);
}
return 0;
}