ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
render.c File Reference

Go to the source code of this file.

Data Structures

struct  glyph_candidate_t

Macros

#define VIDEO_ASCII_RENDER_SEQUENCE_BUFFER_SIZE   16
#define ASCII_TEMPORAL_MOTION_LIMIT   8
#define ASCII_TEMPORAL_MAX_INTERVAL_NS   250000000ULL
#define ASCII_TEMPORAL_COLOR_TIME_NS   50000000ULL
#define ascii_render_set_output_target   ascii_legacy_render_set_output_target
#define ascii_stabilizer_set_target   ascii_legacy_stabilizer_set_target
#define ascii_stabilizer_reset   ascii_legacy_stabilizer_reset
#define ascii_stabilizer_prepare   ascii_legacy_stabilizer_prepare
#define ascii_stabilizer_choose   ascii_legacy_stabilizer_choose
#define ascii_frame_init   ascii_legacy_frame_init
#define ascii_frame_emit_row   ascii_legacy_frame_emit_row
#define ascii_frame_finish   ascii_legacy_frame_finish
#define ascii_half_frame_init   ascii_legacy_half_frame_init
#define ascii_frame_emit_halfrow   ascii_legacy_frame_emit_halfrow
#define ascii_render   ascii_legacy_render
#define ascii_render_halfblocks   ascii_legacy_render_halfblocks
#define ASCII_RENDER_WORKSPACE_POOL_SIZE   4
#define GLYPH_ASCII_COUNT   95
#define GLYPH_BLOCK_COUNT   20
#define GLYPH_COUNT   (GLYPH_ASCII_COUNT + GLYPH_BLOCK_COUNT)

Functions

outbuf_t * ascii_legacy_render_set_output_target (outbuf_t *target)
ascii_stabilizer_t * ascii_legacy_stabilizer_set_target (ascii_stabilizer_t *state)
void ascii_legacy_stabilizer_reset (ascii_stabilizer_t *state)
asciichat_error_t ascii_legacy_stabilizer_prepare (ascii_stabilizer_t *state, size_t width, size_t height, uint64_t configuration)
uint32_t ascii_legacy_stabilizer_choose (ascii_temporal_cell_t *cell, const uint8_t samples[16], uint32_t candidate, uint64_t candidate_error, uint64_t previous_error, uint32_t color, uint64_t elapsed_ns, uint32_t *stabilized_color)
asciichat_error_t ascii_legacy_frame_init (ascii_frame_t *frame, const image_t *image, const char *palette)
void ascii_legacy_frame_emit_row (ascii_frame_t *frame, ascii_color_t mode, bool background, bool more_rows, const simd_cells_t *ops)
char * ascii_legacy_frame_finish (ascii_frame_t *frame)
asciichat_error_t ascii_legacy_half_frame_init (ascii_frame_t *frame, const uint8_t *rgb, int width, int height, int *stride, ascii_color_t mode)
void ascii_legacy_frame_emit_halfrow (ascii_frame_t *frame, ascii_color_t mode, bool more_rows, const simd_cells_t *ops)
char * ascii_legacy_render (const image_t *image, const char *palette, ascii_color_t mode, bool background, bool dither, const simd_cells_t *ops)
char * ascii_legacy_render_halfblocks (const uint8_t *rgb, int width, int height, int stride, ascii_color_t mode, const simd_cells_t *ops)
bool ascii_glyph_palette_supported (const char *palette)
char * ascii_render_glyph_match (const image_t *image, ascii_color_t mode, const simd_cells_t *ops, const char *palette)
char * ascii_render_glyph_match_mode (const image_t *image, ascii_color_t mode, const simd_cells_t *ops, const char *palette, bool background)

Detailed Description

Shared cell construction and terminal emission for scalar and SIMD kernels.

Definition in file lib/video/ascii/render.c.

Macro Definition Documentation

◆ ascii_frame_emit_halfrow

#define ascii_frame_emit_halfrow   ascii_legacy_frame_emit_halfrow

◆ ascii_frame_emit_row

◆ ascii_frame_finish

◆ ascii_frame_init

◆ ascii_half_frame_init

#define ascii_half_frame_init   ascii_legacy_half_frame_init

◆ ascii_render

◆ ascii_render_halfblocks

◆ ascii_render_set_output_target

#define ascii_render_set_output_target   ascii_legacy_render_set_output_target

◆ ASCII_RENDER_WORKSPACE_POOL_SIZE

#define ASCII_RENDER_WORKSPACE_POOL_SIZE   4

Definition at line 54 of file lib/video/ascii/render.c.

◆ ascii_stabilizer_choose

◆ ascii_stabilizer_prepare

#define ascii_stabilizer_prepare   ascii_legacy_stabilizer_prepare

Definition at line 29 of file lib/video/ascii/render.c.

Referenced by ascii_convert_with_buffers_stabilized().

◆ ascii_stabilizer_reset

◆ ascii_stabilizer_set_target

#define ascii_stabilizer_set_target   ascii_legacy_stabilizer_set_target

Definition at line 27 of file lib/video/ascii/render.c.

Referenced by ascii_convert_with_buffers_stabilized().

◆ ASCII_TEMPORAL_COLOR_TIME_NS

◆ ASCII_TEMPORAL_MAX_INTERVAL_NS

◆ ASCII_TEMPORAL_MOTION_LIMIT

◆ GLYPH_ASCII_COUNT

#define GLYPH_ASCII_COUNT   95

Definition at line 498 of file lib/video/ascii/render.c.

Referenced by ascii_glyph_render(), and ascii_render_glyph_match_mode().

◆ GLYPH_BLOCK_COUNT

#define GLYPH_BLOCK_COUNT   20

Definition at line 499 of file lib/video/ascii/render.c.

◆ GLYPH_COUNT

#define GLYPH_COUNT   (GLYPH_ASCII_COUNT + GLYPH_BLOCK_COUNT)

Definition at line 500 of file lib/video/ascii/render.c.

Referenced by ascii_glyph_render(), and ascii_render_glyph_match_mode().

◆ VIDEO_ASCII_RENDER_SEQUENCE_BUFFER_SIZE

#define VIDEO_ASCII_RENDER_SEQUENCE_BUFFER_SIZE   16

Definition at line 6 of file lib/video/ascii/render.c.

Function Documentation

◆ ascii_glyph_palette_supported()

bool ascii_glyph_palette_supported ( const char * palette)

Definition at line 542 of file lib/video/ascii/render.c.

