|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🖼️ Everything necessary to turn pixels into text art More...
Modules | |
| Video Frame Buffers | |
| 📹 High-performance video frame management with double-buffering and lock-free operations | |
Files | |
| file | ansi.c |
| ANSI escape sequence utilities. | |
| file | ansi.h |
| ANSI escape sequence utilities. | |
| file | ansi_fast.c |
| ⚡ Fast ANSI color code generation with SIMD-accelerated terminal output | |
| file | ansi_fast.h |
| Fast ANSI escape sequence generation. | |
| file | ascii.c |
| 🖼️ Image-to-ASCII conversion with SIMD acceleration, color matching, and terminal optimization | |
| file | ascii.h |
| 🖼️ ASCII Art Conversion and Output Interface | |
| file | image.c |
| 🖨️ Image processing: format detection, decoding, scaling, and pixel format conversion | |
| file | image.h |
| Image Data Structures and Operations. | |
| file | output_buffer.c |
| 📝 Output buffer helpers for efficient string building in ASCII rendering pipeline | |
| file | output_buffer.h |
| Dynamic Output Buffer with ANSI Sequence Support. | |
| file | rle.c |
| ANSI RLE (REP) sequence compression and expansion. | |
| file | rle.h |
| ANSI RLE (REP) sequence compression and expansion. | |
| file | ascii_simd.c |
| ⚡ Main SIMD ASCII rendering dispatcher with architecture detection and fallback handling | |
| file | ascii_simd.h |
| SIMD-optimized ASCII conversion interface. | |
| file | ascii_simd_color.c |
| 🎨 SIMD-accelerated color matching and palette lookup for ASCII rendering | |
| file | avx2.c |
| 🚀 AVX2-accelerated ASCII rendering with 256-bit vector operations for x86_64 | |
| file | avx2.h |
| AVX2-optimized ASCII rendering functions. | |
| file | common.c |
| 🔧 Shared SIMD utilities: initialization, cleanup, and architecture-specific resource management | |
| file | common.h |
| Common SIMD utilities and structures. | |
| file | neon.c |
| ⚡ ARM NEON-accelerated ASCII rendering with 128-bit vector operations for ARM64 | |
| file | neon.h |
| NEON-optimized ASCII rendering functions. | |
| file | sse2.c |
| ⚡ SSE2-accelerated ASCII rendering with 128-bit vector operations (x86 baseline) | |
| file | sse2.h |
| SSE2-optimized ASCII rendering functions. | |
| file | ssse3.c |
| 🚀 SSSE3-accelerated ASCII rendering with advanced shuffle operations for x86 | |
| file | ssse3.h |
| SSSE3-optimized ASCII rendering functions. | |
| file | sve.c |
| 🚀 ARM SVE (Scalable Vector Extension) ASCII rendering with variable-length vectors | |
| file | sve.h |
| SVE-optimized ASCII rendering functions. | |
Data Structures | |
| struct | ansi_timing_t |
| Timing breakdown for performance measurement. More... | |
| struct | ansi_rle_context_t |
| Run-length encoded color output context. More... | |
| struct | rgb_error_t |
| RGB error structure for dithering. More... | |
| struct | ascii_frame_source_t |
| Frame source structure for grid layout. More... | |
| struct | __attribute__ |
| RGB pixel structure. More... | |
| struct | image_t |
| Image structure. More... | |
| struct | outbuf_t |
| Dynamic output buffer (auto-expanding) More... | |
| 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 |
| Dynamic string buffer structure. 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 |
| UTF-8 character structure. More... | |
| struct | utf8_palette_cache_s |
| UTF-8 palette cache structure. More... | |
Macros | |
| #define | ASCII_LUMINANCE_LEVELS 256 |
| Number of luminance levels supported (256) | |
| #define | ASCII_SLEEP_NS 50000L |
| Sleep duration in nanoseconds between frames (50000 ns = 50 μs) | |
| #define | ANSI_FG_PREFIX "\033[38;2;" |
| ANSI foreground color prefix (truecolor mode) | |
| #define | ANSI_BG_PREFIX "\033[48;2;" |
| ANSI background color prefix (truecolor mode) | |
| #define | ANSI_COLOR_SUFFIX "m" |
| ANSI color suffix. | |
| #define | print(s) fwrite(s, 1, sizeof(s) / sizeof((s)[0]), stdout) |
| Print string to stdout. | |
| #define | console_clear(fd) (terminal_clear_screen(), terminal_cursor_home(fd)) |
| Clear console and move cursor to home position. | |
| #define | cursor_reset(fd) terminal_cursor_home(fd) |
| Reset cursor to home position. | |
| #define | ascii_clear_screen(fd) terminal_clear_screen() |
| Clear terminal screen. | |
| #define | cursor_hide(fd) terminal_hide_cursor(fd, true) |
| Hide terminal cursor. | |
| #define | cursor_show(fd) terminal_hide_cursor(fd, false) |
| Show terminal cursor. | |
| #define | ascii_zzz() nanosleep((struct timespec *)&ASCII_SLEEP_START, (struct timespec *)&ASCII_SLEEP_STOP) |
| Sleep for frame rate limiting. | |
| #define | IMAGE_MAX_WIDTH 3840 |
| Maximum image width (4K resolution) | |
| #define | IMAGE_MAX_HEIGHT 2160 |
| Maximum image height (4K resolution) | |
| #define | IMAGE_MAX_PIXELS_SIZE (IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT * sizeof(rgb_pixel_t)) |
| Maximum pixel data size in bytes. | |
| #define | RAMP64_SIZE 64 |
| Ramp64 cache size (64 entries) | |
Typedefs | |
| typedef struct utf8_palette_cache_s | utf8_palette_cache_t |
| UTF-8 palette cache structure. | |
Enumerations | |
| enum | ansi_color_mode_t { ANSI_MODE_FOREGROUND , ANSI_MODE_BACKGROUND , ANSI_MODE_FOREGROUND_BACKGROUND } |
| Color mode for ANSI generation. More... | |
| enum | image_alloc_method_t { IMAGE_ALLOC_SIMD = 0 , IMAGE_ALLOC_POOL = 1 } |
| Pixel allocation method tracking. More... | |
Functions | |
| void | ansi_fast_init (void) |
| Initialize the decimal lookup table. | |
| char * | append_truecolor_fg (char *dst, uint8_t r, uint8_t g, uint8_t b) |
| Append truecolor foreground ANSI sequence. | |
| char * | append_truecolor_bg (char *dst, uint8_t r, uint8_t g, uint8_t b) |
| Append truecolor background ANSI sequence. | |
| char * | append_truecolor_fg_bg (char *dst, uint8_t fg_r, uint8_t fg_g, uint8_t fg_b, uint8_t bg_r, uint8_t bg_g, uint8_t bg_b) |
| Append truecolor foreground and background ANSI sequence. | |
| void | ansi_rle_init (ansi_rle_context_t *ctx, char *buffer, size_t capacity, ansi_color_mode_t mode) |
| Initialize run-length encoding context. | |
| void | ansi_rle_add_pixel (ansi_rle_context_t *ctx, uint8_t r, uint8_t g, uint8_t b, char ascii_char) |
| Add a pixel with run-length encoding. | |
| void | ansi_rle_finish (ansi_rle_context_t *ctx) |
| Finish RLE sequence. | |
| void | ansi_fast_init_256color (void) |
| Initialize 256-color mode lookup tables. | |
| char * | append_256color_fg (char *dst, uint8_t color_index) |
| Append 256-color foreground ANSI sequence. | |
| uint8_t | rgb_to_256color (uint8_t r, uint8_t g, uint8_t b) |
| Convert RGB to 256-color palette index. | |
| void | ansi_fast_init_16color (void) |
| Initialize 16-color mode lookup tables. | |
| char * | append_16color_fg (char *dst, uint8_t color_index) |
| Append 16-color foreground ANSI sequence. | |
| char * | append_16color_bg (char *dst, uint8_t color_index) |
| Append 16-color background ANSI sequence. | |
| uint8_t | rgb_to_16color (uint8_t r, uint8_t g, uint8_t b) |
| Convert RGB to 16-color ANSI index. | |
| void | get_16color_rgb (uint8_t color_index, uint8_t *r, uint8_t *g, uint8_t *b) |
| Get the actual RGB values for a 16-color ANSI index. | |
| 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) |
| Convert RGB to 16-color with Floyd-Steinberg dithering. | |
| char * | append_color_fg_for_mode (char *dst, uint8_t r, uint8_t g, uint8_t b, terminal_color_mode_t mode) |
| Append color foreground sequence for specified mode. | |
| asciichat_error_t | ascii_read_init (unsigned short int webcam_index) |
| Initialize ASCII read subsystem (e.g., webcam) | |
| asciichat_error_t | ascii_write_init (int fd, bool reset_terminal) |
| Initialize ASCII write subsystem. | |
| char * | ascii_convert (image_t *original, const ssize_t width, const ssize_t height, const bool color, const bool aspect_ratio, const bool stretch, const char *palette_chars, const char luminance_palette[256]) |
| Convert image to ASCII art. | |
| char * | ascii_convert_with_capabilities (image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const char luminance_palette[256]) |
| Convert image to ASCII art with terminal capability awareness. | |
| asciichat_error_t | ascii_write (const char *frame) |
| Write ASCII frame to terminal. | |
| void | ascii_read_destroy (void) |
| Destroy ASCII read subsystem. | |
| void | ascii_write_destroy (int fd, bool reset_terminal) |
| Destroy ASCII write subsystem. | |
| char * | ascii_pad_frame_width (const char *frame, size_t pad) |
| Add leading spaces (left-padding) to each line of a frame. | |
| char * | ascii_pad_frame_height (const char *frame, size_t pad_top) |
| Add blank lines (vertical padding) to center a frame vertically. | |
| char * | ascii_create_grid (ascii_frame_source_t *sources, int source_count, int width, int height, size_t *out_size) |
| Create a grid layout from multiple ASCII frames. | |
| char * | get_lum_palette (void) |
| Get luminance palette for character mapping. | |
| image_t * | image_new (size_t width, size_t height) |
| Create a new image with standard allocation. | |
| void | image_destroy (image_t *p) |
| Destroy an image allocated with image_new() | |
| image_t * | image_new_from_pool (size_t width, size_t height) |
| Create a new image from buffer pool. | |
| void | image_destroy_to_pool (image_t *image) |
| Destroy an image allocated from buffer pool. | |
| void | image_clear (image_t *p) |
| Clear image (set all pixels to black) | |
| char * | image_print (const image_t *p, const char *palette) |
| Print image as ASCII art (monochrome) | |
| char * | image_print_color (const image_t *p, const char *palette) |
| Print image as ASCII art with color. | |
| char * | image_print_with_capabilities (const image_t *image, const terminal_capabilities_t *caps, const char *palette, const char luminance_palette[256]) |
| Print image with terminal capability awareness. | |
| char * | image_print_256color (const image_t *image, const char *palette) |
| Print image using 256-color ANSI mode. | |
| char * | image_print_16color (const image_t *image, const char *palette) |
| Print image using 16-color ANSI mode. | |
| char * | image_print_16color_dithered (const image_t *image, const char *palette) |
| Print image using 16-color ANSI mode with dithering. | |
| char * | image_print_16color_dithered_with_background (const image_t *image, bool use_background, const char *palette) |
| Print image using 16-color ANSI mode with dithering and background colors. | |
| void | quantize_color (int *r, int *g, int *b, int levels) |
| Quantize color to specified number of levels. | |
| void | precalc_rgb_palettes (const float red, const float green, const float blue) |
| Precalculate RGB palettes with color adjustment. | |
| void | image_resize (const image_t *source, image_t *dest) |
| Resize image using nearest-neighbor interpolation. | |
| void | image_resize_interpolation (const image_t *source, image_t *dest) |
| Resize image using bilinear interpolation. | |
| char * | rgb_to_ansi_fg (int r, int g, int b) |
| Convert RGB to ANSI foreground color code. | |
| char * | rgb_to_ansi_bg (int r, int g, int b) |
| Convert RGB to ANSI background color code. | |
| void | rgb_to_ansi_8bit (int r, int g, int b, int *fg_code, int *bg_code) |
| Convert RGB to 8-bit ANSI color codes. | |
| void | ob_reserve (outbuf_t *ob, size_t need) |
| Reserve buffer space for upcoming writes. | |
| void | ob_putc (outbuf_t *ob, char c) |
| Append a character to buffer. | |
| void | ob_write (outbuf_t *ob, const char *s, size_t n) |
| Append a string to buffer. | |
| void | ob_term (outbuf_t *ob) |
| Append null terminator to buffer. | |
| void | ob_u8 (outbuf_t *ob, uint8_t v) |
| Append unsigned 8-bit integer as decimal string. | |
| void | ob_u32 (outbuf_t *ob, uint32_t v) |
| Append unsigned 32-bit integer as decimal string. | |
| void | emit_set_truecolor_fg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b) |
| Emit truecolor foreground ANSI sequence. | |
| void | emit_set_truecolor_bg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b) |
| Emit truecolor background ANSI sequence. | |
| void | emit_set_256_color_fg (outbuf_t *ob, uint8_t color_idx) |
| Emit 256-color foreground ANSI sequence. | |
| void | emit_set_256_color_bg (outbuf_t *ob, uint8_t color_idx) |
| Emit 256-color background ANSI sequence. | |
| void | emit_reset (outbuf_t *ob) |
| Emit ANSI reset sequence. | |
| bool | rep_is_profitable (uint32_t runlen) |
| Check if run-length encoding is profitable. | |
| void | emit_rep (outbuf_t *ob, uint32_t extra) |
| Emit run-length encoded sequence. | |
| void | emit_set_fg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b) |
| Emit foreground color sequence (auto-select mode) | |
| void | emit_set_bg (outbuf_t *ob, uint8_t r, uint8_t g, uint8_t b) |
| Emit background color sequence (auto-select mode) | |
| char * | ansi_expand_rle (const char *input, size_t input_len) |
| Expand RLE escape sequences in a string. | |
| char * | ansi_compress_rle (const char *input, size_t input_len) |
| Compress repeated characters using RLE escape sequences. | |
| 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_free (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_simd (image_t *image, const char *ascii_chars) |
| Print image as ASCII using SIMD (monochrome) | |
| 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_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_ramp64 (uint8_t ramp64[64], const char *ascii_chars) |
| Build 64-entry character ramp cache. | |
| double | calculate_cache_eviction_score (uint64_t last_access_time, uint32_t access_count, uint64_t creation_time, uint64_t current_time) |
| Calculate cache eviction score. | |
| uint64_t | get_current_time_ns (void) |
| Get current time in nanoseconds. | |
| utf8_palette_cache_t * | get_utf8_palette_cache (const char *ascii_chars) |
| Get or create UTF-8 palette cache. | |
| void | build_utf8_luminance_cache (const char *ascii_chars, utf8_char_t cache[256]) |
| Build UTF-8 luminance cache. | |
| void | build_utf8_ramp64_cache (const char *ascii_chars, utf8_char_t cache64[64], uint8_t char_index_ramp[64]) |
| Build UTF-8 ramp64 cache. | |
| void | simd_caches_destroy_all (void) |
| Destroy all SIMD caches. | |
| bool | has_sse2_support (void) |
| Check if SSE2 is supported. | |
| bool | has_ssse3_support (void) |
| Check if SSSE3 is supported. | |
| bool | has_avx2_support (void) |
| Check if AVX2 is supported. | |
| bool | has_neon_support (void) |
| Check if NEON is supported. | |
| bool | has_sve_support (void) |
| Check if SVE is supported. | |
| char * | append_sgr_truecolor_fg (char *dst, uint8_t r, uint8_t g, uint8_t b) |
| Append truecolor foreground SGR sequence. | |
| char * | append_sgr_truecolor_bg (char *dst, uint8_t r, uint8_t g, uint8_t b) |
| Append truecolor background SGR sequence. | |
| char * | append_sgr_truecolor_fg_bg (char *dst, uint8_t fr, uint8_t fg, uint8_t fb, uint8_t br, uint8_t bg, uint8_t bb) |
| Append truecolor foreground and background SGR sequence. | |
| char * | append_sgr_reset (char *dst) |
| Append ANSI reset sequence. | |
| size_t | write_rgb_triplet (uint8_t value, char *dst) |
| Write decimal RGB triplet using dec3 cache. | |
Luminance Calculation Constants | |
| #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. | |
Cache Eviction Algorithm Parameters | |
| #define | CACHE_FREQUENCY_DECAY_TIME 300.0 |
| Frequency bonus decay time (5 minutes in seconds) | |
| #define | CACHE_RECENCY_SCALE 60.0 |
| Recency importance scale (1 minute in seconds) | |
| #define | CACHE_RECENT_ACCESS_THRESHOLD 10 |
| Recent access protection threshold (10 seconds) | |
| #define | CACHE_MAX_LIFETIME 3600 |
| Maximum cache lifetime (1 hour in seconds) | |
| #define | CACHE_MIN_ACCESS_THRESHOLD 3 |
| Minimum accesses for frequency protection. | |
🖼️ Everything necessary to turn pixels into text art
This header provides optimized ANSI escape sequence generation using precomputed lookup tables and run-length encoding for efficient terminal output.
The interface provides:
This header provides comprehensive functions for converting images to ASCII art and outputting frames to the terminal. Supports multiple color modes, aspect ratio preservation, capability-aware conversion, and frame layout management.
The system supports multiple conversion modes:
Frame management includes:
This header provides comprehensive image data structures and operations for ascii-chat. Supports RGB images with standard and SIMD-optimized formats for efficient image processing and ASCII art conversion.
The system supports:
ASCII conversion supports multiple color modes:
This header provides a dynamic output buffer system with automatic expansion and optimized ANSI escape sequence emission functions. The buffer is designed for efficient ASCII art frame construction and terminal output.
The output buffer automatically expands when space is needed:
The system emits ANSI escape sequences for:
Color emission functions automatically select optimal mode:
This module provides functions for working with ANSI RLE (Run-Length Encoding) escape sequences. The REP sequence (CSI Ps b) repeats the preceding graphic character Ps times.
The ANSI REP sequence format is: ESC [ N b
Example: "A\x1b[3b" means "A" followed by 3 more "A"s = "AAAA"
This header provides SIMD-optimized functions for converting images to ASCII art. Supports multiple architectures including SSE2, SSSE3, AVX2 (x86), NEON (ARM), and SVE (ARM).
The interface provides:
This header provides common utilities, cache systems, and helper functions shared across all SIMD implementations.
The interface provides:
This header provides NEON (Advanced SIMD) optimized functions for converting images to ASCII art on ARM processors.
This header provides SSE2 (Streaming SIMD Extensions 2) optimized functions for converting images to ASCII art on x86-64 CPUs.
This header provides SSSE3 (Supplemental Streaming SIMD Extensions 3) optimized functions for converting images to ASCII art on x86-64 CPUs.
This header provides SVE (Scalable Vector Extension) optimized functions for converting images to ASCII art on ARM processors with SVE support.
ascii-chat renders live video as ASCII art in the terminal by:
The module is highly optimized using SIMD instructions, achieving:
Rendering Modes:
SIMD Acceleration:
Grid Layouts:
Palette Support:
Aspect Ratio Correction:
Resize RGB image from webcam resolution to terminal dimensions:
Convert RGB pixels to luminance (grayscale):
SIMD implementation (SSE2 example):
Map brightness values to ASCII characters:
Half-block rendering uses special logic:
Generate optimized ANSI sequences for terminal:
\x1b[38;2;R;G;Bm (24-bit color)Optimization techniques:
Example output:
Write ANSI output to terminal:
Capabilities:
Performance:
Additional capabilities beyond SSE2:
Performance improvement:
Capabilities:
Performance:
Capabilities:
Performance on Apple M1:
Capabilities:
Performance potential:
ascii-chat automatically detects and uses the best SIMD level:
Measured on Intel i7-10700K @ 3.8 GHz, 1920x1080 → 160x45 conversion:
| Implementation | FPS | Latency | CPU % |
|---|---|---|---|
| Scalar | 15 | 66 ms | 25% |
| SSE2 | 60 | 16 ms | 6% |
| SSSE3 | 75 | 13 ms | 5% |
| AVX2 | 90 | 11 ms | 4% |
Measured on Apple M1 (ARM NEON):
Memory usage:
ascii-chat supports various terminal features:
True Color (24-bit RGB):
\x1b[38;2;R;G;Bm (foreground), \x1b[48;2;R;G;Bm (background)256-Color Mode:
\x1b[38;5;Nm where N is 0-255UTF-8 Support:
Terminal Size Detection:
| #define ANSI_BG_PREFIX "\033[48;2;" |
#include <ascii.h>
ANSI background color prefix (truecolor mode)
ANSI escape sequence prefix for 24-bit truecolor background colors. Format: ESC[48;2;r;g;bm (where r, g, b are RGB values).
| #define ANSI_COLOR_SUFFIX "m" |
#include <ascii.h>
ANSI color suffix.
ANSI escape sequence suffix for color escape sequences. Used with ANSI_FG_PREFIX or ANSI_BG_PREFIX to form complete escape sequences.
| #define ANSI_FG_PREFIX "\033[38;2;" |
#include <ascii.h>
ANSI foreground color prefix (truecolor mode)
ANSI escape sequence prefix for 24-bit truecolor foreground colors. Format: ESC[38;2;r;g;bm (where r, g, b are RGB values).
| #define ascii_clear_screen | ( | fd | ) | terminal_clear_screen() |
#include <ascii.h>
Clear terminal screen.
| fd | File descriptor for terminal |
Clears terminal screen without moving cursor. Equivalent to terminal_clear_screen().
| #define ASCII_LUMINANCE_LEVELS 256 |
#include <ascii.h>
Number of luminance levels supported (256)
Number of luminance levels used for character mapping. Each pixel's brightness value (0-255) maps to a character in the luminance palette.
| #define ASCII_SLEEP_NS 50000L |
#include <ascii.h>
Sleep duration in nanoseconds between frames (50000 ns = 50 μs)
Sleep duration between frame outputs for frame rate limiting. Used to prevent excessive terminal I/O and control frame rate.
| #define ascii_zzz | ( | ) | nanosleep((struct timespec *)&ASCII_SLEEP_START, (struct timespec *)&ASCII_SLEEP_STOP) |
#include <ascii.h>
Sleep for frame rate limiting.
Sleeps for a short duration (500 nanoseconds) to limit frame rate and prevent excessive terminal I/O. Uses nanosleep() for precise timing control.
| #define CACHE_FREQUENCY_DECAY_TIME 300.0 |
#include <common.h>
Frequency bonus decay time (5 minutes in seconds)
Definition at line 42 of file video/simd/common.h.
| #define CACHE_MAX_LIFETIME 3600 |
#include <common.h>
Maximum cache lifetime (1 hour in seconds)
Definition at line 48 of file video/simd/common.h.
| #define CACHE_MIN_ACCESS_THRESHOLD 3 |
#include <common.h>
Minimum accesses for frequency protection.
Definition at line 50 of file video/simd/common.h.
| #define CACHE_RECENCY_SCALE 60.0 |
#include <common.h>
Recency importance scale (1 minute in seconds)
Definition at line 44 of file video/simd/common.h.
| #define CACHE_RECENT_ACCESS_THRESHOLD 10 |
#include <common.h>
Recent access protection threshold (10 seconds)
Definition at line 46 of file video/simd/common.h.
| #define console_clear | ( | fd | ) | (terminal_clear_screen(), terminal_cursor_home(fd)) |
#include <ascii.h>
Clear console and move cursor to home position.
| fd | File descriptor for terminal |
Clears terminal screen and moves cursor to home position (top-left). Equivalent to terminal_clear_screen() followed by terminal_cursor_home().
| #define cursor_hide | ( | fd | ) | terminal_hide_cursor(fd, true) |
| #define cursor_reset | ( | fd | ) | terminal_cursor_home(fd) |
#include <ascii.h>
Reset cursor to home position.
| fd | File descriptor for terminal |
Moves cursor to home position (top-left, row 1, column 1). Equivalent to terminal_cursor_home().
| #define cursor_show | ( | fd | ) | terminal_hide_cursor(fd, false) |
| #define IMAGE_MAX_HEIGHT 2160 |
#include <image.h>
Maximum image height (4K resolution)
Maximum supported image height in pixels. Set to 2160 pixels (4K UHD height) to support high-resolution video capture.
Definition at line 177 of file video/image.h.
| #define IMAGE_MAX_PIXELS_SIZE (IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT * sizeof(rgb_pixel_t)) |
#include <image.h>
Maximum pixel data size in bytes.
Maximum size in bytes for pixel data array. Calculated as: IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT * sizeof(rgb_pixel_t) Used for buffer allocation and validation.
Definition at line 191 of file video/image.h.
| #define IMAGE_MAX_WIDTH 3840 |
#include <image.h>
Maximum image width (4K resolution)
Maximum supported image width in pixels. Set to 3840 pixels (4K UHD width) to support high-resolution video capture.
Definition at line 164 of file video/image.h.
| #define LUMA_BLUE 29 |
#include <ascii_simd.h>
Luminance blue coefficient (0.114 * 256 = 29)
Definition at line 76 of file ascii_simd.h.
| #define LUMA_GREEN 150 |
#include <ascii_simd.h>
Luminance green coefficient (0.587 * 256 = 150)
Definition at line 74 of file ascii_simd.h.
| #define LUMA_RED 77 |
#include <ascii_simd.h>
Luminance red coefficient (0.299 * 256 = 77)
Definition at line 72 of file ascii_simd.h.
| #define LUMA_THRESHOLD 128 |
#include <ascii_simd.h>
Luminance threshold for rounding.
Definition at line 78 of file ascii_simd.h.
| #define print | ( | s | ) | fwrite(s, 1, sizeof(s) / sizeof((s)[0]), stdout) |
#include <ascii.h>
Print string to stdout.
| s | String literal to print |
Utility macro for printing string literals to stdout. Uses fwrite() for efficient output without null terminator requirement.
| #define RAMP64_SIZE 64 |
#include <common.h>
Ramp64 cache size (64 entries)
Definition at line 34 of file video/simd/common.h.
| typedef struct utf8_palette_cache_s utf8_palette_cache_t |
#include <common.h>
UTF-8 palette cache structure.
Thread-safe cache system for UTF-8 character lookup with eviction tracking.
| enum ansi_color_mode_t |
#include <ansi_fast.h>
Color mode for ANSI generation.
Definition at line 40 of file ansi_fast.h.
| enum image_alloc_method_t |
#include <image.h>
Pixel allocation method tracking.
Tracks which allocation method was used for image pixels to ensure correct deallocation. Must match the allocation method used when creating the image.
| Enumerator | |
|---|---|
| IMAGE_ALLOC_SIMD | Pixels allocated with SAFE_MALLOC_SIMD() |
| IMAGE_ALLOC_POOL | Pixels allocated with buffer_pool_alloc() |
Definition at line 116 of file video/image.h.
| ImageRGB alloc_image | ( | int | w, |
| int | h | ||
| ) |
#include <ascii_simd.h>
Allocate a new ImageRGB (RGB8 format)
| w | Image width |
| h | Image height |
Definition at line 98 of file ascii_simd.c.
References ImageRGB::h, ImageRGB::pixels, SAFE_MALLOC, and ImageRGB::w.
| char * ansi_compress_rle | ( | const char * | input, |
| size_t | input_len | ||
| ) |
#include <rle.h>
Compress repeated characters using RLE escape sequences.
| input | Input string (may contain ANSI escape codes) |
| input_len | Length of input string |
Compresses runs of repeated printable characters using ANSI RLE sequences. Only compresses when profitable (run length > RLE overhead). Preserves all existing escape sequences.
Definition at line 98 of file rle.c.
References outbuf_t::buf, emit_rep(), ob_putc(), ob_reserve(), ob_term(), ob_write(), and rep_is_profitable().
| char * ansi_expand_rle | ( | const char * | input, |
| size_t | input_len | ||
| ) |
#include <rle.h>
Expand RLE escape sequences in a string.
| input | Input string containing ANSI escape codes |
| input_len | Length of input string |
Expands ANSI RLE (REP) sequences while preserving all other escape codes:
This is useful when outputting to files/pipes where terminals can't interpret RLE, but you still want to preserve color codes.
Definition at line 13 of file rle.c.
References outbuf_t::buf, ob_reserve(), ob_term(), ob_write(), and SAFE_MEMCPY.
| void ansi_fast_init | ( | void | ) |
#include <ansi_fast.h>
Initialize the decimal lookup table.
Must be called once at startup before using any ANSI generation functions.
Definition at line 173 of file ansi_fast.c.
References ascii_simd_init().
Referenced by mirror_main().
| void ansi_fast_init_16color | ( | void | ) |
#include <ansi_fast.h>
Initialize 16-color mode lookup tables.
Must be called before using 16-color functions.
Definition at line 225 of file ansi_fast.c.
References SAFE_SNPRINTF.
Referenced by append_16color_bg(), append_16color_fg(), image_print_16color(), image_print_16color_dithered(), image_print_16color_dithered_with_background(), and mirror_main().
| void ansi_fast_init_256color | ( | void | ) |
#include <ansi_fast.h>
Initialize 256-color mode lookup tables.
Must be called before using 256-color functions.
Definition at line 179 of file ansi_fast.c.
References SAFE_SNPRINTF.
Referenced by mirror_main().
| void ansi_rle_add_pixel | ( | ansi_rle_context_t * | ctx, |
| uint8_t | r, | ||
| uint8_t | g, | ||
| uint8_t | b, | ||
| char | ascii_char | ||
| ) |
#include <ansi_fast.h>
Add a pixel with run-length encoding.
| ctx | RLE context structure |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
| ascii_char | ASCII character to output |
Only emits SGR when color changes from previous pixel.
Definition at line 125 of file ansi_fast.c.
References ANSI_MODE_BACKGROUND, ANSI_MODE_FOREGROUND, ANSI_MODE_FOREGROUND_BACKGROUND, append_truecolor_bg(), append_truecolor_fg(), append_truecolor_fg_bg(), ansi_rle_context_t::buffer, ansi_rle_context_t::capacity, ansi_rle_context_t::first_pixel, ansi_rle_context_t::last_b, ansi_rle_context_t::last_g, ansi_rle_context_t::last_r, ansi_rle_context_t::length, and ansi_rle_context_t::mode.
Referenced by image_print_color().
| void ansi_rle_finish | ( | ansi_rle_context_t * | ctx | ) |
#include <ansi_fast.h>
Finish RLE sequence.
| ctx | RLE context structure |
Adds ANSI reset sequence and null terminator.
Definition at line 159 of file ansi_fast.c.
References ansi_rle_context_t::buffer, ansi_rle_context_t::capacity, ansi_rle_context_t::length, and SAFE_MEMCPY.
Referenced by image_print_color().
| void ansi_rle_init | ( | ansi_rle_context_t * | ctx, |
| char * | buffer, | ||
| size_t | capacity, | ||
| ansi_color_mode_t | mode | ||
| ) |
#include <ansi_fast.h>
Initialize run-length encoding context.
| ctx | Context structure to initialize |
| buffer | Output buffer |
| capacity | Buffer capacity in bytes |
| mode | Color mode to use |
Definition at line 112 of file ansi_fast.c.
References ansi_rle_context_t::buffer, ansi_rle_context_t::capacity, ansi_rle_context_t::first_pixel, ansi_rle_context_t::last_b, ansi_rle_context_t::last_g, ansi_rle_context_t::last_r, ansi_rle_context_t::length, and ansi_rle_context_t::mode.
Referenced by image_print_color().
| char * append_16color_bg | ( | char * | dst, |
| uint8_t | color_index | ||
| ) |
#include <ansi_fast.h>
Append 16-color background ANSI sequence.
| dst | Destination buffer pointer |
| color_index | 16-color ANSI index (0-15) |
Definition at line 260 of file ansi_fast.c.
References ansi_fast_init_16color().
Referenced by image_print_16color_dithered_with_background().
| char * append_16color_fg | ( | char * | dst, |
| uint8_t | color_index | ||
| ) |
#include <ansi_fast.h>
Append 16-color foreground ANSI sequence.
| dst | Destination buffer pointer |
| color_index | 16-color ANSI index (0-15) |
Definition at line 243 of file ansi_fast.c.
References ansi_fast_init_16color().
Referenced by append_color_fg_for_mode(), image_print_16color(), image_print_16color_dithered(), and image_print_16color_dithered_with_background().
| char * append_256color_fg | ( | char * | dst, |
| uint8_t | color_index | ||
| ) |
#include <ansi_fast.h>
Append 256-color foreground ANSI sequence.
| dst | Destination buffer pointer |
| color_index | 256-color palette index (0-255) |
Definition at line 191 of file ansi_fast.c.
References SAFE_MEMCPY.
Referenced by append_color_fg_for_mode().
| char * append_color_fg_for_mode | ( | char * | dst, |
| uint8_t | r, | ||
| uint8_t | g, | ||
| uint8_t | b, | ||
| terminal_color_mode_t | mode | ||
| ) |
#include <ansi_fast.h>
Append color foreground sequence for specified mode.
| dst | Destination buffer pointer |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
| mode | Color mode to use |
Automatically selects appropriate ANSI sequence based on color mode.
Definition at line 426 of file ansi_fast.c.
References append_16color_fg(), append_256color_fg(), append_truecolor_fg(), COLOR_MODE_16_COLOR, COLOR_MODE_256_COLOR, COLOR_MODE_AUTO, COLOR_MODE_NONE, COLOR_MODE_TRUECOLOR, rgb_to_16color(), and rgb_to_256color().
|
inline |
#include <common.h>
Append ANSI reset sequence.
| dst | Destination buffer pointer |
Definition at line 107 of file ascii_simd_color.c.
#include <common.h>
Append truecolor background SGR sequence.
| dst | Destination buffer pointer |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Definition at line 176 of file ascii_simd_color.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, and dec3_t::s.
#include <common.h>
Append truecolor foreground SGR sequence.
| dst | Destination buffer pointer |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Definition at line 115 of file ascii_simd_color.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, and dec3_t::s.
|
inline |
#include <common.h>
Append truecolor foreground and background SGR sequence.
| dst | Destination buffer pointer |
| fr | Foreground red component (0-255) |
| fg | Foreground green component (0-255) |
| fb | Foreground blue component (0-255) |
| br | Background red component (0-255) |
| bg | Background green component (0-255) |
| bb | Background blue component (0-255) |
Definition at line 237 of file ascii_simd_color.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, and dec3_t::s.
#include <ansi_fast.h>
Append truecolor background ANSI sequence.
| dst | Destination buffer pointer |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Definition at line 49 of file ansi_fast.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, dec3_t::s, and SAFE_MEMCPY.
Referenced by ansi_rle_add_pixel().
#include <ansi_fast.h>
Append truecolor foreground ANSI sequence.
| dst | Destination buffer pointer |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Definition at line 24 of file ansi_fast.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, dec3_t::s, and SAFE_MEMCPY.
Referenced by ansi_rle_add_pixel(), and append_color_fg_for_mode().
| char * append_truecolor_fg_bg | ( | char * | dst, |
| uint8_t | fg_r, | ||
| uint8_t | fg_g, | ||
| uint8_t | fg_b, | ||
| uint8_t | bg_r, | ||
| uint8_t | bg_g, | ||
| uint8_t | bg_b | ||
| ) |
#include <ansi_fast.h>
Append truecolor foreground and background ANSI sequence.
| dst | Destination buffer pointer |
| fg_r | Foreground red component (0-255) |
| fg_g | Foreground green component (0-255) |
| fg_b | Foreground blue component (0-255) |
| bg_r | Background red component (0-255) |
| bg_g | Background green component (0-255) |
| bg_b | Background blue component (0-255) |
Definition at line 70 of file ansi_fast.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, dec3_t::s, and SAFE_MEMCPY.
Referenced by ansi_rle_add_pixel().
| char * ascii_convert | ( | image_t * | original, |
| const ssize_t | width, | ||
| const ssize_t | height, | ||
| const bool | color, | ||
| const bool | aspect_ratio, | ||
| const bool | stretch, | ||
| const char * | palette_chars, | ||
| const char | luminance_palette[256] | ||
| ) |
#include <ascii.h>
Convert image to ASCII art.
| original | Source image (must not be NULL) |
| width | Target width in characters (must be > 0) |
| height | Target height in characters (must be > 0) |
| color | Enable color output (true for color, false for monochrome) |
| aspect_ratio | Preserve aspect ratio (true to maintain proportions, false to fill dimensions) |
| stretch | Stretch to fit (if aspect_ratio is false, true to fill exactly, false to fit within) |
| palette_chars | Character palette to use (or NULL for default ASCII palette) |
| luminance_palette | Luminance-to-character mapping palette (must not be NULL, 256 elements) |
Converts an image to ASCII art with specified dimensions and color mode. Uses character palette to map pixel luminance to ASCII characters and optionally applies color output using ANSI escape sequences.
CONVERSION PROCESS:
Definition at line 67 of file ascii.c.
References ascii_pad_frame_height(), ascii_pad_frame_width(), aspect_ratio(), GET_OPTION, image_t::h, image_clear(), image_destroy(), image_new(), image_print(), image_print_color(), image_print_color_simd(), image_print_simd(), image_resize(), log_error, image_t::pixels, RENDER_MODE_BACKGROUND, RENDER_MODE_HALF_BLOCK, SAFE_FREE, and image_t::w.
Referenced by benchmark_simd_color_conversion_with_source().
| char * ascii_convert_with_capabilities | ( | image_t * | original, |
| const ssize_t | width, | ||
| const ssize_t | height, | ||
| const terminal_capabilities_t * | caps, | ||
| const bool | use_aspect_ratio, | ||
| const bool | stretch, | ||
| const char * | palette_chars, | ||
| const char | luminance_palette[256] | ||
| ) |
#include <ascii.h>
Convert image to ASCII art with terminal capability awareness.
| original | Source image (must not be NULL) |
| width | Target width in characters (must be > 0) |
| height | Target height in characters (must be > 0) |
| caps | Terminal capabilities structure (must not be NULL) |
| use_aspect_ratio | Preserve aspect ratio (true to maintain proportions, false to fill dimensions) |
| stretch | Stretch to fit (if use_aspect_ratio is false, true to fill exactly, false to fit within) |
| palette_chars | Character palette to use (or NULL for default ASCII palette) |
| luminance_palette | Luminance-to-character mapping palette (must not be NULL, 256 elements) |
Converts an image to ASCII art with automatic color mode selection based on terminal capabilities. Automatically chooses the best color mode (16-color, 256-color, or truecolor) for optimal display.
CAPABILITY-AWARE CONVERSION:
Definition at line 188 of file ascii.c.
References ascii_pad_frame_height(), ascii_pad_frame_width(), aspect_ratio(), image_t::h, image_clear(), image_destroy(), image_new(), image_print_with_capabilities(), image_resize(), log_error, terminal_capabilities_t::render_mode, RENDER_MODE_HALF_BLOCK, SAFE_FREE, and image_t::w.
Referenced by mirror_main().
| char * ascii_create_grid | ( | ascii_frame_source_t * | sources, |
| int | source_count, | ||
| int | width, | ||
| int | height, | ||
| size_t * | out_size | ||
| ) |
#include <ascii.h>
Create a grid layout from multiple ASCII frames.
| sources | Array of frame sources (must not be NULL, must have source_count elements) |
| source_count | Number of frame sources (must be > 0) |
| width | Grid width in characters per frame (must be > 0) |
| height | Grid height in characters per frame (must be > 0) |
| out_size | Pointer to store output size in bytes (can be NULL) |
Combines multiple ASCII frames into a single grid layout. Arranges frames in a grid pattern suitable for multi-user display. Each frame is positioned in the grid according to its index in the sources array.
GRID LAYOUT:
Creates a grid layout from multiple ASCII frame sources with | and _ separators.
Parameters: sources Array of ASCII frame sources to combine source_count Number of sources in the array width Target width of the output grid height Target height of the output grid out_size Output parameter for the size of the returned buffer
Returns: A newly allocated, null-terminated string containing the grid layout, or NULL on error. Caller must free the returned buffer.
Definition at line 450 of file ascii.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ascii_frame_source_t::frame_data, ascii_frame_source_t::frame_size, SAFE_MALLOC, SAFE_MEMCPY, SAFE_MEMSET, and SET_ERRNO.
| char * ascii_pad_frame_height | ( | const char * | frame, |
| size_t | pad_top | ||
| ) |
#include <ascii.h>
Add blank lines (vertical padding) to center a frame vertically.
| frame | ASCII frame string (must not be NULL) |
| pad_top | Number of blank lines to add at top (must be >= 0) |
Adds blank lines (vertical padding) to the top of an ASCII frame. Useful for centering frames vertically or creating margins. Blank lines are added at the top of the frame.
Adds vertical padding (blank lines) to center a frame vertically.
Parameters: frame The input ASCII frame to pad vertically. pad_top Number of blank lines to add at the top.
Returns: A newly allocated, null-terminated string with vertical padding, or NULL if frame is NULL.
Definition at line 738 of file ascii.c.
References SAFE_MALLOC, and SAFE_MEMCPY.
Referenced by ascii_convert(), and ascii_convert_with_capabilities().
| char * ascii_pad_frame_width | ( | const char * | frame, |
| size_t | pad | ||
| ) |
#include <ascii.h>
Add leading spaces (left-padding) to each line of a frame.
| frame | ASCII frame string (must not be NULL) |
| pad | Number of spaces to pad on left (must be >= 0) |
Adds leading spaces (left-padding) to each line of an ASCII frame. Useful for centering frames horizontally or creating margins. Each line in the frame is padded with the specified number of spaces.
Definition at line 375 of file ascii.c.
References SAFE_MALLOC, SAFE_MEMCPY, and SAFE_MEMSET.
Referenced by ascii_convert(), and ascii_convert_with_capabilities().
| void ascii_read_destroy | ( | void | ) |
#include <ascii.h>
Destroy ASCII read subsystem.
Cleans up the ASCII read subsystem and releases resources. Closes webcam device and frees associated memory. Should be called when done with image capture.
Definition at line 355 of file ascii.c.
References log_debug, and webcam_cleanup().
| asciichat_error_t ascii_read_init | ( | unsigned short int | webcam_index | ) |
#include <ascii.h>
Initialize ASCII read subsystem (e.g., webcam)
| webcam_index | Webcam device index (0 for default device) |
Initializes the ASCII read subsystem for image capture. Opens webcam device and prepares it for frame capture. This is a convenience wrapper around webcam initialization.
Definition at line 34 of file ascii.c.
References ASCIICHAT_OK, log_info, and webcam_init().
| void ascii_simd_init | ( | void | ) |
#include <ascii_simd.h>
Initialize SIMD subsystem.
Initializes all SIMD subsystems and caches. Must be called once at startup.
Definition at line 90 of file ascii_simd.c.
References init_dec3(), and init_default_luminance_palette().
Referenced by ansi_fast_init(), and server_main().
| asciichat_error_t ascii_write | ( | const char * | frame | ) |
#include <ascii.h>
Write ASCII frame to terminal.
| frame | ASCII frame string to write (must not be NULL) |
Writes an ASCII frame string to the terminal output. Frame string may contain ANSI escape sequences for color output and cursor positioning. Output is written to the file descriptor configured during ascii_write_init().
Definition at line 312 of file ascii.c.
References ASCIICHAT_OK, cursor_reset, ERROR_INVALID_PARAM, ERROR_TERMINAL, GET_OPTION, log_error, log_warn, and SAFE_GETENV.
| void ascii_write_destroy | ( | int | fd, |
| bool | reset_terminal | ||
| ) |
#include <ascii.h>
Destroy ASCII write subsystem.
| fd | File descriptor that was used for writing (must be valid) |
| reset_terminal | Whether to reset terminal on cleanup (true to restore state, false to preserve) |
Cleans up the ASCII write subsystem and restores terminal state. Restores cursor visibility, clears screen, and resets terminal attributes if reset_terminal is true.
TERMINAL CLEANUP:
Definition at line 334 of file ascii.c.
References GET_OPTION, log_debug, log_warn, terminal_hide_cursor(), and terminal_set_echo().
Referenced by display_cleanup().
| asciichat_error_t ascii_write_init | ( | int | fd, |
| bool | reset_terminal | ||
| ) |
#include <ascii.h>
Initialize ASCII write subsystem.
| fd | File descriptor to write to (must be valid file descriptor) |
| reset_terminal | Whether to reset terminal on initialization (true to reset, false to preserve state) |
Initializes the ASCII write subsystem for terminal output. Configures terminal for ASCII art display including cursor hiding, screen clearing, and terminal state management.
TERMINAL INITIALIZATION:
Definition at line 40 of file ascii.c.
References ASCIICHAT_OK, console_clear, cursor_reset, ERROR_INVALID_PARAM, ERROR_TERMINAL, GET_OPTION, log_debug, log_error, log_warn, SAFE_GETENV, terminal_hide_cursor(), and terminal_set_echo().
Referenced by display_init().
| simd_benchmark_t benchmark_simd_color_conversion | ( | int | width, |
| int | height, | ||
| int | iterations, | ||
| bool | background_mode | ||
| ) |
#include <ascii_simd.h>
Benchmark SIMD color conversion methods.
| width | Image width in pixels |
| height | Image height in pixels |
| iterations | Number of benchmark iterations |
| background_mode | Use background colors |
Definition at line 500 of file ascii_simd.c.
References ASCIICHAT_OK, simd_benchmark_t::avx2_time, simd_benchmark_t::best_method, DEFAULT_ASCII_PALETTE, IMAGE_ALLOC_SIMD, image_destroy(), image_new(), image_print_color(), log_error, simd_benchmark_t::neon_time, image_t::pixels, SAFE_CALLOC_SIMD, SAFE_FREE, SAFE_MALLOC, simd_benchmark_t::scalar_time, simd_benchmark_t::speedup_best, simd_benchmark_t::sse2_time, and simd_benchmark_t::ssse3_time.
| 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 | ||
| ) |
#include <ascii_simd.h>
Benchmark SIMD color conversion with source image.
| width | Image width in pixels |
| height | Image height in pixels |
| iterations | Number of benchmark iterations |
| background_mode | Use background colors |
| source_image | Source image for conversion |
| use_256color | Use 256-color mode |
| simd_benchmark_t benchmark_simd_conversion | ( | int | width, |
| int | height, | ||
| int | iterations | ||
| ) |
#include <ascii_simd.h>
Benchmark SIMD conversion methods (monochrome)
| width | Image width in pixels |
| height | Image height in pixels |
| iterations | Number of benchmark iterations |
| 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 | ||
| ) |
#include <ascii_simd.h>
Benchmark SIMD conversion with source image.
| width | Image width in pixels |
| height | Image height in pixels |
| iterations | Number of benchmark iterations |
| background_mode | Use background colors |
| source_image | Source image for conversion |
| use_256color | Use 256-color mode |
Definition at line 656 of file ascii_simd.c.
References ASCIICHAT_OK, simd_benchmark_t::avx2_time, simd_benchmark_t::best_method, DEFAULT_ASCII_PALETTE, image_t::h, image_destroy(), image_new(), image_print_color(), log_error, simd_benchmark_t::neon_time, image_t::pixels, SAFE_CALLOC_SIMD, SAFE_FREE, SAFE_MALLOC, simd_benchmark_t::scalar_time, simd_benchmark_t::speedup_best, simd_benchmark_t::sse2_time, simd_benchmark_t::ssse3_time, simd_benchmark_t::sve_time, and image_t::w.
| void build_ramp64 | ( | uint8_t | ramp64[64], |
| const char * | ascii_chars | ||
| ) |
#include <common.h>
Build 64-entry character ramp cache.
| ramp64 | Output array for ramp indices |
| ascii_chars | Character palette string |
Definition at line 31 of file video/simd/common.c.
References utf8_char_info_t::bytes, RAMP64_SIZE, utf8_palette_create(), utf8_palette_destroy(), utf8_palette_get_char(), and utf8_palette_get_char_count().
| void build_utf8_luminance_cache | ( | const char * | ascii_chars, |
| utf8_char_t | cache[256] | ||
| ) |
#include <common.h>
Build UTF-8 luminance cache.
| ascii_chars | Character palette string |
| cache | Output cache array (256 entries) |
Definition at line 410 of file video/simd/common.c.
References utf8_char_t::byte_len, and utf8_char_t::utf8_bytes.
| void build_utf8_ramp64_cache | ( | const char * | ascii_chars, |
| utf8_char_t | cache64[64], | ||
| uint8_t | char_index_ramp[64] | ||
| ) |
#include <common.h>
Build UTF-8 ramp64 cache.
| ascii_chars | Character palette string |
| cache64 | Output cache array (64 entries) |
| char_index_ramp | Output character index ramp (64 entries) |
Definition at line 463 of file video/simd/common.c.
References utf8_char_t::byte_len, and utf8_char_t::utf8_bytes.
| double calculate_cache_eviction_score | ( | uint64_t | last_access_time, |
| uint32_t | access_count, | ||
| uint64_t | creation_time, | ||
| uint64_t | current_time | ||
| ) |
#include <common.h>
Calculate cache eviction score.
| last_access_time | Last access timestamp (nanoseconds) |
| access_count | Total access count |
| creation_time | Cache creation timestamp (nanoseconds) |
| current_time | Current timestamp (nanoseconds) |
Definition at line 87 of file video/simd/common.c.
References CACHE_FREQUENCY_DECAY_TIME, CACHE_MAX_LIFETIME, and CACHE_RECENCY_SCALE.
Referenced by __attribute__().
| void convert_pixels_scalar | ( | const rgb_pixel_t * | pixels, |
| char * | ascii_chars, | ||
| int | count, | ||
| const char | luminance_palette[256] | ||
| ) |
#include <ascii_simd.h>
Convert pixels to ASCII (scalar fallback)
| pixels | RGB pixel array |
| ascii_chars | Output buffer for ASCII characters |
| count | Number of pixels to convert |
| luminance_palette | Luminance-to-character mapping palette |
Definition at line 167 of file ascii_simd.c.
References LUMA_BLUE, LUMA_GREEN, and LUMA_RED.
| char * convert_pixels_scalar_with_newlines | ( | image_t * | image, |
| const char | luminance_palette[256] | ||
| ) |
#include <ascii_simd.h>
Convert image to ASCII with newlines (scalar fallback)
| image | Source image |
| luminance_palette | Luminance-to-character mapping palette |
Definition at line 182 of file ascii_simd.c.
References outbuf_t::buf, outbuf_t::cap, emit_rep(), image_t::h, log_error, LUMA_BLUE, LUMA_GREEN, LUMA_RED, ob_putc(), ob_term(), image_t::pixels, rep_is_profitable(), SAFE_MALLOC, and image_t::w.
#include <output_buffer.h>
Emit run-length encoded sequence.
| ob | Output buffer structure (must not be NULL) |
| extra | Additional characters to repeat (must be > 0) |
Emits an ANSI run-length encoding sequence that repeats the last character in the buffer 'extra' times. Format: ESC[extram (where 'extra' is the repeat count and the last character is repeated).
Definition at line 149 of file output_buffer.c.
References ob_putc(), and ob_u32().
Referenced by ansi_compress_rle(), convert_pixels_scalar_with_newlines(), and image_print().
| void emit_reset | ( | outbuf_t * | ob | ) |
#include <output_buffer.h>
Emit ANSI reset sequence.
| ob | Output buffer structure (must not be NULL) |
Emits ANSI escape sequence to reset all terminal attributes to defaults. Format: ESC[0m or ESC[m. Resets colors, bold, underline, and other formatting attributes.
Definition at line 131 of file output_buffer.c.
References ob_putc().
#include <output_buffer.h>
Emit 256-color background ANSI sequence.
| ob | Output buffer structure (must not be NULL) |
| color_idx | 256-color palette index (0-255) |
Emits ANSI escape sequence for 256-color background color. Format: ESC[48;5;idxm (where idx is palette index 0-255). Uses extended ANSI color palette for 256-color mode.
Definition at line 172 of file output_buffer.c.
References ob_putc(), ob_u8(), and ob_write().
#include <output_buffer.h>
Emit 256-color foreground ANSI sequence.
| ob | Output buffer structure (must not be NULL) |
| color_idx | 256-color palette index (0-255) |
Emits ANSI escape sequence for 256-color foreground color. Format: ESC[38;5;idxm (where idx is palette index 0-255). Uses extended ANSI color palette for 256-color mode.
Definition at line 160 of file output_buffer.c.
References ob_putc(), ob_u8(), and ob_write().
#include <output_buffer.h>
Emit background color sequence (auto-select mode)
| ob | Output buffer structure (must not be NULL) |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Emits background color ANSI sequence using the optimal color mode based on terminal capabilities. Automatically selects:
Definition at line 198 of file output_buffer.c.
References ob_putc(), ob_u8(), and ob_write().
#include <output_buffer.h>
Emit foreground color sequence (auto-select mode)
| ob | Output buffer structure (must not be NULL) |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Emits foreground color ANSI sequence using the optimal color mode based on terminal capabilities. Automatically selects:
Definition at line 183 of file output_buffer.c.
References ob_putc(), ob_u8(), and ob_write().
#include <output_buffer.h>
Emit truecolor background ANSI sequence.
| ob | Output buffer structure (must not be NULL) |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Emits ANSI escape sequence for 24-bit truecolor background color. Format: ESC[48;2;r;g;bm (where r, g, b are RGB values). Uses 24-bit RGB color values for optimal color accuracy.
Definition at line 116 of file output_buffer.c.
References ob_putc(), ob_u8(), and ob_write().
#include <output_buffer.h>
Emit truecolor foreground ANSI sequence.
| ob | Output buffer structure (must not be NULL) |
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Emits ANSI escape sequence for 24-bit truecolor foreground color. Format: ESC[38;2;r;g;bm (where r, g, b are RGB values). Uses 24-bit RGB color values for optimal color accuracy.
Definition at line 100 of file output_buffer.c.
References ob_putc(), ob_u8(), and ob_write().
#include <ansi_fast.h>
Get the actual RGB values for a 16-color ANSI index.
| color_index | 16-color ANSI index (0-15) |
| r | Output red component (0-255) |
| g | Output green component (0-255) |
| b | Output blue component (0-255) |
Definition at line 320 of file ansi_fast.c.
Referenced by image_print_16color_dithered_with_background(), and rgb_to_16color_dithered().
| bool get_256_color_fast_path | ( | void | ) |
#include <ascii_simd.h>
Get 256-color fast path setting.
| uint64_t get_current_time_ns | ( | void | ) |
#include <common.h>
Get current time in nanoseconds.
Definition at line 81 of file video/simd/common.c.
Referenced by __attribute__().
| char * get_lum_palette | ( | void | ) |
#include <ascii.h>
Get luminance palette for character mapping.
Returns the default luminance-to-character mapping palette. The palette contains 256 characters ordered by luminance (dark to light) for mapping pixel brightness values (0-255) to ASCII characters.
#include <ascii_simd.h>
Get 256-color foreground/background ANSI sequence string.
| fg | Foreground palette index (0-255) |
| bg | Background palette index (0-255) |
| len_out | Output parameter for sequence length |
Definition at line 102 of file ascii_simd_color.c.
#include <ascii_simd.h>
Get 256-color foreground ANSI sequence string.
| fg | 256-color palette index (0-255) |
| len_out | Output parameter for sequence length |
Definition at line 97 of file ascii_simd_color.c.
| utf8_palette_cache_t * get_utf8_palette_cache | ( | const char * | ascii_chars | ) |
#include <common.h>
Get or create UTF-8 palette cache.
| ascii_chars | Character palette string |
Thread-safe cache lookup with automatic creation and eviction.
Referenced by image_print(), image_print_16color(), image_print_16color_dithered(), image_print_16color_dithered_with_background(), and image_print_color().
| bool has_avx2_support | ( | void | ) |
| bool has_neon_support | ( | void | ) |
| bool has_sse2_support | ( | void | ) |
| bool has_ssse3_support | ( | void | ) |
| bool has_sve_support | ( | void | ) |
| void image_clear | ( | image_t * | p | ) |
#include <image.h>
Clear image (set all pixels to black)
| p | Image to clear (must not be NULL) |
Sets all pixels in the image to black (RGB = 0, 0, 0). Useful for resetting image state before filling with new data.
Definition at line 203 of file video/image.c.
References ERROR_INVALID_PARAM, image_t::h, image_t::pixels, SAFE_MEMSET, SET_ERRNO, and image_t::w.
Referenced by ascii_convert(), and ascii_convert_with_capabilities().
| void image_destroy | ( | image_t * | p | ) |
#include <image.h>
Destroy an image allocated with image_new()
| p | Image to destroy (can be NULL, no-op if NULL) |
Frees an image structure and its associated pixel data array allocated by image_new(). Frees both the image structure and the pixels array.
Definition at line 85 of file video/image.c.
References image_t::alloc_method, ASCIICHAT_OK, buffer_pool_free(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, image_t::h, IMAGE_ALLOC_POOL, image_t::pixels, SAFE_FREE, SET_ERRNO, and image_t::w.
Referenced by ascii_convert(), ascii_convert_with_capabilities(), benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), benchmark_simd_conversion_with_source(), and mirror_main().
| void image_destroy_to_pool | ( | image_t * | image | ) |
#include <image.h>
Destroy an image allocated from buffer pool.
| image | Image to destroy (can be NULL, no-op if NULL) |
Returns an image structure and its pixel data to the buffer pool for reuse. This is faster than standard free() because buffers are reused instead of being deallocated.
Definition at line 171 of file video/image.c.
References ASCIICHAT_OK, buffer_pool_free(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, image_t::h, SET_ERRNO, and image_t::w.
Referenced by create_mixed_ascii_frame_for_client().
| image_t * image_new | ( | size_t | width, |
| size_t | height | ||
| ) |
#include <image.h>
Create a new image with standard allocation.
| width | Image width in pixels (must be > 0 and <= IMAGE_MAX_WIDTH) |
| height | Image height in pixels (must be > 0 and <= IMAGE_MAX_HEIGHT) |
Allocates a new image structure and pixel data array using standard malloc() allocation. Image is initialized with specified dimensions and all pixels set to black (0, 0, 0).
Definition at line 36 of file video/image.c.
References image_t::alloc_method, ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_MEMORY, image_t::h, IMAGE_ALLOC_SIMD, IMAGE_MAX_PIXELS_SIZE, image_validate_dimensions(), image_t::pixels, SAFE_FREE, SAFE_MALLOC, SAFE_MALLOC_SIMD, SET_ERRNO, and image_t::w.
Referenced by ascii_convert(), ascii_convert_with_capabilities(), benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), benchmark_simd_conversion_with_source(), and webcam_read().
| image_t * image_new_from_pool | ( | size_t | width, |
| size_t | height | ||
| ) |
#include <image.h>
Create a new image from buffer pool.
| width | Image width in pixels (must be > 0 and <= IMAGE_MAX_WIDTH) |
| height | Image height in pixels (must be > 0 and <= IMAGE_MAX_HEIGHT) |
Allocates a new image structure and pixel data from the buffer pool for efficient memory management in video pipeline. Buffer pool reduces allocation overhead and improves performance for high-frequency operations (video frame capture/processing).
Definition at line 126 of file video/image.c.
References image_t::alloc_method, ASCIICHAT_OK, buffer_pool_alloc(), ERROR_INVALID_PARAM, ERROR_MEMORY, image_t::h, IMAGE_ALLOC_POOL, IMAGE_MAX_HEIGHT, IMAGE_MAX_WIDTH, image_t::pixels, SET_ERRNO, and image_t::w.
| char * image_print | ( | const image_t * | p, |
| const char * | palette | ||
| ) |
#include <image.h>
Print image as ASCII art (monochrome)
| p | Image to print (must not be NULL) |
| palette | Character palette to use (or NULL for default ASCII palette) |
Converts an image to ASCII art without color output. Uses character palette to map pixel luminance to ASCII characters. Returns a null-terminated string containing the ASCII art frame.
Definition at line 349 of file video/image.c.
References ASCIICHAT_OK, outbuf_t::buf, utf8_char_t::byte_len, utf8_palette_cache_s::cache64, outbuf_t::cap, utf8_palette_cache_s::char_index_ramp, emit_rep(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_MEMORY, get_utf8_palette_cache(), image_t::h, ob_putc(), ob_term(), ob_write(), image_t::pixels, rep_is_profitable(), SAFE_MALLOC, SET_ERRNO, utf8_char_t::utf8_bytes, and image_t::w.
Referenced by ascii_convert(), benchmark_simd_conversion(), image_print_simd(), and image_print_with_capabilities().
| char * image_print_16color | ( | const image_t * | image, |
| const char * | palette | ||
| ) |
#include <image.h>
Print image using 16-color ANSI mode.
| image | Image to print (must not be NULL) |
| palette | Character palette to use (or NULL for default ASCII palette) |
Converts an image to ASCII art using 16-color ANSI mode. Uses standard ANSI color palette (0-15) for color output. Colors are quantized to 16-color palette.
Definition at line 739 of file video/image.c.
References ansi_fast_init_16color(), append_16color_fg(), ASCIICHAT_OK, utf8_char_t::byte_len, utf8_palette_cache_s::cache, utf8_palette_cache_s::char_index_ramp, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, get_utf8_palette_cache(), image_t::h, image_t::pixels, rgb_to_16color(), SAFE_MALLOC, SAFE_STRNCPY, SET_ERRNO, utf8_char_t::utf8_bytes, and image_t::w.
| char * image_print_16color_dithered | ( | const image_t * | image, |
| const char * | palette | ||
| ) |
#include <image.h>
Print image using 16-color ANSI mode with dithering.
| image | Image to print (must not be NULL) |
| palette | Character palette to use (or NULL for default ASCII palette) |
Converts an image to ASCII art using 16-color ANSI mode with Floyd-Steinberg dithering. Dithering improves color accuracy by distributing quantization errors across neighboring pixels.
DITHERING:
Definition at line 833 of file video/image.c.
References ansi_fast_init_16color(), append_16color_fg(), ASCIICHAT_OK, utf8_char_t::byte_len, utf8_palette_cache_s::cache, utf8_palette_cache_s::char_index_ramp, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, get_utf8_palette_cache(), image_t::h, image_t::pixels, rgb_to_16color_dithered(), SAFE_CALLOC, SAFE_FREE, SAFE_MALLOC, SAFE_STRNCPY, SET_ERRNO, utf8_char_t::utf8_bytes, and image_t::w.
| char * image_print_16color_dithered_with_background | ( | const image_t * | image, |
| bool | use_background, | ||
| const char * | palette | ||
| ) |
#include <image.h>
Print image using 16-color ANSI mode with dithering and background colors.
| image | Image to print (must not be NULL) |
| use_background | Whether to use background colors (true) or foreground colors only (false) |
| palette | Character palette to use (or NULL for default ASCII palette) |
Converts an image to ASCII art using 16-color ANSI mode with Floyd-Steinberg dithering and optional background color support. Background colors provide better color coverage for block-style rendering.
RENDERING MODES:
Definition at line 936 of file video/image.c.
References ansi_fast_init_16color(), append_16color_bg(), append_16color_fg(), utf8_char_t::byte_len, utf8_palette_cache_s::cache, utf8_palette_cache_s::char_index_ramp, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, get_16color_rgb(), get_utf8_palette_cache(), image_t::h, image_t::pixels, rgb_to_16color_dithered(), SAFE_CALLOC, SAFE_FREE, SAFE_MALLOC, SAFE_STRNCPY, SET_ERRNO, utf8_char_t::utf8_bytes, and image_t::w.
Referenced by image_print_with_capabilities().
| char * image_print_256color | ( | const image_t * | image, |
| const char * | palette | ||
| ) |
#include <image.h>
Print image using 256-color ANSI mode.
| image | Image to print (must not be NULL) |
| palette | Character palette to use (or NULL for default ASCII palette) |
Converts an image to ASCII art using 256-color ANSI mode. Uses extended ANSI color palette (0-255) for color output. Colors are quantized to 256-color palette.
Definition at line 722 of file video/image.c.
References ERROR_INVALID_PARAM, image_print_color(), image_print_color_simd(), image_t::pixels, and SET_ERRNO.
Referenced by image_print_with_capabilities().
| char * image_print_color | ( | const image_t * | p, |
| const char * | palette | ||
| ) |
#include <image.h>
Print image as ASCII art with color.
| p | Image to print (must not be NULL) |
| palette | Character palette to use (or NULL for default ASCII palette) |
Converts an image to ASCII art with color output. Uses character palette for character mapping and ANSI color codes for color output. Returns a null-terminated string containing the ASCII art frame with embedded ANSI escape sequences.
Converts an image to colored ASCII art with ANSI escape codes.
This function generates a string representation of an image where each pixel is converted to an ASCII character with ANSI color codes. The character is chosen based on luminance, and colors are applied using 24-bit RGB ANSI escape sequences.
Buffer allocation is precisely calculated to avoid waste and prevent overflows:
Color modes:
ANSI escape code format:
| p | Pointer to image_t structure containing pixel data |
Definition at line 513 of file video/image.c.
References ANSI_MODE_FOREGROUND, ansi_rle_add_pixel(), ansi_rle_finish(), ansi_rle_init(), ansi_rle_context_t::buffer, utf8_palette_cache_s::cache, ansi_rle_context_t::capacity, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, get_utf8_palette_cache(), image_t::h, ansi_rle_context_t::length, image_t::pixels, SAFE_MALLOC, SET_ERRNO, utf8_char_t::utf8_bytes, and image_t::w.
Referenced by ascii_convert(), benchmark_simd_color_conversion(), benchmark_simd_conversion_with_source(), image_print_256color(), image_print_color_simd(), and image_print_with_capabilities().
| char * image_print_color_simd | ( | image_t * | image, |
| bool | use_background_mode, | ||
| bool | use_256color, | ||
| const char * | ascii_chars | ||
| ) |
#include <ascii_simd.h>
Print image as ASCII with color using SIMD.
| image | Source image |
| use_background_mode | Use background colors |
| use_256color | Use 256-color mode (vs truecolor) |
| ascii_chars | Character palette |
Definition at line 375 of file ascii_simd_color.c.
References image_print_color().
Referenced by ascii_convert(), image_print_256color(), and image_print_with_capabilities().
| char * image_print_simd | ( | image_t * | image, |
| const char * | ascii_chars | ||
| ) |
#include <ascii_simd.h>
Print image as ASCII using SIMD (monochrome)
| image | Source image |
| ascii_chars | Character palette |
Definition at line 252 of file ascii_simd.c.
References image_print().
Referenced by ascii_convert(), and image_print_with_capabilities().
| char * image_print_with_capabilities | ( | const image_t * | image, |
| const terminal_capabilities_t * | caps, | ||
| const char * | palette, | ||
| const char | luminance_palette[256] | ||
| ) |
#include <image.h>
Print image with terminal capability awareness.
| image | Image to print (must not be NULL) |
| caps | Terminal capabilities structure (must not be NULL) |
| palette | Character palette to use (or NULL for default ASCII palette) |
| luminance_palette | Luminance-to-character mapping palette (must not be NULL, 256 elements) |
Converts an image to ASCII art with automatic color mode selection based on terminal capabilities. Automatically chooses the best color mode (16-color, 256-color, or truecolor) for the terminal.
COLOR MODE SELECTION:
#include <image.h>
Resize image using nearest-neighbor interpolation.
| source | Source image (must not be NULL) |
| dest | Destination image (must be allocated and have valid dimensions) |
Resizes an image using nearest-neighbor interpolation. Fast but may produce aliasing artifacts. Source pixels are sampled to nearest destination pixel positions.
NEAREST-NEIGHBOR INTERPOLATION:
Definition at line 232 of file video/image.c.
References ERROR_INVALID_PARAM, image_resize_interpolation(), and SET_ERRNO.
Referenced by ascii_convert(), and ascii_convert_with_capabilities().
#include <image.h>
Resize image using bilinear interpolation.
| source | Source image (must not be NULL) |
| dest | Destination image (must be allocated and have valid dimensions) |
Resizes an image using bilinear interpolation. Produces smoother results than nearest-neighbor but slower. Pixel values are interpolated from four nearest source pixels.
BILINEAR INTERPOLATION:
Definition at line 243 of file video/image.c.
References ERROR_INVALID_PARAM, image_t::h, image_t::pixels, SET_ERRNO, and image_t::w.
Referenced by image_resize().
| void init_dec3 | ( | void | ) |
#include <ascii_simd.h>
Initialize decimal lookup table.
Must be called before using any SIMD conversion functions.
Definition at line 58 of file ascii_simd.c.
References global_dec3_cache_t::dec3_initialized, global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, and dec3_t::s.
Referenced by ascii_simd_init().
| void init_default_luminance_palette | ( | void | ) |
#include <ascii_simd.h>
Initialize default luminance palette.
Definition at line 37 of file ascii_simd.c.
References DEFAULT_ASCII_PALETTE, DEFAULT_ASCII_PALETTE_LEN, and g_default_luminance_palette.
Referenced by ascii_simd_init().
| void ob_putc | ( | outbuf_t * | ob, |
| char | c | ||
| ) |
#include <output_buffer.h>
Append a character to buffer.
| ob | Output buffer structure (must not be NULL) |
| c | Character to append |
Appends a single character to the output buffer. Automatically expands the buffer if necessary. Buffer remains null-terminated after append.
Definition at line 42 of file output_buffer.c.
References outbuf_t::buf, outbuf_t::len, and ob_reserve().
Referenced by ansi_compress_rle(), ansi_strip_escapes(), convert_pixels_scalar_with_newlines(), emit_rep(), emit_reset(), emit_set_256_color_bg(), emit_set_256_color_fg(), emit_set_bg(), emit_set_fg(), emit_set_truecolor_bg(), emit_set_truecolor_fg(), image_print(), ob_term(), and ob_u8().
| void ob_reserve | ( | outbuf_t * | ob, |
| size_t | need | ||
| ) |
#include <output_buffer.h>
Reserve buffer space for upcoming writes.
| ob | Output buffer structure (must not be NULL) |
| need | Minimum bytes needed (must be > 0) |
Ensures the buffer has at least 'need' bytes of available space. Automatically expands the buffer if necessary. Buffer grows exponentially (doubles in size) to minimize reallocation overhead.
Definition at line 21 of file output_buffer.c.
References outbuf_t::buf, outbuf_t::cap, outbuf_t::len, and SAFE_REALLOC.
Referenced by ansi_compress_rle(), ansi_expand_rle(), ansi_strip_escapes(), ob_putc(), ob_u32(), and ob_write().
| void ob_term | ( | outbuf_t * | ob | ) |
#include <output_buffer.h>
Append null terminator to buffer.
| ob | Output buffer structure (must not be NULL) |
Ensures the buffer is null-terminated by appending a null character. Does not increment length counter (null terminator is not counted). Useful for ensuring buffer is a valid C string.
Definition at line 57 of file output_buffer.c.
References ob_putc().
Referenced by ansi_compress_rle(), ansi_expand_rle(), ansi_strip_escapes(), convert_pixels_scalar_with_newlines(), and image_print().
#include <output_buffer.h>
Append unsigned 32-bit integer as decimal string.
| ob | Output buffer structure (must not be NULL) |
| v | Value to append (0 to 4294967295) |
Converts an unsigned 32-bit integer to decimal string representation and appends it to the buffer. Useful for formatting numeric values (dimensions, counts, timestamps, etc.).
Definition at line 85 of file output_buffer.c.
References outbuf_t::buf, outbuf_t::len, and ob_reserve().
Referenced by emit_rep().
#include <output_buffer.h>
Append unsigned 8-bit integer as decimal string.
| ob | Output buffer structure (must not be NULL) |
| v | Value to append (0-255) |
Converts an unsigned 8-bit integer to decimal string representation and appends it to the buffer. Useful for formatting small numeric values (color indices, counts, etc.).
Definition at line 64 of file output_buffer.c.
References ob_putc().
Referenced by emit_set_256_color_bg(), emit_set_256_color_fg(), emit_set_bg(), emit_set_fg(), emit_set_truecolor_bg(), and emit_set_truecolor_fg().
| void ob_write | ( | outbuf_t * | ob, |
| const char * | s, | ||
| size_t | n | ||
| ) |
#include <output_buffer.h>
Append a string to buffer.
| ob | Output buffer structure (must not be NULL) |
| s | String to append (must not be NULL) |
| n | Number of bytes to append (must be > 0) |
Appends n bytes from string s to the output buffer. Automatically expands the buffer if necessary. Buffer remains null-terminated after append.
Definition at line 49 of file output_buffer.c.
References outbuf_t::buf, outbuf_t::cap, outbuf_t::len, ob_reserve(), and SAFE_MEMCPY.
Referenced by ansi_compress_rle(), ansi_expand_rle(), emit_set_256_color_bg(), emit_set_256_color_fg(), emit_set_bg(), emit_set_fg(), emit_set_truecolor_bg(), emit_set_truecolor_fg(), and image_print().
| void precalc_rgb_palettes | ( | const float | red, |
| const float | green, | ||
| const float | blue | ||
| ) |
#include <image.h>
Precalculate RGB palettes with color adjustment.
| red | Red adjustment factor (1.0 = no adjustment, >1.0 = increase, <1.0 = decrease) |
| green | Green adjustment factor (1.0 = no adjustment, >1.0 = increase, <1.0 = decrease) |
| blue | Blue adjustment factor (1.0 = no adjustment, >1.0 = increase, <1.0 = decrease) |
Precalculates RGB color palettes with color adjustment factors. Color adjustment allows brightness, contrast, and color balance adjustments to be applied efficiently during ASCII conversion.
COLOR ADJUSTMENT:
Definition at line 284 of file video/image.c.
References ASCII_LUMINANCE_LEVELS, BLUE, ERROR_INVALID_PARAM, GRAY, GREEN, log_error, log_warn, RED, and SET_ERRNO.
Referenced by server_main().
| void prewarm_sgr256_cache | ( | void | ) |
#include <ascii_simd.h>
Prewarm 256-color foreground/background cache for benchmarks.
Prevents first-frame performance penalty in benchmarks.
Definition at line 92 of file ascii_simd_color.c.
Referenced by benchmark_simd_color_conversion_with_source().
| void prewarm_sgr256_fg_cache | ( | void | ) |
#include <ascii_simd.h>
Prewarm 256-color foreground cache for benchmarks.
Prevents first-frame performance penalty in benchmarks.
Definition at line 88 of file ascii_simd_color.c.
Referenced by benchmark_simd_color_conversion_with_source().
| void print_simd_capabilities | ( | void | ) |
#include <ascii_simd.h>
Print detected SIMD capabilities.
Prints available SIMD instruction sets to stdout.
Definition at line 276 of file ascii_simd.c.
| void quantize_color | ( | int * | r, |
| int * | g, | ||
| int * | b, | ||
| int | levels | ||
| ) |
#include <image.h>
Quantize color to specified number of levels.
| r | Red component (input/output, must not be NULL, range 0-255) |
| g | Green component (input/output, must not be NULL, range 0-255) |
| b | Blue component (input/output, must not be NULL, range 0-255) |
| levels | Number of quantization levels (must be > 0) |
Quantizes RGB color components to a specified number of levels. Reduces color precision for color palette mapping. Input colors are modified in-place to quantized values.
QUANTIZATION:
Definition at line 462 of file video/image.c.
References ERROR_INVALID_PARAM, and SET_ERRNO.
#include <output_buffer.h>
Check if run-length encoding is profitable.
| runlen | Run length to check (number of repeated characters) |
Determines whether run-length encoding (RLE) would reduce output size compared to emitting individual characters. RLE is profitable when the overhead of the repeat sequence is less than the characters it replaces.
RLE PROFITABILITY:
Definition at line 141 of file output_buffer.c.
Referenced by ansi_compress_rle(), convert_pixels_scalar_with_newlines(), and image_print().
#include <ansi_fast.h>
Convert RGB to 16-color ANSI index.
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Definition at line 277 of file ansi_fast.c.
Referenced by append_color_fg_for_mode(), image_print_16color(), and rgb_to_16color_dithered().
| 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 | ||
| ) |
#include <ansi_fast.h>
Convert RGB to 16-color with Floyd-Steinberg dithering.
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
| x | Pixel X coordinate |
| y | Pixel Y coordinate |
| width | Image width |
| height | Image height |
| error_buffer | Error diffusion buffer |
Uses Floyd-Steinberg dithering algorithm for improved color approximation.
Definition at line 351 of file ansi_fast.c.
References rgb_error_t::b, rgb_error_t::g, get_16color_rgb(), rgb_error_t::r, and rgb_to_16color().
Referenced by image_print_16color_dithered(), and image_print_16color_dithered_with_background().
#include <ansi_fast.h>
Convert RGB to 256-color palette index.
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Definition at line 199 of file ansi_fast.c.
Referenced by append_color_fg_for_mode().
| void rgb_to_ansi_8bit | ( | int | r, |
| int | g, | ||
| int | b, | ||
| int * | fg_code, | ||
| int * | bg_code | ||
| ) |
#include <image.h>
Convert RGB to 8-bit ANSI color codes.
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
| fg_code | Output foreground color code (must not be NULL, range 0-255) |
| bg_code | Output background color code (must not be NULL, range 0-255) |
Converts RGB color values to 8-bit ANSI color codes (256-color palette). Quantizes RGB colors to 256-color palette indices for foreground and background colors. Output codes are indices into 256-color ANSI palette.
COLOR QUANTIZATION:
Definition at line 628 of file video/image.c.
References ERROR_INVALID_PARAM, and SET_ERRNO.
| char * rgb_to_ansi_bg | ( | int | r, |
| int | g, | ||
| int | b | ||
| ) |
#include <image.h>
Convert RGB to ANSI background color code.
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Converts RGB color values to ANSI background color escape sequence. Returns a string containing the ANSI escape sequence for background color (e.g., "\033[48;2;255;0;0m" for red background).
Definition at line 622 of file video/image.c.
References SAFE_SNPRINTF.
| char * rgb_to_ansi_fg | ( | int | r, |
| int | g, | ||
| int | b | ||
| ) |
#include <image.h>
Convert RGB to ANSI foreground color code.
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
Converts RGB color values to ANSI foreground color escape sequence. Returns a string containing the ANSI escape sequence for foreground color (e.g., "\033[38;2;255;0;0m" for red).
Definition at line 616 of file video/image.c.
References SAFE_SNPRINTF.
| void set_color_quality_mode | ( | bool | high_quality | ) |
#include <ascii_simd.h>
Set color quality mode.
| high_quality | true for 24-bit truecolor, false for 256-color |
Controls tradeoff between color fidelity and rendering speed.
| void simd_caches_destroy_all | ( | void | ) |
#include <common.h>
Destroy all SIMD caches.
Cleans up all caches and frees associated memory.
Referenced by server_main().
| void str_append_bytes | ( | Str * | s, |
| const void * | src, | ||
| size_t | n | ||
| ) |
#include <ascii_simd.h>
Append bytes to string buffer.
| s | String buffer structure |
| src | Source data |
| n | Number of bytes to append |
Definition at line 130 of file ascii_simd.c.
References Str::data, Str::len, and str_reserve().
Referenced by str_printf().
| void str_append_c | ( | Str * | s, |
| char | c | ||
| ) |
#include <ascii_simd.h>
Append character to string buffer.
| s | String buffer structure |
| c | Character to append |
Definition at line 136 of file ascii_simd.c.
References Str::data, Str::len, and str_reserve().
| void str_free | ( | Str * | s | ) |
#include <ascii_simd.h>
Free string buffer.
| s | String buffer structure |
Definition at line 114 of file ascii_simd.c.
| void str_init | ( | Str * | s | ) |
#include <ascii_simd.h>
Initialize string buffer.
| s | String buffer structure |
Definition at line 108 of file ascii_simd.c.
| void str_printf | ( | Str * | s, |
| const char * | fmt, | ||
| ... | |||
| ) |
#include <ascii_simd.h>
Append formatted string to buffer.
| s | String buffer structure |
| fmt | Format string |
| ... | Variable arguments |
Definition at line 141 of file ascii_simd.c.
References SAFE_FREE, SAFE_MALLOC, and str_append_bytes().
| void str_reserve | ( | Str * | s, |
| size_t | need | ||
| ) |
#include <ascii_simd.h>
Reserve space in string buffer.
| s | String buffer structure |
| need | Minimum bytes needed |
Definition at line 120 of file ascii_simd.c.
References Str::cap, Str::data, and SAFE_REALLOC.
Referenced by str_append_bytes(), and str_append_c().
| size_t write_rgb_triplet | ( | uint8_t | value, |
| char * | dst | ||
| ) |
#include <common.h>
Write decimal RGB triplet using dec3 cache.
| value | RGB component value (0-255) |
| dst | Destination buffer pointer |
Definition at line 26 of file ascii_simd.c.
References global_dec3_cache_t::dec3_table, g_dec3_cache, dec3_t::len, and dec3_t::s.
| 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 | ||
| ) |
#include <ascii_simd.h>
Enhanced REP compression writer.
| fg_r | Foreground red array |
| fg_g | Foreground green array |
| fg_b | Foreground blue array |
| bg_r | Background red array |
| bg_g | Background green array |
| bg_b | Background blue array |
| fg_idx | Foreground color indices |
| bg_idx | Background color indices |
| ascii_chars | Character palette |
| width | Image width in pixels |
| dst | Output buffer |
| cap | Output buffer capacity |
| is_truecolor | Use truecolor mode |
Used by scalar fallbacks and declared in NEON implementation.
| _Atomic uint32_t utf8_palette_cache_s::access_count |
Total access count (atomic)
Definition at line 111 of file video/simd/common.h.
Referenced by __attribute__().
|
extern |
#include <ascii.h>
Default ASCII palette characters.
Default character palette for ASCII art conversion. Contains characters ordered by luminance (dark to light) for mapping pixel brightness to ASCII characters.
| double simd_benchmark_t::avx2_time |
AVX2 implementation time (seconds)
Definition at line 275 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| const char* simd_benchmark_t::best_method |
Name of fastest method
Definition at line 279 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| uint8_t utf8_char_t::byte_len |
Actual byte length (1-4)
Definition at line 91 of file video/simd/common.h.
Referenced by build_utf8_luminance_cache(), build_utf8_ramp64_cache(), image_print(), image_print_16color(), image_print_16color_dithered(), and image_print_16color_dithered_with_background().
| utf8_char_t utf8_palette_cache_s::cache[256] |
256-entry cache for direct luminance lookup (monochrome)
Definition at line 103 of file video/simd/common.h.
Referenced by image_print_16color(), image_print_16color_dithered(), image_print_16color_dithered_with_background(), and image_print_color().
| utf8_char_t utf8_palette_cache_s::cache64[64] |
64-entry cache for SIMD color lookup
Definition at line 104 of file video/simd/common.h.
Referenced by image_print().
| double utf8_palette_cache_s::cached_score |
Last calculated eviction score
Definition at line 116 of file video/simd/common.h.
| size_t Str::cap |
Total bytes allocated
Definition at line 147 of file ascii_simd.h.
Referenced by str_free(), str_init(), and str_reserve().
| int RLEState::cBB |
Current background RGB
Definition at line 213 of file ascii_simd.h.
| int RLEState::cBG |
Definition at line 213 of file ascii_simd.h.
| int RLEState::cBR |
Definition at line 213 of file ascii_simd.h.
| int RLEState::cFB |
Current foreground RGB
Definition at line 212 of file ascii_simd.h.
| int RLEState::cFG |
Definition at line 212 of file ascii_simd.h.
| int RLEState::cFR |
Definition at line 212 of file ascii_simd.h.
| uint8_t utf8_palette_cache_s::char_index_ramp[64] |
Character indices for vqtbl4q_u8 lookup
Definition at line 105 of file video/simd/common.h.
Referenced by image_print(), image_print_16color(), image_print_16color_dithered(), and image_print_16color_dithered_with_background().
| uint64_t utf8_palette_cache_s::creation_time |
When cache was created (immutable)
Definition at line 112 of file video/simd/common.h.
| char* Str::data |
Pointer to allocated buffer
Definition at line 145 of file ascii_simd.h.
Referenced by str_append_bytes(), str_append_c(), str_free(), str_init(), and str_reserve().
|
extern |
#include <ansi_fast.h>
Access to internal decimal lookup table for testing.
| bool global_dec3_cache_t::dec3_initialized |
| dec3_t global_dec3_cache_t::dec3_table[256] |
Lookup table for 0-255
Definition at line 98 of file ascii_simd.h.
Referenced by append_sgr_truecolor_bg(), append_sgr_truecolor_fg(), append_sgr_truecolor_fg_bg(), append_truecolor_bg(), append_truecolor_fg(), append_truecolor_fg_bg(), init_dec3(), and write_rgb_triplet().
|
extern |
#include <ascii_simd.h>
Global decimal cache instance.
Definition at line 23 of file ascii_simd.c.
Referenced by append_sgr_truecolor_bg(), append_sgr_truecolor_fg(), append_sgr_truecolor_fg_bg(), append_truecolor_bg(), append_truecolor_fg(), append_truecolor_fg_bg(), init_dec3(), and write_rgb_triplet().
|
extern |
#include <ascii_simd.h>
Default luminance palette (256 characters)
Definition at line 33 of file ascii_simd.c.
Referenced by benchmark_simd_color_conversion_with_source(), and init_default_luminance_palette().
| int ImageRGB::h |
| size_t utf8_palette_cache_s::heap_index |
Min-heap eviction management (protected by write lock) Position in min-heap (for O(log n) updates)
Definition at line 115 of file video/simd/common.h.
| UT_hash_handle utf8_palette_cache_s::hh |
uthash handle (required for hash table operations)
Definition at line 119 of file video/simd/common.h.
| bool utf8_palette_cache_s::is_valid |
Whether cache is valid
Definition at line 107 of file video/simd/common.h.
| uint32_t utf8_palette_cache_s::key |
Hash key for uthash lookup
Definition at line 102 of file video/simd/common.h.
Referenced by __attribute__().
| _Atomic uint64_t utf8_palette_cache_s::last_access_time |
Thread-safe eviction tracking Nanoseconds since epoch (atomic)
Definition at line 110 of file video/simd/common.h.
Referenced by __attribute__().
| uint8_t dec3_t::len |
Number of digits (1-3)
Definition at line 88 of file ascii_simd.h.
Referenced by append_sgr_truecolor_bg(), append_sgr_truecolor_fg(), append_sgr_truecolor_fg_bg(), append_truecolor_bg(), append_truecolor_fg(), append_truecolor_fg_bg(), init_dec3(), and write_rgb_triplet().
| size_t Str::len |
Number of bytes currently used
Definition at line 146 of file ascii_simd.h.
Referenced by str_append_bytes(), str_append_c(), str_free(), and str_init().
| double simd_benchmark_t::neon_time |
NEON implementation time (seconds)
Definition at line 276 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| char utf8_palette_cache_s::palette_hash[64] |
Hash of palette for cache validation
Definition at line 106 of file video/simd/common.h.
| uint8_t* ImageRGB::pixels |
| int RLEState::runLen |
Current run length
Definition at line 214 of file ascii_simd.h.
| char dec3_t::s[3] |
Digit string (no null terminator)
Definition at line 89 of file ascii_simd.h.
Referenced by append_sgr_truecolor_bg(), append_sgr_truecolor_fg(), append_sgr_truecolor_fg_bg(), append_truecolor_bg(), append_truecolor_fg(), append_truecolor_fg_bg(), init_dec3(), and write_rgb_triplet().
| double simd_benchmark_t::scalar_time |
Scalar implementation time (seconds)
Definition at line 272 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| int RLEState::seeded |
Whether state is initialized
Definition at line 215 of file ascii_simd.h.
| double simd_benchmark_t::speedup_best |
Best speedup ratio
Definition at line 278 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| double simd_benchmark_t::sse2_time |
SSE2 implementation time (seconds)
Definition at line 273 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| double simd_benchmark_t::ssse3_time |
SSSE3 implementation time (seconds)
Definition at line 274 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion(), benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| double simd_benchmark_t::sve_time |
SVE implementation time (seconds)
Definition at line 277 of file ascii_simd.h.
Referenced by benchmark_simd_color_conversion_with_source(), benchmark_simd_conversion(), and benchmark_simd_conversion_with_source().
| char utf8_char_t::utf8_bytes[4] |
UTF-8 character bytes (up to 4)
Definition at line 90 of file video/simd/common.h.
Referenced by build_utf8_luminance_cache(), build_utf8_ramp64_cache(), image_print(), image_print_16color(), image_print_16color_dithered(), image_print_16color_dithered_with_background(), and image_print_color().
| int ImageRGB::w |