ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
ascii.c File Reference

Go to the source code of this file.

Macros

#define ASCII_RESIZE_WORKSPACE_POOL_SIZE   4

Functions

asciichat_error_t ascii_write_init (int fd, bool reset_terminal)
 Initialize ASCII write subsystem.
char * ascii_convert (image_t *original, const ssize_t width, const ssize_t height, const bool color, const bool _aspect_ratio, const bool stretch, const char *palette_chars, const char luminance_palette[ASCII_LUMINANCE_LEVELS])
 Convert image to ASCII art.
char * ascii_convert_with_capabilities (image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars)
 Convert image to ASCII art with terminal capability awareness.
char * ascii_convert_with_capabilities_fit (image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain)
char * ascii_convert_with_capabilities_workspace (image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain, image_t **workspace)
char * ascii_convert_with_buffers (image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain, image_t **workspace, outbuf_t *output)
char * ascii_convert_with_buffers_stabilized (image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain, image_t **workspace, outbuf_t *output, ascii_stabilizer_t *stabilizer)
asciichat_error_t ascii_write (const char *frame)
 Write ASCII frame to terminal.
void ascii_write_destroy (int fd, bool reset_terminal)
 Destroy ASCII write subsystem.
char * ascii_pad_frame_width (const char *frame, size_t pad_left)
 Add leading spaces (left-padding) to each line of a frame.
asciichat_error_t ascii_grid_layout (int source_count, int width, int height, int *grid_cols, int *grid_rows)
char * ascii_create_grid (ascii_frame_source_t *sources, int source_count, int width, int height, size_t *out_size)
 Create a grid layout from multiple ASCII frames.
char * ascii_pad_frame_height (const char *frame, size_t pad_top)
 Add blank lines (vertical padding) to center a frame vertically.
char * image_print_with_capabilities (const image_t *image, const terminal_capabilities_t *caps, const char *palette)
 Convert image to ASCII art with terminal capabilities.

Macro Definition Documentation

◆ ASCII_RESIZE_WORKSPACE_POOL_SIZE

#define ASCII_RESIZE_WORKSPACE_POOL_SIZE   4

Definition at line 58 of file ascii.c.

Function Documentation

◆ ascii_convert_with_buffers()

char * ascii_convert_with_buffers ( image_t * original,
const ssize_t width,
const ssize_t height,
const terminal_capabilities_t * caps,
const bool use_aspect_ratio,
const bool stretch,
const char * palette_chars,
const bool contain,
image_t ** workspace,
outbuf_t * output )

Borrow output from the caller-owned buffer until its next conversion or release. Both workspaces require a single owner; passing NULL output keeps owned-output semantics.

Definition at line 277 of file ascii.c.

278 {
279 return ascii_convert_with_buffers_stabilized(original, width, height, caps, use_aspect_ratio, stretch, palette_chars, contain, workspace, output, NULL);
280}
char * ascii_convert_with_buffers_stabilized(image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain, image_t **workspace, outbuf_t *output, ascii_stabilizer_t *stabilizer)
Definition ascii.c:282
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24

References ascii_convert_with_buffers_stabilized(), height, and width.

Referenced by ascii_convert_with_capabilities_workspace().

◆ ascii_convert_with_buffers_stabilized()

char * ascii_convert_with_buffers_stabilized ( image_t * original,
const ssize_t width,
const ssize_t height,
const terminal_capabilities_t * caps,
const bool use_aspect_ratio,
const bool stretch,
const char * palette_chars,
const bool contain,
image_t ** workspace,
outbuf_t * output,
ascii_stabilizer_t * stabilizer )

Convert with a history owned by this stream; reset it when the source changes.

Definition at line 282 of file ascii.c.

