summarylogtreecommitdiffstats
path: root/0004_openimageio.patch
blob: 0a03919c2eefe802488ce0f7dd3650a599731542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
commit 6389e1fbc4db6a9d9ee283c93806f8eb5aab26bb
Author: CYBERDEViL <cyberdevil@notabug.org>
Date:   Sat Dec 16 16:07:53 2023 +0100

    oiio: Build with C++14

commit 6b0a53306d8b6447288fc703bc6721835bf0a92e
Author: CYBERDEViL <cyberdevil@notabug.org>
Date:   Sat Dec 16 15:51:05 2023 +0100

    oiio: "Build: update CMake to support OpenImageIO 2.3.4"
    
    Fully applied Blender upstream ref: e5100ca3ad17b1b9a40ffd8a8edccb6cb553e558

commit f47f0eb459d739b693043f3980a180b5146fe341
Author: CYBERDEViL <cyberdevil@notabug.org>
Date:   Sat Dec 16 15:41:55 2023 +0100

    oiio: update on OIIO 2.0 compatibility

commit 97947d9a336da23a984352cdb85cfea23d9a551a
Author: CYBERDEViL <cyberdevil@notabug.org>
Date:   Sat Dec 16 15:39:06 2023 +0100

    oiio: "Update code to be compatible with OIIO 2.0"
    
    Adjusted Blender upstream ref: 66d8bfb85c61aafe3bad2edf0e7b4d9d694ee2e7

diff --git a/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake b/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake
index e7527f1..39c296e 100644
--- a/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake
+++ b/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake
@@ -56,6 +56,8 @@ FIND_LIBRARY(OPENIMAGEIO_LIBRARY
     lib64 lib
   )
 
+set(_openimageio_LIBRARIES ${OPENIMAGEIO_LIBRARY})
+
 FIND_FILE(OPENIMAGEIO_IDIFF
   NAMES
     idiff
@@ -65,15 +67,49 @@ FIND_FILE(OPENIMAGEIO_IDIFF
     bin
 )
 
+# Additionally find util library if needed. In old versions this library was
+# included in libOpenImageIO and linking to both would duplicate symbols. In
+# new versions we need to link to both.
+FIND_FILE(_openimageio_export
+  NAMES
+    export.h
+  PATHS
+    ${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO
+  NO_DEFAULT_PATH
+)
+
+# Use existence of OIIO_UTIL_API to check if it's a separate lib.
+FILE(STRINGS "${_openimageio_export}" _openimageio_util_define
+     REGEX "^[ \t]*#[ \t]*define[ \t]+OIIO_UTIL_API.*$")
+
+IF(_openimageio_util_define)
+  FIND_LIBRARY(OPENIMAGEIO_UTIL_LIBRARY
+    NAMES
+      OpenImageIO_Util
+    HINTS
+      ${_openimageio_SEARCH_DIRS}
+    PATH_SUFFIXES
+      lib64 lib
+    )
+
+  LIST(APPEND _openimageio_LIBRARIES ${OPENIMAGEIO_UTIL_LIBRARY})
+ENDIF()
+
+# In cmake version 3.21 and up, we can instead use the NO_CACHE option for
+# FIND_FILE so we don't need to clear it from the cache here.
+UNSET(_openimageio_export CACHE)
+UNSET(_openimageio_util_define)
+
 # handle the QUIETLY and REQUIRED arguments and set OPENIMAGEIO_FOUND to TRUE if 
 # all listed variables are TRUE
 INCLUDE(FindPackageHandleStandardArgs)
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenImageIO DEFAULT_MSG
-    OPENIMAGEIO_LIBRARY OPENIMAGEIO_INCLUDE_DIR)
+    _openimageio_LIBRARIES OPENIMAGEIO_INCLUDE_DIR)
 
 IF(OPENIMAGEIO_FOUND)
-  SET(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARY})
+  SET(OPENIMAGEIO_LIBRARIES ${_openimageio_LIBRARIES})
   SET(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO_INCLUDE_DIR})
