Browse Source

Add loadImage and unloadImage methods

master
Krisjanis Rijnieks 11 years ago
parent
commit
cdd514dbf5
  1. 23
      src/MediaServer/MediaServer.cpp
  2. 8
      src/MediaServer/MediaServer.h

23
src/MediaServer/MediaServer.cpp

@ -31,6 +31,29 @@ namespace piMapper {
return videoWatcher.getFilePaths();
}
void MediaServer::loadImage(string& path) {
// Load image and add to vector if loading success
ofImage image;
if (image.loadImage(path)) {
loadedImages.push_back(image);
loadedImagePaths.push_back(path); // Save also path
}
}
void MediaServer::unloadImage(string& path) {
// Search for given path in loaded image paths
for (int i = 0; i < loadedImagePaths.size(); i++) {
// If found
if (loadedImagePaths[i] == path) {
// Remove path and unload image as well as remove it from storage
loadedImagePaths.erase(loadedImagePaths.begin() + i);
loadedImages[i].clear();
loadedImages.erase(loadedImages.begin() + i);
break;
}
}
}
void MediaServer::handleImageAdded(string& path) {
/*
cout << "onImageAdded: " << path << endl;

8
src/MediaServer/MediaServer.h

@ -27,6 +27,10 @@ class MediaServer {
std::vector<string>& getVideoPaths();
std::vector<string>& getImagePaths();
// Image loading and handling
void loadImage(string& path);
void unloadImage(string& path);
// Custom events
ofEvent<string> onImageAdded;
ofEvent<string> onImageRemoved;
@ -37,6 +41,10 @@ class MediaServer {
// Directory Watchers
ofx::piMapper::DirectoryWatcher videoWatcher;
ofx::piMapper::DirectoryWatcher imageWatcher;
// Loaded media
vector<ofImage> loadedImages;
vector<string> loadedImagePaths;
// imageWatcher event listeners
void handleImageAdded(string& path);

Loading…
Cancel
Save