Merged changes in the trunk up to revision 47977.
[blender.git] / source / blender / render / intern / source / pipeline.c
index c37d7e0e5d8a35fb8b2564288f93ef343337665c..a730868dadd676a710f38832d9d8850f287d5498 100644 (file)
@@ -45,7 +45,7 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "BKE_animsys.h"       /* <------ should this be here?, needed for sequencer update */
+#include "BKE_animsys.h"  /* <------ should this be here?, needed for sequencer update */
 #include "BKE_camera.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
@@ -57,7 +57,7 @@
 #include "BKE_scene.h"
 #include "BKE_sequencer.h"
 #include "BKE_utildefines.h"
-#include "BKE_writeavi.h"      /* <------ should be replaced once with generic movie module */
+#include "BKE_writeavi.h"  /* <------ should be replaced once with generic movie module */
 
 #include "BLI_math.h"
 #include "BLI_listbase.h"
@@ -130,7 +130,7 @@ Render R;
 
 static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovieHandle *mh, const char *name_override);
 
-static volatile int g_break= 0;
+static volatile int g_break = 0;
 static int thread_break(void *UNUSED(arg))
 {
        return g_break;
@@ -148,13 +148,13 @@ static void stats_background(void *UNUSED(arg), RenderStats *rs)
        uintptr_t mem_in_use, mmap_in_use, peak_memory;
        float megs_used_memory, mmap_used_memory, megs_peak_memory;
 
-       mem_in_use= MEM_get_memory_in_use();
-       mmap_in_use= MEM_get_mapped_memory_in_use();
+       mem_in_use = MEM_get_memory_in_use();
+       mmap_in_use = MEM_get_mapped_memory_in_use();
        peak_memory = MEM_get_peak_memory();
 
-       megs_used_memory= (mem_in_use-mmap_in_use)/(1024.0*1024.0);
-       mmap_used_memory= (mmap_in_use)/(1024.0*1024.0);
-       megs_peak_memory = (peak_memory)/(1024.0*1024.0);
+       megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0);
+       mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0);
+       megs_peak_memory = (peak_memory) / (1024.0 * 1024.0);
 
        fprintf(stdout, "Fra:%d Mem:%.2fM (%.2fM, peak %.2fM) ", rs->cfra,
                megs_used_memory, mmap_used_memory, megs_peak_memory);
@@ -189,8 +189,8 @@ float *RE_RenderLayerGetPass(RenderLayer *rl, int passtype)
 {
        RenderPass *rpass;
        
-       for (rpass=rl->passes.first; rpass; rpass= rpass->next)
-               if (rpass->passtype== passtype)
+       for (rpass = rl->passes.first; rpass; rpass = rpass->next)
+               if (rpass->passtype == passtype)
                        return rpass->rect;
        return NULL;
 }
@@ -199,10 +199,10 @@ RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name)
 {
        RenderLayer *rl;
        
-       if (rr==NULL) return NULL;
+       if (rr == NULL) return NULL;
        
-       for (rl= rr->layers.first; rl; rl= rl->next)
-               if (strncmp(rl->name, name, RE_MAXNAME)==0)
+       for (rl = rr->layers.first; rl; rl = rl->next)
+               if (strncmp(rl->name, name, RE_MAXNAME) == 0)
                        return rl;
        return NULL;
 }
@@ -214,7 +214,7 @@ RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty)
 
 RenderLayer *render_get_active_layer(Render *re, RenderResult *rr)
 {
-       RenderLayer *rl= BLI_findlink(&rr->layers, re->r.actlay);
+       RenderLayer *rl = BLI_findlink(&rr->layers, re->r.actlay);
        
        if (rl)
                return rl;
@@ -226,7 +226,7 @@ static int render_scene_needs_vector(Render *re)
 {
        SceneRenderLayer *srl;
        
-       for (srl= re->scene->r.layers.first; srl; srl= srl->next)
+       for (srl = re->scene->r.layers.first; srl; srl = srl->next)
                if (!(srl->layflag & SCE_LAY_DISABLE))
                        if (srl->passflag & SCE_PASS_VECTOR)
                                return 1;
@@ -241,8 +241,8 @@ Render *RE_GetRender(const char *name)
        Render *re;
 
        /* search for existing renders */
-       for (re= RenderGlobal.renderlist.first; re; re= re->next)
-               if (strncmp(re->name, name, RE_MAXNAME)==0)
+       for (re = RenderGlobal.renderlist.first; re; re = re->next)
+               if (strncmp(re->name, name, RE_MAXNAME) == 0)
                        break;
 
        return re;
@@ -273,7 +273,7 @@ void RE_SwapResult(Render *re, RenderResult **rr)
 {
        /* for keeping render buffers */
        if (re) {
-               SWAP(RenderResult*, re->result, *rr);
+               SWAP(RenderResult *, re->result, *rr);
        }
 }
 
@@ -303,25 +303,25 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr)
                if (re->result) {
                        RenderLayer *rl;
                        
-                       rr->rectx= re->result->rectx;
-                       rr->recty= re->result->recty;
+                       rr->rectx = re->result->rectx;
+                       rr->recty = re->result->recty;
                        
-                       rr->rectf= re->result->rectf;
-                       rr->rectz= re->result->rectz;
-                       rr->rect32= re->result->rect32;
+                       rr->rectf = re->result->rectf;
+                       rr->rectz = re->result->rectz;
+                       rr->rect32 = re->result->rect32;
                        
                        /* active layer */
-                       rl= render_get_active_layer(re, re->result);
+                       rl = render_get_active_layer(re, re->result);
 
                        if (rl) {
-                               if (rr->rectf==NULL)
-                                       rr->rectf= rl->rectf;
-                               if (rr->rectz==NULL)
-                                       rr->rectz= RE_RenderLayerGetPass(rl, SCE_PASS_Z);       
+                               if (rr->rectf == NULL)
+                                       rr->rectf = rl->rectf;
+                               if (rr->rectz == NULL)
+                                       rr->rectz = RE_RenderLayerGetPass(rl, SCE_PASS_Z);
                        }
 
-                       rr->have_combined= (re->result->rectf != NULL);
-                       rr->layers= re->result->layers;
+                       rr->have_combined = (re->result->rectf != NULL);
+                       rr->layers = re->result->layers;
                }
        }
 }
@@ -352,11 +352,11 @@ Render *RE_NewRender(const char *name)
        Render *re;
 
        /* only one render per name exists */
