style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / render / render_preview.c
index 8cdde5f160f2e0d32e412e947d6cf87416403997..9ba961302f19f4e21cf1af82645efc45c48cec15 100644 (file)
@@ -202,29 +202,29 @@ void ED_preview_init_dbase(void)
 
 void ED_preview_free_dbase(void)
 {
-       if(pr_main)
+       if (pr_main)
                free_main(pr_main);
 }
 
 static int preview_mat_has_sss(Material *mat, bNodeTree *ntree)
 {
-       if(mat) {
-               if(mat->sss_flag & MA_DIFF_SSS)
+       if (mat) {
+               if (mat->sss_flag & MA_DIFF_SSS)
                        return 1;
-               if(mat->nodetree)
-                       if( preview_mat_has_sss(NULL, mat->nodetree))
+               if (mat->nodetree)
+                       if ( preview_mat_has_sss(NULL, mat->nodetree))
                                return 1;
        }
-       else if(ntree) {
+       else if (ntree) {
                bNode *node;
-               for(node= ntree->nodes.first; node; node= node->next) {
-                       if(node->type==NODE_GROUP && node->id) {
-                               if( preview_mat_has_sss(NULL, (bNodeTree *)node->id))
+               for (node= ntree->nodes.first; node; node= node->next) {
+                       if (node->type==NODE_GROUP && node->id) {
+                               if ( preview_mat_has_sss(NULL, (bNodeTree *)node->id))
                                        return 1;
                        }
-                       else if(node->id && ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT)) {
+                       else if (node->id && ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT)) {
                                mat= (Material *)node->id;
-                               if(mat->sss_flag & MA_DIFF_SSS)
+                               if (mat->sss_flag & MA_DIFF_SSS)
                                        return 1;
                        }
                }
@@ -239,17 +239,17 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
        Scene *sce;
        Base *base;
        
-       if(pr_main==NULL) return NULL;
+       if (pr_main==NULL) return NULL;
        
        sce= pr_main->scene.first;
-       if(sce) {
+       if (sce) {
                
                /* this flag tells render to not execute depsgraph or ipos etc */
                sce->r.scemode |= R_PREVIEWBUTS;
                /* set world always back, is used now */
                sce->world= pr_main->world.first;
                /* now: exposure copy */
-               if(scene->world) {
+               if (scene->world) {
                        sce->world->exp= scene->world->exp;
                        sce->world->range= scene->world->range;
                }
@@ -257,16 +257,16 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                sce->r.color_mgt_flag = scene->r.color_mgt_flag;
                
                /* prevent overhead for small renders and icons (32) */
-               if(id && sp->sizex < 40)
+               if (id && sp->sizex < 40)
                        sce->r.xparts= sce->r.yparts= 1;
                else
                        sce->r.xparts= sce->r.yparts= 4;
                
                /* exception: don't color manage texture previews or icons */
-               if((id && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE)
+               if ((id && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE)
                        sce->r.color_mgt_flag &= ~R_COLOR_MANAGEMENT;
                
-               if((id && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO)
+               if ((id && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO)
                        sce->r.alphamode= R_ALPHAPREMUL;
                else
                        sce->r.alphamode= R_ADDSKY;
@@ -274,10 +274,10 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                sce->r.cfra= scene->r.cfra;
                BLI_strncpy(sce->r.engine, scene->r.engine, sizeof(sce->r.engine));
                
-               if(id_type==ID_MA) {
+               if (id_type==ID_MA) {
                        Material *mat= NULL, *origmat= (Material *)id;
                        
-                       if(origmat) {
+                       if (origmat) {
                                /* work on a copy */
                                mat= localize_material(origmat);
                                sp->matcopy= mat;
@@ -287,27 +287,27 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                end_render_material(mat);
                                
                                /* un-useful option */
-                               if(sp->pr_method==PR_ICON_RENDER)
+                               if (sp->pr_method==PR_ICON_RENDER)
                                        mat->shade_flag &= ~MA_OBCOLOR;
 
                                /* turn on raytracing if needed */
-                               if(mat->mode_l & MA_RAYMIRROR)
+                               if (mat->mode_l & MA_RAYMIRROR)
                                        sce->r.mode |= R_RAYTRACE;
-                               if(mat->material_type == MA_TYPE_VOLUME)
+                               if (mat->material_type == MA_TYPE_VOLUME)
                                        sce->r.mode |= R_RAYTRACE;
-                               if((mat->mode_l & MA_RAYTRANSP) && (mat->mode_l & MA_TRANSP))
+                               if ((mat->mode_l & MA_RAYTRANSP) && (mat->mode_l & MA_TRANSP))
                                        sce->r.mode |= R_RAYTRACE;
-                               if(preview_mat_has_sss(mat, NULL))
+                               if (preview_mat_has_sss(mat, NULL))
                                        sce->r.mode |= R_SSS;
                                
                                /* turn off fake shadows if needed */
                                /* this only works in a specific case where the preview.blend contains
                                 * an object starting with 'c' which has a material linked to it (not the obdata)
                                 * and that material has a fake shadow texture in the active texture slot */
-                               for(base= sce->base.first; base; base= base->next) {
-                                       if(base->object->id.name[2]=='c') {
+                               for (base= sce->base.first; base; base= base->next) {
+                                       if (base->object->id.name[2]=='c') {
                                                Material *shadmat= give_current_material(base->object, base->object->actcol);
-                                               if(shadmat) {
+                                               if (shadmat) {
                                                        if (mat->mode & MA_SHADBUF) shadmat->septex = 0;
                                                        else shadmat->septex |= 1;
                                                }
@@ -316,11 +316,11 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                
                                /* turn off bounce lights for volume, 
                                 * doesn't make much visual difference and slows it down too */
-                               if(mat->material_type == MA_TYPE_VOLUME) {
-                                       for(base= sce->base.first; base; base= base->next) {
-                                               if(base->object->type == OB_LAMP) {
+                               if (mat->material_type == MA_TYPE_VOLUME) {
+                                       for (base= sce->base.first; base; base= base->next) {
+                                               if (base->object->type == OB_LAMP) {
                                                        /* if doesn't match 'Lamp.002' --> main key light */
-                                                       if( strcmp(base->object->id.name+2, "Lamp.002") != 0 ) {
+                                                       if ( strcmp(base->object->id.name+2, "Lamp.002") != 0 ) {
                                                                base->object->restrictflag |= OB_RESTRICT_RENDER;
                                                        }
                                                }
@@ -328,7 +328,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                }
 
                                
-                               if(sp->pr_method==PR_ICON_RENDER) {
+                               if (sp->pr_method==PR_ICON_RENDER) {
                                        if (mat->material_type == MA_TYPE_HALO) {
                                                sce->lay= 1<<MA_FLAT;
                                        } 
@@ -338,7 +338,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                }
                                else {
                                        sce->lay= 1<<mat->pr_type;
-                                       if(mat->nodetree && sp->pr_method==PR_NODE_RENDER) {
+                                       if (mat->nodetree && sp->pr_method==PR_NODE_RENDER) {
                                                /* two previews, they get copied by wmJob */
                                                ntreeInitPreview(mat->nodetree, sp->sizex, sp->sizey);
                                                ntreeInitPreview(origmat->nodetree, sp->sizex, sp->sizey);
@@ -350,45 +350,46 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                
                        }
                        
-                       for(base= sce->base.first; base; base= base->next) {
-                               if(base->object->id.name[2]=='p') {
+                       for (base= sce->base.first; base; base= base->next) {
+                               if (base->object->id.name[2]=='p') {
                                        /* copy over object color, in case material uses it */
                                        copy_v4_v4(base->object->col, sp->col);
                                        
-                                       if(OB_TYPE_SUPPORT_MATERIAL(base->object->type)) {
+                                       if (OB_TYPE_SUPPORT_MATERIAL(base->object->type)) {
                                                /* don't use assign_material, it changed mat->id.us, which shows in the UI */
                                                Material ***matar= give_matarar(base->object);
                                                int actcol= MAX2(base->object->actcol > 0, 1) - 1;
 
-                                               if(matar && actcol < base->object->totcol)
+                                               if (matar && actcol < base->object->totcol)
                                                        (*matar)[actcol]= mat;
-                                       } else if (base->object->type == OB_LAMP) {
+                                       }
+                                       else if (base->object->type == OB_LAMP) {
                                                base->object->restrictflag &= ~OB_RESTRICT_RENDER;
                                        }
                                }
                        }
                }
-               else if(id_type==ID_TE) {
+               else if (id_type==ID_TE) {
                        Tex *tex= NULL, *origtex= (Tex *)id;
                        
-                       if(origtex) {
+                       if (origtex) {
                                tex= localize_texture(origtex);
                                sp->texcopy= tex;
                                BLI_addtail(&pr_main->tex, tex);
                        }                       
                        sce->lay= 1<<MA_TEXTURE;
                        
-                       for(base= sce->base.first; base; base= base->next) {
-                               if(base->object->id.name[2]=='t') {
+                       for (base= sce->base.first; base; base= base->next) {
+                               if (base->object->id.name[2]=='t') {
                                        Material *mat= give_current_material(base->object, base->object->actcol);
-                                       if(mat && mat->mtex[0]) {
+                                       if (mat && mat->mtex[0]) {
                                                mat->mtex[0]->tex= tex;
                                                
-                                               if(tex && sp->slot)
+                                               if (tex && sp->slot)
                                                        mat->mtex[0]->which_output = sp->slot->which_output;
                                                
                                                /* show alpha in this case */
-                                               if(tex==NULL || (tex->flag & TEX_PRV_ALPHA)) {
+                                               if (tex==NULL || (tex->flag & TEX_PRV_ALPHA)) {
                                                        mat->mtex[0]->mapto |= MAP_ALPHA;
                                                        mat->alpha= 0.0f;
                                                }
@@ -400,23 +401,23 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                }
                        }
 
-                       if(tex && tex->nodetree && sp->pr_method==PR_NODE_RENDER) {
+                       if (tex && tex->nodetree && sp->pr_method==PR_NODE_RENDER) {
                                /* two previews, they get copied by wmJob */
                                ntreeInitPreview(origtex->nodetree, sp->sizex, sp->sizey);
                                ntreeInitPreview(tex->nodetree, sp->sizex, sp->sizey);
                        }
                }
-               else if(id_type==ID_LA) {
+               else if (id_type==ID_LA) {
                        Lamp *la= NULL, *origla= (Lamp *)id;
 
                        /* work on a copy */
-                       if(origla) {
+                       if (origla) {
                                la= localize_lamp(origla);
                                sp->lampcopy= la;
                                BLI_addtail(&pr_main->lamp, la);
                        }
                        
-                       if(la && la->type==LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) {
+                       if (la && la->type==LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) {
                                sce->lay= 1<<MA_ATMOS;
                                sce->world= scene->world;
                                sce->camera= (Object *)BLI_findstring(&pr_main->object, "CameraAtmo", offsetof(ID, name)+2);
@@ -428,23 +429,23 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                        }
                        sce->r.mode &= ~R_SHADOW;
                        
-                       for(base= sce->base.first; base; base= base->next) {
-                               if(base->object->id.name[2]=='p') {
-                                       if(base->object->type==OB_LAMP)
+                       for (base= sce->base.first; base; base= base->next) {
+                               if (base->object->id.name[2]=='p') {
+                                       if (base->object->type==OB_LAMP)
                                                base->object->data= la;
                                }
                        }
 
-                       if(la && la->nodetree && sp->pr_method==PR_NODE_RENDER) {
+                       if (la && la->nodetree && sp->pr_method==PR_NODE_RENDER) {
                                /* two previews, they get copied by wmJob */
                                ntreeInitPreview(origla->nodetree, sp->sizex, sp->sizey);
                                ntreeInitPreview(la->nodetree, sp->sizex, sp->sizey);
                        }
                }
-               else if(id_type==ID_WO) {
+               else if (id_type==ID_WO) {
                        World *wrld= NULL, *origwrld= (World *)id;
 
-                       if(origwrld) {
+                       if (origwrld) {
                                wrld= localize_world(origwrld);
                                sp->worldcopy= wrld;
                                BLI_addtail(&pr_main->world, wrld);
@@ -453,7 +454,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                        sce->lay= 1<<MA_SKY;
                        sce->world= wrld;
 
-                       if(wrld && wrld->nodetree && sp->pr_method==PR_NODE_RENDER) {
+                       if (wrld && wrld->nodetree && sp->pr_method==PR_NODE_RENDER) {
                                /* two previews, they get copied by wmJob */
                                ntreeInitPreview(wrld->nodetree, sp->sizex, sp->sizey);
                                ntreeInitPreview(origwrld->nodetree, sp->sizex, sp->sizey);
@@ -484,11 +485,11 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int
                }
        }
 
-       if(!split || first) sprintf(name, "Preview %p", (void *)sa);
+       if (!split || first) sprintf(name, "Preview %p", (void *)sa);
        else sprintf(name, "SecondPreview %p", (void *)sa);
 
-       if(split) {
-               if(first) {
+       if (split) {
+               if (first) {
                        offx= 0;
                        newx= newx/2;
                }
@@ -501,14 +502,14 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int
        re= RE_GetRender(name);
        RE_AcquireResultImage(re, &rres);
 
-       if(rres.rectf) {
+       if (rres.rectf) {
                
-               if(ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2) {
+               if (ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2) {
 
                        newrect->xmax = MAX2(newrect->xmax, rect->xmin + rres.rectx + offx);
                        newrect->ymax = MAX2(newrect->ymax, rect->ymin + rres.recty);
 
-                       if(rres.rectx && rres.recty) {
+                       if (rres.rectx && rres.recty) {
                                /* temporary conversion to byte for drawing */
                                float fx= rect->xmin + offx;
                                float fy= rect->ymin;
@@ -538,7 +539,7 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int
 
 void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, rcti *rect)
 {
-       if(idp) {
+       if (idp) {
                ScrArea *sa= CTX_wm_area(C);
                Scene *sce = CTX_data_scene(C);
                ID *id = (ID *)idp;
@@ -554,23 +555,23 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r
                newrect.ymin = rect->ymin;
                newrect.ymax = rect->ymin;
 
-               if(parent) {
+               if (parent) {
                        ok = ed_preview_draw_rect(sa, sce, id, 1, 1, rect, &newrect);
                        ok &= ed_preview_draw_rect(sa, sce, parent, 1, 0, rect, &newrect);
                }
                else
                        ok = ed_preview_draw_rect(sa, sce, id, 0, 0, rect, &newrect);
 
-               if(ok)
+               if (ok)
                        *rect= newrect;
 
                /* check for spacetype... */
-               if(sbuts->spacetype==SPACE_BUTS && sbuts->preview) {
+               if (sbuts->spacetype==SPACE_BUTS && sbuts->preview) {
                        sbuts->preview= 0;
                        ok= 0;
                }
        
-               if(ok==0) {
+               if (ok==0) {
                        ED_preview_shader_job(C, sa, id, parent, slot, newx, newy, PR_BUTS_RENDER);
                }
        }       
@@ -599,30 +600,30 @@ static void shader_preview_updatejob(void *spv)
 {
        ShaderPreview *sp= spv;
        
-       if(sp->id) {
-               if(sp->pr_method==PR_NODE_RENDER) {
-                       if( GS(sp->id->name) == ID_MA) {
+       if (sp->id) {
+               if (sp->pr_method==PR_NODE_RENDER) {
+                       if ( GS(sp->id->name) == ID_MA) {
                                Material *mat= (Material *)sp->id;
                                
-                               if(sp->matcopy && mat->nodetree && sp->matcopy->nodetree)
+                               if (sp->matcopy && mat->nodetree && sp->matcopy->nodetree)
                                        ntreeLocalSync(sp->matcopy->nodetree, mat->nodetree);
                        }
-                       else if( GS(sp->id->name) == ID_TE) {
+                       else if ( GS(sp->id->name) == ID_TE) {
                                Tex *tex= (Tex *)sp->id;
                                
-                               if(sp->texcopy && tex->nodetree && sp->texcopy->nodetree)
+                               if (sp->texcopy && tex->nodetree && sp->texcopy->nodetree)
                                        ntreeLocalSync(sp->texcopy->nodetree, tex->nodetree);
                        }
-                       else if( GS(sp->id->name) == ID_WO) {
+                       else if ( GS(sp->id->name) == ID_WO) {
                                World *wrld= (World *)sp->id;
                                
-                               if(sp->worldcopy && wrld->nodetree && sp->worldcopy->nodetree)
+                               if (sp->worldcopy && wrld->nodetree && sp->worldcopy->nodetree)
                                        ntreeLocalSync(sp->worldcopy->nodetree, wrld->nodetree);
                        }
-                       else if( GS(sp->id->name) == ID_LA) {
+                       else if ( GS(sp->id->name) == ID_LA) {
                                Lamp *la= (Lamp *)sp->id;
                                
-                               if(sp->lampcopy && la->nodetree && sp->lampcopy->nodetree)
+                               if (sp->lampcopy && la->nodetree && sp->lampcopy->nodetree)
                                        ntreeLocalSync(sp->lampcopy->nodetree, la->nodetree);
                        }
                }               
@@ -640,27 +641,27 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        
        /* get the stuff from the builtin preview dbase */
        sce= preview_prepare_scene(sp->scene, id, idtype, sp); // XXX sizex
-       if(sce==NULL) return;
+       if (sce==NULL) return;
        
-       if(!split || first) sprintf(name, "Preview %p", sp->owner);
+       if (!split || first) sprintf(name, "Preview %p", sp->owner);
        else sprintf(name, "SecondPreview %p", sp->owner);
        re= RE_GetRender(name);
        
        /* full refreshed render from first tile */
-       if(re==NULL)
+       if (re==NULL)
                re= RE_NewRender(name);
                
        /* sce->r gets copied in RE_InitState! */
        sce->r.scemode &= ~(R_MATNODE_PREVIEW|R_TEXNODE_PREVIEW);
        sce->r.scemode &= ~R_NO_IMAGE_LOAD;
 
-       if(sp->pr_method==PR_ICON_RENDER) {
+       if (sp->pr_method==PR_ICON_RENDER) {
                sce->r.scemode |= R_NO_IMAGE_LOAD;
                sce->r.mode |= R_OSA;
        }
-       else if(sp->pr_method==PR_NODE_RENDER) {
-               if(idtype == ID_MA) sce->r.scemode |= R_MATNODE_PREVIEW;
-               else if(idtype == ID_TE) sce->r.scemode |= R_TEXNODE_PREVIEW;
+       else if (sp->pr_method==PR_NODE_RENDER) {
+               if (idtype == ID_MA) sce->r.scemode |= R_MATNODE_PREVIEW;
+               else if (idtype == ID_TE) sce->r.scemode |= R_TEXNODE_PREVIEW;
                sce->r.mode &= ~R_OSA;
        }
        else {  /* PR_BUTS_RENDER */
@@ -668,8 +669,8 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        }
 
        /* in case of split preview, use border render */
-       if(split) {
-               if(first) sizex= sp->sizex/2;
+       if (split) {
+               if (first) sizex= sp->sizex/2;
                else sizex= sp->sizex - sp->sizex/2;
        }
        else sizex= sp->sizex;
@@ -680,7 +681,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        sce->r.size= 100;
 
        /* callbacs are cleared on GetRender() */
-       if(ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) {
+       if (ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) {
                RE_display_draw_cb(re, sp, shader_preview_draw);
        }
        /* set this for all previews, default is react to G.afbreek still */
@@ -688,7 +689,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        
        /* lens adjust */
        oldlens= ((Camera *)sce->camera->data)->lens;
-       if(sizex > sp->sizey)
+       if (sizex > sp->sizey)
                ((Camera *)sce->camera->data)->lens *= (float)sp->sizey/(float)sizex;
 
        /* entire cycle for render engine */
@@ -697,10 +698,10 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        ((Camera *)sce->camera->data)->lens= oldlens;
 
        /* handle results */
-       if(sp->pr_method==PR_ICON_RENDER) {
+       if (sp->pr_method==PR_ICON_RENDER) {
                // char *rct= (char *)(sp->pr_rect + 32*16 + 16);
                
-               if(sp->pr_rect)
+               if (sp->pr_rect)
                        RE_ResultGet32(re, sp->pr_rect);
        }
        else {
@@ -714,9 +715,9 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        preview_prepare_scene(sp->scene, NULL, GS(id->name), sp);
        
        /* XXX bad exception, end-exec is not being called in render, because it uses local main */
-//     if(idtype == ID_TE) {
+//     if (idtype == ID_TE) {
 //             Tex *tex= (Tex *)id;
-//             if(tex->use_nodes && tex->nodetree)
+//             if (tex->use_nodes && tex->nodetree)
 //                     ntreeEndExecTree(tex->nodetree);
 //     }
 
@@ -730,7 +731,7 @@ static void shader_preview_startjob(void *customdata, short *stop, short *do_upd
        sp->stop= stop;
        sp->do_update= do_update;
 
-       if(sp->parent) {
+       if (sp->parent) {
                shader_preview_render(sp, sp->id, 1, 1);
                shader_preview_render(sp, sp->parent, 1, 0);
        }
@@ -744,7 +745,7 @@ static void shader_preview_free(void *customdata)
 {
        ShaderPreview *sp= customdata;
        
-       if(sp->matcopy) {
+       if (sp->matcopy) {
                struct IDProperty *properties;
                int a;
                
@@ -755,9 +756,9 @@ static void shader_preview_free(void *customdata)
                BLI_remlink(&pr_main->mat, sp->matcopy);
                
                /* free_material decrements texture, prevent this. hack alert! */
-               for(a=0; a<MAX_MTEX; a++) {
+               for (a=0; a<MAX_MTEX; a++) {
                        MTex *mtex= sp->matcopy->mtex[a];
-                       if(mtex && mtex->tex) mtex->tex= NULL;
+                       if (mtex && mtex->tex) mtex->tex= NULL;
                }
                
                free_material(sp->matcopy);
@@ -769,7 +770,7 @@ static void shader_preview_free(void *customdata)
                }
                MEM_freeN(sp->matcopy);
        }
-       if(sp->texcopy) {
+       if (sp->texcopy) {
                struct IDProperty *properties;
                /* node previews */
                shader_preview_updatejob(sp);
@@ -785,7 +786,7 @@ static void shader_preview_free(void *customdata)
                }
                MEM_freeN(sp->texcopy);
        }
-       if(sp->worldcopy) {
+       if (sp->worldcopy) {
                struct IDProperty *properties;
                /* node previews */
                shader_preview_updatejob(sp);
@@ -801,7 +802,7 @@ static void shader_preview_free(void *customdata)
                }
                MEM_freeN(sp->worldcopy);
        }
-       if(sp->lampcopy) {
+       if (sp->lampcopy) {
                struct IDProperty *properties;
                /* node previews */
                shader_preview_updatejob(sp);
@@ -831,7 +832,7 @@ static void icon_copy_rect(ImBuf *ibuf, unsigned int w, unsigned int h, unsigned
        short ex, ey, dx, dy;
 
        /* paranoia test */
-       if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
+       if (ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
                return;
        
        /* waste of cpu cyles... but the imbuf API has no other way to scale fast (ton) */
@@ -858,14 +859,14 @@ static void icon_copy_rect(ImBuf *ibuf, unsigned int w, unsigned int h, unsigned
        IMB_scalefastImBuf(ima, ex, ey);
        
        /* if needed, convert to 32 bits */
-       if(ima->rect==NULL)
+       if (ima->rect==NULL)
                IMB_rect_from_float(ima);
 
        srect = ima->rect;
        drect = rect;
 
        drect+= dy*w+dx;
-       for (;ey > 0; ey--)           
+       for (;ey > 0; ey--) {           
                memcpy(drect,srect, ex * sizeof(int));
                drect += w;
                srect += ima->x;
@@ -878,7 +879,7 @@ static void set_alpha(char *cp, int sizex, int sizey, char alpha)
 {
        int a, size= sizex*sizey;
 
-       for(a=0; a<size; a++, cp+=4)
+       for (a=0; a<size; a++, cp+=4)
                cp[3]= alpha;
 }
 
@@ -888,13 +889,13 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat
        ID *id= sp->id;
        short idtype= GS(id->name);
 
-       if(idtype == ID_IM) {
+       if (idtype == ID_IM) {
                Image *ima= (Image*)id;
                ImBuf *ibuf= NULL;
                ImageUser iuser= {NULL};
 
                /* ima->ok is zero when Image cannot load */
-               if(ima==NULL || ima->ok==0)
+               if (ima==NULL || ima->ok==0)
                        return;
 
                /* setup dummy image user */
@@ -905,21 +906,21 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat
                 * already there. Very expensive for large images. Need to find a way to 
                 * only get existing ibuf */
                ibuf = BKE_image_get_ibuf(ima, &iuser);
-               if(ibuf==NULL || ibuf->rect==NULL)
+               if (ibuf==NULL || ibuf->rect==NULL)
                        return;
                
                icon_copy_rect(ibuf, sp->sizex, sp->sizey, sp->pr_rect);
 
                *do_update= 1;
        }
-       else if(idtype == ID_BR) {
+       else if (idtype == ID_BR) {
                Brush *br= (Brush*)id;
 
                br->icon_imbuf= get_brush_icon(br);
 
                memset(sp->pr_rect, 0x888888, sp->sizex*sp->sizey*sizeof(unsigned int));
 
-               if(!(br->icon_imbuf) || !(br->icon_imbuf->rect))
+               if (!(br->icon_imbuf) || !(br->icon_imbuf->rect))
                        return;
 
                icon_copy_rect(br->icon_imbuf, sp->sizex, sp->sizey, sp->pr_rect);
@@ -932,13 +933,13 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat
 
                /* world is rendered with alpha=0, so it wasn't displayed 
                 * this could be render option for sky to, for later */
-               if(idtype == ID_WO) {
+               if (idtype == ID_WO) {
                        set_alpha((char*)sp->pr_rect, sp->sizex, sp->sizey, 255);
                }
-               else if(idtype == ID_MA) {
+               else if (idtype == ID_MA) {
                        Material* ma = (Material*)id;
 
-                       if(ma->material_type == MA_TYPE_HALO)
+                       if (ma->material_type == MA_TYPE_HALO)
                                set_alpha((char*)sp->pr_rect, sp->sizex, sp->sizey, 255);
                }
        }
@@ -951,7 +952,7 @@ static void common_preview_startjob(void *customdata, short *stop, short *do_upd
 {
        ShaderPreview *sp= customdata;
 
-       if(sp->pr_method == PR_ICON_RENDER)
+       if (sp->pr_method == PR_ICON_RENDER)
                icon_preview_startjob(customdata, stop, do_update);
        else
                shader_preview_startjob(customdata, stop, do_update);
@@ -1069,7 +1070,7 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
        sp->id = id;
        sp->parent= parent;
        sp->slot= slot;
-       if(ob && ob->totcol) copy_v4_v4(sp->col, ob->col);
+       if (ob && ob->totcol) copy_v4_v4(sp->col, ob->col);
        else sp->col[0]= sp->col[1]= sp->col[2]= sp->col[3]= 1.0f;
        
        /* setup job */
@@ -1083,7 +1084,7 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
 void ED_preview_kill_jobs(const struct bContext *C)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
-       if(wm)
+       if (wm)
                WM_jobs_kill(wm, NULL, common_preview_startjob);
 }