diff --git a/Makefile.am b/Makefile.am index 62be1784f..0904c7993 100644 --- a/Makefile.am +++ b/Makefile.am @@ -249,7 +249,7 @@ endif # Enable image support. if ENABLE_IMAGES -dist_tmux_SOURCES += image.c image-sixel.c image-kitty.c image-ascii.c +dist_tmux_SOURCES += image.c image-sixel.c image-kitty.c endif # Add bits for fuzzing if enabled. diff --git a/image-ascii.c b/image-ascii.c deleted file mode 100644 index d1598a26f..000000000 --- a/image-ascii.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2026 Michael Grant - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include - -#include "tmux.h" - -void -image_get_text_cell(__unused struct tty *tty, struct image *im, u_int x, - u_int y, const struct grid_cell *gc, struct grid_cell *out, - __unused const struct tty_style_ctx *style_ctx) -{ - static const char ramp[] = " .:-=+*#%@"; - const struct image_cell *cell; - u_int level = 0; - - memcpy(out, gc, sizeof *out); - cell = image_get_cell(im, x, y); - if (cell != NULL) - level = cell->whole.brightness * (sizeof ramp - 2) / 255; - utf8_set(&out->data, ramp[level]); - out->flags &= ~GRID_FLAG_IMAGE; -} diff --git a/image.c b/image.c index 46da4e789..5f41f7677 100644 --- a/image.c +++ b/image.c @@ -42,8 +42,8 @@ struct image_backend { void (*geometry_changed)(struct tty *); }; -static const struct image_backend image_backend_ascii = { - "ascii", IMAGE_BACKEND_SCROLLS, NULL, NULL, NULL +static const struct image_backend image_backend_fallback = { + "fallback", IMAGE_BACKEND_SCROLLS, NULL, NULL, NULL }; static const struct image_backend image_backend_kitty = { "kitty", IMAGE_BACKEND_GRAPHICAL|IMAGE_BACKEND_SCROLLS, @@ -62,7 +62,7 @@ image_tty_find_backend(struct tty *tty) if (tty->term != NULL && tty->term->flags & TERM_SIXEL && tty->xpixel != 0 && tty->ypixel != 0) return (&image_backend_sixel); - return (&image_backend_ascii); + return (&image_backend_fallback); } void @@ -328,6 +328,24 @@ image_get_cell(struct image *im, u_int x, u_int y) return (&im->cells[(size_t)y * im->sx + x]); } +/* Character-cell fallback for clients without a graphical image protocol. */ +void +image_get_fallback_cell(__unused struct tty *tty, struct image *im, u_int x, + u_int y, const struct grid_cell *gc, struct grid_cell *out, + __unused const struct tty_style_ctx *style_ctx) +{ + static const char ramp[] = " .:-=+*#%@"; + const struct image_cell *cell; + u_int level = 0; + + memcpy(out, gc, sizeof *out); + cell = image_get_cell(im, x, y); + if (cell != NULL) + level = cell->whole.brightness * (sizeof ramp - 2) / 255; + utf8_set(&out->data, ramp[level]); + out->flags &= ~GRID_FLAG_IMAGE; +} + void image_set_cell(struct grid_cell *gc, struct image *im, u_int x, u_int y) { diff --git a/tmux.h b/tmux.h index 4bcfc0cbe..6724838a0 100644 --- a/tmux.h +++ b/tmux.h @@ -4298,7 +4298,7 @@ void image_tty_free(struct tty *, int); void image_draw_line(struct tty *, struct screen *, u_int, u_int, u_int, u_int, u_int, const struct tty_style_ctx *); const struct image_cell *image_get_cell(struct image *, u_int, u_int); -void image_get_text_cell(struct tty *, struct image *, u_int, +void image_get_fallback_cell(struct tty *, struct image *, u_int, u_int, const struct grid_cell *, struct grid_cell *, const struct tty_style_ctx *); void image_clear(struct screen_write_ctx *, u_int); diff --git a/tty-draw.c b/tty-draw.c index 51d2d7dcd..6e815cb54 100644 --- a/tty-draw.c +++ b/tty-draw.c @@ -273,7 +273,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, ~GRID_FLAG_IMAGE; skip = 1; } else { - image_get_text_cell(tty, im, + image_get_fallback_cell(tty, im, gc.image_x, gc.image_y, &gc, &image_gc, style_ctx); } diff --git a/tty.c b/tty.c index 329f6ab37..afb170aa5 100644 --- a/tty.c +++ b/tty.c @@ -2159,7 +2159,7 @@ tty_cell(struct tty *tty, const struct grid_cell *gc, if (image_tty_is_graphical(tty)) return; im = image_find(gc->image_id); - image_get_text_cell(tty, im, gc->image_x, gc->image_y, gc, + image_get_fallback_cell(tty, im, gc->image_x, gc->image_y, gc, &image_gc, style_ctx); gc = &image_gc; }