mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-16 23:50:32 +00:00
Clean up more code
The *NSYNC linked list API is good enough that it deserves to be part of the C libray, so this change writes an improved version of it which uses that offsetof() trick from the Linux Kernel. We vendor all of the *NSYNC tests in third_party which helped confirm the needed refactoring is safe This change also deletes more old code that didn't pan out. My goal here is to work towards a vision where the Cosmopolitan core libraries become less experimental and more focused on curation. This better reflects the current level of quality we've managed to achieve.
This commit is contained in:
parent
88612a2cd7
commit
0a24b4fc3c
268 changed files with 632 additions and 8688 deletions
|
@ -25,5 +25,5 @@ void boxblur(struct Graphic *g) {
|
|||
{+1.0, +1.0, +1.0},
|
||||
{+1.0, +1.0, +1.0},
|
||||
};
|
||||
convolve(g->yn, g->xn, g->b.p, 3, kBoxBlurKernel, 9.0, 0);
|
||||
convolve(g->yn, g->xn, g->b, 3, kBoxBlurKernel, 9.0, 0);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_
|
||||
#define COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/viz/lib/graphic.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
@ -24,7 +25,7 @@ forceinline void convolve(unsigned yn, unsigned xn, ttyrgb_m128 img[yn][xn],
|
|||
}
|
||||
bzero(&g, sizeof(g));
|
||||
resizegraphic(&g, yn, xn);
|
||||
tmp = g.b.p;
|
||||
tmp = g.b;
|
||||
for (y = 0; y < yn - KW; ++y) {
|
||||
for (x = 0; x < xn - KW; ++x) {
|
||||
bzero(&p, sizeof(p));
|
||||
|
@ -37,7 +38,7 @@ forceinline void convolve(unsigned yn, unsigned xn, ttyrgb_m128 img[yn][xn],
|
|||
}
|
||||
}
|
||||
memcpy(img, tmp, yn * xn * sizeof(img[0][0]));
|
||||
bfree(&g.b);
|
||||
free(g.b);
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -26,5 +26,5 @@ void emboss(struct Graphic *g) {
|
|||
{-1.0, +1.0, +1.0},
|
||||
{+0.0, +1.0, +2.0},
|
||||
};
|
||||
convolve(g->yn, g->xn, g->b.p, 3, kEmbossKernel, 1, 0);
|
||||
convolve(g->yn, g->xn, g->b, 3, kEmbossKernel, 1, 0);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
void getxtermcodes(struct TtyRgb *p, const struct Graphic *g) {
|
||||
unsigned y, x;
|
||||
unsigned char(*img)[3][g->yn][g->xn] = g->b.p;
|
||||
unsigned char(*img)[3][g->yn][g->xn] = g->b;
|
||||
for (y = 0; y < g->yn; ++y) {
|
||||
for (x = 0; x < g->xn; ++x) {
|
||||
*p++ = rgb2tty((*img)[0][y][x], (*img)[1][y][x], (*img)[2][y][x]);
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_VIZ_LIB_GRAPHIC_H_
|
||||
#define COSMOPOLITAN_TOOL_VIZ_LIB_GRAPHIC_H_
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/runtime/buffer.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct Graphic {
|
||||
union {
|
||||
struct GuardedBuffer b;
|
||||
void *b;
|
||||
char *bytes;
|
||||
float (*lum)[2][8];
|
||||
float (*rgba)[2][2];
|
||||
|
|
|
@ -18,19 +18,14 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/runtime/buffer.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "tool/viz/lib/graphic.h"
|
||||
|
||||
/**
|
||||
* Allocates graphic.
|
||||
*
|
||||
* @param g should be zero initialized before first call
|
||||
* @note bfree(g->b) needs to be called later
|
||||
*/
|
||||
// TODO(jart): DELETE
|
||||
|
||||
struct Graphic *resizegraphic(struct Graphic *g, size_t yn, size_t xn) {
|
||||
/* assert(xn % 2 == 0); */ /* todo: ughhh this whole thing is wrong */
|
||||
yn &= ~1;
|
||||
balloc(&g->b, 64, yn * xn * sizeof(ttyrgb_m128) + /* wut */ PAGESIZE);
|
||||
g->b = pvalloc(yn * xn * sizeof(ttyrgb_m128));
|
||||
g->yn = yn;
|
||||
g->xn = xn;
|
||||
return g;
|
||||
|
|
|
@ -69,7 +69,7 @@ void sobel(struct Graphic* g) {
|
|||
FLIP(BROADCAST(-2), BROADCAST(+0), BROADCAST(+2)),
|
||||
FLIP(BROADCAST(-1), BROADCAST(+0), BROADCAST(+1)));
|
||||
if (g->yn >= 3 && g->xn >= 3) {
|
||||
ConvolveGradient(g->yn, g->xn, g->b.p, 3, &kSobelEmbossKernelY,
|
||||
ConvolveGradient(g->yn, g->xn, g->b, 3, &kSobelEmbossKernelY,
|
||||
&kSobelEmbossKernelX);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,7 @@ o/$(MODE)/tool/viz/lib/dither.o \
|
|||
o/$(MODE)/tool/viz/lib/emboss.o \
|
||||
o/$(MODE)/tool/viz/lib/getxtermcodes.o \
|
||||
o/$(MODE)/tool/viz/lib/lingamma.o \
|
||||
o/$(MODE)/tool/viz/lib/perlin3.o \
|
||||
o/$(MODE)/tool/viz/lib/resizegraphic.o: private \
|
||||
o/$(MODE)/tool/viz/lib/perlin3.o: private \
|
||||
CFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED \
|
||||
$(MATHEMATICAL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue