Gernot Ziegler's patch to add OpenEXR support to blender.
authorKent Mein <mein@cs.umn.edu>
Fri, 11 Mar 2005 20:16:14 +0000 (20:16 +0000)
committerKent Mein <mein@cs.umn.edu>
Fri, 11 Mar 2005 20:16:14 +0000 (20:16 +0000)
To enable it you will need to download OpenEXR and install it.
For the Makefiles you will need to set WITH_OPENEXR=true
and set NAN_OPENEXR to point to where OpenEXR is installed.

For scons you'll need to remove config.opts to get the new options
so you can enable OpenEXR, I was not able to get blender to link
with scons so the scons stuff may need to be tweaked a little but
I think it should work.

For other platform managers  The OpenEXR stuff is similar to QUICKTIME
you need to define WITH_OPENEXR and setup the library stuff and
as you'll notice in this commit there are two extra files.

Kent

22 files changed:
SConstruct
source/Makefile
source/blender/blenkernel/intern/Makefile
source/blender/blenkernel/intern/image.c
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/SConscript
source/blender/imbuf/intern/IMB_openexr.h [new file with mode: 0644]
source/blender/imbuf/intern/Makefile
source/blender/imbuf/intern/cmap.c
source/blender/imbuf/intern/openexr.cpp [new file with mode: 0644]
source/blender/imbuf/intern/readimage.c
source/blender/imbuf/intern/writeimage.c
source/blender/makesdna/DNA_scene_types.h
source/blender/src/Makefile
source/blender/src/buttons_scene.c
source/blender/src/toets.c
source/blender/src/transform_generics.c
source/blender/src/writeimage.c
source/gameengine/GamePlayer/common/SConscript
source/nan_definitions.mk
tools/scons/bs/bs_libs.py

index ce3e77bccb27cc9612297b69ec1c987e06682962..0cbecdfa93758656758af4d38e7a415c02321444 100644 (file)
@@ -82,6 +82,10 @@ if sys.platform == 'linux2' or sys.platform == 'linux-i386':
        png_lib = ['png']
        png_libpath = ['/usr/lib']
        png_include = ['/usr/include']
+       # OpenEXR library information
+       openexr_lib = ['Iex', 'Half', 'IlmImf', 'Imath']
+       openexr_libpath = ['/usr/lib']
+       openexr_include = ['/usr/include/OpenEXR']
        # jpeg library information
        jpeg_lib = ['jpeg']
        jpeg_libpath = ['/usr/lib']
@@ -128,6 +132,9 @@ if sys.platform == 'linux2' or sys.platform == 'linux-i386':
        openal_lib = ['openal']
        openal_libpath = ['/usr/lib']
        openal_include = ['/usr/include']
+        use_openexr = 'false'
+       if use_openexr == 'true':
+               defines += ['WITH_OPENEXR']
 
 elif sys.platform == 'darwin':
        use_international = 'true'
@@ -240,6 +247,8 @@ elif sys.platform == 'darwin':
        openal_lib = ['libopenal']
        openal_libpath = [darwin_precomp + 'openal/lib']
        openal_include = [darwin_precomp + 'openal/include']
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 elif sys.platform == 'cygwin':
        use_international = 'false'
@@ -320,6 +329,8 @@ elif sys.platform == 'cygwin':
        openal_lib = []
        openal_libpath = []
        openal_include = []
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 elif sys.platform == 'win32':
        use_international = 'true'
@@ -421,6 +432,8 @@ elif sys.platform == 'win32':
        openal_lib = ['openal_static']
        openal_libpath = ['#../lib/windows/openal/lib']
        openal_include = ['#../lib/windows/openal/include']
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 elif string.find (sys.platform, 'sunos') != -1:
        use_international = 'true'
@@ -499,6 +512,8 @@ elif string.find (sys.platform, 'sunos') != -1:
        openal_lib = []
        openal_libpath = []
        openal_include = []
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 elif string.find (sys.platform, 'irix') != -1:
        use_international = 'false'
@@ -584,10 +599,14 @@ elif string.find (sys.platform, 'irix') != -1:
        openal_lib = []
        openal_libpath = []
        openal_include = []
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 elif string.find (sys.platform, 'hp-ux') != -1:
        window_system = 'X11'
        defines = []
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 elif sys.platform=='openbsd3':
        print "Building for OpenBSD 3.x"
@@ -667,6 +686,8 @@ elif sys.platform=='openbsd3':
        openal_lib = ['openal']
        openal_libpath = ['/usr/lib']
        openal_include = ['/usr/include']
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
        
 elif sys.platform=='freebsd4' or sys.platform=='freebsd5':
        print "Building for FreeBSD"
