Browse Source

Clean up python binding for image-loading functions.

Joseph Davies 13 years ago
parent
commit
036a1d38fc
  1. 46
      Sources/Plasma/FeatureLib/pfPython/pyImage.cpp
  2. 34
      Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp

46
Sources/Plasma/FeatureLib/pfPython/pyImage.cpp

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

34
Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp

@ -285,23 +285,13 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt
PYTHON_RETURN_ERROR;
}
if (PyUnicode_Check(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))
if (PyString_CheckEx(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[] 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[] 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
}
Loading…
Cancel
Save