Commit: 0d4dd0df6cfc0e97082faba78d7f05e3e24119d7
Author: Nicholas Bishop
Date:   Wed Feb 11 17:06:39 2015 +0100
Branches: cycles-ptex-49
https://developer.blender.org/rB0d4dd0df6cfc0e97082faba78d7f05e3e24119d7

Code cleanup: use BPXRect in Ptex layout interface

===================================================================

M       extern/ptex/BPX_packed_layout.h
M       extern/ptex/BPX_ptex.h
M       extern/ptex/BPX_rect.h
M       extern/ptex/bpx_c_api.cpp
M       intern/cycles/render/image.cpp
M       source/blender/imbuf/intern/imb_ptex.c

===================================================================

diff --git a/extern/ptex/BPX_packed_layout.h b/extern/ptex/BPX_packed_layout.h
index ad8ea08..082a4c5 100644
--- a/extern/ptex/BPX_packed_layout.h
+++ b/extern/ptex/BPX_packed_layout.h
@@ -5,6 +5,8 @@
 #include <cassert>
 #include <vector>
 
+#include "BPX_rect.h"
+
 // TODO(nicholasbishop): there's a lot of room for improvement
 // here. None of this data is saved to a file, so we should be able to
 // safely improve it to improve performance, decrease memory usage,
diff --git a/extern/ptex/BPX_ptex.h b/extern/ptex/BPX_ptex.h
index 15dcae2..3351637 100644
--- a/extern/ptex/BPX_ptex.h
+++ b/extern/ptex/BPX_ptex.h
@@ -121,8 +121,8 @@ void BPX_packed_layout_finalize(struct BPXPackedLayout 
*layout);
 int BPX_packed_layout_width(const struct BPXPackedLayout *layout);
 int BPX_packed_layout_height(const struct BPXPackedLayout *layout);
 bool BPX_packed_layout_item(const struct BPXPackedLayout *layout,
-                                                       int id, int *x, int *y,
-                                                       int *width, int 
*height);
+                                                       const int index,
+                                                       struct BPXRect *r_rect);
 void BPX_packed_layout_delete(struct BPXPackedLayout *layout);
 
 #ifdef __cplusplus
diff --git a/extern/ptex/BPX_rect.h b/extern/ptex/BPX_rect.h
index 5702265..b3393fe 100644
--- a/extern/ptex/BPX_rect.h
+++ b/extern/ptex/BPX_rect.h
@@ -6,8 +6,9 @@ extern "C"{
 #endif
 
 /* TODO(nicholasbishop): this is yet another 2D integer rect
- * structure. Would be better to reuse rcti. */
+ * structure. Could be nicer to reuse rcti. */
 
+/* Note: begin is inclusive, end is exclusive to match OIIO::ROI */
 typedef struct BPXRect {
        int xbegin;
        int xend;
diff --git a/extern/ptex/bpx_c_api.cpp b/extern/ptex/bpx_c_api.cpp
index 253cc75..19565cc 100644
--- a/extern/ptex/bpx_c_api.cpp
+++ b/extern/ptex/bpx_c_api.cpp
@@ -1239,16 +1239,15 @@ int BPX_packed_layout_height(const BPXPackedLayout * 
const layout)
 }
 
 bool BPX_packed_layout_item(const BPXPackedLayout * const layout,
-                                                        const int item_id, int 
*x, int *y,
-                                                        int *width, int 
*height)
+                                                       const int item_id, 
BPXRect *r_rect)
 {
-       if (layout && x && y && width && height) {
+       if (layout && r_rect) {
                const BPXPackedLayout::Items &items = layout->get_items();
                if (item_id >= 0 && item_id < items.size()) {
-                       (*x) = items[item_id].x;
-                       (*y) = items[item_id].y;
-                       (*width) = items[item_id].u_res;
-                       (*height) = items[item_id].v_res;
+                       r_rect->xbegin = items[item_id].x;
+                       r_rect->ybegin = items[item_id].y;
+                       r_rect->xend = items[item_id].x + items[item_id].u_res;
+                       r_rect->yend = items[item_id].y + items[item_id].v_res;
                        return true;
                }
        }
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 144a837..4cd2124 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -406,12 +406,12 @@ static BPXImageBuf *ptex_pack_uchar_cb(const struct 
BPXPackedLayout *layout,
                                                                                
         width, height, num_regions*4);
 
        for (int i = 0; i < num_regions; i++) {
-               int x, y, w, h;
-               if (BPX_packed_layout_item(layout, i, &x, &y, &w, &h)) {
-                       regions[i][0] = x;
-                       regions[i][1] = y;
-                       regions[i][2] = w;
-                       regions[i][3] = h;
+               BPXRect rect;
+               if (BPX_packed_layout_item(layout, i, &rect)) {
+                       regions[i][0] = rect.xbegin;
+                       regions[i][1] = rect.ybegin;
+                       regions[i][2] = rect.xend - rect.xbegin;
+                       regions[i][3] = rect.yend - rect.ybegin;
                }
                else {
                        // TODO
diff --git a/source/blender/imbuf/intern/imb_ptex.c 
b/source/blender/imbuf/intern/imb_ptex.c
index 622f29a..96a7364 100644
--- a/source/blender/imbuf/intern/imb_ptex.c
+++ b/source/blender/imbuf/intern/imb_ptex.c
@@ -42,10 +42,14 @@ ImBuf *IMB_alloc_from_ptex_layout(const struct 
BPXPackedLayout *layout)
 
                for (i = 0; i < ibuf->num_ptex_regions; i++) {
                        ImPtexRegion *dst_region = &ibuf->ptex_regions[i];
-                       if (!BPX_packed_layout_item(layout, i, &dst_region->x,
-                                                                               
 &dst_region->y, &dst_region->width,
-                                                                               
 &dst_region->height))
-                       {
+                       BPXRect rect;
+                       if (BPX_packed_layout_item(layout, i, &rect)) {
+                               dst_region->x = rect.xbegin;
+                               dst_region->y = rect.ybegin;
+                               dst_region->width = rect.xend - rect.xbegin;
+                               dst_region->height = rect.yend - rect.ybegin;
+                       }
+                       else {
                                /* Error */
                                IMB_freeImBuf(ibuf);
                                return NULL;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to