283 {
284 if (original == NULL || caps == NULL) {
285 log_error("Invalid parameters for ascii_convert_with_capabilities");
286 return NULL;
287 }
288
289 // Validate original image dimensions to detect corruption
290 if (original->w <= 0 || original->w > 10000 || original->h <= 0 || original->h > 10000) {
291 log_error("Invalid original image dimensions detected: w=%d, h=%d (likely corrupted)", original->w, original->h);
292 return NULL;
293 }
294
295 if (original->pixels == NULL) {
296 log_error("Original image pixels pointer is NULL");
297 return NULL;
298 }
299
300 // Start with the target dimensions requested by the user.
301 ssize_t resized_width = width;
302 ssize_t resized_height = height;
303
304 // Both contain and cover produce a complete viewport, including any black bars.
305
306 // Preserve an 8x8 sample grid for each glyph in the experimental renderer.
307 bool explicit_palette = caps->palette_explicit;
308 if (caps->text_renderer == ASCII_RENDERER_GLYPH && explicit_palette && !ascii_render_palette_supported(ASCII_RENDERER_GLYPH, palette_chars)) {
309 SET_ERRNO(ERROR_INVALID_PARAM, "Glyph palette contains characters without glyph masks");
310 return NULL;
311 }
312 bool glyph_match = caps->text_renderer == ASCII_RENDERER_GLYPH && caps->render_mode != RENDER_MODE_HALF_BLOCK && resized_width > 0 && resized_height > 0 && resized_width <= IMAGE_MAX_WIDTH / 8 &&
313 resized_height <= IMAGE_MAX_HEIGHT / 8;
314 if (glyph_match) {
315 resized_width *= 8;
316 resized_height *= 8;
317 }
318
319 // Half-block mode doubles height for 2x vertical resolution (AFTER aspect ratio)
320 if (caps->render_mode == RENDER_MODE_HALF_BLOCK) {
321 resized_height = resized_height * 2;
322 }
323
324 // Fitting is performed inside the pixel viewport, so ANSI padding is not needed.
325 size_t pad_width = 0;
326 size_t pad_height = 0;
327
328 // Resize the captured frame to the aspect-correct dimensions
329 if (resized_width <= 0 || resized_height <= 0) {
330 log_error("Invalid dimensions for resize: width=%zd, height=%zd", resized_width, resized_height);
331 return NULL;
332 }
333
334 // Validate dimensions fit in image_t's int fields before casting
335 if (resized_width > INT_MAX || resized_height > INT_MAX) {
336 log_error("Dimensions exceed INT_MAX: width=%zd, height=%zd", resized_width, resized_height);
337 return NULL;
338 }
339
340 // PROFILING: Time image allocation and resize
341 uint64_t prof_alloc_start_ns = time_get_ns();
342
343 if (workspace && *workspace && ((*workspace)->w != resized_width || (*workspace)->h != resized_height)) {
344 image_destroy(*workspace);
345 *workspace = NULL;
346 }
347 image_t *resized = workspace ? *workspace : NULL;
348 if (!resized)
349 resized = image_new((size_t)resized_width, (size_t)resized_height);
350 if (workspace)
351 *workspace = resized;
352 if (!resized) {
353 log_error("Failed to allocate resized image");
354 return NULL;
355 }
356
357 image_clear(resized);
358
359 uint64_t prof_alloc_end_ns = time_get_ns();
360
361 uint64_t prof_resize_start_ns = prof_alloc_end_ns;
362
363 if (use_aspect_ratio && !stretch) {
364 // Fit using terminal cells; half-block pixel height is only the sampling resolution.
365 if (contain)
366 image_resize_contain(original, resized, width, height);
367 else
368 image_resize_cover(original, resized, width, height);
369 } else {
370 image_resize(original, resized);
371 }
372
373 uint64_t prof_resize_end_ns = time_get_ns();
374
375 // Check original image before resize (validate dimensions to prevent integer overflow)
376 int orig_black = 0, orig_total = 0;
377 if (original->w > 0 && original->w <= 10000 && original->h > 0 && original->h <= 10000) {
378 int64_t total_pixels = (int64_t)original->w * original->h;
379 int sample_size = (total_pixels < 1000) ? (int)total_pixels : 1000;
380 for (int i = 0; i < sample_size; i++) {
381 rgb_pixel_t p = original->pixels[i];
382 orig_total++;
383 if (p.r == 0 && p.g == 0 && p.b == 0)
384 orig_black++;
385 }
386 log_debug_every(5 * NS_PER_SEC_INT, ">>> ORIGINAL image: %d/%d pixels are black (%.1f%%), first pixel=RGB(%d,%d,%d)\n", orig_black, orig_total,
387 orig_total > 0 ? 100.0 * orig_black / orig_total : 0, original->pixels[0].r, original->pixels[0].g, original->pixels[0].b);
388 } else {
389 log_warn("Skipping debug check: corrupted image dimensions (w=%d, h=%d)", original->w, original->h);
390 }
391
392 // PROFILING: Time ASCII print
393 uint64_t prof_print_start_ns = prof_resize_end_ns;
394
395 // DEBUG: Log dimensions going to renderer
396 log_debug_every(10 * US_PER_SEC_INT, "original=%dx%d, requested=%zdx%zd, resized=%dx%d, pad=%zux%zu (mode=%d)", original->w, original->h, width, height, resized->w, resized->h, pad_width,
397 pad_height, caps->render_mode);
398
399 // Check if image is all black
400 int black_pixels = 0, total_pixels = 0;
401 for (int i = 0; i < resized->w * resized->h && i < 1000; i++) {
402 rgb_pixel_t p = resized->pixels[i];
403 total_pixels++;
404 if (p.r == 0 && p.g == 0 && p.b == 0)
405 black_pixels++;
406 }
407 log_debug_every(5 * NS_PER_SEC_INT, ">>> Resized image check: %d/%d pixels are black (%.1f%%), first pixel=RGB(%d,%d,%d)\n", black_pixels, total_pixels,
408 total_pixels > 0 ? 100.0 * black_pixels / total_pixels : 0, resized->pixels[0].r, resized->pixels[0].g, resized->pixels[0].b);
409
410 // Apply the target client's filter after resizing, so it is scoped to this
411 // client and never mutates the shared source frame.
412 if (caps->color_filter != COLOR_FILTER_NONE) {
413 const float time_seconds = (float)time_get_ns() / (float)NS_PER_SEC_INT;
414 if (apply_color_filter((uint8_t *)resized->pixels, (uint32_t)resized->w, (uint32_t)resized->h, (uint32_t)(resized->w * sizeof(rgb_pixel_t)), caps->color_filter, time_seconds) != 0) {
415 log_warn("Failed to apply client color filter %d", caps->color_filter);
416 }
417 }
418
419 // Use the capability-aware image printing function with client's palette
420 // History belongs to this stream and is scoped to the current thread's conversion.
421 ascii_stabilizer_t *active_stabilizer = NULL;
422 if (stabilizer) {
423 uint64_t configuration = 1469598103934665603ULL;
424 const unsigned values[] = {(unsigned)caps->text_renderer, (unsigned)caps->color_level, (unsigned)caps->render_mode, (unsigned)caps->color_filter, (unsigned)explicit_palette,
425 (unsigned)use_aspect_ratio, (unsigned)stretch, (unsigned)contain, (unsigned)original->w, (unsigned)original->h};
426 for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
427 configuration ^= values[i];
428 // FNV multiplication intentionally wraps modulo 2^64.
429 (void)__builtin_mul_overflow(configuration, 1099511628211ULL, &configuration);
430 }
431 if (palette_chars) {
432 for (const unsigned char *p = (const unsigned char *)palette_chars; *p; ++p) {
433 configuration ^= *p;
434 (void)__builtin_mul_overflow(configuration, 1099511628211ULL, &configuration);
435 }
436 }
437 size_t history_height = (size_t)height * (caps->render_mode == RENDER_MODE_HALF_BLOCK ? 2u : 1u);
438 if (ascii_stabilizer_prepare(stabilizer, (size_t)width, history_height, configuration) == ASCIICHAT_OK) {
439 uint64_t now = time_get_ns();
440 stabilizer->elapsed_ns =
441 stabilizer->fixed_step_ns ? stabilizer->fixed_step_ns : (stabilizer->last_timestamp_ns && now >= stabilizer->last_timestamp_ns ? now - stabilizer->last_timestamp_ns : UINT64_MAX);
442 stabilizer->last_timestamp_ns = now;
443 active_stabilizer = stabilizer;
444 }
445 }
446 ascii_stabilizer_t *previous_stabilizer = ascii_stabilizer_set_target(active_stabilizer);
447 outbuf_t *previous_output = ascii_render_set_output_target(output);
448 ascii_color_t glyph_color = caps->color_level == TERM_COLOR_TRUECOLOR ? ASCII_COLOR_TRUE
449 : caps->color_level == TERM_COLOR_256 ? ASCII_COLOR_256
450 : caps->color_level == TERM_COLOR_16 ? ASCII_COLOR_16
452 const ascii_render_options_t glyph_options = {.kind = ASCII_RENDERER_GLYPH,
453 .color = glyph_color,
454 .palette = explicit_palette ? palette_chars : NULL,
455 .backend = simd_cells_backend(),
456 .background = caps->render_mode == RENDER_MODE_BACKGROUND};
457 char *ascii = glyph_match ? ascii_render_image(resized, &glyph_options) : image_print_with_capabilities(resized, caps, palette_chars);
458 ascii_render_set_output_target(previous_output);
459 ascii_stabilizer_set_target(previous_stabilizer);
460
461 uint64_t prof_print_end_ns = time_get_ns();
462
463 uint64_t alloc_time_us = time_ns_to_us(time_elapsed_ns(prof_alloc_start_ns, prof_alloc_end_ns));
464 uint64_t resize_time_us = time_ns_to_us(time_elapsed_ns(prof_resize_start_ns, prof_resize_end_ns));
465 uint64_t print_time_us = time_ns_to_us(time_elapsed_ns(prof_print_start_ns, prof_print_end_ns));
466
467 // PROFILING: Time padding
468 uint64_t prof_pad_start_ns = time_get_ns();
469
470 if (!ascii) {
471 log_error("Failed to convert image to ASCII using terminal capabilities");
472 if (!workspace)
473 image_destroy(resized);
474 return NULL;
475 }
476
477 size_t ascii_len = strlen(ascii);
478 if (ascii_len == 0) {
479 log_error("Capability-aware ASCII conversion returned empty string (resized dimensions: %dx%d)", resized->w, resized->h);
480 if (!output)
481 SAFE_FREE(ascii);
482 if (!workspace)
483 image_destroy(resized);
484 return NULL;
485 }
486
487 // Pixel fitting already produced the complete viewport. Return that buffer
488 // directly instead of allocating two identical copies for zero padding.
489 char *ascii_padded = ascii;
490
491 uint64_t prof_pad_end_ns = time_get_ns();
492
493 uint64_t pad_time_ns = time_elapsed_ns(prof_pad_start_ns, prof_pad_end_ns);
494 log_debug_every(US_PER_SEC_INT, "ASCII_STAGE: alloc_ms=%.3f resize_ms=%.3f glyph_ms=%.3f padding_ms=%.3f bytes=%zu", (double)alloc_time_us / 1000, (double)resize_time_us / 1000,
495 (double)print_time_us / 1000, (double)pad_time_ns / NS_PER_MS_INT, ascii_len);
496
497 if (!workspace)
498 image_destroy(resized);
499
500 return ascii_padded;
501}
#define SET_ERRNO(code,...)
const simd_cells_t * simd_cells_backend(void)
Definition cells.c:61
unsigned int uint32_t
#define SAFE_FREE(ptr)
unsigned long long uint64_t
unsigned char uint8_t
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define NS_PER_SEC_INT
Definition time.h:173
#define NS_PER_MS_INT
Definition time.h:172
uint64_t time_elapsed_ns(uint64_t start_ns, uint64_t end_ns)
Calculate elapsed time with wraparound safety.
Definition time.c:117
#define US_PER_SEC_INT
Definition time.h:177
char * image_print_with_capabilities(const image_t *image, const terminal_capabilities_t *caps, const char *palette)
Convert image to ASCII art with terminal capabilities.
Definition ascii.c:884
int apply_color_filter(uint8_t *pixels, uint32_t width, uint32_t height, uint32_t stride, color_filter_t filter, float time)
Apply color filter to entire image in-place.
#define IMAGE_MAX_WIDTH
An owned RGB image with dimensions and row-major pixel storage.
#define IMAGE_MAX_HEIGHT
Maximum image height (4K resolution).
void image_clear(image_t *p)
Clear image (set all pixels to black).
void image_resize(const image_t *s, image_t *d)
Resize image using nearest-neighbor interpolation.
void image_destroy(image_t *image)
Destroy an image allocated with image_new().
image_t * image_new(size_t width, size_t height)
Create a new image with standard allocation.
bool ascii_render_palette_supported(ascii_renderer_t kind, const char *palette)
char * ascii_render_image(const image_t *image, const ascii_render_options_t *options)
#define ascii_render_set_output_target
#define ascii_stabilizer_prepare
#define ascii_stabilizer_set_target
#define log_debug_every(interval_us, fmt,...)
Rate-limited DEBUG logging.
Definition log/log.h:743
uint64_t fixed_step_ns
Definition stabilize.h:30
uint64_t last_timestamp_ns
Definition stabilize.h:29
uint64_t elapsed_ns
Definition stabilize.h:28
int h
Image height in pixels (must be > 0).
rgb_pixel_t * pixels
Pixel data array (width * height RGB pixels, row-major order).
int w
Image width in pixels (must be > 0).
Dynamic output buffer (auto-expanding).
uint8_t b
Blue color component (0-255).
uint8_t g
Green color component (0-255).
uint8_t r
Red color component (0-255).

