ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
video/image.h
Go to the documentation of this file.
1#pragma once
2
52#ifdef _WIN32
53#pragma pack(push, 1)
54#endif
55
56#include <stdio.h>
57#include <stdlib.h>
58#include <stdint.h>
59
60#include "../platform/abstraction.h"
61#include "../common.h"
62
63/* ============================================================================
64 * Data Structures
65 * ============================================================================
66 */
67
80typedef struct {
84} PACKED_ATTR rgb_pixel_t;
85
100typedef struct {
101 uint8_t r;
102 uint8_t g;
103 uint8_t b;
105} ALIGNED_ATTR(16) rgb_pixel_simd_t;
106
120
141typedef struct {
142 int w;
143 int h;
144 rgb_pixel_t *pixels;
146} image_t;
147
148/* ============================================================================
149 * Image Size Constants
150 * ============================================================================
151 */
152
164#define IMAGE_MAX_WIDTH 3840
165
177#define IMAGE_MAX_HEIGHT 2160
178
191#define IMAGE_MAX_PIXELS_SIZE (IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT * sizeof(rgb_pixel_t))
192
193/* ============================================================================
194 * Image Allocation and Management Functions
195 * @{
196 */
197
223image_t *image_new(size_t width, size_t height);
224
239void image_destroy(image_t *p);
240
267image_t *image_new_from_pool(size_t width, size_t height);
268
283void image_destroy_to_pool(image_t *image);
284
297void image_clear(image_t *p);
298
301/* ============================================================================
302 * ASCII Conversion Functions
303 * @{
304 */
305
323char *image_print(const image_t *p, const char *palette);
324
343char *image_print_color(const image_t *p, const char *palette);
344
345/* ============================================================================
346 * Capability-Aware ASCII Conversion Functions
347 * @{
348 */
349
350// Capability-aware image printing functions
351#include "../platform/terminal.h"
352
378char *image_print_with_capabilities(const image_t *image, const terminal_capabilities_t *caps, const char *palette,
379 const char luminance_palette[256]);
380
398char *image_print_256color(const image_t *image, const char *palette);
399
417char *image_print_16color(const image_t *image, const char *palette);
418
442char *image_print_16color_dithered(const image_t *image, const char *palette);
443
468char *image_print_16color_dithered_with_background(const image_t *image, bool use_background, const char *palette);
469
472/* ============================================================================
473 * Color Processing Functions
474 * @{
475 */
476
500void quantize_color(int *r, int *g, int *b, int levels);
501
524void precalc_rgb_palettes(const float red, const float green, const float blue);
525
528/* ============================================================================
529 * Image Resizing Functions
530 * @{
531 */
532
554void image_resize(const image_t *source, image_t *dest);
555
577void image_resize_interpolation(const image_t *source, image_t *dest);
578
581/* ============================================================================
582 * ANSI Color Code Generation Functions
583 * @{
584 */
585
604char *rgb_to_ansi_fg(int r, int g, int b);
605
624char *rgb_to_ansi_bg(int r, int g, int b);
625
650void rgb_to_ansi_8bit(int r, int g, int b, int *fg_code, int *bg_code);
651
654#ifdef _WIN32
655#pragma pack(pop)
656#endif
unsigned char uint8_t
Definition common.h:56
#define ALIGNED_ATTR(x)
Memory alignment attribute (POSIX: attribute((aligned)))
#define PACKED_ATTR
Packed structure attribute (POSIX: attribute((packed)))
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_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.
char * image_print(const image_t *p, const char *palette)
Print image as ASCII art (monochrome)
void image_destroy_to_pool(image_t *image)
Destroy an image allocated from buffer pool.
char * image_print_color(const image_t *p, const char *palette)
Print image as ASCII art with color.
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.
image_alloc_method_t
Pixel allocation method tracking.
char * image_print_16color(const image_t *image, const char *palette)
Print image using 16-color ANSI mode.
char * rgb_to_ansi_fg(int r, int g, int b)
Convert RGB to ANSI foreground color code.
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.
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.
image_t * image_new_from_pool(size_t width, size_t height)
Create a new image from buffer pool.
void image_destroy(image_t *p)
Destroy an image allocated with image_new()
Definition video/image.c:85
image_t * image_new(size_t width, size_t height)
Create a new image with standard allocation.
Definition video/image.c:36
@ IMAGE_ALLOC_POOL
Pixels allocated with buffer_pool_alloc()
@ IMAGE_ALLOC_SIMD
Pixels allocated with SAFE_MALLOC_SIMD()
uint8_t g
Green color component (0-255)
Definition video/image.h:82
uint8_t padding
Padding byte to align to 4-byte boundary (SIMD alignment)
uint8_t r
Red color component (0-255)
Definition video/image.h:81
uint8_t b
Blue color component (0-255)
Definition video/image.h:83
Image structure.
int w
Image width in pixels (must be > 0)
uint8_t alloc_method
Allocation method (image_alloc_method_t) for correct deallocation.
int h
Image height in pixels (must be > 0)
rgb_pixel_t * pixels
Pixel data array (width * height RGB pixels, row-major order)
Complete terminal capabilities structure.
Definition terminal.h:485