mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Clean up python binding for image-loading functions.
This commit is contained in:
@ -201,26 +201,9 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin
|
||||
|
||||
// let's create a nice name for this thing based on the filename
|
||||
std::string name = "PtImageFromDisk_";
|
||||
const wchar_t* i = filename;
|
||||
int charsChecked = 0;
|
||||
|
||||
while (*i != '\\' && *i != '\0' && charsChecked < 1024)
|
||||
{
|
||||
i++;
|
||||
charsChecked++;
|
||||
}
|
||||
|
||||
if (*i == '\0')
|
||||
{
|
||||
i = filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
char* cName = hsWStringToString(i);
|
||||
name = name + cName;
|
||||
char* filetext = hsWStringToString(filename);
|
||||
name = name + filetext;
|
||||
delete[] filetext;
|
||||
|
||||
hsgResMgr::ResMgr()->NewKey(name.c_str(), theMipmap, plLocation::kGlobalFixedLoc);
|
||||
|
||||
@ -246,26 +229,9 @@ PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint
|
||||
|
||||
// let's create a nice name for this thing based on the filename
|
||||
std::string name = "PtImageFromDisk_";
|
||||
const wchar_t* i = filename;
|
||||
int charsChecked = 0;
|
||||
|
||||
while (*i != '\\' && *i != '\0' && charsChecked < 1024)
|
||||
{
|
||||
i++;
|
||||
charsChecked++;
|
||||
}
|
||||
|
||||
if (*i == '\0')
|
||||
{
|
||||
i = filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
char* cName = hsWStringToString(i);
|
||||
name = name + cName;
|
||||
char* filetext = hsWStringToString(filename);
|
||||
name = name + filetext;
|
||||
delete[] filetext;
|
||||
|
||||
hsgResMgr::ResMgr()->NewKey(name.c_str(), theMipmap, plLocation::kGlobalFixedLoc);
|
||||
|
||||
|
@ -285,23 +285,13 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(filenameObj))
|
||||
if (PyString_CheckEx(filenameObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(filenameObj);
|
||||
wchar_t* text = new wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
PyObject* ret = pyImage::LoadJPEGFromDisk(text, width, height);
|
||||
delete [] text;
|
||||
return ret;
|
||||
}
|
||||
else if (PyString_Check(filenameObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(filenameObj);
|
||||
char* text = PyString_AsStringEx(filenameObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
PyObject* ret = pyImage::LoadJPEGFromDisk(wText, width, height);
|
||||
delete [] wText;
|
||||
delete[] wText;
|
||||
delete[] text;
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
@ -320,24 +310,13 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadPNGFromDisk, args, "Params: filename,width
|
||||
PyErr_SetString(PyExc_TypeError, "PtLoadPNGFromDisk expects a string and two unsigned shorts");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(filenameObj))
|
||||
if (PyString_CheckEx(filenameObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(filenameObj);
|
||||
wchar_t* text = new wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
PyObject* ret = pyImage::LoadPNGFromDisk(text, width, height);
|
||||
delete [] text;
|
||||
return ret;
|
||||
}
|
||||
else if (PyString_Check(filenameObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(filenameObj);
|
||||
char* text = PyString_AsStringEx(filenameObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
PyObject* ret = pyImage::LoadPNGFromDisk(wText, width, height);
|
||||
delete [] wText;
|
||||
delete[] wText;
|
||||
delete[] text;
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
@ -352,5 +331,6 @@ void pyImage::AddPlasmaMethods(std::vector<PyMethodDef> &methods)
|
||||
{
|
||||
#ifndef BUILDING_PYPLASMA
|
||||
PYTHON_GLOBAL_METHOD(methods, PtLoadJPEGFromDisk);
|
||||
PYTHON_GLOBAL_METHOD(methods, PtLoadPNGFromDisk);
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user