1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/renddesc.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
38 /* === U S I N G =========================================================== */
42 using namespace synfig;
44 /* === M A C R O S ========================================================= */
47 #define FLAGS(x,y) (((x)&(y))==(y))
49 /* === G L O B A L S ======================================================= */
51 /* === M E T H O D S ======================================================= */
54 RendDesc::apply(const RendDesc &x)
61 RendDesc::get_bg_color()const
67 RendDesc::set_bg_color(const Color &bg)
69 background=bg; return *this;
73 RendDesc::get_physical_w()const
75 return (Real)get_w()/get_x_res();
79 RendDesc::get_physical_h()const
81 return (Real)get_h()/get_y_res();
85 RendDesc::set_physical_w(Real w)
87 set_w(round_to_int(w*get_x_res()));
92 RendDesc::set_physical_h(Real h)
94 set_h(round_to_int(h*get_y_res()));
99 RendDesc::get_w()const
105 RendDesc::set_w(int x)
107 if(FLAGS(flags,LINK_PX_ASPECT)) // never set
112 else if(FLAGS(flags,LINK_PX_AREA)) // never set
117 else if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
120 float old_span=get_span();
122 // If we should preserve image width
123 if( FLAGS(flags,IM_W) // "Image Width"
124 || (FLAGS(flags,IM_ZOOMIN) && d[1]>d[1]/x*w_) // never set
125 || (FLAGS(flags,IM_ZOOMOUT) && d[1]<d[1]/x*w_)) // never set
145 if(FLAGS(flags,IM_SPAN)) // "Image Span"
148 else if(FLAGS(flags,PX_AREA)) // never set
160 RendDesc::get_h()const
166 RendDesc::set_h(int y)
168 if(FLAGS(flags,LINK_PX_ASPECT)) // never set
173 else if(FLAGS(flags,LINK_PX_AREA)) // never set
178 else if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
181 float old_span=get_span();
183 // If we should preserve image width
184 if( FLAGS(flags,IM_W) // "Image Width"
185 || (FLAGS(flags,IM_ZOOMIN) && d[0]>d[0]/y*h_) // never set
186 || (FLAGS(flags,IM_ZOOMOUT) && d[0]<d[0]/y*h_)) // never set
206 if(FLAGS(flags,IM_SPAN)) // "Image Span"
209 else if(FLAGS(flags,PX_AREA)) // never set
221 RendDesc::set_wh(int x, int y)
223 // FIXME: This is a working hack...
231 RendDesc::get_x_res()const
237 RendDesc::set_x_res(Real x)
239 x_res=x; return *this;
243 RendDesc::get_y_res()const
249 RendDesc::set_y_res(Real y)
251 y_res=y; return *this;
255 RendDesc::get_frame_start()const
257 return round_to_int(time_begin*frame_rate);
261 RendDesc::set_frame_start(int x)
263 return set_time_start(Time(x)/frame_rate);
267 RendDesc::get_frame_end()const
269 return round_to_int(time_end*frame_rate);
273 RendDesc::set_frame_end(int x)
275 return set_time_end(Time(x)/frame_rate);
280 RendDesc::get_time_start()const
286 RendDesc::set_time_start(Time x)
289 time_begin=time_end=x;
297 RendDesc::get_time_end()const
303 RendDesc::set_time_end(Time x)
306 time_end=time_begin=x;
313 RendDesc::set_time(Time x)
315 time_end=time_begin=x;
320 RendDesc::set_frame(int x)
322 return set_time(Time(x)/frame_rate);
326 RendDesc::get_frame_rate()const
332 RendDesc::set_frame_rate(float x)
339 RendDesc::get_interlaced()const
345 RendDesc::set_interlaced(bool x)
346 { interlaced=x; return *this; }
348 //! Return the status of the clamp flag
350 RendDesc::get_clamp()const
353 //! Set the clamp flag
355 RendDesc::set_clamp(bool x)
356 { clamp=x; return *this; }
358 //! Set constraint flags
360 RendDesc::set_flags(const int &x)
361 { flags=x; return *this; }
363 //! Clear constraint flags
365 RendDesc::clear_flags()
366 { flags=0; return *this; }
369 RendDesc::get_flags()const
373 //! Return the aspect ratio of a single pixel
375 RendDesc::get_pixel_aspect()const
386 //! Return the aspect ratio of the entire image
388 RendDesc::get_image_aspect()const
398 //! Return the antialias amount
400 RendDesc::get_antialias()const
403 //! Set the antialias amount
405 RendDesc::set_antialias(const int &x)
406 { a=x; return *this; }
409 //! Return the distance from the bottom-right to the top-left
411 RendDesc::get_span()const
413 return (br_-tl_).mag();
416 //! Set the span distance
418 RendDesc::set_span(const Real &x)
420 Vector::value_type ratio=x/get_span();
422 //! \todo this looks wrong. I suspect the intention was to check
423 // "(not IM_W) AND (not IM_H)", ie "not(IM_W OR IM_H)" but
424 // this check does "not(IM_W AND IM_H)"
425 if(!FLAGS(flags,IM_W|IM_H) || FLAGS(flags,IM_ASPECT)) // (not "Image Width") or (not "Image Height") or "Image Aspect"
434 else if(FLAGS(flags,IM_W)) // "Image Width"
436 //! \writeme or fix me
443 }else // IM_H // "Image Height"
445 //! \writeme or fix me
460 RendDesc::get_gamma()const
464 RendDesc::set_gamma(const Gamma &x)
465 { gamma=x; return *this; }
469 RendDesc::get_focus()const
473 RendDesc::set_focus(const Point &x)
474 { focus=x; return *this; }
478 RendDesc::get_tl()const
482 RendDesc::get_br()const
486 RendDesc::set_tl(const Point &x)
488 if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
490 Vector new_size(x-br_);
491 new_size[0]=abs(new_size[0]);
492 new_size[1]=abs(new_size[1]);
494 Vector old_size(tl_-br_);
495 old_size[0]=abs(old_size[0]);
496 old_size[1]=abs(old_size[1]);
498 if(new_size[0]!=old_size[0])
499 w_=round_to_int(new_size[0]*w_/old_size[0]);
501 if(new_size[1]!=old_size[1])
502 h_=round_to_int(new_size[1]*h_/old_size[1]);
509 RendDesc::set_br(const Point &x)
511 if(FLAGS(flags,PX_ASPECT)) // "Pixel Aspect"
513 Vector new_size(x-tl_);
514 new_size[0]=abs(new_size[0]);
515 new_size[1]=abs(new_size[1]);
517 Vector old_size(tl_-br_);
518 old_size[0]=abs(old_size[0]);
519 old_size[1]=abs(old_size[1]);
521 if(new_size[0]!=old_size[0])
522 w_=round_to_int(new_size[0]*w_/old_size[0]);
524 if(new_size[1]!=old_size[1])
525 h_=round_to_int(new_size[1]*h_/old_size[1]);
531 RendDesc::set_viewport(const Point &__tl, const Point &__br)
532 { tl_=__tl; br_=__br; return *this; }
535 RendDesc::set_viewport(Vector::value_type a, Vector::value_type b, Vector::value_type c, Vector::value_type d)
536 { tl_=Point(a,b); br_=Point(c,d); return *this; }
539 RendDesc::get_pw()const
541 return (br_[0] - tl_[0]) / w_;
545 RendDesc::get_ph()const
547 return (br_[1] - tl_[1]) / h_;
551 RendDesc::set_subwindow(int x, int y, int w, int h)
553 const Real pw(get_pw());
554 const Real ph(get_ph());
559 br_[0]-=pw*(w_-(x+w));
560 br_[1]-=ph*(h_-(y+h));