mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-09 01:09:59 +01:00
Store image size in XML
and discard loaded image if size does not match
This commit is contained in:
@@ -552,6 +552,10 @@ FrameBufferImage *SessionLoader::XMLToImage(tinyxml2::XMLElement *xml)
|
||||
// if there is an Image mask stored
|
||||
XMLElement* imageNode = xml->FirstChildElement("Image");
|
||||
if (imageNode) {
|
||||
// get theoretical image size
|
||||
int w = 0, h = 0;
|
||||
imageNode->QueryIntAttribute("width", &w);
|
||||
imageNode->QueryIntAttribute("height", &h);
|
||||
// if there is an internal array of data
|
||||
XMLElement* array = imageNode->FirstChildElement("array");
|
||||
if (array) {
|
||||
@@ -566,6 +570,11 @@ FrameBufferImage *SessionLoader::XMLToImage(tinyxml2::XMLElement *xml)
|
||||
if (XMLElementDecodeArray(array, jpgimg.buffer, jpgimg.len) ) {
|
||||
// create and set the image from jpeg
|
||||
i = new FrameBufferImage(jpgimg);
|
||||
// failed if wrong size
|
||||
if ( (w>0 && h>0) && (i->width != w || i->height != h) ) {
|
||||
delete i;
|
||||
i = nullptr;
|
||||
}
|
||||
}
|
||||
// free temporary buffer
|
||||
if (jpgimg.buffer)
|
||||
@@ -741,7 +750,8 @@ void SessionLoader::visit (Source& s)
|
||||
}
|
||||
|
||||
xmlCurrent_ = sourceNode->FirstChildElement("Blending");
|
||||
if (xmlCurrent_) s.blendingShader()->accept(*this);
|
||||
if (xmlCurrent_)
|
||||
s.blendingShader()->accept(*this);
|
||||
|
||||
xmlCurrent_ = sourceNode->FirstChildElement("Mask");
|
||||
if (xmlCurrent_) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
static bool isClipboard(const std::string &clipboard);
|
||||
static tinyxml2::XMLElement* firstSourceElement(const std::string &clipboard, tinyxml2::XMLDocument &xmlDoc);
|
||||
static void applyImageProcessing(const Source &s, const std::string &clipboard);
|
||||
//TODO static void applyMask(const Source &s, std::string clipboard);
|
||||
//TODO static void applyMask(const Source &s, const std::string &clipboard);
|
||||
|
||||
// Elements of Scene
|
||||
void visit (Node& n) override;
|
||||
@@ -90,6 +90,7 @@ public:
|
||||
void load(const std::string& filename);
|
||||
|
||||
static std::string info(const std::string& filename);
|
||||
// static std::string thumbnail(const std::string& filename);
|
||||
};
|
||||
|
||||
#endif // SESSIONCREATOR_H
|
||||
|
||||
@@ -49,6 +49,13 @@ bool SessionVisitor::saveSession(const std::string& filename, Session *session)
|
||||
// source visitor
|
||||
(*iter)->accept(sv);
|
||||
|
||||
// get the thumbnail
|
||||
FrameBufferImage *thumbnail = session->thumbnail();
|
||||
XMLElement *imageelement = SessionVisitor::ImageToXML(thumbnail, &xmlDoc);
|
||||
if (imageelement)
|
||||
sessionNode->InsertEndChild(imageelement);
|
||||
delete thumbnail;
|
||||
|
||||
// 2. config of views
|
||||
XMLElement *views = xmlDoc.NewElement("Views");
|
||||
xmlDoc.InsertEndChild(views);
|
||||
@@ -161,6 +168,8 @@ XMLElement *SessionVisitor::ImageToXML(FrameBufferImage *img, XMLDocument *doc)
|
||||
if (array) {
|
||||
// create an Image node to store the mask image
|
||||
imageelement = doc->NewElement("Image");
|
||||
imageelement->SetAttribute("width", img->width);
|
||||
imageelement->SetAttribute("height", img->height);
|
||||
imageelement->InsertEndChild(array);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,8 +762,11 @@ void Source::setMask(FrameBufferImage *img)
|
||||
// ask to update the source
|
||||
touch();
|
||||
}
|
||||
else
|
||||
else {
|
||||
// CANCEL mask if set to null
|
||||
mask_need_update_ = false;
|
||||
maskshader_->mode = MaskShader::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
bool Source::hasNode::operator()(const Source* elem) const
|
||||
|
||||
Reference in New Issue
Block a user