diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-10-31 12:57:59 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-10-31 12:57:59 +0000 |
| commit | 834835c99dd9fd182ca3116b5bc3e7ae8b3815ad (patch) | |
| tree | add4c59353b4d5cb914e44a92fcfb08f5981838c /rotord/src | |
| parent | b3abde4531510b7accbc58174ecd9ec27c52ee3a (diff) | |
thumbnail stills and svgs
Diffstat (limited to 'rotord/src')
| -rw-r--r-- | rotord/src/graph.h | 38 | ||||
| -rw-r--r-- | rotord/src/nodes_audio_analysis.cpp | 2 | ||||
| -rw-r--r-- | rotord/src/nodes_drawing.h | 7 | ||||
| -rw-r--r-- | rotord/src/rotor.h | 1 |
4 files changed, 44 insertions, 4 deletions
diff --git a/rotord/src/graph.h b/rotord/src/graph.h index 6f2ee79..2f8843d 100644 --- a/rotord/src/graph.h +++ b/rotord/src/graph.h @@ -97,6 +97,43 @@ 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(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; + } + } + } + //if not svg feed to FFMS2 if (player.open(inputfilename)){ if (player.fetch_frame(w,h,player.get_number_frames()/4)) { Image i; @@ -105,7 +142,6 @@ namespace Rotor { cvtColor(i.rgb,cp,CV_RGB2BGR); cv::imwrite(outputfilename.c_str(),cp); return true; - } } return false; diff --git a/rotord/src/nodes_audio_analysis.cpp b/rotord/src/nodes_audio_analysis.cpp index 5318bb1..a2a9c63 100644 --- a/rotord/src/nodes_audio_analysis.cpp +++ b/rotord/src/nodes_audio_analysis.cpp @@ -122,7 +122,6 @@ namespace Rotor{ cerr<<analysers["segmenter"].features.size()<<" segments"<<endl; cerr<<analysers["tempo"].features.size()<<" tempo features"<<endl; cerr<<analysers["intensity"].features.size()<<" intensity features"<<endl; - auto g=++analysers["segmenter"].features.begin(); int i=0; float min_tempo=9999999.0f; float min_intensity=9999999.0f; @@ -131,6 +130,7 @@ namespace Rotor{ vector<float> tempos; vector<float> intensities; vector<float> times; + auto g=++analysers["segmenter"].features.begin(); for (auto f=analysers["segmenter"].features.begin();g!=analysers["segmenter"].features.end();f++,g++,i++){ cerr<<"segment "<<i<<": "<<f->first<<" to "<<g->first<<endl; times.push_back(f->first); diff --git a/rotord/src/nodes_drawing.h b/rotord/src/nodes_drawing.h index b26841e..1bd6375 100644 --- a/rotord/src/nodes_drawing.h +++ b/rotord/src/nodes_drawing.h @@ -3,7 +3,6 @@ #include "rotor.h" #include <cairo.h> -#include <rsvg.h> namespace Rotor { class Draw_node: public Image_node { @@ -217,6 +216,7 @@ namespace Rotor { }; class Svg: public Draw_node { public: + //rsvg should be cleanup? Svg(){ title="SVG"; description="Draws svg files"; @@ -238,7 +238,10 @@ namespace Rotor { } else cerr<<"Rotor: SVG failed to load "<<attributes["filename"]->value<<endl; }; - ~Svg(){}; + ~Svg(){ + rsvg_handle_close(rsvg,nullptr); + g_object_unref(rsvg); + }; Svg* clone(map<string,string> &_settings) { return new Svg(_settings);}; void vector_output(cairo_t * cr,const Frame_spec &frame){ //to make it resolution independent diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index f179efd..50ae266 100644 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -75,6 +75,7 @@ Requirements #include <iostream> #include <json/json.h> +#include <rsvg.h> #include "Poco/Net/HTTPResponse.h" #include "Poco/Logger.h" |
