Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / render / image.cpp
index 2865b0e5e97c4e02d4ca7bdb941d2166da4fe39c..ea6991172d00949bbc5f367a5f6dfbede774a6a0 100644 (file)
@@ -24,6 +24,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>
@@ -194,7 +195,7 @@ bool ImageManager::get_image_metadata(const string& filename,
                return false;
        }
 
-       ImageInput *in = ImageInput::create(filename);
+       unique_ptr<ImageInput> in(ImageInput::create(filename));
 
        if(!in) {
                return false;
@@ -202,7 +203,6 @@ bool ImageManager::get_image_metadata(const string& filename,
 
        ImageSpec spec;
        if(!in->open(filename, spec)) {
-               delete in;
                return false;
        }
 
@@ -270,7 +270,6 @@ bool ImageManager::get_image_metadata(const string& filename,
        }
 
        in->close();
-       delete in;
 
        return true;
 }
@@ -455,7 +454,7 @@ void ImageManager::tag_reload_image(const string& filename,
 }
 
 bool ImageManager::file_load_image_generic(Image *img,
-                                           ImageInput **in)
+                                           unique_ptr<ImageInput> *in)
 {
        if(img->filename == "")
                return false;
@@ -467,7 +466,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;
@@ -479,8 +478,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;
                }
        }
@@ -494,10 +491,7 @@ bool ImageManager::file_load_image_generic(Image *img,
        if(!(img->metadata.channels >= 1 && img->metadata.channels <= 4)) {
                if(*in) {
                        (*in)->close();
-                       delete *in;
-                       *in = NULL;
                }
-
                return false;
        }
 
@@ -512,7 +506,7 @@ bool ImageManager::file_load_image(Image *img,
                                    int texture_limit,
                                    device_vector<DeviceType>& tex_img)
 {
-       ImageInput *in = NULL;
+       unique_ptr<ImageInput> in = NULL;
        if(!file_load_image_generic(img, &in)) {
                return false;
        }
@@ -575,7 +569,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) {