1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
27 #define SYNFIG_NO_ANGLE
38 #include "target_scanline.h"
42 #include <Accelerate/Accelerate.h>
47 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 class target2surface : public synfig::Target_Scanline
61 target2surface(Surface *surface);
62 virtual ~target2surface();
64 virtual bool set_rend_desc(synfig::RendDesc *newdesc);
66 virtual bool start_frame(synfig::ProgressCallback *cb);
68 virtual void end_frame();
70 virtual Color * start_scanline(int scanline);
72 virtual bool end_scanline();
75 target2surface::target2surface(Surface *surface):surface(surface)
79 target2surface::~target2surface()
84 target2surface::set_rend_desc(synfig::RendDesc *newdesc)
89 return synfig::Target_Scanline::set_rend_desc(newdesc);
93 target2surface::start_frame(synfig::ProgressCallback *cb)
95 if(surface->get_w() != desc.get_w() || surface->get_h() != desc.get_h())
97 surface->set_wh(desc.get_w(),desc.get_h());
103 target2surface::end_frame()
109 target2surface::start_scanline(int scanline)
111 return (*surface)[scanline];
115 target2surface::end_scanline()
120 /* === P R O C E D U R E S ================================================= */
122 /* === M E T H O D S ======================================================= */
124 Target_Scanline::Handle
125 synfig::surface_target(Surface *surface)
127 return Target_Scanline::Handle(new target2surface(surface));
131 synfig::Surface::clear()
134 fill(Color(0.5,0.5,0.5,0.0000001));
136 etl::surface<Color, ColorAccumulator, ColorPrep>::clear();
141 synfig::Surface::blit_to(alpha_pen& pen, int x, int y, int w, int h)
143 static const float epsilon(0.00001);
144 const float alpha(pen.get_alpha());
145 if( pen.get_blend_method()==Color::BLEND_STRAIGHT && fabs(alpha-1.0f)<epsilon )
147 if(x>=get_w() || y>=get_w())
163 //clip width against dest width
164 w = min((long)w,(long)(pen.end_x()-pen.x()));
165 h = min((long)h,(long)(pen.end_y()-pen.y()));
167 //clip width against src width
168 w = min(w,get_w()-x);
169 h = min(h,get_h()-y);
176 char* src(static_cast<char*>(static_cast<void*>(operator[](y)+x))+i*get_w()*sizeof(Color));
177 char* dest(static_cast<char*>(static_cast<void*>(pen.x()))+i*pen.get_width()*sizeof(Color));
178 memcpy(dest,src,w*sizeof(Color));
184 if( pen.get_blend_method()==Color::BLEND_COMPOSITE && fabs(alpha-1.0f)<epsilon )
186 if(x>=get_w() || y>=get_w())
204 //clip width against dest width
205 w = min(w,pen.end_x()-pen.x());
206 h = min(h,pen.end_y()-pen.y());
208 //clip width against src width
209 w = min(w,get_w()-x);
210 h = min(h,get_h()-y);
217 vImage_Buffer top,bottom;
218 vImage_Buffer& dest(bottom);
220 top.data=static_cast<void*>(operator[](y)+x);
223 //top.rowBytes=get_w()*sizeof(Color); //! \fixme this should get the pitch!!
224 top.rowBytes=get_pitch();
226 bottom.data=static_cast<void*>(pen.x());
229 //bottom.rowBytes=pen.get_width()*sizeof(Color); //! \fixme this should get the pitch!!
230 bottom.rowBytes=pen.get_pitch(); //! \fixme this should get the pitch!!
233 ret=vImageAlphaBlend_ARGBFFFF(&top,&bottom,&dest,kvImageNoFlags);
235 assert(ret!=kvImageNoError);
240 etl::surface<Color, ColorAccumulator, ColorPrep>::blit_to(pen,x,y,w,h);