summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rotord/src/nodes_drawing.h85
-rwxr-xr-xrotord/src/rotor.cpp2
2 files changed, 58 insertions, 29 deletions
diff --git a/rotord/src/nodes_drawing.h b/rotord/src/nodes_drawing.h
index ff96d9e..4d3b515 100644
--- a/rotord/src/nodes_drawing.h
+++ b/rotord/src/nodes_drawing.h
@@ -5,19 +5,17 @@
#include <cairo.h>
namespace Rotor {
- class Draw: public Image_node {
+ class Draw_node: public Image_node {
public:
- Draw(){image=nullptr;};
- Draw(map<string,string> &settings) {
+ Draw_node(){image=nullptr;};
+ Draw_node(map<string,string> &settings) {
image=nullptr;
- base_settings(settings);
- if(CAIRO_HAS_IMAGE_SURFACE==1) {
- cerr<<"cairo has image surface"<<endl;
- }
};
- ~Draw(){ if (image) delete image;};
- Draw* clone(map<string,string> &_settings) { return new Draw(_settings);};
+ ~Draw_node(){ if (image) delete image;};
+ Draw_node* clone(map<string,string> &_settings) { return new Draw_node(_settings);};
+ virtual void vector_output(cairo_t * cr,const Frame_spec &frame){};
Image *output(const Frame_spec &frame){
+ //get new or input image to draw upon
if (image_inputs.size()) {
if (image_inputs[0]->connection){
//copy incoming image **writable
@@ -32,38 +30,69 @@ namespace Rotor {
else {
if (!image) image =new Image();
image->setup(frame.w,frame.h); //do this twice or use a goto
- }
- //draw onto new or input image
- //image->convert32(); //pad frame out to 32 bits for cairo
- //turns out cairo doesn't draw at all if the stride definition is wrong
- //crashes like this though
+ }
+ //convert to 32 bit - this can probably be optimised further
cv::Mat chans;
- cv::cvtColor(image->rgb, chans, CV_RGB2RGBA, 4);
-
-
+ cv::cvtColor(image->rgb, chans, CV_BGR2RGBA, 4);
cairo_surface_t * cs = cairo_image_surface_create_for_data (chans.data,
CAIRO_FORMAT_RGB24,
image->w,
image->h,
image->w*4);
cairo_t * cr = cairo_create (cs);
- cairo_rectangle(cr, 0,0, image->w/2, image->h/2);
- cairo_set_source_rgb(cr, 0,1.0,0); //cairo colour is 0.0->1.0
+ //do any kind of vector drawing
+ vector_output(cr,frame);
+ //convert frame back to 24 bits
+ cv::cvtColor(chans,image->rgb,CV_RGBA2BGR,3);
+ cairo_destroy(cr);
+ cairo_surface_destroy(cs);
+ return image;
+ }
+ private:
+ Image *image; //is an image generator
+ };
+ class Hello_draw: public Draw_node {
+ public:
+ Hello_draw(){image=nullptr;};
+ Hello_draw(map<string,string> &settings) {
+ image=nullptr;
+ base_settings(settings);
+ };
+ ~Hello_draw(){ if (image) delete image;};
+ Hello_draw* clone(map<string,string> &_settings) { return new Hello_draw(_settings);};
+ void vector_output(cairo_t * cr,const Frame_spec &frame){
+ cairo_text_extents_t te;
+ cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
+ cairo_select_font_face (cr, "Georgia",
+ CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+ cairo_set_font_size (cr, 50);
+ cairo_text_extents(cr, "hello, world!", &te);
+ cairo_move_to (cr,(frame.w-te.width)/2,(frame.h-te.height)/2);
+ cairo_show_text (cr, "hello, world!");
cairo_fill(cr);
-
+ }
+ private:
+ Image *image; //is an image generator
+ };
+ class Shape: public Draw_node {
+ public:
+ Shape(){image=nullptr;};
+ Shape(map<string,string> &settings) {
+ image=nullptr;
+ base_settings(settings);
+ };
+ ~Shape(){ if (image) delete image;};
+ Shape* clone(map<string,string> &_settings) { return new Shape(_settings);};
+ void vector_output(cairo_t * cr,const Frame_spec &frame){
cairo_text_extents_t te;
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
cairo_select_font_face (cr, "Georgia",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
- cairo_set_font_size (cr, 20);
- cairo_text_extents (cr, "hello world!", &te);
- cairo_move_to (cr, 20,20);
- cairo_show_text (cr, "hello world!");
+ cairo_set_font_size (cr, 50);
+ cairo_text_extents(cr, "hello, world!", &te);
+ cairo_move_to (cr,(frame.w-te.width)/2,(frame.h-te.height)/2);
+ cairo_show_text (cr, "hello, world!");
cairo_fill(cr);
-
- //image->convert24(); //convert frame back to 24 bits
- cv::cvtColor(chans,image->rgb,CV_RGBA2RGB,3);
- return image;
}
private:
Image *image; //is an image generator
diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp
index 77433ac..cf645c6 100755
--- a/rotord/src/rotor.cpp
+++ b/rotord/src/rotor.cpp
@@ -30,7 +30,7 @@ Node_factory::Node_factory(){
add_type("monochrome",new Monochrome());
add_type("transform",new Transform());
add_type("alpha_merge",new Alpha_merge());
- add_type("draw",new Draw());
+ add_type("shape",new Shape());
}
bool Signal_input::connect(Signal_node* source) {