0004_openimageio.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. commit 6389e1fbc4db6a9d9ee283c93806f8eb5aab26bb
  2. Author: CYBERDEViL <cyberdevil@notabug.org>
  3. Date: Sat Dec 16 16:07:53 2023 +0100
  4. oiio: Build with C++14
  5. commit 6b0a53306d8b6447288fc703bc6721835bf0a92e
  6. Author: CYBERDEViL <cyberdevil@notabug.org>
  7. Date: Sat Dec 16 15:51:05 2023 +0100
  8. oiio: "Build: update CMake to support OpenImageIO 2.3.4"
  9. Fully applied Blender upstream ref: e5100ca3ad17b1b9a40ffd8a8edccb6cb553e558
  10. commit f47f0eb459d739b693043f3980a180b5146fe341
  11. Author: CYBERDEViL <cyberdevil@notabug.org>
  12. Date: Sat Dec 16 15:41:55 2023 +0100
  13. oiio: update on OIIO 2.0 compatibility
  14. commit 97947d9a336da23a984352cdb85cfea23d9a551a
  15. Author: CYBERDEViL <cyberdevil@notabug.org>
  16. Date: Sat Dec 16 15:39:06 2023 +0100
  17. oiio: "Update code to be compatible with OIIO 2.0"
  18. Adjusted Blender upstream ref: 66d8bfb85c61aafe3bad2edf0e7b4d9d694ee2e7
  19. diff --git a/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake b/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake
  20. index e7527f1..39c296e 100644
  21. --- a/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake
  22. +++ b/blender-2.79b/build_files/cmake/Modules/FindOpenImageIO.cmake
  23. @@ -56,6 +56,8 @@ FIND_LIBRARY(OPENIMAGEIO_LIBRARY
  24. lib64 lib
  25. )
  26. +set(_openimageio_LIBRARIES ${OPENIMAGEIO_LIBRARY})
  27. +
  28. FIND_FILE(OPENIMAGEIO_IDIFF
  29. NAMES
  30. idiff
  31. @@ -65,15 +67,49 @@ FIND_FILE(OPENIMAGEIO_IDIFF
  32. bin
  33. )
  34. +# Additionally find util library if needed. In old versions this library was
  35. +# included in libOpenImageIO and linking to both would duplicate symbols. In
  36. +# new versions we need to link to both.
  37. +FIND_FILE(_openimageio_export
  38. + NAMES
  39. + export.h
  40. + PATHS
  41. + ${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO
  42. + NO_DEFAULT_PATH
  43. +)
  44. +
  45. +# Use existence of OIIO_UTIL_API to check if it's a separate lib.
  46. +FILE(STRINGS "${_openimageio_export}" _openimageio_util_define
  47. + REGEX "^[ \t]*#[ \t]*define[ \t]+OIIO_UTIL_API.*$")
  48. +
  49. +IF(_openimageio_util_define)
  50. + FIND_LIBRARY(OPENIMAGEIO_UTIL_LIBRARY
  51. + NAMES
  52. + OpenImageIO_Util
  53. + HINTS
  54. + ${_openimageio_SEARCH_DIRS}
  55. + PATH_SUFFIXES
  56. + lib64 lib
  57. + )
  58. +
  59. + LIST(APPEND _openimageio_LIBRARIES ${OPENIMAGEIO_UTIL_LIBRARY})
  60. +ENDIF()
  61. +
  62. +# In cmake version 3.21 and up, we can instead use the NO_CACHE option for
  63. +# FIND_FILE so we don't need to clear it from the cache here.
  64. +UNSET(_openimageio_export CACHE)
  65. +UNSET(_openimageio_util_define)
  66. +
  67. # handle the QUIETLY and REQUIRED arguments and set OPENIMAGEIO_FOUND to TRUE if
  68. # all listed variables are TRUE
  69. INCLUDE(FindPackageHandleStandardArgs)
  70. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenImageIO DEFAULT_MSG
  71. - OPENIMAGEIO_LIBRARY OPENIMAGEIO_INCLUDE_DIR)
  72. + _openimageio_LIBRARIES OPENIMAGEIO_INCLUDE_DIR)
  73. IF(OPENIMAGEIO_FOUND)
  74. - SET(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARY})
  75. + SET(OPENIMAGEIO_LIBRARIES ${_openimageio_LIBRARIES})
  76. SET(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO_INCLUDE_DIR})
  77. + SET(CMAKE_CXX_STANDARD 14)
  78. IF(EXISTS ${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO/pugixml.hpp)
  79. SET(OPENIMAGEIO_PUGIXML_FOUND TRUE)
  80. ELSE()
  81. @@ -86,7 +122,9 @@ ENDIF()
  82. MARK_AS_ADVANCED(
  83. OPENIMAGEIO_INCLUDE_DIR
  84. OPENIMAGEIO_LIBRARY
  85. + OPENIMAGEIO_UTIL_LIBRARY
  86. OPENIMAGEIO_IDIFF
  87. )
  88. UNSET(_openimageio_SEARCH_DIRS)
  89. +UNSET(_openimageio_LIBRARIES)
  90. diff --git a/blender-2.79b/intern/cycles/blender/blender_python.cpp b/blender-2.79b/intern/cycles/blender/blender_python.cpp
  91. index 54973fd..bee6dd1 100644
  92. --- a/blender-2.79b/intern/cycles/blender/blender_python.cpp
  93. +++ b/blender-2.79b/intern/cycles/blender/blender_python.cpp
  94. @@ -493,7 +493,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
  95. socket_type = "NodeSocketString";
  96. data_type = BL::NodeSocket::type_STRING;
  97. if(param->validdefault)
  98. - default_string = param->sdefault[0];
  99. + default_string = param->sdefault[0].string();
  100. }
  101. else
  102. continue;
  103. diff --git a/blender-2.79b/intern/cycles/graph/node_xml.cpp b/blender-2.79b/intern/cycles/graph/node_xml.cpp
  104. index d26b3b2..2a24104 100644
  105. --- a/blender-2.79b/intern/cycles/graph/node_xml.cpp
  106. +++ b/blender-2.79b/intern/cycles/graph/node_xml.cpp
  107. @@ -250,7 +250,7 @@ void xml_read_node(XMLReader& reader, Node *node, xml_node xml_node)
  108. }
  109. }
  110. - if(node->name)
  111. + if(!node->name.empty())
  112. reader.node_map[node->name] = node;
  113. }
  114. diff --git a/blender-2.79b/intern/cycles/render/buffers.cpp b/blender-2.79b/intern/cycles/render/buffers.cpp
  115. index cf402c3..6df6325 100644
  116. --- a/blender-2.79b/intern/cycles/render/buffers.cpp
  117. +++ b/blender-2.79b/intern/cycles/render/buffers.cpp
  118. @@ -27,6 +27,7 @@
  119. #include "util/util_opengl.h"
  120. #include "util/util_time.h"
  121. #include "util/util_types.h"
  122. +#include "util/util_unique_ptr.h"
  123. CCL_NAMESPACE_BEGIN
  124. @@ -453,7 +454,7 @@ void DisplayBuffer::write(Device *device, const string& filename)
  125. device->pixels_copy_from(rgba, 0, w, h);
  126. /* write image */
  127. - ImageOutput *out = ImageOutput::create(filename);
  128. + unique_ptr<ImageOutput> out(ImageOutput::create(filename));
  129. ImageSpec spec(w, h, 4, TypeDesc::UINT8);
  130. int scanlinesize = w*4*sizeof(uchar);
  131. @@ -467,8 +468,6 @@ void DisplayBuffer::write(Device *device, const string& filename)
  132. AutoStride);
  133. out->close();
  134. -
  135. - delete out;
  136. }
  137. device_memory& DisplayBuffer::rgba_data()
  138. diff --git a/blender-2.79b/intern/cycles/render/image.cpp b/blender-2.79b/intern/cycles/render/image.cpp
  139. index 595eb46..7829df9 100644
  140. --- a/blender-2.79b/intern/cycles/render/image.cpp
  141. +++ b/blender-2.79b/intern/cycles/render/image.cpp
  142. @@ -23,6 +23,7 @@
  143. #include "util/util_path.h"
  144. #include "util/util_progress.h"
  145. #include "util/util_texture.h"
  146. +#include "util/util_unique_ptr.h"
  147. #ifdef WITH_OSL
  148. #include <OSL/oslexec.h>
  149. @@ -148,7 +149,7 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
  150. return IMAGE_DATA_TYPE_BYTE4;
  151. }
  152. - ImageInput *in = ImageInput::create(filename);
  153. + unique_ptr<ImageInput> in(ImageInput::create(filename));
  154. if(in) {
  155. ImageSpec spec;
  156. @@ -194,7 +195,6 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
  157. in->close();
  158. }
  159. - delete in;
  160. }
  161. if(is_half) {
  162. @@ -449,7 +449,7 @@ void ImageManager::tag_reload_image(const string& filename,
  163. }
  164. bool ImageManager::file_load_image_generic(Image *img,
  165. - ImageInput **in,
  166. + unique_ptr<ImageInput> *in,
  167. int &width,
  168. int &height,
  169. int &depth,
  170. @@ -465,7 +465,7 @@ bool ImageManager::file_load_image_generic(Image *img,
  171. }
  172. /* load image from file through OIIO */
  173. - *in = ImageInput::create(img->filename);
  174. + *in = unique_ptr<ImageInput>(ImageInput::create(img->filename));
  175. if(!*in)
  176. return false;
  177. @@ -477,8 +477,6 @@ bool ImageManager::file_load_image_generic(Image *img,
  178. config.attribute("oiio:UnassociatedAlpha", 1);
  179. if(!(*in)->open(img->filename, spec, config)) {
  180. - delete *in;
  181. - *in = NULL;
  182. return false;
  183. }
  184. @@ -500,10 +498,7 @@ bool ImageManager::file_load_image_generic(Image *img,
  185. if(!(components >= 1 && components <= 4)) {
  186. if(*in) {
  187. (*in)->close();
  188. - delete *in;
  189. - *in = NULL;
  190. }
  191. -
  192. return false;
  193. }
  194. @@ -519,7 +514,7 @@ bool ImageManager::file_load_image(Image *img,
  195. device_vector<DeviceType>& tex_img)
  196. {
  197. const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
  198. - ImageInput *in = NULL;
  199. + unique_ptr<ImageInput> in = NULL;
  200. int width, height, depth, components;
  201. if(!file_load_image_generic(img, &in, width, height, depth, components)) {
  202. return false;
  203. @@ -575,7 +570,6 @@ bool ImageManager::file_load_image(Image *img,
  204. }
  205. cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
  206. in->close();
  207. - delete in;
  208. }
  209. else {
  210. if(FileFormat == TypeDesc::FLOAT) {
  211. diff --git a/blender-2.79b/intern/cycles/render/image.h b/blender-2.79b/intern/cycles/render/image.h
  212. index db7e28a..f4a14f4 100644
  213. --- a/blender-2.79b/intern/cycles/render/image.h
  214. +++ b/blender-2.79b/intern/cycles/render/image.h
  215. @@ -23,6 +23,7 @@
  216. #include "util/util_image.h"
  217. #include "util/util_string.h"
  218. #include "util/util_thread.h"
  219. +#include "util/util_unique_ptr.h"
  220. #include "util/util_vector.h"
  221. CCL_NAMESPACE_BEGIN
  222. @@ -133,7 +134,7 @@ private:
  223. bool pack_images;
  224. bool file_load_image_generic(Image *img,
  225. - ImageInput **in,
  226. + unique_ptr<ImageInput> *in,
  227. int &width,
  228. int &height,
  229. int &depth,
  230. diff --git a/blender-2.79b/intern/cycles/util/util_unique_ptr.h b/blender-2.79b/intern/cycles/util/util_unique_ptr.h
  231. new file mode 100644
  232. index 0000000..1ceae73
  233. --- /dev/null
  234. +++ b/blender-2.79b/intern/cycles/util/util_unique_ptr.h
  235. @@ -0,0 +1,28 @@
  236. +/*
  237. + * Copyright 2011-2013 Blender Foundation
  238. + *
  239. + * Licensed under the Apache License, Version 2.0 (the "License");
  240. + * you may not use this file except in compliance with the License.
  241. + * You may obtain a copy of the License at
  242. + *
  243. + * http://www.apache.org/licenses/LICENSE-2.0
  244. + *
  245. + * Unless required by applicable law or agreed to in writing, software
  246. + * distributed under the License is distributed on an "AS IS" BASIS,
  247. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  248. + * See the License for the specific language governing permissions and
  249. + * limitations under the License.
  250. + */
  251. +
  252. +#ifndef __UTIL_UNIQUE_PTR_H__
  253. +#define __UTIL_UNIQUE_PTR_H__
  254. +
  255. +#include <memory>
  256. +
  257. +CCL_NAMESPACE_BEGIN
  258. +
  259. +using std::unique_ptr;
  260. +
  261. +CCL_NAMESPACE_END
  262. +
  263. +#endif /* __UTIL_UNIQUE_PTR_H__ */
  264. 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
  265. index b123d50..c31dc38 100644
  266. --- a/blender-2.79b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
  267. +++ b/blender-2.79b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
  268. @@ -35,6 +35,11 @@
  269. #include "utfconv.h"
  270. #endif
  271. +// NOTE: Keep first, BLI_path_util conflicts with OIIO's format.
  272. +#include <memory>
  273. +#include <openimageio_api.h>
  274. +#include <OpenImageIO/imageio.h>
  275. +
  276. extern "C"
  277. {
  278. #include "MEM_guardedalloc.h"
  279. @@ -48,12 +53,11 @@ extern "C"
  280. #include "IMB_colormanagement_intern.h"
  281. }
  282. -#include <openimageio_api.h>
  283. -#include <OpenImageIO/imageio.h>
  284. OIIO_NAMESPACE_USING
  285. using std::string;
  286. +using std::unique_ptr;
  287. typedef unsigned char uchar;
  288. @@ -197,7 +201,6 @@ int imb_save_photoshop(struct ImBuf *ibuf, const char * /*name*/, int flags)
  289. struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
  290. {
  291. - ImageInput *in = NULL;
  292. struct ImBuf *ibuf = NULL;
  293. int width, height, components;
  294. bool is_float, is_alpha;
  295. @@ -210,7 +213,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
  296. colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
  297. - in = ImageInput::create(filename);
  298. + unique_ptr<ImageInput> in(ImageInput::create(filename));
  299. if (!in) {
  300. std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl
  301. << OIIO_NAMESPACE::geterror() << std::endl;
  302. @@ -223,7 +226,6 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
  303. if (!in->open(filename, spec, config)) {
  304. std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl
  305. << in->geterror() << std::endl;
  306. - delete in;
  307. return NULL;
  308. }
  309. @@ -249,19 +251,17 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
  310. if (!(components >= 1 && components <= 4)) {
  311. if (in) {
  312. in->close();
  313. - delete in;
  314. }
  315. return NULL;
  316. }
  317. if (is_float)
  318. - ibuf = imb_oiio_load_image_float(in, width, height, components, flags, is_alpha);
  319. + ibuf = imb_oiio_load_image_float(in.get(), width, height, components, flags, is_alpha);
  320. else
  321. - ibuf = imb_oiio_load_image(in, width, height, components, flags, is_alpha);
  322. + ibuf = imb_oiio_load_image(in.get(), width, height, components, flags, is_alpha);
  323. if (in) {
  324. in->close();
  325. - delete in;
  326. }
  327. if (!ibuf)