542 {
543 if (!palette || !*palette)
544 return false;
545 for (const uint8_t *p = (const uint8_t *)palette; *p;) {
546 size_t length;
547 if (glyph_palette_index(p, &length) < 0)
548 return false;
549 p += length;
550 }
551 return true;
552}
unsigned char uint8_t

Referenced by ascii_render_glyph_match_mode().

◆ ascii_legacy_frame_emit_halfrow()

void ascii_legacy_frame_emit_halfrow ( ascii_frame_t * frame,
ascii_color_t mode,
bool more_rows,
const simd_cells_t * ops )

Definition at line 462 of file lib/video/ascii/render.c.

462 {
463 if (frame->stabilizer) {
464 size_t top_row = frame->row * 2;
465 bool has_bottom = top_row + 1 < frame->source_height;
466 for (size_t x = 0; x < frame->width; ++x) {
467 uint32_t *pixels[] = {&frame->packed[x], &frame->index[x]};
468 for (size_t half = 0; half < (has_bottom ? 2u : 1u); ++half) {
469 uint32_t color = *pixels[half];
470 uint8_t luma = (uint8_t)((76u * (color >> 16) + 150u * ((color >> 8) & 255) + 29u * (color & 255)) >> 8);
471 uint8_t samples[16];
472 memset(samples, luma, sizeof(samples));
473 ascii_temporal_cell_t *cell = &frame->stabilizer->cells[(top_row + half) * frame->width + x];
474 ascii_stabilizer_choose(cell, samples, 0, 0, UINT64_MAX, color, frame->stabilizer->elapsed_ns, pixels[half]);
475 }
476 if (!has_bottom)
477 frame->index[x] = frame->packed[x];
478 }
479 if (mode == ASCII_COLOR_TRUE) {
480 memcpy(frame->fg, frame->packed, frame->width * sizeof(uint32_t));
481 memcpy(frame->bg, frame->index, frame->width * sizeof(uint32_t));
482 } else if (mode != ASCII_COLOR_NONE) {
483 ops->quantize(frame->packed, frame->fg, frame->width, mode == ASCII_COLOR_16 ? 16 : 256);
484 ops->quantize(frame->index, frame->bg, frame->width, mode == ASCII_COLOR_16 ? 16 : 256);
485 }
486 ops->halfblock(frame->packed, frame->index, frame->glyph, frame->fg, frame->bg, frame->width, (unsigned)mode, frame->table);
487 }
488 emit_prepared_row(&frame->output, mode, ops, frame->glyph, frame->fg, frame->bg, frame->width);
489 emit_row_end(&frame->output, mode != ASCII_COLOR_NONE, more_rows);
490 ++frame->row;
491}
unsigned int uint32_t
#define ascii_stabilizer_choose
void emit_row_end(outbuf_t *out, bool colored, bool newline)
ascii_temporal_cell_t * cells
Definition stabilize.h:25
uint64_t elapsed_ns
Definition stabilize.h:28
void(* halfblock)(const uint32_t *top, const uint32_t *bottom, uint32_t *glyph, uint32_t *fg, uint32_t *bg, size_t count, unsigned mode, const uint32_t keys[5])
Definition cells.h:19
void(* quantize)(const uint32_t *rgb, uint32_t *out, size_t count, unsigned colors)
Definition cells.h:18

References ASCII_COLOR_16, ASCII_COLOR_NONE, ASCII_COLOR_TRUE, ascii_stabilizer_choose, ascii_frame_t::bg, ascii_stabilizer_t::cells, ascii_stabilizer_t::elapsed_ns, emit_row_end(), ascii_frame_t::fg, ascii_frame_t::glyph, simd_cells_t::halfblock, ascii_frame_t::index, ascii_frame_t::output, ascii_frame_t::packed, simd_cells_t::quantize, ascii_frame_t::row, ascii_frame_t::source_height, ascii_frame_t::stabilizer, ascii_frame_t::table, and ascii_frame_t::width.

◆ ascii_legacy_frame_emit_row()

void ascii_legacy_frame_emit_row ( ascii_frame_t * frame,
ascii_color_t mode,
bool background,
bool more_rows,
const simd_cells_t * ops )

Definition at line 356 of file lib/video/ascii/render.c.

356 {
357 if (frame->stabilizer && !frame->temporal_preselected) {
358 const uint64_t elapsed = frame->stabilizer->elapsed_ns;
359 const bool recent = elapsed <= ASCII_TEMPORAL_MAX_INTERVAL_NS;
360 const unsigned weight = recent ? (unsigned)(elapsed * 256 / (elapsed + ASCII_TEMPORAL_COLOR_TIME_NS)) : 256;
361 for (size_t x = 0; x < frame->width; ++x) {
362 ascii_temporal_cell_t *cell = &frame->stabilizer->cells[frame->row * frame->width + x];
363 uint8_t luma = frame->luma[x];
364 uint32_t glyph = frame->glyph[x];
365 uint32_t color = frame->packed[x];
366 if (cell->valid && recent && abs((int)luma - (int)cell->samples[0]) <= ASCII_TEMPORAL_MOTION_LIMIT) {
367 if (cell->glyph != glyph) {
368 // Only nearby brightness bins can win the hysteresis test. Searching
369 // outward avoids scanning the entire 64-entry palette for every cell.
370 unsigned bin = luma >> 2;
371 int best_delta = (int)luma - ((int)bin * 4 + 2);
372 uint64_t best_error = (uint64_t)(best_delta * best_delta);
373 uint64_t margin = best_error / 8 + 128;
374 for (unsigned distance = 1; distance < 64; ++distance) {
375 bool found = false;
376 for (int direction = -1; direction <= 1; direction += 2) {
377 int index = (int)bin + direction * (int)distance;
378 if (index < 0 || index >= 64 || frame->table[index] != cell->glyph)
379 continue;
380 int delta = (int)luma - (index * 4 + 2);
381 uint64_t error = (uint64_t)(delta * delta);
382 if (error <= best_error || error - best_error <= margin)
383 glyph = cell->glyph;
384 found = true;
385 }
386 // Bins farther than this cannot fall within the error margin.
387 int nearest_delta = (int)distance * 4 - 3;
388 if (found || (uint64_t)(nearest_delta * nearest_delta) > best_error + margin)
389 break;
390 }
391 }
392 color = temporal_blend_color(cell->color, color, weight);
393 }
394 cell->samples[0] = luma;
395 cell->glyph = frame->glyph[x] = glyph;
396 cell->color = frame->packed[x] = color;
397 cell->valid = true;
398 if (background)
399 frame->luma[x] = (uint8_t)((77u * (color >> 16) + 150u * ((color >> 8) & 255) + 29u * (color & 255) + 128u) >> 8);
400 }
401 if (!frame->dithered && (mode == ASCII_COLOR_16 || mode == ASCII_COLOR_256))
402 ops->quantize(frame->packed, frame->index, frame->width, mode == ASCII_COLOR_16 ? 16 : 256);
403 }
404 for (size_t x = 0; x < frame->width; ++x) {
405 frame->fg[x] = frame->bg[x] = UINT32_MAX;
406 if (mode == ASCII_COLOR_NONE)
407 continue;
408 uint32_t value = mode == ASCII_COLOR_TRUE ? frame->packed[x] : frame->index[x];
409 uint32_t contrast = frame->luma[x] < 128 ? (mode == ASCII_COLOR_TRUE ? 0xffffffu : 15u) : 0;
410 if (mode == ASCII_COLOR_16) {
411 uint8_t r, g, b;
412 get_16color_rgb((uint8_t)value, &r, &g, &b);
413 contrast = (77 * r + 150 * g + 29 * b) / 256 < 127 ? 15u : 0;
414 }
415 frame->fg[x] = background ? contrast : value;
416 frame->bg[x] = background ? value : UINT32_MAX;
417 }
418 emit_prepared_row(&frame->output, mode, ops, frame->glyph, frame->fg, frame->bg, frame->width);
419 emit_row_end(&frame->output, mode != ASCII_COLOR_NONE, more_rows);
420 ++frame->row;
421}
void get_16color_rgb(uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b)
Definition ansi.c:396
unsigned long long uint64_t
#define ASCII_TEMPORAL_COLOR_TIME_NS
#define ASCII_TEMPORAL_MAX_INTERVAL_NS
#define ASCII_TEMPORAL_MOTION_LIMIT
static bool size_t index
Definition queries.h:10
uint8_t samples[16]
Definition stabilize.h:14

