-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from Hoikas/image_roundtrip
Add partial bindings for `plJPEG` and `plPNG`.
- Loading branch information
Showing
11 changed files
with
305 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* This file is part of HSPlasma. | ||
* | ||
* HSPlasma is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HSPlasma is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "pyJPEG.h" | ||
|
||
#include "PRP/Surface/pyBitmap.h" | ||
#include "Stream/pyStream.h" | ||
|
||
#include <Util/plJPEG.h> | ||
|
||
PY_PLASMA_EMPTY_INIT(JPEG) | ||
PY_PLASMA_NEW_MSG(JPEG, "plJPEG cannot be constructed") | ||
|
||
PY_METHOD_STATIC_VA(JPEG, DecompressJPEG, | ||
"Params: stream\n" | ||
"Read JPEG file from stream directly into a plMipmap") | ||
{ | ||
PyObject* streamObj; | ||
if (!PyArg_ParseTuple(args, "O", &streamObj)) { | ||
PyErr_SetString(PyExc_TypeError, "DecompressJPEG expects an hsStream"); | ||
return nullptr; | ||
} | ||
if (!pyStream_Check(streamObj)) { | ||
PyErr_SetString(PyExc_TypeError, "DecompressJPEG expects an hsStream"); | ||
return nullptr; | ||
} | ||
|
||
plMipmap* mm = plJPEG::DecompressJPEG(((pyStream*)streamObj)->fThis); | ||
|
||
// We're doing this manually because the new Mipmap object is being | ||
// released to Python code. | ||
pyMipmap* mmObj = nullptr; | ||
try { | ||
mmObj = PyObject_New(pyMipmap, &pyMipmap_Type); | ||
} catch (const hsJPEGException& ex) { | ||
PyErr_SetString(PyExc_RuntimeError, ex.what()); | ||
return nullptr; | ||
} | ||
mmObj->fPyOwned = true; | ||
mmObj->fThis = mm; | ||
return (PyObject*)mmObj; | ||
} | ||
|
||
static PyMethodDef pyJPEG_Methods[] = { | ||
pyJPEG_DecompressJPEG_method, | ||
PY_METHOD_TERMINATOR, | ||
}; | ||
|
||
PY_PLASMA_TYPE(JPEG, plJPEG, "plJPEG wrapper") | ||
|
||
PY_PLASMA_TYPE_INIT(JPEG) | ||
{ | ||
pyJPEG_Type.tp_new = pyJPEG_new; | ||
pyJPEG_Type.tp_methods = pyJPEG_Methods; | ||
if (PyType_CheckAndReady(&pyJPEG_Type) < 0) | ||
return nullptr; | ||
|
||
Py_INCREF(&pyJPEG_Type); | ||
return (PyObject*)&pyJPEG_Type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* This file is part of HSPlasma. | ||
* | ||
* HSPlasma is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HSPlasma is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _PYJPEG_H | ||
#define _PYJPEG_H | ||
|
||
#include "PyPlasma.h" | ||
|
||
PY_WRAP_PLASMA(JPEG, class plJPEG); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* This file is part of HSPlasma. | ||
* | ||
* HSPlasma is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HSPlasma is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "pyPNG.h" | ||
|
||
#include "PRP/Surface/pyBitmap.h" | ||
#include "Stream/pyStream.h" | ||
|
||
#include <Util/plPNG.h> | ||
|
||
PY_PLASMA_EMPTY_INIT(PNG) | ||
PY_PLASMA_NEW_MSG(PNG, "plPNG cannot be constructed") | ||
|
||
PY_METHOD_STATIC_VA(PNG, DecompressPNG, | ||
"Params: stream\n" | ||
"Read PNG file from stream directly into a plMipmap") | ||
{ | ||
PyObject* streamObj; | ||
if (!PyArg_ParseTuple(args, "O", &streamObj)) { | ||
PyErr_SetString(PyExc_TypeError, "DecompressPNG expects an hsStream"); | ||
return nullptr; | ||
} | ||
if (!pyStream_Check(streamObj)) { | ||
PyErr_SetString(PyExc_TypeError, "DecompressPNG expects an hsStream"); | ||
return nullptr; | ||
} | ||
|
||
plMipmap* mm = nullptr; | ||
try { | ||
mm = plPNG::DecompressPNG(((pyStream*)streamObj)->fThis); | ||
} catch (const hsPNGException& ex) { | ||
PyErr_SetString(PyExc_RuntimeError, ex.what()); | ||
return nullptr; | ||
} | ||
|
||
// We're doing this manually because the new Mipmap object is being | ||
// released to Python code. | ||
pyMipmap* mmObj = PyObject_New(pyMipmap, &pyMipmap_Type); | ||
mmObj->fPyOwned = true; | ||
mmObj->fThis = mm; | ||
return (PyObject*)mmObj; | ||
} | ||
|
||
static PyMethodDef pyPNG_Methods[] = { | ||
pyPNG_DecompressPNG_method, | ||
PY_METHOD_TERMINATOR, | ||
}; | ||
|
||
PY_PLASMA_TYPE(PNG, plPNG, "plPNG wrapper") | ||
|
||
PY_PLASMA_TYPE_INIT(PNG) | ||
{ | ||
pyPNG_Type.tp_new = pyPNG_new; | ||
pyPNG_Type.tp_methods = pyPNG_Methods; | ||
if (PyType_CheckAndReady(&pyPNG_Type) < 0) | ||
return nullptr; | ||
|
||
Py_INCREF(&pyPNG_Type); | ||
return (PyObject*)&pyPNG_Type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* This file is part of HSPlasma. | ||
* | ||
* HSPlasma is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HSPlasma is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _PYPNG_H | ||
#define _PYPNG_H | ||
|
||
#include "PyPlasma.h" | ||
|
||
PY_WRAP_PLASMA(PNG, class plPNG); | ||
|
||
#endif |
Oops, something went wrong.