Also return image dimensions when loading PNG

This commit is contained in:
Kovid Goyal 2018-07-07 08:04:11 +05:30
parent 2b035739f8
commit 1faddeb402
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 2 additions and 2 deletions

View File

@ -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");
}

View File

@ -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