-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
PtFindImage()
for looking up images by name.
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
|
||
#include "pyImage.h" | ||
|
||
#include <algorithm> | ||
#include <vector> | ||
|
||
#include <string_theory/format> | ||
|
||
#include "hsResMgr.h" | ||
|
@@ -52,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
#include "plGImage/plJPEG.h" | ||
#include "plGImage/plMipmap.h" | ||
#include "plGImage/plPNG.h" | ||
#include "plResMgr/plKeyFinder.h" | ||
|
||
#include "pyColor.h" | ||
#include "pyGeometry3.h" | ||
|
@@ -201,6 +205,23 @@ void pyImage::SaveAsPNG(const plFileName& fileName, const std::multimap<ST::stri | |
plPNG::Instance().WriteToFile(fileName, this->GetImage(), textFields); | ||
} | ||
|
||
PyObject* pyImage::Find(const ST::string& name) | ||
{ | ||
std::vector<plKey> foundKeys; | ||
plKeyFinder::Instance().ReallyStupidSubstringSearch(name, plMipmap::Index(), foundKeys); | ||
// Remove anything that isn't loaded - they aren't useful in Python code | ||
std::remove_if( | ||
foundKeys.begin(), | ||
foundKeys.end(), | ||
[](const plKey& key) { return key->ObjectIsLoaded() == nullptr; } | ||
); | ||
|
||
PyObject* tup = PyTuple_New(foundKeys.size()); | ||
for (size_t i = 0; i < foundKeys.size(); ++i) | ||
PyTuple_SET_ITEM(tup, i, pyImage::New(foundKeys[i])); | ||
return tup; | ||
} | ||
|
||
PyObject* pyImage::LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height) | ||
{ | ||
plMipmap* theMipmap = plJPEG::Instance().ReadFromFile(filename); | ||
|
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