@@ -746,6 +767,8 @@ elif sys.platform=='freebsd4' or sys.platform=='freebsd5':
        openal_lib = ['openal']
        openal_libpath = ['/usr/lib']
        openal_include = ['/usr/include']
+       if use_openexr == 'false':
+               defines += ['WITH_OPENEXR']
 
 else:
        print "Unknown platform %s"%sys.platform
@@ -820,6 +843,10 @@ else:
        config.write ("PNG_INCLUDE = %r\n"%(png_include))
        config.write ("PNG_LIBPATH = %r\n"%(png_libpath))
        config.write ("PNG_LIBRARY = %r\n"%(png_lib))
+       config.write ("USE_OPENEXR = %r\n"%(use_openexr))
+       config.write ("OPENEXR_INCLUDE = %r\n"%(openexr_include))
+       config.write ("OPENEXR_LIBPATH = %r\n"%(openexr_libpath))
+       config.write ("if USE_OPENEXR == 'true':\n\tOPENEXR_LIBRARY = %r\n"%(openexr_lib))
        config.write ("JPEG_INCLUDE = %r\n"%(jpeg_include))
        config.write ("JPEG_LIBPATH = %r\n"%(jpeg_libpath))
        config.write ("JPEG_LIBRARY = %r\n"%(jpeg_lib))
