From 1faddeb40219f79b158cf427b1ad63d1fccbfaab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 7 Jul 2018 08:04:11 +0530 Subject: [PATCH] Also return image dimensions when loading PNG --- kitty/png-reader.c | 2 +- kitty_tests/graphics.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kitty/png-reader.c b/kitty/png-reader.c index be1fa32e0..e534dd8d7 100644 --- a/kitty/png-reader.c +++ b/kitty/png-reader.c @@ -105,7 +105,7 @@ load_png_data(PyObject *self UNUSED, PyObject *args) { inflate_png_inner(&d, (const uint8_t*)data, sz); PyObject *ans = NULL; if (d.ok && !PyErr_Occurred()) { - ans = PyBytes_FromStringAndSize((const char*)d.decompressed, d.sz); + ans = Py_BuildValue("y#ii", d.decompressed, (int)d.sz, d.width, d.height); } else { if (!PyErr_Occurred()) PyErr_SetString(PyExc_ValueError, "Unknown error while reading PNG data"); } diff --git a/kitty_tests/graphics.py b/kitty_tests/graphics.py index 5827d0e12..741ce487f 100644 --- a/kitty_tests/graphics.py +++ b/kitty_tests/graphics.py @@ -210,7 +210,7 @@ class TestGraphics(BaseTest): # 1x1 transparent PNG png_data = standard_b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==') expected = b'\x00\xff\xff\x7f' - self.ae(load_png_data(png_data), expected) + self.ae(load_png_data(png_data), (expected, 1, 1)) s, g, l, sl = load_helpers(self) sl(png_data, f=100, expecting_data=expected) # test error handling for loading bad png data