style cleanup: blenkernel
authorCampbell Barton <ideasman42@gmail.com>
Sun, 6 May 2012 17:22:54 +0000 (17:22 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 6 May 2012 17:22:54 +0000 (17:22 +0000)
19 files changed:
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/bvhutils.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/colortools.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/context.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/fcurve.c
source/blender/blenkernel/intern/fmodifier.c
source/blender/blenkernel/intern/idprop.c
source/blender/blenkernel/intern/image_gen.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/packedFile.c
source/blender/blenkernel/intern/property.c
source/blender/blenkernel/intern/texture.c

index f3b106e..ed6eceb 100644 (file)
@@ -88,23 +88,23 @@ void animviz_settings_init(bAnimVizSettings *avs)
                return;
                
        /* ghosting settings */
-       avs->ghost_bc= avs->ghost_ac= 10;
+       avs->ghost_bc = avs->ghost_ac = 10;
        
-       avs->ghost_sf= 1; // xxx - take from scene instead?
-       avs->ghost_ef= 250; // xxx - take from scene instead?
+       avs->ghost_sf = 1; // xxx - take from scene instead?
+       avs->ghost_ef = 250; // xxx - take from scene instead?
        
-       avs->ghost_step= 1;
+       avs->ghost_step = 1;
        
        
        /* path settings */
-       avs->path_bc= avs->path_ac= 10;
+       avs->path_bc = avs->path_ac = 10;
        
-       avs->path_sf= 1; // xxx - take from scene instead?
-       avs->path_ef= 250; // xxx - take from scene instead?
+       avs->path_sf = 1; // xxx - take from scene instead?
+       avs->path_ef = 250; // xxx - take from scene instead?
        
-       avs->path_viewflag= (MOTIONPATH_VIEW_KFRAS|MOTIONPATH_VIEW_KFNOS);
+       avs->path_viewflag = (MOTIONPATH_VIEW_KFRAS | MOTIONPATH_VIEW_KFNOS);
        
-       avs->path_step= 1;
+       avs->path_step = 1;
 }
 
 /* ------------------- */
@@ -121,8 +121,8 @@ void animviz_free_motionpath_cache(bMotionPath *mpath)
                MEM_freeN(mpath->points);
        
        /* reset the relevant parameters */
-       mpath->points= NULL;
-       mpath->length= 0;
+       mpath->points = NULL;
+       mpath->length = 0;
 }
 
 /* Free the given motion path instance and its data 
@@ -162,22 +162,22 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec
        /* get destination data */
        if (pchan) {
                /* paths for posechannel - assume that posechannel belongs to the object */
-               avs= &ob->pose->avs;
-               dst= &pchan->mpath;
+               avs = &ob->pose->avs;
+               dst = &pchan->mpath;
        }
        else {
                /* paths for object */
-               avs= &ob->avs;
-               dst= &ob->mpath;
+               avs = &ob->avs;
+               dst = &ob->mpath;
        }
 
        /* avoid 0 size allocs */
        if (avs->path_sf >= avs->path_ef) {
                BKE_reportf(reports, RPT_ERROR,
-                                       "Motion Path frame extents invalid for %s (%d to %d).%s\n",
-                                       (pchan)? pchan->name : ob->id.name,
-                                       avs->path_sf, avs->path_ef,
-                                       (avs->path_sf == avs->path_ef)? " Cannot have single-frame paths." : "");
+                           "Motion Path frame extents invalid for %s (%d to %d).%s\n",
+                           (pchan) ? pchan->name : ob->id.name,
+                           avs->path_sf, avs->path_ef,
+                           (avs->path_sf == avs->path_ef) ? " Cannot have single-frame paths." : "");
                return NULL;
        }
 
@@ -187,7 +187,7 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec
        if (*dst != NULL) {
                int expected_length = avs->path_ef - avs->path_sf;
                
-               mpath= *dst;
+               mpath = *dst;
                
                /* path is "valid" if length is valid, but must also be of the same length as is being requested */
                if ((mpath->start_frame != mpath->end_frame) && (mpath->length > 0)) {
@@ -204,15 +204,15 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec
        }
        else {
                /* create a new motionpath, and assign it */
-               mpath= MEM_callocN(sizeof(bMotionPath), "bMotionPath");
-               *dst= mpath;
+               mpath = MEM_callocN(sizeof(bMotionPath), "bMotionPath");
+               *dst = mpath;
        }
        
        /* set settings from the viz settings */
-       mpath->start_frame= avs->path_sf;
-       mpath->end_frame= avs->path_ef;
+       mpath->start_frame = avs->path_sf;
+       mpath->end_frame = avs->path_ef;
        
-       mpath->length= mpath->end_frame - mpath->start_frame;
+       mpath->length = mpath->end_frame - mpath->start_frame;
        
        if (avs->path_bakeflag & MOTIONPATH_BAKE_HEADS)
                mpath->flag |= MOTIONPATH_FLAG_BHEAD;
@@ -220,7 +220,7 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec
                mpath->flag &= ~MOTIONPATH_FLAG_BHEAD;
        
        /* allocate a cache */
-       mpath->points= MEM_callocN(sizeof(bMotionPathVert)*mpath->length, "bMotionPathVerts");
+       mpath->points = MEM_callocN(sizeof(bMotionPathVert) * mpath->length, "bMotionPathVerts");
        
        /* tag viz settings as currently having some path(s) which use it */
        avs->path_bakeflag |= MOTIONPATH_BAKE_HAS_PATHS;
@@ -235,16 +235,16 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec
 typedef struct MPathTarget {
        struct MPathTarget *next, *prev;
        
-       bMotionPath *mpath;                     /* motion path in question */
+       bMotionPath *mpath;         /* motion path in question */
        
-       Object *ob;                                     /* source object */
-       bPoseChannel *pchan;            /* source posechannel (if applicable) */
+       Object *ob;                 /* source object */
+       bPoseChannel *pchan;        /* source posechannel (if applicable) */
 } MPathTarget;
 
 /* ........ */
 
 /* get list of motion paths to be baked for the given object
- *     - assumes the given list is ready to be used
+ *  - assumes the given list is ready to be used
  */
 // TODO: it would be nice in future to be able to update objects dependent on these bones too?
 void animviz_get_object_motionpaths(Object *ob, ListBase *targets)
@@ -254,27 +254,27 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets)
        /* object itself first */
        if ((ob->avs.recalc & ANIMVIZ_RECALC_PATHS) && (ob->mpath)) {
                /* new target for object */
-               mpt= MEM_callocN(sizeof(MPathTarget), "MPathTarget Ob");
+               mpt = MEM_callocN(sizeof(MPathTarget), "MPathTarget Ob");
                BLI_addtail(targets, mpt);
                
-               mpt->mpath= ob->mpath;
-               mpt->ob= ob;
+               mpt->mpath = ob->mpath;
+               mpt->ob = ob;
        }
        
        /* bones */
        if ((ob->pose) && (ob->pose->avs.recalc & ANIMVIZ_RECALC_PATHS)) {
-               bArmature *arm= ob->data;
+               bArmature *arm = ob->data;
                bPoseChannel *pchan;
                
-               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+               for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
                        if ((pchan->bone) && (arm->layer & pchan->bone->layer) && (pchan->mpath)) {
                                /* new target for bone */
-                               mpt= MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone");
+                               mpt = MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone");
                                BLI_addtail(targets, mpt);
                                
-                               mpt->mpath= pchan->mpath;
-                               mpt->ob= ob;
-                               mpt->pchan= pchan;
+                               mpt->mpath = pchan->mpath;
+                               mpt->ob = ob;
+                               mpt->pchan = pchan;
                        }
                }
        }
@@ -296,12 +296,12 @@ static void motionpaths_calc_optimise_depsgraph(Scene *scene, ListBase *targets)
        MPathTarget *mpt;
        
        /* make sure our temp-tag isn't already in use */
-       for (base= scene->base.first; base; base= base->next)
+       for (base = scene->base.first; base; base = base->next)
                base->object->flag &= ~BA_TEMP_TAG;
        
        /* for each target, dump its object to the start of the list if it wasn't moved already */
