1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #define SYNFIG_NO_ANGLE
36 #include "target_scanline.h"
40 #include <Accelerate/Accelerate.h>
45 using namespace synfig;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 class target2surface : public synfig::Target_Scanline
59 target2surface(Surface *surface);
60 virtual ~target2surface();
62 virtual bool set_rend_desc(synfig::RendDesc *newdesc);
64 virtual bool start_frame(synfig::ProgressCallback *cb);
66 virtual void end_frame();
68 virtual Color * start_scanline(int scanline);
70 virtual bool end_scanline();
73 target2surface::target2surface(Surface *surface):surface(surface)
77 target2surface::~target2surface()
82 target2surface::set_rend_desc(synfig::RendDesc *newdesc)
87 return synfig::Target_Scanline::set_rend_desc(newdesc);
91 target2surface::start_frame(synfig::ProgressCallback *cb)
93 if(surface->get_w() != desc.get_w() || surface->get_h() != desc.get_h())
95 surface->set_wh(desc.get_w(),desc.get_h());
101 target2surface::end_frame()
107 target2surface::start_scanline(int scanline)
109 return (*surface)[scanline];
113 target2surface::end_scanline()
118 /* === P R O C E D U R E S ================================================= */
120 /* === M E T H O D S ======================================================= */
122 Target_Scanline::Handle
123 synfig::surface_target(Surface *surface)
125 return Target_Scanline::Handle(new target2surface(surface));
129 synfig::Surface::clear()
132 fill(Color(0.5,0.5,0.5,0.0000001));
134 etl::surface<Color, ColorAccumulator, ColorPrep>::clear();
139 synfig::Surface::blit_to(alpha_pen& pen, int x, int y, int w, int h)
141 static const float epsilon(0.00001);
142 const float alpha(pen.get_alpha());
143 if( pen.get_blend_method()==Color::BLEND_STRAIGHT && fabs(alpha-1.0f)<epsilon )
145 if(x>=get_w() || y>=get_w())
161 //clip width against dest width
162 w = min((long)w,(long)(pen.end_x()-pen.x()));
163 h = min((long)h,(long)(pen.end_y()-pen.y()));
165 //clip width against src width
166 w = min(w,get_w()-x);
167 h = min(h,get_h()-y);
174 char* src(static_cast<char*>(static_cast<void*>(operator[](y)+x))+i*get_w()*sizeof(Color));
175 char* dest(static_cast<char*>(static_cast<void*>(pen.x()))+i*pen.get_width()*sizeof(Color));
176 memcpy(dest,src,w*sizeof(Color));
182 if( pen.get_blend_method()==Color::BLEND_COMPOSITE && fabs(alpha-1.0f)<epsilon )
184 if(x>=get_w() || y>=get_w())
202 //clip width against dest width
203 w = min(w,pen.end_x()-pen.x());
204 h = min(h,pen.end_y()-pen.y());
206 //clip width against src width
207 w = min(w,get_w()-x);
208 h = min(h,get_h()-y);
215 vImage_Buffer top,bottom;
216 vImage_Buffer& dest(bottom);
218 top.data=static_cast<void*>(operator[](y)+x);
221 //top.rowBytes=get_w()*sizeof(Color); //! \fixme this should get the pitch!!
222 top.rowBytes=get_pitch();
224 bottom.data=static_cast<void*>(pen.x());
227 //bottom.rowBytes=pen.get_width()*sizeof(Color); //! \fixme this should get the pitch!!
228 bottom.rowBytes=pen.get_pitch(); //! \fixme this should get the pitch!!
231 ret=vImageAlphaBlend_ARGBFFFF(&top,&bottom,&dest,kvImageNoFlags);
233 assert(ret!=kvImageNoError);
238 etl::surface<Color, ColorAccumulator, ColorPrep>::blit_to(pen,x,y,w,h);