@@ -900,6 +927,9 @@ user_options.AddOptions (
                (BoolOption ('USE_QUICKTIME',
                                        'Set to 1 to add support for QuickTime.',
                                        'false')),
+               (BoolOption ('USE_OPENEXR',
+                                       'Set to 1 to add support for OpenEXR.',
+                                       'false')),
                ('HOST_CC', 'C compiler for the host platfor. This is the same as target platform when not cross compiling.'),
                ('HOST_CXX', 'C++ compiler for the host platform. This is the same as target platform when not cross compiling.'),
                ('TARGET_CC', 'C compiler for the target platform.'),
@@ -923,6 +953,9 @@ user_options.AddOptions (
                ('PNG_INCLUDE', 'Include directory for png header files.'),
                ('PNG_LIBPATH', 'Library path where the png library is located.'),
                ('PNG_LIBRARY', 'png library name.'),
+               ('OPENEXR_INCLUDE', 'Include directory for OpenEXR header files.'),
+               ('OPENEXR_LIBPATH', 'Library path where the OpenEXR library is located.'),
+               ('OPENEXR_LIBRARY', 'openexr library names.'),
                ('JPEG_INCLUDE', 'Include directory for jpeg header files.'),
                ('JPEG_LIBPATH', 'Library path where the jpeg library is located.'),
                ('JPEG_LIBRARY', 'jpeg library name.'),
index 60c8ede03c14d4e0b734ee161ee253ddb282c11f..ed466332ec946fb2ec26b9a42c2340e1a85ac236 100644 (file)
@@ -148,6 +148,12 @@ endif
     COMLIB += $(NAN_GUARDEDALLOC)/lib/libguardedalloc.a
     COMLIB += $(NAN_BMFONT)/lib/$(DEBUG_DIR)libbmfont.a
     COMLIB += $(NAN_PNG)/lib/libpng.a
+  ifeq ($(WITH_OPENEXR), true)
+    COMLIB += $(NAN_OPENEXR)/lib/libIlmImf.a
+    COMLIB += $(NAN_OPENEXR)/lib/libHalf.a
+    COMLIB += $(NAN_OPENEXR)/lib/libIex.a
+    COMLIB += $(NAN_OPENEXR)/lib/libImath.a
+  endif
     COMLIB += $(OCGDIR)/blender/yafray/$(DEBUG_DIR)libyafrayexport.a
     COMLIB += $(OCGDIR)/blender/blenlib/$(DEBUG_DIR)libblenlib.a
   ifeq ($(WITH_QUICKTIME), true)
index 4468fa01f1265c20da81f325c33e320b6f67a965..0b8c0a03217df9d431ed42fc79b5a755236a5a33 100644 (file)
@@ -77,3 +77,7 @@ ifeq ($(WITH_FREETYPE2), true)
     CPPFLAGS += -I$(NAN_FREETYPE)/include
     CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
 endif
+
+ifeq ($(WITH_OPENEXR), true)
+    CPPFLAGS += -DWITH_OPENEXR
+endif
index d8c455c9c480011c4cb6ab14bf7d236108437992..e4752220737c984a8feacc1466dda9237f2f3da2 100644 (file)
@@ -193,6 +193,11 @@ void makepicstring(char *string, int frame)
        else if(G.scene->r.imtype==R_PNG) {
                extension= ".png";
        }
+#ifdef WITH_OPENEXR
+       else if(G.scene->r.imtype==R_OPENEXR) {
+               extension= ".exr";
+       }
+#endif
        else if(G.scene->r.imtype==R_TARGA) {
                extension= ".tga";
        }
index 7f7b2b08a56d513ab8d06cbc3a9fc5808c06cd06..80eec3746278ce72d21da1dbb4e12560936ddfb2 100644 (file)
@@ -140,7 +140,7 @@ short IMB_converttocmap(struct ImBuf *ibuf);
  *
  * @attention Defined in cmap.c
  */
-int IMB_alpha_to_col0(int new);
+int IMB_alpha_to_col0(int value);
 
 /**
  *
index 8abb00d722d2193970f7abe3d51ccd0d6f034a8f..e0a1d42aa1ac99afaf36c3c4ed24b05f999ec8e5 100644 (file)
@@ -75,6 +75,7 @@ typedef struct ImBuf{
        int     ftype;          /**< File type */
        unsigned int    *cmap;          /**< Color map data. */
        unsigned int    *rect;          /**< databuffer */
+       float *rect_float;              /**< databuffer in Float format, unclampled !! */
        unsigned int    **planes;       /**< bitplanes */
        int     flags;          /**< Controls which components should exist. */
        int     mall;           /**< what is malloced internal, and can be freed */
@@ -151,6 +152,9 @@ typedef enum {
 #ifdef WITH_IMAGEMAGICK
 #define IMAGEMAGICK    (1 << 23)
 #endif
+#ifdef WITH_OPENEXR
+#define OPENEXR                (1 << 22)
+#endif
 
 #define RAWTGA         (TGA | 1)
 
@@ -187,6 +191,7 @@ typedef enum {
 #define IS_hamx(x)             (x->ftype == AN_hamx)
 #define IS_tga(x)              (x->ftype & TGA)
 #define IS_png(x)              (x->ftype & PNG)
+#define IS_openexr(x)          (x->ftype & OPENEXR)
 #define IS_bmp(x)              (x->ftype & BMP)
 
 #define IMAGIC         0732
index 11d7cfb2b30854dda0a014fba71e98351c5913d6..199e872e49b17f5f1b0d8fb7ddda4746c6c5bb20 100644 (file)
@@ -33,6 +33,9 @@ source_files = ['intern/allocimbuf.c',
                 'intern/util.c',
                 'intern/writeimage.c']
 
+if user_options_dict['USE_OPENEXR'] == 1:
+       source_files.append('intern/openexr.cpp')
+
 imbuf_env.Append (CPPPATH = ['.',
                              '../makesdna',
                              '#/intern/guardedalloc',
@@ -43,6 +46,7 @@ imbuf_env.Append (CPPPATH = ['.',
 
 imbuf_env.Append (CPPPATH = user_options_dict['JPEG_INCLUDE'])
 imbuf_env.Append (CPPPATH = user_options_dict['PNG_INCLUDE'])
+imbuf_env.Append (CPPPATH = user_options_dict['OPENEXR_INCLUDE'])
 imbuf_env.Append (CPPPATH = user_options_dict['Z_INCLUDE'])
 imbuf_env.Append (CPPPATH = extra_includes)
 imbuf_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/blender_imbuf', source=source_files)
diff --git a/source/blender/imbuf/intern/IMB_openexr.h b/source/blender/imbuf/intern/IMB_openexr.h
new file mode 100644 (file)
index 0000000..edf8b14
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+/**
+ * \file IMB_openexr.h
+ * \ingroup imbuf
+ * \brief Function declarations for openexr.cc
+ */
+
+#ifndef IMB_OPENEXR_H
+#define IMB_OPENEXR_H
+
+struct ImBuf;
+
+int imb_is_a_openexr(void *buf);
+
+struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags);
+short imb_save_openexr(struct ImBuf * ibuf, char *name, int flags);
+#endif
index 0cb0316524dac2e0144d4e148e762b6ca5eebada..15062044716099f485d007f91ca8ef9510ba75de 100644 (file)
@@ -60,6 +60,11 @@ CPPFLAGS += -I../../makesdna
 CPPFLAGS += -I..
 
 ifeq ($(WITH_QUICKTIME), true)
-       CPPFLAGS += -DWITH_QUICKTIME
+   CPPFLAGS += -DWITH_QUICKTIME
+endif
+
+ifeq ($(WITH_OPENEXR), true)
+   CPPFLAGS += -DWITH_OPENEXR
+   CPPFLAGS += -I$(NAN_OPENEXR)/include/OpenEXR
 endif
 
index f5302b311d854fa3bf5bc530fe0775340471917a..c955fbf7e60a028159f80ce162217d8d6b4c7ad4 100644 (file)
@@ -64,12 +64,12 @@ void IMB_freeImBufdata(void)
 }
 
 
-int IMB_alpha_to_col0(int new)
+int IMB_alpha_to_col0(int value)
 {
        int old;
        
        old = alpha_col0;
-       alpha_col0 = new;
+       alpha_col0 = value;
        return (old);
 }
 
diff --git a/source/blender/imbuf/intern/openexr.cpp b/source/blender/imbuf/intern/openexr.cpp
new file mode 100644 (file)
index 0000000..96c8977
--- /dev/null
@@ -0,0 +1,392 @@
+/**
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Copyright by Gernot Ziegler <gz@lysator.liu.se>.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string>
+
+#include <iostream>
+
+#include <half.h>
+#include <ImfVersion.h>
+#include <ImathBox.h>
+#include <ImfArray.h>
+#include <ImfIO.h>
+#include <ImfChannelList.h>
+#include <ImfPixelType.h>
+#include <ImfInputFile.h>
+#include <ImfOutputFile.h>
+
+using namespace Imf;
+using namespace Imath;
+
+extern "C"
+{
+#ifdef WIN32
+#include "BLI_winstuff.h"
+#endif
+#include "BLI_blenlib.h"
+
+#include "imbuf.h"
+#include "imbuf_patch.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
+#include "IMB_allocimbuf.h"
+#include "IMB_cmap.h"
+}
+
+
+int imb_is_a_openexr(void *mem)
+{
+       return Imf::isImfMagic ((const char *)mem);
+}
+
+
+class Mem_IStream: public IStream
+{
+       public:
+
+               Mem_IStream (unsigned char *exrbuf, int exrsize):
+               IStream("dummy"), _exrpos (0), _exrsize(exrsize)  { _exrbuf = exrbuf; }
+
+               virtual bool  read (char c[], int n);
+               virtual Int64 tellg ();
+               virtual void  seekg (Int64 pos);
+               virtual void  clear ();
+//virtual ~Mem_IStream() {}; // unused
+
+       private:
+
+               Int64 _exrpos;
+               Int64 _exrsize;
+               unsigned char *_exrbuf;
+};
+
+bool Mem_IStream::read (char c[], int n)
+{
+       if (n + _exrpos <= _exrsize)
+       {
+               memcpy(c, (void *)(&_exrbuf[_exrpos]), n);
+               _exrpos += n;
+               return true;
+       }
+       else
+               return false;
+}
+
+
+Int64 Mem_IStream::tellg ()
+{
+       return _exrpos;
+}
+
+
+void Mem_IStream::seekg (Int64 pos)
+{
+       _exrpos = pos;
+}
+
+
+void Mem_IStream::clear ()
+{
+}
+
+
+struct _RGBAZ
+{
+       half r;
+       half g;
+       half b;
+       half a;
+       half z;
+};
+
+typedef struct _RGBAZ RGBAZ;
+
+extern "C"
+{
+       short imb_save_openexr(struct ImBuf *ibuf, char *name, int flags)
+       {
+               int width = ibuf->x;
+               int height = ibuf->y;
+               int i;
+
+                                                                                                 // summarize
+               int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != 0;
+
+               printf("OpenEXR-save: Saving %s image of %d x %d\n",
+                       write_zbuf ? "RGBAZ" : "RGBA", width, height);
+
+               try
+               {
+                       Header header (width, height);
+                       header.channels().insert ("R", Channel (HALF));
+                       header.channels().insert ("G", Channel (HALF));
+                       header.channels().insert ("B", Channel (HALF));
+                       header.channels().insert ("A", Channel (HALF));
+                       if (write_zbuf)
+                               header.channels().insert ("Z", Channel (HALF));
+
+                       FrameBuffer frameBuffer;
+                       OutputFile *file;
+
+                       if (flags & IB_mem)
+                       {
+                               printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n");
+                               imb_addencodedbufferImBuf(ibuf);
+                               ibuf->encodedsize = 0;
+                               return(0);
+                       }
+                       else
+                       {
+                               printf("OpenEXR-save: Creating output file %s\n", name);
+                               file = new OutputFile(name, header);
+                       }
+
+                       RGBAZ *pixels = new RGBAZ[height * width];
+
+                       int bytesperpixel = (ibuf->depth + 7) >> 3;
+                       if ((bytesperpixel > 4) || (bytesperpixel == 2))
+                       {
+                               printf("OpenEXR-save: unsupported bytes per pixel: %d\n", bytesperpixel);
+                               return (0);
+                       }
+
+                       frameBuffer.insert ("R",
+                               Slice (HALF,
+                               (char *) &pixels[0].r,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       frameBuffer.insert ("G",
+                               Slice (HALF,
+                               (char *) &pixels[0].g,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       frameBuffer.insert ("B",
+                               Slice (HALF,
+                               (char *) &pixels[0].b,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       frameBuffer.insert ("A",
+                               Slice (HALF,
+                               (char *) &pixels[0].a,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       if (write_zbuf)
+                               frameBuffer.insert ("Z",
+                                       Slice (HALF,
+                                       (char *) &pixels[0].z,
+                                       sizeof (pixels[0]) * 1,
+                                       sizeof (pixels[0]) * width));
+
+                       if (!ibuf->rect_float)
+                       {
+                               printf("OpenEXR-save: Converting Blender 8/8/8/8 pixels to OpenEXR format\n");
+
+                               RGBAZ *to = pixels;
+                               unsigned char *from = (unsigned char *) ibuf->rect;
+
+                               for (i = ibuf->x * ibuf->y; i > 0; i--)
+                               {
+                                       to->r = (float)(from[0])/255.0;
+                                       to->g = (float)(from[1])/255.0;
+                                       to->b = (float)(from[2])/255.0;
+                                       to->a = (float)(from[3])/255.0;
+                                       to++; from += 4;
+                               }
+                       }
+                       else
+                       {
+                               printf("OpenEXR-save: Converting Blender FLOAT pixels to OpenEXR format\n");
+
+                               RGBAZ *to = pixels;
+                               float *from = ibuf->rect_float;
+
+                               for (i = ibuf->x * ibuf->y; i > 0; i--)
+                               {
+                                       to->r = from[0];
+                                       to->g = from[1];
+                                       to->b = from[2];
+                                       to->a = from[3];
+                                       to++; from += 4;
+                               }
+                       }
+
+                       if (write_zbuf)
+                       {
+                               RGBAZ *to = pixels;
+                               int *fromz = ibuf->zbuf;
+
+                               for (int i = ibuf->x * ibuf->y; i > 0; i--)
+                               {
+                                       to->z =  (0.5+((float)(*fromz/65536)/65536.0));
+                                       to++; fromz ++;
+                               }
+                       }
+
+                       printf("OpenEXR-save: Writing OpenEXR file of height %d.\n", height);
+
+                       file->setFrameBuffer (frameBuffer);
+                       file->writePixels (height);
+                       delete file;
+               }
+               catch (const std::exception &exc)
+               {
+                       printf("OpenEXR-save: ERROR: %s\n", exc.what());
+                       if (ibuf) IMB_freeImBuf(ibuf);
+
+                       return (0);
+               }
+
+               return (1);
+               printf("OpenEXR-save: Done.\n");
+       }
+
+       struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
+       {
+               struct ImBuf *ibuf = 0;
+
+               printf("OpenEXR-load: testing input, size is %d\n", size);
+               if (imb_is_a_openexr(mem) == 0) return(0);
+
+               InputFile *file = NULL;
+
+               try
+               {
+                       printf("OpenEXR-load: Creating InputFile from mem source\n");
+                       Mem_IStream membuf(mem, size);
+                       file = new InputFile(membuf);
+
+                       Box2i dw = file->header().dataWindow();
+                       int width  = dw.max.x - dw.min.x + 1;
+                       int height = dw.max.y - dw.min.y + 1;
+
+                       printf("OpenEXR-load: image data window %d %d %d %d\n",
+                               dw.min.x, dw.min.y, dw.max.x, dw.max.y);
+
+                       const ChannelList &channels = file->header().channels();
+
+                       for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i)
+                       {
+                               const Channel &channel = i.channel();
+                               printf("OpenEXR-load: Found channel %s of type %d\n", i.name(), channel.type);
+                               if (channel.type != 1)
+                               {
+                                       printf("OpenEXR-load: Can only process HALF input !!\n");
+                                       return(NULL);
+                               }
+                       }
+
+                       RGBAZ *pixels = new RGBAZ[height * width];
+
+                       FrameBuffer frameBuffer;
+
+                       frameBuffer.insert ("R",
+                               Slice (HALF,
+                               (char *) &pixels[0].r,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       frameBuffer.insert ("G",
+                               Slice (HALF,
+                               (char *) &pixels[0].g,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       frameBuffer.insert ("B",
+                               Slice (HALF,
+                               (char *) &pixels[0].b,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+                       frameBuffer.insert ("A",
+                               Slice (HALF,
+                               (char *) &pixels[0].a,
+                               sizeof (pixels[0]) * 1,
+                               sizeof (pixels[0]) * width));
+
+// FIXME ? Would be able to read Z data or other channels here !
+
+                       printf("OpenEXR-load: Reading pixel data\n");
+                       file->setFrameBuffer (frameBuffer);
+                       file->readPixels (dw.min.y, dw.max.y);
+
+                       printf("OpenEXR-load: Converting to Blender ibuf\n");
+
+                       int bytesperpixel = 4;                            // since OpenEXR fills in unknown channels
+                       ibuf = IMB_allocImBuf(width, height, 8 * bytesperpixel, 0, 0);
+
+                       if (ibuf)
+                       {
+                               ibuf->ftype = PNG;
+                               imb_addrectImBuf(ibuf);
+
+                               if (!(flags & IB_test))
+                               {
+                                       unsigned char *to = (unsigned char *) ibuf->rect;
+                                       RGBAZ *from = pixels;
+                                       RGBAZ prescale;
+
+                                       for (int i = ibuf->x * ibuf->y; i > 0; i--)
+                                       {
+                                               to[0] = (unsigned char)(((float)from->r > 1.0) ? 1.0 : (float)from->r)  * 255;
+                                               to[1] = (unsigned char)(((float)from->g > 1.0) ? 1.0 : (float)from->g)  * 255;
+                                               to[2] = (unsigned char)(((float)from->b > 1.0) ? 1.0 : (float)from->b)  * 255;
+                                               to[3] = (unsigned char)(((float)from->a > 1.0) ? 1.0 : (float)from->a)  * 255;
+                                               to += 4; from++;
+                                       }
+                               }
+
+                       }
+                       else
+                               printf("Couldn't allocate memory for PNG image\n");
+
+                       printf("OpenEXR-load: Done\n");
+
+                       return(ibuf);
+               }
+               catch (const std::exception &exc)
+               {
+                       std::cerr << exc.what() << std::endl;
+                       if (ibuf) IMB_freeImBuf(ibuf);
+
+                       return (0);
+               }
+
+       }
+
+}                                                                                                // export "C"
index 0f817e22dd10fae303ce22c1f66de447a38a05b1..9d40ef602f8523b0822e6fed63923272c969345a 100644 (file)
 #include "IMB_jpeg.h"
 #include "IMB_bmp.h"
 #include "BKE_global.h"
+
+#ifdef WITH_OPENEXR
+#include "IMB_openexr.h"
+#endif
+
 #ifdef WITH_QUICKTIME
 #if defined(_WIN32) || defined (__APPLE__)
 #include "quicktime_import.h"
@@ -137,6 +142,11 @@ ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) {
                ibuf = imb_loadtarga((uchar *)mem, flags);
                if (ibuf) return(ibuf);
 
+#ifdef WITH_OPENEXR
+               ibuf = imb_load_openexr((uchar *)mem, size, flags);
+               if (ibuf) return(ibuf);
+#endif
+
 #ifdef WITH_QUICKTIME
 #if defined(_WIN32) || defined (__APPLE__)
                if(G.have_quicktime) {
index 150ab8aac26c8f69d6c8e41b089b1a9d0d3c726f..925eaca3e8767b16121fb2909367e00f66eee0df 100644 (file)
@@ -50,6 +50,9 @@
 #include "IMB_amiga.h"
 #include "IMB_png.h"
 #include "IMB_bmp.h"
+#ifdef WITH_OPENEXR
+#include "IMB_openexr.h"
+#endif
 
 #include "IMB_iff.h"
 #include "IMB_bitplanes.h"
@@ -70,6 +73,11 @@ short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags)
        if (IS_png(ibuf)) {
                return imb_savepng(ibuf,naam,flags);
        }
+#ifdef WITH_OPENEXR
+       if (IS_openexr(ibuf)) {
+               return imb_save_openexr(ibuf,naam,flags);
+       }
+#endif
        if (IS_bmp(ibuf)) {
                return imb_savebmp(ibuf,naam,flags);
        }
index 04aa96c9d1fa31a2ab06f994e543e15ad0f6c371..aae1465df0dbeef50ea74dec280aedddd7cf9be4 100644 (file)
@@ -340,7 +340,7 @@ typedef struct Scene {
 #define R_AVICODEC     18
 #define R_QUICKTIME    19
 #define R_BMP          20
-
+#define R_OPENEXR      21
 
 /* **************** RENDER ********************* */
 /* mode flag is same as for renderdata */
index 210ed7d73206fc0938aad07ecc1d7b994fe3c8fe..7755c8cf7079618141b9d6f3957a0085c6e14aae 100644 (file)
@@ -111,6 +111,10 @@ ifeq ($(WITH_QUICKTIME),true)
        CPPFLAGS += -DWITH_QUICKTIME
 endif
 
+ifeq ($(WITH_OPENEXR),true)
+       CPPFLAGS += -DWITH_OPENEXR
+endif
+
 ifeq ($(INTERNATIONAL), true)
     CPPFLAGS += -DINTERNATIONAL
 endif
index 522fa23b7a773f65a822be40983d9ac2787c697c..8702f320c6c02b2bc8fa52d8f3595ab0adf91fc5 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifdef WIN32
 #include "BLI_winstuff.h"
 #endif
@@ -958,6 +954,9 @@ static char *imagetype_pup(void)
 #endif
 
        strcat(formatstring, "|%s %%x%d");      // add space for PNG
+#ifdef WITH_OPENEXR
+       strcat(formatstring, "|%s %%x%d");      // add space for OpenEXR
+#endif
        strcat(formatstring, "|%s %%x%d");      // add space for BMP
 
 #ifdef _WIN32
@@ -982,6 +981,9 @@ static char *imagetype_pup(void)
                        "Targa",          R_TARGA,
                        "Targa Raw",      R_RAWTGA,
                        "PNG",            R_PNG,
+#ifdef WITH_OPENEXR
+                       "OpenEXR",        R_OPENEXR,
+#endif
                        "BMP",            R_BMP,
                        "Jpeg",           R_JPEG90,
                        "HamX",           R_HAMX,
@@ -1000,6 +1002,9 @@ static char *imagetype_pup(void)
                        "Targa",          R_TARGA,
                        "Targa Raw",      R_RAWTGA,
                        "PNG",            R_PNG,
+#ifdef WITH_OPENEXR
+                       "OpenEXR",        R_OPENEXR,
+#endif
                        "BMP",            R_BMP,
                        "Jpeg",           R_JPEG90,
                        "HamX",           R_HAMX,
index 9118a35e53b3b1dabeafb6b35b76b749a90dcb04..752f4359365c6f1f86c89c326f3d48bdcc3d8ec2 100644 (file)
 #include <string.h>
 #include <math.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifdef WIN32
 #include "BLI_winstuff.h"
 #endif
@@ -177,6 +173,7 @@ void schrijfplaatje(char *name)
 
        if(ibuf) {
                ibuf->rect= (unsigned int *) R.rectot;
+               ibuf->rect_float = R.rectftot;
 
                if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
 
@@ -195,6 +192,17 @@ void schrijfplaatje(char *name)
                else if(R.r.imtype==R_PNG) {
                        ibuf->ftype= PNG;
                }
+#ifdef WITH_OPENEXR
+               else if(R.r.imtype==R_OPENEXR) {
+                       ibuf->ftype= OPENEXR;
+                       if (ibuf->zbuf == 0) {
+                               if (R.rectz) {
+                                       ibuf->zbuf = (int *)R.rectz;
+                               }
+                               else printf("Write OPENEXR: no zbuf !\n");
+                       }
+               }
+#endif
                else if(R.r.imtype==R_BMP) {
                        ibuf->ftype= BMP;
                }
@@ -474,6 +482,8 @@ int save_image_filesel_str(char *str)
        switch(G.scene->r.imtype) {
        case R_PNG:
                strcpy(str, "Save PNG"); return 1;
+       case R_OPENEXR:
+               strcpy(str, "Save OPENEXR"); return 1;
        case R_BMP:
                strcpy(str, "Save BMP"); return 1;
        case R_TARGA:
index 005ae9fda15b7dd91bf72af9761bf4ddd0e70cc4..d6c211d122d3f2d3b811d5f2622e43c5f5de6c0b 100755 (executable)
@@ -684,4 +684,5 @@ void calculatePropRatio(TransInfo *t)
 
 TransInfo * BIF_GetTransInfo() {
        return &Trans;
-}
\ No newline at end of file
+}
+
index 75b215f70bddefa0028c3145cf506286233a4837..d16247a70b2fcf66e58e97c74073732a66d75321 100644 (file)
 
 #include "render.h"                    // RE_make_existing_file, R. stuff
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 int BIF_write_ibuf(ImBuf *ibuf, char *name)
 {
        int ok;
@@ -61,6 +57,11 @@ int BIF_write_ibuf(ImBuf *ibuf, char *name)
        else if ((G.scene->r.imtype==R_BMP)) {
                ibuf->ftype= BMP;
        }
+#ifdef WITH_OPENEXR
+       else if ((G.scene->r.imtype==R_OPENEXR)) {
+               ibuf->ftype= OPENEXR;
+       }
+#endif
        else if ((G.scene->r.imtype==R_TARGA) || (G.scene->r.imtype==R_PNG)) {
                // fall back to Targa if PNG writing is not supported
                ibuf->ftype= TGA;
index b074c3659ee0d4ad8525aa269b36a1c49eba5f90..ad557eae2f45e9bf4b2c3abad2e3060e95c8100d 100644 (file)
@@ -65,9 +65,10 @@ gp_common_env.Append( CPPPATH = ['.',
 gp_common_env.Append (CPPPATH = user_options_dict['PYTHON_INCLUDE'])
 gp_common_env.Append (CPPPATH = user_options_dict['SOLID_INCLUDE'])
 gp_common_env.Append (CPPPATH = user_options_dict['PNG_INCLUDE'])
+gp_common_env.Append (CPPPATH = user_options_dict['OPENEXR_INCLUDE'])
 gp_common_env.Append (CPPPATH = user_options_dict['Z_INCLUDE'])
 
 if sys.platform=='win32':
     gp_common_env.Append (CXXFLAGS = ['/GR'])
 
-gp_common_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/GPC_common', source=source_files)
\ No newline at end of file
+gp_common_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/GPC_common', source=source_files)
index 3b89a425b07ae73f72bb1b6b9e3bf4ac9776bf87..1ed4fe2ebae7b1a487d5781f647e4b74385c36cd 100644 (file)
@@ -102,6 +102,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= $(LCGDIR)/jpeg
     export NAN_PNG ?= $(LCGDIR)/png
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr/src/Mesa-3.1
@@ -153,6 +156,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= /sw
     export NAN_PNG ?= /sw
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr/src/Mesa-3.1
@@ -197,6 +203,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= /usr/local
     export NAN_PNG ?= /usr/local
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr/src/Mesa-3.1
@@ -240,6 +249,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= $(LCGDIR)/jpeg
     export NAN_PNG ?= $(LCGDIR)/png
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr/src/Mesa-3.1
@@ -281,6 +293,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= /usr
     export NAN_PNG ?= /usr
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr
@@ -323,6 +338,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= $(LCGDIR)/jpeg
     export NAN_PNG ?= $(LCGDIR)/png
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr/src/Mesa-3.1
@@ -364,6 +382,9 @@ endif
     export NAN_FMOD ?= $(LCGDIR)/fmod
     export NAN_JPEG ?= /usr/local
     export NAN_PNG ?= /usr/local
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?=
     export NAN_MESA ?= /usr/src/Mesa-3.1
@@ -403,6 +424,9 @@ endif
     ifeq ($(FREE_WINDOWS), true)
       export NAN_PYTHON_BINARY ?= $(NAN_PYTHON)/bin/python$(NAN_PYTHON_VERSION)
       export NAN_FREETYPE ?= $(LCGDIR)/gcc/freetype
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
       export NAN_ODE ?= $(LCGDIR)/gcc/ode
       ifeq ($(NAN_SDL),)
          export NAN_SDL ?= $(LCGDIR)/gcc/sdl
@@ -411,6 +435,9 @@ endif
     else
       export NAN_PYTHON_BINARY ?= python
       export NAN_FREETYPE ?= $(LCGDIR)/freetype
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
       export NAN_ODE ?= $(LCGDIR)/ode
       ifeq ($(NAN_SDL),)
          export NAN_SDL ?= $(LCGDIR)/sdl
@@ -458,6 +485,9 @@ endif
     export NAN_JPEG ?= $(LCGDIR)/jpeg
     export NAN_PNG ?= $(LCGDIR)/png
     export NAN_SDL ?= $(LCGDIR)/sdl
+# Commented out by default
+#    export WITH_OPENEXR ?= true
+    export NAN_OPENEXR ?= $(LCGDIR)/OpenEXR
     export NAN_ODE ?= $(LCGDIR)/ode
     export NAN_TERRAPLAY ?= $(LCGDIR)/terraplay
     export NAN_MESA ?= /usr/src/Mesa-3.1
index 3783b926dfb9f7286d3082bb0b1e60364a4b6334..f2a8ec9fa2e3dfa433d515392d5ed5ad34bf2f8e 100644 (file)
@@ -123,6 +123,9 @@ def system_libs(env):
        env.Append (LIBPATH=bs_globals.user_options_dict['SDL_LIBPATH'])
        env.Append (LIBS=bs_globals.user_options_dict['PNG_LIBRARY'])
        env.Append (LIBPATH=bs_globals.user_options_dict['PNG_LIBPATH'])
+       if bs_globals.user_options_dict['USE_OPENEXR'] == 1:
+               env.Append (LIBS=bs_globals.user_options_dict['OPENEXR_LIBRARY'])
+               env.Append (LIBPATH=bs_globals.user_options_dict['OPENEXR_LIBPATH'])
        env.Append (LIBS=bs_globals.user_options_dict['JPEG_LIBRARY'])
        env.Append (LIBPATH=bs_globals.user_options_dict['JPEG_LIBPATH'])
        env.Append (LIBS=bs_globals.user_options_dict['GETTEXT_LIBRARY'])