diff options
| author | Tim Redfern <tim@eclectronics.org> | 2014-01-23 17:57:37 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2014-01-23 17:57:37 +0000 |
| commit | f533df23fb1cd3044aaa02bf74625e9b53c032c1 (patch) | |
| tree | ed3695dfe02205b4c109317fbcf00298159984f8 /rotord/src/nodes_drawing.h | |
| parent | efebf20348daca798c22cbac770d47e9151f941f (diff) | |
mosaic node
Diffstat (limited to 'rotord/src/nodes_drawing.h')
| -rw-r--r-- | rotord/src/nodes_drawing.h | 45 |
1 files changed, 25 insertions, 20 deletions
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: }; |
