ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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// Keep dependency structures at their normal alignment; only image types are packed.
61#ifdef _WIN32
62#pragma pack(push, 1)
63#endif
64
65/* ============================================================================
66 * Data Structures
67 * ============================================================================
68 */
69
81typedef struct {
85} PACKED_ATTR rgb_pixel_t;
86
101typedef struct {
106} ALIGNED_ATTR(16) rgb_pixel_simd_t;
107
128typedef struct {
129 int w;
130 int h;
134} image_t;
135
136/* ============================================================================
137 * Image Size Constants
138 * ============================================================================
139 */
140
153#define IMAGE_MAX_WIDTH 3840
154
166#define IMAGE_MAX_HEIGHT 2160
167
180#define IMAGE_MAX_PIXELS_SIZE (IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT * sizeof(rgb_pixel_t))
181
182/* ============================================================================
183 * Image Allocation and Management Functions
184 * @{
185 */
186
212image_t *image_new(size_t width, size_t height);
213
228void image_destroy(image_t *p);
229
242void image_clear(image_t *p);
243
262
264
265/* ============================================================================
266 * ASCII Conversion Functions
267 * @{
268 */
269
287char *image_print(const image_t *p, const char *palette);
288
307char *image_print_color(const image_t *p, const char *palette);
308
309/* ============================================================================
310 * Capability-Aware ASCII Conversion Functions
311 * @{
312 */
313
339char *image_print_with_capabilities(const image_t *image, const terminal_capabilities_t *caps, const char *palette);
340
358char *image_print_256color(const image_t *image, const char *palette);
359
377char *image_print_16color(const image_t *image, const char *palette);
378
402char *image_print_16color_dithered(const image_t *image, const char *palette);
403
428char *image_print_16color_dithered_with_background(const image_t *image, bool use_background, const char *palette);
429
431
432/* ============================================================================
433 * Color Processing Functions
434 * @{
435 */
436
460void quantize_color(int *r, int *g, int *b, int levels);
461
484void precalc_rgb_palettes(const float red, const float green, const float blue);
485
487
488/* ============================================================================
489 * Image Resizing Functions
490 * @{
491 */
492
514void image_resize(const image_t *source, image_t *dest);
515
538
540
541/* ============================================================================
542 * ANSI Color Code Generation Functions
543 * @{
544 */
545
564char *rgb_to_ansi_fg(int r, int g, int b);
565
584char *rgb_to_ansi_bg(int r, int g, int b);
585
610void rgb_to_ansi_8bit(int r, int g, int b, int *fg_code, int *bg_code);
611
613
614#ifdef _WIN32
615#pragma pack(pop)
616#endif
⚙️ Common definitions, error codes, macros, and types shared throughout the application
audio_visualization_source_t source
Definition fft.c:24
unsigned int height
Definition fft.c:23
unsigned int width
Definition fft.c:23
unsigned char uint8_t
Definition common.h:60
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:918
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:64
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:71
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.
SIMD-friendly storage for one RGB pixel. r, g, and b hold the color channels and padding keeps the la...
int w
Image width in pixels (must be > 0).
int h
Image height in pixels (must be > 0).
rgb_pixel_t * pixels
Pixel data array (width * height RGB pixels, row-major order).
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).