Cleanup: style, use braces for render
[blender.git] / source / blender / render / intern / source / render_result.c
index e8c27b4..9ca9472 100644 (file)
@@ -62,14 +62,17 @@ static void render_result_views_free(RenderResult *res)
     RenderView *rv = res->views.first;
     BLI_remlink(&res->views, rv);
 
-    if (rv->rect32)
+    if (rv->rect32) {
       MEM_freeN(rv->rect32);
+    }
 
-    if (rv->rectz)
+    if (rv->rectz) {
       MEM_freeN(rv->rectz);
+    }
 
-    if (rv->rectf)
+    if (rv->rectf) {
       MEM_freeN(rv->rectf);
+    }
 
     MEM_freeN(rv);
   }
@@ -79,25 +82,30 @@ static void render_result_views_free(RenderResult *res)
 
 void render_result_free(RenderResult *res)
 {
-  if (res == NULL)
+  if (res == NULL) {
     return;
+  }
 
   while (res->layers.first) {
     RenderLayer *rl = res->layers.first;
 
     /* acolrect and scolrect are optionally allocated in shade_tile,
      * only free here since it can be used for drawing. */
-    if (rl->acolrect)
+    if (rl->acolrect) {
       MEM_freeN(rl->acolrect);
-    if (rl->scolrect)
+    }
+    if (rl->scolrect) {
       MEM_freeN(rl->scolrect);
-    if (rl->display_buffer)
+    }
+    if (rl->display_buffer) {
       MEM_freeN(rl->display_buffer);
+    }
 
     while (rl->passes.first) {
       RenderPass *rpass = rl->passes.first;
-      if (rpass->rect)
+      if (rpass->rect) {
         MEM_freeN(rpass->rect);
+      }
       BLI_remlink(&rl->passes, rpass);
       MEM_freeN(rpass);
     }
@@ -107,16 +115,21 @@ void render_result_free(RenderResult *res)
 
   render_result_views_free(res);
 
-  if (res->rect32)
+  if (res->rect32) {
     MEM_freeN(res->rect32);
-  if (res->rectz)
+  }
+  if (res->rectz) {
     MEM_freeN(res->rectz);
-  if (res->rectf)
+  }
+  if (res->rectf) {
     MEM_freeN(res->rectf);
-  if (res->text)
+  }
+  if (res->text) {
     MEM_freeN(res->text);
-  if (res->error)
+  }
+  if (res->error) {
     MEM_freeN(res->error);
+  }
 
   BKE_stamp_data_free(res->stamp_data);
 
@@ -131,8 +144,9 @@ void render_result_free_list(ListBase *lb, RenderResult *rr)
   for (; rr; rr = rrnext) {
     rrnext = rr->next;
 
-    if (lb && lb->first)
+    if (lb && lb->first) {
       BLI_remlink(lb, rr);
+    }
 
     render_result_free(rr);
   }
@@ -145,8 +159,9 @@ void render_result_views_shallowcopy(RenderResult *dst, RenderResult *src)
 {
   RenderView *rview;
 
-  if (dst == NULL || src == NULL)
+  if (dst == NULL || src == NULL) {
     return;
+  }
 
   for (rview = src->views.first; rview; rview = rview->next) {
     RenderView *rv;
@@ -164,8 +179,9 @@ void render_result_views_shallowcopy(RenderResult *dst, RenderResult *src)
 /* free the views created temporarily */
 void render_result_views_shallowdelete(RenderResult *rr)
 {
-  if (rr == NULL)
+  if (rr == NULL) {
     return;
+  }
 
   while (rr->views.first) {
     RenderView *rv = rr->views.first;
@@ -248,13 +264,15 @@ static RenderPass *render_layer_add_pass(RenderResult *rr,
     if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) {
       /* initialize to max speed */
       rect = rpass->rect;
-      for (x = rectsize - 1; x >= 0; x--)
+      for (x = rectsize - 1; x >= 0; x--) {
         rect[x] = PASS_VECTOR_MAX;
+      }
     }
     else if (STREQ(rpass->name, RE_PASSNAME_Z)) {
       rect = rpass->rect;
-      for (x = rectsize - 1; x >= 0; x--)
+      for (x = rectsize - 1; x >= 0; x--) {
         rect[x] = 10e10;
+      }
     }
   }
 
@@ -288,8 +306,9 @@ RenderResult *render_result_new(Render *re,
   rectx = BLI_rcti_size_x(partrct);
   recty = BLI_rcti_size_y(partrct);
 
-  if (rectx <= 0 || recty <= 0)
+  if (rectx <= 0 || recty <= 0) {
     return NULL;
+  }
 
   rr = MEM_callocN(sizeof(RenderResult), "new render result");
   rr->rectx = rectx;
@@ -342,12 +361,15 @@ RenderResult *render_result_new(Render *re,
     for (rv = rr->views.first; rv; rv = rv->next) {
       const char *view = rv->name;
 
-      if (viewname && viewname[0])
-        if (!STREQ(view, viewname))
+      if (viewname && viewname[0]) {
+        if (!STREQ(view, viewname)) {
           continue;
+        }
+      }
 
-      if (rr->do_exr_tile)
+      if (rr->do_exr_tile) {
         IMB_exr_add_view(rl->exrhandle, view);
+      }
 
 #define RENDER_LAYER_ADD_PASS_SAFE(rr, rl, channels, name, viewname, chan_id) \
   do { \
@@ -360,54 +382,78 @@ RenderResult *render_result_new(Render *re,
       /* a renderlayer should always have a Combined pass*/
       render_layer_add_pass(rr, rl, 4, "Combined", view, "RGBA");
 
-      if (view_layer->passflag & SCE_PASS_Z)
+      if (view_layer->passflag & SCE_PASS_Z) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_Z, view, "Z");
-      if (view_layer->passflag & SCE_PASS_VECTOR)
+      }
+      if (view_layer->passflag & SCE_PASS_VECTOR) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_VECTOR, view, "XYZW");
-      if (view_layer->passflag & SCE_PASS_NORMAL)
+      }
+      if (view_layer->passflag & SCE_PASS_NORMAL) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_NORMAL, view, "XYZ");
-      if (view_layer->passflag & SCE_PASS_UV)
+      }
+      if (view_layer->passflag & SCE_PASS_UV) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_UV, view, "UVA");
-      if (view_layer->passflag & SCE_PASS_EMIT)
+      }
+      if (view_layer->passflag & SCE_PASS_EMIT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_EMIT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_AO)
+      }
+      if (view_layer->passflag & SCE_PASS_AO) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_AO, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_ENVIRONMENT)
+      }
+      if (view_layer->passflag & SCE_PASS_ENVIRONMENT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_ENVIRONMENT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_SHADOW)
+      }
+      if (view_layer->passflag & SCE_PASS_SHADOW) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SHADOW, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_INDEXOB)
+      }
+      if (view_layer->passflag & SCE_PASS_INDEXOB) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_INDEXOB, view, "X");
-      if (view_layer->passflag & SCE_PASS_INDEXMA)
+      }
+      if (view_layer->passflag & SCE_PASS_INDEXMA) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_INDEXMA, view, "X");
-      if (view_layer->passflag & SCE_PASS_MIST)
+      }
+      if (view_layer->passflag & SCE_PASS_MIST) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_MIST, view, "Z");
-      if (rl->passflag & SCE_PASS_RAYHITS)
+      }
+      if (rl->passflag & SCE_PASS_RAYHITS) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_RAYHITS, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_DIFFUSE_DIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_DIFFUSE_DIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_DIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_DIFFUSE_INDIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_DIFFUSE_INDIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_INDIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_DIFFUSE_COLOR)
+      }
+      if (view_layer->passflag & SCE_PASS_DIFFUSE_COLOR) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_COLOR, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_GLOSSY_DIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_GLOSSY_DIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_DIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_GLOSSY_INDIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_GLOSSY_INDIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_INDIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_GLOSSY_COLOR)
+      }
+      if (view_layer->passflag & SCE_PASS_GLOSSY_COLOR) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_COLOR, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_TRANSM_DIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_TRANSM_DIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_DIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_TRANSM_INDIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_TRANSM_INDIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_INDIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_TRANSM_COLOR)
+      }
+      if (view_layer->passflag & SCE_PASS_TRANSM_COLOR) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_COLOR, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_SUBSURFACE_DIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_SUBSURFACE_DIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_DIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_SUBSURFACE_INDIRECT)
+      }
+      if (view_layer->passflag & SCE_PASS_SUBSURFACE_INDIRECT) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_INDIRECT, view, "RGB");
-      if (view_layer->passflag & SCE_PASS_SUBSURFACE_COLOR)
+      }
+      if (view_layer->passflag & SCE_PASS_SUBSURFACE_COLOR) {
         RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_COLOR, view, "RGB");