References apply_color_filter(), ASCII_COLOR_16, ASCII_COLOR_256, ASCII_COLOR_NONE, ASCII_COLOR_TRUE, ascii_render_image(), ascii_render_palette_supported(), ascii_render_set_output_target, ASCII_RENDERER_GLYPH, ascii_stabilizer_prepare, ascii_stabilizer_set_target, ASCIICHAT_OK, rgb_pixel_t::b, ascii_stabilizer_t::elapsed_ns, ERROR_INVALID_PARAM, ascii_stabilizer_t::fixed_step_ns, rgb_pixel_t::g, image::h, height, image_clear(), image_destroy(), IMAGE_MAX_HEIGHT, IMAGE_MAX_WIDTH, image_new(), image_print_with_capabilities(), image_resize(), ascii_stabilizer_t::last_timestamp_ns, log_debug_every, log_error, log_warn, NS_PER_MS_INT, NS_PER_SEC_INT, image::pixels, rgb_pixel_t::r, SAFE_FREE, SET_ERRNO, simd_cells_backend(), time_elapsed_ns(), US_PER_SEC_INT, image::w, and width.

Referenced by ascii_convert_with_buffers(), and mirror_convert_frame().

◆ ascii_convert_with_capabilities_fit()

char * ascii_convert_with_capabilities_fit ( image_t * original,
const ssize_t width,
const ssize_t height,
const terminal_capabilities_t * caps,
const bool use_aspect_ratio,
const bool stretch,
const char * palette_chars,
const bool contain )

