From a823f72e0ed21d5eb2d36b86affd79dec5396ad1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Feb 2026 10:11:13 +0530 Subject: [PATCH] Use the new C code --- kitty/fonts.c | 8 +++----- kitty/print-graphics.h | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index a1140b337..5ec816b67 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -13,6 +13,7 @@ #include "char-props.h" #include "decorations.h" #include "glyph-cache.h" +#include "print-graphics.h" #define MISSING_GLYPH 1 #define MAX_NUM_EXTRA_GLYPHS_PUA 4u @@ -136,11 +137,7 @@ static void initialize_font_group(FontGroup *fg); static void display_rgba_data(const pixel *b, unsigned width, unsigned height) { - RAII_PyObject(m, PyImport_ImportModule("kitty.fonts.render")); - RAII_PyObject(f, PyObject_GetAttrString(m, "show")); - RAII_PyObject(data, PyMemoryView_FromMemory((char*)b, (Py_ssize_t)width * height * sizeof(b[0]), PyBUF_READ)); - RAII_PyObject(ret, PyObject_CallFunction(f, "OII", data, width, height)); - if (ret == NULL) PyErr_Print(); + print_rgba32(b, width, height); } static void @@ -1224,6 +1221,7 @@ render_group( scaled_canvas_width = canvas_width; } else memcpy(fg->canvas.buf, canvas, sizeof(pixel) * canvas_width * scaled_metrics.cell_height); canvas = fg->canvas.buf; + if (0) { print_rgba32(fg->canvas.buf, canvas_width, unscaled_metrics.cell_height); printf("\n"); } } apply_horizontal_alignment( canvas, rf, center_glyph, ri, canvas_width, diff --git a/kitty/print-graphics.h b/kitty/print-graphics.h index cf763088f..06e6a9ec3 100644 --- a/kitty/print-graphics.h +++ b/kitty/print-graphics.h @@ -10,15 +10,14 @@ #include #include "base64.h" -// Write the kitty graphics protocol escape codes for a 32-bit RGBA raster image to fp. +// Write the kitty graphics protocol escape codes for a 32-bit RGBA image to fp. static inline void fprint_rgba32(FILE *fp, const uint32_t *rgba, uint32_t width, uint32_t height) { const uint8_t *data = (const uint8_t *)rgba; - const size_t total_bytes = (size_t)width * height * 4; - unsigned char b64_buf[4096]; + const size_t total_bytes = (size_t)width * height * sizeof(uint32_t); + uint8_t b64_buf[4096]; size_t offset = 0; bool first = true; - while (offset < total_bytes) { size_t chunk = total_bytes - offset; if (chunk > 3072) chunk = 3072;