diff options
Diffstat (limited to 'rotord/src')
| -rw-r--r-- | rotord/src/cvimage.h | 32 | ||||
| -rw-r--r-- | rotord/src/libavwrapper.cpp | 5 | ||||
| -rw-r--r-- | rotord/src/nodes_drawing.h | 45 | ||||
| -rw-r--r-- | rotord/src/rotor.cpp | 1 |
4 files changed, 60 insertions, 23 deletions
diff --git a/rotord/src/cvimage.h b/rotord/src/cvimage.h index b356f82..25cf3e8 100644 --- a/rotord/src/cvimage.h +++ b/rotord/src/cvimage.h @@ -218,10 +218,38 @@ namespace Rotor { */ return t; } - void crop(int _w,int _h){ //change borders, crop/ extend + void crop(int _w,int _h){ //change borders, crop/ extend, centred + cv::Mat source; + int X,Y,W,H; + //do crop part if ( _w<w||_h<h){ - + //create crop rectangle xywh + X=Y=0; + W=w; + H=h; + if (_w<w){ + W=_w; + X=(w-_w)/2; + w=_w; + } + if (_h<h){ + H=_h; + Y=(h-_h)/2; + h=_h; + } + cv::Mat cropped; + CvRect r=cvRect(X,Y,W,H) ; + rgb(r).copyTo(source); } + else source=rgb; + copyMakeBorder(source,rgb,(_h-h)/2,(_h-h)/2,(_w-w)/2,(_w-w)/2,cv::BORDER_REPLICATE); + w=rgb.rows; + h=rgb.cols; + } + void resize(int _w,int _h){ + cv::resize(rgb,rgb,cv::Size(_w,_h),0,0,cv::INTER_LINEAR ); + w=rgb.rows; + h=rgb.cols; } Image & operator=(const Image &other); //believe these still work, don't know if these optimisations are better than opencvs.. diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index a6cb56d..4a8315f 100644 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -267,10 +267,13 @@ bool libav::exporter::record(std::string filename){ AVDictionary *opts = NULL; // "create" an empty dictionary + // https://libav.org/avprobe.html#MOV_002fMP4_002fISMV + //THIS DOES SEEM TO SET CONTAINER OPTS= AS MOOV_SIZE MAKES THE MOVIE BANJAXED //av_dict_set(&opts, "moov_size", "20000", 0); if (fragmentation) { - av_dict_set(&opts, "movflags","frag_keyframe", 0); + av_dict_set(&opts, "movflags","frag_keyframe", 0); //makes a video watchable in chrome, quicktime & mplayer + //av_dict_set(&opts, "movflags","empty_moov",1); } diff --git a/rotord/src/nodes_drawing.h b/rotord/src/nodes_drawing.h index f4ddbf7..7e7a178 100644 --- a/rotord/src/nodes_drawing.h +++ b/rotord/src/nodes_drawing.h @@ -201,39 +201,44 @@ namespace Rotor { class Mosaic: public Draw_node { //the difficulty here is in keeping the pixels centred //the center of the screen should remain in between pixels - //this implies that the public: Mosaic(){ title="Mosaic"; description="Increases size of pixels"; create_image_input("Image to mosaic","Image input"); - create_parameter("pixels","number","Height of scrren in pixels","Pixels",20.0,0.0,1.0); + create_parameter("pixels","number","Height of screen in pixels","Pixels",20.0,0.0,1.0); NODEID="a33a1a6a-8420-11e3-831b-74d02b29f6a6"; }; - Mosaic(map<string,string> &settings):Shape() { + Mosaic(map<string,string> &settings):Mosaic() { base_settings(settings); }; ~Mosaic(){}; Mosaic* clone(map<string,string> &_settings) { return new Mosaic(_settings);}; void vector_output(cairo_t * cr,const Frame_spec &frame){ - colour=Colour(attributes["colour"]->value); - cairo_set_source_rgb(cr, colour.Rdouble(),colour.Gdouble(),colour.Bdouble()); - switch(attributes["shape"]->intVal) { - case SHAPE_square: - cairo_rectangle(cr,-frame.w/2,-frame.w/2,frame.w,frame.w); - break; - case SHAPE_circle: - cairo_arc(cr,0,0,frame.w/2,0.0, 2 * M_PI); - break; - case SHAPE_triangle: - //subtracting PI/2 =(1.5*PI)/3 so the triangle is pointing up - cairo_line_to(cr,0,-frame.w/2); - cairo_line_to(cr,cos((0.5 * M_PI)/3)*frame.w/2,sin((0.5 * M_PI)/3)*frame.w/2); - cairo_line_to(cr,cos((2.5 * M_PI)/3)*frame.w/2,sin((2.5 * M_PI)/3)*frame.w/2); - cairo_close_path(cr); - break; + double vpix=max(parameters["pixels"]->value,1.0); + double pixel_size=frame.h/vpix; + int h_padded=ceil(vpix/2)*2; + int w_padded=ceil((((vpix/frame.h)*frame.w))/2)*2; + + Image *in1=image_inputs[0]->get(frame); + if (in1){ + Image in=*(in1); + in.crop(w_padded*pixel_size,h_padded*pixel_size); + in.resize(w_padded,h_padded); + int x_start=-((w_padded*pixel_size)/2); + int y_start=-((h_padded*pixel_size)/2); + cairo_translate(cr,x_start,y_start); + for (int i=0;i<w_padded;i++){ + for (int j=0;j<h_padded;j++){ + double R=((double)in.rgb.data[3*(w_padded*j + i) + 0])/255.0; + double G=((double)in.rgb.data[3*(w_padded*j + i) + 1])/255.0; + double B=((double)in.rgb.data[3*(w_padded*j + i) + 2])/255.0; + cairo_set_source_rgb(cr, R,G,B); + cairo_rectangle(cr,i*pixel_size,j*pixel_size,pixel_size,pixel_size); + cairo_fill(cr); + } + } } - cairo_fill(cr); } private: }; diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp index d16d9f4..b31e2ce 100644 --- a/rotord/src/rotor.cpp +++ b/rotord/src/rotor.cpp @@ -74,6 +74,7 @@ Node_factory::Node_factory(){ category["FX"]=vector<Node*>(); add_type("blur",new Blur(),category["FX"]); + add_type("mosaic",new Mosaic(),category["FX"]); //add_type("vhs",new VHS(),category["FX"]); add_type("echo_trails",new Echo_trails(),category["FX"]); add_type("video_feedback",new Video_feedback(),category["FX"]); |