Convert with explicit contain (true) or cover (false) viewport fitting.

Definition at line 265 of file ascii.c.

266 {
267
268 return ascii_convert_with_capabilities_workspace(original, width, height, caps, use_aspect_ratio, stretch, palette_chars, contain, NULL);
269}
char * ascii_convert_with_capabilities_workspace(image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain, image_t **workspace)
Definition ascii.c:271

References ascii_convert_with_capabilities_workspace(), height, and width.

Referenced by ascii_convert_with_capabilities().

◆ ascii_convert_with_capabilities_workspace()

char * ascii_convert_with_capabilities_workspace ( image_t * original,
const ssize_t width,
const ssize_t height,
const terminal_capabilities_t * caps,
const bool use_aspect_ratio,
const bool stretch,
const char * palette_chars,
const bool contain,
image_t ** workspace )

Caller owns the reusable resize image; calls using it must be serialized.

Definition at line 271 of file ascii.c.

272 {
273
274 return ascii_convert_with_buffers(original, width, height, caps, use_aspect_ratio, stretch, palette_chars, contain, workspace, NULL);
275}
char * ascii_convert_with_buffers(image_t *original, const ssize_t width, const ssize_t height, const terminal_capabilities_t *caps, const bool use_aspect_ratio, const bool stretch, const char *palette_chars, const bool contain, image_t **workspace, outbuf_t *output)
Definition ascii.c:277

