Cycles: svn merge -r41182:41205 ^/trunk/blender
[blender-staging.git] / source / blender / imbuf / intern / readimage.c
index 1c1e681bb30534969013e5727af9618d523eb00f..a4fd189f8d8ccd607af31d0b57ae85f6be954d66 100644 (file)
 #include "IMB_imbuf.h"
 #include "IMB_filetype.h"
 
+static ImBuf *imb_ibImageFromFile(const char *filepath, int flags)
+{
+       ImBuf *ibuf;
+       ImFileType *type;
+
+       for(type=IMB_FILE_TYPES; type->is_a; type++) {
+               if(type->load_filepath) {
+                       ibuf= type->load_filepath(filepath, flags);
+                       if(ibuf) {
+                               if(flags & IB_premul) {
+                                       IMB_premultiply_alpha(ibuf);
+                                       ibuf->flags |= IB_premul;
+                               }
+
+                               return ibuf;
+                       }
+               }
+       }
+       
+       return NULL;
+}
+
 ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags)
 {
        ImBuf *ibuf;
@@ -127,10 +149,15 @@ ImBuf *IMB_loadiffname(const char *name, int flags)
 
        imb_cache_filename(filename, name, flags);
 
-       file = open(filename, O_BINARY|O_RDONLY);
-       if(file < 0) return NULL;
+       ibuf= imb_ibImageFromFile(name, flags);
+
+       if(!ibuf) {
+               file = open(filename, O_BINARY|O_RDONLY);
+               if(file < 0) return NULL;
 
-       ibuf= IMB_loadifffile(file, flags);
+               ibuf= IMB_loadifffile(file, flags);
+               close(file);
+       }
 
        if(ibuf) {
                BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
@@ -140,8 +167,6 @@ ImBuf *IMB_loadiffname(const char *name, int flags)
                if(flags & IB_fields) IMB_de_interlace(ibuf);
        }
 
-       close(file);
-
        return ibuf;
 }
 
@@ -184,7 +209,7 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int
        }
 
        for(type=IMB_FILE_TYPES; type->is_a; type++)
-               if(type->load_tile && type->ftype(type, ibuf))
+               if(type->load_tile && type->ftype && type->ftype(type, ibuf))
                        type->load_tile(ibuf, mem, size, tx, ty, rect);
 
        if(munmap(mem, size))