Fix allocates the max-sized buffer once and reuses it, no per-frame alloc/free

This commit is contained in:
Harshit-Dhanwalkar 2026-06-18 13:33:21 +05:30
parent e4051f2a71
commit dc843f3e59
2 changed files with 5 additions and 13 deletions

View file

@ -238,7 +238,7 @@ int main(int argc, char *argv[]) {
.dither = 0,
.threshold_val = 35,
.charset = NULL,
.render_mode = RENDER_BRAILLE,
.render_mode = RENDER_DOTS, // RENDER_BRAILLE,
.depth_pop = 0,
.depth_invert = 0,
};
@ -579,14 +579,6 @@ int main(int argc, char *argv[]) {
break;
}
size_t out_size = ascii_out_size_for_mode(subpixel_w, subpixel_h,
opts.color, opts.render_mode);
char *out_buf = malloc(out_size);
if (!out_buf) {
perror("Failed to allocate text output buffer");
break;
}
// Process frame mapping using dynamically calculated bounds
int len = grayscale_to_ascii(gray, rgb, cam.width, cam.height, subpixel_w,
subpixel_h, out_buf, out_size, &opts);
@ -600,8 +592,6 @@ int main(int argc, char *argv[]) {
selected, opts.color, &opts, &charsets);
}
free(out_buf);
if (webcam_requeue_buffer(&cam) < 0) {
perror("requeue_buffer");
break;