-       re= RE_GetRender(name);
-       if (re==NULL) {
+       re = RE_GetRender(name);
+       if (re == NULL) {
                
                /* new render data struct */
-               re= MEM_callocN(sizeof(Render), "new render");
+               re = MEM_callocN(sizeof(Render), "new render");
                BLI_addtail(&RenderGlobal.renderlist, re);
                BLI_strncpy(re->name, name, RE_MAXNAME);
                BLI_rw_mutex_init(&re->resultmutex);
@@ -365,7 +365,7 @@ Render *RE_NewRender(const char *name)
        RE_InitRenderCB(re);
 
        /* init some variables */
-       re->ycor= 1.0f;
+       re->ycor = 1.0f;
        
        return re;
 }
@@ -375,17 +375,17 @@ Render *RE_NewRender(const char *name)
 void RE_InitRenderCB(Render *re)
 {
        /* set default empty callbacks */
-       re->display_init= result_nothing;
-       re->display_clear= result_nothing;
-       re->display_draw= result_rcti_nothing;
-       re->progress= float_nothing;
-       re->test_break= default_break;
+       re->display_init = result_nothing;
+       re->display_clear = result_nothing;
+       re->display_draw = result_rcti_nothing;
+       re->progress = float_nothing;
+       re->test_break = default_break;
        if (G.background)
-               re->stats_draw= stats_background;
+               re->stats_draw = stats_background;
        else
-               re->stats_draw= stats_nothing;
+               re->stats_draw = stats_nothing;
        /* clear callback handles */
-       re->dih= re->dch= re->ddh= re->sdh= re->prh= re->tbh= NULL;
+       re->dih = re->dch = re->ddh = re->sdh = re->prh = re->tbh = NULL;
 }
 
 /* only call this while you know it will remove the link too */
@@ -432,66 +432,66 @@ void RE_FreeAllRenderResults(void)
 /* disprect is optional, if NULL it assumes full window render */
 void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer *srl, int winx, int winy, rcti *disprect)
 {
-       re->ok= TRUE;   /* maybe flag */
+       re->ok = TRUE;   /* maybe flag */
        
-       re->i.starttime= PIL_check_seconds_timer();
-       re->r= *rd;             /* hardcopy */
+       re->i.starttime = PIL_check_seconds_timer();
+       re->r = *rd;     /* hardcopy */
        
-       re->winx= winx;
-       re->winy= winy;
+       re->winx = winx;
+       re->winy = winy;
        if (disprect) {
-               re->disprect= *disprect;
-               re->rectx= disprect->xmax-disprect->xmin;
-               re->recty= disprect->ymax-disprect->ymin;
+               re->disprect = *disprect;
+               re->rectx = disprect->xmax - disprect->xmin;
+               re->recty = disprect->ymax - disprect->ymin;
        }
        else {
                re->disprect.xmin = re->disprect.ymin = 0;
                re->disprect.xmax = winx;
                re->disprect.ymax = winy;
-               re->rectx= winx;
-               re->recty= winy;
+               re->rectx = winx;
+               re->recty = winy;
        }
        
        if (re->rectx < 2 || re->recty < 2 || (BKE_imtype_is_movie(rd->im_format.imtype) &&
                                               (re->rectx < 16 || re->recty < 16) ))
        {
                BKE_report(re->reports, RPT_ERROR, "Image too small");
-               re->ok= 0;
+               re->ok = 0;
                return;
        }
 
-       if ((re->r.mode & (R_OSA))==0)
+       if ((re->r.mode & (R_OSA)) == 0)
                re->r.scemode &= ~R_FULL_SAMPLE;
 
 #ifdef WITH_OPENEXR
        if (re->r.scemode & R_FULL_SAMPLE)
-               re->r.scemode |= R_EXR_TILE_FILE;       /* enable automatic */
+               re->r.scemode |= R_EXR_TILE_FILE;   /* enable automatic */
 
        /* Until use_border is made compatible with save_buffers/full_sample, render without the later instead of not rendering at all.*/
        if (re->r.mode & R_BORDER) {
-               re->r.scemode &= ~(R_EXR_TILE_FILE|R_FULL_SAMPLE);
+               re->r.scemode &= ~(R_EXR_TILE_FILE | R_FULL_SAMPLE);
        }
 
 #else
        /* can't do this without openexr support */
-       re->r.scemode &= ~(R_EXR_TILE_FILE|R_FULL_SAMPLE);
+       re->r.scemode &= ~(R_EXR_TILE_FILE | R_FULL_SAMPLE);
 #endif
        
        /* fullsample wants uniform osa levels */
        if (source && (re->r.scemode & R_FULL_SAMPLE)) {
                /* but, if source has no full sample we disable it */
-               if ((source->r.scemode & R_FULL_SAMPLE)==0)
+               if ((source->r.scemode & R_FULL_SAMPLE) == 0)
                        re->r.scemode &= ~R_FULL_SAMPLE;
                else
-                       re->r.osa= re->osa= source->osa;
+                       re->r.osa = re->osa = source->osa;
        }
        else {
                /* check state variables, osa? */
                if (re->r.mode & (R_OSA)) {
-                       re->osa= re->r.osa;
-                       if (re->osa>16) re->osa= 16;
+                       re->osa = re->r.osa;
+                       if (re->osa > 16) re->osa = 16;
                }
-               else re->osa= 0;
+               else re->osa = 0;
        }
        
        if (srl) {
@@ -509,25 +509,25 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer *
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 
        if (re->r.scemode & R_PREVIEWBUTS) {
-               if (re->result && re->result->rectx==re->rectx && re->result->recty==re->recty);
+               if (re->result && re->result->rectx == re->rectx && re->result->recty == re->recty) ;
                else {
                        render_result_free(re->result);
-                       re->result= NULL;
+                       re->result = NULL;
                }
        }
        else {
                
                /* make empty render result, so display callbacks can initialize */
                render_result_free(re->result);
-               re->result= MEM_callocN(sizeof(RenderResult), "new render result");
-               re->result->rectx= re->rectx;
-               re->result->recty= re->recty;
+               re->result = MEM_callocN(sizeof(RenderResult), "new render result");
+               re->result->rectx = re->rectx;
+               re->result->recty = re->recty;
        }
 
        BLI_rw_mutex_unlock(&re->resultmutex);
        
        /* we clip faces with a minimum of 2 pixel boundary outside of image border. see zbuf.c */
-       re->clipcrop= 1.0f + 2.0f/(float)(re->winx>re->winy?re->winy:re->winx);
+       re->clipcrop = 1.0f + 2.0f / (float)(re->winx > re->winy ? re->winy : re->winx);
        
        re->mblur_offs = re->field_offs = 0.f;
        
@@ -538,9 +538,9 @@ void RE_SetWindow(Render *re, rctf *viewplane, float clipsta, float clipend)
 {
        /* re->ok flag? */
        
-       re->viewplane= *viewplane;
-       re->clipsta= clipsta;
-       re->clipend= clipend;
+       re->viewplane = *viewplane;
+       re->clipsta = clipsta;
+       re->clipend = clipend;
        re->r.mode &= ~R_ORTHO;
 
        perspective_m4(re->winmat,
@@ -553,9 +553,9 @@ void RE_SetOrtho(Render *re, rctf *viewplane, float clipsta, float clipend)
 {
        /* re->ok flag? */
        
-       re->viewplane= *viewplane;
-       re->clipsta= clipsta;
-       re->clipend= clipend;
+       re->viewplane = *viewplane;
+       re->clipsta = clipsta;
+       re->clipend = clipend;
        re->r.mode |= R_ORTHO;
 
        orthographic_m4(re->winmat,
@@ -573,40 +573,40 @@ void RE_SetView(Render *re, float mat[][4])
 /* image and movie output has to move to either imbuf or kernel */
 void RE_display_init_cb(Render *re, void *handle, void (*f)(void *handle, RenderResult *rr))
 {
-       re->display_init= f;
-       re->dih= handle;
+       re->display_init = f;
+       re->dih = handle;
 }
 void RE_display_clear_cb(Render *re, void *handle, void (*f)(void *handle, RenderResult *rr))
 {
-       re->display_clear= f;
-       re->dch= handle;
+       re->display_clear = f;
+       re->dch = handle;
 }
 void RE_display_draw_cb(Render *re, void *handle, void (*f)(void *handle, RenderResult *rr, volatile rcti *rect))
 {
-       re->display_draw= f;
-       re->ddh= handle;
+       re->display_draw = f;
+       re->ddh = handle;
 }
 void RE_stats_draw_cb(Render *re, void *handle, void (*f)(void *handle, RenderStats *rs))
 {
-       re->stats_draw= f;
-       re->sdh= handle;
+       re->stats_draw = f;
+       re->sdh = handle;
 }
 void RE_progress_cb(Render *re, void *handle, void (*f)(void *handle, float))
 {
-       re->progress= f;
-       re->prh= handle;
+       re->progress = f;
+       re->prh = handle;
 }
 
 void RE_draw_lock_cb(Render *re, void *handle, void (*f)(void *handle, int i))
 {
-       re->draw_lock= f;
-       re->tbh= handle;
+       re->draw_lock = f;
+       re->tbh = handle;
 }
 
 void RE_test_break_cb(Render *re, void *handle, int (*f)(void *handle))
 {
-       re->test_break= f;
-       re->tbh= handle;
+       re->test_break = f;
+       re->tbh = handle;
 }
 
 
@@ -635,15 +635,15 @@ static int render_display_draw_enabled(Render *re)
 /* the main thread call, renders an entire part */
 static void *do_part_thread(void *pa_v)
 {
-       RenderPart *pa= pa_v;
+       RenderPart *pa = pa_v;
        
        /* need to return nicely all parts on esc */
-       if (R.test_break(R.tbh)==0) {
+       if (R.test_break(R.tbh) == 0) {
                
                if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE))
-                       pa->result= render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM);
+                       pa->result = render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM);
                else
-                       pa->result= render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM);
+                       pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM);
 
                if (R.sss_points)
                        zbufshade_sss_tile(pa);
@@ -658,12 +658,12 @@ static void *do_part_thread(void *pa_v)
                }
                else if (render_display_draw_enabled(&R)) {
                        /* on break, don't merge in result for preview renders, looks nicer */
-                       if (R.test_break(R.tbh) && (R.r.scemode & R_PREVIEWBUTS));
+                       if (R.test_break(R.tbh) && (R.r.scemode & R_PREVIEWBUTS)) ;
                        else render_result_merge(R.result, pa->result);
                }
        }
        
-       pa->ready= 1;
+       pa->ready = 1;
        
        return NULL;
 }
@@ -674,21 +674,21 @@ static void *do_part_thread(void *pa_v)
 float panorama_pixel_rot(Render *re)
 {
        float psize, phi, xfac;
-       float borderfac= (float)(re->disprect.xmax - re->disprect.xmin) / (float)re->winx;
+       float borderfac = (float)(re->disprect.xmax - re->disprect.xmin) / (float)re->winx;
        
        /* size of 1 pixel mapped to viewplane coords */
-       psize= (re->viewplane.xmax-re->viewplane.xmin)/(float)(re->winx);
+       psize = (re->viewplane.xmax - re->viewplane.xmin) / (float)(re->winx);
        /* angle of a pixel */
-       phi= atan(psize/re->clipsta);
+       phi = atan(psize / re->clipsta);
        
        /* correction factor for viewplane shifting, first calculate how much the viewplane angle is */
-       xfac= borderfac*((re->viewplane.xmax-re->viewplane.xmin))/(float)re->xparts;
-       xfac= atan(0.5f*xfac/re->clipsta); 
+       xfac = borderfac * ((re->viewplane.xmax - re->viewplane.xmin)) / (float)re->xparts;
+       xfac = atan(0.5f * xfac / re->clipsta);
        /* and how much the same viewplane angle is wrapped */
-       psize= 0.5f*phi*((float)re->partx);
+       psize = 0.5f * phi * ((float)re->partx);
        
        /* the ratio applied to final per-pixel angle */
-       phi*= xfac/psize;
+       phi *= xfac / psize;
        
        return phi;
 }