-       for (mpt= targets->first; mpt; mpt= mpt->next) {
-               for (base=scene->base.first; base; base=baseNext) {
+       for (mpt = targets->first; mpt; mpt = mpt->next) {
+               for (base = scene->base.first; base; base = baseNext) {
                        baseNext = base->next;
                        
                        if ((base->object == mpt->ob) && !(mpt->ob->flag & BA_TEMP_TAG)) {
@@ -322,7 +322,7 @@ static void motionpaths_calc_optimise_depsgraph(Scene *scene, ListBase *targets)
 static void motionpaths_calc_update_scene(Scene *scene)
 {
 #if 1 // 'production' optimisations always on
-       Base *base, *last=NULL;
+       Base *base, *last = NULL;
        
        /* only stuff that moves or needs display still */
        DAG_scene_update_flags(G.main, scene, scene->lay, TRUE);
@@ -331,7 +331,7 @@ static void motionpaths_calc_update_scene(Scene *scene)
         *      - all those afterwards are assumed to not be relevant for our calculations
         */
        // optimize further by moving out...
-       for (base=scene->base.first; base; base=base->next) {
+       for (base = scene->base.first; base; base = base->next) {
                if (base->object->flag & BA_TEMP_TAG)
                        last = base;
        }
@@ -339,7 +339,7 @@ static void motionpaths_calc_update_scene(Scene *scene)
        /* perform updates for tagged objects */
        // XXX: this will break if rigs depend on scene or other data that 
        // is animated but not attached to/updatable from objects
-       for (base=scene->base.first; base; base=base->next) {
+       for (base = scene->base.first; base; base = base->next) {
                /* update this object */
                BKE_object_handle_update(scene, base->object);
                
@@ -348,11 +348,11 @@ static void motionpaths_calc_update_scene(Scene *scene)
                        break;
        }
 #else // original, 'always correct' version
-       /* do all updates 
-        *      - if this is too slow, resort to using a more efficient way 
-        *        that doesn't force complete update, but for now, this is the
-        *        most accurate way!
-        */
+         /* do all updates
+          *  - if this is too slow, resort to using a more efficient way
+          *    that doesn't force complete update, but for now, this is the
+          *    most accurate way!
+          */
        BKE_scene_update_for_newframe(G.main, scene, scene->lay); // XXX this is the best way we can get anything moving
 #endif
 }
@@ -365,8 +365,8 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
        MPathTarget *mpt;
        
        /* for each target, check if it can be baked on the current frame */
-       for (mpt= targets->first; mpt; mpt= mpt->next) {        
-               bMotionPath *mpath= mpt->mpath;
+       for (mpt = targets->first; mpt; mpt = mpt->next) {
+               bMotionPath *mpath = mpt->mpath;
                bMotionPathVert *mpv;
                
                /* current frame must be within the range the cache works for 
@@ -376,7 +376,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
                        continue;
                
                /* get the relevant cache vert to write to */
-               mpv= mpath->points + (CFRA - mpath->start_frame);
+               mpv = mpath->points + (CFRA - mpath->start_frame);
                
                /* pose-channel or object path baking? */
                if (mpt->pchan) {
@@ -421,10 +421,10 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets)
        // TODO: this method could be improved...
        //      1) max range for standard baking
        //      2) minimum range for recalc baking (i.e. between keyframes, but how?)
-       for (mpt= targets->first; mpt; mpt= mpt->next) {
+       for (mpt = targets->first; mpt; mpt = mpt->next) {
                /* try to increase area to do (only as much as needed) */
-               sfra= MIN2(sfra, mpt->mpath->start_frame);
-               efra= MAX2(efra, mpt->mpath->end_frame);
+               sfra = MIN2(sfra, mpt->mpath->start_frame);
+               efra = MAX2(efra, mpt->mpath->end_frame);
        }
        if (efra <= sfra) return;
        
@@ -433,7 +433,7 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets)
        motionpaths_calc_optimise_depsgraph(scene, targets);
        
        /* calculate path over requested range */
-       for (CFRA=sfra; CFRA<=efra; CFRA++) {
+       for (CFRA = sfra; CFRA <= efra; CFRA++) {
                /* update relevant data for new frame */
                motionpaths_calc_update_scene(scene);
                
@@ -442,18 +442,18 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets)
        }
        
        /* reset original environment */
-       CFRA= cfra;
+       CFRA = cfra;
        motionpaths_calc_update_scene(scene);
        
        /* clear recalc flags from targets */
-       for (mpt= targets->first; mpt; mpt= mpt->next) {
+       for (mpt = targets->first; mpt; mpt = mpt->next) {
                bAnimVizSettings *avs;
                
                /* get pointer to animviz settings for each target */
                if (mpt->pchan)
-                       avs= &mpt->ob->pose->avs;
+                       avs = &mpt->ob->pose->avs;
                else    
-                       avs= &mpt->ob->avs;
+                       avs = &mpt->ob->avs;
                
                /* clear the flag requesting recalculation of targets */
                avs->recalc &= ~ANIMVIZ_RECALC_PATHS;
@@ -474,7 +474,7 @@ void free_path(Path *path)
 }
 
 /* calculate a curve-deform path for a curve 
- *     - only called from displist.c -> do_makeDispListCurveTypes
+ *  - only called from displist.c -> do_makeDispListCurveTypes
  */
 void calc_curvepath(Object *ob)
 {
@@ -485,92 +485,92 @@ void calc_curvepath(Object *ob)
        Nurb *nu;
        Path *path;
        float *fp, *dist, *maxdist, xyz[3];
-       float fac, d=0, fac1, fac2;
-       int a, tot, cycl=0;
+       float fac, d = 0, fac1, fac2;
+       int a, tot, cycl = 0;
        ListBase *nurbs;
        
        /* in a path vertices are with equal differences: path->len = number of verts */
        /* NOW WITH BEVELCURVE!!! */
        
-       if (ob==NULL || ob->type != OB_CURVE) return;
-       cu= ob->data;
+       if (ob == NULL || ob->type != OB_CURVE) return;
+       cu = ob->data;
 
-       nurbs= BKE_curve_nurbs_get(cu);
-       nu= nurbs->first;
+       nurbs = BKE_curve_nurbs_get(cu);
+       nu = nurbs->first;
 
        if (cu->path) free_path(cu->path);
-       cu->path= NULL;
+       cu->path = NULL;
        
-       bl= cu->bev.first;
-       if (bl==NULL || !bl->nr) return;
+       bl = cu->bev.first;
+       if (bl == NULL || !bl->nr) return;
 
-       cu->path=path= MEM_callocN(sizeof(Path), "calc_curvepath");
+       cu->path = path = MEM_callocN(sizeof(Path), "calc_curvepath");
        
        /* if POLY: last vertice != first vertice */
-       cycl= (bl->poly!= -1);
+       cycl = (bl->poly != -1);
        
-       if (cycl) tot= bl->nr;
-       else tot= bl->nr-1;
+       if (cycl) tot = bl->nr;
+       else tot = bl->nr - 1;
        
-       path->len= tot+1;
+       path->len = tot + 1;
        /* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */
-       if (path->len<nu->resolu*SEGMENTSU(nu)) path->len= nu->resolu*SEGMENTSU(nu);
+       if (path->len < nu->resolu * SEGMENTSU(nu)) path->len = nu->resolu * SEGMENTSU(nu);
        
-       dist= (float *)MEM_mallocN((tot+1)*4, "calcpathdist");
+       dist = (float *)MEM_mallocN((tot + 1) * 4, "calcpathdist");
 
-               /* all lengths in *dist */
-       bevp= bevpfirst= (BevPoint *)(bl+1);
-       fp= dist;
-       *fp= 0;
-       for (a=0; a<tot; a++) {
+       /* all lengths in *dist */
+       bevp = bevpfirst = (BevPoint *)(bl + 1);
+       fp = dist;
+       *fp = 0;
+       for (a = 0; a < tot; a++) {
                fp++;
-               if (cycl && a==tot-1)
+               if (cycl && a == tot - 1)
                        sub_v3_v3v3(xyz, bevpfirst->vec, bevp->vec);
                else
-                       sub_v3_v3v3(xyz, (bevp+1)->vec, bevp->vec);
+                       sub_v3_v3v3(xyz, (bevp + 1)->vec, bevp->vec);
                
-               *fp= *(fp-1)+len_v3(xyz);
+               *fp = *(fp - 1) + len_v3(xyz);
                bevp++;
        }
        
-       path->totdist= *fp;
-       
-               /* the path verts  in path->data */
-               /* now also with TILT value */
-       pp= path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint)*path->len, "pathdata");
+       path->totdist = *fp;
        
-       bevp= bevpfirst;
-       bevpn= bevp+1;
-       bevplast= bevpfirst + (bl->nr-1);
-       fp= dist+1;
-       maxdist= dist+tot;
-       fac= 1.0f/((float)path->len-1.0f);
-               fac = fac * path->totdist;
+       /* the path verts  in path->data */
+       /* now also with TILT value */
+       pp = path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint) * path->len, "pathdata");
+
+       bevp = bevpfirst;
+       bevpn = bevp + 1;
+       bevplast = bevpfirst + (bl->nr - 1);
+       fp = dist + 1;
+       maxdist = dist + tot;
+       fac = 1.0f / ((float)path->len - 1.0f);
+       fac = fac * path->totdist;
        
-       for (a=0; a<path->len; a++) {
+       for (a = 0; a < path->len; a++) {
                
-               d= ((float)a)*fac;
+               d = ((float)a) * fac;
                
                /* we're looking for location (distance) 'd' in the array */
-               while ((d>= *fp) && fp<maxdist) {
+               while ((d >= *fp) && fp < maxdist) {
                        fp++;
-                       if (bevp<bevplast) bevp++;
-                       bevpn= bevp+1;
-                       if (bevpn>bevplast) {
-                               if (cycl) bevpn= bevpfirst;
-                               else bevpn= bevplast;
+                       if (bevp < bevplast) bevp++;
+                       bevpn = bevp + 1;
+                       if (bevpn > bevplast) {
+                               if (cycl) bevpn = bevpfirst;
+                               else bevpn = bevplast;
                        }
                }
                
-               fac1= *(fp)- *(fp-1);
-               fac2= *(fp)-d;
-               fac1= fac2/fac1;
-               fac2= 1.0f-fac1;
+               fac1 = *(fp) - *(fp - 1);
+               fac2 = *(fp) - d;
+               fac1 = fac2 / fac1;
+               fac2 = 1.0f - fac1;
                
                interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2);
-               pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa;
-               pp->radius= fac1*bevp->radius + fac2*bevpn->radius;
-               pp->weight= fac1*bevp->weight + fac2*bevpn->weight;
+               pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa;
+               pp->radius = fac1 * bevp->radius + fac2 * bevpn->radius;
+               pp->weight = fac1 * bevp->weight + fac2 * bevpn->weight;
                interp_qt_qtqt(pp->quat, bevp->quat, bevpn->quat, fac2);
                normalize_qt(pp->quat);
                
@@ -586,13 +586,13 @@ int interval_test(int min, int max, int p1, int cycl)
 {
        if (cycl) {
                if (p1 < min) 
-                       p1=  ((p1 -min) % (max-min+1)) + max+1;
+                       p1 =  ((p1 - min) % (max - min + 1)) + max + 1;
                else if (p1 > max)
-                       p1=  ((p1 -min) % (max-min+1)) + min;
+                       p1 =  ((p1 - min) % (max - min + 1)) + min;
        }
        else {
-               if (p1 < min) p1= min;
-               else if (p1 > max) p1= max;
+               if (p1 < min) p1 = min;
+               else if (p1 > max) p1 = max;
        }
        return p1;
 }
@@ -614,84 +614,84 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua
        PathPoint *pp, *p0, *p1, *p2, *p3;
        float fac;
        float data[4];
-       int cycl=0, s0, s1, s2, s3;
+       int cycl = 0, s0, s1, s2, s3;
 
-       if (ob==NULL || ob->type != OB_CURVE) return 0;
-       cu= ob->data;
-       if (cu->path==NULL || cu->path->data==NULL) {
+       if (ob == NULL || ob->type != OB_CURVE) return 0;
+       cu = ob->data;
+       if (cu->path == NULL || cu->path->data == NULL) {
                printf("no path!\n");
                return 0;
        }
-       path= cu->path;
-       pp= path->data;
+       path = cu->path;
+       pp = path->data;
        
        /* test for cyclic */
-       bl= cu->bev.first;
+       bl = cu->bev.first;
        if (!bl) return 0;
        if (!bl->nr) return 0;
-       if (bl->poly> -1) cycl= 1;
+       if (bl->poly > -1) cycl = 1;
 
-       ctime *= (path->len-1);
+       ctime *= (path->len - 1);
        
-       s1= (int)floor(ctime);
-       fac= (float)(s1+1)-ctime;
+       s1 = (int)floor(ctime);
+       fac = (float)(s1 + 1) - ctime;
 
        /* path->len is corected for cyclic */
-       s0= interval_test(0, path->len-1-cycl, s1-1, cycl);
-       s1= interval_test(0, path->len-1-cycl, s1, cycl);
-       s2= interval_test(0, path->len-1-cycl, s1+1, cycl);
-       s3= interval_test(0, path->len-1-cycl, s1+2, cycl);
+       s0 = interval_test(0, path->len - 1 - cycl, s1 - 1, cycl);
+       s1 = interval_test(0, path->len - 1 - cycl, s1, cycl);
+       s2 = interval_test(0, path->len - 1 - cycl, s1 + 1, cycl);
+       s3 = interval_test(0, path->len - 1 - cycl, s1 + 2, cycl);
 
-       p0= pp + s0;
-       p1= pp + s1;
-       p2= pp + s2;
-       p3= pp + s3;
+       p0 = pp + s0;
+       p1 = pp + s1;
+       p2 = pp + s2;
+       p3 = pp + s3;
 
        /* note, commented out for follow constraint */
        //if (cu->flag & CU_FOLLOW) {
 
-               key_curve_tangent_weights(1.0f-fac, data, KEY_BSPLINE);
+       key_curve_tangent_weights(1.0f - fac, data, KEY_BSPLINE);
 
-               interp_v3_v3v3v3v3(dir, p0->vec, p1->vec, p2->vec, p3->vec, data);
+       interp_v3_v3v3v3v3(dir, p0->vec, p1->vec, p2->vec, p3->vec, data);
 
-               /* make compatible with vectoquat */
-               negate_v3(dir);
+       /* make compatible with vectoquat */
+       negate_v3(dir);
        //}
        
-       nu= cu->nurb.first;
+       nu = cu->nurb.first;
 
        /* make sure that first and last frame are included in the vectors here  */
-       if (nu->type == CU_POLY) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR);
-       else if (nu->type == CU_BEZIER) key_curve_position_weights(1.0f-fac, data, KEY_LINEAR);
-       else if (s0==s1 || p2==p3) key_curve_position_weights(1.0f-fac, data, KEY_CARDINAL);
-       else key_curve_position_weights(1.0f-fac, data, KEY_BSPLINE);
+       if (nu->type == CU_POLY) key_curve_position_weights(1.0f - fac, data, KEY_LINEAR);
+       else if (nu->type == CU_BEZIER) key_curve_position_weights(1.0f - fac, data, KEY_LINEAR);
+       else if (s0 == s1 || p2 == p3) key_curve_position_weights(1.0f - fac, data, KEY_CARDINAL);
+       else key_curve_position_weights(1.0f - fac, data, KEY_BSPLINE);
 
-       vec[0]= data[0]*p0->vec[0] + data[1]*p1->vec[0] + data[2]*p2->vec[0] + data[3]*p3->vec[0] ; /* X */
-       vec[1]= data[0]*p0->vec[1] + data[1]*p1->vec[1] + data[2]*p2->vec[1] + data[3]*p3->vec[1] ; /* Y */
-       vec[2]= data[0]*p0->vec[2] + data[1]*p1->vec[2] + data[2]*p2->vec[2] + data[3]*p3->vec[2] ; /* Z */
-       vec[3]= data[0]*p0->vec[3] + data[1]*p1->vec[3] + data[2]*p2->vec[3] + data[3]*p3->vec[3] ; /* Tilt, should not be needed since we have quat still used */
+       vec[0] = data[0] * p0->vec[0] + data[1] * p1->vec[0] + data[2] * p2->vec[0] + data[3] * p3->vec[0]; /* X */
+       vec[1] = data[0] * p0->vec[1] + data[1] * p1->vec[1] + data[2] * p2->vec[1] + data[3] * p3->vec[1]; /* Y */
+       vec[2] = data[0] * p0->vec[2] + data[1] * p1->vec[2] + data[2] * p2->vec[2] + data[3] * p3->vec[2]; /* Z */
+       vec[3] = data[0] * p0->vec[3] + data[1] * p1->vec[3] + data[2] * p2->vec[3] + data[3] * p3->vec[3]; /* Tilt, should not be needed since we have quat still used */
 
        if (quat) {
                float totfac, q1[4], q2[4];
 
-               totfac= data[0]+data[3];
-               if (totfac>FLT_EPSILON) interp_qt_qtqt(q1, p0->quat, p3->quat, data[3] / totfac);
-               else                                    copy_qt_qt(q1, p1->quat);
+               totfac = data[0] + data[3];
+               if (totfac > FLT_EPSILON) interp_qt_qtqt(q1, p0->quat, p3->quat, data[3] / totfac);
+               else copy_qt_qt(q1, p1->quat);
 
-               totfac= data[1]+data[2];
-               if (totfac>FLT_EPSILON) interp_qt_qtqt(q2, p1->quat, p2->quat, data[2] / totfac);
-               else                                    copy_qt_qt(q2, p3->quat);
+               totfac = data[1] + data[2];
+               if (totfac > FLT_EPSILON) interp_qt_qtqt(q2, p1->quat, p2->quat, data[2] / totfac);
+               else copy_qt_qt(q2, p3->quat);
 
-               totfac = data[0]+data[1]+data[2]+data[3];
-               if (totfac>FLT_EPSILON) interp_qt_qtqt(quat, q1, q2, (data[1]+data[2]) / totfac);
-               else                                    copy_qt_qt(quat, q2);
+               totfac = data[0] + data[1] + data[2] + data[3];
+               if (totfac > FLT_EPSILON) interp_qt_qtqt(quat, q1, q2, (data[1] + data[2]) / totfac);
+               else copy_qt_qt(quat, q2);
        }
 
        if (radius)
-               *radius= data[0]*p0->radius + data[1]*p1->radius + data[2]*p2->radius + data[3]*p3->radius;
+               *radius = data[0] * p0->radius + data[1] * p1->radius + data[2] * p2->radius + data[3] * p3->radius;
 
        if (weight)
-               *weight= data[0]*p0->weight + data[1]*p1->weight + data[2]*p2->weight + data[3]*p3->weight;
+               *weight = data[0] * p0->weight + data[1] * p1->weight + data[2] * p2->weight + data[3] * p3->weight;
 
        return 1;
 }
@@ -701,17 +701,17 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua
 
 static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int type, int animated)
 {
-       DupliObject *dob= MEM_callocN(sizeof(DupliObject), "dupliobject");
+       DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject");
        
        BLI_addtail(lb, dob);
-       dob->ob= ob;
+       dob->ob = ob;
        copy_m4_m4(dob->mat, mat);
        copy_m4_m4(dob->omat, ob->obmat);
-       dob->origlay= ob->lay;
-       dob->index= index;
-       dob->type= type;
-       dob->animated= (type == OB_DUPLIGROUP) && animated;
-       ob->lay= lay;
+       dob->origlay = ob->lay;
+       dob->index = index;
+       dob->type = type;
+       dob->animated = (type == OB_DUPLIGROUP) && animated;
+       ob->lay = lay;
        
        return dob;
 }
@@ -723,20 +723,20 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i
        GroupObject *go;
        float mat[4][4], tmat[4][4];
        
-       if (ob->dup_group==NULL) return;
-       group= ob->dup_group;
+       if (ob->dup_group == NULL) return;
+       group = ob->dup_group;
        
        /* simple preventing of too deep nested groups */
-       if (level>MAX_DUPLI_RECUR) return;
+       if (level > MAX_DUPLI_RECUR) return;
        
        /* handles animated groups, and */
        /* we need to check update for objects that are not in scene... */
        group_handle_recalc_and_update(scene, ob, group);
-       animated= animated || group_is_animated(ob, group);
+       animated = animated || group_is_animated(ob, group);
        
-       for (go= group->gobject.first; go; go= go->next) {
+       for (go = group->gobject.first; go; go = go->next) {
                /* note, if you check on layer here, render goes wrong... it still deforms verts and uses parent imat */
-               if (go->ob!=ob) {
+               if (go->ob != ob) {
                        
                        /* group dupli offset, should apply after everything else */
                        if (!is_zero_v3(group->dupli_ofs)) {
@@ -748,22 +748,22 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i
                                mult_m4_m4m4(mat, ob->obmat, go->ob->obmat);
                        }
                        
-                       dob= new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated);
+                       dob = new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated);
 
                        /* check the group instance and object layers match, also that the object visible flags are ok. */
-                       if (    (dob->origlay & group->layer)==0 ||
-                               (G.rendering==0 && dob->ob->restrictflag & OB_RESTRICT_VIEW) ||
-                               (G.rendering && dob->ob->restrictflag & OB_RESTRICT_RENDER)
-                       ) {
-                               dob->no_draw= 1;
+                       if (    (dob->origlay & group->layer) == 0 ||
+                               (G.rendering == 0 && dob->ob->restrictflag & OB_RESTRICT_VIEW) ||
+                               (G.rendering && dob->ob->restrictflag & OB_RESTRICT_RENDER)
+                               ) {
+                               dob->no_draw = 1;
                        }
                        else {
-                               dob->no_draw= 0;
+                               dob->no_draw = 0;
                        }
 
                        if (go->ob->transflag & OB_DUPLI) {
                                copy_m4_m4(dob->ob->obmat, dob->mat);
-                               object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, level+1, animated);
+                               object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, level + 1, animated);
                                copy_m4_m4(dob->ob->obmat, dob->omat);
                        }
                }
@@ -772,7 +772,7 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i
 
 static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, int animated)
 {
-       extern int enable_cu_speed;     /* object.c */
+       extern int enable_cu_speed; /* object.c */
        Object copyob;
        int cfrao = scene->r.cfra;
        int dupend = ob->dupend;
@@ -783,7 +783,7 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level,
        /* if we don't have any data/settings which will lead to object movement,
         * don't waste time trying, as it will all look the same...
         */
-       if (ob->parent==NULL && ob->constraints.first==NULL && ob->adt==NULL) 
+       if (ob->parent == NULL && ob->constraints.first == NULL && ob->adt == NULL)
                return;
        
        /* make a copy of the object's original data (before any dupli-data overwrites it) 
@@ -794,18 +794,18 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level,
        copyob = *ob;
        
        /* duplicate over the required range */
-       if (ob->transflag & OB_DUPLINOSPEED) enable_cu_speed= 0;
+       if (ob->transflag & OB_DUPLINOSPEED) enable_cu_speed = 0;
        
-       for (scene->r.cfra= ob->dupsta; scene->r.cfra<=dupend; scene->r.cfra++) {
-               short ok= 1;
+       for (scene->r.cfra = ob->dupsta; scene->r.cfra <= dupend; scene->r.cfra++) {
+               short ok = 1;
                
                /* - dupoff = how often a frames within the range shouldn't be made into duplis
                 * - dupon = the length of each "skipping" block in frames
                 */
                if (ob->dupoff) {
-                       ok= scene->r.cfra - ob->dupsta;
-                       ok= ok % (ob->dupon+ob->dupoff);
-                       ok= (ok < ob->dupon);
+                       ok = scene->r.cfra - ob->dupsta;
+                       ok = ok % (ob->dupon + ob->dupoff);
+                       ok = (ok < ob->dupon);
                }
                
                if (ok) {       
@@ -818,17 +818,17 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level,
                        BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
                        BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
                        
-                       dob= new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, OB_DUPLIFRAMES, animated);
+                       dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, OB_DUPLIFRAMES, animated);
                        copy_m4_m4(dob->omat, copyob.obmat);
                }
        }
 
-       enable_cu_speed= 1;
+       enable_cu_speed = 1;
        
        /* reset frame to original frame, then re-evaluate animation as above 
         * as 2.5 animation data may have far-reaching consequences
         */
-       scene->r.cfra= cfrao;
+       scene->r.cfra = cfrao;
        
        BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
        BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
@@ -857,7 +857,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
                                   const float no_f[3], const short no_s[3])
 {
        DupliObject *dob;
-       vertexDupliData *vdd= userData;
+       vertexDupliData *vdd = userData;
        float vec[3], q2[4], mat[3][3], tmat[4][4], obmat[4][4];
        int origlay;
        
@@ -870,10 +870,10 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
        
        if (vdd->par->transflag & OB_DUPLIROT) {
                if (no_f) {
-                       vec[0]= -no_f[0]; vec[1]= -no_f[1]; vec[2]= -no_f[2];
+                       vec[0] = -no_f[0]; vec[1] = -no_f[1]; vec[2] = -no_f[2];
                }
                else if (no_s) {
-                       vec[0]= -no_s[0]; vec[1]= -no_s[1]; vec[2]= -no_s[2];
+                       vec[0] = -no_s[0]; vec[1] = -no_s[1]; vec[2] = -no_s[2];
                }
                
                vec_to_quat(q2, vec, vdd->ob->trackflag, vdd->ob->upflag);
@@ -885,7 +885,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
 
        origlay = vdd->ob->lay;
        
-       dob= new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS, vdd->animated);
+       dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS, vdd->animated);
 
        /* restore the original layer so that each dupli will have proper dob->origlay */
        vdd->ob->lay = origlay;
@@ -897,7 +897,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
                float tmpmat[4][4];
                copy_m4_m4(tmpmat, vdd->ob->obmat);
                copy_m4_m4(vdd->ob->obmat, obmat); /* pretend we are really this mat */
-               object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->level+1, vdd->animated);
+               object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->level + 1, vdd->animated);
                copy_m4_m4(vdd->ob->obmat, tmpmat);
        }
 }
@@ -905,13 +905,13 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
 static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int level, int animated)
 {
        Object *ob, *ob_iter;
-       Mesh *me= par->data;
+       Mesh *me = par->data;
        Base *base = NULL;
        DerivedMesh *dm;
        vertexDupliData vdd;
        Scene *sce = NULL;
        Group *group = NULL;
-       GroupObject * go = NULL;
+       GroupObject *go = NULL;
        BMEditMesh *em;
        float vec[3], no[3], pmat[4][4];
        int totvert, a, oblay;
@@ -920,54 +920,54 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
        copy_m4_m4(pmat, par->obmat);
        
        /* simple preventing of too deep nested groups */
-       if (level>MAX_DUPLI_RECUR) return;
+       if (level > MAX_DUPLI_RECUR) return;
        
        em = me->edit_btmesh;
        
        if (em) {
-               dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
+               dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
        }
        else
-               dm= mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
+               dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
        
        if (G.rendering) {
-               vdd.orco= (float(*)[3])BKE_mesh_orco_verts_get(par);
+               vdd.orco = (float(*)[3])BKE_mesh_orco_verts_get(par);
                BKE_mesh_orco_verts_transform(me, vdd.orco, me->totvert, 0);
        }
        else
-               vdd.orco= NULL;
+               vdd.orco = NULL;
        
        totvert = dm->getNumVerts(dm);
 
        /* having to loop on scene OR group objects is NOT FUN */
        if (GS(id->name) == ID_SCE) {
                sce = (Scene *)id;
-               lay= sce->lay;
-               base= sce->base.first;
+               lay = sce->lay;
+               base = sce->base.first;
        }
        else {
                group = (Group *)id;
-               lay= group->layer;
+               lay = group->layer;
                go = group->gobject.first;
        }
        
        /* Start looping on Scene OR Group objects */
        while (base || go) { 
                if (sce) {
-                       ob_iter= base->object;
+                       ob_iter = base->object;
                        oblay = base->lay;
                }
                else {
-                       ob_iter= go->ob;
+                       ob_iter = go->ob;
                        oblay = ob_iter->lay;
                }
                
-               if (lay & oblay && scene->obedit!=ob_iter) {
-                       ob=ob_iter->parent;
+               if (lay & oblay && scene->obedit != ob_iter) {
+                       ob = ob_iter->parent;
                        while (ob) {
-                               if (ob==par) {
+                               if (ob == par) {
                                        ob = ob_iter;
-       /* End Scene/Group object loop, below is generic */
+                                       /* End Scene/Group object loop, below is generic */
                                        
                                        
                                        /* par_space_mat - only used for groups so we can modify the space dupli's are in
@@ -978,23 +978,23 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
                                        else
                                                copy_m4_m4(vdd.obmat, ob->obmat);
 
-                                       vdd.id= id;
-                                       vdd.level= level;
-                                       vdd.animated= animated;
-                                       vdd.lb= lb;
-                                       vdd.ob= ob;
-                                       vdd.scene= scene;
-                                       vdd.par= par;
+                                       vdd.id = id;
+                                       vdd.level = level;
+                                       vdd.animated = animated;
+                                       vdd.lb = lb;
+                                       vdd.ob = ob;
+                                       vdd.scene = scene;
+                                       vdd.par = par;
                                        copy_m4_m4(vdd.pmat, pmat);
                                        
                                        /* mballs have a different dupli handling */
-                                       if (ob->type!=OB_MBALL) ob->flag |= OB_DONE;    /* doesnt render */
+                                       if (ob->type != OB_MBALL) ob->flag |= OB_DONE;  /* doesnt render */
 
                                        if (me->edit_btmesh) {
-                                               dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void*) &vdd);
+                                               dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void *) &vdd);
                                        }
                                        else {
-                                               for (a=0; a<totvert; a++) {
+                                               for (a = 0; a < totvert; a++) {
                                                        dm->getVertCo(dm, a, vec);
                                                        dm->getVertNo(dm, a, no);
                                                        
@@ -1012,11 +1012,11 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
                                        
                                        break;
                                }
-                               ob= ob->parent;
+                               ob = ob->parent;
                        }
                }
-               if (sce)        base= base->next;       /* scene loop */
-               else            go= go->next;           /* group loop */
+               if (sce) base = base->next;     /* scene loop */
+               else go = go->next;             /* group loop */
        }
 
        if (vdd.orco)
@@ -1030,7 +1030,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
        Base *base = NULL;
        DupliObject *dob;
        DerivedMesh *dm;
-       Mesh *me= par->data;
+       Mesh *me = par->data;
        MLoopUV *mloopuv;
        MPoly *mpoly, *mp;
        MLoop *mloop;
@@ -1044,63 +1044,63 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
        float ob__obmat[4][4]; /* needed for groups where the object matrix needs to be modified */
        
        /* simple preventing of too deep nested groups */
-       if (level>MAX_DUPLI_RECUR) return;
+       if (level > MAX_DUPLI_RECUR) return;
        
        copy_m4_m4(pmat, par->obmat);
        em = me->edit_btmesh;
 
        if (em) {
-               dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
+               dm = editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
        }
        else {
                dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
        }
 
-       totface= dm->getNumPolys(dm);
-       mpoly= dm->getPolyArray(dm);
-       mloop= dm->getLoopArray(dm);
-       mvert= dm->getVertArray(dm);
+       totface = dm->getNumPolys(dm);
+       mpoly = dm->getPolyArray(dm);
+       mloop = dm->getLoopArray(dm);
+       mvert = dm->getVertArray(dm);
 
        if (G.rendering) {
 
-               orco= (float(*)[3])BKE_mesh_orco_verts_get(par);
+               orco = (float(*)[3])BKE_mesh_orco_verts_get(par);
                BKE_mesh_orco_verts_transform(me, orco, me->totvert, 0);
-               mloopuv= me->mloopuv;
+               mloopuv = me->mloopuv;
        }
        else {
-               orco= NULL;
-               mloopuv= NULL;
+               orco = NULL;
+               mloopuv = NULL;
        }
        
        /* having to loop on scene OR group objects is NOT FUN */
        if (GS(id->name) == ID_SCE) {
                sce = (Scene *)id;
-               lay= sce->lay;
-               base= sce->base.first;
+               lay = sce->lay;
+               base = sce->base.first;
        }
        else {
                group = (Group *)id;
-               lay= group->layer;
+               lay = group->layer;
                go = group->gobject.first;
        }
        
        /* Start looping on Scene OR Group objects */
        while (base || go) { 
                if (sce) {
-                       ob_iter= base->object;
+                       ob_iter = base->object;
                        oblay = base->lay;
                }
                else {
-                       ob_iter= go->ob;
+                       ob_iter = go->ob;
                        oblay = ob_iter->lay;
                }
                
-               if (lay & oblay && scene->obedit!=ob_iter) {
-                       ob=ob_iter->parent;
+               if (lay & oblay && scene->obedit != ob_iter) {
+                       ob = ob_iter->parent;
                        while (ob) {
-                               if (ob==par) {
+                               if (ob == par) {
                                        ob = ob_iter;
-       /* End Scene/Group object loop, below is generic */
+                                       /* End Scene/Group object loop, below is generic */
                                        
                                        /* par_space_mat - only used for groups so we can modify the space dupli's are in
                                         * when par_space_mat is NULL ob->obmat can be used instead of ob__obmat
@@ -1113,9 +1113,9 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                        copy_m3_m4(imat, ob->parentinv);
                                                
                                        /* mballs have a different dupli handling */
-                                       if (ob->type!=OB_MBALL) ob->flag |= OB_DONE;    /* doesnt render */
+                                       if (ob->type != OB_MBALL) ob->flag |= OB_DONE;  /* doesnt render */
 
-                                       for (a=0, mp= mpoly; a<totface; a++, mp++) {
+                                       for (a = 0, mp = mpoly; a < totface; a++, mp++) {
                                                int mv1;
                                                int mv2;
                                                int mv3;
@@ -1125,19 +1125,19 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                                float *v3;
                                                /* float *v4; */ /* UNUSED */
                                                float cent[3], quat[4], mat[3][3], mat3[3][3], tmat[4][4], obmat[4][4];
-                                               MLoop *loopstart= mloop + mp->loopstart;
+                                               MLoop *loopstart = mloop + mp->loopstart;
 
                                                if (mp->totloop < 3) {
                                                        /* highly unlikely but to be safe */
                                                        continue;
                                                }
                                                else {
-                                                       v1= mvert[(mv1= loopstart[0].v)].co;
-                                                       v2= mvert[(mv2= loopstart[1].v)].co;
-                                                       v3= mvert[(mv3= loopstart[2].v)].co;
+                                                       v1 = mvert[(mv1 = loopstart[0].v)].co;
+                                                       v2 = mvert[(mv2 = loopstart[1].v)].co;
+                                                       v3 = mvert[(mv3 = loopstart[2].v)].co;
 #if 0
                                                        if (mp->totloop > 3) {
-                                                               v4= mvert[(mv4= loopstart[3].v)].co;
+                                                               v4 = mvert[(mv4 = loopstart[3].v)].co;
                                                        }
 #endif
                                                }
@@ -1160,8 +1160,8 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                                
                                                /* scale */
                                                if (par->transflag & OB_DUPLIFACES_SCALE) {
-                                                       float size= BKE_mesh_calc_poly_area(mp, loopstart, mvert, NULL);
-                                                       size= sqrtf(size) * par->dupfacesca;
+                                                       float size = BKE_mesh_calc_poly_area(mp, loopstart, mvert, NULL);
+                                                       size = sqrtf(size) * par->dupfacesca;
                                                        mul_m3_fl(mat, size);
                                                }
                                                
@@ -1171,9 +1171,9 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                                copy_m4_m4(tmat, obmat);
                                                mul_m4_m4m3(obmat, tmat, mat);
                                                
-                                               dob= new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIFACES, animated);
+                                               dob = new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIFACES, animated);
                                                if (G.rendering) {
-                                                       w= 1.0f / (float)mp->totloop;
+                                                       w = 1.0f / (float)mp->totloop;
 
                                                        if (orco) {
                                                                int j;
@@ -1194,18 +1194,18 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                                                        float tmpmat[4][4];
                                                        copy_m4_m4(tmpmat, ob->obmat);
                                                        copy_m4_m4(ob->obmat, obmat); /* pretend we are really this mat */
-                                                       object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, level+1, animated);
+                                                       object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, level + 1, animated);
                                                        copy_m4_m4(ob->obmat, tmpmat);
                                                }
                                        }
                                        
                                        break;
                                }
-                               ob= ob->parent;
+                               ob = ob->parent;
                        }
                }
-               if (sce)        base= base->next;       /* scene loop */
-               else            go= go->next;           /* group loop */
+               if (sce) base = base->next;     /* scene loop */
+               else go = go->next;             /* group loop */
        }
 
        if (orco)
@@ -1217,30 +1217,30 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
 static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], ParticleSystem *psys, int level, int animated)
 {
        GroupObject *go;
-       Object *ob=NULL, **oblist=NULL, obcopy, *obcopylist=NULL;
+       Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL;
        DupliObject *dob;
        ParticleDupliWeight *dw;
        ParticleSettings *part;
        ParticleData *pa;
-       ChildParticle *cpa=NULL;
+       ChildParticle *cpa = NULL;
        ParticleKey state;
        ParticleCacheKey *cache;
        float ctime, pa_time, scale = 1.0f;
-       float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size=0.0;
+       float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size = 0.0;
        float (*obmat)[4], (*oldobmat)[4];
        int a, b, counter, hair = 0;
-       int totpart, totchild, totgroup=0 /*, pa_num */;
+       int totpart, totchild, totgroup = 0 /*, pa_num */;
 
        int no_draw_flag = PARS_UNEXIST;
 
-       if (psys==NULL) return;
+       if (psys == NULL) return;
        
        /* simple preventing of too deep nested groups */
-       if (level>MAX_DUPLI_RECUR) return;
+       if (level > MAX_DUPLI_RECUR) return;
        
-       part=psys->part;
+       part = psys->part;
 
-       if (part==NULL)
+       if (part == NULL)
                return;
 
        if (!psys_check_enabled(par, psys))
@@ -1256,12 +1256,12 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
 
        BLI_srandom(31415926 + psys->seed);
 
-       if ((psys->renderdata || part->draw_as==PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
-               ParticleSimulationData sim= {NULL};
-               sim.scene= scene;
-               sim.ob= par;
-               sim.psys= psys;
-               sim.psmd= psys_get_modifier(par, psys);
+       if ((psys->renderdata || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
+               ParticleSimulationData sim = {NULL};
+               sim.scene = scene;
+               sim.ob = par;
+               sim.psys = psys;
+               sim.psmd = psys_get_modifier(par, psys);
                /* make sure emitter imat is in global coordinates instead of render view coordinates */
                invert_m4_m4(par->imat, par->obmat);
 
@@ -1274,7 +1274,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                        if (part->dup_group == NULL || part->dup_group->gobject.first == NULL)
                                return;
 
-                       for (go=part->dup_group->gobject.first; go; go=go->next)
+                       for (go = part->dup_group->gobject.first; go; go = go->next)
                                if (go->ob == par)
                                        return;
                }
@@ -1282,7 +1282,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                /* if we have a hair particle system, use the path cache */
                if (part->type == PART_HAIR) {
                        if (psys->flag & PSYS_HAIR_DONE)
-                               hair= (totchild == 0 || psys->childcache) && psys->pathcache;
+                               hair = (totchild == 0 || psys->childcache) && psys->pathcache;
                        if (!hair)
                                return;
                        
@@ -1296,29 +1296,29 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                psys->lattice = psys_get_lattice(&sim);
 
                /* gather list of objects or single object */
-               if (part->ren_as==PART_DRAW_GR) {
+               if (part->ren_as == PART_DRAW_GR) {
                        group_handle_recalc_and_update(scene, par, part->dup_group);
 
                        if (part->draw & PART_DRAW_COUNT_GR) {
-                               for (dw=part->dupliweights.first; dw; dw=dw->next)
+                               for (dw = part->dupliweights.first; dw; dw = dw->next)
                                        totgroup += dw->count;
                        }
                        else {
-                               for (go=part->dup_group->gobject.first; go; go=go->next)
+                               for (go = part->dup_group->gobject.first; go; go = go->next)
                                        totgroup++;
                        }
 
                        /* we also copy the actual objects to restore afterwards, since
                         * BKE_object_where_is_calc_time will change the object which breaks transform */
-                       oblist = MEM_callocN(totgroup*sizeof(Object *), "dupgroup object list");
-                       obcopylist = MEM_callocN(totgroup*sizeof(Object), "dupgroup copy list");
+                       oblist = MEM_callocN(totgroup * sizeof(Object *), "dupgroup object list");
+                       obcopylist = MEM_callocN(totgroup * sizeof(Object), "dupgroup copy list");
 
                        
                        if (part->draw & PART_DRAW_COUNT_GR && totgroup) {
                                dw = part->dupliweights.first;
 
-                               for (a=0; a<totgroup; dw=dw->next) {
-                                       for (b=0; b<dw->count; b++, a++) {
+                               for (a = 0; a < totgroup; dw = dw->next) {
+                                       for (b = 0; b < dw->count; b++, a++) {
                                                oblist[a] = dw->ob;
                                                obcopylist[a] = *dw->ob;
                                        }
@@ -1326,7 +1326,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                        }
                        else {
                                go = part->dup_group->gobject.first;
-                               for (a=0; a<totgroup; a++, go=go->next) {
+                               for (a = 0; a < totgroup; a++, go = go->next) {
                                        oblist[a] = go->ob;
                                        obcopylist[a] = *go->ob;
                                }
@@ -1337,13 +1337,13 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                        obcopy = *ob;
                }
 
-               if (totchild==0 || part->draw & PART_DRAW_PARENT)
+               if (totchild == 0 || part->draw & PART_DRAW_PARENT)
                        a = 0;
                else
                        a = totpart;
 
-               for (pa=psys->particles, counter=0; a<totpart+totchild; a++, pa++, counter++) {
-                       if (a<totpart) {
+               for (pa = psys->particles, counter = 0; a < totpart + totchild; a++, pa++, counter++) {
+                       if (a < totpart) {
                                /* handle parent particle */
                                if (pa->flag & no_draw_flag)
                                        continue;
@@ -1364,29 +1364,29 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                        /* some hair paths might be non-existent so they can't be used for duplication */
                        if (hair &&
                            ((a < totpart && psys->pathcache[a]->steps < 0) ||
-                            (a >= totpart && psys->childcache[a-totpart]->steps < 0)))
+                            (a >= totpart && psys->childcache[a - totpart]->steps < 0)))
                        {
                                continue;
                        }
 
-                       if (part->ren_as==PART_DRAW_GR) {
+                       if (part->ren_as == PART_DRAW_GR) {
                                /* prevent divide by zero below [#28336] */
                                if (totgroup == 0)
                                        continue;
 
                                /* for groups, pick the object based on settings */
-                               if (part->draw&PART_DRAW_RAND_GR)
-                                       b= BLI_rand() % totgroup;
+                               if (part->draw & PART_DRAW_RAND_GR)
+                                       b = BLI_rand() % totgroup;
                                else
-                                       b= a % totgroup;
+                                       b = a % totgroup;
 
                                ob = oblist[b];
                                obmat = oblist[b]->obmat;
                                oldobmat = obcopylist[b].obmat;
                        }
                        else {
-                               obmat= ob->obmat;
-                               oldobmat= obcopy.obmat;
+                               obmat = ob->obmat;
+                               oldobmat = obcopy.obmat;
                        }
 
                        if (hair) {
@@ -1396,12 +1396,12 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                                        psys_get_dupli_path_transform(&sim, pa, NULL, cache, pamat, &scale);
                                }
                                else {
-                                       cache = psys->childcache[a-totpart];
+                                       cache = psys->childcache[a - totpart];
                                        psys_get_dupli_path_transform(&sim, NULL, cpa, cache, pamat, &scale);
                                }
 
                                copy_v3_v3(pamat[3], cache->co);
-                               pamat[3][3]= 1.0f;
+                               pamat[3][3] = 1.0f;
                                
                        }
                        else {
@@ -1415,17 +1415,17 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                                        normalize_qt_qt(tquat, state.rot);
                                        quat_to_mat4(pamat, tquat);
                                        copy_v3_v3(pamat[3], state.co);
-                                       pamat[3][3]= 1.0f;
+                                       pamat[3][3] = 1.0f;
                                }
                        }
 
-                       if (part->ren_as==PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) {
-                               for (go= part->dup_group->gobject.first, b=0; go; go= go->next, b++) {
+                       if (part->ren_as == PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) {
+                               for (go = part->dup_group->gobject.first, b = 0; go; go = go->next, b++) {
 
                                        copy_m4_m4(tmat, oblist[b]->obmat);
                                        /* apply particle scale */
-                                       mul_mat3_m4_fl(tmat, size*scale);
-                                       mul_v3_fl(tmat[3], size*scale);
+                                       mul_mat3_m4_fl(tmat, size * scale);
+                                       mul_v3_fl(tmat[3], size * scale);
                                        /* group dupli offset, should apply after everything else */
                                        if (!is_zero_v3(part->dup_group->dupli_ofs))
                                                sub_v3_v3v3(tmat[3], tmat[3], part->dup_group->dupli_ofs);
@@ -1437,7 +1437,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                                        else
                                                copy_m4_m4(mat, tmat);
 
-                                       dob= new_dupli_object(lb, go->ob, mat, par->lay, counter, OB_DUPLIPARTS, animated);
+                                       dob = new_dupli_object(lb, go->ob, mat, par->lay, counter, OB_DUPLIPARTS, animated);
                                        copy_m4_m4(dob->omat, obcopylist[b].obmat);
                                        if (G.rendering)
                                                psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
@@ -1445,7 +1445,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                        }
                        else {
                                /* to give ipos in object correct offset */
-                               BKE_object_where_is_calc_time(scene, ob, ctime-pa_time);
+                               BKE_object_where_is_calc_time(scene, ob, ctime - pa_time);
 
                                copy_v3_v3(vec, obmat[3]);
                                obmat[3][0] = obmat[3][1] = obmat[3][2] = 0.0f;
@@ -1457,7 +1457,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                                        xvec[1] = xvec[2] = 0;
                                        vec_to_quat(q, xvec, ob->trackflag, ob->upflag);
                                        quat_to_mat4(obmat, q);
-                                       obmat[3][3]= 1.0f;
+                                       obmat[3][3] = 1.0f;
                                }
                                
                                /* Normal particles and cached hair live in global space so we need to
@@ -1469,7 +1469,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                                        copy_m4_m4(mat, pamat);
 
                                mult_m4_m4m4(tmat, mat, obmat);
-                               mul_mat3_m4_fl(tmat, size*scale);
+                               mul_mat3_m4_fl(tmat, size * scale);
 
                                if (par_space_mat)
                                        mult_m4_m4m4(mat, par_space_mat, tmat);
@@ -1479,7 +1479,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                                if (part->draw & PART_DRAW_GLOBAL_OB)
                                        add_v3_v3v3(mat[3], mat[3], vec);
 
-                               dob= new_dupli_object(lb, ob, mat, ob->lay, counter, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated);
+                               dob = new_dupli_object(lb, ob, mat, ob->lay, counter, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated);
                                copy_m4_m4(dob->omat, oldobmat);
                                if (G.rendering)
                                        psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
@@ -1487,12 +1487,12 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
                }
 
                /* restore objects since they were changed in BKE_object_where_is_calc_time */
-               if (part->ren_as==PART_DRAW_GR) {
-                       for (a=0; a<totgroup; a++)
-                               *(oblist[a])= obcopylist[a];
+               if (part->ren_as == PART_DRAW_GR) {
+                       for (a = 0; a < totgroup; a++)
+                               *(oblist[a]) = obcopylist[a];
                }
                else
-                       *ob= obcopy;
+                       *ob = obcopy;
        }
 
        /* clean up */
@@ -1512,19 +1512,19 @@ static Object *find_family_object(Object **obar, char *family, char ch)
        Object *ob;
        int flen;
        
-       if ( obar[(int)ch] ) return obar[(int)ch];
+       if (obar[(int)ch]) return obar[(int)ch];
        
-       flen= strlen(family);
+       flen = strlen(family);
        
-       ob= G.main->object.first;
+       ob = G.main->object.first;
        while (ob) {
                if (ob->id.name[flen + 2] == ch) {
-                       if ( strncmp(ob->id.name+2, family, flen)==0 ) break;
+                       if (strncmp(ob->id.name + 2, family, flen) == 0) break;
                }
-               ob= ob->id.next;
+               ob = ob->id.next;
        }
        
-       obar[(int)ch]= ob;
+       obar[(int)ch] = ob;
        
        return ob;
 }
@@ -1532,37 +1532,37 @@ static Object *find_family_object(Object **obar, char *family, char ch)
 
 static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, int animated)
 {
-       Object *ob, *obar[256]= {NULL};
+       Object *ob, *obar[256] = {NULL};
        Curve *cu;
        struct chartrans *ct, *chartransdata;
        float vec[3], obmat[4][4], pmat[4][4], fsize, xof, yof;
        int slen, a;
        
        /* simple preventing of too deep nested groups */
-       if (level>MAX_DUPLI_RECUR) return;
+       if (level > MAX_DUPLI_RECUR) return;
        
        copy_m4_m4(pmat, par->obmat);
        
        /* in par the family name is stored, use this to find the other objects */
        
-       chartransdata= BKE_vfont_to_curve(G.main, scene, par, FO_DUPLI);
-       if (chartransdata==NULL) return;
+       chartransdata = BKE_vfont_to_curve(G.main, scene, par, FO_DUPLI);
+       if (chartransdata == NULL) return;
 
-       cu= par->data;
-       slen= strlen(cu->str);
-       fsize= cu->fsize;
-       xof= cu->xof;
-       yof= cu->yof;
+       cu = par->data;
+       slen = strlen(cu->str);
+       fsize = cu->fsize;
+       xof = cu->xof;
+       yof = cu->yof;
        
-       ct= chartransdata;
+       ct = chartransdata;
        
-       for (a=0; a<slen; a++, ct++) {
+       for (a = 0; a < slen; a++, ct++) {
                
-               ob= find_family_object(obar, cu->family, cu->str[a]);
+               ob = find_family_object(obar, cu->family, cu->str[a]);
                if (ob) {
-                       vec[0]= fsize*(ct->xof - xof);
-                       vec[1]= fsize*(ct->yof - yof);
-                       vec[2]= 0.0;
+                       vec[0] = fsize * (ct->xof - xof);
+                       vec[1] = fsize * (ct->yof - yof);
+                       vec[2] = 0.0;
                        
                        mul_m4_v3(pmat, vec);
                        
@@ -1580,7 +1580,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i
 
 static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int level, int animated)
 {      
-       if ((ob->transflag & OB_DUPLI)==0)
+       if ((ob->transflag & OB_DUPLI) == 0)
                return;
        
        /* Should the dupli's be generated for this object? - Respect restrict flags */
@@ -1597,35 +1597,35 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas
 
        if (ob->transflag & OB_DUPLIPARTS) {
                ParticleSystem *psys = ob->particlesystem.first;
-               for (; psys; psys=psys->next)
-                       new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, psys, level+1, animated);
+               for (; psys; psys = psys->next)
+                       new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, psys, level + 1, animated);
        }
        else if (ob->transflag & OB_DUPLIVERTS) {
-               if (ob->type==OB_MESH) {
-                       vertex_duplilist(duplilist, id, scene, ob, par_space_mat, level+1, animated);
+               if (ob->type == OB_MESH) {
+                       vertex_duplilist(duplilist, id, scene, ob, par_space_mat, level + 1, animated);
                }
-               else if (ob->type==OB_FONT) {
-                       if (GS(id->name)==ID_SCE) { /* TODO - support dupligroups */
-                               font_duplilist(duplilist, scene, ob, level+1, animated);
+               else if (ob->type == OB_FONT) {
+                       if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */
+                               font_duplilist(duplilist, scene, ob, level + 1, animated);
                        }
                }
        }
        else if (ob->transflag & OB_DUPLIFACES) {
-               if (ob->type==OB_MESH)
-                       face_duplilist(duplilist, id, scene, ob, par_space_mat, level+1, animated);
+               if (ob->type == OB_MESH)
+                       face_duplilist(duplilist, id, scene, ob, par_space_mat, level + 1, animated);
        }
        else if (ob->transflag & OB_DUPLIFRAMES) {
-               if (GS(id->name)==ID_SCE) { /* TODO - support dupligroups */
-                       frames_duplilist(duplilist, scene, ob, level+1, animated);
+               if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */
+                       frames_duplilist(duplilist, scene, ob, level + 1, animated);
                }
        }
        else if (ob->transflag & OB_DUPLIGROUP) {
                DupliObject *dob;
                
-               group_duplilist(duplilist, scene, ob, level+1, animated); /* now recursive */
+               group_duplilist(duplilist, scene, ob, level + 1, animated); /* now recursive */
 
-               if (level==0) {
-                       for (dob= duplilist->first; dob; dob= dob->next)
+               if (level == 0) {
+                       for (dob = duplilist->first; dob; dob = dob->next)
                                if (dob->type == OB_DUPLIGROUP)
                                        copy_m4_m4(dob->ob->obmat, dob->mat);
                }
@@ -1636,8 +1636,8 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas
  * note; group dupli's already set transform matrix. see note in group_duplilist() */
 ListBase *object_duplilist(Scene *sce, Object *ob)
 {
-       ListBase *duplilist= MEM_mallocN(sizeof(ListBase), "duplilist");
-       duplilist->first= duplilist->last= NULL;
+       ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist");
+       duplilist->first = duplilist->last = NULL;
        object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0);
        return duplilist;
 }
@@ -1649,8 +1649,8 @@ void free_object_duplilist(ListBase *lb)
        /* loop in reverse order, if object is instanced multiple times
         * the original layer may not really be original otherwise, proper
         * solution is more complicated */
-       for (dob= lb->last; dob; dob= dob->prev) {
-               dob->ob->lay= dob->origlay;
+       for (dob = lb->last; dob; dob = dob->prev) {
+               dob->ob->lay = dob->origlay;
                copy_m4_m4(dob->ob->obmat, dob->omat);
        }
        
@@ -1662,16 +1662,16 @@ int count_duplilist(Object *ob)
 {
        if (ob->transflag & OB_DUPLI) {
                if (ob->transflag & OB_DUPLIVERTS) {
-                       if (ob->type==OB_MESH) {
+                       if (ob->type == OB_MESH) {
                                if (ob->transflag & OB_DUPLIVERTS) {
                                        ParticleSystem *psys = ob->particlesystem.first;
-                                       int pdup=0;
+                                       int pdup = 0;
 
-                                       for (; psys; psys=psys->next)
+                                       for (; psys; psys = psys->next)
                                                pdup += psys->totpart;
 
-                                       if (pdup==0) {
-                                               Mesh *me= ob->data;
+                                       if (pdup == 0) {
+                                               Mesh *me = ob->data;
                                                return me->totvert;
                                        }
                                        else
@@ -1680,9 +1680,9 @@ int count_duplilist(Object *ob)
                        }
                }
                else if (ob->transflag & OB_DUPLIFRAMES) {
-                       int tot= ob->dupend - ob->dupsta; 
-                       tot/= (ob->dupon+ob->dupoff);
-                       return tot*ob->dupon;
+                       int tot = ob->dupend - ob->dupsta;
+                       tot /= (ob->dupon + ob->dupoff);
+                       return tot * ob->dupon;
                }
        }
        return 1;
index 58ada7b..d8ae95e 100644 (file)
@@ -95,7 +95,7 @@ Global G;
 UserDef U;
 /* ListBase = {NULL, NULL}; */
 
-char versionstr[48]= "";
+char versionstr[48] = "";
 
 /* ********** free ********** */
 
@@ -104,9 +104,9 @@ void free_blender(void)
 {
        /* samples are in a global list..., also sets G.main->sound->sample NULL */
        free_main(G.main);
-       G.main= NULL;
+       G.main = NULL;
 
-       BKE_spacetypes_free();          /* after free main, it uses space callbacks */
+       BKE_spacetypes_free();      /* after free main, it uses space callbacks */
        
        IMB_exit();
 
@@ -122,18 +122,18 @@ void initglobals(void)
 {
        memset(&G, 0, sizeof(Global));
        
-       U.savetime= 1;
+       U.savetime = 1;
 
-       G.main= MEM_callocN(sizeof(Main), "initglobals");
+       G.main = MEM_callocN(sizeof(Main), "initglobals");
 
        strcpy(G.ima, "//");
 
        if (BLENDER_SUBVERSION)
-               BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d.%d", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
+               BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d.%d", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION);
        else
-               BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d", BLENDER_VERSION/100, BLENDER_VERSION%100);
+               BLI_snprintf(versionstr, sizeof(versionstr), "v%d.%02d", BLENDER_VERSION / 100, BLENDER_VERSION % 100);
 
-#ifdef _WIN32  // FULLSCREEN
+#ifdef _WIN32   // FULLSCREEN
        G.windowstate = G_WINDOWSTATE_USERDEF;
 #endif
 
@@ -154,11 +154,11 @@ static void clear_global(void)
 {
 //     extern short winqueue_break;    /* screen.c */
 
-       free_main(G.main);                      /* free all lib data */
+       free_main(G.main);          /* free all lib data */
        
 //     free_vertexpaint();
 
-       G.main= NULL;
+       G.main = NULL;
 }
 
 static int clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src)
@@ -175,7 +175,7 @@ static void clean_paths(Main *main)
 
        BLI_bpath_traverse_main(main, clean_paths_visit_cb, BLI_BPATH_TRAVERSE_SKIP_MULTIFILE, NULL);
 
-       for (scene= main->scene.first; scene; scene= scene->id.next) {
+       for (scene = main->scene.first; scene; scene = scene->id.next) {
                BLI_clean(scene->r.pic);
        }
 }
@@ -188,17 +188,17 @@ static void clean_paths(Main *main)
 
 static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath)
 {
-       bScreen *curscreen= NULL;
-       Scene *curscene= NULL;
+       bScreen *curscreen = NULL;
+       Scene *curscene = NULL;
        int recover;
        char mode;
 
        /* 'u' = undo save, 'n' = no UI load */
-       if (bfd->main->screen.first==NULL) mode= 'u';
-       else if (G.fileflags & G_FILE_NO_UI) mode= 'n';
-       else mode= 0;
+       if (bfd->main->screen.first == NULL) mode = 'u';
+       else if (G.fileflags & G_FILE_NO_UI) mode = 'n';
+       else mode = 0;
 
-       recover= (G.fileflags & G_FILE_RECOVER);
+       recover = (G.fileflags & G_FILE_RECOVER);
 
        /* Free all render results, without this stale data gets displayed after loading files */
        if (mode != 'u') {
@@ -222,12 +222,12 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
                SWAP(ListBase, G.main->script, bfd->main->script);
                
                /* we re-use current screen */
-               curscreen= CTX_wm_screen(C);
+               curscreen = CTX_wm_screen(C);
                /* but use new Scene pointer */
-               curscene= bfd->curscene;
-               if (curscene==NULL) curscene= bfd->main->scene.first;
+               curscene = bfd->curscene;
+               if (curscene == NULL) curscene = bfd->main->scene.first;
                /* and we enforce curscene to be in current screen */
-               if (curscreen) curscreen->scene= curscene; /* can run in bgmode */
+               if (curscreen) curscreen->scene = curscene;  /* can run in bgmode */
 
                /* clear_global will free G.main, here we can still restore pointers */
                lib_link_screen_restore(bfd->main, curscreen, curscene);
@@ -240,7 +240,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
        /* clear old property update cache, in case some old references are left dangling */
        RNA_property_update_cache_free();
        
-       G.main= bfd->main;
+       G.main = bfd->main;
 
        CTX_data_main_set(C, G.main);
 
@@ -251,7 +251,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
                /* only here free userdef themes... */
                BKE_userdef_free();
                
-               U= *bfd->user;
+               U = *bfd->user;
                MEM_freeN(bfd->user);
        }
        
@@ -261,9 +261,9 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
                CTX_data_scene_set(C, curscene);
        }
        else {
-               G.winpos= bfd->winpos;
-               G.displaymode= bfd->displaymode;
-               G.fileflags= bfd->fileflags;
+               G.winpos = bfd->winpos;
+               G.displaymode = bfd->displaymode;
+               G.fileflags = bfd->fileflags;
                CTX_wm_manager_set(C, bfd->main->wm.first);
                CTX_wm_screen_set(C, bfd->curscreen);
                CTX_data_scene_set(C, bfd->curscreen->scene);
@@ -273,20 +273,20 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
        }
        
        /* this can happen when active scene was lib-linked, and doesn't exist anymore */
-       if (CTX_data_scene(C)==NULL) {
+       if (CTX_data_scene(C) == NULL) {
                CTX_data_scene_set(C, bfd->main->scene.first);
-               CTX_wm_screen(C)->scene= CTX_data_scene(C);
-               curscene= CTX_data_scene(C);
+               CTX_wm_screen(C)->scene = CTX_data_scene(C);
+               curscene = CTX_data_scene(C);
        }
 
        /* special cases, override loaded flags: */
        if (G.f != bfd->globalf) {
                const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF);
-               bfd->globalf= (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
+               bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
        }
 
 
-       G.f= bfd->globalf;
+       G.f = bfd->globalf;
 
        if (!G.background) {
                //setscreen(G.curscreen);
@@ -300,12 +300,12 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
        if (recover && bfd->filename[0] && G.relbase_valid) {
                /* in case of autosave or quit.blend, use original filename instead
                 * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */
-               filepath= bfd->filename;
+               filepath = bfd->filename;
        }
 #if 0
        else if (!G.relbase_valid) {
                /* otherwise, use an empty string as filename, rather than <memory2> */
-               filepath="";
+               filepath = "";
        }
 #endif
        
@@ -324,8 +324,8 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
 static int handle_subversion_warning(Main *main, ReportList *reports)
 {
        if (main->minversionfile > BLENDER_VERSION ||
-          (main->minversionfile == BLENDER_VERSION && 
-                main->minsubversionfile > BLENDER_SUBVERSION)) {
+           (main->minversionfile == BLENDER_VERSION &&
+            main->minsubversionfile > BLENDER_SUBVERSION)) {
                BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
        }
 
@@ -348,8 +348,8 @@ void BKE_userdef_free(void)
        wmKeyMapItem *kmi;
        wmKeyMapDiffItem *kmdi;
 
-       for (km=U.user_keymaps.first; km; km=km->next) {
-               for (kmdi=km->diff_items.first; kmdi; kmdi=kmdi->next) {
+       for (km = U.user_keymaps.first; km; km = km->next) {
+               for (kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) {
                        if (kmdi->add_item) {
                                keymap_item_free(kmdi->add_item);
                                MEM_freeN(kmdi->add_item);
@@ -360,7 +360,7 @@ void BKE_userdef_free(void)
                        }
                }
 
-               for (kmi=km->items.first; kmi; kmi=kmi->next)
+               for (kmi = km->items.first; kmi; kmi = kmi->next)
                        keymap_item_free(kmi);
 
                BLI_freelistN(&km->diff_items);
@@ -377,41 +377,41 @@ void BKE_userdef_free(void)
 int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
 {
        BlendFileData *bfd;
-       int retval= BKE_READ_FILE_OK;
+       int retval = BKE_READ_FILE_OK;
 
-       if (strstr(filepath, BLENDER_STARTUP_FILE)==NULL) /* don't print user-pref loading */
+       if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) /* don't print user-pref loading */
                printf("read blend: %s\n", filepath);
 
-       bfd= BLO_read_from_file(filepath, reports);
+       bfd = BLO_read_from_file(filepath, reports);
        if (bfd) {
-               if (bfd->user) retval= BKE_READ_FILE_OK_USERPREFS;
+               if (bfd->user) retval = BKE_READ_FILE_OK_USERPREFS;
                
-               if (0==handle_subversion_warning(bfd->main, reports)) {
+               if (0 == handle_subversion_warning(bfd->main, reports)) {
                        free_main(bfd->main);
                        MEM_freeN(bfd);
-                       bfd= NULL;
-                       retval= BKE_READ_FILE_FAIL;
+                       bfd = NULL;
+                       retval = BKE_READ_FILE_FAIL;
                }
                else
-                       setup_app_data(C, bfd, filepath); // frees BFD
+                       setup_app_data(C, bfd, filepath);  // frees BFD
        } 
        else
                BKE_reports_prependf(reports, "Loading %s failed: ", filepath);
                
-       return (bfd?retval:BKE_READ_FILE_FAIL);
+       return (bfd ? retval : BKE_READ_FILE_FAIL);
 }
 
-int BKE_read_file_from_memory(bContext *C, charfilebuf, int filelength, ReportList *reports)
+int BKE_read_file_from_memory(bContext *C, char *filebuf, int filelength, ReportList *reports)
 {
        BlendFileData *bfd;
 
-       bfd= BLO_read_from_memory(filebuf, filelength, reports);
+       bfd = BLO_read_from_memory(filebuf, filelength, reports);
        if (bfd)
                setup_app_data(C, bfd, "<memory2>");
        else
                BKE_reports_prepend(reports, "Loading failed: ");
 
-       return (bfd?1:0);
+       return (bfd ? 1 : 0);
 }
 
 /* memfile is the undo buffer */
@@ -419,13 +419,13 @@ int BKE_read_file_from_memfile(bContext *C, MemFile *memfile, ReportList *report
 {
        BlendFileData *bfd;
 
-       bfd= BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports);
+       bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports);
        if (bfd)
                setup_app_data(C, bfd, "<memory1>");
        else
                BKE_reports_prepend(reports, "Loading failed: ");
 
-       return (bfd?1:0);
+       return (bfd ? 1 : 0);
 }
 
 
@@ -435,7 +435,7 @@ static void (*blender_test_break_cb)(void) = NULL;
 
 void set_blender_test_break_cb(void (*func)(void) )
 {
-       blender_test_break_cb= func;
+       blender_test_break_cb = func;
 }
 
 
@@ -446,15 +446,15 @@ int blender_test_break(void)
                        blender_test_break_cb();
        }
        
-       return (G.afbreek==1);
+       return (G.afbreek == 1);
 }
 
 
 /* ***************** GLOBAL UNDO *************** */
 
-#define UNDO_DISK      0
+#define UNDO_DISK   0
 
-#define MAXUNDONAME    64
+#define MAXUNDONAME 64
 typedef struct UndoElem {
        struct UndoElem *next, *prev;
        char str[FILE_MAX];
@@ -463,31 +463,31 @@ typedef struct UndoElem {
        uintptr_t undosize;
 } UndoElem;
 
-static ListBase undobase={NULL, NULL};
-static UndoElem *curundo= NULL;
+static ListBase undobase = {NULL, NULL};
+static UndoElem *curundo = NULL;
 
 
 static int read_undosave(bContext *C, UndoElem *uel)
 {
        char mainstr[sizeof(G.main->name)];
-       int success=0, fileflags;
+       int success = 0, fileflags;
        
        /* This is needed so undoing/redoing doesn't crash with threaded previews going */
        WM_jobs_stop_all(CTX_wm_manager(C));
 
-       BLI_strncpy(mainstr, G.main->name, sizeof(mainstr));    /* temporal store */
+       BLI_strncpy(mainstr, G.main->name, sizeof(mainstr));    /* temporal store */
 
-       fileflags= G.fileflags;
+       fileflags = G.fileflags;
        G.fileflags |= G_FILE_NO_UI;
 
        if (UNDO_DISK) 
-               success= (BKE_read_file(C, uel->str, NULL) != BKE_READ_FILE_FAIL);
+               success = (BKE_read_file(C, uel->str, NULL) != BKE_READ_FILE_FAIL);
        else
-               success= BKE_read_file_from_memfile(C, &uel->memfile, NULL);
+               success = BKE_read_file_from_memfile(C, &uel->memfile, NULL);
 
        /* restore */
        BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */
-       G.fileflags= fileflags;
+       G.fileflags = fileflags;
 
        if (success) {
                /* important not to update time here, else non keyed tranforms are lost */
@@ -504,33 +504,33 @@ void BKE_write_undo(bContext *C, const char *name)
        int nr /*, success */ /* UNUSED */;
        UndoElem *uel;
        
-       if ( (U.uiflag & USER_GLOBALUNDO)==0) return;
-       if ( U.undosteps==0) return;
+       if ( (U.uiflag & USER_GLOBALUNDO) == 0) return;
+       if (U.undosteps == 0) return;
        
        /* remove all undos after (also when curundo==NULL) */
        while (undobase.last != curundo) {
-               uel= undobase.last;
+               uel = undobase.last;
                BLI_remlink(&undobase, uel);
                BLO_free_memfile(&uel->memfile);
                MEM_freeN(uel);
        }
        
        /* make new */
-       curundo= uel= MEM_callocN(sizeof(UndoElem), "undo file");
+       curundo = uel = MEM_callocN(sizeof(UndoElem), "undo file");
        BLI_strncpy(uel->name, name, sizeof(uel->name));
        BLI_addtail(&undobase, uel);
        
        /* and limit amount to the maximum */
-       nr= 0;
-       uel= undobase.last;
+       nr = 0;
+       uel = undobase.last;
        while (uel) {
                nr++;
-               if (nr==U.undosteps) break;
-               uel= uel->prev;
+               if (nr == U.undosteps) break;
+               uel = uel->prev;
        }
        if (uel) {
-               while (undobase.first!=uel) {
-                       UndoElem *first= undobase.first;
+               while (undobase.first != uel) {
+                       UndoElem *first = undobase.first;
                        BLI_remlink(&undobase, first);
                        /* the merge is because of compression */
                        BLO_merge_memfile(&first->memfile, &first->next->memfile);
@@ -541,14 +541,14 @@ void BKE_write_undo(bContext *C, const char *name)
 
        /* disk save version */
        if (UNDO_DISK) {
-               static int counter= 0;
+               static int counter = 0;
                char filepath[FILE_MAX];
                char numstr[32];
                int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on undo */
 
                /* calculate current filepath */
                counter++;
-               counter= counter % U.undosteps; 
+               counter = counter % U.undosteps;
        
                BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
                BLI_make_file_string("/", filepath, BLI_temporary_dir(), numstr);
@@ -558,34 +558,34 @@ void BKE_write_undo(bContext *C, const char *name)
                BLI_strncpy(curundo->str, filepath, sizeof(curundo->str));
        }
        else {
-               MemFile *prevfile=NULL;
+               MemFile *prevfile = NULL;
                
-               if (curundo->prev) prevfile= &(curundo->prev->memfile);
+               if (curundo->prev) prevfile = &(curundo->prev->memfile);
                
-               memused= MEM_get_memory_in_use();
+               memused = MEM_get_memory_in_use();
                /* success= */ /* UNUSED */ BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags);
-               curundo->undosize= MEM_get_memory_in_use() - memused;
+               curundo->undosize = MEM_get_memory_in_use() - memused;
        }
 
        if (U.undomemory != 0) {
                /* limit to maximum memory (afterwards, we can't know in advance) */
-               totmem= 0;
-               maxmem= ((uintptr_t)U.undomemory)*1024*1024;
+               totmem = 0;
+               maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024;
 
                /* keep at least two (original + other) */
-               uel= undobase.last;
+               uel = undobase.last;
                while (uel && uel->prev) {
-                       totmem+= uel->undosize;
-                       if (totmem>maxmem) break;
-                       uel= uel->prev;
+                       totmem += uel->undosize;
+                       if (totmem > maxmem) break;
+                       uel = uel->prev;
                }
 
                if (uel) {
                        if (uel->prev && uel->prev->prev)
-                               uel= uel->prev;
+                               uel = uel->prev;
 
-                       while (undobase.first!=uel) {
-                               UndoElem *first= undobase.first;
+                       while (undobase.first != uel) {
+                               UndoElem *first = undobase.first;
                                BLI_remlink(&undobase, first);
                                /* the merge is because of compression */
                                BLO_merge_memfile(&first->memfile, &first->next->memfile);
@@ -599,25 +599,25 @@ void BKE_write_undo(bContext *C, const char *name)
 void BKE_undo_step(bContext *C, int step)
 {
        
-       if (step==0) {
+       if (step == 0) {
                read_undosave(C, curundo);
        }
-       else if (step==1) {
+       else if (step == 1) {
                /* curundo should never be NULL, after restart or load file it should call undo_save */
-               if (curundo==NULL || curundo->prev==NULL) ; // XXX error("No undo available");
+               if (curundo == NULL || curundo->prev == NULL) ;  // XXX error("No undo available");
                else {
                        if (G.debug & G_DEBUG) printf("undo %s\n", curundo->name);
-                       curundo= curundo->prev;
+                       curundo = curundo->prev;
                        read_undosave(C, curundo);
                }
        }
        else {
                /* curundo has to remain current situation! */
                
-               if (curundo==NULL || curundo->next==NULL) ; // XXX error("No redo available");
+               if (curundo == NULL || curundo->next == NULL) ;  // XXX error("No redo available");
                else {
                        read_undosave(C, curundo->next);
-                       curundo= curundo->next;
+                       curundo = curundo->next;
                        if (G.debug & G_DEBUG) printf("redo %s\n", curundo->name);
                }
        }
@@ -627,30 +627,30 @@ void BKE_reset_undo(void)
 {
        UndoElem *uel;
        
-       uel= undobase.first;
+       uel = undobase.first;
        while (uel) {
                BLO_free_memfile(&uel->memfile);
-               uel= uel->next;
+               uel = uel->next;
        }
        
        BLI_freelistN(&undobase);
-       curundo= NULL;
+       curundo = NULL;
 }
 
 /* based on index nr it does a restore */
 void BKE_undo_number(bContext *C, int nr)
 {
-       curundo= BLI_findlink(&undobase, nr);
+       curundo = BLI_findlink(&undobase, nr);
        BKE_undo_step(C, 0);
 }
 
 /* go back to the last occurance of name in stack */
 void BKE_undo_name(bContext *C, const char *name)
 {
-       UndoElem *uel= BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
+       UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
 
        if (uel && uel->prev) {
-               curundo= uel->prev;
+               curundo = uel->prev;
                BKE_undo_step(C, 0);
        }
 }
@@ -659,7 +659,7 @@ void BKE_undo_name(bContext *C, const char *name)
 int BKE_undo_valid(const char *name)
 {
        if (name) {
-               UndoElem *uel= BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
+               UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
                return uel && uel->prev;
        }
        
@@ -670,13 +670,13 @@ int BKE_undo_valid(const char *name)
 /* if active pointer, set it to 1 if true */
 const char *BKE_undo_get_name(int nr, int *active)
 {
-       UndoElem *uel= BLI_findlink(&undobase, nr);
+       UndoElem *uel = BLI_findlink(&undobase, nr);
        
-       if (active) *active= 0;
+       if (active) *active = 0;
        
        if (uel) {
-               if (active && uel==curundo)
-                       *active= 1;
+               if (active && uel == curundo)
+                       *active = 1;
                return uel->name;
        }
        return NULL;
@@ -685,23 +685,23 @@ const char *BKE_undo_get_name(int nr, int *active)
 char *BKE_undo_menu_string(void)
 {
        UndoElem *uel;
-       DynStr *ds= BLI_dynstr_new();
+       DynStr *ds = BLI_dynstr_new();
        char *menu;
 
        BLI_dynstr_append(ds, "Global Undo History %t");
        
-       for (uel= undobase.first; uel; uel= uel->next) {
+       for (uel = undobase.first; uel; uel = uel->next) {
                BLI_dynstr_append(ds, "|");
                BLI_dynstr_append(ds, uel->name);
        }
 
-       menu= BLI_dynstr_get_cstring(ds);
+       menu = BLI_dynstr_get_cstring(ds);
        BLI_dynstr_free(ds);
 
        return menu;
 }
 
-       /* saves quit.blend */
+/* saves quit.blend */
 void BKE_undo_save_quit(void)
 {
        UndoElem *uel;
@@ -709,16 +709,16 @@ void BKE_undo_save_quit(void)
        int file;
        char str[FILE_MAX];
        
-       if ( (U.uiflag & USER_GLOBALUNDO)==0) return;
+       if ( (U.uiflag & USER_GLOBALUNDO) == 0) return;
        
-       uel= curundo;
-       if (uel==NULL) {
+       uel = curundo;
+       if (uel == NULL) {
                printf("No undo buffer to save recovery file\n");
                return;
        }
        
        /* no undo state to save */
-       if (undobase.first==undobase.last) return;
+       if (undobase.first == undobase.last) return;
                
        BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
 
@@ -728,28 +728,28 @@ void BKE_undo_save_quit(void)
                return;
        }
 
-       chunk= uel->memfile.chunks.first;
+       chunk = uel->memfile.chunks.first;
        while (chunk) {
-               if ( write(file, chunk->buf, chunk->size) != chunk->size) break;
-               chunk= chunk->next;
+               if (write(file, chunk->buf, chunk->size) != chunk->size) break;
+               chunk = chunk->next;
        }
        
        close(file);
        
-       if (chunk) ; //XXX error("Unable to save %s, internal error", str);
+       if (chunk) ;  //XXX error("Unable to save %s, internal error", str);
        else printf("Saved session recovery to %s\n", str);
 }
 
 /* sets curscene */
 Main *BKE_undo_get_main(Scene **scene)
 {
-       Main *mainp= NULL;
-       BlendFileData *bfd= BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL);
+       Main *mainp = NULL;
+       BlendFileData *bfd = BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL);
        
        if (bfd) {
-               mainp= bfd->main;
+               mainp = bfd->main;
                if (scene)
-                       *scene= bfd->curscene;
+                       *scene = bfd->curscene;
                
                MEM_freeN(bfd);
        }
index f0bc2dd..24583c1 100644 (file)
@@ -101,11 +101,11 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
        sub_v3_v3v3(e1, v2, v0);
        
        A00 = dot_v3v3(e0, e0);
-       A01 = dot_v3v3(e0, e1 );
-       A11 = dot_v3v3(e1, e1 );
-       B0 = dot_v3v3(diff, e0 );
-       B1 = dot_v3v3(diff, e1 );
-       C = dot_v3v3(diff, diff );
+       A01 = dot_v3v3(e0, e1);
+       A11 = dot_v3v3(e1, e1);
+       B0 = dot_v3v3(diff, e0);
+       B1 = dot_v3v3(diff, e1);
+       C = dot_v3v3(diff, diff);
        Det = fabs(A00 * A11 - A01 * A01);
        S = A01 * B1 - A11 * B0;
        T = A01 * B0 - A00 * B1;
@@ -122,7 +122,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                                        }
                                        else {
                                                if (fabsf(A00) > FLT_EPSILON)
-                                                       S = -B0/A00;
+                                                       S = -B0 / A00;
                                                else
                                                        S = 0.0f;
                                                sqrDist = B0 * S + C;
@@ -195,7 +195,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                        }
                }
                else { /* Region 0 */
-                       // Minimum at interior lv
+                       /* Minimum at interior lv */
                        float invDet;
                        if (fabsf(Det) > FLT_EPSILON)
                                invDet = 1.0f / Det;
@@ -203,8 +203,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                                invDet = 0.0f;
                        S *= invDet;
                        T *= invDet;
-                       sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0) +
-                                 T * ( A01 * S + A11 * T + 2.0f * B1 ) + C;
+                       sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) +
+                                 T * (A01 * S + A11 * T + 2.0f * B1) + C;
                }
        }
        else {
@@ -213,10 +213,10 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                if (S < 0.0f) { /* Region 2 */
                        tmp0 = A01 + B0;
                        tmp1 = A11 + B1;
-                       if ( tmp1 > tmp0 ) {
+                       if (tmp1 > tmp0) {
                                numer = tmp1 - tmp0;
                                denom = A00 - 2.0f * A01 + A11;
-                               if ( numer >= denom ) {
+                               if (numer >= denom) {
                                        S = 1.0f;
                                        T = 0.0f;
                                        sqrDist = A00 + 2.0f * B0 + C;
@@ -228,14 +228,14 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                                        else
                                                S = 0.0f;
                                        T = 1.0f - S;
-                                       sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0 ) +
-                                                 T * ( A01 * S + A11 * T + 2.0f * B1 ) + C;
+                                       sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) +
+                                                 T * (A01 * S + A11 * T + 2.0f * B1) + C;
                                        le = 2;
                                }
                        }
                        else {
                                S = 0.0f;
-                               if ( tmp1 <= 0.0f ) {
+                               if (tmp1 <= 0.0f) {
                                        T = 1.0f;
                                        sqrDist = A11 + 2.0f * B1 + C;
                                        lv = 2;
@@ -258,10 +258,10 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                else if (T < 0.0f) { /* Region 6 */
                        tmp0 = A01 + B1;
                        tmp1 = A00 + B0;
-                       if ( tmp1 > tmp0 ) {
+                       if (tmp1 > tmp0) {
                                numer = tmp1 - tmp0;
                                denom = A00 - 2.0f * A01 + A11;
-                               if ( numer >= denom ) {
+                               if (numer >= denom) {
                                        T = 1.0f;
                                        S = 0.0f;
                                        sqrDist = A11 + 2.0f * B1 + C;
@@ -273,8 +273,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                                        else
                                                T = 0.0f;
                                        S = 1.0f - T;
-                                       sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0 ) +
-                                                 T * ( A01 * S + A11 * T + 2.0f * B1 ) + C;
+                                       sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) +
+                                                 T * (A01 * S + A11 * T + 2.0f * B1) + C;
                                        le = 2;
                                }
                        }
@@ -302,7 +302,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                }
                else { /* Region 1 */
                        numer = A11 + B1 - A01 - B0;
-                       if ( numer <= 0.0f ) {
+                       if (numer <= 0.0f) {
                                S = 0.0f;
                                T = 1.0f;
                                sqrDist = A11 + 2.0f * B1 + C;
@@ -310,7 +310,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                        }
                        else {
                                denom = A00 - 2.0f * A01 + A11;
-                               if ( numer >= denom ) {
+                               if (numer >= denom) {
                                        S = 1.0f;
                                        T = 0.0f;
                                        sqrDist = A00 + 2.0f * B0 + C;
@@ -322,8 +322,8 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
                                        else
                                                S = 0.0f;
                                        T = 1.0f - S;
-                                       sqrDist = S * ( A00 * S + A01 * T + 2.0f * B0 ) +
-                                                 T * ( A01 * S + A11 * T + 2.0f * B1 ) + C;
+                                       sqrDist = S * (A00 * S + A01 * T + 2.0f * B0) +
+                                                 T * (A01 * S + A11 * T + 2.0f * B1) + C;
                                        le = 2;
                                }
                        }
@@ -331,7 +331,7 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
        }
 
        // Account for numerical round-off error
-       if ( sqrDist < FLT_EPSILON )
+       if (sqrDist < FLT_EPSILON)
                sqrDist = 0.0f;
        
        {
@@ -362,19 +362,18 @@ float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const f
 // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
 static void mesh_faces_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
 {
-       const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata;
-       MVert *vert     = data->vert;
+       const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
+       MVert *vert = data->vert;
        MFace *face = data->face + index;
 
        float *t0, *t1, *t2, *t3;
-       t0 = vert[ face->v1 ].co;
-       t1 = vert[ face->v2 ].co;
-       t2 = vert[ face->v3 ].co;
-       t3 = face->v4 ? vert[ face->v4].co : NULL;
+       t0 = vert[face->v1].co;
+       t1 = vert[face->v2].co;
+       t2 = vert[face->v3].co;
+       t3 = face->v4 ? vert[face->v4].co : NULL;
 
        
-       do
-       {       
+       do {
                float nearest_tmp[3], dist;
                int vertex, edge;
                
@@ -397,8 +396,8 @@ static void mesh_faces_nearest_point(void *userdata, int index, const float co[3
 // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
 static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
-       const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata;
-       MVert *vert     = data->vert;
+       const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
+       MVert *vert = data->vert;
        MFace *face = data->face + index;
 
        float *t0, *t1, *t2, *t3;
@@ -408,8 +407,7 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r
        t3 = face->v4 ? vert[face->v4].co : NULL;
 
        
-       do
-       {       
+       do {
                float dist;
                if (data->sphere_radius == 0.0f)
                        dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2);
@@ -435,14 +433,14 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r
 // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
 static void mesh_edges_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
 {
-       const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata;
-       MVert *vert     = data->vert;
+       const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
+       MVert *vert = data->vert;
        MEdge *edge = data->edge + index;
        float nearest_tmp[3], dist;
 
        float *t0, *t1;
-       t0 = vert[ edge->v1 ].co;
-       t1 = vert[ edge->v2 ].co;
+       t0 = vert[edge->v1].co;
+       t1 = vert[edge->v2].co;
 
        closest_to_line_segment_v3(nearest_tmp, co, t0, t1);
        dist = len_squared_v3v3(nearest_tmp, co);
@@ -460,15 +458,15 @@ static void mesh_edges_nearest_point(void *userdata, int index, const float co[3
  * BVH builders
  */
 // Builds a bvh tree.. where nodes are the vertexs of the given mesh
-BVHTreebvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
+BVHTree *bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
 {
        BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_VERTICES);
 
        //Not in cache
        if (tree == NULL) {
                int i;
-               int numVerts= mesh->getNumVerts(mesh);
-               MVert *vert     = mesh->getVertDataArray(mesh, CD_MVERT);
+               int numVerts = mesh->getNumVerts(mesh);
+               MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT);
 
                if (vert != NULL) {
                        tree = BLI_bvhtree_new(numVerts, epsilon, tree_type, axis);
@@ -514,14 +512,14 @@ BVHTree* bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float
 }
 
 // Builds a bvh tree.. where nodes are the faces of the given mesh.
-BVHTreebvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
+BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
 {
        BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_FACES);
 
        //Not in cache
        if (tree == NULL) {
                int i;
-               int numFaces= mesh->getNumTessFaces(mesh);
+               int numFaces = mesh->getNumTessFaces(mesh);
 
                /* BMESH specific check that we have tessfaces,
                 * we _could_ tessellate here but rather not - campbell
@@ -534,7 +532,7 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
                        /* Create a bvh-tree of the given target */
                        tree = BLI_bvhtree_new(numFaces, epsilon, tree_type, axis);
                        if (tree != NULL) {
-                               BMEditMesh *em= data->em_evil;
+                               BMEditMesh *em = data->em_evil;
                                if (em) {
                                        /* data->em_evil is only set for snapping, and only for the mesh of the object
                                         * which is currently open in edit mode. When set, the bvhtree should not contain
@@ -594,17 +592,17 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
                                        }
                                }
                                else {
-                                       MVert *vert     = mesh->getVertDataArray(mesh, CD_MVERT);
+                                       MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT);
                                        MFace *face = mesh->getTessFaceDataArray(mesh, CD_MFACE);
 
                                        if (vert != NULL && face != NULL) {
                                                for (i = 0; i < numFaces; i++) {
                                                        float co[4][3];
-                                                       copy_v3_v3(co[0], vert[ face[i].v1 ].co);
-                                                       copy_v3_v3(co[1], vert[ face[i].v2 ].co);
-                                                       copy_v3_v3(co[2], vert[ face[i].v3 ].co);
+                                                       copy_v3_v3(co[0], vert[face[i].v1].co);
+                                                       copy_v3_v3(co[1], vert[face[i].v2].co);
+                                                       copy_v3_v3(co[2], vert[face[i].v3].co);
                                                        if (face[i].v4)
-                                                               copy_v3_v3(co[3], vert[ face[i].v4 ].co);
+                                                               copy_v3_v3(co[3], vert[face[i].v4].co);
                                        
                                                        BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
                                                }
@@ -644,15 +642,15 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float
 }
 
 // Builds a bvh tree.. where nodes are the faces of the given mesh.
-BVHTreebvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
+BVHTree *bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
 {
        BVHTree *tree = bvhcache_find(&mesh->bvhCache, BVHTREE_FROM_EDGES);
 
        //Not in cache
        if (tree == NULL) {
                int i;
-               int numEdges= mesh->getNumEdges(mesh);
-               MVert *vert     = mesh->getVertDataArray(mesh, CD_MVERT);
+               int numEdges = mesh->getNumEdges(mesh);
+               MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT);
                MEdge *edge = mesh->getEdgeDataArray(mesh, CD_MEDGE);
 
                if (vert != NULL && edge != NULL) {
@@ -661,8 +659,8 @@ BVHTree* bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float
                        if (tree != NULL) {
                                for (i = 0; i < numEdges; i++) {
                                        float co[4][3];
-                                       copy_v3_v3(co[0], vert[ edge[i].v1 ].co);
-                                       copy_v3_v3(co[1], vert[ edge[i].v2 ].co);
+                                       copy_v3_v3(co[0], vert[edge[i].v1].co);
+                                       copy_v3_v3(co[1], vert[edge[i].v2].co);
                        
                                        BLI_bvhtree_insert(tree, i, co[0], 2);
                                }
@@ -712,8 +710,7 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
 
 
 /* BVHCache */
-typedef struct BVHCacheItem
-{
+typedef struct BVHCacheItem {
        int type;
        BVHTree *tree;
 
@@ -721,8 +718,8 @@ typedef struct BVHCacheItem
 
 static void bvhcacheitem_set_if_match(void *_cached, void *_search)
 {
-       BVHCacheItem * cached = (BVHCacheItem *)_cached;
-       BVHCacheItem * search = (BVHCacheItem *)_search;
+       BVHCacheItem *cached = (BVHCacheItem *)_cached;
+       BVHCacheItem *search = (BVHCacheItem *)_search;
 
        if (search->type == cached->type) {
                search->tree = cached->tree;            
index 15db0df..db2362b 100644 (file)
@@ -1,4 +1,4 @@
- /*
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -172,7 +172,7 @@ static void cdDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r)
 
 static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        int i;
 
        if (dm->numVertData) {
@@ -188,7 +188,7 @@ static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
 
 static void cdDM_getVertCo(DerivedMesh *dm, int index, float co_r[3])
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
 
        copy_v3_v3(co_r, cddm->mvert[index].co);
 }
@@ -204,16 +204,16 @@ static void cdDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3])
 
 static void cdDM_getVertNo(DerivedMesh *dm, int index, float no_r[3])
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        normal_short_to_float_v3(no_r, cddm->mvert[index].no);
 }
 
 static const MeshElemMap *cdDM_getPolyMap(Object *ob, DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
 
        if (!cddm->pmap && ob->type == OB_MESH) {
-               Mesh *me= ob->data;
+               Mesh *me = ob->data;
 
                create_vert_poly_map(&cddm->pmap, &cddm->pmap_mem,
                                     me->mpoly, me->mloop,
@@ -225,7 +225,7 @@ static const MeshElemMap *cdDM_getPolyMap(Object *ob, DerivedMesh *dm)
 
 static int can_pbvh_draw(Object *ob, DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        Mesh *me = ob->data;
        int deformed = 0;
 
@@ -247,10 +247,10 @@ static int can_pbvh_draw(Object *ob, DerivedMesh *dm)
 
 static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
 
        if (!ob) {
-               cddm->pbvh= NULL;
+               cddm->pbvh = NULL;
                return NULL;
        }
 
@@ -258,7 +258,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
                return NULL;
 
        if (ob->sculpt->pbvh) {
-               cddm->pbvh= ob->sculpt->pbvh;
+               cddm->pbvh = ob->sculpt->pbvh;
                cddm->pbvh_draw = can_pbvh_draw(ob, dm);
        }
 
@@ -286,7 +286,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
                        int totvert;
 
                        totvert = deformdm->getNumVerts(deformdm);
-                       vertCos = MEM_callocN(3*totvert*sizeof(float), "cdDM_getPBVH vertCos");
+                       vertCos = MEM_callocN(3 * totvert * sizeof(float), "cdDM_getPBVH vertCos");
                        deformdm->getVertCos(deformdm, vertCos);
                        BLI_pbvh_apply_vertCos(cddm->pbvh, vertCos);
                        MEM_freeN(vertCos);
@@ -300,7 +300,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
  * TODO: proper fix is to support the pbvh in all drawing modes */
 static void cdDM_update_normals_from_pbvh(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        float (*face_nors)[3];
 
        if (!cddm->pbvh || !cddm->pbvh_draw || !dm->numTessFaceData)
@@ -313,7 +313,7 @@ static void cdDM_update_normals_from_pbvh(DerivedMesh *dm)
 
 static void cdDM_drawVerts(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mv = cddm->mvert;
        int i;
 
@@ -323,7 +323,7 @@ static void cdDM_drawVerts(DerivedMesh *dm)
                        glVertex3fv(mv->co);
                glEnd();
        }
-       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
+       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
                GPU_vertex_setup(dm);
                if (!GPU_buffer_legacy(dm)) {
                        if (dm->drawObject->tot_triangle_point)
@@ -337,7 +337,7 @@ static void cdDM_drawVerts(DerivedMesh *dm)
 
 static void cdDM_drawUVEdges(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MFace *mf = cddm->mface;
        MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE);
        int i;
@@ -346,7 +346,7 @@ static void cdDM_drawUVEdges(DerivedMesh *dm)
                if (GPU_buffer_legacy(dm)) {
                        glBegin(GL_LINES);
                        for (i = 0; i < dm->numTessFaceData; i++, mf++, tf++) {
-                               if (!(mf->flag&ME_HIDE)) {
+                               if (!(mf->flag & ME_HIDE)) {
                                        glVertex2fv(tf->uv[0]);
                                        glVertex2fv(tf->uv[1]);
 
@@ -377,19 +377,19 @@ static void cdDM_drawUVEdges(DerivedMesh *dm)
                        GPU_uvedge_setup(dm);
                        if (!GPU_buffer_legacy(dm)) {
                                for (i = 0; i < dm->numTessFaceData; i++, mf++) {
-                                       if (!(mf->flag&ME_HIDE)) {
+                                       if (!(mf->flag & ME_HIDE)) {
                                                draw = 1;
                                        } 
                                        else {
                                                draw = 0;
                                        }
-                                       if ( prevdraw != draw ) {
-                                               if ( prevdraw > 0 && (curpos-prevstart) > 0) {
-                                                       glDrawArrays(GL_LINES, prevstart, curpos-prevstart);
+                                       if (prevdraw != draw) {
+                                               if (prevdraw > 0 && (curpos - prevstart) > 0) {
+                                                       glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
                                                }
                                                prevstart = curpos;
                                        }
-                                       if ( mf->v4 ) {
+                                       if (mf->v4) {
                                                curpos += 8;
                                        }
                                        else {
@@ -397,8 +397,8 @@ static void cdDM_drawUVEdges(DerivedMesh *dm)
                                        }
                                        prevdraw = draw;
                                }
-                               if ( prevdraw > 0 && (curpos-prevstart) > 0 ) {
-                                       glDrawArrays(GL_LINES, prevstart, curpos-prevstart);
+                               if (prevdraw > 0 && (curpos - prevstart) > 0) {
+                                       glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
                                }
                        }
                        GPU_buffer_unbind();
@@ -408,7 +408,7 @@ static void cdDM_drawUVEdges(DerivedMesh *dm)
 
 static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mvert = cddm->mvert;
        MEdge *medge = cddm->medge;
        int i;
@@ -426,7 +426,7 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges
                }
                glEnd();
        }
-       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
+       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
                int prevstart = 0;
                int prevdraw = 1;
                int draw = TRUE;
@@ -442,16 +442,16 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges
                                else {
                                        draw = FALSE;
                                }
-                               if ( prevdraw != draw ) {
-                                       if ( prevdraw > 0 && (i-prevstart) > 0 ) {
+                               if (prevdraw != draw) {
+                                       if (prevdraw > 0 && (i - prevstart) > 0) {
                                                GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2);
                                        }
                                        prevstart = i;
                                }
                                prevdraw = draw;
                        }
-                       if ( prevdraw > 0 && (i-prevstart) > 0 ) {
-                               GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i-prevstart) * 2);
+                       if (prevdraw > 0 && (i - prevstart) > 0) {
+                               GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2);
                        }
                }
                GPU_buffer_unbind();
@@ -460,7 +460,7 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges
 
 static void cdDM_drawLooseEdges(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mvert = cddm->mvert;
        MEdge *medge = cddm->medge;
        int i;
@@ -469,14 +469,14 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm)
                DEBUG_VBO("Using legacy code. cdDM_drawLooseEdges\n");
                glBegin(GL_LINES);
                for (i = 0; i < dm->numEdgeData; i++, medge++) {
-                       if (medge->flag&ME_LOOSEEDGE) {
+                       if (medge->flag & ME_LOOSEEDGE) {
                                glVertex3fv(mvert[medge->v1].co);
                                glVertex3fv(mvert[medge->v2].co);
                        }
                }
                glEnd();
        }
-       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
+       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
                int prevstart = 0;
                int prevdraw = 1;
                int draw = 1;
@@ -484,21 +484,21 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm)
                GPU_edge_setup(dm);
                if (!GPU_buffer_legacy(dm)) {
                        for (i = 0; i < dm->numEdgeData; i++, medge++) {
-                               if (medge->flag&ME_LOOSEEDGE) {
+                               if (medge->flag & ME_LOOSEEDGE) {
                                        draw = 1;
                                } 
                                else {
                                        draw = 0;
                                }
-                               if ( prevdraw != draw ) {
-                                       if ( prevdraw > 0 && (i-prevstart) > 0) {
+                               if (prevdraw != draw) {
+                                       if (prevdraw > 0 && (i - prevstart) > 0) {
                                                GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2);
                                        }
                                        prevstart = i;
                                }
                                prevdraw = draw;
                        }
-                       if ( prevdraw > 0 && (i-prevstart) > 0 ) {
+                       if (prevdraw > 0 && (i - prevstart) > 0) {
                                GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, prevstart * 2, (i - prevstart) * 2);
                        }
                }
@@ -507,13 +507,13 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm)
 }
 
 static void cdDM_drawFacesSolid(DerivedMesh *dm,
-                               float (*partial_redraw_planes)[4],
-                               int UNUSED(fast), DMSetMaterial setMaterial)
+                                float (*partial_redraw_planes)[4],
+                                int UNUSED(fast), DMSetMaterial setMaterial)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mvert = cddm->mvert;
        MFace *mface = cddm->mface;
-       float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL);
+       float *nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
        int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1;
 
 #define PASSVERT(index) {                                              \
@@ -521,7 +521,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
                short *no = mvert[index].no;                    \
                glNormal3sv(no);                                                \
        }                                                                                       \
-       glVertex3fv(mvert[index].co);   \
+       glVertex3fv(mvert[index].co);                           \
 }
 
        if (cddm->pbvh && cddm->pbvh_draw) {
@@ -541,9 +541,9 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
                for (a = 0; a < dm->numTessFaceData; a++, mface++) {
                        int new_glmode, new_matnr, new_shademodel;
 
-                       new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES;
+                       new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES;
                        new_matnr = mface->mat_nr + 1;
-                       new_shademodel = (mface->flag & ME_SMOOTH)?GL_SMOOTH:GL_FLAT;
+                       new_shademodel = (mface->flag & ME_SMOOTH) ? GL_SMOOTH : GL_FLAT;
                        
                        if (new_glmode != glmode || new_matnr != matnr || new_shademodel != shademodel) {
                                glEnd();
@@ -584,7 +584,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
                }
                glEnd();
        }
-       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
+       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
                GPU_vertex_setup(dm);
                GPU_normal_setup(dm);
                if (!GPU_buffer_legacy(dm)) {
@@ -604,16 +604,16 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
 }
 
 static void cdDM_drawFacesTex_common(DerivedMesh *dm,
-                          DMSetDrawOptionsTex drawParams,
-                          DMSetDrawOptions drawParamsMapped,
-                          DMCompareDrawOptions compareDrawOptions,
-                          void *userData) 
+                                     DMSetDrawOptionsTex drawParams,
+                                     DMSetDrawOptions drawParamsMapped,
+                                     DMCompareDrawOptions compareDrawOptions,
+                                     void *userData)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mv = cddm->mvert;
        MFace *mf = DM_get_tessface_data_layer(dm, CD_MFACE);
        MCol *realcol = dm->getTessFaceDataArray(dm, CD_TEXTURE_MCOL);
-       float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL);
+       float *nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
        MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE);
        int i, j, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
        int startFace = 0 /*, lastFlag = 0xdeadbeef */ /* UNUSED */;
@@ -631,25 +631,25 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                        unsigned char *cp = NULL;
 
                        if (drawParams) {
-                               draw_option = drawParams(tf? &tf[i]: NULL, (mcol != NULL), mf->mat_nr);
+                               draw_option = drawParams(tf ? &tf[i] : NULL, (mcol != NULL), mf->mat_nr);
                        }
                        else {
                                if (index) {
                                        orig = *index++;
-                                       if (orig == ORIGINDEX_NONE)             { if (nors) nors += 3; continue; }
+                                       if (orig == ORIGINDEX_NONE)     { if (nors) nors += 3; continue; }
                                        if (drawParamsMapped) draw_option = drawParamsMapped(userData, orig);
-                                       else    { if (nors) nors += 3; continue; }
+                                       else {    if (nors) nors += 3; continue; }
                                }
                                else
-                                       if (drawParamsMapped) draw_option = drawParamsMapped(userData, i);
-                                       else    { if (nors) nors += 3; continue; }
+                               if (drawParamsMapped) draw_option = drawParamsMapped(userData, i);
+                               else {    if (nors) nors += 3; continue; }
                        }
                        
                        if (draw_option != DM_DRAW_OPTION_SKIP) {
                                if (draw_option != DM_DRAW_OPTION_NO_MCOL && mcol)
-                                       cp = (unsigned char*) &mcol[i*4];
+                                       cp = (unsigned char *) &mcol[i * 4];
 
-                               if (!(mf->flag&ME_SMOOTH)) {
+                               if (!(mf->flag & ME_SMOOTH)) {
                                        if (nors) {
                                                glNormal3fv(nors);
                                        }
@@ -665,30 +665,30 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                        }
                                }
 
-                               glBegin(mf->v4?GL_QUADS:GL_TRIANGLES);
+                               glBegin(mf->v4 ? GL_QUADS : GL_TRIANGLES);
                                if (tf) glTexCoord2fv(tf[i].uv[0]);
                                if (cp) glColor3ub(cp[3], cp[2], cp[1]);
                                mvert = &mv[mf->v1];
-                               if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no);
+                               if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no);
                                glVertex3fv(mvert->co);
                                        
                                if (tf) glTexCoord2fv(tf[i].uv[1]);
                                if (cp) glColor3ub(cp[7], cp[6], cp[5]);
                                mvert = &mv[mf->v2];
-                               if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no);
+                               if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no);
                                glVertex3fv(mvert->co);
 
                                if (tf) glTexCoord2fv(tf[i].uv[2]);
                                if (cp) glColor3ub(cp[11], cp[10], cp[9]);
                                mvert = &mv[mf->v3];
-                               if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no);
+                               if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no);
                                glVertex3fv(mvert->co);
 
                                if (mf->v4) {
                                        if (tf) glTexCoord2fv(tf[i].uv[3]);
                                        if (cp) glColor3ub(cp[15], cp[14], cp[13]);
                                        mvert = &mv[mf->v4];
-                                       if (mf->flag&ME_SMOOTH) glNormal3sv(mvert->no);
+                                       if (mf->flag & ME_SMOOTH) glNormal3sv(mvert->no);
                                        glVertex3fv(mvert->co);
                                }
                                glEnd();
@@ -705,7 +705,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                GPU_vertex_setup(dm);
                GPU_normal_setup(dm);
                GPU_uv_setup(dm);
-               if ( col != NULL ) {
+               if (col != NULL) {
 #if 0
                        if (realcol && dm->drawObject->colType == CD_TEXTURE_MCOL) {
                                col = 0;
@@ -717,13 +717,13 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                        if (col != 0)
 #endif
                        {
-                               unsigned char *colors = MEM_mallocN(dm->getNumTessFaces(dm)*4*3*sizeof(unsigned char), "cdDM_drawFacesTex_common");
+                               unsigned char *colors = MEM_mallocN(dm->getNumTessFaces(dm) * 4 * 3 * sizeof(unsigned char), "cdDM_drawFacesTex_common");
                                for (i = 0; i < dm->getNumTessFaces(dm); i++) {
                                        for (j = 0; j < 4; j++) {
                                                /* bgr -> rgb is intentional (and stupid), but how its stored internally */
-                                               colors[i*12+j*3] = col[i*4+j].b;
-                                               colors[i*12+j*3+1] = col[i*4+j].g;
-                                               colors[i*12+j*3+2] = col[i*4+j].r;
+                                               colors[i * 12 + j * 3] = col[i * 4 + j].b;
+                                               colors[i * 12 + j * 3 + 1] = col[i * 4 + j].g;
+                                               colors[i * 12 + j * 3 + 2] = col[i * 4 + j].r;
                                        }
                                }
                                GPU_color3_upload(dm, colors);
@@ -737,7 +737,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                }
 
                if (!GPU_buffer_legacy(dm)) {
-                       int tottri = dm->drawObject->tot_triangle_point/3;
+                       int tottri = dm->drawObject->tot_triangle_point / 3;
                        int next_actualFace = dm->drawObject->triangle_to_mface[0];
 
                        glShadeModel(GL_SMOOTH);
@@ -747,11 +747,11 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
                                int flush = 0;
 
-                               if (i != tottri-1)
-                                       next_actualFace= dm->drawObject->triangle_to_mface[i+1];
+                               if (i != tottri - 1)
+                                       next_actualFace = dm->drawObject->triangle_to_mface[i + 1];
 
                                if (drawParams) {
-                                       draw_option = drawParams(tf? &tf[actualFace]: NULL, (mcol != NULL), mf[actualFace].mat_nr);
+                                       draw_option = drawParams(tf ? &tf[actualFace] : NULL, (mcol != NULL), mf[actualFace].mat_nr);
                                }
                                else {
                                        if (index) {
@@ -761,8 +761,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                                        draw_option = drawParamsMapped(userData, orig);
                                        }
                                        else
-                                               if (drawParamsMapped)
-                                                       draw_option = drawParamsMapped(userData, actualFace);
+                                       if (drawParamsMapped)
+                                               draw_option = drawParamsMapped(userData, actualFace);
                                }
 
                                /* flush buffer if current triangle isn't drawable or it's last triangle */
@@ -771,13 +771,13 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                if (!flush && compareDrawOptions) {
                                        /* also compare draw options and flush buffer if they're different
                                         * need for face selection highlight in edit mode */
-                                       flush|= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
+                                       flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
                                }
 
                                if (flush) {
-                                       int first = startFace*3;
+                                       int first = startFace * 3;
                                        /* Add one to the length if we're drawing at the end of the array */
-                                       int count = (i-startFace+(draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0))*3;
+                                       int count = (i - startFace + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3;
 
                                        if (count) {
                                                if (col)
@@ -799,24 +799,24 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
 }
 
 static void cdDM_drawFacesTex(DerivedMesh *dm,
-                          DMSetDrawOptionsTex setDrawOptions,
-                          DMCompareDrawOptions compareDrawOptions,
-                          void *userData)
+                              DMSetDrawOptionsTex setDrawOptions,
+                              DMCompareDrawOptions compareDrawOptions,
+                              void *userData)
 {
        cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
 }
 
 static void cdDM_drawMappedFaces(DerivedMesh *dm,
-                       DMSetDrawOptions setDrawOptions,
-                       DMSetMaterial setMaterial,
-                       DMCompareDrawOptions compareDrawOptions,
-                       void *userData, DMDrawFlag flag)
+                                 DMSetDrawOptions setDrawOptions,
+                                 DMSetMaterial setMaterial,
+                                 DMCompareDrawOptions compareDrawOptions,
+                                 void *userData, DMDrawFlag flag)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mv = cddm->mvert;
        MFace *mf = cddm->mface;
        MCol *mc;
-       float *nors= DM_get_tessface_data_layer(dm, CD_NORMAL);
+       float *nors = DM_get_tessface_data_layer(dm, CD_NORMAL);
        int useColors = flag & DM_DRAW_USE_COLORS;
        int i, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
 
@@ -836,12 +836,12 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                        int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mf->flag & ME_SMOOTH);
                        DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
 
-                       orig = (index==NULL) ? i : *index++;
+                       orig = (index == NULL) ? i : *index++;
                        
                        if (orig == ORIGINDEX_NONE)
-                               draw_option= setMaterial(mf->mat_nr + 1, NULL);
+                               draw_option = setMaterial(mf->mat_nr + 1, NULL);
                        else if (setDrawOptions != NULL)
-                               draw_option= setDrawOptions(userData, orig);
+                               draw_option = setDrawOptions(userData, orig);
 
                        if (draw_option != DM_DRAW_OPTION_SKIP) {
                                unsigned char *cp = NULL;
@@ -852,7 +852,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                /* no need to set shading mode to flat because
                                 *  normals are already used to change shading */
                                glShadeModel(GL_SMOOTH);
-                               glBegin(mf->v4?GL_QUADS:GL_TRIANGLES);
+                               glBegin(mf->v4 ? GL_QUADS : GL_TRIANGLES);
 
                                if (!drawSmooth) {
                                        if (nors) {
@@ -907,10 +907,10 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                int prevstart = 0;
                GPU_vertex_setup(dm);
                GPU_normal_setup(dm);
-               if ( useColors && mc )
+               if (useColors && mc)
                        GPU_color_setup(dm);
                if (!GPU_buffer_legacy(dm)) {
-                       int tottri = dm->drawObject->tot_triangle_point/3;
+                       int tottri = dm->drawObject->tot_triangle_point / 3;
                        glShadeModel(GL_SMOOTH);
                        
                        if (tottri == 0) {
@@ -932,15 +932,15 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                        DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
                                        int flush = 0;
 
-                                       if (i != tottri-1)
-                                               next_actualFace= dm->drawObject->triangle_to_mface[i+1];
+                                       if (i != tottri - 1)
+                                               next_actualFace = dm->drawObject->triangle_to_mface[i + 1];
 
-                                       orig = (index==NULL) ? actualFace : index[actualFace];
+                                       orig = (index == NULL) ? actualFace : index[actualFace];
 
                                        if (orig == ORIGINDEX_NONE)
-                                               draw_option= setMaterial(mface->mat_nr + 1, NULL);
+                                               draw_option = setMaterial(mface->mat_nr + 1, NULL);
                                        else if (setDrawOptions != NULL)
-                                               draw_option= setDrawOptions(userData, orig);
+                                               draw_option = setDrawOptions(userData, orig);
        
                                        /* Goal is to draw as long of a contiguous triangle
                                         * array as possible, so draw when we hit either an
@@ -957,9 +957,9 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                        }
 
                                        if (flush) {
-                                               int first = prevstart*3;
+                                               int first = prevstart * 3;
                                                /* Add one to the length if we're drawing at the end of the array */
-                                               int count = (i-prevstart+(draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0))*3;
+                                               int count = (i - prevstart + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3;
 
                                                if (count)
                                                        glDrawArrays(GL_TRIANGLES, first, count);
@@ -976,9 +976,9 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 }
 
 static void cdDM_drawMappedFacesTex(DerivedMesh *dm,
-                          DMSetDrawOptions setDrawOptions,
-                          DMCompareDrawOptions compareDrawOptions,
-                          void *userData)
+                                    DMSetDrawOptions setDrawOptions,
+                                    DMCompareDrawOptions compareDrawOptions,
+                                    void *userData)
 {
        cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
 }
@@ -1007,15 +1007,15 @@ static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int
 
        /* vertex colors */
        for (b = 0; b < attribs->totmcol; b++) {
-               MCol *cp = &attribs->mcol[b].array[a*4 + vert];
+               MCol *cp = &attribs->mcol[b].array[a * 4 + vert];
                GLubyte col[4];
-               col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
+               col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
                glVertexAttrib4ubvARB(attribs->mcol[b].gl_index, col);
        }
 
        /* tangent for normal mapping */
        if (attribs->tottang) {
-               float *tang = attribs->tang.array[a*4 + vert];
+               float *tang = attribs->tang.array[a * 4 + vert];
                glVertexAttrib4fvARB(attribs->tang.gl_index, tang);
        }
 
@@ -1028,11 +1028,11 @@ static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int
 }
 
 static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
-                          DMSetMaterial setMaterial,
-                          DMSetDrawOptions setDrawOptions,
-                          void *userData)
+                                     DMSetMaterial setMaterial,
+                                     DMSetDrawOptions setDrawOptions,
+                                     void *userData)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        GPUVertexAttribs gattribs;
        DMVertexAttribs attribs;
        MVert *mvert = cddm->mvert;
@@ -1049,7 +1049,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
 
        glShadeModel(GL_SMOOTH);
 
-       if ( GPU_buffer_legacy(dm) || setDrawOptions != NULL ) {
+       if (GPU_buffer_legacy(dm) || setDrawOptions != NULL) {
                DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n");
                memset(&attribs, 0, sizeof(attribs));
 
@@ -1073,7 +1073,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
                                continue;
                        }
                        else if (setDrawOptions) {
-                               orig = (index)? index[a]: a;
+                               orig = (index) ? index[a] : a;
 
                                if (orig == ORIGINDEX_NONE) {
                                        /* since the material is set by setMaterial(), faces with no
@@ -1128,7 +1128,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
                GPU_normal_setup(dm);
 
                if (!GPU_buffer_legacy(dm)) {
-                       for (i = 0; i < dm->drawObject->tot_triangle_point/3; i++) {
+                       for (i = 0; i < dm->drawObject->tot_triangle_point / 3; i++) {
 
                                a = dm->drawObject->triangle_to_mface[i];
 
@@ -1148,7 +1148,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
                                                                GPU_interleaved_attrib_setup(buffer, datatypes, numdata);
                                                        }
 
-                                                       glDrawArrays(GL_TRIANGLES, start*3, numfaces*3);
+                                                       glDrawArrays(GL_TRIANGLES, start * 3, numfaces * 3);
 
                                                        if (numdata != 0) {
 
@@ -1215,84 +1215,84 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
                                        }
                                }
 
-                               if (dodraw && numdata != 0 ) {
+                               if (dodraw && numdata != 0) {
                                        offset = 0;
                                        if (attribs.totorco) {
-                                               copy_v3_v3((float *)&varray[elementsize*curface*3], (float *)attribs.orco.array[mface->v1]);
-                                               copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize], (float *)attribs.orco.array[mface->v2]);
-                                               copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize*2], (float *)attribs.orco.array[mface->v3]);
-                                               offset += sizeof(float)*3;
+                                               copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v1]);
+                                               copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v2]);
+                                               copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v3]);
+                                               offset += sizeof(float) * 3;
                                        }
                                        for (b = 0; b < attribs.tottface; b++) {
                                                MTFace *tf = &attribs.tface[b].array[a];
-                                               copy_v2_v2((float *)&varray[elementsize*curface*3+offset], tf->uv[0]);
-                                               copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize], tf->uv[1]);
+                                               copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[0]);
+                                               copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[1]);
 
-                                               copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize*2], tf->uv[2]);
-                                               offset += sizeof(float)*2;
+                                               copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[2]);
+                                               offset += sizeof(float) * 2;
                                        }
                                        for (b = 0; b < attribs.totmcol; b++) {
-                                               MCol *cp = &attribs.mcol[b].array[a*4 + 0];
+                                               MCol *cp = &attribs.mcol[b].array[a * 4 + 0];
                                                GLubyte col[4];
-                                               col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
-                                               copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset], (char *)col);
-                                               cp = &attribs.mcol[b].array[a*4 + 1];
-                                               col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
-                                               copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize], (char *)col);
-                                               cp = &attribs.mcol[b].array[a*4 + 2];
-                                               col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
-                                               copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize*2], (char *)col);
-                                               offset += sizeof(unsigned char)*4;
+                                               col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+                                               copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col);
+                                               cp = &attribs.mcol[b].array[a * 4 + 1];
+                                               col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+                                               copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col);
+                                               cp = &attribs.mcol[b].array[a * 4 + 2];
+                                               col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+                                               copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col);
+                                               offset += sizeof(unsigned char) * 4;
                                        }       
                                        if (attribs.tottang) {
-                                               float *tang = attribs.tang.array[a*4 + 0];
-                                               copy_v4_v4((float *)&varray[elementsize*curface*3+offset], tang);
-                                               tang = attribs.tang.array[a*4 + 1];
-                                               copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize], tang);
-                                               tang = attribs.tang.array[a*4 + 2];
-                                               copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang);
-                                               offset += sizeof(float)*4;
+                                               float *tang = attribs.tang.array[a * 4 + 0];
+                                               copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang);
+                                               tang = attribs.tang.array[a * 4 + 1];
+                                               copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize], tang);
+                                               tang = attribs.tang.array[a * 4 + 2];
+                                               copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tang);
+                                               offset += sizeof(float) * 4;
                                        }
                                        (void)offset;
                                }
                                curface++;
                                if (mface->v4) {
-                                       if (dodraw && numdata != 0 ) {
+                                       if (dodraw && numdata != 0) {
                                                offset = 0;
                                                if (attribs.totorco) {
-                                                       copy_v3_v3((float *)&varray[elementsize*curface*3], (float *)attribs.orco.array[mface->v3]);
-                                                       copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize], (float *)attribs.orco.array[mface->v4]);
-                                                       copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize*2], (float *)attribs.orco.array[mface->v1]);
-                                                       offset += sizeof(float)*3;
+                                                       copy_v3_v3((float *)&varray[elementsize * curface * 3], (float *)attribs.orco.array[mface->v3]);
+                                                       copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize], (float *)attribs.orco.array[mface->v4]);
+                                                       copy_v3_v3((float *)&varray[elementsize * curface * 3 + elementsize * 2], (float *)attribs.orco.array[mface->v1]);
+                                                       offset += sizeof(float) * 3;
                                                }
                                                for (b = 0; b < attribs.tottface; b++) {
                                                        MTFace *tf = &attribs.tface[b].array[a];
-                                                       copy_v2_v2((float *)&varray[elementsize*curface*3+offset], tf->uv[2]);
-                                                       copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize], tf->uv[3]);
-                                                       copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize*2], tf->uv[0]);
-                                                       offset += sizeof(float)*2;
+                                                       copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset], tf->uv[2]);
+                                                       copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize], tf->uv[3]);
+                                                       copy_v2_v2((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tf->uv[0]);
+                                                       offset += sizeof(float) * 2;
                                                }
                                                for (b = 0; b < attribs.totmcol; b++) {
-                                                       MCol *cp = &attribs.mcol[b].array[a*4 + 2];
+                                                       MCol *cp = &attribs.mcol[b].array[a * 4 + 2];
                                                        GLubyte col[4];
-                                                       col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
-                                                       copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset], (char *)col);
-                                                       cp = &attribs.mcol[b].array[a*4 + 3];
-                                                       col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
-                                                       copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize], (char *)col);
-                                                       cp = &attribs.mcol[b].array[a*4 + 0];
-                                                       col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
-                                                       copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize*2], (char *)col);
-                                                       offset += sizeof(unsigned char)*4;
+                                                       col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+                                                       copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset], (char *)col);
+                                                       cp = &attribs.mcol[b].array[a * 4 + 3];
+                                                       col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+                                                       copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize], (char *)col);
+                                                       cp = &attribs.mcol[b].array[a * 4 + 0];
+                                                       col[0] = cp->b; col[1] = cp->g; col[2] = cp->r; col[3] = cp->a;
+                                                       copy_v4_v4_char((char *)&varray[elementsize * curface * 3 + offset + elementsize * 2], (char *)col);
+                                                       offset += sizeof(unsigned char) * 4;
                                                }       
                                                if (attribs.tottang) {
-                                                       float *tang = attribs.tang.array[a*4 + 2];
-                                                       copy_v4_v4((float *)&varray[elementsize*curface*3+offset], tang);
-                                                       tang = attribs.tang.array[a*4 + 3];
-                                                       copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize], tang);
-                                                       tang = attribs.tang.array[a*4 + 0];
-                                                       copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang);
-                                                       offset += sizeof(float)*4;
+                                                       float *tang = attribs.tang.array[a * 4 + 2];
+                                                       copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset], tang);
+                                                       tang = attribs.tang.array[a * 4 + 3];
+                                                       copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize], tang);
+                                                       tang = attribs.tang.array[a * 4 + 0];
+                                                       copy_v4_v4((float *)&varray[elementsize * curface * 3 + offset + elementsize * 2], tang);
+                                                       offset += sizeof(float) * 4;
                                                }
                                                (void)offset;
                                        }
@@ -1307,7 +1307,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
                                                GPU_buffer_unlock(buffer);
                                                GPU_interleaved_attrib_setup(buffer, datatypes, numdata);
                                        }
-                                       glDrawArrays(GL_TRIANGLES, start*3, (curface-start)*3);
+                                       glDrawArrays(GL_TRIANGLES, start * 3, (curface - start) * 3);
                                }
                        }
                        GPU_buffer_unbind();
@@ -1324,10 +1324,10 @@ static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
 }
 
 static void cdDM_drawMappedFacesMat(DerivedMesh *dm,
-       void (*setMaterial)(void *userData, int, void *attribs),
-       int (*setFace)(void *userData, int index), void *userData)
+                                    void (*setMaterial)(void *userData, int, void *attribs),
+                                    int (*setFace)(void *userData, int index), void *userData)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        GPUVertexAttribs gattribs;
        DMVertexAttribs attribs;
        MVert *mvert = cddm->mvert;
@@ -1363,7 +1363,7 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm,
 
                /* skipping faces */
                if (setFace) {
-                       orig = (index)? index[a]: a;
+                       orig = (index) ? index[a] : a;
 
                        if (orig != ORIGINDEX_NONE && !setFace(userData, orig))
                                continue;
@@ -1404,7 +1404,7 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm,
 
 static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *vert = cddm->mvert;
        MEdge *edge = cddm->medge;
        int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX);
@@ -1450,7 +1450,7 @@ static void cdDM_foreachMappedEdge(
         void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]),
         void *userData)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
        MVert *mv = cddm->mvert;
        MEdge *med = cddm->medge;
        int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX);
@@ -1471,7 +1471,7 @@ static void cdDM_foreachMappedFaceCenter(
         void (*func)(void *userData, int index, const float cent[3], const float no[3]),
         void *userData)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        MVert *mv = cddm->mvert;
        MPoly *mp = cddm->mpoly;
        MLoop *ml = cddm->mloop;
@@ -1492,7 +1492,7 @@ static void cdDM_foreachMappedFaceCenter(
                
                ml = &cddm->mloop[mp->loopstart];
                cent[0] = cent[1] = cent[2] = 0.0f;
-               for (j=0; j<mp->totloop; j++, ml++) {
+               for (j = 0; j < mp->totloop; j++, ml++) {
                        add_v3_v3v3(cent, cent, mv[ml->v].co);
                }
                mul_v3_fl(cent, 1.0f / (float)j);
@@ -1519,7 +1519,7 @@ static void cdDM_foreachMappedFaceCenter(
 
 void CDDM_recalc_tessellation_ex(DerivedMesh *dm, const int do_face_nor_cpy)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
        dm->numTessFaceData = BKE_mesh_recalc_tessellation(&dm->faceData, &dm->loopData, &dm->polyData,
                                                           cddm->mvert,
@@ -1551,7 +1551,7 @@ static void cdDM_free_internal(CDDerivedMesh *cddm)
 
 static void cdDM_release(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
        if (DM_release(dm)) {
                cdDM_free_internal(cddm);
@@ -1671,18 +1671,18 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *UNUSED(ob))
        /* this does a referenced copy, with an exception for fluidsim */
 
        DM_init(dm, DM_TYPE_CDDM, mesh->totvert, mesh->totedge, mesh->totface,
-                   mesh->totloop, mesh->totpoly);
+               mesh->totloop, mesh->totpoly);
 
        dm->deformedOnly = 1;
 
-       alloctype= CD_REFERENCE;
+       alloctype = CD_REFERENCE;
 
        CustomData_merge(&mesh->vdata, &dm->vertData, mask, alloctype,
-                                        mesh->totvert);
+                        mesh->totvert);
        CustomData_merge(&mesh->edata, &dm->edgeData, mask, alloctype,
-                                        mesh->totedge);
-       CustomData_merge(&mesh->fdata, &dm->faceData, mask|CD_MASK_POLYINDEX, alloctype,
-                                        mesh->totface);
+                        mesh->totedge);
+       CustomData_merge(&mesh->fdata, &dm->faceData, mask | CD_MASK_POLYINDEX, alloctype,
+                        mesh->totface);
        CustomData_merge(&mesh->ldata, &dm->loopData, mask, alloctype,
                         mesh->totloop);
        CustomData_merge(&mesh->pdata, &dm->polyData, mask, alloctype,
@@ -1733,12 +1733,12 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase)
        dm = CDDM_new(totvert, totedge, 0, totloop, totpoly);
        dm->deformedOnly = 1;
 
-       cddm = (CDDerivedMesh*)dm;
+       cddm = (CDDerivedMesh *)dm;
 
-       memcpy(cddm->mvert, allvert, totvert*sizeof(MVert));
-       memcpy(cddm->medge, alledge, totedge*sizeof(MEdge));
-       memcpy(cddm->mloop, allloop, totloop*sizeof(MLoop));
-       memcpy(cddm->mpoly, allpoly, totpoly*sizeof(MPoly));
+       memcpy(cddm->mvert, allvert, totvert * sizeof(MVert));
+       memcpy(cddm->medge, alledge, totedge * sizeof(MEdge));
+       memcpy(cddm->mloop, allloop, totloop * sizeof(MLoop));
+       memcpy(cddm->mpoly, allpoly, totpoly * sizeof(MPoly));
 
        MEM_freeN(allvert);
        MEM_freeN(alledge);
@@ -1751,8 +1751,8 @@ DerivedMesh *CDDM_from_curve_customDB(Object *ob, ListBase *dispbase)
 }
 
 static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
-                                         int cdindex, BMLoop *l3[3],
-                                         int numCol, int numTex)
+                                        int cdindex, BMLoop *l3[3],
+                                        int numCol, int numTex)
 {
        BMLoop *l;
        BMFace *f = l3[0]->f;
@@ -1769,7 +1769,7 @@ static void loops_to_customdata_corners(BMesh *bm, CustomData *facedata,
                
                ME_MTEXFACE_CPY(texface, texpoly);
        
-               for (j = 0 ; j < 3; j++) {
+               for (j = 0; j < 3; j++) {
                        l = l3[j];
                        mloopuv = CustomData_bmesh_get_n(&bm->ldata, l->head.data, CD_MLOOPUV, i);
                        copy_v2_v2(texface->uv[j], mloopuv->uv);
@@ -1807,7 +1807,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
                                   bm->totloop,
                                   bm->totface);
 
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        BMIter iter, liter;
        BMVert *eve;
        BMEdge *eed;
@@ -1833,7 +1833,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
        /*don't add origindex layer if one already exists*/
        add_orig = !CustomData_has_layer(&bm->pdata, CD_ORIGINDEX);
 
-       mask = use_mdisps ? CD_MASK_DERIVEDMESH|CD_MASK_MDISPS : CD_MASK_DERIVEDMESH;
+       mask = use_mdisps ? CD_MASK_DERIVEDMESH | CD_MASK_MDISPS : CD_MASK_DERIVEDMESH;
        
        /* don't process shapekeys, we only feed them through the modifier stack as needed,
         * e.g. for applying modifiers or the like*/
@@ -1867,7 +1867,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
                mv->flag = BM_vert_flag_to_mflag(eve);
 
                if (has_vert_bweight)
-                       mv->bweight = (unsigned char)(BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT)*255.0f);
+                       mv->bweight = (unsigned char)(BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f);
 
                if (add_orig) *index = i;
 
@@ -1886,9 +1886,9 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
                med->v2 = BM_elem_index_get(eed->v2);
 
                if (has_crease)
-                       med->crease = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_CREASE)*255.0f);
+                       med->crease = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_CREASE) * 255.0f);
                if (has_edge_bweight)
-                       med->bweight = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT)*255.0f);
+                       med->bweight = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT) * 255.0f);
                
                med->flag = BM_edge_flag_to_mflag(eed);
 
@@ -1917,7 +1917,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
                        mf->mat_nr = efa->mat_nr;
                        mf->flag = BM_face_flag_to_mflag(efa);
 
-                       *index = add_orig ? BM_elem_index_get(efa) : *(int*)CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_ORIGINDEX);
+                       *index = add_orig ? BM_elem_index_get(efa) : *(int *)CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_ORIGINDEX);
                        *polyindex = BM_elem_index_get(efa);
 
                        loops_to_customdata_corners(bm, &dm->faceData, i, l, numCol, numTex);
@@ -1974,7 +1974,7 @@ static DerivedMesh *cddm_copy_ex(DerivedMesh *source, int faces_from_tessfaces)
 
        /* this initializes dm, and copies all non mvert/medge/mface layers */
        DM_from_template(dm, source, DM_TYPE_CDDM, numVerts, numEdges, numTessFaces,
-               numLoops, numPolys);
+                        numLoops, numPolys);
        dm->deformedOnly = source->deformedOnly;
        dm->dirty = source->dirty;
 
@@ -2056,7 +2056,7 @@ DerivedMesh *CDDM_from_template(DerivedMesh *source,
 
 void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3])
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        MVert *vert;
        int i;
 
@@ -2070,7 +2070,7 @@ void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3])
 
 void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3])
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        MVert *vert;
        int i;
 
@@ -2084,7 +2084,7 @@ void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3])
 
 void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const short only_face_normals)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        float (*face_nors)[3] = NULL;
 
        if (dm->numVertData == 0) return;
@@ -2114,7 +2114,7 @@ void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const short only_face_normals
        }
 
 
-       face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, "face_nors");
+       face_nors = MEM_mallocN(sizeof(float) * 3 * dm->numTessFaceData, "face_nors");
 
        /* calculate face normals */
        BKE_mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
@@ -2123,7 +2123,7 @@ void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const short only_face_normals
                                         only_face_normals);
 
        CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN,
-                                                face_nors, dm->numTessFaceData);
+                            face_nors, dm->numTessFaceData);
 }
 
 
@@ -2138,7 +2138,7 @@ void CDDM_calc_normals_mapping(DerivedMesh *dm)
 /* bmesh note: this matches what we have in trunk */
 void CDDM_calc_normals(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        float (*poly_nors)[3];
 
        if (dm->numVertData == 0) return;
@@ -2158,7 +2158,7 @@ void CDDM_calc_normals(DerivedMesh *dm)
 
 void CDDM_calc_normals_tessface(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        float (*face_nors)[3];
 
        if (dm->numVertData == 0) return;
@@ -2190,7 +2190,7 @@ void CDDM_calc_normals_tessface(DerivedMesh *dm)
  */
 DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        CDDerivedMesh *cddm2 = NULL;
        MVert *mv, *mvert = NULL;
        BLI_array_declare(mvert);
@@ -2209,9 +2209,9 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
        totloop = dm->numLoopData;
        totpoly = dm->numPolyData;
        
-       newv = MEM_callocN(sizeof(int)*dm->numVertData, "newv vtable CDDM_merge_verts");
-       newe = MEM_callocN(sizeof(int)*dm->numEdgeData, "newv etable CDDM_merge_verts");
-       newl = MEM_callocN(sizeof(int)*totloop, "newv ltable CDDM_merge_verts");
+       newv = MEM_callocN(sizeof(int) * dm->numVertData, "newv vtable CDDM_merge_verts");
+       newe = MEM_callocN(sizeof(int) * dm->numEdgeData, "newv etable CDDM_merge_verts");
+       newl = MEM_callocN(sizeof(int) * totloop, "newv ltable CDDM_merge_verts");
        
        /*fill newl with destination vertex indices*/
        mv = cddm->mvert;
@@ -2247,7 +2247,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
                if (LIKELY(med->v1 != med->v2)) {
                        const unsigned int v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1;
                        const unsigned int v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2;
-                       void **eh_p= BLI_edgehash_lookup_p(ehash, v1, v2);
+                       void **eh_p = BLI_edgehash_lookup_p(ehash, v1, v2);
 
                        if (eh_p) {
                                newe[i] = GET_INT_FROM_POINTER(*eh_p);
@@ -2275,8 +2275,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
                for (j = 0; j < mp->totloop; j++, ml++) {
                        med = cddm->medge + ml->e;
                        if (LIKELY(med->v1 != med->v2)) {
-                               newl[j+mp->loopstart] = BLI_array_count(mloop);
-                               BLI_array_append(oldl, j+mp->loopstart);
+                               newl[j + mp->loopstart] = BLI_array_count(mloop);
+                               BLI_array_append(oldl, j + mp->loopstart);
                                BLI_array_append(mloop, *ml);
                                c++;
                        }
@@ -2294,7 +2294,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
        }
        
        /*create new cddm*/     
-       cddm2 = (CDDerivedMesh*) CDDM_from_template((DerivedMesh*)cddm, BLI_array_count(mvert), BLI_array_count(medge), 0, BLI_array_count(mloop), BLI_array_count(mpoly));
+       cddm2 = (CDDerivedMesh *) CDDM_from_template((DerivedMesh *)cddm, BLI_array_count(mvert), BLI_array_count(medge), 0, BLI_array_count(mloop), BLI_array_count(mpoly));
        
        /*update edge indices and copy customdata*/
        med = medge;
@@ -2331,10 +2331,10 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
        }
        
        /*copy over data.  CustomData_add_layer can do this, need to look it up.*/
-       memcpy(cddm2->mvert, mvert, sizeof(MVert)*BLI_array_count(mvert));
-       memcpy(cddm2->medge, medge, sizeof(MEdge)*BLI_array_count(medge));
-       memcpy(cddm2->mloop, mloop, sizeof(MLoop)*BLI_array_count(mloop));
-       memcpy(cddm2->mpoly, mpoly, sizeof(MPoly)*BLI_array_count(mpoly));
+       memcpy(cddm2->mvert, mvert, sizeof(MVert) * BLI_array_count(mvert));
+       memcpy(cddm2->medge, medge, sizeof(MEdge) * BLI_array_count(medge));
+       memcpy(cddm2->mloop, mloop, sizeof(MLoop) * BLI_array_count(mloop));
+       memcpy(cddm2->mpoly, mpoly, sizeof(MPoly) * BLI_array_count(mpoly));
        BLI_array_free(mvert); BLI_array_free(medge); BLI_array_free(mloop); BLI_array_free(mpoly);
        
        if (newv) 
@@ -2358,13 +2358,13 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
        dm->needsFree = 1;
        dm->release(dm);
        
-       return (DerivedMesh*)cddm2;
+       return (DerivedMesh *)cddm2;
 }
 #endif
 
 void CDDM_calc_edges_tessface(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        CustomData edgeData;
        EdgeHashIterator *ehi;
        MFace *mf = cddm->mface;
@@ -2401,10 +2401,10 @@ void CDDM_calc_edges_tessface(DerivedMesh *dm)
        med = CustomData_get_layer(&edgeData, CD_MEDGE);
        index = CustomData_get_layer(&edgeData, CD_ORIGINDEX);
        for (i = 0; !BLI_edgehashIterator_isDone(ehi);
-               BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
+            BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
                BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2);
 
-               med->flag = ME_EDGEDRAW|ME_EDGERENDER;
+               med->flag = ME_EDGEDRAW | ME_EDGERENDER;
                *index = ORIGINDEX_NONE;
        }
        BLI_edgehashIterator_free(ehi);
@@ -2422,7 +2422,7 @@ void CDDM_calc_edges_tessface(DerivedMesh *dm)
 /* warning, this uses existing edges but CDDM_calc_edges_tessface() doesn't */
 void CDDM_calc_edges(DerivedMesh *dm)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        CustomData edgeData;
        EdgeHashIterator *ehi;
        MPoly *mp = cddm->mpoly;
@@ -2438,7 +2438,7 @@ void CDDM_calc_edges(DerivedMesh *dm)
        med = cddm->medge;
        if (med) {
                for (i = 0; i < numEdges; i++, med++) {
-                       BLI_edgehash_insert(eh, med->v1, med->v2, SET_INT_IN_POINTER(i+1));
+                       BLI_edgehash_insert(eh, med->v1, med->v2, SET_INT_IN_POINTER(i + 1));
                }
        }
 
@@ -2464,12 +2464,12 @@ void CDDM_calc_edges(DerivedMesh *dm)
        med = CustomData_get_layer(&edgeData, CD_MEDGE);
        index = CustomData_get_layer(&edgeData, CD_ORIGINDEX);
        for (i = 0; !BLI_edgehashIterator_isDone(ehi);
-           BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
+            BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
                BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2);
                j = GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
 
-               med->flag = ME_EDGEDRAW|ME_EDGERENDER;
-               *index = j==0 ? ORIGINDEX_NONE : eindex[j-1];
+               med->flag = ME_EDGEDRAW | ME_EDGERENDER;
+               *index = j == 0 ? ORIGINDEX_NONE : eindex[j - 1];
 
                BLI_edgehashIterator_setValue(ehi, SET_INT_IN_POINTER(i));
        }
@@ -2498,7 +2498,7 @@ void CDDM_calc_edges(DerivedMesh *dm)
 void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts)
 {
        if (numVerts < dm->numVertData)
-               CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData-numVerts);
+               CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData - numVerts);
 
        dm->numVertData = numVerts;
 }
@@ -2506,7 +2506,7 @@ void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts)
 void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges)
 {
        if (numEdges < dm->numEdgeData)
-               CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData-numEdges);
+               CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData - numEdges);
 
        dm->numEdgeData = numEdges;
 }
@@ -2514,7 +2514,7 @@ void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges)
 void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces)
 {
        if (numTessFaces < dm->numTessFaceData)
-               CustomData_free_elem(&dm->faceData, numTessFaces, dm->numTessFaceData-numTessFaces);
+               CustomData_free_elem(&dm->faceData, numTessFaces, dm->numTessFaceData - numTessFaces);
 
        dm->numTessFaceData = numTessFaces;
 }
@@ -2522,7 +2522,7 @@ void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces)
 void CDDM_lower_num_polys(DerivedMesh *dm, int numPolys)
 {
        if (numPolys < dm->numPolyData)
-               CustomData_free_elem(&dm->polyData, numPolys, dm->numPolyData-numPolys);
+               CustomData_free_elem(&dm->polyData, numPolys, dm->numPolyData - numPolys);
 
        dm->numPolyData = numPolys;
 }
@@ -2531,60 +2531,60 @@ void CDDM_lower_num_polys(DerivedMesh *dm, int numPolys)
 
 MVert *CDDM_get_vert(DerivedMesh *dm, int index)
 {
-       return &((CDDerivedMesh*)dm)->mvert[index];
+       return &((CDDerivedMesh *)dm)->mvert[index];
 }
 
 MEdge *CDDM_get_edge(DerivedMesh *dm, int index)
 {
-       return &((CDDerivedMesh*)dm)->medge[index];
+       return &((CDDerivedMesh *)dm)->medge[index];
 }
 
 MFace *CDDM_get_tessface(DerivedMesh *dm, int index)
 {
-       return &((CDDerivedMesh*)dm)->mface[index];
+       return &((CDDerivedMesh *)dm)->mface[index];
 }
 
 MLoop *CDDM_get_loop(DerivedMesh *dm, int index)
 {
-       return &((CDDerivedMesh*)dm)->mloop[index];
+       return &((CDDerivedMesh *)dm)->mloop[index];
 }
 
 MPoly *CDDM_get_poly(DerivedMesh *dm, int index)
 {
-       return &((CDDerivedMesh*)dm)->mpoly[index];
+       return &((CDDerivedMesh *)dm)->mpoly[index];
 }
 
 /* array access functions */
 
 MVert *CDDM_get_verts(DerivedMesh *dm)
 {
-       return ((CDDerivedMesh*)dm)->mvert;
+       return ((CDDerivedMesh *)dm)->mvert;
 }
 
 MEdge *CDDM_get_edges(DerivedMesh *dm)
 {
-       return ((CDDerivedMesh*)dm)->medge;
+       return ((CDDerivedMesh *)dm)->medge;
 }
 
 MFace *CDDM_get_tessfaces(DerivedMesh *dm)
 {
-       return ((CDDerivedMesh*)dm)->mface;
+       return ((CDDerivedMesh *)dm)->mface;
 }
 
 MLoop *CDDM_get_loops(DerivedMesh *dm)
 {
-       return ((CDDerivedMesh*)dm)->mloop;
+       return ((CDDerivedMesh *)dm)->mloop;
 }
 
 MPoly *CDDM_get_polys(DerivedMesh *dm)
 {
-       return ((CDDerivedMesh*)dm)->mpoly;
+       return ((CDDerivedMesh *)dm)->mpoly;
 }
 
 void CDDM_tessfaces_to_faces(DerivedMesh *dm)
 {
        /*converts mfaces to mpolys/mloops*/
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        MFace *mf;
        MEdge *me;
        EdgeHash *eh = BLI_edgehash_new();
@@ -2628,13 +2628,13 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm)
                MPoly *mp;
                int l, *polyindex;
 
-               cddm->mloop = MEM_callocN(sizeof(MLoop)*totloop, "cddm->mloop in CDDM_tessfaces_to_faces");
-               cddm->mpoly = MEM_callocN(sizeof(MPoly)*cddm->dm.numTessFaceData, "cddm->mpoly in CDDM_tessfaces_to_faces");
+               cddm->mloop = MEM_callocN(sizeof(MLoop) * totloop, "cddm->mloop in CDDM_tessfaces_to_faces");
+               cddm->mpoly = MEM_callocN(sizeof(MPoly) * cddm->dm.numTessFaceData, "cddm->mpoly in CDDM_tessfaces_to_faces");
 
                CustomData_add_layer(&cddm->dm.loopData, CD_MLOOP, CD_ASSIGN, cddm->mloop, totloop);
                CustomData_add_layer(&cddm->dm.polyData, CD_MPOLY, CD_ASSIGN, cddm->mpoly, cddm->dm.numPolyData);
                CustomData_merge(&cddm->dm.faceData, &cddm->dm.polyData,
-                       CD_MASK_ORIGINDEX, CD_DUPLICATE, cddm->dm.numTessFaceData);
+                                CD_MASK_ORIGINDEX, CD_DUPLICATE, cddm->dm.numTessFaceData);
 
                polyindex = CustomData_get_layer(&cddm->dm.faceData, CD_POLYINDEX);
 
@@ -2657,12 +2657,12 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm)
                        ml++, l++;
 
                        ml->v = mf->v3;
-                       ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v3, mf->v4?mf->v4:mf->v1));
+                       ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v3, mf->v4 ? mf->v4 : mf->v1));
                        ml++, l++;
 
                        if (mf->v4) {
                                ml->v = mf->v4;
-                               ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v4, mf->v1));
+                               ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v4, mf->v1));
                                ml++, l++;
                        }
 
@@ -2675,7 +2675,7 @@ void CDDM_tessfaces_to_faces(DerivedMesh *dm)
 
 void CDDM_set_mvert(DerivedMesh *dm, MVert *mvert)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        
        if (!CustomData_has_layer(&dm->vertData, CD_MVERT))
                CustomData_add_layer(&dm->vertData, CD_MVERT, CD_ASSIGN, mvert, dm->numVertData);
@@ -2685,7 +2685,7 @@ void CDDM_set_mvert(DerivedMesh *dm, MVert *mvert)
 
 void CDDM_set_medge(DerivedMesh *dm, MEdge *medge)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
        if (!CustomData_has_layer(&dm->edgeData, CD_MEDGE))
                CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_ASSIGN, medge, dm->numEdgeData);
@@ -2695,7 +2695,7 @@ void CDDM_set_medge(DerivedMesh *dm, MEdge *medge)
 
 void CDDM_set_mface(DerivedMesh *dm, MFace *mface)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
        if (!CustomData_has_layer(&dm->faceData, CD_MFACE))
                CustomData_add_layer(&dm->faceData, CD_MFACE, CD_ASSIGN, mface, dm->numTessFaceData);
@@ -2705,7 +2705,7 @@ void CDDM_set_mface(DerivedMesh *dm, MFace *mface)
 
 void CDDM_set_mloop(DerivedMesh *dm, MLoop *mloop)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
        if (!CustomData_has_layer(&dm->loopData, CD_MLOOP))
                CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_ASSIGN, mloop, dm->numLoopData);
@@ -2715,7 +2715,7 @@ void CDDM_set_mloop(DerivedMesh *dm, MLoop *mloop)
 
 void CDDM_set_mpoly(DerivedMesh *dm, MPoly *mpoly)
 {
-       CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
        if (!CustomData_has_layer(&dm->polyData, CD_MPOLY))
                CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_ASSIGN, mpoly, dm->numPolyData);
index 2955e20..7ba1178 100644 (file)
@@ -62,9 +62,9 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa
        int a;
        float clipminx, clipminy, clipmaxx, clipmaxy;
        
-       cumap= MEM_callocN(sizeof(CurveMapping), "new curvemap");
-       cumap->flag= CUMA_DO_CLIP;
-       if (tot==4) cumap->cur= 3;              /* rhms, hack for 'col' curve? */
+       cumap = MEM_callocN(sizeof(CurveMapping), "new curvemap");
+       cumap->flag = CUMA_DO_CLIP;
+       if (tot == 4) cumap->cur = 3;   /* rhms, hack for 'col' curve? */
        
        clipminx = MIN2(minx, maxx);
        clipminy = MIN2(miny, maxy);
@@ -72,20 +72,20 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa
        clipmaxy = MAX2(miny, maxy);
        
        BLI_init_rctf(&cumap->curr, clipminx, clipmaxx, clipminy, clipmaxy);
-       cumap->clipr= cumap->curr;
+       cumap->clipr = cumap->curr;
        
-       cumap->white[0]= cumap->white[1]= cumap->white[2]= 1.0f;
-       cumap->bwmul[0]= cumap->bwmul[1]= cumap->bwmul[2]= 1.0f;
+       cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f;
+       cumap->bwmul[0] = cumap->bwmul[1] = cumap->bwmul[2] = 1.0f;
        
-       for (a=0; a<tot; a++) {
-               cumap->cm[a].flag= CUMA_EXTEND_EXTRAPOLATE;
-               cumap->cm[a].totpoint= 2;
-               cumap->cm[a].curve= MEM_callocN(2*sizeof(CurveMapPoint), "curve points");
-               
-               cumap->cm[a].curve[0].x= minx;
-               cumap->cm[a].curve[0].y= miny;
-               cumap->cm[a].curve[1].x= maxx;
-               cumap->cm[a].curve[1].y= maxy;
+       for (a = 0; a < tot; a++) {
+               cumap->cm[a].flag = CUMA_EXTEND_EXTRAPOLATE;
+               cumap->cm[a].totpoint = 2;
+               cumap->cm[a].curve = MEM_callocN(2 * sizeof(CurveMapPoint), "curve points");
+
+               cumap->cm[a].curve[0].x = minx;
+               cumap->cm[a].curve[0].y = miny;
+               cumap->cm[a].curve[1].x = maxx;
+               cumap->cm[a].curve[1].y = maxy;
        }       
 
        cumap->changed_timestamp = 0;
@@ -98,7 +98,7 @@ void curvemapping_free(CurveMapping *cumap)
        int a;
        
        if (cumap) {
-               for (a=0; a<CM_TOT; a++) {
+               for (a = 0; a < CM_TOT; a++) {
                        if (cumap->cm[a].curve) MEM_freeN(cumap->cm[a].curve);
                        if (cumap->cm[a].table) MEM_freeN(cumap->cm[a].table);
                        if (cumap->cm[a].premultable) MEM_freeN(cumap->cm[a].premultable);
@@ -112,14 +112,14 @@ CurveMapping *curvemapping_copy(CurveMapping *cumap)
        int a;
        
        if (cumap) {
-               CurveMapping *cumapn= MEM_dupallocN(cumap);
-               for (a=0; a<CM_TOT; a++) {
+               CurveMapping *cumapn = MEM_dupallocN(cumap);
+               for (a = 0; a < CM_TOT; a++) {
                        if (cumap->cm[a].curve) 
-                               cumapn->cm[a].curve= MEM_dupallocN(cumap->cm[a].curve);
+                               cumapn->cm[a].curve = MEM_dupallocN(cumap->cm[a].curve);
                        if (cumap->cm[a].table) 
-                               cumapn->cm[a].table= MEM_dupallocN(cumap->cm[a].table);
+                               cumapn->cm[a].table = MEM_dupallocN(cumap->cm[a].table);
                        if (cumap->cm[a].premultable) 
-                               cumapn->cm[a].premultable= MEM_dupallocN(cumap->cm[a].premultable);
+                               cumapn->cm[a].premultable = MEM_dupallocN(cumap->cm[a].premultable);
                }
                return cumapn;
        }
@@ -135,11 +135,11 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con
        if (black)
                copy_v3_v3(cumap->black, black);
        
-       for (a=0; a<3; a++) {
-               if (cumap->white[a]==cumap->black[a])
-                       cumap->bwmul[a]= 0.0f;
+       for (a = 0; a < 3; a++) {
+               if (cumap->white[a] == cumap->black[a])
+                       cumap->bwmul[a] = 0.0f;
                else
-                       cumap->bwmul[a]= 1.0f/(cumap->white[a] - cumap->black[a]);
+                       cumap->bwmul[a] = 1.0f / (cumap->white[a] - cumap->black[a]);
        }       
 }
 
@@ -149,52 +149,52 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con
 /* removes with flag set */
 void curvemap_remove(CurveMap *cuma, int flag)
 {
-       CurveMapPoint *cmp= MEM_mallocN((cuma->totpoint)*sizeof(CurveMapPoint), "curve points");
-       int a, b, removed=0;
+       CurveMapPoint *cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points");
+       int a, b, removed = 0;
        
        /* well, lets keep the two outer points! */
-       cmp[0]= cuma->curve[0];
-       for (a=1, b=1; a<cuma->totpoint-1; a++) {
+       cmp[0] = cuma->curve[0];
+       for (a = 1, b = 1; a < cuma->totpoint - 1; a++) {
                if (!(cuma->curve[a].flag & flag)) {
-                       cmp[b]= cuma->curve[a];
+                       cmp[b] = cuma->curve[a];
                        b++;
                }
                else removed++;
        }
-       cmp[b]= cuma->curve[a];
+       cmp[b] = cuma->curve[a];
        
        MEM_freeN(cuma->curve);
-       cuma->curve= cmp;
+       cuma->curve = cmp;
        cuma->totpoint -= removed;
 }
 
 void curvemap_insert(CurveMap *cuma, float x, float y)
 {
-       CurveMapPoint *cmp= MEM_callocN((cuma->totpoint+1)*sizeof(CurveMapPoint), "curve points");
-       int a, b, foundloc= 0;
+       CurveMapPoint *cmp = MEM_callocN((cuma->totpoint + 1) * sizeof(CurveMapPoint), "curve points");
+       int a, b, foundloc = 0;
                
        /* insert fragments of the old one and the new point to the new curve */
        cuma->totpoint++;
-       for (a=0, b=0; a<cuma->totpoint; a++) {
+       for (a = 0, b = 0; a < cuma->totpoint; a++) {
                if ((x < cuma->curve[a].x) && !foundloc) {
-                       cmp[a].x= x;
-                       cmp[a].y= y;
-                       cmp[a].flag= CUMA_SELECT;
-                       foundloc= 1;
+                       cmp[a].x = x;
+                       cmp[a].y = y;
+                       cmp[a].flag = CUMA_SELECT;
+                       foundloc = 1;
                }
                else {
-                       cmp[a].x= cuma->curve[b].x;
-                       cmp[a].y= cuma->curve[b].y;
-                       cmp[a].flag= cuma->curve[b].flag;
+                       cmp[a].x = cuma->curve[b].x;
+                       cmp[a].y = cuma->curve[b].y;
+                       cmp[a].flag = cuma->curve[b].flag;
                        cmp[a].flag &= ~CUMA_SELECT; /* make sure old points don't remain selected */
-                       cmp[a].shorty= cuma->curve[b].shorty;
+                       cmp[a].shorty = cuma->curve[b].shorty;
                        b++;
                }
        }
 
        /* free old curve and replace it with new one */
        MEM_freeN(cuma->curve);
-       cuma->curve= cmp;
+       cuma->curve = cmp;
 }
 
 void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope)
@@ -203,91 +203,91 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope)
                MEM_freeN(cuma->curve);
 
        switch (preset) {
-               case CURVE_PRESET_LINE: cuma->totpoint= 2; break;
-               case CURVE_PRESET_SHARP: cuma->totpoint= 4; break;
-               case CURVE_PRESET_SMOOTH: cuma->totpoint= 4; break;
-               case CURVE_PRESET_MAX: cuma->totpoint= 2; break;
-               case CURVE_PRESET_MID9: cuma->totpoint= 9; break;
-               case CURVE_PRESET_ROUND: cuma->totpoint= 4; break;
-               case CURVE_PRESET_ROOT: cuma->totpoint= 4; break;
+               case CURVE_PRESET_LINE: cuma->totpoint = 2; break;
+               case CURVE_PRESET_SHARP: cuma->totpoint = 4; break;
+               case CURVE_PRESET_SMOOTH: cuma->totpoint = 4; break;
+               case CURVE_PRESET_MAX: cuma->totpoint = 2; break;
+               case CURVE_PRESET_MID9: cuma->totpoint = 9; break;
+               case CURVE_PRESET_ROUND: cuma->totpoint = 4; break;
+               case CURVE_PRESET_ROOT: cuma->totpoint = 4; break;
        }
 
-       cuma->curve= MEM_callocN(cuma->totpoint*sizeof(CurveMapPoint), "curve points");
+       cuma->curve = MEM_callocN(cuma->totpoint * sizeof(CurveMapPoint), "curve points");
 
        switch (preset) {
                case CURVE_PRESET_LINE:
-                       cuma->curve[0].x= clipr->xmin;
-                       cuma->curve[0].y= clipr->ymax;
-                       cuma->curve[0].flag= 0;
-                       cuma->curve[1].x= clipr->xmax;
-                       cuma->curve[1].y= clipr->ymin;
-                       cuma->curve[1].flag= 0;
+                       cuma->curve[0].x = clipr->xmin;
+                       cuma->curve[0].y = clipr->ymax;
+                       cuma->curve[0].flag = 0;
+                       cuma->curve[1].x = clipr->xmax;
+                       cuma->curve[1].y = clipr->ymin;
+                       cuma->curve[1].flag = 0;
                        break;
                case CURVE_PRESET_SHARP:
-                       cuma->curve[0].x= 0;
-                       cuma->curve[0].y= 1;
-                       cuma->curve[1].x= 0.25;
-                       cuma->curve[1].y= 0.50;
-                       cuma->curve[2].x= 0.75;
-                       cuma->curve[2].y= 0.04;
-                       cuma->curve[3].x= 1;
-                       cuma->curve[3].y= 0;
+                       cuma->curve[0].x = 0;
+                       cuma->curve[0].y = 1;
+                       cuma->curve[1].x = 0.25;
+                       cuma->curve[1].y = 0.50;
+                       cuma->curve[2].x = 0.75;
+                       cuma->curve[2].y = 0.04;
+                       cuma->curve[3].x = 1;
+                       cuma->curve[3].y = 0;
                        break;
                case CURVE_PRESET_SMOOTH:
-                       cuma->curve[0].x= 0;
-                       cuma->curve[0].y= 1;
-                       cuma->curve[1].x= 0.25;
-                       cuma->curve[1].y= 0.94;
-                       cuma->curve[2].x= 0.75;
-                       cuma->curve[2].y= 0.06;
-                       cuma->curve[3].x= 1;
-                       cuma->curve[3].y= 0;
+                       cuma->curve[0].x = 0;
+                       cuma->curve[0].y = 1;
+                       cuma->curve[1].x = 0.25;
+                       cuma->curve[1].y = 0.94;
+                       cuma->curve[2].x = 0.75;
+                       cuma->curve[2].y = 0.06;
+                       cuma->curve[3].x = 1;
+                       cuma->curve[3].y = 0;
                        break;
                case CURVE_PRESET_MAX:
-                       cuma->curve[0].x= 0;
-                       cuma->curve[0].y= 1;
-                       cuma->curve[1].x= 1;
-                       cuma->curve[1].y= 1;
+                       cuma->curve[0].x = 0;
+                       cuma->curve[0].y = 1;
+                       cuma->curve[1].x = 1;
+                       cuma->curve[1].y = 1;
                        break;
                case CURVE_PRESET_MID9:
-                       {
-                               int i;
-                               for (i = 0; i < cuma->totpoint; i++) {
-                                       cuma->curve[i].x = i / ((float)cuma->totpoint - 1);
-                                       cuma->curve[i].y = 0.5;
-                               }
+               {
+                       int i;
+                       for (i = 0; i < cuma->totpoint; i++) {
+                               cuma->curve[i].x = i / ((float)cuma->totpoint - 1);
+                               cuma->curve[i].y = 0.5;
                        }
-                       break;
+               }
+               break;
                case CURVE_PRESET_ROUND:
-                       cuma->curve[0].x= 0;
-                       cuma->curve[0].y= 1;
-                       cuma->curve[1].x= 0.5;
-                       cuma->curve[1].y= 0.90;
-                       cuma->curve[2].x= 0.86;
-                       cuma->curve[2].y= 0.5;
-                       cuma->curve[3].x= 1;
-                       cuma->curve[3].y= 0;
+                       cuma->curve[0].x = 0;
+                       cuma->curve[0].y = 1;
+                       cuma->curve[1].x = 0.5;
+                       cuma->curve[1].y = 0.90;
+                       cuma->curve[2].x = 0.86;
+                       cuma->curve[2].y = 0.5;
+                       cuma->curve[3].x = 1;
+                       cuma->curve[3].y = 0;
                        break;
                case CURVE_PRESET_ROOT:
-                       cuma->curve[0].x= 0;
-                       cuma->curve[0].y= 1;
-                       cuma->curve[1].x= 0.25;
-                       cuma->curve[1].y= 0.95;
-                       cuma->curve[2].x= 0.75;
-                       cuma->curve[2].y= 0.44;
-                       cuma->curve[3].x= 1;
-                       cuma->curve[3].y= 0;
+                       cuma->curve[0].x = 0;
+                       cuma->curve[0].y = 1;
+                       cuma->curve[1].x = 0.25;
+                       cuma->curve[1].y = 0.95;
+                       cuma->curve[2].x = 0.75;
+                       cuma->curve[2].y = 0.44;
+                       cuma->curve[3].x = 1;
+                       cuma->curve[3].y = 0;
                        break;
        }
 
        /* mirror curve in x direction to have positive slope
         * rather than default negative slope */
        if (slope == CURVEMAP_SLOPE_POSITIVE) {
-               int i, last=cuma->totpoint-1;
-               CurveMapPoint *newpoints= MEM_dupallocN(cuma->curve);
+               int i, last = cuma->totpoint - 1;
+               CurveMapPoint *newpoints = MEM_dupallocN(cuma->curve);
                
-               for (i=0; i<cuma->totpoint; i++) {
-                       newpoints[i].y = cuma->curve[last-i].y;
+               for (i = 0; i < cuma->totpoint; i++) {
+                       newpoints[i].y = cuma->curve[last - i].y;
                }
                
                MEM_freeN(cuma->curve);
@@ -296,7 +296,7 @@ void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope)
        
        if (cuma->table) {
                MEM_freeN(cuma->table);
-               cuma->table= NULL;
+               cuma->table = NULL;
        }
 }
 
@@ -305,7 +305,7 @@ void curvemap_sethandle(CurveMap *cuma, int type)
 {
        int a;
        
-       for (a=0; a<cuma->totpoint; a++) {
+       for (a = 0; a < cuma->totpoint; a++) {
                if (cuma->curve[a].flag & CUMA_SELECT) {
                        if (type) cuma->curve[a].flag |= CUMA_VECTOR;
                        else cuma->curve[a].flag &= ~CUMA_VECTOR;
@@ -322,65 +322,65 @@ static void calchandle_curvemap(BezTriple *bezt, BezTriple *prev, BezTriple *nex
        float len, len_a, len_b;
        float dvec_a[2], dvec_b[2];
 
-       if (bezt->h1==0 && bezt->h2==0) {
+       if (bezt->h1 == 0 && bezt->h2 == 0) {
                return;
        }
        
-       p2= bezt->vec[1];
+       p2 = bezt->vec[1];
        
-       if (prev==NULL) {
-               p3= next->vec[1];
-               pt[0]= 2.0f*p2[0] - p3[0];
-               pt[1]= 2.0f*p2[1] - p3[1];
-               p1= pt;
+       if (prev == NULL) {
+               p3 = next->vec[1];
+               pt[0] = 2.0f * p2[0] - p3[0];
+               pt[1] = 2.0f * p2[1] - p3[1];
+               p1 = pt;
        }
        else {
-               p1= prev->vec[1];
+               p1 = prev->vec[1];
        }
        
-       if (next==NULL) {
-               p1= prev->vec[1];
-               pt[0]= 2.0f*p2[0] - p1[0];
-               pt[1]= 2.0f*p2[1] - p1[1];
-               p3= pt;
+       if (next == NULL) {
+               p1 = prev->vec[1];
+               pt[0] = 2.0f * p2[0] - p1[0];
+               pt[1] = 2.0f * p2[1] - p1[1];
+               p3 = pt;
        }
        else {
-               p3= next->vec[1];
+               p3 = next->vec[1];
        }
 
        sub_v2_v2v2(dvec_a, p2, p1);
        sub_v2_v2v2(dvec_b, p3, p2);
 
-       len_a= len_v2(dvec_a);
-       len_b= len_v2(dvec_b);
+       len_a = len_v2(dvec_a);
+       len_b = len_v2(dvec_b);
 
-       if (len_a==0.0f) len_a=1.0f;
-       if (len_b==0.0f) len_b=1.0f;
+       if (len_a == 0.0f) len_a = 1.0f;
+       if (len_b == 0.0f) len_b = 1.0f;
 
-       if (bezt->h1==HD_AUTO || bezt->h2==HD_AUTO) { /* auto */
+       if (bezt->h1 == HD_AUTO || bezt->h2 == HD_AUTO) { /* auto */
                float tvec[2];
-               tvec[0]= dvec_b[0]/len_b + dvec_a[0]/len_a;
-               tvec[1]= dvec_b[1]/len_b + dvec_a[1]/len_a;
+               tvec[0] = dvec_b[0] / len_b + dvec_a[0] / len_a;
+               tvec[1] = dvec_b[1] / len_b + dvec_a[1] / len_a;
 
-               len= len_v2(tvec) * 2.5614f;
-               if (len!=0.0f) {
+               len = len_v2(tvec) * 2.5614f;
+               if (len != 0.0f) {
                        
-                       if (bezt->h1==HD_AUTO) {
-                               len_a/=len;
-                               madd_v2_v2v2fl(p2-3, p2, tvec, -len_a);
+                       if (bezt->h1 == HD_AUTO) {
+                               len_a /= len;
+                               madd_v2_v2v2fl(p2 - 3, p2, tvec, -len_a);
                        }
-                       if (bezt->h2==HD_AUTO) {
-                               len_b/=len;
-                               madd_v2_v2v2fl(p2+3, p2, tvec,  len_b);
+                       if (bezt->h2 == HD_AUTO) {
+                               len_b /= len;
+                               madd_v2_v2v2fl(p2 + 3, p2, tvec,  len_b);
                        }
                }
        }
 
-       if (bezt->h1==HD_VECT) {        /* vector */
-               madd_v2_v2v2fl(p2-3, p2, dvec_a, -1.0f/3.0f);
+       if (bezt->h1 == HD_VECT) {    /* vector */
+               madd_v2_v2v2fl(p2 - 3, p2, dvec_a, -1.0f / 3.0f);
        }
-       if (bezt->h2==HD_VECT) {
-               madd_v2_v2v2fl(p2+3, p2, dvec_b,  1.0f/3.0f);
+       if (bezt->h2 == HD_VECT) {
+               madd_v2_v2v2fl(p2 + 3, p2, dvec_b,  1.0f / 3.0f);
        }
 }
 
@@ -389,27 +389,27 @@ static void calchandle_curvemap(BezTriple *bezt, BezTriple *prev, BezTriple *nex
 static float curvemap_calc_extend(CurveMap *cuma, float x, const float first[2], const float last[2])
 {
        if (x <= first[0]) {
-               if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) {
+               if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
                        /* no extrapolate */
                        return first[1];
                }
                else {
-                       if (cuma->ext_in[0]==0.0f)
-                               return first[1] + cuma->ext_in[1]*10000.0f;
+                       if (cuma->ext_in[0] == 0.0f)
+                               return first[1] + cuma->ext_in[1] * 10000.0f;
                        else
-                               return first[1] + cuma->ext_in[1]*(x - first[0])/cuma->ext_in[0];
+                               return first[1] + cuma->ext_in[1] * (x - first[0]) / cuma->ext_in[0];
                }
        }
        else if (x >= last[0]) {
-               if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) {
+               if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
                        /* no extrapolate */
                        return last[1];
                }
                else {
-                       if (cuma->ext_out[0]==0.0f)
-                               return last[1] - cuma->ext_out[1]*10000.0f;
+                       if (cuma->ext_out[0] == 0.0f)
+                               return last[1] - cuma->ext_out[1] * 10000.0f;
                        else
-                               return last[1] + cuma->ext_out[1]*(x - last[0])/cuma->ext_out[0];
+                               return last[1] + cuma->ext_out[1] * (x - last[0]) / cuma->ext_out[0];
                }
        }
        return 0.0f;
@@ -418,74 +418,74 @@ static float curvemap_calc_extend(CurveMap *cuma, float x, const float first[2],
 /* only creates a table for a single channel in CurveMapping */
 static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
 {
-       CurveMapPoint *cmp= cuma->curve;
+       CurveMapPoint *cmp = cuma->curve;
        BezTriple *bezt;
        float *fp, *allpoints, *lastpoint, curf, range;
        int a, totpoint;
        
-       if (cuma->curve==NULL) return;
+       if (cuma->curve == NULL) return;
        
        /* default rect also is table range */
-       cuma->mintable= clipr->xmin;
-       cuma->maxtable= clipr->xmax;
+       cuma->mintable = clipr->xmin;
+       cuma->maxtable = clipr->xmax;
        
        /* hrmf... we now rely on blender ipo beziers, these are more advanced */
-       bezt= MEM_callocN(cuma->totpoint*sizeof(BezTriple), "beztarr");
+       bezt = MEM_callocN(cuma->totpoint * sizeof(BezTriple), "beztarr");
        
-       for (a=0; a<cuma->totpoint; a++) {
-               cuma->mintable= MIN2(cuma->mintable, cmp[a].x);
-               cuma->maxtable= MAX2(cuma->maxtable, cmp[a].x);
-               bezt[a].vec[1][0]= cmp[a].x;
-               bezt[a].vec[1][1]= cmp[a].y;
+       for (a = 0; a < cuma->totpoint; a++) {
+               cuma->mintable = MIN2(cuma->mintable, cmp[a].x);
+               cuma->maxtable = MAX2(cuma->maxtable, cmp[a].x);
+               bezt[a].vec[1][0] = cmp[a].x;
+               bezt[a].vec[1][1] = cmp[a].y;
                if (cmp[a].flag & CUMA_VECTOR)
-                       bezt[a].h1= bezt[a].h2= HD_VECT;
+                       bezt[a].h1 = bezt[a].h2 = HD_VECT;
                else
-                       bezt[a].h1= bezt[a].h2= HD_AUTO;
+                       bezt[a].h1 = bezt[a].h2 = HD_AUTO;
        }
        
-       for (a=0; a<cuma->totpoint; a++) {
-               if (a==0)
-                       calchandle_curvemap(bezt, NULL, bezt+1, 0);
-               else if (a==cuma->totpoint-1)
-                       calchandle_curvemap(bezt+a, bezt+a-1, NULL, 0);
+       for (a = 0; a < cuma->totpoint; a++) {
+               if (a == 0)
+                       calchandle_curvemap(bezt, NULL, bezt + 1, 0);
+               else if (a == cuma->totpoint - 1)
+                       calchandle_curvemap(bezt + a, bezt + a - 1, NULL, 0);
                else
-                       calchandle_curvemap(bezt+a, bezt+a-1, bezt+a+1, 0);
+                       calchandle_curvemap(bezt + a, bezt + a - 1, bezt + a + 1, 0);
        }
        
        /* first and last handle need correction, instead of pointing to center of next/prev, 
         * we let it point to the closest handle */
-       if (cuma->totpoint>2) {
+       if (cuma->totpoint > 2) {
                float hlen, nlen, vec[3];
                
-               if (bezt[0].h2==HD_AUTO) {
+               if (bezt[0].h2 == HD_AUTO) {
                        
-                       hlen= len_v3v3(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */
+                       hlen = len_v3v3(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */
                        /* clip handle point */
                        copy_v3_v3(vec, bezt[1].vec[0]);
                        if (vec[0] < bezt[0].vec[1][0])
-                               vec[0]= bezt[0].vec[1][0];
+                               vec[0] = bezt[0].vec[1][0];
                        
                        sub_v3_v3(vec, bezt[0].vec[1]);
-                       nlen= len_v3(vec);
-                       if (nlen>FLT_EPSILON) {
-                               mul_v3_fl(vec, hlen/nlen);
+                       nlen = len_v3(vec);
+                       if (nlen > FLT_EPSILON) {
+                               mul_v3_fl(vec, hlen / nlen);
                                add_v3_v3v3(bezt[0].vec[2], vec, bezt[0].vec[1]);
                                sub_v3_v3v3(bezt[0].vec[0], bezt[0].vec[1], vec);
                        }
                }
-               a= cuma->totpoint-1;
-               if (bezt[a].h2==HD_AUTO) {
+               a = cuma->totpoint - 1;
+               if (bezt[a].h2 == HD_AUTO) {
                        
-                       hlen= len_v3v3(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */
+                       hlen = len_v3v3(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */
                        /* clip handle point */
-                       copy_v3_v3(vec, bezt[a-1].vec[2]);
+                       copy_v3_v3(vec, bezt[a - 1].vec[2]);
                        if (vec[0] > bezt[a].vec[1][0])
-                               vec[0]= bezt[a].vec[1][0];
+                               vec[0] = bezt[a].vec[1][0];
                        
                        sub_v3_v3(vec, bezt[a].vec[1]);
-                       nlen= len_v3(vec);
-                       if (nlen>FLT_EPSILON) {
-                               mul_v3_fl(vec, hlen/nlen);
+                       nlen = len_v3(vec);
+                       if (nlen > FLT_EPSILON) {
+                               mul_v3_fl(vec, hlen / nlen);
                                add_v3_v3v3(bezt[a].vec[0], vec, bezt[a].vec[1]);
                                sub_v3_v3v3(bezt[a].vec[2], bezt[a].vec[1], vec);
                        }
@@ -494,63 +494,63 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
        /* make the bezier curve */
        if (cuma->table)
                MEM_freeN(cuma->table);
-       totpoint= (cuma->totpoint-1)*CM_RESOL;
-       fp= allpoints= MEM_callocN(totpoint*2*sizeof(float), "table");
+       totpoint = (cuma->totpoint - 1) * CM_RESOL;
+       fp = allpoints = MEM_callocN(totpoint * 2 * sizeof(float), "table");
        
-       for (a=0; a<cuma->totpoint-1; a++, fp += 2*CM_RESOL) {
-               correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a+1].vec[0], bezt[a+1].vec[1]);
-               BKE_curve_forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a+1].vec[0][0], bezt[a+1].vec[1][0], fp, CM_RESOL-1, 2*sizeof(float)); 
-               BKE_curve_forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2*sizeof(float));
+       for (a = 0; a < cuma->totpoint - 1; a++, fp += 2 * CM_RESOL) {
+               correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a + 1].vec[0], bezt[a + 1].vec[1]);
+               BKE_curve_forward_diff_bezier(bezt[a].vec[1][0], bezt[a].vec[2][0], bezt[a + 1].vec[0][0], bezt[a + 1].vec[1][0], fp, CM_RESOL - 1, 2 * sizeof(float));
+               BKE_curve_forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a + 1].vec[0][1], bezt[a + 1].vec[1][1], fp + 1, CM_RESOL - 1, 2 * sizeof(float));
        }
        
        /* store first and last handle for extrapolation, unit length */
-       cuma->ext_in[0]= bezt[0].vec[0][0] - bezt[0].vec[1][0];
-       cuma->ext_in[1]= bezt[0].vec[0][1] - bezt[0].vec[1][1];
-       range= sqrt(cuma->ext_in[0]*cuma->ext_in[0] + cuma->ext_in[1]*cuma->ext_in[1]);
-       cuma->ext_in[0]/= range;
-       cuma->ext_in[1]/= range;
-       
-       a= cuma->totpoint-1;
-       cuma->ext_out[0]= bezt[a].vec[1][0] - bezt[a].vec[2][0];
-       cuma->ext_out[1]= bezt[a].vec[1][1] - bezt[a].vec[2][1];
-       range= sqrt(cuma->ext_out[0]*cuma->ext_out[0] + cuma->ext_out[1]*cuma->ext_out[1]);
-       cuma->ext_out[0]/= range;
-       cuma->ext_out[1]/= range;
+       cuma->ext_in[0] = bezt[0].vec[0][0] - bezt[0].vec[1][0];
+       cuma->ext_in[1] = bezt[0].vec[0][1] - bezt[0].vec[1][1];
+       range = sqrt(cuma->ext_in[0] * cuma->ext_in[0] + cuma->ext_in[1] * cuma->ext_in[1]);
+       cuma->ext_in[0] /= range;
+       cuma->ext_in[1] /= range;
+
+       a = cuma->totpoint - 1;
+       cuma->ext_out[0] = bezt[a].vec[1][0] - bezt[a].vec[2][0];
+       cuma->ext_out[1] = bezt[a].vec[1][1] - bezt[a].vec[2][1];
+       range = sqrt(cuma->ext_out[0] * cuma->ext_out[0] + cuma->ext_out[1] * cuma->ext_out[1]);
+       cuma->ext_out[0] /= range;
+       cuma->ext_out[1] /= range;
        
        /* cleanup */
        MEM_freeN(bezt);
 
-       range= CM_TABLEDIV*(cuma->maxtable - cuma->mintable);
-       cuma->range= 1.0f/range;
+       range = CM_TABLEDIV * (cuma->maxtable - cuma->mintable);
+       cuma->range = 1.0f / range;
        
        /* now make a table with CM_TABLE equal x distances */
-       fp= allpoints;
-       lastpoint= allpoints + 2*(totpoint-1);
-       cmp= MEM_callocN((CM_TABLE+1)*sizeof(CurveMapPoint), "dist table");
-       
-       for (a=0; a<=CM_TABLE; a++) {
-               curf= cuma->mintable + range*(float)a;
-               cmp[a].x= curf;
+       fp = allpoints;
+       lastpoint = allpoints + 2 * (totpoint - 1);
+       cmp = MEM_callocN((CM_TABLE + 1) * sizeof(CurveMapPoint), "dist table");
+
+       for (a = 0; a <= CM_TABLE; a++) {
+               curf = cuma->mintable + range * (float)a;
+               cmp[a].x = curf;
                
                /* get the first x coordinate larger than curf */
-               while (curf >= fp[0] && fp!=lastpoint) {
-                       fp+=2;
+               while (curf >= fp[0] && fp != lastpoint) {
+                       fp += 2;
                }
-               if (fp==allpoints || (curf >= fp[0] && fp==lastpoint))
-                       cmp[a].y= curvemap_calc_extend(cuma, curf, allpoints, lastpoint);
+               if (fp == allpoints || (curf >= fp[0] && fp == lastpoint))
+                       cmp[a].y = curvemap_calc_extend(cuma, curf, allpoints, lastpoint);
                else {
-                       float fac1= fp[0] - fp[-2];
-                       float fac2= fp[0] - curf;
+                       float fac1 = fp[0] - fp[-2];
+                       float fac2 = fp[0] - curf;
                        if (fac1 > FLT_EPSILON)
-                               fac1= fac2/fac1;
+                               fac1 = fac2 / fac1;
                        else
-                               fac1= 0.0f;
-                       cmp[a].y= fac1*fp[-1] + (1.0f-fac1)*fp[1];
+                               fac1 = 0.0f;
+                       cmp[a].y = fac1 * fp[-1] + (1.0f - fac1) * fp[1];
                }
        }
        
        MEM_freeN(allpoints);
-       cuma->table= cmp;
+       cuma->table = cmp;
 }
 
 /* call when you do images etc, needs restore too. also verifies tables */
@@ -561,34 +561,34 @@ void curvemapping_premultiply(CurveMapping *cumap, int restore)
        
        if (restore) {
                if (cumap->flag & CUMA_PREMULLED) {
-                       for (a=0; a<3; a++) {
+                       for (a = 0; a < 3; a++) {
                                MEM_freeN(cumap->cm[a].table);
-                               cumap->cm[a].table= cumap->cm[a].premultable;
-                               cumap->cm[a].premultable= NULL;
+                               cumap->cm[a].table = cumap->cm[a].premultable;
+                               cumap->cm[a].premultable = NULL;
                        }
                        
                        cumap->flag &= ~CUMA_PREMULLED;
                }
        }
        else {
-               if ((cumap->flag & CUMA_PREMULLED)==0) {
+               if ((cumap->flag & CUMA_PREMULLED) == 0) {
                        /* verify and copy */
-                       for (a=0; a<3; a++) {
-                               if (cumap->cm[a].table==NULL)
-                                       curvemap_make_table(cumap->cm+a, &cumap->clipr);
-                               cumap->cm[a].premultable= cumap->cm[a].table;
-                               cumap->cm[a].table= MEM_mallocN((CM_TABLE+1)*sizeof(CurveMapPoint), "premul table");
-                               memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE+1)*sizeof(CurveMapPoint));
+                       for (a = 0; a < 3; a++) {
+                               if (cumap->cm[a].table == NULL)
+                                       curvemap_make_table(cumap->cm + a, &cumap->clipr);
+                               cumap->cm[a].premultable = cumap->cm[a].table;
+                               cumap->cm[a].table = MEM_mallocN((CM_TABLE + 1) * sizeof(CurveMapPoint), "premul table");
+                               memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE + 1) * sizeof(CurveMapPoint));
                        }
                        
-                       if (cumap->cm[3].table==NULL)
-                               curvemap_make_table(cumap->cm+3, &cumap->clipr);
+                       if (cumap->cm[3].table == NULL)
+                               curvemap_make_table(cumap->cm + 3, &cumap->clipr);
                
                        /* premul */
-                       for (a=0; a<3; a++) {
+                       for (a = 0; a < 3; a++) {
                                int b;
-                               for (b=0; b<=CM_TABLE; b++) {
-                                       cumap->cm[a].table[b].y= curvemap_evaluateF(cumap->cm+3, cumap->cm[a].table[b].y);
+                               for (b = 0; b <= CM_TABLE; b++) {
+                                       cumap->cm[a].table[b].y = curvemap_evaluateF(cumap->cm + 3, cumap->cm[a].table[b].y);
                                }
                        }
                        
@@ -599,10 +599,10 @@ void curvemapping_premultiply(CurveMapping *cumap, int restore)
 
 static int sort_curvepoints(const void *a1, const void *a2)
 {
-       const struct CurveMapPoint *x1=a1, *x2=a2;
+       const struct CurveMapPoint *x1 = a1, *x2 = a2;
        
-       if ( x1->x > x2->x ) return 1;
-       else if ( x1->x < x2->x) return -1;
+       if (x1->x > x2->x) return 1;
+       else if (x1->x < x2->x) return -1;
        return 0;
 }
 
@@ -611,30 +611,30 @@ static int sort_curvepoints(const void *a1, const void *a2)
 /* note; only does current curvemap! */
 void curvemapping_changed(CurveMapping *cumap, int rem_doubles)
 {
-       CurveMap *cuma= cumap->cm+cumap->cur;
-       CurveMapPoint *cmp= cuma->curve;
-       rctf *clipr= &cumap->clipr;
-       float thresh= 0.01f*(clipr->xmax - clipr->xmin);
-       float dx= 0.0f, dy= 0.0f;
+       CurveMap *cuma = cumap->cm + cumap->cur;
+       CurveMapPoint *cmp = cuma->curve;
+       rctf *clipr = &cumap->clipr;
+       float thresh = 0.01f * (clipr->xmax - clipr->xmin);
+       float dx = 0.0f, dy = 0.0f;
        int a;
 
        cumap->changed_timestamp++;
 
        /* clamp with clip */
        if (cumap->flag & CUMA_DO_CLIP) {
-               for (a=0; a<cuma->totpoint; a++) {
+               for (a = 0; a < cuma->totpoint; a++) {
                        if (cmp[a].flag & CUMA_SELECT) {
                                if (cmp[a].x < clipr->xmin)
-                                       dx= MIN2(dx, cmp[a].x - clipr->xmin);
+                                       dx = MIN2(dx, cmp[a].x - clipr->xmin);
                                else if (cmp[a].x > clipr->xmax)
-                                       dx= MAX2(dx, cmp[a].x - clipr->xmax);
+                                       dx = MAX2(dx, cmp[a].x - clipr->xmax);
                                if (cmp[a].y < clipr->ymin)
-                                       dy= MIN2(dy, cmp[a].y - clipr->ymin);
+                                       dy = MIN2(dy, cmp[a].y - clipr->ymin);
                                else if (cmp[a].y > clipr->ymax)
-                                       dy= MAX2(dy, cmp[a].y - clipr->ymax);
+                                       dy = MAX2(dy, cmp[a].y - clipr->ymax);
                        }
                }
-               for (a=0; a<cuma->totpoint; a++) {
+               for (a = 0; a < cuma->totpoint; a++) {
                        if (cmp[a].flag & CUMA_SELECT) {
                                cmp[a].x -= dx;
                                cmp[a].y -= dy;
@@ -646,25 +646,25 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles)
        qsort(cmp, cuma->totpoint, sizeof(CurveMapPoint), sort_curvepoints);
        
        /* remove doubles, threshold set on 1% of default range */
-       if (rem_doubles && cuma->totpoint>2) {
-               for (a=0; a<cuma->totpoint-1; a++) {
-                       dx= cmp[a].x - cmp[a+1].x;
-                       dy= cmp[a].y - cmp[a+1].y;
-                       if ( sqrtf(dx*dx + dy*dy) < thresh ) {
-                               if (a==0) {
-                                       cmp[a+1].flag|= 2;
-                                       if (cmp[a+1].flag & CUMA_SELECT)
+       if (rem_doubles && cuma->totpoint > 2) {
+               for (a = 0; a < cuma->totpoint - 1; a++) {
+                       dx = cmp[a].x - cmp[a + 1].x;
+                       dy = cmp[a].y - cmp[a + 1].y;
+                       if (sqrtf(dx * dx + dy * dy) < thresh) {
+                               if (a == 0) {
+                                       cmp[a + 1].flag |= 2;
+                                       if (cmp[a + 1].flag & CUMA_SELECT)
                                                cmp[a].flag |= CUMA_SELECT;
                                }
                                else {
-                                       cmp[a].flag|= 2;
+                                       cmp[a].flag |= 2;
                                        if (cmp[a].flag & CUMA_SELECT)
-                                               cmp[a+1].flag |= CUMA_SELECT;
+                                               cmp[a + 1].flag |= CUMA_SELECT;
                                }
-                               break;  /* we assume 1 deletion per edit is ok */
+                               break;  /* we assume 1 deletion per edit is ok */
                        }
                }
-               if (a != cuma->totpoint-1)
+               if (a != cuma->totpoint - 1)
                        curvemap_remove(cuma, 2);
        }       
        curvemap_make_table(cuma, clipr);
@@ -677,31 +677,31 @@ float curvemap_evaluateF(CurveMap *cuma, float value)
        int i;
 
        /* index in table */
-       fi= (value-cuma->mintable)*cuma->range;
-       i= (int)fi;
+       fi = (value - cuma->mintable) * cuma->range;
+       i = (int)fi;
        
        /* fi is table float index and should check against table range i.e. [0.0 CM_TABLE] */
-       if (fi<0.0f || fi>CM_TABLE)
+       if (fi < 0.0f || fi > CM_TABLE)
                return curvemap_calc_extend(cuma, value, &cuma->table[0].x, &cuma->table[CM_TABLE].x);
        else {
-               if (i<0) return cuma->table[0].y;
-               if (i>=CM_TABLE) return cuma->table[CM_TABLE].y;
+               if (i < 0) return cuma->table[0].y;
+               if (i >= CM_TABLE) return cuma->table[CM_TABLE].y;
                
-               fi= fi-(float)i;
-               return (1.0f-fi)*cuma->table[i].y + (fi)*cuma->table[i+1].y; 
+               fi = fi - (float)i;
+               return (1.0f - fi) * cuma->table[i].y + (fi) * cuma->table[i + 1].y;
        }
 }
 
 /* works with curve 'cur' */
 float curvemapping_evaluateF(CurveMapping *cumap, int cur, float value)
 {
-       CurveMap *cuma= cumap->cm+cur;
+       CurveMap *cuma = cumap->cm + cur;
        
        /* allocate or bail out */
-       if (cuma->table==NULL) {
+       if (cuma->table == NULL) {
                curvemap_make_table(cuma, &cumap->clipr);
-               if (cuma->table==NULL)
-                       return 1.0f-value;
+               if (cuma->table == NULL)
+                       return 1.0f - value;
        }
        return curvemap_evaluateF(cuma, value);
 }
@@ -709,17 +709,17 @@ float curvemapping_evaluateF(CurveMapping *cumap, int cur, float value)
 /* vector case */
 void curvemapping_evaluate3F(CurveMapping *cumap, float vecout[3], const float vecin[3])
 {
-       vecout[0]= curvemapping_evaluateF(cumap, 0, vecin[0]);
-       vecout[1]= curvemapping_evaluateF(cumap, 1, vecin[1]);
-       vecout[2]= curvemapping_evaluateF(cumap, 2, vecin[2]);
+       vecout[0] = curvemapping_evaluateF(cumap, 0, vecin[0]);
+       vecout[1] = curvemapping_evaluateF(cumap, 1, vecin[1]);
+       vecout[2] = curvemapping_evaluateF(cumap, 2, vecin[2]);
 }
 
 /* RGB case, no black/white points, no premult */
 void curvemapping_evaluateRGBF(CurveMapping *cumap, float vecout[3], const float vecin[3])
 {
-       vecout[0]= curvemapping_evaluateF(cumap, 0, curvemapping_evaluateF(cumap, 3, vecin[0]));
-       vecout[1]= curvemapping_evaluateF(cumap, 1, curvemapping_evaluateF(cumap, 3, vecin[1]));
-       vecout[2]= curvemapping_evaluateF(cumap, 2, curvemapping_evaluateF(cumap, 3, vecin[2]));
+       vecout[0] = curvemapping_evaluateF(cumap, 0, curvemapping_evaluateF(cumap, 3, vecin[0]));
+       vecout[1] = curvemapping_evaluateF(cumap, 1, curvemapping_evaluateF(cumap, 3, vecin[1]));
+       vecout[2] = curvemapping_evaluateF(cumap, 2, curvemapping_evaluateF(cumap, 3, vecin[2]));
 }
 
 
@@ -728,14 +728,14 @@ void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float vecout[3], cons
 {
        float fac;
        
-       fac= (vecin[0] - cumap->black[0])*cumap->bwmul[0];
-       vecout[0]= curvemap_evaluateF(cumap->cm, fac);
+       fac = (vecin[0] - cumap->black[0]) * cumap->bwmul[0];
+       vecout[0] = curvemap_evaluateF(cumap->cm, fac);
        
-       fac= (vecin[1] - cumap->black[1])*cumap->bwmul[1];
-       vecout[1]= curvemap_evaluateF(cumap->cm+1, fac);
+       fac = (vecin[1] - cumap->black[1]) * cumap->bwmul[1];
+       vecout[1] = curvemap_evaluateF(cumap->cm + 1, fac);
        
-       fac= (vecin[2] - cumap->black[2])*cumap->bwmul[2];
-       vecout[2]= curvemap_evaluateF(cumap->cm+2, fac);
+       fac = (vecin[2] - cumap->black[2]) * cumap->bwmul[2];
+       vecout[2] = curvemap_evaluateF(cumap->cm + 2, fac);
 }
 
 
@@ -746,14 +746,14 @@ void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf)
        int pixel;
        float *pix_in;
        float col[3];
-       int stride= 4;
+       int stride = 4;
        float *pix_out;
        
-       if (ibuf==NULL)
+       if (ibuf == NULL)
                return;
-       if (ibuf->rect_float==NULL)
+       if (ibuf->rect_float == NULL)
                IMB_float_from_rect(ibuf);
-       else if (ibuf->rect==NULL)
+       else if (ibuf->rect == NULL)
                imb_addrectImBuf(ibuf);
        
        if (!ibuf->rect || !ibuf->rect_float)
@@ -765,27 +765,27 @@ void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf)
        
        curvemapping_premultiply(cumap, 0);
        
-       pix_in= ibuf->rect_float;
-       pix_out= tmpbuf->rect_float;
+       pix_in = ibuf->rect_float;
+       pix_out = tmpbuf->rect_float;
 
        if (ibuf->channels)
-               stride= ibuf->channels;
+               stride = ibuf->channels;
        
-       for (pixel= ibuf->x*ibuf->y; pixel>0; pixel--, pix_in+=stride, pix_out+=stride) {
-               if (stride<3) {
-                       col[0]= curvemap_evaluateF(cumap->cm, *pix_in);
+       for (pixel = ibuf->x * ibuf->y; pixel > 0; pixel--, pix_in += stride, pix_out += stride) {
+               if (stride < 3) {
+                       col[0] = curvemap_evaluateF(cumap->cm, *pix_in);
                        
-                       pix_out[1]= pix_out[2]= pix_out[3]= pix_out[0]= col[0];
+                       pix_out[1] = pix_out[2] = pix_out[3] = pix_out[0] = col[0];
                }
                else {
                        curvemapping_evaluate_premulRGBF(cumap, col, pix_in);
-                       pix_out[0]= col[0];
-                       pix_out[1]= col[1];
-                       pix_out[2]= col[2];
-                       if (stride>3)
-                               pix_out[3]= pix_in[3];
+                       pix_out[0] = col[0];
+                       pix_out[1] = col[1];
+                       pix_out[2] = col[2];
+                       if (stride > 3)
+                               pix_out[3] = pix_in[3];
                        else
-                               pix_out[3]= 1.f;
+                               pix_out[3] = 1.f;
                }
        }
        
@@ -800,16 +800,16 @@ int curvemapping_RGBA_does_something(CurveMapping *cumap)
 {
        int a;
        
-       if (cumap->black[0]!=0.0f) return 1;
-       if (cumap->black[1]!=0.0f) return 1;
-       if (cumap->black[2]!=0.0f) return 1;
-       if (cumap->white[0]!=1.0f) return 1;
-       if (cumap->white[1]!=1.0f) return 1;
-       if (cumap->white[2]!=1.0f) return 1;
+       if (cumap->black[0] != 0.0f) return 1;
+       if (cumap->black[1] != 0.0f) return 1;
+       if (cumap->black[2] != 0.0f) return 1;
+       if (cumap->white[0] != 1.0f) return 1;
+       if (cumap->white[1] != 1.0f) return 1;
+       if (cumap->white[2] != 1.0f) return 1;
        
-       for (a=0; a<CM_TOT; a++) {
+       for (a = 0; a < CM_TOT; a++) {
                if (cumap->cm[a].curve) {
-                       if (cumap->cm[a].totpoint!=2)  return 1;
+                       if (cumap->cm[a].totpoint != 2) return 1;
                        
                        if (cumap->cm[a].curve[0].x != 0.0f) return 1;
                        if (cumap->cm[a].curve[0].y != 0.0f) return 1;
@@ -824,11 +824,11 @@ void curvemapping_initialize(CurveMapping *cumap)
 {
        int a;
        
-       if (cumap==NULL) return;
+       if (cumap == NULL) return;
        
-       for (a=0; a<CM_TOT; a++) {
-               if (cumap->cm[a].table==NULL)
-                       curvemap_make_table(cumap->cm+a, &cumap->clipr);
+       for (a = 0; a < CM_TOT; a++) {
+               if (cumap->cm[a].table == NULL)
+                       curvemap_make_table(cumap->cm + a, &cumap->clipr);
        }
 }
 
@@ -836,29 +836,29 @@ void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size)
 {
        int a;
        
-       *size = CM_TABLE+1;
-       *array = MEM_callocN(sizeof(float)*(*size)*4, "CurveMapping");
+       *size = CM_TABLE + 1;
+       *array = MEM_callocN(sizeof(float) * (*size) * 4, "CurveMapping");
        curvemapping_initialize(cumap);
 
-       for (a=0; a<*size; a++) {
+       for (a = 0; a < *size; a++) {
                if (cumap->cm[0].table)
-                       (*array)[a*4+0]= cumap->cm[0].table[a].y;
+                       (*array)[a * 4 + 0] = cumap->cm[0].table[a].y;
                if (cumap->cm[1].table)
-                       (*array)[a*4+1]= cumap->cm[1].table[a].y;
+                       (*array)[a * 4 + 1] = cumap->cm[1].table[a].y;
                if (cumap->cm[2].table)
-                       (*array)[a*4+2]= cumap->cm[2].table[a].y;
+                       (*array)[a * 4 + 2] = cumap->cm[2].table[a].y;
                if (cumap->cm[3].table)
-                       (*array)[a*4+3]= cumap->cm[3].table[a].y;
+                       (*array)[a * 4 + 3] = cumap->cm[3].table[a].y;
        }
 }
 
 /* ***************** Histogram **************** */
 
-#define INV_255                (1.f/255.f)
+#define INV_255     (1.f / 255.f)
 
 DO_INLINE int get_bin_float(float f)
 {
-       int bin= (int)((f*255.0f) + 0.5f);      /* 0.5 to prevent quantisation differences */
+       int bin = (int)((f * 255.0f) + 0.5f);  /* 0.5 to prevent quantisation differences */
 
        /* note: clamp integer instead of float to avoid problems with NaN */
        CLAMP(bin, 0, 255);
@@ -907,17 +907,17 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
        int x, y, c;
        unsigned int n, nl;
        double div, divl;
-       float *rf=NULL;
-       unsigned char *rc=NULL;
+       float *rf = NULL;
+       unsigned char *rc = NULL;
        unsigned int *bin_r, *bin_g, *bin_b, *bin_lum;
        int savedlines, saveline;
        float rgb[3], ycc[3], luma;
-       int ycc_mode=-1;
+       int ycc_mode = -1;
        const short is_float = (ibuf->rect_float != NULL);
 
-       if (ibuf->rect==NULL && ibuf->rect_float==NULL) return;
+       if (ibuf->rect == NULL && ibuf->rect_float == NULL) return;
 
-       if (scopes->ok == 1 ) return;
+       if (scopes->ok == 1) return;
 
        if (scopes->hist.ymax == 0.f) scopes->hist.ymax = 1.f;
 
@@ -950,19 +950,19 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
        bin_lum = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
 
        /* convert to number of lines with logarithmic scale */
-       scopes->sample_lines = (scopes->accuracy*0.01f) * (scopes->accuracy*0.01f) * ibuf->y;
+       scopes->sample_lines = (scopes->accuracy * 0.01f) * (scopes->accuracy * 0.01f) * ibuf->y;
        
        if (scopes->sample_full)
                scopes->sample_lines = ibuf->y;
 
        /* scan the image */
-       savedlines=0;
-       for (c=0; c<3; c++) {
-               scopes->minmax[c][0]=25500.0f;
-               scopes->minmax[c][1]=-25500.0f;
+       savedlines = 0;
+       for (c = 0; c < 3; c++) {
+               scopes->minmax[c][0] = 25500.0f;
+               scopes->minmax[c][1] = -25500.0f;
        }
        
-       scopes->waveform_tot = ibuf->x*scopes->sample_lines;
+       scopes->waveform_tot = ibuf->x * scopes->sample_lines;
        
        if (scopes->waveform_1)
                MEM_freeN(scopes->waveform_1);
@@ -973,10 +973,10 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
        if (scopes->vecscope)
                MEM_freeN(scopes->vecscope);
        
-       scopes->waveform_1= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 1");
-       scopes->waveform_2= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 2");
-       scopes->waveform_3= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 3");
-       scopes->vecscope= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "vectorscope point channel");
+       scopes->waveform_1 = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 1");
+       scopes->waveform_2 = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 2");
+       scopes->waveform_3 = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 3");
+       scopes->vecscope = MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "vectorscope point channel");
        
        if (is_float)
                rf = ibuf->rect_float;
@@ -984,7 +984,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
                rc = (unsigned char *)ibuf->rect;
 
        for (y = 0; y < ibuf->y; y++) {
-               if (savedlines<scopes->sample_lines && y>=((savedlines)*ibuf->y)/(scopes->sample_lines+1)) {
+               if (savedlines < scopes->sample_lines && y >= ((savedlines) * ibuf->y) / (scopes->sample_lines + 1)) {
                        saveline = 1;
                }
                else {
@@ -999,7 +999,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
                                        copy_v3_v3(rgb, rf);
                        }
                        else {
-                               for (c=0; c<3; c++)
+                               for (c = 0; c < 3; c++)
                                        rgb[c] = rc[c] * INV_255;
                        }
 
@@ -1007,44 +1007,44 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
                        luma = rgb_to_luma(rgb);
 
                        /* check for min max */
-                       if (ycc_mode == -1 ) {
-                               for (c=0; c<3; c++) {
+                       if (ycc_mode == -1) {
+                               for (c = 0; c < 3; c++) {
                                        if (rgb[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgb[c];
                                        if (rgb[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgb[c];
                                }
                        }
                        else {
                                rgb_to_ycc(rgb[0], rgb[1], rgb[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode);
-                               for (c<