synfig-core  1.0.3
renddesc.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
23 /* ========================================================================= */
24 
25 /* === S T A R T =========================================================== */
26 
27 #ifndef __SYNFIG_RENDERDESC_H
28 #define __SYNFIG_RENDERDESC_H
29 
30 /* === H E A D E R S ======================================================= */
31 
32 #include "vector.h"
33 #include "color.h"
34 #include "types.h"
35 #include <cmath>
36 #include "rect.h"
37 #include "matrix.h"
38 
39 /* === M A C R O S ========================================================= */
40 
41 #ifndef DPM2DPI
42 #define DPM2DPI(x) (float(x)/39.3700787402f)
43 #define DPI2DPM(x) (float(x)*39.3700787402f)
44 #endif
45 
46 /* === T Y P E D E F S ===================================================== */
47 
48 /* === C L A S S E S & S T R U C T S ======================================= */
49 
50 namespace synfig {
51 
55 class RendDesc
56 {
57 public:
58  enum Lock
59  {
60  PX_ASPECT=(1<<0), // "Pixel Aspect" in Locks and Links
61  PX_AREA=(1<<1), // not used
62  PX_W=(1<<2), // "Pixel Width" in Locks and Links - not used
63  PX_H=(1<<3), // "Pixel Height" in Locks and Links - not used
64 
65  IM_ASPECT=(1<<4), // "Image Aspect" in Locks and Links
66  IM_SPAN=(1<<5), // "Image Span" in Locks and Links
67  IM_W=(1<<6), // "Image Width" in Locks and Links
68  IM_H=(1<<7), // "Image Height" in Locks and Links
69  IM_ZOOMIN=(1<<8), // not used
70  IM_ZOOMOUT=(1<<9), // not used
71 
72  LINK_PX_ASPECT=(1<<10), // not used
73  LINK_PX_AREA=(1<<11), // not used
74  LINK_IM_ASPECT=(1<<12), // "Width and Height pixel ratio" in Image Size
75  LINK_IM_SPAN=(1<<13), // not used
76  LINK_IM_CENTER=(1<<14), // not used
77  LINK_RES=(1<<15) // Resolution ratio in Image Size
78  };
79 
80 private:
82  int w_,h_;
84  int w_ratio_, h_ratio_;
86  Real x_res;
88  Real y_res;
90  Real x_res_ratio_;
92  Real y_res_ratio_;
94  Point tl_, br_;
96  Point focus;
98  int a;
100  Color background;
103  int flags;
105  bool interlaced;
107  bool clamp;
109  bool render_excluded_contexts;
111  float frame_rate;
113  Time time_begin, time_end;
115  Matrix transformation_matrix;
116 
117 public:
119  enum
120  {
126  } AntialiasFilter;
127 
130  w_ (480),
131  h_ (270),
132  x_res (DPI2DPM(72.0f)),
133  y_res (DPI2DPM(72.0f)),
134  tl_ (-4,2.25),
135  br_ (4,-2.25),
136  focus (0,0),
137  a (2),
138  background (Color::gray()),
139  flags (0),
140  interlaced (false),
141  clamp (false),
142  render_excluded_contexts(false),
143  frame_rate (24),
144  time_begin (0),
145  time_end (0),
147  { }
148 
150  RendDesc &apply(const RendDesc &x);
151 
153  const Color &get_bg_color()const;
154 
156  RendDesc &set_bg_color(const Color &bg);
157 
159  int get_w()const;
160 
162 
168  RendDesc &set_w(int x);
169 
171  int get_h()const;
172 
174 
180  RendDesc &set_h(int y);
181 
183  RendDesc &set_wh(int x, int y);
184 
186  Real get_x_res()const;
187 
189  RendDesc &set_x_res(Real x);
190 
192  Real get_y_res()const;
193 
195  RendDesc &set_y_res(Real y);
196 
197 
199  Real get_physical_w()const;
200 
202  Real get_physical_h()const;
203 
206 
209 
210 
212  int get_frame_start()const;
213 
215  RendDesc &set_frame_start(int x);
216 
218  int get_frame_end()const;
219 
221  RendDesc &set_frame_end(int x);
222 
224  const Time get_time_start()const;
225 
228 
230  const Time get_time_end()const;
231 
234 
236  RendDesc &set_time(Time x);
237 
239  RendDesc &set_frame(int x);
240 
242  const float &get_frame_rate()const;
243 
245  RendDesc &set_frame_rate(float x);
246 
248  const bool &get_interlaced()const;
249 
251  RendDesc &set_interlaced(bool x);
252 
254  const bool &get_clamp()const;
255 
257  RendDesc &set_clamp(bool x);
258 
260  const bool &get_render_excluded_contexts()const;
261 
264 
266  RendDesc &set_flags(const int &x);
267 
270 
272  int get_flags()const;
273 
276 
279 
281  void set_pixel_ratio(const int &x, const int &y);
282 
284  void get_pixel_ratio_reduced(int &w_ratio_reduced, int &h_ratio_reduced);
285 
287  void set_res_ratio(const Real &x, const Real &y);
288 
290  const int &get_antialias()const;
291 
293  RendDesc &set_antialias(const int &x);
294 
296  Real get_span()const;
297 
299  RendDesc& set_span(const Real &x);
300 
302  const Point &get_focus()const;
304  RendDesc &set_focus(const Point &x);
306  const Point &get_tl()const;
308  RendDesc &set_tl(const Point &x);
310  const Point &get_br()const;
312  RendDesc &set_br(const Point &x);
314  // Use this when the individual set_tl or set_br
315  // produce degenerate w or h
316  RendDesc &set_tl_br( const Point &x, const Point &y);
318  Rect get_rect()const { return Rect(get_tl(),get_br()); }
320  RendDesc &set_viewport(const Point &__tl, const Point &__br);
324  Real get_pw()const;
326  Real get_ph()const;
328  RendDesc &set_subwindow(int x, int y, int w, int h);
330  // Keeps the start time and modifies the end time to match the duration
333  const Time get_duration();
335  void set_transformation_matrix(const Matrix &x) { transformation_matrix = x; }
337  const Matrix& get_transformation_matrix() const { return transformation_matrix; }
338 
340  {
341  const Real epsilon = 1e-20;
342  Vector size = get_br() - get_tl();
343  Vector ratio(
344  fabs(size[0]) < epsilon ? 0.0 : 1.0/size[0] * Real(get_w()),
345  fabs(size[1]) < epsilon ? 0.0 : 1.0/size[1] * Real(get_h()) );
346  return Matrix(
347  ratio[0], 0.0, 0.0,
348  0.0, ratio[1], 0.0,
349  -get_tl()[0]*ratio[0], -get_tl()[1]*ratio[1], 1.0 );
350  }
351 
353  {
354  return Matrix(
355  (get_w() > 0 ? 0.0 : 1.0/Real(get_w())*(get_br()[0] - get_tl()[0])), 0.0, 0.0,
356  0.0, (get_h() > 0 ? 0.0 : 1.0/Real(get_h())*(get_br()[1] - get_tl()[1])), 0.0,
357  get_tl()[0], get_tl()[1], 1.0 );
358  }
359 
360 }; // END of class RendDesc
361 
363 
365 {
366  return static_cast<RendDesc::Lock>((int)lhs|(int)rhs);
367 }
368 
370 
372 {
373  return static_cast<RendDesc::Lock>((int)lhs&(int)rhs);
374 }
375 
377 
379 {
380  return static_cast<RendDesc::Lock>(~(int)rhs);
381 }
382 
383 }; /* end namespace synfig */
384 
385 /* === E N D =============================================================== */
386 
387 #endif