1 2 /****************************************************************************** 3 * MODULE : picture.hpp 4 * DESCRIPTION: Abstract graphical pictures 5 * COPYRIGHT : (C) 2013 Joris van der Hoeven 6 ******************************************************************************* 7 * This software falls under the GNU general public license version 3 or later. 8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE 9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. 10 ******************************************************************************/ 11 12 #ifndef PICTURE_H 13 #define PICTURE_H 14 #include "url.hpp" 15 16 /****************************************************************************** 17 * The abstract picture class 18 ******************************************************************************/ 19 20 enum picture_kind { 21 picture_native, 22 picture_raster, 23 picture_lazy }; 24 25 class picture_rep; 26 class picture { 27 ABSTRACT_NULL(picture); 28 }; 29 30 class picture_rep: public abstract_struct { 31 protected: 32 virtual color internal_smooth_pixel (double x, double y); 33 virtual color internal_get_pixel (int x, int y) = 0; 34 virtual void internal_set_pixel (int x, int y, color c) = 0; 35 virtual void internal_copy_from (int x, int y, picture src, 36 int x1, int y1, int x2, int y2); 37 virtual void internal_copy_to (int x, int y, picture dest, 38 int x1, int y1, int x2, int y2); 39 40 public: picture_rep()41 inline picture_rep () {} ~picture_rep()42 inline virtual ~picture_rep () {} 43 44 virtual picture_kind get_type () = 0; 45 virtual void* get_handle () = 0; 46 virtual url get_name (); 47 48 virtual int get_width () = 0; 49 virtual int get_height () = 0; 50 virtual int get_origin_x () = 0; 51 virtual int get_origin_y () = 0; 52 virtual void set_origin (int ox, int oy) = 0; 53 virtual void translate_origin (int dx, int dy); 54 smooth_pixel(double x,double y)55 inline color smooth_pixel (double x, double y) { 56 return internal_smooth_pixel (x + get_origin_x (), y + get_origin_y ()); } get_pixel(int x,int y)57 inline color get_pixel (int x, int y) { 58 return internal_get_pixel (x + get_origin_x (), y + get_origin_y ()); } set_pixel(int x,int y,color c)59 inline void set_pixel (int x, int y, color c) { 60 internal_set_pixel (x + get_origin_x (), y + get_origin_y (), c); } copy_from(picture s)61 inline void copy_from (picture s) { 62 internal_copy_from (0, 0, s, 0, 0, s->get_width (), s->get_height ()); } copy_to(picture d)63 inline void copy_to (picture d) { 64 internal_copy_to (0, 0, d, 0, 0, get_width (), get_height ()); } 65 66 friend class picture; 67 }; 68 69 ABSTRACT_NULL_CODE(picture); 70 71 /****************************************************************************** 72 * Pictures on disk 73 ******************************************************************************/ 74 75 picture load_picture (url u, int w, int h); 76 picture load_xpm (url file_name); 77 void picture_cache_reserve (url u, int w, int h); 78 void picture_cache_release (url u, int w, int h); 79 void picture_cache_clean (); 80 picture cached_load_picture (url u, int w, int h, bool permanent= true); 81 string picture_as_eps (picture pic, int dpi); 82 83 /****************************************************************************** 84 * Drawing on pictures and combining pictures 85 ******************************************************************************/ 86 87 enum composition_mode { 88 compose_destination, 89 compose_source, 90 compose_source_over, 91 compose_towards_source, 92 compose_alpha_distance, 93 compose_add, 94 compose_sub, 95 compose_mul, 96 compose_min, 97 compose_max 98 }; 99 100 picture native_picture (int w, int h, int ox, int oy); 101 picture raster_picture (int w, int h, int ox= 0, int oy= 0); 102 picture as_raster_picture (picture pict); 103 picture error_picture (int w, int h); 104 picture as_native_picture (picture pict); 105 106 int composition_type (composition_mode mode); 107 void draw_on (picture& pic, color c, composition_mode mode); 108 picture compose (picture pic, color c, composition_mode mode); 109 void draw_on (picture& d, picture s, int x, int y, composition_mode m); 110 picture compose (picture p1, picture p2, composition_mode mode); 111 picture compose (array<picture> ps, composition_mode mode); 112 picture mix (picture pic1, double a1, picture pic2, double a2); 113 114 /****************************************************************************** 115 * Operations on pictures 116 ******************************************************************************/ 117 118 picture shift (picture pic, double dx, double dy); 119 picture magnify (picture pic, double sx, double sy); 120 picture bubble (picture pic, double r, double a); 121 122 picture gaussian_pen_picture (double r); 123 picture oval_pen_picture (double r); 124 picture rectangular_pen_picture (double r); 125 picture gaussian_pen_picture (double rx, double ry, double phi= 0.0); 126 picture oval_pen_picture (double rx, double ry, double phi= 0.0); 127 picture rectangular_pen_picture (double rx, double ry, double phi= 0.0); 128 picture motion_pen_picture (double dx, double dy); 129 130 picture blur (picture pic, picture pen); 131 picture outline (picture pic, picture pen); 132 picture thicken (picture pic, picture pen); 133 picture erode (picture pic, picture pen); 134 135 picture normalize (picture eff); 136 picture color_matrix (picture eff, array<double> m); 137 picture make_transparent (picture eff, color bgc); 138 picture make_opaque (picture eff, color bgc); 139 140 #endif // defined PICTURE_H 141