Initial import

This commit is contained in:
Justine Tunney 2020-06-15 07:18:57 -07:00
commit c91b3c5006
14915 changed files with 590219 additions and 0 deletions

View file

@ -0,0 +1,56 @@
/*-*- 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
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#include "tool/build/lib/interner.h"
TEST(interner, test) {
struct Interner *t = defer(freeinterner, newinterner());
EXPECT_STREQ("hi", &t->p[intern(t, gc(strdup("hi")))]);
EXPECT_STREQ("there", &t->p[intern(t, gc(strdup("there")))]);
EXPECT_STREQ("hi", &t->p[intern(t, gc(strdup("hi")))]);
EXPECT_STREQ("there", &t->p[intern(t, gc(strdup("there")))]);
EXPECT_BINEQ(u"hi there  ", t->p);
EXPECT_EQ(strlen("hi") + 1 + strlen("there") + 1, t->i);
}
TEST(interner, testWordCount) {
struct Interner *t = defer(freeinterner, newinterner());
size_t i, j;
char word[16];
for (i = 0, j = 0; i < kHyperionSize; ++i) {
if (isalpha(kHyperion[i]) || kHyperion[i] == '\'') {
word[j++] = tolower(kHyperion[i]);
} else if (j) {
word[j] = '\0';
intern(t, word);
j = 0;
}
}
EXPECT_BINEQ(u"the fall of hyperion a dream", t->p);
/* 1547 = grep -Po "['a-zA-Z]+" hyperion.txt | tr A-Z a-z | dedupe | wc -l */
EXPECT_EQ(1548, interncount(t));
EXPECT_EQ(10502, t->i);
EXPECT_LT(t->i, t->n);
EXPECT_EQ('\0', t->p[t->i]);
}

View file

