From 5c33825103bf1cb7070e06ab48b15c873fae6b80 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 11 Jul 2014 23:09:59 -0400 Subject: [PATCH] Expose plMipmap::CompressImage to Python --- Python/PRP/Surface/pyMipmap.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Python/PRP/Surface/pyMipmap.cpp b/Python/PRP/Surface/pyMipmap.cpp index a65b9eade..3fa758382 100644 --- a/Python/PRP/Surface/pyMipmap.cpp +++ b/Python/PRP/Surface/pyMipmap.cpp @@ -236,6 +236,26 @@ static PyObject* pyMipmap_DecompressImage(pyMipmap* self, PyObject* args) { return img; } +static PyObject* pyMipmap_CompressImage(pyMipmap* self, PyObject* args) { + int level, dataSize; + char* data; + if (!PyArg_ParseTuple(args, "is#", &level, &data, &dataSize)) { + PyErr_SetString(PyExc_TypeError, "CompressImage expects an int and a binary string"); + return NULL; + } + try { + self->fThis->CompressImage(level, data, dataSize); + } catch (hsBadParamException& ex) { + PyErr_SetString(PyExc_RuntimeError, ex.what()); + return NULL; + } catch (hsNotImplementedException& ex) { + PyErr_SetString(PyExc_NotImplementedError, ex.what()); + return NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* pyMipmap_getWidth(pyMipmap* self, void*) { return PyInt_FromLong(self->fThis->getWidth()); } @@ -319,6 +339,9 @@ static PyMethodDef pyMipmap_Methods[] = { { "DecompressImage", (PyCFunction)pyMipmap_DecompressImage, METH_VARARGS, "Params: level\n" "Deompresses the specified mip level and returns the uncompressed RGBA buffer" }, + { "CompressImage", (PyCFunction)pyMipmap_CompressImage, METH_VARARGS, + "Params: level, data\n" + "Compresses the specified mip level" }, { NULL, NULL, 0, NULL } };