summarylogtreecommitdiffstats
path: root/oiio2.patch
blob: 4bbc7ed6d84779cd409f18b7735d1a000f92b363 (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
From 8873abf4abeb5b0e7f832c862dcc7bd3c4204b78 Mon Sep 17 00:00:00 2001
From: Luis Barrancos <luisbarrancos@users.noreply.github.com>
Date: Tue, 29 Jan 2019 20:13:59 +0800
Subject: [PATCH] Initial OIIO 2 support

`ImageInput`'s and `ImageOutput`'s static `create()` and `open()` methods now return
`std::unique_ptr` rather than raw pointers, and OpenVDB is now read via `texture3d()`.

It also brings us the gradients needed for bump2roughness. Notes at https://github.com/OpenImageIO/oiio/releases/tag/Release-2.0.3
---
 .../image/genericimagefilewriter.cpp          | 62 +++++++++++--------
 .../foundation/image/genericimagefilewriter.h |  4 +-
 .../genericprogressiveimagefilereader.cpp     | 15 +++--
 3 files changed, 48 insertions(+), 33 deletions(-)

diff --git a/src/appleseed/foundation/image/genericimagefilewriter.cpp b/src/appleseed/foundation/image/genericimagefilewriter.cpp
index b7668c9bb..dcc718b78 100644
--- a/src/appleseed/foundation/image/genericimagefilewriter.cpp
+++ b/src/appleseed/foundation/image/genericimagefilewriter.cpp
@@ -43,6 +43,9 @@
 // Boost headers.
 #include "boost/filesystem/path.hpp"
 
+// OIIO headers.
+#include "OpenImageIO/version.h"
+
 // Standard headers.
 #include <algorithm>
 #include <cstring>
@@ -55,8 +58,14 @@ namespace foundation
 
 struct GenericImageFileWriter::Impl
 {
-    std::vector<const ICanvas*>     m_canvas;
-    std::vector<OIIO::ImageSpec>    m_spec;
+    const char*                         m_filename;
+#if OIIO_VERSION >= 20000
+    std::unique_ptr<OIIO::ImageOutput>  m_writer;
+#else
+    OIIO::ImageOutput*                  m_writer;
+#endif
+    std::vector<const ICanvas*>         m_canvas;
+    std::vector<OIIO::ImageSpec>        m_spec;
 };
 
 GenericImageFileWriter::GenericImageFileWriter(const char* filename) :
@@ -65,10 +74,10 @@ GenericImageFileWriter::GenericImageFileWriter(const char* filename) :
 {
     assert(filename);
 
-    m_filename = filename;
+    impl->m_filename = filename;
+    impl->m_writer   = OIIO::ImageOutput::create(impl->m_filename);
 
-    m_writer = OIIO::ImageOutput::create(m_filename);
-    if (m_writer == nullptr)
+    if (impl->m_writer == nullptr)
     {
         const std::string msg = OIIO::geterror();
         throw ExceptionIOError(msg.c_str());
@@ -77,9 +86,10 @@ GenericImageFileWriter::GenericImageFileWriter(const char* filename) :
 
 GenericImageFileWriter::~GenericImageFileWriter()
 {
-    // Destroy the ImageOutput stucture.
-    if (m_writer != nullptr)
-        OIIO::ImageOutput::destroy(m_writer);
+#if OIIO_VERSION < 20000
+    if (impl->m_writer != nullptr)
+        OIIO::ImageOutput::destroy(impl->m_writer);
+#endif
 
     delete impl;
 }
@@ -170,7 +180,7 @@ void GenericImageFileWriter::set_image_spec()
     spec.full_y = spec.y;
 
     // Size of a tile.
-    if (m_writer->supports("tiles"))
+    if (impl->m_writer->supports("tiles"))
     {
         spec.tile_width = static_cast<int>(props.m_tile_width);
         spec.tile_height = static_cast<int>(props.m_tile_height);
@@ -186,7 +196,7 @@ void GenericImageFileWriter::set_image_spec()
     set_image_channels(props.m_channel_count, channel_names);
 
     // Format of the pixel data.
-    const boost::filesystem::path filepath(m_filename);
+    const boost::filesystem::path filepath(impl->m_filename);
     const std::string extension = lower_case(filepath.extension().string());
 
     set_image_output_format(props.m_pixel_format);
@@ -292,7 +302,7 @@ void GenericImageFileWriter::set_image_attributes(const ImageAttributes& image_a
     assert(!impl->m_spec.empty());
 
     // Retrieve filename extension.
-    const boost::filesystem::path filepath(m_filename);
+    const boost::filesystem::path filepath(impl->m_filename);
     const std::string extension = lower_case(filepath.extension().string());
 
     // General image attributes.
@@ -340,7 +350,7 @@ void GenericImageFileWriter::write_tiles(const size_t image_index)
             const Tile& tile = canvas->tile(tile_x, tile_y);
 
             // Write the tile into the file.
-            if (!m_writer->write_tile(
+            if (!impl->m_writer->write_tile(
                     static_cast<int>(tile_offset_x),
                     static_cast<int>(tile_offset_y),
                     0,
@@ -349,7 +359,7 @@ void GenericImageFileWriter::write_tiles(const size_t image_index)
                     xstride,
                     ystride))
             {
-                const std::string msg = m_writer->geterror();
+                const std::string msg = impl->m_writer->geterror();
                 close_file();
                 throw ExceptionIOError(msg.c_str());
             }
@@ -406,14 +416,14 @@ void GenericImageFileWriter::write_scanlines(const size_t image_index)
         const size_t y_end = y_begin + props.m_tile_height;
 
         // Write scanline into the file.
-        if (!m_writer->write_scanlines(
+        if (!impl->m_writer->write_scanlines(
                 static_cast<int>(y_begin), 
                 static_cast<int>(y_end), 
                 0, 
                 convert_pixel_format(props.m_pixel_format),
                 buffer_ptr))
         {
-            const std::string msg = m_writer->geterror();
+            const std::string msg = impl->m_writer->geterror();
             close_file();
             throw ExceptionIOError(msg.c_str());
         }
@@ -424,7 +434,7 @@ void GenericImageFileWriter::write(const size_t image_index)
 {
     assert(image_index < impl->m_canvas.size());
 
-    if (m_writer->supports("tiles"))
+    if (impl->m_writer->supports("tiles"))
         write_tiles(image_index);
     else
         write_scanlines(image_index);
@@ -432,9 +442,9 @@ void GenericImageFileWriter::write(const size_t image_index)
 
 void GenericImageFileWriter::write_single_image()
 {
-    if (!m_writer->open(m_filename, impl->m_spec.back()))
+    if (!impl->m_writer->open(impl->m_filename, impl->m_spec.back()))
     {
-        const std::string msg = m_writer->geterror();
+        const std::string msg = impl->m_writer->geterror();
         throw ExceptionIOError(msg.c_str());
     }
 
@@ -447,12 +457,12 @@ void GenericImageFileWriter::write_single_image()
 
 void GenericImageFileWriter::write_multi_images()
 {
-    if (!m_writer->supports("multiimage"))
+    if (!impl->m_writer->supports("multiimage"))
         throw ExceptionIOError("File format is unable to write multiple images");
 
-    if (!m_writer->open(m_filename, static_cast<int>(get_image_count()), impl->m_spec.data()))
+    if (!impl->m_writer->open(impl->m_filename, static_cast<int>(get_image_count()), impl->m_spec.data()))
     {
-        const std::string msg = m_writer->geterror();
+        const std::string msg = impl->m_writer->geterror();
         throw ExceptionIOError(msg.c_str());
     }
     
@@ -460,9 +470,9 @@ void GenericImageFileWriter::write_multi_images()
     {
         if (i > 0)
         {
-            if (!m_writer->open(m_filename, impl->m_spec[i], OIIO::ImageOutput::AppendSubimage))
+            if (!impl->m_writer->open(impl->m_filename, impl->m_spec[i], OIIO::ImageOutput::AppendSubimage))
             {
-                const std::string msg = m_writer->geterror();
+                const std::string msg = impl->m_writer->geterror();
                 close_file();
                 throw ExceptionIOError(msg.c_str());
             }
@@ -495,10 +505,12 @@ void GenericImageFileWriter::write()
 
 void GenericImageFileWriter::close_file()
 {
+    assert(impl->m_writer);
+
     // Close the image file.
-    if (!m_writer->close())
+    if (!impl->m_writer->close())
     {
-        const std::string msg = m_writer->geterror();
+        const std::string msg = impl->m_writer->geterror();
         throw ExceptionIOError(msg.c_str());
     }
 }
diff --git a/src/appleseed/foundation/image/genericimagefilewriter.h b/src/appleseed/foundation/image/genericimagefilewriter.h
index 2c46ed3ea..02a650e6b 100644
--- a/src/appleseed/foundation/image/genericimagefilewriter.h
+++ b/src/appleseed/foundation/image/genericimagefilewriter.h
@@ -38,6 +38,7 @@
 // OpenImageIO headers.
 #include "foundation/platform/_beginoiioheaders.h"
 #include "OpenImageIO/imageio.h"
+#include "OpenImageIO/version.h"
 #include "foundation/platform/_endoiioheaders.h"
 
 // Forward declarations.
@@ -91,9 +92,6 @@ class APPLESEED_DLLSYMBOL GenericImageFileWriter
   private:
     struct Impl;
     Impl* impl;
-
-    OIIO::ImageOutput*  m_writer;
-    const char*         m_filename;
 };
 
 }   // namespace foundation
diff --git a/src/appleseed/foundation/image/genericprogressiveimagefilereader.cpp b/src/appleseed/foundation/image/genericprogressiveimagefilereader.cpp
index 1196cabcb..eac17a782 100644
--- a/src/appleseed/foundation/image/genericprogressiveimagefilereader.cpp
+++ b/src/appleseed/foundation/image/genericprogressiveimagefilereader.cpp
@@ -43,6 +43,7 @@
 #include "OpenImageIO/imageio.h"
 #include "OpenImageIO/paramlist.h"
 #include "OpenImageIO/typedesc.h"
+#include "OpenImageIO/version.h"
 #include "foundation/platform/_endoiioheaders.h"
 
 // Standard headers.
@@ -65,7 +66,13 @@ struct GenericProgressiveImageFileReader::Impl
 {
     Logger*                                 m_logger;
     string                                  m_filename;
+
+#if OIIO_VERSION < 20000
     OIIO::ImageInput*                       m_input;
+#else
+    std::unique_ptr<OIIO::ImageInput>       m_input;
+#endif
+
     bool                                    m_supports_random_access;
     bool                                    m_is_tiled;
     CanvasProperties                        m_props;
@@ -173,11 +180,9 @@ void GenericProgressiveImageFileReader::close()
 
     impl->m_input->close();
 
-    // todo: we should really be calling OIIO::ImageInput::destroy(impl->m_input)
-    // but OpenImageIO 1.5.20 (the version included in appleseed-deps at the time
-    // of writing) is too old to have this method. Since on Windows we link to
-    // OpenImageIO statically, this should be safe anyway.
-    delete impl->m_input;
+#if OIIO_VERSION < 20000
+    OIIO::ImageInput::destroy(impl->m_input);
+#endif
 
     impl->m_input = nullptr;
 }
-- 
2.22.0