@ -0,0 +1,52 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += TEST_TOOL_BUILD_LIB
TEST_TOOL_BUILD_LIB_SRCS := $(wildcard test/tool/build/lib/*.c)
TEST_TOOL_BUILD_LIB_SRCS_TEST = $(filter %_test.c,$(TEST_TOOL_BUILD_LIB_SRCS))
TEST_TOOL_BUILD_LIB_COMS = $(TEST_TOOL_BUILD_LIB_OBJS:%.o=%.com)
TEST_TOOL_BUILD_LIB_OBJS = \
$(TEST_TOOL_BUILD_LIB_SRCS:%=o/$(MODE)/%.zip.o) \
$(TEST_TOOL_BUILD_LIB_SRCS:%.c=o/$(MODE)/%.o)
TEST_TOOL_BUILD_LIB_BINS = \
$(TEST_TOOL_BUILD_LIB_COMS) \
$(TEST_TOOL_BUILD_LIB_COMS:%=%.dbg)
TEST_TOOL_BUILD_LIB_TESTS = \
$(TEST_TOOL_BUILD_LIB_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_TOOL_BUILD_LIB_CHECKS = \
$(TEST_TOOL_BUILD_LIB_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_TOOL_BUILD_LIB_DIRECTDEPS = \
LIBC_X \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STUBS \
LIBC_TESTLIB \
TOOL_BUILD_LIB
TEST_TOOL_BUILD_LIB_DEPS := \
$(call uniq,$(foreach x,$(TEST_TOOL_BUILD_LIB_DIRECTDEPS),$($(x))))
o/$(MODE)/test/tool/build/lib/buildlib.pkg: \
$(TEST_TOOL_BUILD_LIB_OBJS) \
$(foreach x,$(TEST_TOOL_BUILD_LIB_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/tool/build/lib/%.com.dbg: \
$(TEST_TOOL_BUILD_LIB_DEPS) \
o/$(MODE)/test/tool/build/lib/%.o \
o/$(MODE)/test/tool/build/lib/buildlib.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE)
@$(APELINK)
.PHONY: o/$(MODE)/test/tool/build/lib
o/$(MODE)/test/tool/build/lib: \
$(TEST_TOOL_BUILD_LIB_BINS) \
$(TEST_TOOL_BUILD_LIB_CHECKS)

6
test/tool/build/test.mk Normal file
View file

@ -0,0 +1,6 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
.PHONY: o/$(MODE)/test/tool/build
o/$(MODE)/test/tool/build: \
o/$(MODE)/test/tool/build/lib

7
test/tool/test.mk Normal file
View file

@ -0,0 +1,7 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
.PHONY: o/$(MODE)/test/tool
o/$(MODE)/test/tool: \
o/$(MODE)/test/tool/build \
o/$(MODE)/test/tool/viz

View file

@ -0,0 +1,146 @@
/*-*- 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
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/log/log.h"
#include "libc/rand/rand.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "tool/viz/lib/bilinearscale.h"
#include "tool/viz/lib/graphic.h"
TEST(BilinearScale, testWindmill_1x1_to_2x2) {
EXPECT_BINEQ(
u"λλ"
u"λλ",
BilinearScale(1, 2, 2, tgc(tmalloc(1 * 2 * 2)), 1, 1, 1,
tgc(tunbing(u"λ")), 0, 1, 2, 2, 1, 1, .5, .5, 0, 0));
}
TEST(BilinearScale, testWindmill_4x4_to_2x2) {
EXPECT_BINEQ(u"λ "
u" λ",
BilinearScale(1, 2, 2, tgc(tmalloc(2 * 2)), 1, 4, 4,
tgc(tunbing(u"λλ  "
u"λλ  "
u"  λλ"
u"  λλ")),
0, 1, 2, 2, 4, 4, 2, 2, 0, 0));
}
TEST(BilinearScale, testWindmill_8x8_to_4x4) {
EXPECT_BINEQ(u"λλ  "
u"λλ  "
u"  λλ"
u"  λλ",
BilinearScale(1, 4, 4, tgc(tmalloc(4 * 4)), 1, 8, 8,
tgc(tunbing(u"λλλλ    "
u"λλλλ    "
u"λλλλ    "
u"λλλλ    "
u"    λλλλ"
u"    λλλλ"
u"    λλλλ"
u"    λλλλ")),
0, 1, 4, 4, 8, 8, 2, 2, 0, 0));
}
TEST(BilinearScale, testWindmill_4x4_to_8x8) {
EXPECT_BINEQ(u"λλλλ┐   "
u"λλλλ┐   "
u"λλλλ┐   "
u"λλλλ┐   "
u"┐┐┐┐ƒ⁇⁇⁇"
u"    ⁇λλλ"
u"    ⁇λλλ"
u"    ⁇λλλ",
BilinearScale(1, 8, 8, tgc(tmalloc(8 * 8)), 1, 4, 4,
tgc(tunbing(u"λλ  "
u"λλ  "
u"  λλ"
u"  λλ")),
0, 1, 8, 8, 4, 4, .5, .5, 0, 0));
}
TEST(BilinearScale, testWindmill_5x5_to_8x8_withRatioIntent) {
EXPECT_BINEQ(u"λλλλλ   "
u"λλλλλ   "
u"λλλλλ   "
u"¬¬¬╞λTTT"
u"   Tλλλλ"
u"     λλλ"
u"     λλλ"
u"     λλλ",
BilinearScale(1, 8, 8, tgc(tmalloc(8 * 8)), 1, 5, 5,
tgc(tunbing(u"λλλ  "
u"λλλ  "
u"  λλλ"
u"   λλ"
u"   λλ")),
0, 1, 8, 8, 5, 5, 2 / 3., 2 / 3., 0, 0));
}
TEST(BilinearScale, testWindmill_5x5_to_8x8_withoutRatioIntent) {
EXPECT_BINEQ(u"λλλλλÅ  "
u"λλλλλÅ  "
u"λλλλλÅ  "
u"╧╧╧╪λñ//"
u"   /λλλλ"
u"   →Å└λλ"
u"     oλλ"
u"     oλλ",
BilinearScale(1, 8, 8, tgc(tmalloc(8 * 8)), 1, 5, 5,
tgc(tunbing(u"λλλ  "
u"λλλ  "
u"  λλλ"
u"   λλ"
u"   λλ")),
0, 1, 8, 8, 5, 5, 5 / 8., 5 / 8., 0, 0));
}
TEST(BilinearScale, testNyquistTorture) {
EXPECT_BINEQ(u"███ "
u"████"
u" ███"
u"███ ",
BilinearScale(1, 4, 4, tgc(tmalloc(4 * 4)), 1, 8, 8,
tgc(tunbing(u"█ █ █ "
u" █ █ █ "
u"█ █ █ █ "
u" █ █ █ █"
u" █ █ █ "
u" █ █ █ "
u"█ █ █ "
u" █ █ ")),
0, 1, 4, 4, 8, 8, 2, 2, 0, 0));
}
BENCH(BilinearScale, Bench) {
void *src, *dst;
double c, w1, h1, w2, h2;
c = 3;
w1 = 1920;
h1 = 1080;
w2 = 1136;
h2 = 136;
src = tgc(tmemalign(32, w1 * h1 * c));
dst = tgc(tmemalign(32, w2 * h2 * c));
EZBENCH2("BilinearScale", donothing,
BilinearScale(c, h2, w2, dst, c, h1, w1, src, 0, c, h2, w2, h1, w1,
h2 / h1, w2 / w1, 0, 0));
}

View file

@ -0,0 +1,34 @@
/*-*- 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
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/runtime/gc.h"
#include "libc/testlib/testlib.h"
#include "tool/viz/lib/convolution.h"
TEST(convoindex, test) {
unsigned *ix;
ix = gc(convoindex(2, 2, 2));
ix += 2;
EXPECT_EQ(0, ix[-2]);
EXPECT_EQ(0, ix[-1]);
EXPECT_EQ(0, ix[+0]);
EXPECT_EQ(1, ix[+1]);
EXPECT_EQ(1, ix[+2]);
EXPECT_EQ(1, ix[+3]);
}

View file

@ -0,0 +1,333 @@
/*-*- 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
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/log/check.h"
#include "libc/macros.h"
#include "libc/rand/rand.h"
#include "libc/runtime/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "tool/viz/lib/ycbcr.h"
#define C1331(A, B, C, D) \
({ \
unsigned short Ax, Bx; \
unsigned char Al, Bl, Cl, Dl; \
Al = (A); \
Bl = (B); \
Cl = (C); \
Dl = (D); \
Bx = Bl; \
Bx += Cl; \
Bx *= 3; \
Ax = Al; \
Ax += Dl; \
Ax += Bx; \
Ax += 4; \
Ax >>= 3; \
Al = Ax; \
Al; \
})
TEST(C1331, test) {
EXPECT_EQ(0, C1331(0, 0, 0, 0));
EXPECT_EQ(255, C1331(255, 255, 255, 255));
EXPECT_EQ(79, C1331(33, 100, 77, 69));
EXPECT_EQ(80, C1331(39, 100, 77, 69));
}
#define C161(A, B, C) \
({ \
short Dx; \
unsigned char Dl; \
unsigned char Al, Bl, Cl; \
unsigned short Ax, Bx, Cx; \
Al = (A); \
Bl = (B); \
Cl = (C); \
\
Bx = Bl; \
Bx += 3; \
Bx >>= 1; \
Bx += Bl; \
\
Ax = Al; \
Ax += 4; \
Ax >>= 2; \
\
Cx = Cl; \
Cx += 4; \
Cx >>= 2; \
\
Dx = Bx; \
Dx -= Ax; \
Dx -= Cx; \
\
Dx = MAX(0, Dx); \
Dx = MIN(255, Dx); \
Dl = Dx; \
Dl; \
})
TEST(C161, test) {
EXPECT_EQ(0, C161(0, 0, 0));
EXPECT_EQ(255, C161(255, 255, 255));
EXPECT_EQ(124, C161(33, 100, 69)); /* 124.50 = 3/2.*100 -1/4.*33 -1/4.*69 */
EXPECT_EQ(124, C161(33, 100, 70)); /* 124.25 = 3/2.*100 -1/4.*33 -1/4.*70 */
EXPECT_EQ(126, C161(33, 101, 69)); /* 126.00 = 3/2.*101 -1/4.*33 -1/4.*69 */
}
#define C121(A, B, C) \
({ \
short Dx; \
unsigned char Dl; \
unsigned char Al, Bl, Cl; \
unsigned short Ax, Bx, Cx; \
Al = (A); \
Bl = (B); \
Cl = (C); \
\
Bx = Bl; \
Bx += 3; \
Bx >>= 1; \
Bx += Bl; \
\
Ax = Al; \
Ax += 4; \
Ax >>= 2; \
\
Cx = Cl; \
Cx += 4; \
Cx >>= 2; \
\
Dx = Bx; \
Dx -= Ax; \
Dx -= Cx; \
\
Dx = MAX(0, Dx); \
Dx = MIN(255, Dx); \
Dl = Dx; \
Dl; \
})
TEST(C121, test) {
EXPECT_EQ(0, C161(0, 0, 0));
EXPECT_EQ(255, C161(255, 255, 255));
EXPECT_EQ(124, C161(33, 100, 69)); /* 124.50 = 3/2.*100 -1/4.*33 -1/4.*69 */
EXPECT_EQ(124, C161(33, 100, 70)); /* 124.25 = 3/2.*100 -1/4.*33 -1/4.*70 */
EXPECT_EQ(126, C161(33, 101, 69)); /* 126.00 = 3/2.*101 -1/4.*33 -1/4.*69 */
}
#define BLERP(A, B, P) \
({ \
unsigned char Al, Bl, Cl, Dl; \
unsigned short Bx; \
Al = (A); \
Bl = (B); \
Cl = MAX(Al, Bl); \
Al = MIN(Al, Bl); \
Dl = Cl - Al; \
Bl = (P); \
Bx = Bl; \
Bx *= Dl; \
Bx += 255; \
Bx >>= 8; \
Bx += Al; \
Al = Bx; \
Al; \
})
TEST(BLERP, test) {
EXPECT_EQ(0, BLERP(0, 0, 128));
EXPECT_EQ(255, BLERP(255, 255, 128));
EXPECT_EQ(64, BLERP(0, 128, 128));
EXPECT_EQ(64, BLERP(128, 0, 128));
EXPECT_EQ(32, BLERP(0, 128, 64));
EXPECT_EQ(32, BLERP(128, 0, 64));
EXPECT_EQ(8, BLERP(0, 128, 16));
EXPECT_EQ(8, BLERP(128, 0, 16));
EXPECT_EQ(0, BLERP(0, 128, 0));
EXPECT_EQ(0, BLERP(128, 0, 0));
EXPECT_EQ(128, BLERP(0, 128, 255));
EXPECT_EQ(128, BLERP(128, 0, 255));
}
#define MIX(A, B) \
({ \
short Ax, Bx; \
Ax = (A); \
Bx = (B); \
Ax += Bx; \
Ax += 1; \
Ax /= 2; \
Ax; \
})
TEST(MIX, test) {
EXPECT_EQ(0, MIX(0, 0));
EXPECT_EQ(255, MIX(255, 255));
EXPECT_EQ(64, MIX(0, 128));
EXPECT_EQ(64, MIX(128, 0));
EXPECT_EQ(127, MIX(0, 254));
}
void ExpandLuminosityRange(unsigned n, unsigned char *Y) {
unsigned i, j;
unsigned char b[16];
unsigned short s[16];
CHECK_ALIGNED(16, Y);
for (i = 0; i < n; i += 16) {
memcpy(b, Y + i, 16);
for (j = 0; j < 16; ++j) b[j] = MAX(0, b[j] - 16);
for (j = 0; j < 16; ++j) s[j] = b[j];
for (j = 0; j < 16; ++j) s[j] *= 150;
for (j = 0; j < 16; ++j) s[j] /= 128;
for (j = 0; j < 16; ++j) s[j] = MIN(255, s[j]);
for (j = 0; j < 16; ++j) b[j] = s[j];
memcpy(Y + i, b, 16);
}
}
TEST(ExpandLuminosityRange, test) {
unsigned char Y[32];
Y[0] = 0;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(0, Y[0]);
Y[0] = 16;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(0, Y[0]);
Y[0] = 17;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(1, Y[0]);
Y[0] = 128;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(131, Y[0]);
Y[0] = 233;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(254, Y[0]);
Y[0] = 235;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(255, Y[0]);
Y[0] = 255;
ExpandLuminosityRange(16, Y);
EXPECT_EQ(255, Y[0]);
}
#if 1
void NtscItu601YCbCrToStandardRgb(unsigned n, unsigned char *restrict Y,
unsigned char *restrict Cb,
unsigned char *restrict Cr) {
unsigned i;
short r, g, b;
unsigned char y;
for (i = 0; i < n; ++i) {
y = MIN(255, (MIN(235, MAX(16, Y[i])) - 16) * 150 / 128);
r = y + ((Cr[i] + ((Cr[i] * 103) / 256)) - 179);
g = y - (((Cb[i] * 88) / 256) - 44 + ((Cr[i] * 183) / 256) - 91);
b = y + ((Cb[i] + ((Cb[i] * 198) / 256)) - 227);
Y[i] = MIN(255, MAX(0, r));
Cb[i] = MIN(255, MAX(0, g));
Cr[i] = MIN(255, MAX(0, b));
}
}
#else
void NtscItu601YCbCrToStandardRgb(size_t n, unsigned char *restrict Y,
unsigned char *restrict Cb,
unsigned char *restrict Cr) {
unsigned i;
short y, gb, gr, r, g, b;
unsigned char gs, cb, cr;
unsigned short bw, ky, kr, kb, kgb, kgr;
for (i = 0; i < n; ++i) {
y = Y[i];
cb = Cb[i];
cr = Cr[i];
y -= 16; /* luminance (expand tv range [16,235] for pc [0,255]) */
y = MAX(0, y);
y = MIN(234 - 16, y);
ky = y;
ky *= 150;
ky /= 128;
gs = ky;
kr = cr; /* red */
kr *= 103;
kr /= 256;
kr += cr;
r = kr;
r -= 179;
r += gs;
kb = cb; /* blue */
kb *= 198;
kb /= 256;
kb += cb;
b = kb;
b -= 227;
b += gs;
kgb = cb; /* green */
kgb *= 88;
kgb /= 256;
gb = kgb;
gb -= 44;
kgr = cr;
kgr *= 183;
kgr /= 256;
gr = kgr;
gr -= 91;
g = gs;
g -= gr;
g -= gb;
r = MAX(0, r); /* clamp */
g = MAX(0, g);
b = MAX(0, b);
r = MIN(255, r);
g = MIN(255, g);
b = MIN(255, b);
Y[i] = r;
Cb[i] = g;
Cr[i] = b;
}
}
#endif
TEST(NtscItu601YCbCrToStandardRgb, testWhite) {
unsigned char a, b, c;
a = 234;
b = 128;
c = 128;
NtscItu601YCbCrToStandardRgb(1, &a, &b, &c);
EXPECT_EQ(255, a);
EXPECT_EQ(255, b);
EXPECT_EQ(255, c);
a = 235;
b = 128;
c = 128;
NtscItu601YCbCrToStandardRgb(1, &a, &b, &c);
EXPECT_EQ(255, a);
EXPECT_EQ(255, b);
EXPECT_EQ(255, c);
a = 255;
b = 128;
c = 128;
NtscItu601YCbCrToStandardRgb(1, &a, &b, &c);
EXPECT_EQ(255, a);
EXPECT_EQ(255, b);
EXPECT_EQ(255, c);
}