@@ -697,25 +697,25 @@ float panorama_pixel_rot(Render *re)
 /* if slice found, it rotates the dbase */
 static RenderPart *find_next_pano_slice(Render *re, int *minx, rctf *viewplane)
 {
-       RenderPart *pa, *best= NULL;
+       RenderPart *pa, *best = NULL;
        
-       *minx= re->winx;
+       *minx = re->winx;
        
        /* most left part of the non-rendering parts */
-       for (pa= re->parts.first; pa; pa= pa->next) {
-               if (pa->ready==0 && pa->nr==0) {
+       for (pa = re->parts.first; pa; pa = pa->next) {
+               if (pa->ready == 0 && pa->nr == 0) {
                        if (pa->disprect.xmin < *minx) {
-                               best= pa;
-                               *minx= pa->disprect.xmin;
+                               best = pa;
+                               *minx = pa->disprect.xmin;
                        }
                }
        }
                        
        if (best) {
-               float phi= panorama_pixel_rot(re);
+               float phi = panorama_pixel_rot(re);
 
-               R.panodxp= (re->winx - (best->disprect.xmin + best->disprect.xmax) )/2;
-               R.panodxv= ((viewplane->xmax-viewplane->xmin)*R.panodxp)/(float)(re->winx);
+               R.panodxp = (re->winx - (best->disprect.xmin + best->disprect.xmax) ) / 2;
+               R.panodxv = ((viewplane->xmax - viewplane->xmin) * R.panodxp) / (float)(re->winx);
                
                /* shift viewplane */
                R.viewplane.xmin = viewplane->xmin + R.panodxv;
@@ -724,48 +724,48 @@ static RenderPart *find_next_pano_slice(Render *re, int *minx, rctf *viewplane)
                copy_m4_m4(R.winmat, re->winmat);
                
                /* rotate database according to part coordinates */
-               project_renderdata(re, projectverto, 1, -R.panodxp*phi, 1);
-               R.panosi= sin(R.panodxp*phi);
-               R.panoco= cos(R.panodxp*phi);
+               project_renderdata(re, projectverto, 1, -R.panodxp * phi, 1);
+               R.panosi = sin(R.panodxp * phi);
+               R.panoco = cos(R.panodxp * phi);
        }
        return best;
 }
 
 static RenderPart *find_next_part(Render *re, int minx)
 {
-       RenderPart *pa, *best= NULL;
+       RenderPart *pa, *best = NULL;
 
        /* long long int's needed because of overflow [#24414] */
-       long long int centx=re->winx/2, centy=re->winy/2, tot=1;
-       long long int mindist= (long long int)re->winx * (long long int)re->winy;
+       long long int centx = re->winx / 2, centy = re->winy / 2, tot = 1;
+       long long int mindist = (long long int)re->winx * (long long int)re->winy;
        
        /* find center of rendered parts, image center counts for 1 too */
-       for (pa= re->parts.first; pa; pa= pa->next) {
+       for (pa = re->parts.first; pa; pa = pa->next) {
                if (pa->ready) {
-                       centx+= (pa->disprect.xmin+pa->disprect.xmax)/2;
-                       centy+= (pa->disprect.ymin+pa->disprect.ymax)/2;
+                       centx += (pa->disprect.xmin + pa->disprect.xmax) / 2;
+                       centy += (pa->disprect.ymin + pa->disprect.ymax) / 2;
                        tot++;
                }
        }
-       centx/=tot;
-       centy/=tot;
+       centx /= tot;
+       centy /= tot;
        
        /* closest of the non-rendering parts */
-       for (pa= re->parts.first; pa; pa= pa->next) {
-               if (pa->ready==0 && pa->nr==0) {
-                       long long int distx= centx - (pa->disprect.xmin+pa->disprect.xmax)/2;
-                       long long int disty= centy - (pa->disprect.ymin+pa->disprect.ymax)/2;
-                       distx= (long long int)sqrt(distx*distx + disty*disty);
-                       if (distx<mindist) {
+       for (pa = re->parts.first; pa; pa = pa->next) {
+               if (pa->ready == 0 && pa->nr == 0) {
+                       long long int distx = centx - (pa->disprect.xmin + pa->disprect.xmax) / 2;
+                       long long int disty = centy - (pa->disprect.ymin + pa->disprect.ymax) / 2;
+                       distx = (long long int)sqrt(distx * distx + disty * disty);
+                       if (distx < mindist) {
                                if (re->r.mode & R_PANORAMA) {
-                                       if (pa->disprect.xmin==minx) {
-                                               best= pa;
-                                               mindist= distx;
+                                       if (pa->disprect.xmin == minx) {
+                                               best = pa;
+                                               mindist = distx;
                                        }
                                }
                                else {
-                                       best= pa;
-                                       mindist= distx;
+                                       best = pa;
+                                       mindist = distx;
                                }
                        }
                }
@@ -777,37 +777,37 @@ static void print_part_stats(Render *re, RenderPart *pa)
 {
        char str[64];
        
-       BLI_snprintf(str, sizeof(str), "%s, Part %d-%d", re->scene->id.name+2, pa->nr, re->i.totpart);
-       re->i.infostr= str;
+       BLI_snprintf(str, sizeof(str), "%s, Part %d-%d", re->scene->id.name + 2, pa->nr, re->i.totpart);
+       re->i.infostr = str;
        re->stats_draw(re->sdh, &re->i);
-       re->i.infostr= NULL;
+       re->i.infostr = NULL;
 }
 
 static void threaded_tile_processor(Render *re)
 {
        ListBase threads;
        RenderPart *pa, *nextpa;
-       rctf viewplane= re->viewplane;
-       int rendering=1, counter= 1, drawtimer=0, hasdrawn, minx=0;
+       rctf viewplane = re->viewplane;
+       int rendering = 1, counter = 1, drawtimer = 0, hasdrawn, minx = 0;
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 
        /* first step; free the entire render result, make new, and/or prepare exr buffer saving */
-       if (re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
+       if (re->result == NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
                render_result_free(re->result);
        
                if (re->sss_points && render_display_draw_enabled(re))
-                       re->result= render_result_new(re, &re->disprect, 0, RR_USE_MEM);
+                       re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
                else if (re->r.scemode & R_FULL_SAMPLE)
-                       re->result= render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR);
+                       re->result = render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR);
                else
-                       re->result= render_result_new(re, &re->disprect, 0,
-                               (re->r.scemode & R_EXR_TILE_FILE)? RR_USE_EXR: RR_USE_MEM);
+                       re->result = render_result_new(re, &re->disprect, 0,
+                                                      (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM);
        }
 
        BLI_rw_mutex_unlock(&re->resultmutex);
        
-       if (re->result==NULL)
+       if (re->result == NULL)
                return;
        
        /* warning; no return here without closing exr file */
@@ -820,32 +820,32 @@ static void threaded_tile_processor(Render *re)
        BLI_init_threads(&threads, do_part_thread, re->r.threads);
        
        /* assuming no new data gets added to dbase... */
-       R= *re;
+       R = *re;
        
        /* set threadsafe break */
-       R.test_break= thread_break;
+       R.test_break = thread_break;
        
        /* timer loop demands to sleep when no parts are left, so we enter loop with a part */
        if (re->r.mode & R_PANORAMA)
-               nextpa= find_next_pano_slice(re, &minx, &viewplane);
+               nextpa = find_next_pano_slice(re, &minx, &viewplane);
        else
-               nextpa= find_next_part(re, 0);
+               nextpa = find_next_part(re, 0);
        
        while (rendering) {
                
                if (re->test_break(re->tbh))
                        PIL_sleep_ms(50);
                else if (nextpa && BLI_available_threads(&threads)) {
-                       drawtimer= 0;
-                       nextpa->nr= counter++;  /* for nicest part, and for stats */
-                       nextpa->thread= BLI_available_thread_index(&threads);   /* sample index */
+                       drawtimer = 0;
+                       nextpa->nr = counter++;  /* for nicest part, and for stats */
+                       nextpa->thread = BLI_available_thread_index(&threads);   /* sample index */
                        BLI_insert_thread(&threads, nextpa);
 
-                       nextpa= find_next_part(re, minx);
+                       nextpa = find_next_part(re, minx);
                }
                else if (re->r.mode & R_PANORAMA) {
-                       if (nextpa==NULL && BLI_available_threads(&threads)==re->r.threads)
-                               nextpa= find_next_pano_slice(re, &minx, &viewplane);
+                       if (nextpa == NULL && BLI_available_threads(&threads) == re->r.threads)
+                               nextpa = find_next_pano_slice(re, &minx, &viewplane);
                        else {
                                PIL_sleep_ms(50);
                                drawtimer++;
@@ -857,9 +857,9 @@ static void threaded_tile_processor(Render *re)
                }
                
                /* check for ready ones to display, and if we need to continue */
-               rendering= 0;
-               hasdrawn= 0;
-               for (pa= re->parts.first; pa; pa= pa->next) {
+               rendering = 0;
+               hasdrawn = 0;
+               for (pa = re->parts.first; pa; pa = pa->next) {
                        if (pa->ready) {
                                
                                BLI_remove_thread(&threads, pa);
@@ -870,27 +870,27 @@ static void threaded_tile_processor(Render *re)
                                        print_part_stats(re, pa);
                                        
                                        render_result_free_list(&pa->fullresult, pa->result);
-                                       pa->result= NULL;
+                                       pa->result = NULL;
                                        re->i.partsdone++;
                                        re->progress(re->prh, re->i.partsdone / (float)re->i.totpart);
-                                       hasdrawn= 1;
+                                       hasdrawn = 1;
                                }
                        }
                        else {
-                               rendering= 1;
-                               if (pa->nr && pa->result && drawtimer>20) {
+                               rendering = 1;
+                               if (pa->nr && pa->result && drawtimer > 20) {
                                        if (render_display_draw_enabled(re))
                                                re->display_draw(re->ddh, pa->result, &pa->result->renrect);
-                                       hasdrawn= 1;
+                                       hasdrawn = 1;
                                }
                        }
                }
                if (hasdrawn)
-                       drawtimer= 0;
+                       drawtimer = 0;
 
                /* on break, wait for all slots to get freed */
-               if ( (g_break=re->test_break(re->tbh)) && BLI_available_threads(&threads)==re->r.threads)
-                       rendering= 0;
+               if ( (g_break = re->test_break(re->tbh)) && BLI_available_threads(&threads) == re->r.threads)
+                       rendering = 0;
                
        }
        
@@ -901,11 +901,11 @@ static void threaded_tile_processor(Render *re)
        }
        
        /* unset threadsafety */
-       g_break= 0;
+       g_break = 0;
        
        BLI_end_threads(&threads);
        freeparts(re);
-       re->viewplane= viewplane; /* restore viewplane, modified by pano render */
+       re->viewplane = viewplane; /* restore viewplane, modified by pano render */
 }
 
 /* currently only called by preview renders and envmap */
@@ -964,59 +964,59 @@ static void do_render_3d(Render *re)
 /* called by blur loop, accumulate RGBA key alpha */
 static void addblur_rect_key(RenderResult *rr, float *rectf, float *rectf1, float blurfac)
 {
-       float mfac= 1.0f - blurfac;
-       int a, b, stride= 4*rr->rectx;
-       int len= stride*sizeof(float);
+       float mfac = 1.0f - blurfac;
+       int a, b, stride = 4 * rr->rectx;
+       int len = stride * sizeof(float);
        
-       for (a=0; a<rr->recty; a++) {
-               if (blurfac==1.0f) {
+       for (a = 0; a < rr->recty; a++) {
+               if (blurfac == 1.0f) {
                        memcpy(rectf, rectf1, len);
                }
                else {
-                       float *rf= rectf, *rf1= rectf1;
+                       float *rf = rectf, *rf1 = rectf1;
                        
-                       for ( b= rr->rectx; b>0; b--, rf+=4, rf1+=4) {
-                               if (rf1[3]<0.01f)
-                                       rf[3]= mfac*rf[3];
-                               else if (rf[3]<0.01f) {
-                                       rf[0]= rf1[0];
-                                       rf[1]= rf1[1];
-                                       rf[2]= rf1[2];
-                                       rf[3]= blurfac*rf1[3];
+                       for (b = rr->rectx; b > 0; b--, rf += 4, rf1 += 4) {
+                               if (rf1[3] < 0.01f)
+                                       rf[3] = mfac * rf[3];
+                               else if (rf[3] < 0.01f) {
+                                       rf[0] = rf1[0];
+                                       rf[1] = rf1[1];
+                                       rf[2] = rf1[2];
+                                       rf[3] = blurfac * rf1[3];
                                }
                                else {
-                                       rf[0]= mfac*rf[0] + blurfac*rf1[0];
-                                       rf[1]= mfac*rf[1] + blurfac*rf1[1];
-                                       rf[2]= mfac*rf[2] + blurfac*rf1[2];
-                                       rf[3]= mfac*rf[3] + blurfac*rf1[3];
+                                       rf[0] = mfac * rf[0] + blurfac * rf1[0];
+                                       rf[1] = mfac * rf[1] + blurfac * rf1[1];
+                                       rf[2] = mfac * rf[2] + blurfac * rf1[2];
+                                       rf[3] = mfac * rf[3] + blurfac * rf1[3];
                                }                               
                        }
                }
-               rectf+= stride;
-               rectf1+= stride;
+               rectf += stride;
+               rectf1 += stride;
        }
 }
 
 /* called by blur loop, accumulate renderlayers */
 static void addblur_rect(RenderResult *rr, float *rectf, float *rectf1, float blurfac, int channels)
 {
-       float mfac= 1.0f - blurfac;
-       int a, b, stride= channels*rr->rectx;
-       int len= stride*sizeof(float);
+       float mfac = 1.0f - blurfac;
+       int a, b, stride = channels * rr->rectx;
+       int len = stride * sizeof(float);
        
-       for (a=0; a<rr->recty; a++) {
-               if (blurfac==1.0f) {
+       for (a = 0; a < rr->recty; a++) {
+               if (blurfac == 1.0f) {
                        memcpy(rectf, rectf1, len);
                }
                else {
-                       float *rf= rectf, *rf1= rectf1;
+                       float *rf = rectf, *rf1 = rectf1;
                        
-                       for ( b= rr->rectx*channels; b>0; b--, rf++, rf1++) {
-                               rf[0]= mfac*rf[0] + blurfac*rf1[0];
+                       for (b = rr->rectx * channels; b > 0; b--, rf++, rf1++) {
+                               rf[0] = mfac * rf[0] + blurfac * rf1[0];
                        }
                }
-               rectf+= stride;
-               rectf1+= stride;
+               rectf += stride;
+               rectf1 += stride;
        }
 }
 
@@ -1027,8 +1027,8 @@ static void merge_renderresult_blur(RenderResult *rr, RenderResult *brr, float b
        RenderLayer *rl, *rl1;
        RenderPass *rpass, *rpass1;
        
-       rl1= brr->layers.first;
-       for (rl= rr->layers.first; rl && rl1; rl= rl->next, rl1= rl1->next) {
+       rl1 = brr->layers.first;
+       for (rl = rr->layers.first; rl && rl1; rl = rl->next, rl1 = rl1->next) {
                
                /* combined */
                if (rl->rectf && rl1->rectf) {
@@ -1039,8 +1039,8 @@ static void merge_renderresult_blur(RenderResult *rr, RenderResult *brr, float b
                }
                
                /* passes are allocated in sync */
-               rpass1= rl1->passes.first;
-               for (rpass= rl->passes.first; rpass && rpass1; rpass= rpass->next, rpass1= rpass1->next) {
+               rpass1 = rl1->passes.first;
+               for (rpass = rl->passes.first; rpass && rpass1; rpass = rpass->next, rpass1 = rpass1->next) {
                        addblur_rect(rr, rpass->rect, rpass1->rect, blurfac, rpass->channels);
                }
        }
@@ -1051,20 +1051,20 @@ static void do_render_blur_3d(Render *re)
 {
        RenderResult *rres;
        float blurfac;
-       int blur= re->r.mblur_samples;
+       int blur = re->r.mblur_samples;
        
        /* create accumulation render result */
-       rres= render_result_new(re, &re->disprect, 0, RR_USE_MEM);
+       rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
        
        /* do the blur steps */
        while (blur--) {
-               re->mblur_offs = re->r.blurfac*((float)(re->r.mblur_samples-blur))/(float)re->r.mblur_samples;
+               re->mblur_offs = re->r.blurfac * ((float)(re->r.mblur_samples - blur)) / (float)re->r.mblur_samples;
                
-               re->i.curblur= re->r.mblur_samples-blur;        /* stats */
+               re->i.curblur = re->r.mblur_samples - blur;    /* stats */
                
                do_render_3d(re);
                
-               blurfac= 1.0f/(float)(re->r.mblur_samples-blur);
+               blurfac = 1.0f / (float)(re->r.mblur_samples - blur);
                
                merge_renderresult_blur(rres, re->result, blurfac, re->r.alphamode & R_ALPHAKEY);
                if (re->test_break(re->tbh)) break;
@@ -1073,14 +1073,14 @@ static void do_render_blur_3d(Render *re)
        /* swap results */
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
        render_result_free(re->result);
-       re->result= rres;
+       re->result = rres;
        BLI_rw_mutex_unlock(&re->resultmutex);
        
        re->mblur_offs = 0.0f;
-       re->i.curblur= 0;       /* stats */
+       re->i.curblur = 0;   /* stats */
        
        /* weak... the display callback wants an active renderlayer pointer... */
-       re->result->renlay= render_get_active_layer(re, re->result);
+       re->result->renlay = render_get_active_layer(re, re->result);
        re->display_draw(re->ddh, re->result, NULL);    
 }
 
@@ -1088,16 +1088,16 @@ static void do_render_blur_3d(Render *re)
 /* function assumes rectf1 and rectf2 to be half size of rectf */
 static void interleave_rect(RenderResult *rr, float *rectf, float *rectf1, float *rectf2, int channels)
 {
-       int a, stride= channels*rr->rectx;
-       int len= stride*sizeof(float);
+       int a, stride = channels * rr->rectx;
+       int len = stride * sizeof(float);
        
-       for (a=0; a<rr->recty; a+=2) {
+       for (a = 0; a < rr->recty; a += 2) {
                memcpy(rectf, rectf1, len);
-               rectf+= stride;
-               rectf1+= stride;
+               rectf += stride;
+               rectf1 += stride;
                memcpy(rectf, rectf2, len);
-               rectf+= stride;
-               rectf2+= stride;
+               rectf += stride;
+               rectf2 += stride;
        }
 }
 
@@ -1107,18 +1107,18 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende
        RenderLayer *rl, *rl1, *rl2;
        RenderPass *rpass, *rpass1, *rpass2;
        
-       rl1= rr1->layers.first;
-       rl2= rr2->layers.first;
-       for (rl= rr->layers.first; rl && rl1 && rl2; rl= rl->next, rl1= rl1->next, rl2= rl2->next) {
+       rl1 = rr1->layers.first;
+       rl2 = rr2->layers.first;
+       for (rl = rr->layers.first; rl && rl1 && rl2; rl = rl->next, rl1 = rl1->next, rl2 = rl2->next) {
                
                /* combined */
                if (rl->rectf && rl1->rectf && rl2->rectf)
                        interleave_rect(rr, rl->rectf, rl1->rectf, rl2->rectf, 4);
                
                /* passes are allocated in sync */
-               rpass1= rl1->passes.first;
-               rpass2= rl2->passes.first;
-               for (rpass= rl->passes.first; rpass && rpass1 && rpass2; rpass= rpass->next, rpass1= rpass1->next, rpass2= rpass2->next) {
+               rpass1 = rl1->passes.first;
+               rpass2 = rl2->passes.first;
+               for (rpass = rl->passes.first; rpass && rpass1 && rpass2; rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next) {
                        interleave_rect(rr, rpass->rect, rpass1->rect, rpass2->rect, rpass->channels);
                }
        }
@@ -1128,8 +1128,8 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende
 /* interleaves 2 frames */
 static void do_render_fields_3d(Render *re)
 {
-       Object *camera= RE_GetCamera(re);
-       RenderResult *rr1, *rr2= NULL;
+       Object *camera = RE_GetCamera(re);
+       RenderResult *rr1, *rr2 = NULL;
        
        /* no render result was created, we can safely halve render y */
        re->winy /= 2;
@@ -1137,31 +1137,31 @@ static void do_render_fields_3d(Render *re)
        re->disprect.ymin /= 2;
        re->disprect.ymax /= 2;
        
-       re->i.curfield= 1;      /* stats */
+       re->i.curfield = 1;  /* stats */
        
        /* first field, we have to call camera routine for correct aspect and subpixel offset */
        RE_SetCamera(re, camera);
-       if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0)
+       if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0)
                do_render_blur_3d(re);
        else
                do_render_3d(re);
 
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       rr1= re->result;
-       re->result= NULL;
+       rr1 = re->result;
+       re->result = NULL;
        BLI_rw_mutex_unlock(&re->resultmutex);
        
        /* second field */
        if (!re->test_break(re->tbh)) {
                
-               re->i.curfield= 2;      /* stats */
+               re->i.curfield = 2;  /* stats */
                
                re->flag |= R_SEC_FIELD;
-               if ((re->r.mode & R_FIELDSTILL)==0) {
+               if ((re->r.mode & R_FIELDSTILL) == 0) {
                        re->field_offs = 0.5f;
                }
                RE_SetCamera(re, camera);
-               if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0)
+               if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0)
                        do_render_blur_3d(re);
                else
                        do_render_3d(re);
@@ -1169,7 +1169,7 @@ static void do_render_fields_3d(Render *re)
                
                re->field_offs = 0.0f;
                
-               rr2= re->result;
+               rr2 = re->result;
        }
        
        /* allocate original height new buffers */
@@ -1179,7 +1179,7 @@ static void do_render_fields_3d(Render *re)
        re->disprect.ymax *= 2;
 
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       re->result= render_result_new(re, &re->disprect, 0, RR_USE_MEM);
+       re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 
        if (rr2) {
                if (re->r.mode & R_ODDFIELD)
@@ -1192,10 +1192,10 @@ static void do_render_fields_3d(Render *re)
 
        render_result_free(rr1);
        
-       re->i.curfield= 0;      /* stats */
+       re->i.curfield = 0;  /* stats */
        
        /* weak... the display callback wants an active renderlayer pointer... */
-       re->result->renlay= render_get_active_layer(re, re->result);
+       re->result->renlay = render_get_active_layer(re, re->result);
 
        BLI_rw_mutex_unlock(&re->resultmutex);
 
@@ -1205,11 +1205,11 @@ static void do_render_fields_3d(Render *re)
 /* main render routine, no compositing */
 static void do_render_fields_blur_3d(Render *re)
 {
-       Object *camera= RE_GetCamera(re);
+       Object *camera = RE_GetCamera(re);
        /* also check for camera here */
        if (camera == NULL) {
                printf("ERROR: Cannot render, no camera\n");
-               G.afbreek= 1;
+               G.afbreek = 1;
                return;
        }
 
@@ -1218,7 +1218,7 @@ static void do_render_fields_blur_3d(Render *re)
        
        if (re->r.mode & R_FIELDS)
                do_render_fields_3d(re);
-       else if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0)
+       else if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0)
                do_render_blur_3d(re);
        else
                do_render_3d(re);
@@ -1226,30 +1226,30 @@ static void do_render_fields_blur_3d(Render *re)
        /* when border render, check if we have to insert it in black */
        if (re->result) {
                if (re->r.mode & R_BORDER) {
-                       if ((re->r.mode & R_CROP)==0) {
+                       if ((re->r.mode & R_CROP) == 0) {
                                RenderResult *rres;
                                
                                BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 
                                /* sub-rect for merge call later on */
-                               re->result->tilerect= re->disprect;
+                               re->result->tilerect = re->disprect;
                                
                                /* this copying sequence could become function? */
                                /* weak is: it chances disprect from border */
                                re->disprect.xmin = re->disprect.ymin = 0;
                                re->disprect.xmax = re->winx;
                                re->disprect.ymax = re->winy;
-                               re->rectx= re->winx;
-                               re->recty= re->winy;
+                               re->rectx = re->winx;
+                               re->recty = re->winy;
                                
-                               rres= render_result_new(re, &re->disprect, 0, RR_USE_MEM);
+                               rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
                                
                                render_result_merge(rres, re->result);
                                render_result_free(re->result);
-                               re->result= rres;
+                               re->result = rres;
                                
                                /* weak... the display callback wants an active renderlayer pointer... */
-                               re->result->renlay= render_get_active_layer(re, re->result);
+                               re->result->renlay = render_get_active_layer(re, re->result);
                                
                                BLI_rw_mutex_unlock(&re->resultmutex);
                
@@ -1258,8 +1258,8 @@ static void do_render_fields_blur_3d(Render *re)
                        }
                        else {
                                /* set offset (again) for use in compositor, disprect was manipulated. */
-                               re->result->xof= 0;
-                               re->result->yof= 0;
+                               re->result->xof = 0;
+                               re->result->yof = 0;
                        }
                }
        }
@@ -1271,37 +1271,37 @@ static void do_render_fields_blur_3d(Render *re)
  */
 static void render_scene(Render *re, Scene *sce, int cfra)
 {
-       Render *resc= RE_NewRender(sce->id.name);
-       int winx= re->winx, winy= re->winy;
+       Render *resc = RE_NewRender(sce->id.name);
+       int winx = re->winx, winy = re->winy;
        
-       sce->r.cfra= cfra;
+       sce->r.cfra = cfra;
 
        BKE_scene_camera_switch_update(sce);
 
        /* exception: scene uses own size (unfinished code) */
        if (0) {
-               winx= (sce->r.size*sce->r.xsch)/100;
-               winy= (sce->r.size*sce->r.ysch)/100;
+               winx = (sce->r.size * sce->r.xsch) / 100;
+               winy = (sce->r.size * sce->r.ysch) / 100;
        }
        
        /* initial setup */
        RE_InitState(resc, re, &sce->r, NULL, winx, winy, &re->disprect);
        
        /* still unsure entity this... */
-       resc->main= re->main;
-       resc->scene= sce;
-       resc->lay= sce->lay;
+       resc->main = re->main;
+       resc->scene = sce;
+       resc->lay = sce->lay;
        
        /* ensure scene has depsgraph, base flags etc OK */
        BKE_scene_set_background(re->main, sce);
 
        /* copy callbacks */
-       resc->display_draw= re->display_draw;
-       resc->ddh= re->ddh;
-       resc->test_break= re->test_break;
-       resc->tbh= re->tbh;
-       resc->stats_draw= re->stats_draw;
-       resc->sdh= re->sdh;
+       resc->display_draw = re->display_draw;
+       resc->ddh = re->ddh;
+       resc->test_break = re->test_break;
+       resc->tbh = re->tbh;
+       resc->stats_draw = re->stats_draw;
+       resc->sdh = re->sdh;
        
        do_render_fields_blur_3d(resc);
 }
@@ -1309,16 +1309,16 @@ static void render_scene(Render *re, Scene *sce, int cfra)
 /* helper call to detect if this scene needs a render, or if there's a any render layer to render */
 static int composite_needs_render(Scene *sce, int this_scene)
 {
-       bNodeTree *ntree= sce->nodetree;
+       bNodeTree *ntree = sce->nodetree;
        bNode *node;
        
-       if (ntree==NULL) return 1;
+       if (ntree == NULL) return 1;
        if (sce->use_nodes == FALSE) return 1;
-       if ((sce->r.scemode & R_DOCOMP)==0) return 1;
+       if ((sce->r.scemode & R_DOCOMP) == 0) return 1;
        
-       for (node= ntree->nodes.first; node; node= node->next) {
-               if (node->type==CMP_NODE_R_LAYERS)
-                       if (this_scene==0 || node->id==NULL || node->id==&sce->id)
+       for (node = ntree->nodes.first; node; node = node->next) {
+               if (node->type == CMP_NODE_R_LAYERS)
+                       if (this_scene == 0 || node->id == NULL || node->id == &sce->id)
                                return 1;
        }
        return 0;
@@ -1329,17 +1329,17 @@ static void tag_scenes_for_render(Render *re)
        bNode *node;
        Scene *sce;
        
-       for (sce= re->main->scene.first; sce; sce= sce->id.next)
+       for (sce = re->main->scene.first; sce; sce = sce->id.next)
                sce->id.flag &= ~LIB_DOIT;
        
        if (RE_GetCamera(re) && composite_needs_render(re->scene, 1))
                re->scene->id.flag |= LIB_DOIT;
        
-       if (re->scene->nodetree==NULL) return;
+       if (re->scene->nodetree == NULL) return;
        
        /* check for render-layers nodes using other scenes, we tag them LIB_DOIT */
-       for (node= re->scene->nodetree->nodes.first; node; node= node->next) {
-               if (node->type==CMP_NODE_R_LAYERS) {
+       for (node = re->scene->nodetree->nodes.first; node; node = node->next) {
+               if (node->type == CMP_NODE_R_LAYERS) {
                        if (node->id) {
                                if (node->id != (ID *)re->scene)
                                        node->id->flag |= LIB_DOIT;
@@ -1352,23 +1352,23 @@ static void tag_scenes_for_render(Render *re)
 static void ntree_render_scenes(Render *re)
 {
        bNode *node;
-       int cfra= re->scene->r.cfra;
-       int restore_scene= 0;
+       int cfra = re->scene->r.cfra;
+       int restore_scene = 0;
        
-       if (re->scene->nodetree==NULL) return;
+       if (re->scene->nodetree == NULL) return;
        
        tag_scenes_for_render(re);
        
        /* now foreach render-result node tagged we do a full render */
        /* results are stored in a way compisitor will find it */
-       for (node= re->scene->nodetree->nodes.first; node; node= node->next) {
-               if (node->type==CMP_NODE_R_LAYERS) {
+       for (node = re->scene->nodetree->nodes.first; node; node = node->next) {
+               if (node->type == CMP_NODE_R_LAYERS) {
                        if (node->id && node->id != (ID *)re->scene) {
                                if (node->id->flag & LIB_DOIT) {
-                                       Scene *scene = (Scene*)node->id;
+                                       Scene *scene = (Scene *)node->id;
 
                                        render_scene(re, scene, cfra);
-                                       restore_scene= (scene != re->scene);
+                                       restore_scene = (scene != re->scene);
                                        node->id->flag &= ~LIB_DOIT;
                                        
                                        nodeUpdate(re->scene->nodetree, node);
@@ -1385,9 +1385,9 @@ static void ntree_render_scenes(Render *re)
 /* bad call... need to think over proper method still */
 static void render_composit_stats(void *UNUSED(arg), char *str)
 {
-       R.i.infostr= str;
+       R.i.infostr = str;
        R.stats_draw(R.sdh, &R.i);
-       R.i.infostr= NULL;
+       R.i.infostr = NULL;
 }
 
 /* invokes Freestyle stroke rendering */
@@ -1466,33 +1466,33 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
        
        /* interaction callbacks */
        if (ntree) {
-               ntree->stats_draw= render_composit_stats;
-               ntree->test_break= re->test_break;
-               ntree->progress= re->progress;
-               ntree->sdh= re->sdh;
-               ntree->tbh= re->tbh;
-               ntree->prh= re->prh;
+               ntree->stats_draw = render_composit_stats;
+               ntree->test_break = re->test_break;
+               ntree->progress = re->progress;
+               ntree->sdh = re->sdh;
+               ntree->tbh = re->tbh;
+               ntree->prh = re->prh;
        }
        
        /* filtmask needs it */
-       R= *re;
+       R = *re;
        
        /* we accumulate in here */
-       rectf= MEM_mapallocN(re->rectx*re->recty*sizeof(float)*4, "fullsample rgba");
+       rectf = MEM_mapallocN(re->rectx * re->recty * sizeof(float) * 4, "fullsample rgba");
        
-       for (sample=0; sample<re->r.osa; sample++) {
+       for (sample = 0; sample < re->r.osa; sample++) {
                Render *re1;
                RenderResult rres;
                int x, y, mask;
                
                /* enable full sample print */
-               R.i.curfsa= sample+1;
+               R.i.curfsa = sample + 1;
                
                /* set all involved renders on the samplebuffers (first was done by render itself, but needs tagged) */
                /* also function below assumes this */
                        
                tag_scenes_for_render(re);
-               for (re1= RenderGlobal.renderlist.first; re1; re1= re1->next) {
+               for (re1 = RenderGlobal.renderlist.first; re1; re1 = re1->next) {
                        if (re1->scene->id.flag & LIB_DOIT) {
                                if (re1->r.scemode & R_FULL_SAMPLE) {
                                        if (sample) {
@@ -1512,25 +1512,25 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
                        ntreeCompositTagRender(re->scene);
                        ntreeCompositTagAnimated(ntree);
                        
-                       ntreeCompositExecTree(ntree, &re->r, 1, G.background==0);
+                       ntreeCompositExecTree(ntree, &re->r, 1, G.background == 0);
                }
                
                /* ensure we get either composited result or the active layer */
                RE_AcquireResultImage(re, &rres);
                
                /* accumulate with filter, and clip */
-               mask= (1<<sample);
+               mask = (1 << sample);
                mask_array(mask, filt);
 
-               for (y=0; y<re->recty; y++) {
-                       float *rf= rectf + 4*y*re->rectx;
-                       float *col= rres.rectf + 4*y*re->rectx;
+               for (y = 0; y < re->recty; y++) {
+                       float *rf = rectf + 4 * y * re->rectx;
+                       float *col = rres.rectf + 4 * y * re->rectx;
                                
-                       for (x=0; x<re->rectx; x++, rf+=4, col+=4) {
+                       for (x = 0; x < re->rectx; x++, rf += 4, col += 4) {
                                /* clamping to 1.0 is needed for correct AA */
-                               if (col[0]<0.0f) col[0]=0.0f; else if (col[0] > 1.0f) col[0]= 1.0f;
-                               if (col[1]<0.0f) col[1]=0.0f; else if (col[1] > 1.0f) col[1]= 1.0f;
-                               if (col[2]<0.0f) col[2]=0.0f; else if (col[2] > 1.0f) col[2]= 1.0f;
+                               if (col[0] < 0.0f) col[0] = 0.0f; else if (col[0] > 1.0f) col[0] = 1.0f;
+                               if (col[1] < 0.0f) col[1] = 0.0f; else if (col[1] > 1.0f) col[1] = 1.0f;
+                               if (col[2] < 0.0f) col[2] = 0.0f; else if (col[2] > 1.0f) col[2] = 1.0f;
                                
                                add_filt_fmask_coord(filt, col, rf, re->rectx, re->recty, x, y);
                        }
@@ -1539,9 +1539,9 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
                RE_ReleaseResultImage(re);
 
                /* show stuff */
-               if (sample!=re->osa-1) {
+               if (sample != re->osa - 1) {
                        /* weak... the display callback wants an active renderlayer pointer... */
-                       re->result->renlay= render_get_active_layer(re, re->result);
+                       re->result->renlay = render_get_active_layer(re, re->result);
                        re->display_draw(re->ddh, re->result, NULL);
                }
                
@@ -1551,19 +1551,19 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
        
        /* clear interaction callbacks */
        if (ntree) {
-               ntree->stats_draw= NULL;
-               ntree->test_break= NULL;
-               ntree->progress= NULL;
-               ntree->tbh= ntree->sdh= ntree->prh= NULL;
+               ntree->stats_draw = NULL;
+               ntree->test_break = NULL;
+               ntree->progress = NULL;
+               ntree->tbh = ntree->sdh = ntree->prh = NULL;
        }
        
        /* disable full sample print */
-       R.i.curfsa= 0;
+       R.i.curfsa = 0;
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
        if (re->result->rectf)
                MEM_freeN(re->result->rectf);
-       re->result->rectf= rectf;
+       re->result->rectf = rectf;
        BLI_rw_mutex_unlock(&re->resultmutex);
 }
 
@@ -1574,24 +1574,24 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree)
        bNode *node;
 
        /* default start situation */
-       G.afbreek= 0;
+       G.afbreek = 0;
        
-       re->main= bmain;
-       re->scene= sce;
+       re->main = bmain;
+       re->scene = sce;
        
        /* first call RE_ReadRenderResult on every renderlayer scene. this creates Render structs */
        
        /* tag scenes unread */
-       for (scene= re->main->scene.first; scene; scene= scene->id.next)
+       for (scene = re->main->scene.first; scene; scene = scene->id.next)
                scene->id.flag |= LIB_DOIT;
        
-       for (node= ntree->nodes.first; node; node= node->next) {
-               if (node->type==CMP_NODE_R_LAYERS) {
-                       Scene *nodescene= (Scene *)node->id;
+       for (node = ntree->nodes.first; node; node = node->next) {
+               if (node->type == CMP_NODE_R_LAYERS) {
+                       Scene *nodescene = (Scene *)node->id;
                        
-                       if (nodescene==NULL) nodescene= sce;
+                       if (nodescene == NULL) nodescene = sce;
                        if (nodescene->id.flag & LIB_DOIT) {
-                               nodescene->r.mode |= R_OSA;     /* render struct needs tables */
+                               nodescene->r.mode |= R_OSA; /* render struct needs tables */
                                RE_ReadRenderResult(sce, nodescene);
                                nodescene->id.flag &= ~LIB_DOIT;
                        }
@@ -1614,8 +1614,8 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree)
 /* returns fully composited render-result on given time step (in RenderData) */
 static void do_render_composite_fields_blur_3d(Render *re)
 {
-       bNodeTree *ntree= re->scene->nodetree;
-       int update_newframe=0;
+       bNodeTree *ntree = re->scene->nodetree;
+       int update_newframe = 0;
        
        /* INIT seeding, compositor can use random texture */
        BLI_srandom(re->r.cfra);
@@ -1631,7 +1631,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
                BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
                
                render_result_free(re->result);
-               re->result= render_result_new(re, &re->disprect, 0, RR_USE_MEM);
+               re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 
                BLI_rw_mutex_unlock(&re->resultmutex);
                
@@ -1655,20 +1655,20 @@ static void do_render_composite_fields_blur_3d(Render *re)
                
                if (ntree && re->scene->use_nodes && re->r.scemode & R_DOCOMP) {
                        /* checks if there are render-result nodes that need scene */
-                       if ((re->r.scemode & R_SINGLE_LAYER)==0)
+                       if ((re->r.scemode & R_SINGLE_LAYER) == 0)
                                ntree_render_scenes(re);
                        
                        if (!re->test_break(re->tbh)) {
-                               ntree->stats_draw= render_composit_stats;
-                               ntree->test_break= re->test_break;
-                               ntree->progress= re->progress;
-                               ntree->sdh= re->sdh;
-                               ntree->tbh= re->tbh;
-                               ntree->prh= re->prh;
+                               ntree->stats_draw = render_composit_stats;
+                               ntree->test_break = re->test_break;
+                               ntree->progress = re->progress;
+                               ntree->sdh = re->sdh;
+                               ntree->tbh = re->tbh;
+                               ntree->prh = re->prh;
                                
                                /* in case it was never initialized */
-                               R.sdh= re->sdh;
-                               R.stats_draw= re->stats_draw;
+                               R.sdh = re->sdh;
+                               R.stats_draw = re->stats_draw;
                                
                                if (update_newframe)
                                        BKE_scene_update_for_newframe(re->main, re->scene, re->lay);
@@ -1676,13 +1676,13 @@ static void do_render_composite_fields_blur_3d(Render *re)
                                if (re->r.scemode & R_FULL_SAMPLE)
                                        do_merge_fullsample(re, ntree);
                                else {
-                                       ntreeCompositExecTree(ntree, &re->r, 1, G.background==0);
+                                       ntreeCompositExecTree(ntree, &re->r, 1, G.background == 0);
                                }
                                
-                               ntree->stats_draw= NULL;
-                               ntree->test_break= NULL;
-                               ntree->progress= NULL;
-                               ntree->tbh= ntree->sdh= ntree->prh= NULL;
+                               ntree->stats_draw = NULL;
+                               ntree->test_break = NULL;
+                               ntree->progress = NULL;
+                               ntree->tbh = ntree->sdh = ntree->prh = NULL;
                        }
                }
                else if (re->r.scemode & R_FULL_SAMPLE)
@@ -1692,7 +1692,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
        free_all_freestyle_renders(re->scene);
 
        /* weak... the display callback wants an active renderlayer pointer... */
-       re->result->renlay= render_get_active_layer(re, re->result);
+       re->result->renlay = render_get_active_layer(re, re->result);
        re->display_draw(re->ddh, re->result, NULL);
 }
 
@@ -1716,7 +1716,7 @@ int RE_seq_render_active(Scene *scene, RenderData *rd)
        if (!(rd->scemode & R_DOSEQ) || !ed || !ed->seqbase.first)
                return 0;
        
-       for (seq= ed->seqbase.first; seq; seq= seq->next) {
+       for (seq = ed->seqbase.first; seq; seq = seq->next) {
                if (seq->type != SEQ_TYPE_SOUND_RAM)
                        return 1;
        }
@@ -1724,7 +1724,7 @@ int RE_seq_render_active(Scene *scene, RenderData *rd)
        return 0;
 }
 
-static void do_render_seq(Render * re)
+static void do_render_seq(Render *re)
 {
        static int recurs_depth = 0;
        struct ImBuf *ibuf;
@@ -1732,26 +1732,26 @@ static void do_render_seq(Render * re)
        int cfra = re->r.cfra;
        SeqRenderData context;
 
-       re->i.cfra= cfra;
+       re->i.cfra = cfra;
 
-       if (recurs_depth==0) {
+       if (recurs_depth == 0) {
                /* otherwise sequencer animation isn't updated */
                BKE_animsys_evaluate_all_animation(re->main, re->scene, (float)cfra); // XXX, was BKE_scene_frame_get(re->scene)
        }
 
        recurs_depth++;
 
-       if ((re->r.mode & R_BORDER) && (re->r.mode & R_CROP)==0) {
+       if ((re->r.mode & R_BORDER) && (re->r.mode & R_CROP) == 0) {
                /* if border rendering is used and cropping is disabled, final buffer should
                 * be as large as the whole frame */
                context = seq_new_render_data(re->main, re->scene,
-                                             re->winx, re->winy,
-                                             100);
+                                             re->winx, re->winy,
+                                             100);
        }
        else {
                context = seq_new_render_data(re->main, re->scene,
-                                             re->result->rectx, re->result->recty,
-                                             100);
+                                             re->result->rectx, re->result->recty,
+                                             100);
        }
 
        ibuf = give_ibuf_seq(context, cfra, 0);
@@ -1767,7 +1767,7 @@ static void do_render_seq(Render * re)
                render_result_rect_from_ibuf(rr, &re->r, ibuf);
                
                if (recurs_depth == 0) { /* with nested scenes, only free on toplevel... */
-                       Editing * ed = re->scene->ed;
+                       Editing *ed = re->scene->ed;
                        if (ed)
                                free_imbuf_seq(re->scene, &ed->seqbase, TRUE, TRUE);
                }
@@ -1784,8 +1784,8 @@ static void do_render_seq(Render * re)
        re->r.scemode |= R_DOSEQ;
 
        /* set overall progress of sequence rendering */
-       if (re->r.efra!=re->r.sfra)
-               re->progress(re->prh, (float)(cfra-re->r.sfra) / (re->r.efra-re->r.sfra));
+       if (re->r.efra != re->r.sfra)
+               re->progress(re->prh, (float)(cfra - re->r.sfra) / (re->r.efra - re->r.sfra));
        else
                re->progress(re->prh, 1.0f);
 }
@@ -1797,7 +1797,7 @@ static void do_render_all_options(Render *re)
 {
        BKE_scene_camera_switch_update(re->scene);
 
-       re->i.starttime= PIL_check_seconds_timer();
+       re->i.starttime = PIL_check_seconds_timer();
 
        /* ensure no images are in memory from previous animated sequences */
        BKE_image_all_free_anim_ibufs(re->r.cfra);
@@ -1817,7 +1817,7 @@ static void do_render_all_options(Render *re)
                do_render_composite_fields_blur_3d(re);
        }
        
-       re->i.lastframetime= PIL_check_seconds_timer()- re->i.starttime;
+       re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime;
        
        re->stats_draw(re->sdh, &re->i);
        
@@ -1830,16 +1830,16 @@ static void do_render_all_options(Render *re)
 
 static int check_valid_camera(Scene *scene, Object *camera_override)
 {
-       int check_comp= 1;
+       int check_comp = 1;
 
        if (camera_override == NULL && scene->camera == NULL)
-               scene->camera= BKE_scene_camera_find(scene);
+               scene->camera = BKE_scene_camera_find(scene);
 
-       if (scene->r.scemode&R_DOSEQ) {
+       if (scene->r.scemode & R_DOSEQ) {
                if (scene->ed) {
-                       Sequence *seq= scene->ed->seqbase.first;
+                       Sequence *seq = scene->ed->seqbase.first;
 
-                       check_comp= 0;
+                       check_comp = 0;
 
                        while (seq) {
                                if (seq->type == SEQ_TYPE_SCENE && seq->scene) {
@@ -1847,7 +1847,7 @@ static int check_valid_camera(Scene *scene, Object *camera_override)
                                                if (!seq->scene->camera && !BKE_scene_camera_find(seq->scene)) {
                                                        if (seq->scene == scene) {
                                                                /* for current scene camera could be unneeded due to compisite nodes */
-                                                               check_comp= 1;
+                                                               check_comp = 1;
                                                        }
                                                        else {
                                                                /* for other scenes camera is necessary */
@@ -1857,18 +1857,18 @@ static int check_valid_camera(Scene *scene, Object *camera_override)
                                        }
                                }
 
-                               seq= seq->next;
+                               seq = seq->next;
                        }
                }
        }
 
        if (check_comp) { /* no sequencer or sequencer depends on compositor */
-               if (scene->r.scemode&R_DOCOMP && scene->use_nodes) {
-                       bNode *node= scene->nodetree->nodes.first;
+               if (scene->r.scemode & R_DOCOMP && scene->use_nodes) {
+                       bNode *node = scene->nodetree->nodes.first;
 
                        while (node) {
                                if (node->type == CMP_NODE_R_LAYERS) {
-                                       Scene *sce= node->id ? (Scene*)node->id : scene;
+                                       Scene *sce = node->id ? (Scene *)node->id : scene;
 
                                        if (!sce->camera && !BKE_scene_camera_find(sce)) {
                                                /* all render layers nodes need camera */
@@ -1876,7 +1876,7 @@ static int check_valid_camera(Scene *scene, Object *camera_override)
                                        }
                                }
 
-                               node= node->next;
+                               node = node->next;
                        }
                }
                else {
@@ -1922,12 +1922,12 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
                }
        }
        
-       if (scene->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE)) {
+       if (scene->r.scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) {
                char str[FILE_MAX];
                
                render_result_exr_file_path(scene, 0, str);
                
-               if (BLI_file_is_writable(str)==0) {
+               if (BLI_file_is_writable(str) == 0) {
                        BKE_report(reports, RPT_ERROR, "Can not save render buffers, check the temp default path");
                        return 0;
                }
@@ -1940,7 +1940,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
                
        }
        else
-               scene->r.scemode &= ~R_FULL_SAMPLE;     /* clear to be sure */
+               scene->r.scemode &= ~R_FULL_SAMPLE;  /* clear to be sure */
        
        if (scene->r.scemode & R_DOCOMP) {
                if (scene->use_nodes) {
@@ -1955,7 +1955,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
                        }
                        
                        if (scene->r.scemode & R_FULL_SAMPLE) {
-                               if (composite_needs_render(scene, 0)==0) {
+                               if (composite_needs_render(scene, 0) == 0) {
                                        BKE_report(reports, RPT_ERROR, "Full Sample AA not supported without 3d rendering");
                                        return 0;
                                }
@@ -1963,7 +1963,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
                }
        }
        
-        /* check valid camera, without camera render is OK (compo, seq) */
+       /* check valid camera, without camera render is OK (compo, seq) */
        if (!check_valid_camera(scene, camera_override)) {
                BKE_report(reports, RPT_ERROR, "No camera");
                return 0;
@@ -1982,15 +1982,15 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
 
        /* layer flag tests */
        if (scene->r.scemode & R_SINGLE_LAYER) {
-               srl= BLI_findlink(&scene->r.layers, scene->r.actlay);
+               srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
                /* force layer to be enabled */
                srl->layflag &= ~SCE_LAY_DISABLE;
        }
        
-       for (srl= scene->r.layers.first; srl; srl= srl->next)
+       for (srl = scene->r.layers.first; srl; srl = srl->next)
                if (!(srl->layflag & SCE_LAY_DISABLE))
                        break;
-       if (srl==NULL) {
+       if (srl == NULL) {
                BKE_report(reports, RPT_ERROR, "All RenderLayers are disabled");
                return 0;
        }
@@ -2000,17 +2000,17 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
 
 static void validate_render_settings(Render *re)
 {
-       if (re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE)) {
+       if (re->r.scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) {
                /* no osa + fullsample won't work... */
-               if (re->r.osa==0)
+               if (re->r.osa == 0)
                        re->r.scemode &= ~R_FULL_SAMPLE;
        }
-       else re->r.scemode &= ~R_FULL_SAMPLE;   /* clear to be sure */
+       else re->r.scemode &= ~R_FULL_SAMPLE;   /* clear to be sure */
 
        if (RE_engine_is_external(re)) {
                /* not supported yet */
-               re->r.scemode &= ~(R_EXR_TILE_FILE|R_FULL_SAMPLE);
-               re->r.mode &= ~(R_FIELDS|R_MBLUR);
+               re->r.scemode &= ~(R_EXR_TILE_FILE | R_FULL_SAMPLE);
+               re->r.mode &= ~(R_FIELDS | R_MBLUR);
        }
 }
 
@@ -2041,16 +2041,16 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc
         * r.border is the clipping rect */
        
        /* calculate actual render result and display size */
-       winx= (scene->r.size*scene->r.xsch)/100;
-       winy= (scene->r.size*scene->r.ysch)/100;
+       winx = (scene->r.size * scene->r.xsch) / 100;
+       winy = (scene->r.size * scene->r.ysch) / 100;
        
        /* we always render smaller part, inserting it in larger image is compositor bizz, it uses disprect for it */
        if (scene->r.mode & R_BORDER) {
-               disprect.xmin = scene->r.border.xmin*winx;
-               disprect.xmax = scene->r.border.xmax*winx;
+               disprect.xmin = scene->r.border.xmin * winx;
+               disprect.xmax = scene->r.border.xmax * winx;
                
-               disprect.ymin = scene->r.border.ymin*winy;
-               disprect.ymax = scene->r.border.ymax*winy;
+               disprect.ymin = scene->r.border.ymin * winy;
+               disprect.ymax = scene->r.border.ymax * winy;
        }
        else {
                disprect.xmin = disprect.ymin = 0;
@@ -2058,14 +2058,14 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc
                disprect.ymax = winy;
        }
        
-       re->main= bmain;
-       re->scene= scene;
-       re->camera_override= camera_override;
-       re->lay= lay;
+       re->main = bmain;
+       re->scene = scene;
+       re->camera_override = camera_override;
+       re->lay = lay;
        
        /* not too nice, but it survives anim-border render */
        if (anim) {
-               re->disprect= disprect;
+               re->disprect = disprect;
                return 1;
        }
        
@@ -2105,16 +2105,16 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc
 
 void RE_SetReports(Render *re, ReportList *reports)
 {
-       re->reports= reports;
+       re->reports = reports;
 }
 
 /* general Blender frame render call */
 void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *srl, Object *camera_override, unsigned int lay, int frame, const short write_still)
 {
        /* ugly global still... is to prevent preview events and signal subsurfs etc to make full resol */
-       G.rendering= 1;
+       G.rendering = 1;
        
-       scene->r.cfra= frame;
+       scene->r.cfra = frame;
        
        if (render_initialize_from_main(re, bmain, scene, srl, camera_override, lay, 0, 0)) {
                MEM_reset_peak_memory();
@@ -2143,7 +2143,7 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr
        BLI_callback_exec(re->main, (ID *)scene, G.afbreek ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE);
 
        /* UGLY WARNING */
-       G.rendering= 0;
+       G.rendering = 0;
 }
 
 void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene)
@@ -2159,8 +2159,8 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
 {
        char name[FILE_MAX];
        RenderResult rres;
-       Object *camera= RE_GetCamera(re);
-       int ok= 1;
+       Object *camera = RE_GetCamera(re);
+       int ok = 1;
        
        RE_AcquireResultImage(re, &rres);
 
@@ -2170,13 +2170,13 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
                unsigned int *rect32 = (unsigned int *)rres.rect32;
                /* note; the way it gets 32 bits rects is weak... */
                if (rres.rect32 == NULL) {
-                       rect32 = MEM_mapallocN(sizeof(int)*rres.rectx*rres.recty, "temp 32 bits rect");
+                       rect32 = MEM_mapallocN(sizeof(int) * rres.rectx * rres.recty, "temp 32 bits rect");
                        RE_ResultGet32(re, rect32);
                        do_free = TRUE;
                }
 
-               ok= mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *)rect32,
-                                    rres.rectx, rres.recty, re->reports);
+               ok = mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *)rect32,
+                                     rres.rectx, rres.recty, re->reports);
                if (do_free) {
                        MEM_freeN(rect32);
                }
@@ -2188,36 +2188,36 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
                else
                        BKE_makepicstring(name, scene->r.pic, bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, TRUE);
                
-               if (re->r.im_format.imtype==R_IMF_IMTYPE_MULTILAYER) {
+               if (re->r.im_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
                        if (re->result) {
                                RE_WriteRenderResult(re->reports, re->result, name, scene->r.im_format.exr_codec);
                                printf("Saved: %s", name);
                        }
                }
                else {
-                       ImBuf *ibuf= render_result_rect_to_ibuf(&rres, &scene->r);
+                       ImBuf *ibuf = render_result_rect_to_ibuf(&rres, &scene->r);
 
-                       ok= BKE_imbuf_write_stamp(scene, camera, ibuf, name, &scene->r.im_format);
+                       ok = BKE_imbuf_write_stamp(scene, camera, ibuf, name, &scene->r.im_format);
                        
-                       if (ok==0) {
+                       if (ok == 0) {
                                printf("Render error: cannot save %s\n", name);
                        }
                        else printf("Saved: %s", name);
                        
                        /* optional preview images for exr */
-                       if (ok && scene->r.im_format.imtype==R_IMF_IMTYPE_OPENEXR && (scene->r.im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
-                               ImageFormatData imf= scene->r.im_format;
-                               imf.imtype= R_IMF_IMTYPE_JPEG90;
+                       if (ok && scene->r.im_format.imtype == R_IMF_IMTYPE_OPENEXR && (scene->r.im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
+                               ImageFormatData imf = scene->r.im_format;
+                               imf.imtype = R_IMF_IMTYPE_JPEG90;
 
                                if (BLI_testextensie(name, ".exr"))
-                                       name[strlen(name)-4]= 0;
+                                       name[strlen(name) - 4] = 0;
                                BKE_add_image_extension(name, R_IMF_IMTYPE_JPEG90);
-                               ibuf->planes= 24;
+                               ibuf->planes = 24;
                                BKE_imbuf_write_stamp(scene, camera, ibuf, name, &imf);
                                printf("\nSaved: %s", name);
                        }
                        
-                                       /* imbuf knows which rects are not part of ibuf */
+                       /* imbuf knows which rects are not part of ibuf */
                        IMB_freeImBuf(ibuf);
                }
        }
@@ -2238,9 +2238,9 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
 /* saves images to disk */
 void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_override, unsigned int lay, int sfra, int efra, int tfra)
 {
-       bMovieHandle *mh= BKE_movie_handle_get(scene->r.im_format.imtype);
-       int cfrao= scene->r.cfra;
-       int nfra, totrendered= 0, totskipped= 0;
+       bMovieHandle *mh = BKE_movie_handle_get(scene->r.im_format.imtype);
+       int cfrao = scene->r.cfra;
+       int nfra, totrendered = 0, totskipped = 0;
        
        /* do not fully call for each frame, it initializes & pops output window */
        if (!render_initialize_from_main(re, bmain, scene, NULL, camera_override, lay, 0, 1))
@@ -2248,13 +2248,13 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
        
        /* ugly global still... is to prevent renderwin events and signal subsurfs etc to make full resol */
        /* is also set by caller renderwin.c */
-       G.rendering= 1;
+       G.rendering = 1;
 
        re->flag |= R_ANIMATION;
 
        if (BKE_imtype_is_movie(scene->r.im_format.imtype))
                if (!mh->start_movie(scene, &re->r, re->rectx, re->recty, re->reports))
-                       G.afbreek= 1;
+                       G.afbreek = 1;
 
        if (mh->get_next_frame) {
                while (!(G.afbreek == 1)) {
@@ -2269,7 +2269,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
 
                                if (re->test_break(re->tbh) == 0) {
                                        if (!do_write_image_or_movie(re, bmain, scene, mh, NULL))
-                                               G.afbreek= 1;
+                                               G.afbreek = 1;
                                }
 
                                if (G.afbreek == 0) {
@@ -2278,18 +2278,18 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                        }
                        else {
                                if (re->test_break(re->tbh))
-                                       G.afbreek= 1;
+                                       G.afbreek = 1;
                        }
                }
        }
        else {
-               for (nfra= sfra, scene->r.cfra= sfra; scene->r.cfra<=efra; scene->r.cfra++) {
+               for (nfra = sfra, scene->r.cfra = sfra; scene->r.cfra <= efra; scene->r.cfra++) {
                        char name[FILE_MAX];
                        
                        /* only border now, todo: camera lens. (ton) */
                        render_initialize_from_main(re, bmain, scene, NULL, camera_override, lay, 1, 0);
 
-                       if (nfra!=scene->r.cfra) {
+                       if (nfra != scene->r.cfra) {
                                /*
                                 * Skip this frame, but update for physics and particles system.
                                 * From convertblender.c:
@@ -2298,15 +2298,15 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                                unsigned int updatelay;
 
                                if (re->lay & 0xFF000000)
-                                       updatelay= re->lay & 0xFF000000;
+                                       updatelay = re->lay & 0xFF000000;
                                else
-                                       updatelay= re->lay;
+                                       updatelay = re->lay;
 
                                BKE_scene_update_for_newframe(bmain, scene, updatelay);
                                continue;
                        }
                        else
-                               nfra+= tfra;
+                               nfra += tfra;
 
                        /* Touch/NoOverwrite options are only valid for image's */
                        if (BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) {
@@ -2324,7 +2324,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                                }
                        }
 
-                       re->r.cfra= scene->r.cfra;         /* weak.... */
+                       re->r.cfra = scene->r.cfra;     /* weak.... */
 
                        /* run callbacs before rendering, before the scene is updated */
                        BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_PRE);
@@ -2336,12 +2336,12 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                        if (re->test_break(re->tbh) == 0) {
                                if (!G.afbreek)
                                        if (!do_write_image_or_movie(re, bmain, scene, mh, NULL))
-                                               G.afbreek= 1;
+                                               G.afbreek = 1;
                        }
                        else
-                               G.afbreek= 1;
+                               G.afbreek = 1;
                
-                       if (G.afbreek==1) {
+                       if (G.afbreek == 1) {
                                /* remove touched file */
                                if (BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) {
                                        if (scene->r.mode & R_TOUCH && BLI_exists(name) && BLI_file_size(name) == 0) {
@@ -2352,7 +2352,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
                                break;
                        }
 
-                       if (G.afbreek==0) {
+                       if (G.afbreek == 0) {
                                BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */
                        }
                }
@@ -2365,14 +2365,14 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
        if (totskipped && totrendered == 0)
                BKE_report(re->reports, RPT_INFO, "No frames rendered, skipped to not overwrite");
 
-       scene->r.cfra= cfrao;
+       scene->r.cfra = cfrao;
 
        re->flag &= ~R_ANIMATION;
 
        BLI_callback_exec(re->main, (ID *)scene, G.afbreek ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE);
 
        /* UGLY WARNING */
-       G.rendering= 0;
+       G.rendering = 0;
 }
 
 void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
@@ -2380,8 +2380,8 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
        Object *camera;
        int winx, winy;
 
-       winx= (sce->r.size*sce->r.xsch)/100;
-       winy= (sce->r.size*sce->r.ysch)/100;
+       winx = (sce->r.size * sce->r.xsch) / 100;
+       winy = (sce->r.size * sce->r.ysch) / 100;
 
        RE_InitState(re, NULL, &sce->r, NULL, winx, winy, NULL);
 
@@ -2405,16 +2405,16 @@ int RE_ReadRenderResult(Scene *scene, Scene *scenode)
        rcti disprect;
        
        /* calculate actual render result and display size */
-       winx= (scene->r.size*scene->r.xsch)/100;
-       winy= (scene->r.size*scene->r.ysch)/100;
+       winx = (scene->r.size * scene->r.xsch) / 100;
+       winy = (scene->r.size * scene->r.ysch) / 100;
        
        /* only in movie case we render smaller part */
        if (scene->r.mode & R_BORDER) {
-               disprect.xmin = scene->r.border.xmin*winx;
-               disprect.xmax = scene->r.border.xmax*winx;
+               disprect.xmin = scene->r.border.xmin * winx;
+               disprect.xmax = scene->r.border.xmax * winx;
                
-               disprect.ymin = scene->r.border.ymin*winy;
-               disprect.ymax = scene->r.border.ymax*winy;
+               disprect.ymin = scene->r.border.ymin * winy;
+               disprect.ymax = scene->r.border.ymax * winy;
        }
        else {
                disprect.xmin = disprect.ymin = 0;
@@ -2423,17 +2423,17 @@ int RE_ReadRenderResult(Scene *scene, Scene *scenode)
        }
        
        if (scenode)
-               scene= scenode;
+               scene = scenode;
        
        /* get render: it can be called from UI with draw callbacks */
-       re= RE_GetRender(scene->id.name);
-       if (re==NULL)
-               re= RE_NewRender(scene->id.name);
+       re = RE_GetRender(scene->id.name);
+       if (re == NULL)
+               re = RE_NewRender(scene->id.name);
        RE_InitState(re, NULL, &scene->r, NULL, winx, winy, &disprect);
-       re->scene= scene;
+       re->scene = scene;
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       success= render_result_exr_file_read(re, 0);
+       success = render_result_exr_file_read(re, 0);
        BLI_rw_mutex_unlock(&re->resultmutex);
 
        return success;
@@ -2441,11 +2441,11 @@ int RE_ReadRenderResult(Scene *scene, Scene *scenode)
 
 void RE_set_max_threads(int threads)
 {
-       if (threads==0) {
+       if (threads == 0) {
                RenderGlobal.threads = BLI_system_thread_count();
        }
-       else if (threads>=1 && threads<=BLENDER_MAX_THREADS) {
-               RenderGlobal.threads= threads;
+       else if (threads >= 1 && threads <= BLENDER_MAX_THREADS) {
+               RenderGlobal.threads = threads;
        }
        else {
                printf("Error, threads has to be in range 0-%d\n", BLENDER_MAX_THREADS);
@@ -2455,9 +2455,9 @@ void RE_set_max_threads(int threads)
 void RE_init_threadcount(Render *re) 
 {
        if (RenderGlobal.threads >= 1) { /* only set as an arg in background mode */
-               re->r.threads= MIN2(RenderGlobal.threads, BLENDER_MAX_THREADS);
+               re->r.threads = MIN2(RenderGlobal.threads, BLENDER_MAX_THREADS);
        }
-       else if ((re->r.mode & R_FIXED_THREADS)==0 || RenderGlobal.threads == 0) { /* Automatic threads */
+       else if ((re->r.mode & R_FIXED_THREADS) == 0 || RenderGlobal.threads == 0) { /* Automatic threads */
                re->r.threads = BLI_system_thread_count();
        }
 }
@@ -2470,23 +2470,23 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char
 
        if (ibuf && (ibuf->rect || ibuf->rect_float)) {
                if (ibuf->x == layer->rectx && ibuf->y == layer->recty) {
-                       if (ibuf->rect_float==NULL)
+                       if (ibuf->rect_float == NULL)
                                IMB_float_from_rect(ibuf);
 
-                       memcpy(layer->rectf, ibuf->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
+                       memcpy(layer->rectf, ibuf->rect_float, sizeof(float) * 4 * layer->rectx * layer->recty);
                }
                else {
                        if ((ibuf->x - x >= layer->rectx) && (ibuf->y - y >= layer->recty)) {
                                ImBuf *ibuf_clip;
 
-                               if (ibuf->rect_float==NULL)
+                               if (ibuf->rect_float == NULL)
                                        IMB_float_from_rect(ibuf);
 
                                ibuf_clip = IMB_allocImBuf(layer->rectx, layer->recty, 32, IB_rectfloat);
                                if (ibuf_clip) {
                                        IMB_rectcpy(ibuf_clip, ibuf, 0, 0, x, y, layer->rectx, layer->recty);
 
-                                       memcpy(layer->rectf, ibuf_clip->rect_float, sizeof(float)*4*layer->rectx*layer->recty);
+                                       memcpy(layer->rectf, ibuf_clip->rect_float, sizeof(float) * 4 * layer->rectx * layer->recty);
                                        IMB_freeImBuf(ibuf_clip);
                                }
                                else {
@@ -2518,33 +2518,33 @@ const float default_envmap_layout[] = { 0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1 };
 int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, const char *relpath, const char imtype, float layout[12])
 {
        ImageFormatData imf;
-       ImBuf *ibuf=NULL;
+       ImBuf *ibuf = NULL;
        int ok;
        int dx;
-       int maxX=0, maxY=0, i=0;
+       int maxX = 0, maxY = 0, i = 0;
        char filepath[FILE_MAX];
 
-       if (env->cube[1]==NULL) {
+       if (env->cube[1] == NULL) {
                BKE_report(reports, RPT_ERROR, "There is no generated environment map available to save");
                return 0;
        }
 
-       imf= scene->r.im_format;
-       imf.imtype= imtype;
+       imf = scene->r.im_format;
+       imf.imtype = imtype;
 
-       dx= env->cube[1]->x;
+       dx = env->cube[1]->x;
 
        if (env->type == ENV_CUBE) {
-               for (i=0; i < 12; i+=2) {
+               for (i = 0; i < 12; i += 2) {
                        maxX = MAX2(maxX, layout[i] + 1);
-                       maxY = MAX2(maxY, layout[i+1] + 1);
+                       maxY = MAX2(maxY, layout[i + 1] + 1);
                }
 
-               ibuf = IMB_allocImBuf(maxX*dx, maxY*dx, 24, IB_rectfloat);
+               ibuf = IMB_allocImBuf(maxX * dx, maxY * dx, 24, IB_rectfloat);
 
-               for (i=0; i < 12; i+=2)
-                       if (layout[i] > -1 && layout[i+1] > -1)
-                               IMB_rectcpy(ibuf, env->cube[i/2], layout[i]*dx, layout[i+1]*dx, 0, 0, dx, dx);
+               for (i = 0; i < 12; i += 2)
+                       if (layout[i] > -1 && layout[i + 1] > -1)
+                               IMB_rectcpy(ibuf, env->cube[i / 2], layout[i] * dx, layout[i + 1] * dx, 0, 0, dx, dx);
        }
        else if (env->type == ENV_PLANE) {
                ibuf = IMB_allocImBuf(dx, dx, 24, IB_rectfloat);
@@ -2562,7 +2562,7 @@ int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env,
        BLI_strncpy(filepath, relpath, sizeof(filepath));
        BLI_path_abs(filepath, G.main->name);
 
-       ok= BKE_imbuf_write(ibuf, filepath, &imf);
+       ok = BKE_imbuf_write(ibuf, filepath, &imf);
 
        IMB_freeImBuf(ibuf);