Update code to be compatible with OIIO 2.0

There are some changes in API of OpenImageIO, but those are quite
simple to keep working with older and newer library versions.

Reviewers: brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D4064
This commit is contained in:
Sergey Sharybin
2018-12-11 12:17:26 +01:00
parent 84b02dc54a
commit 66d8bfb85c
7 changed files with 47 additions and 27 deletions

View File

@@ -500,7 +500,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
socket_type = "NodeSocketString"; socket_type = "NodeSocketString";
data_type = BL::NodeSocket::type_STRING; data_type = BL::NodeSocket::type_STRING;
if(param->validdefault) if(param->validdefault)
default_string = param->sdefault[0]; default_string = param->sdefault[0].string();
} }
else else
continue; continue;

View File

@@ -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; reader.node_map[node->name] = node;
} }

View File

@@ -663,7 +663,7 @@ void AttributeRequestSet::add(AttributeRequestSet& reqs)
void AttributeRequestSet::add_standard(ustring name) void AttributeRequestSet::add_standard(ustring name)
{ {
if(!name) { if(name.empty()) {
return; return;
} }

View File

@@ -24,6 +24,7 @@
#include "util/util_path.h" #include "util/util_path.h"
#include "util/util_progress.h" #include "util/util_progress.h"
#include "util/util_texture.h" #include "util/util_texture.h"
#include "util/util_unique_ptr.h"
#ifdef WITH_OSL #ifdef WITH_OSL
#include <OSL/oslexec.h> #include <OSL/oslexec.h>
@@ -194,7 +195,7 @@ bool ImageManager::get_image_metadata(const string& filename,
return false; return false;
} }
ImageInput *in = ImageInput::create(filename); unique_ptr<ImageInput> in(ImageInput::create(filename));
if(!in) { if(!in) {
return false; return false;
@@ -202,7 +203,6 @@ bool ImageManager::get_image_metadata(const string& filename,
ImageSpec spec; ImageSpec spec;
if(!in->open(filename, spec)) { if(!in->open(filename, spec)) {
delete in;
return false; return false;
} }
@@ -270,7 +270,6 @@ bool ImageManager::get_image_metadata(const string& filename,
} }
in->close(); in->close();
delete in;
return true; return true;
} }
@@ -455,7 +454,7 @@ void ImageManager::tag_reload_image(const string& filename,
} }
bool ImageManager::file_load_image_generic(Image *img, bool ImageManager::file_load_image_generic(Image *img,
ImageInput **in) unique_ptr<ImageInput> *in)
{ {
if(img->filename == "") if(img->filename == "")
return false; return false;
@@ -467,7 +466,7 @@ bool ImageManager::file_load_image_generic(Image *img,
} }
/* load image from file through OIIO */ /* load image from file through OIIO */
*in = ImageInput::create(img->filename); *in = unique_ptr<ImageInput>(ImageInput::create(img->filename));
if(!*in) if(!*in)
return false; return false;
@@ -479,8 +478,6 @@ bool ImageManager::file_load_image_generic(Image *img,
config.attribute("oiio:UnassociatedAlpha", 1); config.attribute("oiio:UnassociatedAlpha", 1);
if(!(*in)->open(img->filename, spec, config)) { if(!(*in)->open(img->filename, spec, config)) {
delete *in;
*in = NULL;
return false; return false;
} }
} }
@@ -494,10 +491,7 @@ bool ImageManager::file_load_image_generic(Image *img,
if(!(img->metadata.channels >= 1 && img->metadata.channels <= 4)) { if(!(img->metadata.channels >= 1 && img->metadata.channels <= 4)) {
if(*in) { if(*in) {
(*in)->close(); (*in)->close();
delete *in;
*in = NULL;
} }
return false; return false;
} }
@@ -512,7 +506,7 @@ bool ImageManager::file_load_image(Image *img,
int texture_limit, int texture_limit,
device_vector<DeviceType>& tex_img) device_vector<DeviceType>& tex_img)
{ {
ImageInput *in = NULL; unique_ptr<ImageInput> in = NULL;
if(!file_load_image_generic(img, &in)) { if(!file_load_image_generic(img, &in)) {
return false; return false;
} }
@@ -575,7 +569,6 @@ bool ImageManager::file_load_image(Image *img,
} }
cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4; cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
in->close(); in->close();
delete in;
} }
else { else {
if(FileFormat == TypeDesc::FLOAT) { if(FileFormat == TypeDesc::FLOAT) {

View File

@@ -23,6 +23,7 @@
#include "util/util_image.h" #include "util/util_image.h"
#include "util/util_string.h" #include "util/util_string.h"
#include "util/util_thread.h" #include "util/util_thread.h"
#include "util/util_unique_ptr.h"
#include "util/util_vector.h" #include "util/util_vector.h"
CCL_NAMESPACE_BEGIN CCL_NAMESPACE_BEGIN
@@ -141,8 +142,7 @@ private:
vector<Image*> images[IMAGE_DATA_NUM_TYPES]; vector<Image*> images[IMAGE_DATA_NUM_TYPES];
void *osl_texture_system; void *osl_texture_system;
bool file_load_image_generic(Image *img, bool file_load_image_generic(Image *img, unique_ptr<ImageInput> *in);
ImageInput **in);
template<TypeDesc::BASETYPE FileFormat, template<TypeDesc::BASETYPE FileFormat,
typename StorageType, typename StorageType,

View File

@@ -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__ */

View File

@@ -35,6 +35,11 @@
#include "utfconv.h" #include "utfconv.h"
#endif #endif
// NOTE: Keep first, BLI_path_util conflicts with OIIO's format.
#include <memory>
#include <openimageio_api.h>
#include <OpenImageIO/imageio.h>
extern "C" extern "C"
{ {
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
@@ -48,12 +53,10 @@ extern "C"
#include "IMB_colormanagement_intern.h" #include "IMB_colormanagement_intern.h"
} }
#include <openimageio_api.h>
#include <OpenImageIO/imageio.h>
OIIO_NAMESPACE_USING OIIO_NAMESPACE_USING
using std::string; using std::string;
using std::unique_ptr;
typedef unsigned char uchar; typedef unsigned char uchar;
@@ -197,7 +200,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]) struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
{ {
ImageInput *in = NULL;
struct ImBuf *ibuf = NULL; struct ImBuf *ibuf = NULL;
int width, height, components; int width, height, components;
bool is_float, is_alpha; bool is_float, is_alpha;
@@ -210,7 +212,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); 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) { if (!in) {
std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl
<< OIIO_NAMESPACE::geterror() << std::endl; << OIIO_NAMESPACE::geterror() << std::endl;
@@ -223,7 +225,6 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
if (!in->open(filename, spec, config)) { if (!in->open(filename, spec, config)) {
std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl
<< in->geterror() << std::endl; << in->geterror() << std::endl;
delete in;
return NULL; return NULL;
} }
@@ -249,19 +250,17 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
if (!(components >= 1 && components <= 4)) { if (!(components >= 1 && components <= 4)) {
if (in) { if (in) {
in->close(); in->close();
delete in;
} }
return NULL; return NULL;
} }
if (is_float) 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 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) { if (in) {
in->close(); in->close();
delete in;
} }
if (!ibuf) if (!ibuf)