References ASCII_COLOR_16, ASCII_COLOR_256, ASCII_COLOR_NONE, ASCII_COLOR_TRUE, ASCII_TEMPORAL_COLOR_TIME_NS, ASCII_TEMPORAL_MAX_INTERVAL_NS, ASCII_TEMPORAL_MOTION_LIMIT, ascii_frame_t::bg, ascii_stabilizer_t::cells, ascii_temporal_cell_t::color, ascii_frame_t::dithered, ascii_stabilizer_t::elapsed_ns, emit_row_end(), ascii_frame_t::fg, get_16color_rgb(), ascii_frame_t::glyph, ascii_temporal_cell_t::glyph, ascii_frame_t::index, index, ascii_frame_t::luma, ascii_frame_t::output, ascii_frame_t::packed, simd_cells_t::quantize, ascii_frame_t::row, ascii_temporal_cell_t::samples, ascii_frame_t::stabilizer, ascii_frame_t::table, ascii_frame_t::temporal_preselected, ascii_temporal_cell_t::valid, and ascii_frame_t::width.

◆ ascii_legacy_frame_finish()

char * ascii_legacy_frame_finish ( ascii_frame_t * frame)

Definition at line 422 of file lib/video/ascii/render.c.

422 {
423 if (frame->scratch != frame->inline_scratch)
424 release_scratch(frame->scratch);
425 ob_term(&frame->output);
426 if (frame->output_target)
427 *frame->output_target = frame->output;
428 return frame->output.buf;
429}
void ob_term(outbuf_t *ob)
Append null terminator to buffer.
char * buf
Buffer pointer (allocated, owned by caller, must be freed).

References outbuf_t::buf, ascii_frame_t::inline_scratch, ob_term(), ascii_frame_t::output, ascii_frame_t::output_target, and ascii_frame_t::scratch.

◆ ascii_legacy_frame_init()

asciichat_error_t ascii_legacy_frame_init ( ascii_frame_t * frame,
const image_t * image,
const char * palette )

Definition at line 324 of file lib/video/ascii/render.c.

324 {
325 ASCII_OTEL_SCOPE(ASCII_FRAME_INIT);
326 outbuf_t *target = g_output_target;
327 memset(frame, 0, sizeof(*frame));
328 if (!image || !image->pixels || image->w <= 0 || image->h <= 0 || !palette || !palette[0])
329 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid image or palette");
330 size_t bytes, pixels, capacity, rows;
331 if (checked_size_mul((size_t)image->w, (size_t)image->h, &pixels) != ASCIICHAT_OK || checked_size_mul(pixels, 48u, &capacity) != ASCIICHAT_OK ||
332 checked_size_mul((size_t)image->h, 5u, &rows) != ASCIICHAT_OK || checked_size_add(capacity, rows, &capacity) != ASCIICHAT_OK || checked_size_add(capacity, 1u, &capacity) != ASCIICHAT_OK ||
333 checked_size_mul((size_t)image->w, 6 * sizeof(uint32_t), &bytes) != ASCIICHAT_OK)
334 return ERROR_INVALID_PARAM;
336 if (!cache)
337 return ERROR_INVALID_PARAM;
338 prepare_output(frame, capacity, target);
339 frame->width = (size_t)image->w;
340 ascii_stabilizer_t *stabilizer_target = ascii_stabilizer_target();
341 if (stabilizer_target && stabilizer_target->cells && stabilizer_target->width == (size_t)image->w && stabilizer_target->height == (size_t)image->h)
342 frame->stabilizer = stabilizer_target;
343 for (size_t i = 0; i < 64; ++i)
344 memcpy(frame->table + i, cache->cache64[i].utf8_bytes, cache->cache64[i].byte_len);
345 frame->scratch = acquire_scratch(frame->inline_scratch, bytes);
346 if (!frame->scratch)
347 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate ASCII scratch workspace");
348 frame->packed = frame->scratch;
349 frame->index = frame->packed + frame->width;
350 frame->glyph = frame->index + frame->width;
351 frame->fg = frame->glyph + frame->width;
352 frame->bg = frame->fg + frame->width;
353 frame->luma = (uint8_t *)(frame->bg + frame->width);
354 return ASCIICHAT_OK;
355}
#define SET_ERRNO(code,...)
@ ERROR_MEMORY
Definition error_codes.h:55
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
utf8_palette_cache_t * get_utf8_palette_cache(const char *ascii_chars)
Get UTF-8 palette cache for a character set.
struct utf8_palette_cache utf8_palette_cache_t
#define ASCII_OTEL_SCOPE(id)
Definition otel.h:102
ascii_stabilizer_t * ascii_stabilizer_target(void)
Definition stabilize.c:9
SIMD-friendly storage for one RGB pixel. r, g, and b hold the color channels and padding keeps the la...
int h
Image height in pixels (must be > 0).
rgb_pixel_t * pixels
Pixel data array (width * height RGB pixels, row-major order).
int w
Image width in pixels (must be > 0).
Dynamic output buffer (auto-expanding).

