Commit: b1cdf58286b577b7e76ed012bec9868d935be753
Author: Nicholas Bishop
Date: Fri Jan 16 12:11:28 2015 +0100
Branches: cycles-ptex-49
https://developer.blender.org/rBb1cdf58286b577b7e76ed012bec9868d935be753
Add API for packing Ptex faces into a single large image
TODO: this is much smaller now than before, can probably be moved to
better spot
===================================================================
M build_files/cmake/macros.cmake
M extern/CMakeLists.txt
M extern/SConscript
A extern/ptex/BPX_pack.h
A extern/ptex/CMakeLists.txt
A extern/ptex/SConscript
A extern/ptex/bpx_c_api.cpp
A extern/ptex/ptex_packed_layout.h
M intern/cycles/SConscript
===================================================================
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 056241b..f8ee3f1 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -575,6 +575,7 @@ macro(SETUP_BLENDER_SORTED_LIBS)
extern_libmv
extern_glog
extern_sdlew
+ extern_ptex
bf_intern_glew_mx
)
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 0ea8aa1..7284f76 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -94,3 +94,7 @@ endif()
if(WITH_SDL AND WITH_SDL_DYNLOAD)
add_subdirectory(sdlew)
endif()
+
+# if(WITH_PTEX)
+ add_subdirectory(ptex)
+# endif()
\ No newline at end of file
diff --git a/extern/SConscript b/extern/SConscript
index 1f94f50..7796732 100644
--- a/extern/SConscript
+++ b/extern/SConscript
@@ -12,6 +12,8 @@ SConscript(['rangetree/SConscript'])
SConscript(['wcwidth/SConscript'])
SConscript(['libmv/SConscript'])
+SConscript(['ptex/SConscript'])
+
if env['WITH_BF_GAMEENGINE']:
SConscript(['recastnavigation/SConscript'])
diff --git a/extern/ptex/BPX_pack.h b/extern/ptex/BPX_pack.h
new file mode 100644
index 0000000..f563a8e
--- /dev/null
+++ b/extern/ptex/BPX_pack.h
@@ -0,0 +1,151 @@
+#ifndef __BPX_PACK_H__
+#define __BPX_PACK_H__
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+/* BPX is short for Blender Ptex */
+
+/* TODO(nicholasbishop): merge some bits of bl_pack.h */
+
+/* TODO(nicholasbishop): more comments and organization */
+
+typedef struct BPXImageBuf BPXImageBuf;
+typedef struct BPXImageInput BPXImageInput;
+
+typedef struct {
+ int xbegin;
+ int ybegin;
+ int xend;
+ int yend;
+} BPXRect;
+
+/*
+ * 01______11
+ * | |
+ * | |
+ * |______|
+ * 00 10
+ */
+typedef enum {
+ BPX_SIDE_BOTTOM = 0, /* 00 -> 10 */
+ BPX_SIDE_RIGHT = 1, /* 10 -> 11 */
+ BPX_SIDE_TOP = 2, /* 11 -> 01 */
+ BPX_SIDE_LEFT = 3, /* 01 -> 00 */
+
+ BPX_NUM_SIDES = 4
+} BPXSide;
+
+typedef struct {
+ BPXSide side;
+ bool reverse;
+} BPXEdge;
+
+/* TODO(nicholasbishop): Ptex file format can also contain 16-bit
+ * integers and floats, nice to add at some point */
+typedef enum {
+ BPX_TYPE_DESC_UINT8,
+ BPX_TYPE_DESC_FLOAT
+} BPXTypeDesc;
+
+/* Allocate an empty BPXImageBuf
+ *
+ * Return NULL on failure.
+ *
+ * When no longer needed the BPXImageBuf should be deallocated with
+ * BPX_image_buf_free(). */
+BPXImageBuf *BPX_image_buf_alloc_empty(void);
+
+/* Allocate a BPXImageBuf to wrap existing image data
+ *
+ * Return NULL on failure.
+ *
+ * Note that BPXImageBuf does not take ownership of the pixels
+ * pointer. It also does not make a copy of the data, so the original
+ * pixels must stay valid until the BPXImageBuf is freed.
+ *
+ * When no longer needed the BPXImageBuf should be deallocated with
+ * BPX_image_buf_free(). */
+BPXImageBuf *BPX_image_buf_wrap(int width, int height, int num_channels,
+ BPXTypeDesc
type_desc, void *pixels);
+
+/* Deallocate a BPXImageBuf */
+void BPX_image_buf_free(BPXImageBuf *buf);
+
+/* Copy all of the source into the destination
+ *
+ * The copy is placed at origin (x, y) in the destination.
+ *
+ * Return true on success, false otherwise. */
+bool BPX_image_buf_pixels_copy(BPXImageBuf *dst, const BPXImageBuf *src,
+ int x, int y);
+
+/* Copy a rectangle from source into the destination
+ *
+ * The copy is placed at origin (x, y) in the destination.
+ *
+ * Return true on success, false otherwise. */
+bool BPX_image_buf_pixels_copy_partial(BPXImageBuf *dst, const BPXImageBuf
*src,
+ int x, int y, const
BPXRect *src_rect);
+
+/* Allocate a BPXImageInput with the given filepath
+ *
+ * Return NULL on failure.
+ *
+ * When no longer needed the BPXImageInput should be deallocated with
+ * BPX_image_input_free(). */
+BPXImageInput *BPX_image_input_from_filepath(const char filepath[]);
+
+/* Deallocate a BPXImageInput */
+void BPX_image_input_free(BPXImageInput *input);
+
+bool BPX_image_input_type_desc(const BPXImageInput *input,
+ BPXTypeDesc
*type_desc);
+
+bool BPX_image_input_num_channels(const BPXImageInput *input,
+ int
*num_channels);
+
+bool BPX_image_input_seek_subimage(BPXImageInput *input, const int subimage,
+ int *width,
int *height);
+
+bool BPX_image_input_read(BPXImageBuf *bpx_dst, BPXImageInput *bpx_src);
+
+bool BPX_rect_borders_update(BPXImageBuf *bpx_buf,
+ const BPXRect
*dst_rect,
+ const BPXRect
src_rect[BPX_NUM_SIDES],
+ const BPXEdge
src_edge[BPX_NUM_SIDES]);
+
+bool BPX_image_buf_quad_split(BPXImageBuf *dst[4], const BPXImageBuf *src);
+
+bool TODO_test_write(BPXImageBuf *bpx_buf, const char *path);
+
+bool BPX_image_buf_transform(BPXImageBuf *bpx_buf);
+
+int BPX_packed_layout_num_regions(const struct PtexPackedLayout *layout);
+
+typedef BPXImageBuf* (*BPXImageBufFromLayout)
+ (const struct PtexPackedLayout *layout, void *context);
+
+BPXImageBuf *BPX_image_buf_ptex_pack(BPXImageInput *bpx_src,
+
BPXImageBufFromLayout dst_create_func,
+ void
*dst_create_context);
+
+// TODO: naming
+struct PtexPackedLayout;
+struct PtexPackedLayout *ptex_packed_layout_new(int count);
+void ptex_packed_layout_add(struct PtexPackedLayout *layout,
+ int u_res, int v_res,
int id);
+void ptex_packed_layout_finalize(struct PtexPackedLayout *layout);
+int ptex_packed_layout_width(const struct PtexPackedLayout *layout);
+int ptex_packed_layout_height(const struct PtexPackedLayout *layout);
+bool ptex_packed_layout_item(const struct PtexPackedLayout *layout,
+ int id, int *x, int *y,
+ int *width, int
*height);
+void ptex_packed_layout_delete(struct PtexPackedLayout *layout);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/extern/ptex/CMakeLists.txt b/extern/ptex/CMakeLists.txt
new file mode 100644
index 0000000..0de6696
--- /dev/null
+++ b/extern/ptex/CMakeLists.txt
@@ -0,0 +1,38 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2006, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Jacques Beaurain.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+)
+
+set(INC_SYS
+)
+
+set(SRC
+ BPX_pack.h
+ bpx_c_api.cpp
+)
+
+blender_add_lib(extern_ptex "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/extern/ptex/SConscript b/extern/ptex/SConscript
new file mode 100644
index 0000000..1ae168d
--- /dev/null
+++ b/extern/ptex/SConscript
@@ -0,0 +1,8 @@
+Import ('env')
+
+sources = env.Glob('*.cpp')
+
+incs = '.'
+defs = ''
+
+env.BlenderLib ('extern_ptex', sources, Split(incs), Split(defs),
libtype=['extern'], priority=[100] )
diff --git a/extern/ptex/bpx_c_api.cpp b/extern/ptex/bpx_c_api.cpp
new file mode 100644
index 0000000..81730de
--- /dev/null
+++ b/extern/ptex/bpx_c_api.cpp
@@ -0,0 +1,1260 @@
+#include <iostream>
+
+#include <OpenImageIO/imagebuf.h>
+#include <OpenImageIO/imagebufalgo.h>
+
+#include "BPX_pack.h"
+#include "ptex_packed_layout.h"
+
+OIIO_NAMESPACE_USING
+
+// TODO
+static const int nthreads = 1;
+
+/* Directed edges (uv1 -> uv2)
+ *
+ * 01______11
+ * | |
+ * | |
+ * |______|
+ * 00 10
+ */
+#if 0
+typedef enum {
+ /* Bottom */
+ BPX_EDGE_00_10 = 0,
+ BPX_EDGE_10_00 = 1,
+
+ /* Right */
+ BPX_EDGE_10_11 = 2,
+ BPX_EDGE_11_10 = 3,
+
+ /* Top */
+ BPX_EDGE_11_01 = 4,
+ BPX_EDGE_01_11 = 5,
+
+ /* Left */
+ BPX_EDGE_01_00 = 6,
+ BPX_EDGE_00_01 = 7,
+} BPXEdge;
+#endif
+
+static TypeDesc bpx_type_desc_to_oiio_type_desc(const BPXTypeDesc type_desc)
+{
+ switch (type_desc) {
+ case BPX_TYPE_DESC_UINT8:
+ return TypeDesc::UINT8;
+
+ case BPX_TYPE_DESC_FLOAT:
+ return TypeDesc::FLOAT;
+ }
+
+ assert(!"Invalid BPXTypeDesc");
+}
+
+static bool bpx_type_desc_from_oiio_type_desc(const TypeDesc src,
+
BPXTypeDesc *dst)
+{
+ if (dst) {
+ if (src == TypeDesc::UINT8) {
+ (*dst) = BPX_TYPE_DESC_UINT8;
+ return true;
+ }
+ else if (src == TypeDesc::FLOAT) {
+ (*dst) = BPX_TYPE_DESC_FLOAT;
+ return true;
+ }
+ }
+ return false;
+}
+
+#define ASSERT_BPX_RECT_VALID(r_) \
+ assert(r_.xbegin >= 0 && r_.xend > r_.xbegin && \
+ r_.ybegin >= 0 && r_.yend > r_.ybegin)
+
+static ROI bpx_rect_to_oiio_roi(const BPXRect &rect)
+{
+ ASSERT_BPX_RECT_VALID(rect);
+
+ return ROI(rect.xbegin, rect.xend, rect.ybegin, rect.yend);
+}
+
+static BPXImageBuf *bpx_image_buf_from_oiio_image_buf(ImageBuf *buf)
+{
+ return reinterpret_cast<BPXImageBuf *>(buf);
+}
+
+static ImageBuf *bpx_image_buf_to_oiio_image_buf(BPXImageBuf *buf)
+{
+ return reinterpret_cast<ImageBuf *>(buf);
+}
+
+static const ImageBuf *bpx_image_buf_to_oiio_image_buf(const BPXImageBuf *buf)
+{
+ return reinterpret_cast<const ImageBuf *>(buf);
+}
+
+static BPXImageInput *bpx_image_input_from_oiio_image_input(ImageInput *in)
+{
+ return reinterpret_cast<BPXImageInput *>(in);
+}
+
+static ImageInput *bpx_image_input_to_oiio_image_input(BPXImageInput *in)
+{
+ return reinterpret_cast<ImageInput *>(in);
+}
+
+static const ImageInput *bpx_image_input_to_oiio_image_input(const
BPXImageInput *in)
+{
+ return reinterpret_cast<const ImageInput *>(in);
+}
+
+BPXImageBuf *BPX_image_buf_alloc_empty(void)
+{
+ return bpx_image_buf_from_oiio_image_buf(new ImageBuf());
+}
+
+BPXImageBuf *BPX_image_buf_wrap(const int width, const int height,
+ const int
num_channels,
+ const
BPXTypeDesc type_desc,
+ void * const
pixels)
+{
+ // TODO
+ const bool r = OIIO::attribute("threads", 1);
+ assert(r);
+
+ if (width > 0 && height > 0 && num_channels > 0 &&
+ (type_desc == BPX_TYPE_DESC_UINT8 ||
+ typ
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs