X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Frender.cpp;fp=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Frender.cpp;h=acfcbe325f864b97577536ed24b581f321bf3190;hb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;hp=0000000000000000000000000000000000000000;hpb=ced68168d8518aac837f20e73bcd1e84a6bd6178;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/render.cpp b/synfig-core/trunk/src/synfig/render.cpp new file mode 100644 index 0000000..acfcbe3 --- /dev/null +++ b/synfig-core/trunk/src/synfig/render.cpp @@ -0,0 +1,525 @@ +/* === S I N F G =========================================================== */ +/*! \file render.cpp +** \brief Renderer +** +** $Id: render.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $ +** +** \legal +** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** +** This software and associated documentation +** are CONFIDENTIAL and PROPRIETARY property of +** the above-mentioned copyright holder. +** +** You may not copy, print, publish, or in any +** other way distribute this software without +** a prior written agreement with +** the copyright holder. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#define SINFG_NO_ANGLE + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef WIN32 +#include +#include +#include +#endif + +#include "render.h" +#include "target.h" +#include "canvas.h" +#include +#include +#include "context.h" +#include "surface.h" + +#endif + +using namespace std; +using namespace sinfg; +using namespace etl; + +/* === M A C R O S ========================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +bool +sinfg::parametric_render( + Context context, + Surface &surface, + const RendDesc &desc, + ProgressCallback *callback +) +{ + Point::value_type + u,v, // Current location in image + su,sv, // Starting locations + du, dv, // Distance between pixels + dsu,dsv; // Distance between subpixels + + bool + no_clamp=!desc.get_clamp(); + + int + w(desc.get_w()), + h(desc.get_h()), + a(desc.get_antialias()); + + Point + tl(desc.get_tl()), + br(desc.get_br()); + + //Gamma + // gamma(desc.get_gamma()); + + int + x,y, // Current location on output bitmap + x2,y2; // Subpixel counters + + Color::value_type + pool; // Alpha pool (for correct alpha antialiasing) + + // Calculate the number of channels + //chan=channels(desc.get_pixel_format()); + + // Calculate the distance between pixels + du=(br[0]-tl[0])/(Point::value_type)w; + dv=(br[1]-tl[1])/(Point::value_type)h; + + // Calculate the distance between sub pixels + dsu=du/(Point::value_type)a; + dsv=dv/(Point::value_type)a; + + // Calculate the starting points + //su=tl[0]+(du-dsu)/(Point::value_type)2.0; + //sv=tl[1]-(dv-dsv)/(Point::value_type)2.0; + su=tl[0]; + sv=tl[1]; + + surface.set_wh(desc.get_w(),desc.get_h()); + + assert(surface); + + // Loop through all horizontal lines + for(y=0,v=sv;yamount_complete(y,h) == false ) + { + // If the callback returns false, + // then the render has been aborted. + + return false; + } + + // Loop through every pixel in row + for(x=0,u=su;xamount_complete(h,h); + + // Report our success + return(true); +} + +bool +sinfg::render( + Context context, + Target_Scanline::Handle target, + const RendDesc &desc, + ProgressCallback *callback) +{ + Point::value_type + u,v, // Current location in image + su,sv, // Starting locations + du, dv, // Distance between pixels + dsu,dsv; // Distance between subpixels + + bool + no_clamp=!desc.get_clamp(); + + int + w(desc.get_w()), + h(desc.get_h()), + a(desc.get_antialias()); + + Point + tl(desc.get_tl()), + br(desc.get_br()); + + //Gamma + // gamma(desc.get_gamma()); + + int + x,y, // Current location on output bitmap + x2,y2; // Subpixel counters + + Color::value_type + pool; // Alpha pool (for correct alpha antialiasing) + + assert(target); + + // If we do not have a a target then bail + if(!target) + return false; + + // Calculate the number of channels + //chan=channels(desc.get_pixel_format()); + + // Calculate the distance between pixels + du=(br[0]-tl[0])/(Point::value_type)w; + dv=(br[1]-tl[1])/(Point::value_type)h; + + // Calculate the distance between sub pixels + dsu=du/(Point::value_type)a; + dsv=dv/(Point::value_type)a; + + // Calculate the starting points + su=tl[0]+(du-dsu)/(Point::value_type)2.0; + sv=tl[1]-(dv-dsv)/(Point::value_type)2.0; + + // Mark the start of a new frame. + if(!target->start_frame(callback)) + return false; + + // Loop through all horizontal lines + for(y=0,v=sv;ystart_scanline(y); + + if(!colordata) + { + if(callback)callback->error(_("Target panic")); + else throw(string(_("Target panic"))); + return false; + } + + // If we have a callback that we need + // to report to, do so now. + if(callback) + if( callback->amount_complete(y,h) == false ) + { + // If the callback returns false, + // then the render has been aborted. + // Exit gracefuly. + + target->end_scanline(); + target->end_frame(); + return false; + } + + // Loop through every pixel in row + for(x=0,u=su;xend_scanline()) + { + if(callback)callback->error(_("Target panic")); + else throw(string(_("Target panic"))); + return false; + } + } + + // Finish up the target's frame + target->end_frame(); + + // Give the callback one more last call, + // this time with the full height as the + // current line + if(callback) + callback->amount_complete(h,h); + + // Report our success + return(true); +} + +bool +sinfg::render_threaded( + Context context, + Target_Scanline::Handle target, + const RendDesc &desc, + ProgressCallback *callback, + int threads) +{ +#ifndef WIN32 + struct _render_thread + { + int + pipe_read, + pipe_write, + pid; + _render_thread() + { + pipe(&pipe_read); + pid=0; + } + ~_render_thread() + { + close(pipe_read); + close(pipe_write); + if(pid) + { + kill(pid,9); + } + } + } *render_thread; + + int i, mythread=-1; + + Point::value_type + u,v, // Current location in image + su,sv, // Starting locations + du, dv, // Distance between pixels + dsu,dsv; // Distance between subpixels + + bool + no_clamp=!desc.get_clamp(); + + int + w(desc.get_w()), + h(desc.get_h()), + a(desc.get_antialias()); + + Point + tl(desc.get_tl()), + br(desc.get_br()); + + int + x,y, // Current location on output bitmap + x2,y2; // Subpixel counters + + Color::value_type + pool; // Alpha pool (for correct alpha antialiasing) + + assert(target); + + // If we do not have a a target then bail + if(!target) + return false; + + // Calculate the distance between pixels + du=(br[0]-tl[0])/(Point::value_type)w; + dv=(br[1]-tl[1])/(Point::value_type)h; + + // Calculate the distance between sub pixels + dsu=du/(Point::value_type)a; + dsv=dv/(Point::value_type)a; + + // Calculate the starting points + su=tl[0]+(du-dsu)/(Point::value_type)2.0; + sv=tl[1]-(dv-dsv)/(Point::value_type)2.0; + + render_thread=new _render_thread[threads]; + + // Start the forks + for(i=0;istart_frame(callback)) + return false; + + for(y=0;ystart_scanline(y)); + + if(!colordata) + { + if(callback)callback->error(_("Target panic")); + else throw(string(_("Target panic"))); + return false; + } + + // If we have a callback that we need + // to report to, do so now. + if(callback) + if( callback->amount_complete(y,h) == false ) + { + // If the callback returns false, + // then the render has been aborted. + // Exit gracefuly. + + target->end_scanline(); + target->end_frame(); + delete [] render_thread; + return false; + } + + read(render_thread[y%threads].pipe_read,colordata,w*sizeof(Color)); + + // Send the buffer to the render target. + // If anything goes wrong, cleanup and bail. + if(!target->end_scanline()) + { + delete [] render_thread; + if(callback)callback->error(_("Target panic")); + else throw(string(_("Target panic"))); + return false; + } + } + + // Finish up the target's frame + target->end_frame(); + + // Give the callback one more last call, + // this time with the full height as the + // current line + if(callback) + callback->amount_complete(h,h); + + delete [] render_thread; + return true; + +renderthread: + + // Change the random seed, so that each thread has a different one + srand(mythread*20+threads+time(0)); + + Color *buffer(new Color[w]); + + // Loop through all horizontal lines + for(y=mythread,v=sv+dv*(Real)mythread;y