ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
web/common/capture.c
Go to the documentation of this file.
1#include "capture.h"
2#include <ascii-chat/common.h>
3#include <emscripten.h>
4#include <stdint.h>
6
7/* Uploads carry pixels, not remote flip preferences. Resolve orientation from
8 * the same C option store used by local rendering, before any upload codec. */
10 return GET_OPTION(flip_x) || GET_OPTION(flip_y);
11}
12
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,...)
⚙️ Common definitions, error codes, macros, and types shared throughout the application
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
#define GET_OPTION(field)
Safely get a specific option field (lock-free read).
Definition options.h:1336
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
int browser_capture_transform_rgba(uint8_t *pixels, int width, int height)
int browser_capture_transform_required(void)