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

Go to the source code of this file.

Functions

int browser_capture_transform_required (void)
int browser_capture_transform_rgba (uint8_t *pixels, int width, int height)

Function Documentation

◆ browser_capture_transform_required()

int browser_capture_transform_required ( void )

Definition at line 9 of file web/common/capture.c.

9 {
10 return GET_OPTION(flip_x) || GET_OPTION(flip_y);
11}
#define GET_OPTION(field)
Safely get a specific option field (lock-free read).
Definition options.h:1336

References GET_OPTION.

Referenced by EMSCRIPTEN_BINDINGS().

◆ browser_capture_transform_rgba()

int browser_capture_transform_rgba ( uint8_t * pixels,
int width,
int height )

Browser-facing C interface implemented in capture.c.

Definition at line 13 of file web/common/capture.c.

13 {
14 if (!pixels || width <= 0 || height <= 0 || (size_t)width > SIZE_MAX / (size_t)height / 4) {
15 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid browser capture pixels or dimensions");
16 return -1;
17 }
18 bool flip_x = GET_OPTION(flip_x), flip_y = GET_OPTION(flip_y);
19 if (!flip_x && !flip_y)
20 return 0;
21 size_t count = (size_t)width * (size_t)height;
22 for (size_t i = 0; i < count; ++i) {
23 size_t x = i % (size_t)width, y = i / (size_t)width;
24 size_t target = (flip_y ? (size_t)height - 1 - y : y) * (size_t)width + (flip_x ? (size_t)width - 1 - x : x);
25 if (i >= target)
26 continue;
27 for (size_t channel = 0; channel < 4; ++channel) {
28 uint8_t value = pixels[i * 4 + channel];
29 pixels[i * 4 + channel] = pixels[target * 4 + channel];
30 pixels[target * 4 + channel] = value;
31 }
32 }
33 return 0;
34}
#define SET_ERRNO(code,...)
unsigned int height
Definition fft.c:23
unsigned int width
Definition fft.c:23
unsigned char uint8_t
Definition common.h:60
@ ERROR_INVALID_PARAM

References ERROR_INVALID_PARAM, GET_OPTION, height, SET_ERRNO, and width.

Referenced by MirrorFrameBinding::transform().