1 /* ========================================================================
4 ** $Id: surface.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
24 #define SYNFIG_NO_ANGLE
35 #include "target_scanline.h"
39 #include <Accelerate/Accelerate.h>
44 using namespace synfig;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 class target2surface : public synfig::Target_Scanline
58 target2surface(Surface *surface);
59 virtual ~target2surface();
61 virtual bool set_rend_desc(synfig::RendDesc *newdesc);
63 virtual bool start_frame(synfig::ProgressCallback *cb);
65 virtual void end_frame();
67 virtual Color * start_scanline(int scanline);
69 virtual bool end_scanline();
72 target2surface::target2surface(Surface *surface):surface(surface)
76 target2surface::~target2surface()
81 target2surface::set_rend_desc(synfig::RendDesc *newdesc)
86 return synfig::Target_Scanline::set_rend_desc(newdesc);
90 target2surface::start_frame(synfig::ProgressCallback *cb)
92 if(surface->get_w() != desc.get_w() || surface->get_h() != desc.get_h())
94 surface->set_wh(desc.get_w(),desc.get_h());
100 target2surface::end_frame()
106 target2surface::start_scanline(int scanline)
108 return (*surface)[scanline];
112 target2surface::end_scanline()
117 /* === P R O C E D U R E S ================================================= */
119 /* === M E T H O D S ======================================================= */
121 Target_Scanline::Handle
122 synfig::surface_target(Surface *surface)
124 return Target_Scanline::Handle(new target2surface(surface));
128 synfig::Surface::clear()
131 fill(Color(0.5,0.5,0.5,0.0000001));
133 etl::surface<Color, ColorAccumulator, ColorPrep>::clear();
138 synfig::Surface::blit_to(alpha_pen& pen, int x, int y, int w, int h)
140 static const float epsilon(0.00001);
141 const float alpha(pen.get_alpha());
142 if( pen.get_blend_method()==Color::BLEND_STRAIGHT && fabs(alpha-1.0f)<epsilon )
144 if(x>=get_w() || y>=get_w())
160 //clip width against dest width
161 w = min(w,pen.end_x()-pen.x());
162 h = min(h,pen.end_y()-pen.y());
164 //clip width against src width
165 w = min(w,get_w()-x);
166 h = min(h,get_h()-y);
173 char* src(static_cast<char*>(static_cast<void*>(operator[](y)+x))+i*get_w()*sizeof(Color));
174 char* dest(static_cast<char*>(static_cast<void*>(pen.x()))+i*pen.get_width()*sizeof(Color));
175 memcpy(dest,src,w*sizeof(Color));
181 if( pen.get_blend_method()==Color::BLEND_COMPOSITE && fabs(alpha-1.0f)<epsilon )
183 if(x>=get_w() || y>=get_w())
201 //clip width against dest width
202 w = min(w,pen.end_x()-pen.x());
203 h = min(h,pen.end_y()-pen.y());
205 //clip width against src width
206 w = min(w,get_w()-x);
207 h = min(h,get_h()-y);
214 vImage_Buffer top,bottom;
215 vImage_Buffer& dest(bottom);
217 top.data=static_cast<void*>(operator[](y)+x);
220 //top.rowBytes=get_w()*sizeof(Color); //! \fixme this should get the pitch!!
221 top.rowBytes=get_pitch();
223 bottom.data=static_cast<void*>(pen.x());
226 //bottom.rowBytes=pen.get_width()*sizeof(Color); //! \fixme this should get the pitch!!
227 bottom.rowBytes=pen.get_pitch(); //! \fixme this should get the pitch!!
230 ret=vImageAlphaBlend_ARGBFFFF(&top,&bottom,&dest,kvImageNoFlags);
232 assert(ret!=kvImageNoError);
237 etl::surface<Color, ColorAccumulator, ColorPrep>::blit_to(pen,x,y,w,h);