+  SET(CMAKE_CXX_STANDARD 14)
   IF(EXISTS ${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO/pugixml.hpp)
     SET(OPENIMAGEIO_PUGIXML_FOUND TRUE)
   ELSE()
@@ -86,7 +122,9 @@ ENDIF()
 MARK_AS_ADVANCED(
   OPENIMAGEIO_INCLUDE_DIR
   OPENIMAGEIO_LIBRARY
+  OPENIMAGEIO_UTIL_LIBRARY
   OPENIMAGEIO_IDIFF
 )
 
 UNSET(_openimageio_SEARCH_DIRS)
+UNSET(_openimageio_LIBRARIES)
diff --git a/blender-2.79b/intern/cycles/blender/blender_python.cpp b/blender-2.79b/intern/cycles/blender/blender_python.cpp
index 54973fd..bee6dd1 100644
--- a/blender-2.79b/intern/cycles/blender/blender_python.cpp
+++ b/blender-2.79b/intern/cycles/blender/blender_python.cpp
@@ -493,7 +493,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
 				socket_type = "NodeSocketString";
 				data_type = BL::NodeSocket::type_STRING;
 				if(param->validdefault)
-					default_string = param->sdefault[0];
+					default_string = param->sdefault[0].string();
 			}
 			else
 				continue;
diff --git a/blender-2.79b/intern/cycles/graph/node_xml.cpp b/blender-2.79b/intern/cycles/graph/node_xml.cpp
index d26b3b2..2a24104 100644
--- a/blender-2.79b/intern/cycles/graph/node_xml.cpp
+++ b/blender-2.79b/intern/cycles/graph/node_xml.cpp
@@ -250,7 +250,7 @@ void xml_read_node(XMLReader& reader, Node *node, xml_node xml_node)
 		}
 	}
 
-	if(node->name)
+	if(!node->name.empty())
 		reader.node_map[node->name] = node;
 }
 
diff --git a/blender-2.79b/intern/cycles/render/buffers.cpp b/blender-2.79b/intern/cycles/render/buffers.cpp
index cf402c3..6df6325 100644
--- a/blender-2.79b/intern/cycles/render/buffers.cpp
+++ b/blender-2.79b/intern/cycles/render/buffers.cpp
@@ -27,6 +27,7 @@
 #include "util/util_opengl.h"
 #include "util/util_time.h"
 #include "util/util_types.h"
+#include "util/util_unique_ptr.h"
 
 CCL_NAMESPACE_BEGIN
 
@@ -453,7 +454,7 @@ void DisplayBuffer::write(Device *device, const string& filename)
 	device->pixels_copy_from(rgba, 0, w, h);
 
 	/* write image */
-	ImageOutput *out = ImageOutput::create(filename);
+	unique_ptr<ImageOutput> out(ImageOutput::create(filename));
 	ImageSpec spec(w, h, 4, TypeDesc::UINT8);
 	int scanlinesize = w*4*sizeof(uchar);
 
@@ -467,8 +468,6 @@ void DisplayBuffer::write(Device *device, const string& filename)
 		AutoStride);
 
 	out->close();
-
-	delete out;
 }
 
 device_memory& DisplayBuffer::rgba_data()
diff --git a/blender-2.79b/intern/cycles/render/image.cpp b/blender-2.79b/intern/cycles/render/image.cpp
index 595eb46..7829df9 100644
--- a/blender-2.79b/intern/cycles/render/image.cpp
+++ b/blender-2.79b/intern/cycles/render/image.cpp
@@ -23,6 +23,7 @@
 #include "util/util_path.h"
 #include "util/util_progress.h"
 #include "util/util_texture.h"
+#include "util/util_unique_ptr.h"
 
 #ifdef WITH_OSL
 #include <OSL/oslexec.h>
@@ -148,7 +149,7 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
 		return IMAGE_DATA_TYPE_BYTE4;
 	}
 
-	ImageInput *in = ImageInput::create(filename);
+	unique_ptr<ImageInput> in(ImageInput::create(filename));
 
 	if(in) {
 		ImageSpec spec;
@@ -194,7 +195,6 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
 			in->close();
 		}
 