View file

@ -0,0 +1,45 @@
/*-*- 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
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/testlib/testlib.h"
#include "tool/viz/lib/halfblit.h"
TEST(halfblit, test_4x4_to_2x2) {
EXPECT_BINEQ(u" ☺"
u"►◄",
halfblit(2, tgc(tunbing(u" ☺☻♥"
u"►◄↕‼"
u"♀♪♫☼"
u"∟↔▲▼"))));
}
TEST(halfblit, test_8x8_to_4x4) {
EXPECT_BINEQ(u" ☺☻♥"
u"►◄↕‼"
u"◘○◙♂"
u"↑↓→←",
halfblit(4, tgc(tunbing(u" ☺☻♥♦♣♠•"
u"►◄↕‼¶§▬↨"
u"◘○◙♂♀♪♫☼"
u"↑↓→←∟↔▲▼"
u"01234567"
u"░▒▓│┤╡╢╖"
u"╕╣║╗╝╜╛┐"
u"89:;<=>?"))));
}

62
test/tool/viz/lib/test.mk Normal file
View file

@ -0,0 +1,62 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += TEST_TOOL_VIZ_LIB
TEST_TOOL_VIZ_LIB_SRCS := $(wildcard test/tool/viz/lib/*.c)
TEST_TOOL_VIZ_LIB_SRCS_TEST = $(filter %_test.c,$(TEST_TOOL_VIZ_LIB_SRCS))
TEST_TOOL_VIZ_LIB_COMS = $(TEST_TOOL_VIZ_LIB_OBJS:%.o=%.com)
TEST_TOOL_VIZ_LIB_OBJS = \
$(TEST_TOOL_VIZ_LIB_SRCS:%=o/$(MODE)/%.zip.o) \
$(TEST_TOOL_VIZ_LIB_SRCS:%.c=o/$(MODE)/%.o)
TEST_TOOL_VIZ_LIB_BINS = \
$(TEST_TOOL_VIZ_LIB_COMS) \
$(TEST_TOOL_VIZ_LIB_COMS:%=%.dbg)
TEST_TOOL_VIZ_LIB_TESTS = \
$(TEST_TOOL_VIZ_LIB_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_TOOL_VIZ_LIB_CHECKS = \
$(TEST_TOOL_VIZ_LIB_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_TOOL_VIZ_LIB_DIRECTDEPS = \
DSP_MPEG \
LIBC_FMT \
LIBC_LOG \
LIBC_UNICODE \
LIBC_TIME \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_ALG \
LIBC_RAND \
LIBC_STDIO \
LIBC_STUBS \
LIBC_TINYMATH \
LIBC_TESTLIB \
LIBC_X \
TOOL_VIZ_LIB \
THIRD_PARTY_AVIR
TEST_TOOL_VIZ_LIB_DEPS := \
$(call uniq,$(foreach x,$(TEST_TOOL_VIZ_LIB_DIRECTDEPS),$($(x))))
o/$(MODE)/test/tool/viz/lib/vizlib.pkg: \
$(TEST_TOOL_VIZ_LIB_OBJS) \
$(foreach x,$(TEST_TOOL_VIZ_LIB_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/tool/viz/lib/%.com.dbg: \
$(TEST_TOOL_VIZ_LIB_DEPS) \
o/$(MODE)/test/tool/viz/lib/%.o \
o/$(MODE)/test/tool/viz/lib/vizlib.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE)
@$(APELINK)
.PHONY: o/$(MODE)/test/tool/viz/lib
o/$(MODE)/test/tool/viz/lib: \
$(TEST_TOOL_VIZ_LIB_BINS) \
$(TEST_TOOL_VIZ_LIB_CHECKS)

View file

@ -0,0 +1,90 @@
/*-*- 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
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "dsp/mpeg/mpeg.h"
#include "libc/macros.h"
#include "libc/rand/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
#include "tool/viz/lib/graphic.h"
#include "tool/viz/lib/ycbcr.h"
#if 0
__v4sf fRGBA[4][3];
unsigned char iRGB[3][8][8];
unsigned char uRGB[4][4][3];
unsigned char kY[16][16] = {
{16, 43, 16, 43},
{70, 97, 70, 97},
{16, 43, 16, 43},
{70, 97, 70, 97},
};
unsigned char kCb[8][8] = {
{240, 240},
{240, 240},
};
unsigned char kCr[8][8] = {
{35, 35},
{35, 35},
};
plm_frame_t kFrame = {
.width = 4,
.height = 4,
.y = {.width = 16, .height = 16, .data = (void *)kY},
.cb = {.width = 8, .height = 8, .data = (void *)kCb},
.cr = {.width = 8, .height = 8, .data = (void *)kCr},
};
TEST(ycbcr2rgb, testMyImpl) {
memset(iRGB, 0, sizeof(iRGB));
YCbCr2RGB(1, iRGB, kY, kCb, kCr);
EXPECT_EQ(0, iRGB[0][0][0]);
EXPECT_BINEQ(u" "
u" ",
iRGB[1]);
}
TEST(ycbcr2rgb, testReferenceImpl) {
memset(uRGB, 0, sizeof(uRGB));
plm_frame_to_rgb(&kFrame, (void *)uRGB);
EXPECT_BINEQ(u" :╓", uRGB[0][0]);
EXPECT_BINEQ(u" ", uRGB[0][1]);
EXPECT_BINEQ(u" :╓", uRGB[0][2]);
EXPECT_BINEQ(u" ", uRGB[0][3]);
EXPECT_BINEQ(u" ", uRGB[1][0]);
EXPECT_BINEQ(u" ïλ", uRGB[1][1]);
EXPECT_BINEQ(u" ", uRGB[1][2]);
EXPECT_BINEQ(u" ïλ", uRGB[1][3]);
EXPECT_BINEQ(u" :╓", uRGB[2][0]);
EXPECT_BINEQ(u" ", uRGB[2][1]);
EXPECT_BINEQ(u" :╓", uRGB[2][2]);
EXPECT_BINEQ(u" ", uRGB[2][3]);
EXPECT_BINEQ(u" ", uRGB[3][0]);
EXPECT_BINEQ(u" ïλ", uRGB[3][1]);
EXPECT_BINEQ(u" ", uRGB[3][2]);
EXPECT_BINEQ(u" ïλ", uRGB[3][3]);
}
#endif

6
test/tool/viz/test.mk Normal file
View file

@ -0,0 +1,6 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
.PHONY: o/$(MODE)/test/tool/viz
o/$(MODE)/test/tool/viz: \
o/$(MODE)/test/tool/viz/lib