1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/renddesc.cpp
3 ** \brief Class that defines the parameters needed by the Renderer to
4 * render a context to a surface.
9 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** Copyright (c) 2008 Chris Moore
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
48 #define FLAGS(x,y) (((x)&(y))==(y))
50 /* === G L O B A L S ======================================================= */
52 /* === M E T H O D S ======================================================= */
55 RendDesc::apply(const RendDesc &x)
62 RendDesc::get_bg_color()const
68 RendDesc::set_bg_color(const Color &bg)
70 background=bg; return *this;
74 RendDesc::get_physical_w()const
76 return (Real)get_w()/get_x_res();
80 RendDesc::get_physical_h()const
82 return (Real)get_h()/get_y_res();
86 RendDesc::set_physical_w(Real w)
88 set_w(round_to_int(w*get_x_res()));
93 RendDesc::set_physical_h(Real h)
95 set_h(round_to_int(h*get_y_res()));
100 RendDesc::get_w()const
106 RendDesc::set_w(int x)
108 if(FLAGS(flags,LINK_PX_ASPECT)) // never set
113 else if(FLAGS(flags,LINK_PX_AREA)) // never set
118 else if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
121 float old_span=get_span();
123 // If we should preserve image width
124 if( FLAGS(flags,IM_W) // "Image Width"
125 || (FLAGS(flags,IM_ZOOMIN) && d[1]>d[1]/x*w_) // never set
126 || (FLAGS(flags,IM_ZOOMOUT) && d[1]<d[1]/x*w_)) // never set
146 if(FLAGS(flags,IM_SPAN)) // "Image Span"
149 else if(FLAGS(flags,PX_AREA)) // never set
161 RendDesc::get_h()const
167 RendDesc::set_h(int y)
169 if(FLAGS(flags,LINK_PX_ASPECT)) // never set
174 else if(FLAGS(flags,LINK_PX_AREA)) // never set
179 else if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
182 float old_span=get_span();
184 // If we should preserve image width
185 if( FLAGS(flags,IM_W) // "Image Width"
186 || (FLAGS(flags,IM_ZOOMIN) && d[0]>d[0]/y*h_) // never set
187 || (FLAGS(flags,IM_ZOOMOUT) && d[0]<d[0]/y*h_)) // never set
207 if(FLAGS(flags,IM_SPAN)) // "Image Span"
210 else if(FLAGS(flags,PX_AREA)) // never set
222 RendDesc::set_wh(int x, int y)
224 // FIXME: This is a working hack...
232 RendDesc::get_x_res()const
238 RendDesc::set_x_res(Real x)
240 x_res=x; return *this;
244 RendDesc::get_y_res()const
250 RendDesc::set_y_res(Real y)
252 y_res=y; return *this;
256 RendDesc::get_frame_start()const
258 return round_to_int(time_begin*frame_rate);
262 RendDesc::set_frame_start(int x)
264 return set_time_start(Time(x)/frame_rate);
268 RendDesc::get_frame_end()const
270 return round_to_int(time_end*frame_rate);
274 RendDesc::set_frame_end(int x)
276 return set_time_end(Time(x)/frame_rate);
281 RendDesc::get_time_start()const
287 RendDesc::set_time_start(Time x)
290 time_begin=time_end=x;
298 RendDesc::get_time_end()const
304 RendDesc::set_time_end(Time x)
307 time_end=time_begin=x;
314 RendDesc::set_time(Time x)
316 time_end=time_begin=x;
321 RendDesc::set_frame(int x)
323 return set_time(Time(x)/frame_rate);
327 RendDesc::get_frame_rate()const
333 RendDesc::set_frame_rate(float x)
340 RendDesc::get_interlaced()const
346 RendDesc::set_interlaced(bool x)
347 { interlaced=x; return *this; }
349 //! Return the status of the clamp flag
351 RendDesc::get_clamp()const
354 //! Set the clamp flag
356 RendDesc::set_clamp(bool x)
357 { clamp=x; return *this; }
359 //! Set constraint flags
361 RendDesc::set_flags(const int &x)
362 { flags=x; return *this; }
364 //! Clear constraint flags
366 RendDesc::clear_flags()
367 { flags=0; return *this; }
370 RendDesc::get_flags()const
374 //! Return the aspect ratio of a single pixel
376 RendDesc::get_pixel_aspect()const
387 //! Return the aspect ratio of the entire image
389 RendDesc::get_image_aspect()const
399 //! Return the antialias amount
401 RendDesc::get_antialias()const
404 //! Set the antialias amount
406 RendDesc::set_antialias(const int &x)
407 { a=x; return *this; }
410 //! Return the distance from the bottom-right to the top-left
412 RendDesc::get_span()const
414 return (br_-tl_).mag();
417 //! Set the span distance
419 RendDesc::set_span(const Real &x)
421 Vector::value_type ratio=x/get_span();
423 //! \todo this looks wrong. I suspect the intention was to check
424 // "(not IM_W) AND (not IM_H)", ie "not(IM_W OR IM_H)" but
425 // this check does "not(IM_W AND IM_H)"
426 if(!FLAGS(flags,IM_W|IM_H) || FLAGS(flags,IM_ASPECT)) // (not "Image Width") or (not "Image Height") or "Image Aspect"
435 else if(FLAGS(flags,IM_W)) // "Image Width"
437 //! \writeme or fix me
444 }else // IM_H // "Image Height"
446 //! \writeme or fix me
460 RendDesc::get_focus()const
464 RendDesc::set_focus(const Point &x)
465 { focus=x; return *this; }
469 RendDesc::get_tl()const
473 RendDesc::get_br()const
477 RendDesc::set_tl(const Point &x)
479 if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
481 Vector new_size(x-br_);
482 new_size[0]=abs(new_size[0]);
483 new_size[1]=abs(new_size[1]);
485 Vector old_size(tl_-br_);
486 old_size[0]=abs(old_size[0]);
487 old_size[1]=abs(old_size[1]);
489 if(new_size[0]!=old_size[0])
490 w_=round_to_int(new_size[0]*w_/old_size[0]);
492 if(new_size[1]!=old_size[1])
493 h_=round_to_int(new_size[1]*h_/old_size[1]);
500 RendDesc::set_br(const Point &x)
502 if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
504 Vector new_size(x-tl_);
505 new_size[0]=abs(new_size[0]);
506 new_size[1]=abs(new_size[1]);
508 Vector old_size(tl_-br_);
509 old_size[0]=abs(old_size[0]);
510 old_size[1]=abs(old_size[1]);
512 if(new_size[0]!=old_size[0])
513 w_=round_to_int(new_size[0]*w_/old_size[0]);
515 if(new_size[1]!=old_size[1])
516 h_=round_to_int(new_size[1]*h_/old_size[1]);
522 RendDesc::set_viewport(const Point &__tl, const Point &__br)
523 { tl_=__tl; br_=__br; return *this; }
526 RendDesc::set_viewport(Vector::value_type a, Vector::value_type b, Vector::value_type c, Vector::value_type d)
527 { tl_=Point(a,b); br_=Point(c,d); return *this; }
530 RendDesc::get_pw()const
532 return (br_[0] - tl_[0]) / w_;
536 RendDesc::get_ph()const
538 return (br_[1] - tl_[1]) / h_;
542 RendDesc::set_subwindow(int x, int y, int w, int h)
544 const Real pw(get_pw());
545 const Real ph(get_ph());
550 br_[0]-=pw*(w_-(x+w));
551 br_[1]-=ph*(h_-(y+h));