+      }
 #undef RENDER_LAYER_ADD_PASS_SAFE
     }
   }
@@ -431,12 +477,15 @@ RenderResult *render_result_new(Render *re,
     for (rv = rr->views.first; rv; rv = rv->next) {
       const char *view = rv->name;
 
-      if (viewname && viewname[0])
-        if (strcmp(view, viewname) != 0)
+      if (viewname && viewname[0]) {
+        if (strcmp(view, viewname) != 0) {
           continue;
+        }
+      }
 
-      if (rr->do_exr_tile)
+      if (rr->do_exr_tile) {
         IMB_exr_add_view(rl->exrhandle, view);
+      }
 
       /* a renderlayer should always have a Combined pass */
       render_layer_add_pass(rr, rl, 4, RE_PASSNAME_COMBINED, view, "RGBA");
@@ -504,15 +553,18 @@ void render_result_add_pass(RenderResult *rr,
     for (rv = rr->views.first; rv; rv = rv->next) {
       const char *view = rv->name;
 
-      if (viewname && viewname[0] && !STREQ(view, viewname))
+      if (viewname && viewname[0] && !STREQ(view, viewname)) {
         continue;
+      }
 
       /* Ensure that the pass doesn't exist yet. */
       for (rp = rl->passes.first; rp; rp = rp->next) {
-        if (!STREQ(rp->name, name))
+        if (!STREQ(rp->name, name)) {
           continue;
-        if (!STREQ(rp->view, view))
+        }
+        if (!STREQ(rp->view, view)) {
           continue;
+        }
         break;
       }
 
@@ -649,37 +701,47 @@ static int order_render_passes(const void *a, const void *b)
   unsigned int passtype_b = passtype_from_name(rpb->name);
 
   /* Render passes with default type always go first. */
-  if (passtype_b && !passtype_a)
+  if (passtype_b && !passtype_a) {
     return 1;
-  if (passtype_a && !passtype_b)
+  }
+  if (passtype_a && !passtype_b) {
     return 0;
+  }
 
   if (passtype_a && passtype_b) {
-    if (passtype_a > passtype_b)
+    if (passtype_a > passtype_b) {
       return 1;
-    else if (passtype_a < passtype_b)
+    }
+    else if (passtype_a < passtype_b) {
       return 0;
+    }
   }
   else {
     int cmp = strncmp(rpa->name, rpb->name, EXR_PASS_MAXNAME);
-    if (cmp > 0)
+    if (cmp > 0) {
       return 1;
-    if (cmp < 0)
+    }
+    if (cmp < 0) {
       return 0;
+    }
   }
 
   /* they have the same type */
   /* left first */
-  if (STREQ(rpa->view, STEREO_LEFT_NAME))
+  if (STREQ(rpa->view, STEREO_LEFT_NAME)) {
     return 0;
-  else if (STREQ(rpb->view, STEREO_LEFT_NAME))
+  }
+  else if (STREQ(rpb->view, STEREO_LEFT_NAME)) {
     return 1;
+  }
 
   /* right second */
-  if (STREQ(rpa->view, STEREO_RIGHT_NAME))
+  if (STREQ(rpa->view, STEREO_RIGHT_NAME)) {
     return 0;
-  else if (STREQ(rpb->view, STEREO_RIGHT_NAME))
+  }
+  else if (STREQ(rpb->view, STEREO_RIGHT_NAME)) {
     return 1;
+  }
 
   /* remaining in ascending id order */
   return (rpa->view_id < rpb->view_id);
@@ -743,8 +805,9 @@ void render_result_views_new(RenderResult *rr, RenderData *rd)
   /* check renderdata for amount of views */
   if ((rd->scemode & R_MULTIVIEW)) {
     for (srv = rd->views.first; srv; srv = srv->next) {
-      if (BKE_scene_multiview_is_render_view_active(rd, srv) == false)
+      if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) {
         continue;
+      }
       render_result_view_new(rr, srv->name);
     }
   }
@@ -813,8 +876,9 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart)
       for (rpass = rl->passes.first, rpassp = rlp->passes.first; rpass && rpassp;
            rpass = rpass->next) {
         /* renderresult have all passes, renderpart only the active view's passes */
-        if (strcmp(rpassp->fullname, rpass->fullname) != 0)
+        if (strcmp(rpassp->fullname, rpass->fullname) != 0) {
           continue;
+        }
 
         do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels);
 
@@ -1013,8 +1077,9 @@ void render_result_single_layer_end(Render *re)
     return;
   }
 
-  if (!re->pushedresult)
+  if (!re->pushedresult) {
     return;
+  }
 
   if (re->pushedresult->rectx == re->result->rectx &&
       re->pushedresult->recty == re->result->recty) {
@@ -1242,8 +1307,9 @@ void render_result_exr_file_end(Render *re, RenderEngine *engine)
 /* save part into exr file */
 void render_result_exr_file_merge(RenderResult *rr, RenderResult *rrpart, const char *viewname)
 {
-  for (; rr && rrpart; rr = rr->next, rrpart = rrpart->next)
+  for (; rr && rrpart; rr = rr->next, rrpart = rrpart->next) {
     save_render_result_tile(rr, rrpart, viewname);
+  }
 }
 
 /* path to temporary exr file */
@@ -1282,17 +1348,20 @@ int render_result_exr_file_read_path(RenderResult *rr,
   }
 
   if (rr == NULL || rectx != rr->rectx || recty != rr->recty) {
-    if (rr)
+    if (rr) {
       printf("error in reading render result: dimensions don't match\n");
-    else
+    }
+    else {
       printf("error in reading render result: NULL result pointer\n");
+    }
     IMB_exr_close(exrhandle);
     return 0;
   }
 
   for (rl = rr->layers.first; rl; rl = rl->next) {
-    if (rl_single && rl_single != rl)
+    if (rl_single && rl_single != rl) {
       continue;
+    }
 
     /* passes are allocated in sync */
     for (rpass = rl->passes.first; rpass; rpass = rpass->next) {
@@ -1438,8 +1507,9 @@ void RE_render_result_rect_from_ibuf(RenderResult *rr,
   if (ibuf->rect_float) {
     rr->have_combined = true;
 
-    if (!rv->rectf)
+    if (!rv->rectf) {
       rv->rectf = MEM_mallocN(4 * sizeof(float) * rr->rectx * rr->recty, "render_seq rectf");
+    }
 
     memcpy(rv->rectf, ibuf->rect_float, 4 * sizeof(float) * rr->rectx * rr->recty);
 
@@ -1450,8 +1520,9 @@ void RE_render_result_rect_from_ibuf(RenderResult *rr,
   else if (ibuf->rect) {
     rr->have_combined = true;
 
-    if (!rv->rect32)
+    if (!rv->rect32) {
       rv->rect32 = MEM_mallocN(sizeof(int) * rr->rectx * rr->recty, "render_seq rect");
+    }
 
     memcpy(rv->rect32, ibuf->rect, 4 * rr->rectx * rr->recty);
 
@@ -1464,12 +1535,15 @@ void render_result_rect_fill_zero(RenderResult *rr, const int view_id)
 {
   RenderView *rv = RE_RenderViewGetById(rr, view_id);
 
-  if (rv->rectf)
+  if (rv->rectf) {
     memset(rv->rectf, 0, 4 * sizeof(float) * rr->rectx * rr->recty);
-  else if (rv->rect32)
+  }
+  else if (rv->rect32) {
     memset(rv->rect32, 0, 4 * rr->rectx * rr->recty);
-  else
+  }
+  else {
     rv->rect32 = MEM_callocN(sizeof(int) * rr->rectx * rr->recty, "render_seq rect");
+  }
 }
 
 void render_result_rect_get_pixels(RenderResult *rr,
@@ -1482,9 +1556,10 @@ void render_result_rect_get_pixels(RenderResult *rr,
 {
   RenderView *rv = RE_RenderViewGetById(rr, view_id);
 
-  if (rv->rect32)
+  if (rv->rect32) {
     memcpy(rect, rv->rect32, sizeof(int) * rr->rectx * rr->recty);
-  else if (rv->rectf)
+  }
+  else if (rv->rectf) {
     IMB_display_buffer_transform_apply((unsigned char *)rect,
                                        rv->rectf,
                                        rr->rectx,
@@ -1493,9 +1568,11 @@ void render_result_rect_get_pixels(RenderResult *rr,
                                        view_settings,
                                        display_settings,
                                        true);
-  else
+  }
+  else {
     /* else fill with black */
     memset(rect, 0, sizeof(int) * rectx * recty);
+  }
 }
 
 /*************************** multiview functions *****************************/
@@ -1504,12 +1581,14 @@ bool RE_HasCombinedLayer(RenderResult *res)
 {
   RenderView *rv;
 
-  if (res == NULL)
+  if (res == NULL) {
     return false;
+  }
 
   rv = res->views.first;
-  if (rv == NULL)
+  if (rv == NULL) {
     return false;
+  }
 
   return (rv->rect32 || rv->rectf);
 }