ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
test_pattern.h File Reference

Go to the source code of this file.

Typedefs

typedef struct test_pattern test_pattern_t

Functions

asciichat_error_t test_pattern_create (int width, int height, test_pattern_t **out)
asciichat_error_t test_pattern_resize (test_pattern_t *pattern, int width, int height)
asciichat_error_t test_pattern_render (test_pattern_t *pattern, int index, double time_ms, bool cadence)
const uint8_t * test_pattern_rgba (test_pattern_t *pattern)
image_t * test_pattern_image (test_pattern_t *pattern)
void test_pattern_destroy (test_pattern_t *pattern)

Typedef Documentation

◆ test_pattern_t

typedef struct test_pattern test_pattern_t

Definition at line 4 of file video/anim/test_pattern.h.

Function Documentation

◆ test_pattern_create()

asciichat_error_t test_pattern_create ( int width,
int height,
test_pattern_t ** out )

Independent, reusable RGB renderer. Time is elapsed milliseconds, not frame count.

Definition at line 109 of file video/anim/test_pattern.c.

109 {
110 if (!out)
111 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing test pattern output");
112 *out = NULL;
113 test_pattern_t *p = SAFE_CALLOC(1, sizeof(*p), test_pattern_t *);
115 if (result != ASCIICHAT_OK) {
117 return result;
118 }
119 *out = p;
120 return ASCIICHAT_OK;
121}
#define SET_ERRNO(code,...)
unsigned int height
Definition fft.c:23
unsigned int width
Definition fft.c:23
#define SAFE_CALLOC(count, size, cast)
Definition common.h:275
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
static bool size_t gotel_query_t * out
Definition queries.h:8
void test_pattern_destroy(test_pattern_t *p)
asciichat_error_t test_pattern_resize(test_pattern_t *p, int width, int height)
struct test_pattern test_pattern_t

References ASCIICHAT_OK, ERROR_INVALID_PARAM, height, out, SAFE_CALLOC, SET_ERRNO, test_pattern_destroy(), test_pattern_resize(), and width.

Referenced by TestPatternBinding::TestPatternBinding().

◆ test_pattern_destroy()

void test_pattern_destroy ( test_pattern_t * pattern)

Definition at line 122 of file video/anim/test_pattern.c.

122 {
123 if (!p)
124 return;
125 if (p->image)
126 image_destroy(p->image);
127 SAFE_FREE(p->rgba);
128 SAFE_FREE(p);
129}
#define SAFE_FREE(ptr)
Definition common.h:377
void image_destroy(image_t *image)
Destroy an image allocated with image_new().

References test_pattern::image, image_destroy(), test_pattern::rgba, and SAFE_FREE.

Referenced by media_source_destroy(), test_pattern_create(), and TestPatternBinding::~TestPatternBinding().

◆ test_pattern_image()

image_t * test_pattern_image ( test_pattern_t * pattern)

Definition at line 130 of file video/anim/test_pattern.c.

130 {
131 return p ? p->image : NULL;
132}

References test_pattern::image.

◆ test_pattern_render()

asciichat_error_t test_pattern_render ( test_pattern_t * pattern,
int index,
double time_ms,
bool cadence )

Definition at line 149 of file video/anim/test_pattern.c.

149 {
150 animation_sample_t sample;
151 animation_config_t config = {.type = ANIMATION_TEST_PATTERN, .fps = 60, .speed = 1};
152 asciichat_error_t err = animation_sample_at(config, time_ms / 1000.0, &sample);
153 if (err != ASCIICHAT_OK)
154 return err;
156 .test_pattern = {.context = p, .index = index, .cadence = cadence}};
157 return animation_apply(&sample, &target);
158}
static bool size_t index
Definition queries.h:8
For animation config, this is the live record that ties type, fps, speed, hidden_policy together....
asciichat_error_t animation_apply(const animation_sample_t *s, animation_target_t *t)
asciichat_error_t animation_sample_at(animation_config_t config, double seconds, animation_sample_t *out)
@ ANIMATION_TEST_PATTERN
@ ANIMATION_TARGET_TEST_PATTERN

References animation_apply(), animation_sample_at(), ANIMATION_TARGET_TEST_PATTERN, ANIMATION_TEST_PATTERN, ASCIICHAT_OK, and index.

Referenced by TestPatternBinding::render().

◆ test_pattern_resize()

asciichat_error_t test_pattern_resize ( test_pattern_t * pattern,
int width,
int height )

Definition at line 65 of file video/anim/test_pattern.c.

65 {
66 if (!p || width < 1 || height < 1)
67 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid test pattern dimensions");
68 if (p->image && p->image->w == width && p->image->h == height)
69 return ASCIICHAT_OK;
70 image_t *next = image_new(width, height);
71 if (!next)
72 return SET_ERRNO(ERROR_MEMORY, "Test pattern image allocation failed");
73 if (p->image)
74 image_destroy(p->image);
75 p->image = next;
76 SAFE_FREE(p->rgba);
77 return ASCIICHAT_OK;
78}
@ ERROR_MEMORY
Definition error_codes.h:51
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...

References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_MEMORY, image_t::h, height, test_pattern::image, image_destroy(), image_new(), test_pattern::rgba, SAFE_FREE, SET_ERRNO, image_t::w, and width.

Referenced by TestPatternBinding::render(), and test_pattern_create().

◆ test_pattern_rgba()

const uint8_t * test_pattern_rgba ( test_pattern_t * pattern)

Reusable RGBA view for browser upload; invalidated by resize/destroy.

Definition at line 134 of file video/anim/test_pattern.c.

134 {
135 if (!p || !p->image)
136 return NULL;
137 size_t count = (size_t)p->image->w * p->image->h;
138 if (!p->rgba)
139 p->rgba = SAFE_MALLOC(count * 4, uint8_t *);
140 for (size_t i = 0; i < count; i++) {
141 p->rgba[i * 4] = p->image->pixels[i].r;
142 p->rgba[i * 4 + 1] = p->image->pixels[i].g;
143 p->rgba[i * 4 + 2] = p->image->pixels[i].b;
144 p->rgba[i * 4 + 3] = 255;
145 }
146 return p->rgba;
147}
#define SAFE_MALLOC(size, cast)
Definition common.h:265
unsigned char uint8_t
Definition common.h:60

References rgb_pixel_t::b, rgb_pixel_t::g, image_t::h, test_pattern::image, image_t::pixels, rgb_pixel_t::r, test_pattern::rgba, SAFE_MALLOC, and image_t::w.

Referenced by TestPatternBinding::render().