References ASCII_OTEL_SCOPE, ascii_stabilizer_target(), ASCIICHAT_OK, ascii_frame_t::bg, utf8_char_t::byte_len, utf8_palette_cache::cache64, ascii_stabilizer_t::cells, ERROR_INVALID_PARAM, ERROR_MEMORY, ascii_frame_t::fg, get_utf8_palette_cache(), ascii_frame_t::glyph, image::h, ascii_stabilizer_t::height, ascii_frame_t::index, ascii_frame_t::inline_scratch, ascii_frame_t::luma, ascii_frame_t::packed, image::pixels, ascii_frame_t::scratch, SET_ERRNO, ascii_frame_t::stabilizer, ascii_frame_t::table, utf8_char_t::utf8_bytes, image::w, ascii_frame_t::width, and ascii_stabilizer_t::width.

◆ ascii_legacy_half_frame_init()

asciichat_error_t ascii_legacy_half_frame_init ( ascii_frame_t * frame,
const uint8_t * rgb,
int width,
int height,
int * stride,
ascii_color_t mode )

Definition at line 431 of file lib/video/ascii/render.c.

431 {
432 ASCII_OTEL_SCOPE(ASCII_HALF_FRAME_INIT);
433 outbuf_t *target = g_output_target;
434 memset(frame, 0, sizeof(*frame));
435 size_t row_bytes, extent, bytes, capacity;
436 if (!rgb || width <= 0 || height <= 0 || mode < ASCII_COLOR_NONE || mode > ASCII_COLOR_TRUE || checked_size_mul((size_t)width, 3, &row_bytes) != ASCIICHAT_OK || row_bytes > INT_MAX)
437 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid half-block input");
438 if (*stride <= 0)
439 *stride = (int)row_bytes;
440 if ((size_t)*stride < row_bytes || checked_size_mul((size_t)*stride, (size_t)height, &extent) != ASCIICHAT_OK || checked_size_mul((size_t)width, 6 * sizeof(uint32_t), &bytes) != ASCIICHAT_OK ||
441 checked_size_mul((size_t)width, ((size_t)height + 1) / 2, &capacity) != ASCIICHAT_OK || checked_size_mul(capacity, 48u, &capacity) != ASCIICHAT_OK ||
442 checked_size_add(capacity, 1u, &capacity) != ASCIICHAT_OK)
443 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid half-block stride or size");
444 prepare_output(frame, capacity, target);
445 frame->width = (size_t)width;
446 frame->source_height = (size_t)height;
447 if (g_stabilizer_target && g_stabilizer_target->cells && g_stabilizer_target->width == (size_t)width && g_stabilizer_target->height == (size_t)height)
448 frame->stabilizer = g_stabilizer_target;
449 frame->scratch = acquire_scratch(frame->inline_scratch, bytes);
450 if (!frame->scratch)
451 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate ASCII scratch workspace");
452 frame->packed = frame->scratch;
453 frame->index = frame->packed + width;
454 frame->glyph = frame->index + width;
455 frame->fg = frame->glyph + width;
456 frame->bg = frame->fg + width;
457 const char blocks[5][4] = {"\xe2\x96\x91", "\xe2\x96\x92", "\xe2\x96\x93", "\xe2\x96\x88", "\xe2\x96\x80"};
458 for (size_t i = 0; i < 5; ++i)
459 memcpy(frame->table + i, blocks[i], 3);
460 return ASCIICHAT_OK;
461}
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24

References ASCII_COLOR_TRUE, ASCII_OTEL_SCOPE, ASCIICHAT_OK, ascii_frame_t::bg, ERROR_INVALID_PARAM, ERROR_MEMORY, ascii_frame_t::fg, ascii_frame_t::glyph, height, ascii_frame_t::index, ascii_frame_t::inline_scratch, ascii_frame_t::packed, ascii_frame_t::scratch, SET_ERRNO, ascii_frame_t::source_height, ascii_frame_t::stabilizer, ascii_frame_t::table, ascii_frame_t::width, and width.

◆ ascii_legacy_render()

char * ascii_legacy_render ( const image_t * image,
const char * palette,
ascii_color_t mode,
bool background,
bool dither,
const simd_cells_t * ops )

Definition at line 220 of file lib/video/ascii/render.c.

