ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
avx2/color.c
Go to the documentation of this file.
1#if SIMD_SUPPORT_AVX2
2#define SIMD_CELL_AVX2 1
3#define SIMD_CELL_ISA avx2
4#include "../simd/quantize.c"
8
9char *render_ascii_cells_avx2(const image_t *image, const char *palette, ascii_color_t mode, bool background) {
10 ascii_frame_t frame;
11 if (ascii_frame_init(&frame, image, palette) != ASCIICHAT_OK)
12 return NULL;
13 for (int y = 0; y < image->h; ++y) {
14 const rgb_pixel_t *row = image->pixels + (size_t)y * frame.width;
15 simd_luminance_avx2((const uint8_t *)row, frame.luma, frame.width);
16 simd_pack_avx2((const uint8_t *)row, frame.packed, frame.width);
17 simd_lookup_avx2(frame.luma, frame.table, frame.glyph, frame.width);
18 if (mode == ASCII_COLOR_256 || mode == ASCII_COLOR_16)
19 simd_quantize_avx2(frame.packed, frame.index, frame.width, mode == ASCII_COLOR_16 ? 16 : 256);
20 ascii_frame_emit_row(&frame, mode, background, y + 1 < image->h, &simd_cells_avx2);
21 }
22 return ascii_frame_finish(&frame);
23}
24char *render_ascii_color_avx2(const image_t *image, bool background, bool indexed, const char *palette) {
25 return render_ascii_cells_avx2(image, palette, indexed ? ASCII_COLOR_256 : ASCII_COLOR_TRUE, background);
26}
27#endif
void simd_luminance_avx2(const uint8_t *rgb, uint8_t *out, size_t width)
AVX2-optimized ASCII rendering functions.
void simd_quantize_avx2(const uint32_t *, uint32_t *, size_t, unsigned)
void simd_pack_avx2(const uint8_t *, uint32_t *, size_t)
const simd_cells_t simd_cells_avx2
void simd_lookup_avx2(const uint8_t *, const uint32_t[64], uint32_t *, size_t)
unsigned char uint8_t
Definition common.h:60
@ ASCIICHAT_OK
Definition error_codes.h:46
char * render_ascii_cells_avx2(const image_t *, const char *, ascii_color_t, bool)
char * ascii_frame_finish(ascii_frame_t *frame)
void ascii_frame_emit_row(ascii_frame_t *frame, ascii_color_t mode, bool background, bool more_rows, const simd_cells_t *ops)
asciichat_error_t ascii_frame_init(ascii_frame_t *frame, const image_t *image, const char *palette)
When code needs to work with ascii frame, it keeps output, output_target, width, source_height here i...
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).
SIMD-optimized ASCII conversion interface.