summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-11-01 16:56:52 +0000
committerTim Redfern <tim@eclectronics.org>2013-11-01 16:56:52 +0000
commit2c74f2bf6cba53e17b5b36beacc895a121de3b4d (patch)
tree8ac67bb64835019f5d93c2a27f7c2153165c849c /rotord
parente67e0a69e8f168646076d26e7317eaec4e02058a (diff)
listnode/json
Diffstat (limited to 'rotord')
-rw-r--r--rotord/src/graph.h63
-rw-r--r--rotord/src/nodes_drawing.h2
-rw-r--r--rotord/src/rotor.cpp144
-rw-r--r--rotord/src/rotor.h16
-rw-r--r--rotord/src/rotord.cpp14
5 files changed, 137 insertions, 102 deletions
diff --git a/rotord/src/graph.h b/rotord/src/graph.h
index 50f3f87..ddf2471 100644
--- a/rotord/src/graph.h
+++ b/rotord/src/graph.h
@@ -97,42 +97,33 @@ namespace Rotor {
class Thumbnailer{
public:
bool make(const string &inputfilename,int w,int h,const string &outputfilename) {
- //Poco::StringTokenizer t1(inputfilename,".");
- //if (t1.count()>1) {
- // if (t1[t1.count()-1]=="svg"){
- // cerr<<"found an svg"<<endl;
- RsvgHandle * rsvg=rsvg_handle_new_from_file(inputfilename.c_str(),nullptr);
- if (rsvg) {
- RsvgDimensionData dims;
- rsvg_handle_get_dimensions(rsvg,&dims);
- cerr<<"Rotor: SVG loaded "<<inputfilename<<" , "<<dims.width<<"x"<<dims.height<<endl;
- cv::Mat cp=cv::Mat::zeros(h,w,CV_8UC4);
- cv::Mat co=cv::Mat(h,w,CV_8UC3);
- cairo_surface_t * cs = cairo_image_surface_create_for_data (cp.data,
- CAIRO_FORMAT_RGB24,
- w,
- h,
- w*4);
- cairo_t * cr = cairo_create (cs);
- cairo_translate(cr, w/2, h/2);
- cairo_scale(cr, ((float)w)/640.0f,((float)w)/640.0f);
- cairo_translate(cr, -w/2, -h/2);
- cairo_translate(cr, w/2-(dims.width/2), h/2-(dims.height/2));
- rsvg_handle_render_cairo(rsvg,cr);
- cv::cvtColor(cp,co,CV_RGBA2BGR,3);
- cv::imwrite(outputfilename.c_str(),co);
- cairo_destroy(cr);
- cairo_surface_destroy(cs);
- rsvg_handle_close(rsvg,nullptr);
- g_object_unref(rsvg);
- return true;
- }
- // else {
- // cerr<<"Rotor: SVG failed to load "<<inputfilename<<endl;
- // return false;
- // }
- // }
- //}
+ //first try svg
+ RsvgHandle * rsvg=rsvg_handle_new_from_file(inputfilename.c_str(),nullptr);
+ if (rsvg) {
+ RsvgDimensionData dims;
+ rsvg_handle_get_dimensions(rsvg,&dims);
+ cerr<<"Rotor: SVG loaded "<<inputfilename<<" , "<<dims.width<<"x"<<dims.height<<endl;
+ cv::Mat cp=cv::Mat::zeros(h,w,CV_8UC4);
+ cv::Mat co=cv::Mat(h,w,CV_8UC3);
+ cairo_surface_t * cs = cairo_image_surface_create_for_data (cp.data,
+ CAIRO_FORMAT_RGB24,
+ w,
+ h,
+ w*4);
+ cairo_t * cr = cairo_create (cs);
+ cairo_translate(cr, w/2, h/2);
+ cairo_scale(cr, ((float)w)/640.0f,((float)w)/640.0f);
+ cairo_translate(cr, -w/2, -h/2);
+ cairo_translate(cr, w/2-(dims.width/2), h/2-(dims.height/2));
+ rsvg_handle_render_cairo(rsvg,cr);
+ cv::cvtColor(cp,co,CV_RGBA2BGR,3);
+ cv::imwrite(outputfilename.c_str(),co);
+ cairo_destroy(cr);
+ cairo_surface_destroy(cs);
+ rsvg_handle_close(rsvg,nullptr);
+ //g_object_unref(rsvg);
+ return true;
+ }
//if not svg feed to FFMS2
if (player.open(inputfilename)){
if (player.fetch_frame(w,h,player.get_number_frames()/4)) {
diff --git a/rotord/src/nodes_drawing.h b/rotord/src/nodes_drawing.h
index 1bd6375..f46c2b0 100644
--- a/rotord/src/nodes_drawing.h
+++ b/rotord/src/nodes_drawing.h
@@ -240,7 +240,7 @@ namespace Rotor {
};
~Svg(){
rsvg_handle_close(rsvg,nullptr);
- g_object_unref(rsvg);
+ //g_object_unref(rsvg);
};
Svg* clone(map<string,string> &_settings) { return new Svg(_settings);};
void vector_output(cairo_t * cr,const Frame_spec &frame){
diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp
index a4ef055..6ceab91 100644
--- a/rotord/src/rotor.cpp
+++ b/rotord/src/rotor.cpp
@@ -45,6 +45,7 @@ Node_factory::Node_factory(){
add_type("waves",new Waves(),category["Source"]);
add_type("still_image",new Still_image(),category["Source"]);
add_type("video_loader",new Video_loader(),category["Source"]);
+ add_type("video_bank",new Video_bank(),category["Source"]);
add_type("svg",new Svg(),category["Source"]);
category["Distort"]=vector<Node*>();
@@ -112,7 +113,83 @@ bool Node_factory::list_node(const string &t,xmlIO XML){
}
}
XML.addValue("error","Node /"+t+"/ not found");
+ return false;
};
+bool Node_factory::list_node(const string &t,Json::Value &JSON){
+ for (auto& type: type_map) {
+ if (type.first==t) {
+ JSON["node"]=list_node(type.second);
+ return true;
+ }
+ }
+ JSON["error"]="Node /"+t+"/ not found";
+ return false;
+};
+Json::Value Node_factory::list_node(Rotor::Node* _node){
+ Json::Value node;
+ node["type"]=_node->type;
+ node["title"]=_node->title;
+ node["inputs"]=_node->duplicate_inputs?"expandable":"fixed";
+ if (dynamic_cast<Signal_node*> (_node)!=nullptr) node["output"]="signal";
+ if (dynamic_cast<Image_node*> (_node)!=nullptr) node["output"]="image";
+ node["description"]=_node->description;
+ node["UID"]=_node->UID;
+ if (_node->inputs.size()){
+ node["signal_inputs"]=Json::arrayValue;
+ for (auto& input: _node->inputs) {
+ Json::Value signal_input;
+ signal_input["title"]=input->title;
+ signal_input["description"]=input->description;
+ node["signal_inputs"].append(signal_input);
+ }
+ }
+ if (dynamic_cast<Image_node*> (_node)!=nullptr) {
+ if ((dynamic_cast<Image_node*>(_node))->image_inputs.size()){
+ node["image_inputs"]=Json::arrayValue;
+ for (auto& input: (dynamic_cast<Image_node*>(_node))->image_inputs) {
+ Json::Value image_input;
+ image_input["title"]=input->title;
+ image_input["description"]=input->description;
+ node["image_inputs"].append(image_input);
+ }
+ }
+ }
+ if (_node->parameters.size()){
+ node["parameters"]=Json::arrayValue;
+ for (auto& param: _node->parameters) {
+ Json::Value parameter;
+ parameter["name"]=param.first;
+ parameter["type"]=param.second->type;
+ parameter["title"]=param.second->title;
+ parameter["description"]=param.second->description;
+ parameter["value"]=param.second->value;
+ parameter["min"]=param.second->min;
+ parameter["max"]=param.second->max;
+ parameter["step"]=param.second->step;
+ node["parameters"].append(parameter);
+ }
+ }
+ if (_node->attributes.size()){
+ node["attributes"]=Json::arrayValue;
+ for (auto& attr: _node->attributes) {
+ Json::Value attribute;
+ attribute["name"]=attr.first;
+ attribute["title"]=attr.second->title;
+ attribute["description"]=attr.second->description;
+ attribute["value"]=attr.second->value;
+ if (attr.second->vals.size()){ //document attribute enumeration
+ attribute["type"]="enum";
+ attribute["options"]=Json::arrayValue;
+ for (auto val: attr.second->vals){
+ attribute["options"].append(val);
+ }
+ }
+ else attribute["type"]="string";
+ node["attributes"].append(attribute);
+ }
+ }
+ return node;
+}
void Node_factory::list_node(Rotor::Node* type,xmlIO XML,int i=0){
XML.addTag("node");
XML.addAttribute("node","type",type->type,i);
@@ -210,70 +287,9 @@ void Node_factory::list_categories(Json::Value &JSON){
category["name"]=_category.first;
category["nodes"]=Json::arrayValue;
for (auto& _node: _category.second){
- cerr<<"Adding "<<_category.first<<":"<<_node->type<<endl;
- Json::Value node;
- node["type"]=_node->type;
- node["title"]=_node->title;
- node["inputs"]=_node->duplicate_inputs?"expandable":"fixed";
- if (dynamic_cast<Signal_node*> (_node)!=nullptr) node["output"]="signal";
- if (dynamic_cast<Image_node*> (_node)!=nullptr) node["output"]="image";
- node["description"]=_node->description;
- node["UID"]=_node->UID;
- if (_node->inputs.size()){
- node["signal_inputs"]=Json::arrayValue;
- for (auto& input: _node->inputs) {
- Json::Value signal_input;
- signal_input["title"]=input->title;
- signal_input["description"]=input->description;
- node["signal_inputs"].append(signal_input);
- }
- }
- if (dynamic_cast<Image_node*> (_node)!=nullptr) {
- if ((dynamic_cast<Image_node*>(_node))->image_inputs.size()){
- node["image_inputs"]=Json::arrayValue;
- for (auto& input: (dynamic_cast<Image_node*>(_node))->image_inputs) {
- Json::Value image_input;
- image_input["title"]=input->title;
- image_input["description"]=input->description;
- node["image_inputs"].append(image_input);
- }
- }
- }
- if (_node->parameters.size()){
- node["parameters"]=Json::arrayValue;
- for (auto& param: _node->parameters) {
- Json::Value parameter;
- parameter["name"]=param.first;
- parameter["type"]=param.second->type;
- parameter["title"]=param.second->title;
- parameter["description"]=param.second->description;
- parameter["value"]=param.second->value;
- parameter["min"]=param.second->min;
- parameter["max"]=param.second->max;
- parameter["step"]=param.second->step;
- node["parameters"].append(parameter);
- }
- }
- if (_node->attributes.size()){
- node["attributes"]=Json::arrayValue;
- for (auto& attr: _node->attributes) {
- Json::Value attribute;
- attribute["name"]=attr.first;
- attribute["title"]=attr.second->title;
- attribute["description"]=attr.second->description;
- attribute["value"]=attr.second->value;
- if (attr.second->vals.size()){ //document attribute enumeration
- attribute["type"]="enum";
- attribute["options"]=Json::arrayValue;
- for (auto val: attr.second->vals){
- attribute["options"].append(val);
- }
- }
- else attribute["type"]="string";
- node["attributes"].append(attribute);
- }
- }
- category["nodes"].append(node);
+ //cerr<<"Adding "<<_category.first<<":"<<_node->type<<endl;
+
+ category["nodes"].append(list_node(_node));
}
JSON["category"].append(category);
}
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h
index 50ae266..fcee9d9 100644
--- a/rotord/src/rotor.h
+++ b/rotord/src/rotor.h
@@ -243,6 +243,9 @@ namespace Rotor {
void create_attribute(const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}) {
attributes[_attr]=new Attribute(_desc,_title,_value,_vals);
};
+ //void create_attribute(const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}) {
+ // attributes[_attr]=new Attribute(_desc,_title,_value,_vals);
+ //};
void create_attribute(string *alias,const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}) {
create_attribute(_attr,_desc,_title,_value,_vals);
alias=&(attributes[_attr]->value);
@@ -568,6 +571,17 @@ namespace Rotor {
Image in1,in2,in2t,temp; //for blend frames;
string *filename;
};
+ class Video_bank: public Video_loader {
+ public:
+ Video_bank(){
+ UID="73616e66-4306-11e3-981e-74d02b29f6a6";
+ };
+ Video_bank(map<string,string> &settings): Video_bank() {
+ base_settings(settings);
+ };
+ ~Video_bank(){};
+ private:
+ };
class Video_output: public Image_node {
//Video_output 'presents' the output movie. Aspect ratio, bars, fadein/fadeout would happen here
public:
@@ -696,7 +710,9 @@ namespace Rotor {
return NULL;
};
bool list_node(const string &t,xmlIO XML);
+ bool list_node(const string &t,Json::Value &JSON);
void list_node(Rotor::Node* type,xmlIO XML,int i=0);
+ Json::Value list_node(Rotor::Node* type);
void list_nodes(xmlIO XML);
void list_nodes(Json::Value &JSON);
void list_categories(xmlIO XML);
diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp
index de853e4..c4c562e 100644
--- a/rotord/src/rotord.cpp
+++ b/rotord/src/rotord.cpp
@@ -212,8 +212,20 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
}
}
else if (command[0]=="listnode") {
- XML.pushTag("rotor");
if (request.getMethod()=="GET") {
+ if (command.size()>1){
+ if (command[1]=="json") {
+ Json::Value root;
+ Json::StyledWriter writer;
+
+ Node_factory factory;
+ factory.list_node(body,root);
+ string content = writer.write(root);
+ status=HTTPResponse::HTTP_OK;
+ return new RenderContextHandler(content, status);
+ }
+ }
+ XML.pushTag("rotor");
Node_factory factory;
if (factory.list_node(body,XML)) status=HTTPResponse::HTTP_OK;
}