picture compose (picture p1, picture p2, composition_mode mode) { raster<true_color> r1= as_raster<true_color> (p1); raster<true_color> r2= as_raster<true_color> (p2); raster<true_color> r = compose (r1, r2, mode); return raster_picture (r); }
picture compose (array<picture> ps, composition_mode mode) { array<raster<true_color> > rs (N(ps)); for (int i=0; i<N(ps); i++) rs[i]= as_raster<true_color> (ps[i]); raster<true_color> r= compose (rs, mode); return raster_picture (r); }
template<class C> raster<C> as_raster (picture pic) { if (pic->get_type () != picture_kind_helper<C>::kind) { picture rew= raster_picture (pic->get_width (), pic->get_height (), pic->get_origin_x (), pic->get_origin_y ()); pic->copy_to (rew); pic= rew; } raster_picture_rep<C>* rep= (raster_picture_rep<C>*) pic->get_handle (); return rep->r; }
picture inner_shadow (picture pic, color c, double dx, double dy) { true_color col (c); raster<true_color> r= as_raster<true_color> (pic); raster<double> alpha = get_alpha (r); raster<double> ashift= shift (alpha, dx, dy); raster<double> compat= change_extents (ashift, r->w, r->h, r->ox, r->oy); raster<double> cshift= ((double) 1) - compat; raster<double> shad = min (alpha, cshift); raster<true_color> appl= apply_alpha (col, shad); return raster_picture (appl); }
picture engrave (picture pic, double a0, color tlc, color brc, double tlw, double brw) { raster<true_color> ras= as_raster<true_color> (pic); int w= ras->w, h= ras->h, ox= ras->ox, oy= ras->oy; raster<double> tl= tl_distances (ras); raster<double> br= br_distances (ras); raster<true_color> ret (w, h, ox, oy); true_color c1 (tlc); true_color c2 (brc); for (int y=0; y<h; y++) for (int x=0; x<w; x++) { double d1= tl->a[y*w+x]; double d2= br->a[y*w+x]; double a1= 1.0 / (1.0 + d1*d1/(tlw*tlw)); double a2= 1.0 / (1.0 + d2*d2/(brw*brw)); true_color c0= ras->a[y*w+x]; true_color cc (c0.r, c0.g, c0.b, a0); true_color mc= (a0 * cc + a1 * c1 + a2 * c2) / (a0 + a1 + a2); ret->a[y*w+x]= true_color (mc.r, mc.g, mc.b, c0.a * mc.a); } return raster_picture (ret); }
picture magnify (picture pic, double sx, double sy) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (magnify (ras, sx, sy)); }
picture shift (picture pic, double dx, double dy) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (shift (ras, dx, dy)); }
picture mix (picture pic1, double a1, picture pic2, double a2) { raster<true_color> r1= as_raster<true_color> (pic1); raster<true_color> r2= as_raster<true_color> (pic2); return raster_picture (mix<true_color,double> (r1, a1, r2, a2)); }
picture motion_pen_picture (double dx, double dy) { raster<double> ras= motion_pen<double> (dx, dy); return raster_picture (apply_alpha (true_color (0, 0, 0, 1), ras)); }
picture outline (picture pic, picture pen) { raster<true_color> ras= as_raster<true_color> (pic); raster<double> alpha= get_alpha (as_raster<true_color> (pen)); return raster_picture (variation (ras, alpha)); }
picture compose (picture pic, color c, composition_mode mode) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (compose (ras, true_color (c), mode)); }
picture error_picture (int w, int h) { picture pic= raster_picture (w, h); draw_on (pic, 0x20ff0000, compose_source); return pic; }
picture rectangular_pen_picture (double rx, double ry, double phi) { raster<double> ras= rectangular_pen<double> (rx, ry, phi); return raster_picture (apply_alpha (true_color (0, 0, 0, 1), ras)); }
picture make_opaque (picture pic, color bgc) { raster<true_color> ras= as_raster<true_color> (pic); true_color tbgc (bgc); return raster_picture (map (make_opaque_function (tbgc), ras)); }
picture bubble (picture pic, double r, double a) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (bubble (ras, r, a)); }
picture make_transparent (picture pic, color bgc) { raster<true_color> ras= as_raster<true_color> (pic); true_color tbgc (bgc); return raster_picture (map (make_transparent_function (tbgc), ras)); }
picture raster_picture (int w, int h, int ox, int oy) { return raster_picture (raster<true_color> (w, h, ox, oy)); }
picture color_matrix (picture pic, array<double> m) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (map (color_matrix_function (m), ras)); }
picture normalize (picture pic) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (normalize (ras)); }
picture erode (picture pic, picture pen) { raster<true_color> ras= as_raster<true_color> (pic); raster<double> alpha= get_alpha (as_raster<true_color> (pen)); return raster_picture (erode (ras, alpha)); }
picture gaussian_pen_picture (double rx, double ry, double phi) { raster<double> ras= gaussian_pen<double> (rx, ry, phi); return raster_picture (apply_alpha (true_color (0, 0, 0, 1), ras)); }
picture gravitational_outline (picture pic, int R, double expon) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (gravitational_outline (ras, R, expon)); }
picture load_xpm (url file_name) { static hashmap<string,picture> cache; string name= as_string (file_name); if (cache->contains (name)) return cache[name]; #ifdef QTTEXMACS picture pict= qt_load_xpm (file_name); #else tree t= xpm_load (file_name); // get main info int ok, i=0, j, k, w, h, c, b, x, y; string s= as_string (t[0]); skip_spaces (s, i); ok= read_int (s, i, w); skip_spaces (s, i); ok= read_int (s, i, h) && ok; skip_spaces (s, i); ok= read_int (s, i, c) && ok; skip_spaces (s, i); ok= read_int (s, i, b) && ok; if ((!ok) || (N(t)<(c+1)) || (c<=0)) { failed_error << "file_name= " << file_name << "\n"; FAILED ("invalid xpm"); } // setup colors string first_name; hashmap<string,color> pmcs(0); for (k=0; k<c; k++) { string s = as_string (t[k+1]); string name= ""; string def = "none"; if (N(s)<b) i=N(s); else { name= s(0,b); i=b; } if (k==0) first_name= name; skip_spaces (s, i); if ((i<N(s)) && (s[i]=='s')) { i++; skip_spaces (s, i); while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++; skip_spaces (s, i); } if ((i<N(s)) && (s[i]=='c')) { i++; skip_spaces (s, i); j=i; while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++; def= locase_all (s (j, i)); } pmcs(name)= xpm_color (def); } // setup pixmap picture pict= raster_picture (w, h); draw_on (pict, 0x00646464, compose_source); for (y=0; y<h; y++) { if (N(t) < (y+c+1)) s= ""; else s= as_string (t[y+c+1]); for (x=0; x<w; x++) { string name; if (N(s)<(b*(x+1))) name= first_name; else name= s (b*x, b*(x+1)); color pmc= pmcs[name]; if (!pmcs->contains (name)) pmc= pmcs[first_name]; pict->set_pixel (x, h-1-y, pmc); } } pict= as_native_picture (pict); #endif cache (name)= pict; return pict; }
picture gravitational_shadow (picture pic, color col, double phi) { raster<true_color> ras= as_raster<true_color> (pic); return raster_picture (gravitational_shadow (ras, 30, 10.0, col, phi)); }