References ascii_convert_with_buffers(), height, and width.

Referenced by ascii_convert_with_capabilities_fit().

◆ ascii_grid_layout()

asciichat_error_t ascii_grid_layout ( int source_count,
int width,
int height,
int * grid_cols,
int * grid_rows )

Calculate the shared grid layout before sizing source video tiles.

Definition at line 625 of file ascii.c.

625 {
626 if (source_count <= 0 || width <= 0 || height <= 0 || !grid_cols || !grid_rows)
627 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid grid dimensions");
628 // Multiple sources: create grid layout
629 // Calculate grid dimensions that maximize the use of terminal space
630 // Character aspect ratio: terminal chars are typically ~2x taller than wide
631 float char_aspect = 2.0f;
632
633 float best_score = -1.0f;
634 int best_cols = 1;
635 int best_rows = source_count;
636
637 // Try all possible grid configurations
638 for (int test_cols = 1; test_cols <= source_count; test_cols++) {
639 int test_rows = (int)ceil((double)source_count / test_cols);
640
641 // Skip configurations with too many empty cells
642 int empty_cells = (test_cols * test_rows) - source_count;
643 if (empty_cells > source_count / 2)
644 continue; // Don't waste more than 50% space
645
646 // Calculate the size each cell would have
647 int cell_width = (width - (test_cols - 1)) / test_cols; // -1 per separator
648 int cell_height = (height - (test_rows - 1)) / test_rows; // -1 per separator
649
650 // Skip if cells would be too small
651 if (cell_width < 10 || cell_height < 3)
652 continue;
653
654 // Calculate the aspect ratio of each cell (accounting for char aspect)
655 float cell_aspect = ((float)cell_width / (float)cell_height) / char_aspect;
656
657 // Score based on how close to square (1:1) each video cell would be
658 // This naturally adapts to any terminal size
659 float aspect_score = 1.0f - fabsf(logf(cell_aspect)); // log makes it symmetric around 1
660 if (aspect_score < 0)
661 aspect_score = 0;
662
663 // Bonus for better space utilization
664 float utilization = (float)source_count / (float)(test_cols * test_rows);
665
666 // For 2 clients specifically, heavily weight the aspect score
667 // This makes 2 clients naturally go horizontal on wide terminals and vertical on tall ones
668 float total_score;
669 if (source_count == 2) {
670 // For 2 clients, we want the layout that gives the most square-ish cells
671 total_score = aspect_score * 0.9f + utilization * 0.1f;
672 } else {
673 // For 3+ clients, balance aspect ratio with space utilization
674 total_score = aspect_score * 0.7f + utilization * 0.3f;
675 }
676
677 // Small bonus for simpler grids (prefer 2x2 over 3x1, etc.)
678 if (test_cols == test_rows) {
679 total_score += 0.05f; // Slight preference for square grids
680 }
681
682 if (total_score > best_score) {
683 best_score = total_score;
684 best_cols = test_cols;
685 best_rows = test_rows;
686 }
687 }
688
689 *grid_cols = best_cols;
690 *grid_rows = best_rows;
691 return ASCIICHAT_OK;
692}

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

Referenced by ascii_create_grid().