-		delete in;
 	}
 
 	if(is_half) {
@@ -449,7 +449,7 @@ void ImageManager::tag_reload_image(const string& filename,
 }
 
 bool ImageManager::file_load_image_generic(Image *img,
-                                           ImageInput **in,
+                                           unique_ptr<ImageInput> *in,
                                            int &width,
                                            int &height,
                                            int &depth,
@@ -465,7 +465,7 @@ bool ImageManager::file_load_image_generic(Image *img,
 		}
 
 		/* load image from file through OIIO */
-		*in = ImageInput::create(img->filename);
+		*in = unique_ptr<ImageInput>(ImageInput::create(img->filename));
 
 		if(!*in)
 			return false;
@@ -477,8 +477,6 @@ bool ImageManager::file_load_image_generic(Image *img,
 			config.attribute("oiio:UnassociatedAlpha", 1);
 
 		if(!(*in)->open(img->filename, spec, config)) {
-			delete *in;
-			*in = NULL;
 			return false;
 		}
 
@@ -500,10 +498,7 @@ bool ImageManager::file_load_image_generic(Image *img,
 	if(!(components >= 1 && components <= 4)) {
 		if(*in) {
 			(*in)->close();
-			delete *in;
-			*in = NULL;
 		}
-
 		return false;
 	}
 
@@ -519,7 +514,7 @@ bool ImageManager::file_load_image(Image *img,
                                    device_vector<DeviceType>& tex_img)
 {
 	const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
-	ImageInput *in = NULL;
+	unique_ptr<ImageInput> in = NULL;
 	int width, height, depth, components;
 	if(!file_load_image_generic(img, &in, width, height, depth, components)) {
 		return false;
@@ -575,7 +570,6 @@ bool ImageManager::file_load_image(Image *img,
 		}
 		cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
 		in->close();
-		delete in;
 	}
 	else {
 		if(FileFormat == TypeDesc::FLOAT) {
diff --git a/blender-2.79b/intern/cycles/render/image.h b/blender-2.79b/intern/cycles/render/image.h
index db7e28a..f4a14f4 100644
--- a/blender-2.79b/intern/cycles/render/image.h
+++ b/blender-2.79b/intern/cycles/render/image.h
@@ -23,6 +23,7 @@
 #include "util/util_image.h"
 #include "util/util_string.h"
 #include "util/util_thread.h"
+#include "util/util_unique_ptr.h"
 #include "util/util_vector.h"
 
 CCL_NAMESPACE_BEGIN
@@ -133,7 +134,7 @@ private:
 	bool pack_images;
 
 	bool file_load_image_generic(Image *img,
-	                             ImageInput **in,
+	                             unique_ptr<ImageInput> *in,
 	                             int &width,
 	                             int &height,
 	                             int &depth,
diff --git a/blender-2.79b/intern/cycles/util/util_unique_ptr.h b/blender-2.79b/intern/cycles/util/util_unique_ptr.h
new file mode 100644
index 0000000..1ceae73
--- /dev/null
+++ b/blender-2.79b/intern/cycles/util/util_unique_ptr.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UTIL_UNIQUE_PTR_H__
+#define __UTIL_UNIQUE_PTR_H__
+
+#include <memory>
+
+CCL_NAMESPACE_BEGIN
+
+using std::unique_ptr;
+
+CCL_NAMESPACE_END
+
+#endif  /* __UTIL_UNIQUE_PTR_H__ */
diff --git a/blender-2.79b/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/blender-2.79b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
index b123d50..c31dc38 100644
--- a/blender-2.79b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
+++ b/blender-2.79b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -35,6 +35,11 @@
 #include "utfconv.h"
 #endif
 
+// NOTE: Keep first, BLI_path_util conflicts with OIIO's format.
+#include <memory>
+#include <openimageio_api.h>
+#include <OpenImageIO/imageio.h>
+
 extern "C"
 {
 #include "MEM_guardedalloc.h"
@@ -48,12 +53,11 @@ extern "C"
 #include "IMB_colormanagement_intern.h"
 }
 
-#include <openimageio_api.h>
-#include <OpenImageIO/imageio.h>
 
 OIIO_NAMESPACE_USING
 
 using std::string;
+using std::unique_ptr;
 
 typedef unsigned char uchar;
 
@@ -197,7 +201,6 @@ int imb_save_photoshop(struct ImBuf *ibuf, const char * /*name*/, int flags)
 
 struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
 {
-	ImageInput *in = NULL;
 	struct ImBuf *ibuf = NULL;
 	int width, height, components;
 	bool is_float, is_alpha;
@@ -210,7 +213,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 
 	colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
 
-	in = ImageInput::create(filename);
+	unique_ptr<ImageInput> in(ImageInput::create(filename));
 	if (!in) {
 		std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl
 		          << OIIO_NAMESPACE::geterror() << std::endl;
@@ -223,7 +226,6 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	if (!in->open(filename, spec, config)) {
 		std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl
 		          << in->geterror() << std::endl;
-		delete in;
 		return NULL;
 	}
 
@@ -249,19 +251,17 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	if (!(components >= 1 && components <= 4)) {
 		if (in) {
 			in->close();
-			delete in;
 		}
 		return NULL;
 	}
 
 	if (is_float)
-		ibuf = imb_oiio_load_image_float(in, width, height, components, flags, is_alpha);
+		ibuf = imb_oiio_load_image_float(in.get(), width, height, components, flags, is_alpha);
 	else
-		ibuf = imb_oiio_load_image(in, width, height, components, flags, is_alpha);
+		ibuf = imb_oiio_load_image(in.get(), width, height, components, flags, is_alpha);
 
 	if (in) {
 		in->close();
-		delete in;
 	}
 
 	if (!ibuf)