mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-20 04:09:16 +00:00
Add Python function and glue for PNG saving.
This commit is contained in:
@ -176,6 +176,13 @@ void pyImage::SaveAsJPEG(const wchar* fileName, UInt8 quality)
|
|||||||
plJPEG::Instance().WriteToFile( fileName, this->GetImage() );
|
plJPEG::Instance().WriteToFile( fileName, this->GetImage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "../plGImage/plPNG.h"
|
||||||
|
void pyImage::SaveAsPNG(const wchar* fileName)
|
||||||
|
{
|
||||||
|
|
||||||
|
plPNG::Instance().WriteToFile( fileName, this->GetImage() );
|
||||||
|
}
|
||||||
|
|
||||||
#include "hsResMgr.h"
|
#include "hsResMgr.h"
|
||||||
#include "../pnKeyedObject/plUoid.h"
|
#include "../pnKeyedObject/plUoid.h"
|
||||||
PyObject* pyImage::LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16 height)
|
PyObject* pyImage::LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16 height)
|
||||||
|
@ -166,6 +166,7 @@ public:
|
|||||||
UInt32 GetWidth(); // returns the width of the image
|
UInt32 GetWidth(); // returns the width of the image
|
||||||
UInt32 GetHeight(); // returns the height of the image
|
UInt32 GetHeight(); // returns the height of the image
|
||||||
void SaveAsJPEG(const wchar* fileName, UInt8 quality = 75);
|
void SaveAsJPEG(const wchar* fileName, UInt8 quality = 75);
|
||||||
|
void SaveAsPNG(const wchar* fileName);
|
||||||
static PyObject* LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16 height); // returns pyImage
|
static PyObject* LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16 height); // returns pyImage
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -174,6 +174,41 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsJPEG, args)
|
|||||||
PYTHON_RETURN_ERROR;
|
PYTHON_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PYTHON_METHOD_DEFINITION(ptImage, saveAsPNG, args)
|
||||||
|
{
|
||||||
|
PyObject* filenameObj;
|
||||||
|
if (!PyArg_ParseTuple(args, "O", &filenameObj))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "saveAsPNG expects a string");
|
||||||
|
PYTHON_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PyUnicode_Check(filenameObj))
|
||||||
|
{
|
||||||
|
int strLen = PyUnicode_GetSize(filenameObj);
|
||||||
|
wchar_t* text = TRACKED_NEW wchar_t[strLen + 1];
|
||||||
|
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||||
|
text[strLen] = L'\0';
|
||||||
|
self->fThis->SaveAsPNG(text);
|
||||||
|
delete [] text;
|
||||||
|
PYTHON_RETURN_NONE;
|
||||||
|
}
|
||||||
|
else if (PyString_Check(filenameObj))
|
||||||
|
{
|
||||||
|
// we'll allow this, just in case something goes weird
|
||||||
|
char* text = PyString_AsString(filenameObj);
|
||||||
|
wchar_t* wText = hsStringToWString(text);
|
||||||
|
self->fThis->SaveAsPNG(wText);
|
||||||
|
delete [] wText;
|
||||||
|
PYTHON_RETURN_NONE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "saveAsPNG expects a string");
|
||||||
|
PYTHON_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif // BUILDING_PYPLASMA
|
#endif // BUILDING_PYPLASMA
|
||||||
|
|
||||||
PYTHON_START_METHODS_TABLE(ptImage)
|
PYTHON_START_METHODS_TABLE(ptImage)
|
||||||
@ -183,6 +218,7 @@ PYTHON_START_METHODS_TABLE(ptImage)
|
|||||||
PYTHON_METHOD_NOARGS(ptImage, getWidth, "Returns the width of the image"),
|
PYTHON_METHOD_NOARGS(ptImage, getWidth, "Returns the width of the image"),
|
||||||
PYTHON_METHOD_NOARGS(ptImage, getHeight, "Returns the height of the image"),
|
PYTHON_METHOD_NOARGS(ptImage, getHeight, "Returns the height of the image"),
|
||||||
PYTHON_METHOD(ptImage, saveAsJPEG, "Params: filename,quality=75\nSaves this image to disk as a JPEG file"),
|
PYTHON_METHOD(ptImage, saveAsJPEG, "Params: filename,quality=75\nSaves this image to disk as a JPEG file"),
|
||||||
|
PYTHON_METHOD(ptImage, saveAsPNG, "Params: filename\nSaves this image to disk as a PNG file"),
|
||||||
#endif
|
#endif
|
||||||
PYTHON_END_METHODS_TABLE;
|
PYTHON_END_METHODS_TABLE;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user