ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
common.h File Reference

SIMD-optimized ASCII conversion interface. More...

Go to the source code of this file.

Data Structures

struct  dec3_t
 Decimal conversion cache structure (1-3 digits). More...
struct  global_dec3_cache_t
 Global decimal cache for digit conversion. More...
struct  Str
 Growable NUL-terminated buffer used while assembling ASCII output. More...
struct  RLEState
 Run-length encoding state for ANSI color optimization. More...
struct  ImageRGB
 ImageRGB structure for NEON renderers. More...
struct  simd_benchmark_t
 SIMD benchmark results structure. More...
struct  utf8_char_t
struct  utf8_palette_cache

Macros

#define ASCII_LUMINANCE_LEVELS   256
#define ASCII_PALETTE_BUFFER_SIZE   256
#define RAMP64_SIZE   64
 UTF-8 character palette cache.
#define CACHE_FREQUENCY_DECAY_TIME   10000
#define CACHE_RECENCY_SCALE   100
#define CACHE_MAX_LIFETIME   3600
Luminance Calculation Constants

Cached decimal text for a small integer. len says how many characters are valid in the inline representation, allowing hot rendering paths to avoid formatting and allocation for values from one to three digits.

Global decimal cache for digit conversion

Small RGB image view used by the NEON renderer. w and h describe the image geometry and pixels points at row-major RGB storage owned by the caller; the renderer reads it and does not free the pixels.

Run-length encoding state for ANSI color optimization

This is the handoff point for simd benchmark. Callers fill scalar_time, sse2_time, ssse3_time, avx2_time before passing it on; consumers read the values during the operation and return ownership only where the member contract explicitly says they do.

Growable NUL-terminated buffer used while assembling ASCII output

utf8 char is intentionally a small, concrete record. Fields such as width, byte_len, _pad give callers the identity and current value they need. It is normally borrowed from, or owned by, the surrounding subsystem—not independently managed.

Owns the temporary storage used by utf8 palette cache. The data pointers and size or cursor fields describe the live portion of the allocation; callers must use the type's cleanup path when the buffer or queue is no longer needed.

#define LUMA_RED   77
 Luminance red coefficient (0.299 * 256 = 77).
#define LUMA_GREEN   150
 Luminance green coefficient (0.587 * 256 = 150).
#define LUMA_BLUE   29
 Luminance blue coefficient (0.114 * 256 = 29).
#define LUMA_THRESHOLD   128
 Luminance threshold for rounding.

Typedefs

typedef struct utf8_palette_cache utf8_palette_cache_t

Functions

void init_dec3 (void)
 Initialize decimal lookup table.
void ascii_simd_init (void)
 Initialize SIMD subsystem.
void init_default_luminance_palette (void)
 Initialize default luminance palette.
void str_init (Str *s)
 Initialize string buffer.
void str_destroy (Str *s)
 Free string buffer.
void str_reserve (Str *s, size_t need)
 Reserve space in string buffer.
void str_append_bytes (Str *s, const void *src, size_t n)
 Append bytes to string buffer.
void str_append_c (Str *s, char c)
 Append character to string buffer.
void str_printf (Str *s, const char *fmt,...)
 Append formatted string to buffer.
ImageRGB alloc_image (int w, int h)
 Allocate a new ImageRGB (RGB8 format).
void convert_pixels_scalar (const rgb_pixel_t *pixels, char *ascii_chars, int count, const char luminance_palette[256])
 Convert pixels to ASCII (scalar fallback).
char * convert_pixels_scalar_with_newlines (image_t *image, const char luminance_palette[256])
 Convert image to ASCII with newlines (scalar fallback).
simd_benchmark_t benchmark_simd_conversion (int width, int height, int iterations)
 Benchmark SIMD conversion methods (monochrome).
simd_benchmark_t benchmark_simd_color_conversion (int width, int height, int iterations, bool background_mode)
 Benchmark SIMD color conversion methods.
simd_benchmark_t benchmark_simd_conversion_with_source (int width, int height, int iterations, bool background_mode, const image_t *source_image, bool use_256color)
 Benchmark SIMD conversion with source image.
simd_benchmark_t benchmark_simd_color_conversion_with_source (int width, int height, int iterations, bool background_mode, const image_t *source_image, bool use_256color)
 Benchmark SIMD color conversion with source image.
void print_simd_capabilities (void)
 Print detected SIMD capabilities.
char * image_print_color_simd (image_t *image, bool use_background_mode, bool use_256color, const char *ascii_chars)
 Print image as ASCII with color using SIMD.
void set_color_quality_mode (bool high_quality)
 Set color quality mode.
bool get_256_color_fast_path (void)
 Get 256-color fast path setting.
void prewarm_sgr256_fg_cache (void)
 Prewarm 256-color foreground cache for benchmarks.
void prewarm_sgr256_cache (void)
 Prewarm 256-color foreground/background cache for benchmarks.
char * get_sgr256_fg_string (uint8_t fg, uint8_t *len_out)
 Get 256-color foreground ANSI sequence string.
char * get_sgr256_bg_string (uint8_t bg, uint8_t *len_out)
 Get 256-color background ANSI sequence string.
char * get_sgr256_fg_bg_string (uint8_t fg, uint8_t bg, uint8_t *len_out)
 Get 256-color foreground/background ANSI sequence string.
size_t write_row_rep_from_arrays_enhanced (const uint8_t *fg_r, const uint8_t *fg_g, const uint8_t *fg_b, const uint8_t *bg_r, const uint8_t *bg_g, const uint8_t *bg_b, const uint8_t *fg_idx, const uint8_t *bg_idx, const char *ascii_chars, int width, char *dst, size_t cap, bool is_truecolor)
 Enhanced REP compression writer.
void build_utf8_luminance_cache (const char *ascii_chars, utf8_char_t cache[256])
 Build UTF-8 luminance cache for all 256 levels.
void build_utf8_ramp64_cache (const char *ascii_chars, utf8_char_t cache64[64], uint8_t char_index_ramp[256])
 Build UTF-8 ramp64 cache and character index ramp.
utf8_palette_cache_t * get_utf8_palette_cache (const char *ascii_chars)
 Get UTF-8 palette cache for a character set.
void simd_caches_destroy_all (void)
 Destroy all SIMD caches (palette and other caches).

Variables

global_dec3_cache_t g_dec3_cache
 Global decimal cache instance.
char g_default_luminance_palette [256]
 Default luminance palette (256 characters).

Detailed Description

SIMD-optimized ASCII conversion interface.

Definition in file video/ascii/common.h.