220 {
221 if (!ops || mode < ASCII_COLOR_NONE || mode > ASCII_COLOR_TRUE) {
222 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid rendering backend or color mode");
223 return NULL;
224 }
225 if (!dither) {
226#if SIMD_SUPPORT_SSE2
227 if (ops == &simd_cells_sse2)
228 return render_ascii_cells_sse2(image, palette, mode, background);
229#endif
230#if SIMD_SUPPORT_SSSE3
231 if (ops == &simd_cells_ssse3)
232 return render_ascii_cells_ssse3(image, palette, mode, background);
233#endif
234#if SIMD_SUPPORT_AVX2
235 if (ops == &simd_cells_avx2)
236 return render_ascii_cells_avx2(image, palette, mode, background);
237#endif
238#if SIMD_SUPPORT_NEON
239 if (ops == &simd_cells_neon)
240 return render_ascii_cells_neon(image, palette, mode, background);
241#endif
242#if SIMD_SUPPORT_SVE
243 if (ops == &simd_cells_sve)
244 return render_ascii_cells_sve(image, palette, mode, background);
245#endif
246 }
247 ascii_frame_t frame;
248 if (ascii_frame_init(&frame, image, palette) != ASCIICHAT_OK)
249 return NULL;
250 rgb_error_t *errors = NULL;
251 if (mode == ASCII_COLOR_16 && dither)
252 errors = SAFE_CALLOC((size_t)image->w * (size_t)image->h, sizeof(rgb_error_t), rgb_error_t *);
253 frame.dithered = errors != NULL;
254 for (int y = 0; y < image->h; ++y) {
255 const uint8_t *source = (const uint8_t *)(image->pixels + (size_t)y * frame.width);
256 ops->luminance(source, frame.luma, frame.width);
257 ops->pack(source, frame.packed, frame.width);
258 ops->lookup(frame.luma, frame.table, frame.glyph, frame.width);
259 if (mode == ASCII_COLOR_16 || mode == ASCII_COLOR_256) {
260 if (errors) {
261 // Floyd-Steinberg error propagation is ordered; the other stages remain SIMD.
262 for (int x = 0; x < image->w; ++x) {
263 uint32_t pixel = frame.packed[x];
264 frame.index[x] = rgb_to_16color_dithered((int)(pixel >> 16), (int)((pixel >> 8) & 255), (int)(pixel & 255), x, y, image->w, image->h, errors);
265 }
266 } else
267 ops->quantize(frame.packed, frame.index, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
268 }
269 ascii_frame_emit_row(&frame, mode, background, y + 1 < image->h, ops);
270 }
271 SAFE_FREE(errors);
272 return ascii_frame_finish(&frame);
273}
const simd_cells_t simd_cells_sve
const simd_cells_t simd_cells_sse2
const simd_cells_t simd_cells_avx2
const simd_cells_t simd_cells_ssse3
const simd_cells_t simd_cells_neon
audio_visualization_source_t source
Definition fft.c:25
uint8_t rgb_to_16color_dithered(int r, int g, int b, int x, int y, int width, int height, rgb_error_t *error_buffer)
Definition ansi.c:427
#define SAFE_FREE(ptr)
#define SAFE_CALLOC(count, size, cast)
char * render_ascii_cells_sve(const image_t *, const char *, ascii_color_t, bool)
char * render_ascii_cells_sse2(const image_t *, const char *, ascii_color_t, bool)
char * render_ascii_cells_ssse3(const image_t *, const char *, ascii_color_t, bool)
char * render_ascii_cells_neon(const image_t *, const char *, ascii_color_t, bool)
char * render_ascii_cells_avx2(const image_t *, const char *, ascii_color_t, bool)
#define ascii_frame_init
#define ascii_frame_emit_row
#define ascii_frame_finish
When code needs to work with ascii frame, it keeps output, output_target, width, source_height here i...
void(* pack)(const uint8_t *rgb, uint32_t *out, size_t count)
Definition cells.h:16
simd_luminance_fn luminance
Definition cells.h:15
void(* lookup)(const uint8_t *luma, const uint32_t table[64], uint32_t *out, size_t count)
Definition cells.h:17

References ASCII_COLOR_16, ASCII_COLOR_256, ASCII_COLOR_TRUE, ascii_frame_emit_row, ascii_frame_finish, ascii_frame_init, ASCIICHAT_OK, ascii_frame_t::dithered, ERROR_INVALID_PARAM, ascii_frame_t::glyph, image::h, ascii_frame_t::index, simd_cells_t::lookup, ascii_frame_t::luma, simd_cells_t::luminance, simd_cells_t::pack, ascii_frame_t::packed, image::pixels, simd_cells_t::quantize, render_ascii_cells_avx2(), render_ascii_cells_neon(), render_ascii_cells_sse2(), render_ascii_cells_ssse3(), render_ascii_cells_sve(), rgb_to_16color_dithered(), SAFE_CALLOC, SAFE_FREE, SET_ERRNO, simd_cells_avx2, simd_cells_neon, simd_cells_sse2, simd_cells_ssse3, simd_cells_sve, source, ascii_frame_t::table, image::w, and ascii_frame_t::width.

◆ ascii_legacy_render_halfblocks()

char * ascii_legacy_render_halfblocks ( const uint8_t * rgb,
int width,
int height,
int stride,
ascii_color_t mode,
const simd_cells_t * ops )

Definition at line 275 of file lib/video/ascii/render.c.

275 {
276#if SIMD_SUPPORT_SSE2
277 if (ops == &simd_cells_sse2)
278 return render_halfblocks_sse2(rgb, width, height, stride, mode);
279#endif
280#if SIMD_SUPPORT_SSSE3
281 if (ops == &simd_cells_ssse3)
282 return render_halfblocks_ssse3(rgb, width, height, stride, mode);
283#endif
284#if SIMD_SUPPORT_AVX2
285 if (ops == &simd_cells_avx2)
286 return render_halfblocks_avx2(rgb, width, height, stride, mode);
287#endif
288#if SIMD_SUPPORT_NEON
289 if (ops == &simd_cells_neon)
290 return render_halfblocks_neon(rgb, width, height, stride, mode);
291#endif
292#if SIMD_SUPPORT_SVE
293 if (ops == &simd_cells_sve)
294 return render_halfblocks_sve(rgb, width, height, stride, mode);
295#endif
296
297 if (width <= 0 || height <= 0)
298 return platform_strdup("");
299 if (!ops) {
300 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid half-block backend");
301 return NULL;
302 }
303 ascii_frame_t frame;
304 if (ascii_half_frame_init(&frame, rgb, width, height, &stride, mode) != ASCIICHAT_OK)
305 return NULL;
306 for (size_t y = 0; y < (size_t)height; y += 2) {
307 const uint8_t *top = rgb + y * (size_t)stride;
308 const uint8_t *bottom = y + 1 < (size_t)height ? top + stride : top;
309 ops->pack(top, frame.packed, frame.width);
310 ops->pack(bottom, frame.index, frame.width);
311 if (mode == ASCII_COLOR_TRUE) {
312 memcpy(frame.fg, frame.packed, frame.width * sizeof(uint32_t));
313 memcpy(frame.bg, frame.index, frame.width * sizeof(uint32_t));
314 } else if (mode != ASCII_COLOR_NONE) {
315 ops->quantize(frame.packed, frame.fg, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
316 ops->quantize(frame.index, frame.bg, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
317 }
318 ops->halfblock(frame.packed, frame.index, frame.glyph, frame.fg, frame.bg, frame.width, (unsigned)mode, frame.table);
319 ascii_frame_emit_halfrow(&frame, mode, y + 2 < (size_t)height, ops);
320 }
321 return ascii_frame_finish(&frame);
322}
char * render_halfblocks_sse2(const uint8_t *, int, int, int, ascii_color_t)
char * render_halfblocks_ssse3(const uint8_t *, int, int, int, ascii_color_t)
char * render_halfblocks_avx2(const uint8_t *, int, int, int, ascii_color_t)
char * render_halfblocks_sve(const uint8_t *, int, int, int, ascii_color_t)
char * render_halfblocks_neon(const uint8_t *, int, int, int, ascii_color_t)
#define ascii_frame_emit_halfrow
#define ascii_half_frame_init
char * platform_strdup(const char *s)

References ASCII_COLOR_16, ASCII_COLOR_NONE, ASCII_COLOR_TRUE, ascii_frame_emit_halfrow, ascii_frame_finish, ascii_half_frame_init, ASCIICHAT_OK, ascii_frame_t::bg, ERROR_INVALID_PARAM, ascii_frame_t::fg, ascii_frame_t::glyph, simd_cells_t::halfblock, height, ascii_frame_t::index, simd_cells_t::pack, ascii_frame_t::packed, platform_strdup(), simd_cells_t::quantize, render_halfblocks_avx2(), render_halfblocks_neon(), render_halfblocks_sse2(), render_halfblocks_ssse3(), render_halfblocks_sve(), SET_ERRNO, simd_cells_avx2, simd_cells_neon, simd_cells_sse2, simd_cells_ssse3, simd_cells_sve, ascii_frame_t::table, ascii_frame_t::width, and width.

◆ ascii_legacy_render_set_output_target()

outbuf_t * ascii_legacy_render_set_output_target ( outbuf_t * target)

Definition at line 150 of file lib/video/ascii/render.c.

150 {
151 outbuf_t *previous = g_output_target;
152 g_output_target = target;
153 return previous;
154}

◆ ascii_legacy_stabilizer_choose()

uint32_t ascii_legacy_stabilizer_choose ( ascii_temporal_cell_t * cell,
const uint8_t samples[16],
uint32_t candidate,
uint64_t candidate_error,
uint64_t previous_error,
uint32_t color,
uint64_t elapsed_ns,
uint32_t * stabilized_color )

Definition at line 123 of file lib/video/ascii/render.c.

124 {
125 unsigned motion = 0;
126 if (cell->valid) {
127 for (size_t i = 0; i < 16; ++i)
128 motion += (unsigned)abs((int)samples[i] - (int)cell->samples[i]);
129 motion /= 16;
130 }
131 uint32_t result = candidate;
132 uint32_t output_color = color;
133 if (cell->valid && motion <= ASCII_TEMPORAL_MOTION_LIMIT && elapsed_ns <= ASCII_TEMPORAL_MAX_INTERVAL_NS) {
134 uint64_t margin = candidate_error / 8 + 128;
135 if (previous_error != UINT64_MAX && (previous_error <= candidate_error || previous_error - candidate_error <= margin))
136 result = cell->glyph;
137 // Weight depends on elapsed time, avoiding a different response at each FPS.
138 unsigned weight = (unsigned)(elapsed_ns * 256 / (elapsed_ns + ASCII_TEMPORAL_COLOR_TIME_NS));
139 output_color = temporal_blend_color(cell->color, color, weight);
140 }
141 memcpy(cell->samples, samples, sizeof(cell->samples));
142 cell->glyph = result;
143 cell->color = output_color;
144 cell->valid = true;
145 if (stabilized_color)
146 *stabilized_color = output_color;
147 return result;
148}

References ASCII_TEMPORAL_COLOR_TIME_NS, ASCII_TEMPORAL_MAX_INTERVAL_NS, ASCII_TEMPORAL_MOTION_LIMIT, ascii_temporal_cell_t::color, ascii_temporal_cell_t::glyph, ascii_temporal_cell_t::samples, and ascii_temporal_cell_t::valid.

◆ ascii_legacy_stabilizer_prepare()

asciichat_error_t ascii_legacy_stabilizer_prepare ( ascii_stabilizer_t * state,
size_t width,
size_t height,
uint64_t configuration )

Definition at line 95 of file lib/video/ascii/render.c.

95 {
96 if (!state || !width || !height || width > SIZE_MAX / height || width * height > SIZE_MAX / sizeof(ascii_temporal_cell_t))
97 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid stabilization viewport");
98 if (state->cells && state->width == width && state->height == height && state->configuration == configuration)
99 return ASCIICHAT_OK;
101 if (!cells)
102 return SET_ERRNO(ERROR_MEMORY, "Cannot allocate stabilization history");
103 SAFE_FREE(state->cells);
104 state->cells = cells;
105 state->width = width;
106 state->height = height;
107 state->configuration = configuration;
108 state->last_timestamp_ns = 0;
109 state->elapsed_ns = UINT64_MAX;
110 return ASCIICHAT_OK;
111}
char cells[(512 *256 *2)]
Definition fft.c:22
uint64_t last_timestamp_ns
Definition stabilize.h:29
uint64_t configuration
Definition stabilize.h:27

References ASCIICHAT_OK, ascii_stabilizer_t::cells, cells, ascii_stabilizer_t::configuration, ascii_stabilizer_t::elapsed_ns, ERROR_INVALID_PARAM, ERROR_MEMORY, ascii_stabilizer_t::height, height, ascii_stabilizer_t::last_timestamp_ns, SAFE_CALLOC, SAFE_FREE, SET_ERRNO, ascii_stabilizer_t::width, and width.

◆ ascii_legacy_stabilizer_reset()

void ascii_legacy_stabilizer_reset ( ascii_stabilizer_t * state)

Definition at line 88 of file lib/video/ascii/render.c.

88 {
89 if (!state)
90 return;
91 SAFE_FREE(state->cells);
92 memset(state, 0, sizeof(*state));
93}

References ascii_stabilizer_t::cells, and SAFE_FREE.

◆ ascii_legacy_stabilizer_set_target()

ascii_stabilizer_t * ascii_legacy_stabilizer_set_target ( ascii_stabilizer_t * state)

Definition at line 82 of file lib/video/ascii/render.c.

82 {
83 ascii_stabilizer_t *previous = g_stabilizer_target;
84 g_stabilizer_target = state;
85 return previous;
86}

◆ ascii_render_glyph_match()

char * ascii_render_glyph_match ( const image_t * image,
ascii_color_t mode,
const simd_cells_t * ops,
const char * palette )

Definition at line 586 of file lib/video/ascii/render.c.

586 {
587 return ascii_render_glyph_match_mode(image, mode, ops, palette, false);
588}
char * ascii_render_glyph_match_mode(const image_t *image, ascii_color_t mode, const simd_cells_t *ops, const char *palette, bool background)

References ascii_render_glyph_match_mode().

◆ ascii_render_glyph_match_mode()

char * ascii_render_glyph_match_mode ( const image_t * image,
ascii_color_t mode,
const simd_cells_t * ops,
const char * palette,
bool background )

Definition at line 590 of file lib/video/ascii/render.c.

590 {
591 if (!image || !image->pixels || !ops || image->w <= 0 || image->h <= 0 || image->w % 8 || image->h % 8 || mode < ASCII_COLOR_NONE || mode > ASCII_COLOR_TRUE) {
592 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid glyph matching input");
593 return NULL;
594 }
595 bool allowed[GLYPH_COUNT] = {false};
596 bool use_chroma_shape = false;
597 if (mode == ASCII_COLOR_TRUE && palette) {
598 for (const uint8_t *p = (const uint8_t *)palette; *p; ++p) {
599 if (*p >= 0x80) {
600 use_chroma_shape = true;
601 break;
602 }
603 }
604 }
605 int candidates[GLYPH_COUNT];
606 // Restrict the atlas to unique palette entries before scoring any cells.
607 size_t candidate_count = 0;
608 int (*shape_correlation)(const int16_t[16], const int16_t[16]) = ops->glyph_shape_correlation ? ops->glyph_shape_correlation : glyph_shape_correlation_scalar;
609 if (palette) {
610 if (!ascii_glyph_palette_supported(palette)) {
611 SET_ERRNO(ERROR_INVALID_PARAM, "Glyph palette contains an unsupported character");
612 return NULL;
613 }
614 for (const uint8_t *p = (const uint8_t *)palette; *p;) {
615 size_t length = 1;
616 int index = glyph_palette_index(p, &length);
617 if (!allowed[index]) {
618 allowed[index] = true;
619 candidates[candidate_count++] = index;
620 }
621 p += length;
622 }
623 } else {
624 for (int i = 0; i < GLYPH_ASCII_COUNT; ++i) {
625 allowed[i] = true;
626 candidates[candidate_count++] = i;
627 }
628 }
629 // Prepare coverage and its sufficient statistics once per frame.
631 // Precompute each mask's brightness and centered shape for correlation.
632 for (size_t c = 0; c < candidate_count; ++c) {
633 int g = candidates[c];
634 glyph_candidate_t *glyph = &glyphs[c];
635 glyph->key = glyph_key(g);
636 uint8_t block_mask[16];
637 const uint8_t *mask = g < GLYPH_ASCII_COUNT ? glyph_masks[g] : block_mask;
638 if (g >= GLYPH_ASCII_COUNT)
639 glyph_block_mask(g - GLYPH_ASCII_COUNT, block_mask);
640 glyph->sum = glyph->energy = 0;
641 for (int i = 0; i < 16; ++i) {
642 glyph->mask[i] = mask[i];
643 glyph->sum += mask[i];
644 }
645 int mean = glyph->sum / 16;
646 glyph->tone = glyph->sum * 255 / (g < GLYPH_ASCII_COUNT ? GLYPH_MASK_MAX_SUM : 16 * 255);
647 for (int i = 0; i < 16; ++i) {
648 glyph->centered[i] = (int16_t)((int)mask[i] - mean);
649 glyph->energy += glyph->centered[i] * glyph->centered[i];
650 }
651 }
653 cells.w /= 8;
654 cells.h /= 8;
655 ascii_frame_t frame;
656 if (ascii_frame_init(&frame, &cells, " .") != ASCIICHAT_OK)
657 return NULL;
658 frame.temporal_preselected = true;
659 for (int y = 0; y < cells.h; ++y) {
660 for (int x = 0; x < cells.w; ++x) {
661 int16_t samples[3][16] = {{0}};
662 int sums[3] = {0};
663 uint8_t patch[16];
664 int sample_mean = 0;
665 for (int sy = 0; sy < 4; ++sy) {
666 const rgb_pixel_t *top = image->pixels + (size_t)(y * 8 + sy * 2) * (size_t)image->w + (size_t)(x * 8);
667 const rgb_pixel_t *bottom = top + image->w;
668 for (int sx = 0; sx < 4; ++sx) {
669 const rgb_pixel_t a = top[sx * 2], b = top[sx * 2 + 1];
670 const rgb_pixel_t c = bottom[sx * 2], d = bottom[sx * 2 + 1];
671 int i = sy * 4 + sx;
672 int red = (a.r + b.r + c.r + d.r) / 4;
673 int green = (a.g + b.g + c.g + d.g) / 4;
674 int blue = (a.b + b.b + c.b + d.b) / 4;
675 uint8_t luma = (uint8_t)((77 * red + 150 * green + 29 * blue) >> 8);
676 patch[i] = (uint8_t)(luma + (luma * (255 - luma) + 256) / 512);
677 samples[0][i] = (int16_t)red;
678 samples[1][i] = (int16_t)green;
679 samples[2][i] = (int16_t)blue;
680 sample_mean += patch[i];
681 for (int channel = 0; channel < 3; ++channel)
682 sums[channel] += samples[channel][i];
683 }
684 }
685 // Compare local shape independently of the patch's average brightness.
686 sample_mean /= 16;
687 int16_t centered_samples[16];
688 int sample_energy = 0;
689 for (int i = 0; i < 16; ++i) {
690 int centered = (int)patch[i] - sample_mean;
691 centered_samples[i] = (int16_t)centered;
692 sample_energy += centered * centered;
693 }
694 size_t best = 0, previous_index = 0;
695 uint64_t best_error = UINT64_MAX;
696 uint64_t previous_error = UINT64_MAX;
697 ascii_temporal_cell_t *previous = frame.stabilizer ? &frame.stabilizer->cells[(size_t)y * frame.width + x] : NULL;
698 for (size_t c = 0; c < candidate_count; ++c) {
699 bool is_previous = previous && previous->valid && previous->glyph == glyphs[c].key;
700 int tone_delta = sample_mean - glyphs[c].tone;
701 int tone_error = 16 * tone_delta * tone_delta;
702 // Shape error cannot lower the score below the brightness error.
703 if (!is_previous && (uint64_t)tone_error > best_error)
704 continue;
705 int dot = shape_correlation(centered_samples, glyphs[c].centered);
706 uint64_t error = (uint64_t)(tone_error + sample_energy + glyphs[c].energy - 2 * dot);
707 if (use_chroma_shape) {
708 // Luminance alone cannot distinguish equal-luminance chromatic
709 // regions. Use the strongest color-channel shape correlation as a
710 // secondary signal so vertical and horizontal boundaries retain
711 // their orientation in true-colour output.
712 int chroma_dot = 0;
713 for (int channel = 0; channel < 3; ++channel) {
714 int channel_mean = sums[channel] / 16;
715 int channel_dot = 0;
716 for (int i = 0; i < 16; ++i)
717 channel_dot += (samples[channel][i] - channel_mean) * glyphs[c].centered[i];
718 if (abs(channel_dot) > abs(chroma_dot))
719 chroma_dot = channel_dot;
720 }
721 uint64_t chroma_bonus = (uint64_t)(abs(chroma_dot) / 8);
722 error = chroma_bonus < error ? error - chroma_bonus : 0;
723 }
724 if (is_previous) {
725 previous_error = error;
726 previous_index = c;
727 }
728 if (error < best_error) {
729 best_error = error;
730 best = c;
731 }
732 }
733 uint32_t rgb = glyph_foreground(&glyphs[best], samples, sums);
734 uint32_t bg_rgb = ((uint32_t)(sums[0] / 128) << 16) | ((uint32_t)(sums[1] / 128) << 8) | (uint32_t)(sums[2] / 128);
735 uint32_t selected = glyphs[best].key;
736 if (previous) {
737 ascii_temporal_cell_t old = *previous;
738 unsigned motion = 0;
739 unsigned color_motion = 0;
740 for (int i = 0; i < 16; ++i)
741 motion += (unsigned)abs((int)patch[i] - (int)old.samples[i]);
742 if (old.valid && mode != ASCII_COLOR_NONE) {
743 for (int channel = 0; channel < 3; ++channel)
744 for (int i = 0; i < 16; ++i)
745 color_motion += (unsigned)abs(samples[channel][i] - (int)old.rgb_samples[channel][i]);
746 color_motion /= 48;
747 }
748 uint64_t elapsed = frame.stabilizer->elapsed_ns;
749 uint64_t effective_elapsed = color_motion > ASCII_TEMPORAL_MOTION_LIMIT ? UINT64_MAX : elapsed;
750 selected = ascii_stabilizer_choose(previous, patch, selected, best_error, previous_error, rgb, effective_elapsed, &rgb);
751 if (selected != glyphs[best].key) {
752 *previous = old;
753 selected = ascii_stabilizer_choose(previous, patch, glyphs[best].key, best_error, previous_error, glyph_foreground(&glyphs[previous_index], samples, sums), effective_elapsed, &rgb);
754 }
755 if (old.valid && motion / 16 <= ASCII_TEMPORAL_MOTION_LIMIT && color_motion <= ASCII_TEMPORAL_MOTION_LIMIT && elapsed <= ASCII_TEMPORAL_MAX_INTERVAL_NS) {
756 unsigned weight = (unsigned)(elapsed * 256 / (elapsed + ASCII_TEMPORAL_COLOR_TIME_NS));
757 bg_rgb = temporal_blend_color(old.background, bg_rgb, weight);
758 }
759 for (int channel = 0; channel < 3; ++channel)
760 for (int i = 0; i < 16; ++i)
761 previous->rgb_samples[channel][i] = (uint8_t)samples[channel][i];
762 previous->background = bg_rgb;
763 }
764 frame.glyph[x] = selected;
765 frame.packed[x] = rgb;
766 frame.index[x] = bg_rgb;
767 frame.luma[x] = (uint8_t)((77 * ((rgb >> 16) & 255) + 150 * ((rgb >> 8) & 255) + 29 * (rgb & 255)) >> 8);
768 }
769 if (background && mode != ASCII_COLOR_NONE) {
770 if (mode == ASCII_COLOR_TRUE) {
771 memcpy(frame.fg, frame.packed, frame.width * sizeof(uint32_t));
772 memcpy(frame.bg, frame.index, frame.width * sizeof(uint32_t));
773 } else {
774 ops->quantize(frame.packed, frame.fg, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
775 ops->quantize(frame.index, frame.bg, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
776 }
777 ascii_emit_prepared_row(&frame.output, mode, ops, frame.glyph, frame.fg, frame.bg, frame.width);
778 emit_row_end(&frame.output, true, y + 1 < cells.h);
779 ++frame.row;
780 } else {
781 if (mode == ASCII_COLOR_16 || mode == ASCII_COLOR_256)
782 ops->quantize(frame.packed, frame.index, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
783 ascii_frame_emit_row(&frame, mode, false, y + 1 < cells.h, ops);
784 }
785 }
786 return ascii_frame_finish(&frame);
787}
int glyph_shape_correlation_scalar(const int16_t samples[16], const int16_t mask[16])
Definition cells.c:4
#define GLYPH_MASK_MAX_SUM
#define GLYPH_COUNT
#define GLYPH_ASCII_COUNT
bool ascii_glyph_palette_supported(const char *palette)
uint8_t rgb_samples[3][16]
Definition stabilize.h:15
uint8_t b
Blue color component (0-255).
uint8_t g
Green color component (0-255).
uint8_t r
Red color component (0-255).
int(* glyph_shape_correlation)(const int16_t samples[16], const int16_t mask[16])
Definition cells.h:23
void ascii_emit_prepared_row(outbuf_t *out, ascii_color_t mode, const simd_cells_t *ops, const uint32_t *glyph, const uint32_t *fg, const uint32_t *bg, size_t width)

References ASCII_COLOR_16, ASCII_COLOR_256, ASCII_COLOR_NONE, ASCII_COLOR_TRUE, ascii_emit_prepared_row(), ascii_frame_emit_row, ascii_frame_finish, ascii_frame_init, ascii_glyph_palette_supported(), ascii_stabilizer_choose, ASCII_TEMPORAL_COLOR_TIME_NS, ASCII_TEMPORAL_MAX_INTERVAL_NS, ASCII_TEMPORAL_MOTION_LIMIT, ASCIICHAT_OK, rgb_pixel_t::b, ascii_temporal_cell_t::background, ascii_frame_t::bg, ascii_stabilizer_t::cells, cells, glyph_candidate_t::centered, ascii_stabilizer_t::elapsed_ns, emit_row_end(), glyph_candidate_t::energy, ERROR_INVALID_PARAM, ascii_frame_t::fg, rgb_pixel_t::g, ascii_frame_t::glyph, GLYPH_ASCII_COUNT, GLYPH_COUNT, GLYPH_MASK_MAX_SUM, simd_cells_t::glyph_shape_correlation, glyph_shape_correlation_scalar(), image::h, ascii_frame_t::index, index, glyph_candidate_t::key, ascii_frame_t::luma, glyph_candidate_t::mask, ascii_frame_t::output, ascii_frame_t::packed, image::pixels, simd_cells_t::quantize, rgb_pixel_t::r, ascii_temporal_cell_t::rgb_samples, ascii_frame_t::row, ascii_temporal_cell_t::samples, SET_ERRNO, ascii_frame_t::stabilizer, glyph_candidate_t::sum, ascii_frame_t::temporal_preselected, glyph_candidate_t::tone, ascii_temporal_cell_t::valid, image::w, and ascii_frame_t::width.

Referenced by ascii_render_glyph_match().