ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
video/rgba/image.h
Go to the documentation of this file.
1#pragma once
2
51
52#include <stdio.h>
53#include <stdlib.h>
54#include <stdint.h>
55
56#include <libplatform/compiler.h>
57#include <ascii-chat/common.h>
58#include <libplatform/terminal.h>
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64// Keep dependency structures at their normal alignment; only image types are packed.
65#ifdef _WIN32
66#pragma pack(push, 1)
67#endif
68
69/* ============================================================================
70 * Data Structures
71 * ============================================================================
72 */
73
85typedef struct {
89} PACKED_ATTR rgb_pixel_t;
90
107typedef struct {
112} ALIGNED_ATTR(16) rgb_pixel_simd_t;
113
135typedef struct image {
136 int w;
137 int h;
142
143/* ============================================================================
144 * Image Size Constants
145 * ============================================================================
146 */
147
160#define IMAGE_MAX_WIDTH 3840
161
173#define IMAGE_MAX_HEIGHT 2160
174
187#define IMAGE_MAX_PIXELS_SIZE (IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT * sizeof(rgb_pixel_t))
188
189/* ============================================================================
190 * Image Allocation and Management Functions
191 * @{
192 */
193
219image_t *image_new(size_t width, size_t height);
220
235void image_destroy(image_t *p);
236
249void image_clear(image_t *p);
250
269
271
272/* ============================================================================
273 * ASCII Conversion Functions
274 * @{
275 */
276
294char *image_print(const image_t *p, const char *palette);
295
314char *image_print_color(const image_t *p, const char *palette);
315
316/* ============================================================================
317 * Capability-Aware ASCII Conversion Functions
318 * @{
319 */
320
346char *image_print_with_capabilities(const image_t *image, const terminal_capabilities_t *caps, const char *palette);
347
365char *image_print_256color(const image_t *image, const char *palette);
366
384char *image_print_16color(const image_t *image, const char *palette);
385
409char *image_print_16color_dithered(const image_t *image, const char *palette);
410
435char *image_print_16color_dithered_with_background(const image_t *image, bool use_background, const char *palette);
436
438
439/* ============================================================================
440 * Color Processing Functions
441 * @{
442 */
443
467void quantize_color(int *r, int *g, int *b, int levels);
468
491void precalc_rgb_palettes(const float red, const float green, const float blue);
492
494
495/* ============================================================================
496 * Image Resizing Functions
497 * @{
498 */
499
521void image_resize(const image_t *source, image_t *dest);
522
545
547
548/* ============================================================================
549 * ANSI Color Code Generation Functions
550 * @{
551 */
552
571char *rgb_to_ansi_fg(int r, int g, int b);
572
591char *rgb_to_ansi_bg(int r, int g, int b);
592
617void rgb_to_ansi_8bit(int r, int g, int b, int *fg_code, int *bg_code);
618
620
621#ifdef __cplusplus
622}
623#endif
624
625#ifdef _WIN32
626#pragma pack(pop)
627#endif
audio_visualization_source_t source
Definition fft.c:25
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
unsigned char uint8_t
image_t * image_new_copy(const image_t *source)
Create a copy of an existing image.
void quantize_color(int *r, int *g, int *b, int levels)
Quantize color to specified number of levels.
Definition foreground.c:40
void precalc_rgb_palettes(const float red, const float green, const float blue)
Precalculate RGB palettes with color adjustment.
void image_resize_interpolation(const image_t *source, image_t *dest)
Resize image using bilinear interpolation.
char * image_print_16color_dithered(const image_t *image, const char *palette)
Print image using 16-color ANSI mode with dithering.
Definition foreground.c:32
char * image_print(const image_t *p, const char *palette)
Print image as ASCII art (monochrome).
Definition foreground.c:12
char * image_print_with_capabilities(const image_t *image, const terminal_capabilities_t *caps, const char *palette)
Convert image to ASCII art with terminal capabilities.
Definition ascii.c:884
char * image_print_color(const image_t *p, const char *palette)
Print image as ASCII art with color.
Definition foreground.c:16
char * rgb_to_ansi_bg(int r, int g, int b)
Convert RGB to ANSI background color code.
Definition foreground.c:63
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.
Definition foreground.c:69
char * image_print_16color(const image_t *image, const char *palette)
Print image using 16-color ANSI mode.
Definition foreground.c:28
char * rgb_to_ansi_fg(int r, int g, int b)
Convert RGB to ANSI foreground color code.
Definition foreground.c:57
void image_clear(image_t *p)
Clear image (set all pixels to black).
void image_resize(const image_t *source, image_t *dest)
Resize image using nearest-neighbor interpolation.
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.
Definition foreground.c:36
char * image_print_256color(const image_t *image, const char *palette)
Print image using 256-color ANSI mode.
Definition foreground.c:24
void image_destroy(image_t *p)
Destroy an image allocated with image_new().
image_t * image_new(size_t width, size_t height)
Create a new image with standard allocation.
⚙️ Common definitions, error codes, macros, and types shared throughout the application
SIMD-friendly storage for one RGB pixel. r, g, and b hold the color channels and padding keeps the la...
int h
Image height in pixels (must be > 0).
rgb_pixel_t * pixels
Pixel data array (width * height RGB pixels, row-major order).
int w
Image width in pixels (must be > 0).
rgb pixel is intentionally a small, concrete record. Fields such as r, g, b give callers the identity...
uint8_t r
Red color component (0-255).
uint8_t g
Green color component (0-255).
uint8_t padding
Padding byte to align to 4-byte boundary (SIMD alignment).
uint8_t b
Blue color component (0-255).
uint8_t b
Blue color component (0-255).
uint8_t g
Green color component (0-255).
uint8_t r
Red color component (0-255).