Orange: Further cleanup of EXR saving
authorTon Roosendaal <ton@blender.org>
Mon, 9 Jan 2006 10:55:41 +0000 (10:55 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 9 Jan 2006 10:55:41 +0000 (10:55 +0000)
- F10 scene buttons now has options "half" and "zbuf" for exr saving.
  Note: when no float buffer is available, it always saves as "half",
  that's sufficient anyway, since half is 16 bits per channel.

- EXR in imbuf now uses compliant ibuf->ftype flags for denoting exr
  extensions such as 'half' and 'compression'.

- Removed ugly blenkernel dependency from exr module

source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/intern/openexr/openexr_api.cpp
source/blender/imbuf/intern/openexr/openexr_api.h
source/blender/imbuf/intern/writeimage.c
source/blender/include/butspace.h
source/blender/makesdna/DNA_scene_types.h
source/blender/src/buttons_scene.c
source/blender/src/screendump.c
source/blender/src/toets.c
source/blender/src/writeimage.c

index 4f648031fc69978f3d1944c89772e800992204d3..652c15afdd3de96ece773002dc388e52c0babad7 100644 (file)
@@ -134,15 +134,9 @@ typedef enum {
 #define IB_mem                 (1 << 14)
 #define IB_rectfloat   (1 << 15)
 
-/**@}*/
-
-/** \name imbuf_formats Image file formats
- * \brief These defines are bit flags for the various image file formats.
- */
-/**@{*/
-/** \brief Identifier for an image file format.
- *
+/*
  * The bit flag is stored in the ImBuf.ftype variable.
+ * Note that the lower 10 bits is used for storing custom flags 
  */
 #define AMI                            (1 << 31)
 #define PNG                            (1 << 30)
@@ -157,7 +151,10 @@ typedef enum {
 
 #define RADHDR                 (1 << 24)
 #define TIF                            (1 << 23)
+
 #define OPENEXR                        (1 << 22)
+#define OPENEXR_HALF   (1 << 8 )
+#define OPENEXR_COMPRESS (7)   
 
 #define RAWTGA         (TGA | 1)
 
index 86beab537ef2430509ed961053a534be446b6bd7..76a128cb2007cf5e8e89f2100fe26248d64f0216 100644 (file)
@@ -39,8 +39,6 @@ extern "C"
 #include "IMB_imbuf.h"
        
 #include "IMB_allocimbuf.h"
-#include "BKE_global.h"
-#include "DNA_scene_types.h"
 }
 
 #include <iostream>
@@ -150,27 +148,18 @@ static void openexr_header_compression(Header *header, int compression)
        }
 }
 
-short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
+static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
 {
        
        int width = ibuf->x;
        int height = ibuf->y;
-       
-       if (flags & IB_mem) 
-       {
-               printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n");
-               imb_addencodedbufferImBuf(ibuf);
-               ibuf->encodedsize = 0;    
-               return(0);
-       } 
-       
        int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL;   // summarize
        
        try
        {
                Header header (width, height);
                
-               openexr_header_compression(&header, G.scene->r.quality);
+               openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
                
                header.channels().insert ("R", Channel (HALF));
                header.channels().insert ("G", Channel (HALF));
@@ -249,30 +238,18 @@ short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
        return (1);
 }
 
-short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
+static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
 {
        
        int width = ibuf->x;
        int height = ibuf->y;
-       
-       if (flags & IB_mem) 
-       {
-               printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n");
-               imb_addencodedbufferImBuf(ibuf);
-               ibuf->encodedsize = 0;    
-               return(0);
-       } 
-       
-       if (ibuf->rect_float==NULL)
-               return(0);
-       
        int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL;   // summarize
        
        try
        {
                Header header (width, height);
                
-               openexr_header_compression(&header, G.scene->r.quality);
+               openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
                
                header.channels().insert ("R", Channel (FLOAT));
                header.channels().insert ("G", Channel (FLOAT));
@@ -313,6 +290,26 @@ short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
 }
 
 
+short imb_save_openexr(struct ImBuf *ibuf, char *name, int flags)
+{
+       if (flags & IB_mem) 
+       {
+               printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n");
+               imb_addencodedbufferImBuf(ibuf);
+               ibuf->encodedsize = 0;    
+               return(0);
+       } 
+       
+       if (ibuf->ftype & OPENEXR_HALF) 
+               return imb_save_openexr_half(ibuf, name, flags);
+       else {
+               /* when no float rect, we save as half (16 bits is sufficient) */
+               if (ibuf->rect_float==NULL)
+                       return imb_save_openexr_half(ibuf, name, flags);
+               else
+                       return imb_save_openexr_float(ibuf, name, flags);
+       }
+}
 
 struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
 {
@@ -437,5 +434,6 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
        }
        
 }
-       
+
+
 } // export "C"
index 882b9d98a06c6985215b212fbe379de16d9e968f..c12eb1f05ae8b70296265274506514f109c5dc8f 100644 (file)
@@ -49,8 +49,7 @@ extern "C" {
   
 int imb_is_a_openexr(unsigned char *mem);
        
-short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags);
-short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags);
+short imb_save_openexr(struct ImBuf *ibuf, char *name, int flags);
 
 struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags);
 
index b752dbf9dd0db9dfac410a7204bc899f67959169..522ce78ebc0ae41f0278ead026169ee9b9a00f5e 100644 (file)
@@ -97,7 +97,7 @@ short IMB_saveiff(struct ImBuf *ibuf, char *name, int flags)
        }
 #ifdef WITH_OPENEXR
        if (IS_openexr(ibuf)) {
-               return imb_save_openexr_half(ibuf, name, flags);
+               return imb_save_openexr(ibuf, name, flags);
        }
 #endif
 
index 86f57d4455ee96ddbaf46adeb573410b5e29794d..2ae3054a1abc1e156f3b3fdf2ce1e469bac023ee 100644 (file)
@@ -320,7 +320,6 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
 
 #define B_SET_EDGE             1643
 #define B_SET_ZBLUR            1644
-#define        B_SET_OPENEXR           1645
 
 /* *********************** */
 #define B_ARMATUREBUTS         1800
index e2067f7dfdd53fa98b0959bb7b3d60d6c9886c07..cc9d090a5e353a5b49adadb5b147c327d5b572ec 100644 (file)
@@ -1,9 +1,4 @@
 /**
- * blenlib/DNA_scene_types.h (mar-2001 nzc)
- *
- * Renderrecipe and scene decription. The fact that there is a
- * hierarchy here is a bit strange, and not desirable.
- *
  * $Id$ 
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
@@ -117,7 +112,7 @@ typedef struct RenderData {
        
        short dimensionspreset;         /* for the dimensions presets menu */
        
-       short filtertype, pad;          /* filter is box, tent, gauss, mitch, etc */
+       short filtertype;                       /* filter is box, tent, gauss, mitch, etc */
 
 
        short size, maximsize;  /* size in %, max in Kb */
@@ -146,14 +141,14 @@ typedef struct RenderData {
         * The number of part to use in the y direction
         */
        short yparts;
-       /* should rewrite this I think... */
-       rctf safety, border;
         
-       short winpos, planes, imtype;
+       short winpos, planes, imtype, subimtype;
+       
        /** Mode bits:                                                           */
        /* 0: Enable backbuffering for images                                    */
        short bufflag;
        short quality;
+       
        /**
         * Flags for render settings. Use bit-masking to access the settings.
         * 0: enable sequence output rendering                                   
@@ -210,6 +205,9 @@ typedef struct RenderData {
         * identical materials with this number.*/
        short same_mat_redux;
        
+       /* safety and border rect */
+       rctf safety, border;
+       
        /**
         * The gamma for the normal rendering. Used when doing
         * oversampling, to correctly blend subpixels to pixels.  */
@@ -407,6 +405,11 @@ typedef struct Scene {
 #define R_TIFF         22
 #define R_OPENEXR      23
 
+/* subimtype, flag options for imtype */
+#define R_OPENEXR_HALF 1
+#define R_OPENEXR_ZBUF 2
+
+
 /* **************** SCENE ********************* */
 #define RAD_PHASE_PATCHES      1
 #define RAD_PHASE_FACES                2
index 5545000579339f97aa454354efe1ebaf4a53302f..4494d1d33c31cb02ef3ea1477096c8af4da307e9 100644 (file)
@@ -1218,12 +1218,13 @@ static void render_panel_format(void)
 
 #ifdef __sgi
        yofs = 76;
-       uiDefButS(block, NUM,B_DIFF,"MaxSize:", 892,32,165,20, &G.scene->r.maximsize, 0.0, 500.0, 0, 0, "Maximum size per frame to save in an SGI movie");
-       uiDefButBitI(block, TOG, R_COSMO, 0,"Cosmo", 1059,32,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Attempt to save SGI movies using Cosmo hardware");
+       uiDefButS(block, NUM,B_DIFF,"MaxSize:",                 892,32,165,20, &G.scene->r.maximsize, 0.0, 500.0, 0, 0, "Maximum size per frame to save in an SGI movie");
+       uiDefButBitI(block, TOG, R_COSMO, 0,"Cosmo",    1059,32,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Attempt to save SGI movies using Cosmo hardware");
 #endif
 
+       
        uiDefButS(block, MENU,B_FILETYPEMENU,imagetype_pup(),   892,yofs,174,20, &G.scene->r.imtype, 0, 0, 0, 0, "Images are saved in this file format");
-       uiDefButBitI(block, TOG, R_MOVIECROP, B_DIFF, "Crop",          1068,yofs,51,20, &G.scene->r.mode, 0, 0, 0, 0, "Exclude border rendering from total image");
+       uiDefButBitI(block, TOG, R_MOVIECROP, B_DIFF, "Crop",   1068,yofs,51,20, &G.scene->r.mode, 0, 0, 0, 0, "Exclude border rendering from total image");
 
        yofs -= 22;
 
@@ -1258,12 +1259,21 @@ static void render_panel_format(void)
                        uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
                }
 #ifdef WITH_OPENEXR
-       } else if (G.scene->r.imtype == R_OPENEXR ) {
+       } 
+       else if (G.scene->r.imtype == R_OPENEXR ) {
                if (G.scene->r.quality > 5) G.scene->r.quality = 0;
-               uiDefButS(block, MENU,B_SET_OPENEXR, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",  892,yofs,112,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
+               
+               uiBlockBeginAlign(block);
+               uiDefButBitS(block, TOG, R_OPENEXR_HALF, B_NOP,"Half",  892,yofs+44,60,20, &G.scene->r.subimtype, 0, 0, 0, 0, "Use 16 bits float 'Half' type");
+               uiDefButBitS(block, TOG, R_OPENEXR_ZBUF, B_NOP,"Zbuf",  952,yofs+44,60,20, &G.scene->r.subimtype, 0, 0, 0, 0, "Save the zbuffer as 32 bits unsigned int");
+               uiBlockEndAlign(block);
+               
+               uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",  
+                                                                                                                       892,yofs,112,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
+               
 #endif
        } else {
-               if(G.scene->r.quality < 5) G.scene->r.quality = 90;     // temp
+               if(G.scene->r.quality < 5) G.scene->r.quality = 90;     /* restore from openexr */
                
                uiDefButS(block, NUM,B_DIFF, "Quality:",           892,yofs,112,20, &G.scene->r.quality, 10.0, 100.0, 0, 0, "Quality setting for JPEG images, AVI Jpeg and SGI movies");
        }
index cd51f1fdb0f54067cf13c2f9480158a7140ef5da..557a6f101a5d6a5ee45340cc79c60a05b58ba49d 100644 (file)
@@ -88,7 +88,12 @@ void write_screendump(char *name)
                        else if((G.have_libtiff) && 
                                (G.scene->r.imtype==R_TIFF)) ibuf->ftype= TIF;
 #ifdef WITH_OPENEXR
-                       else if(G.scene->r.imtype==R_OPENEXR) ibuf->ftype= OPENEXR;
+                       else if(G.scene->r.imtype==R_OPENEXR) {
+                               ibuf->ftype= OPENEXR;
+                               if(G.scene->r.subimtype & R_OPENEXR_HALF)
+                                       ibuf->ftype |= OPENEXR_HALF;
+                               ibuf->ftype |= (G.scene->r.quality & OPENEXR_COMPRESS);
+                       }
 #endif
                        else if(G.scene->r.imtype==R_HAMX) ibuf->ftype= AN_hamx;
                        else if(ELEM5(G.scene->r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
index 8fc3f740a0b782d75df8410960495faa5f7c1832..62f31f7f5853ce6a9e65f925a12e54a8bed9c8a3 100644 (file)
@@ -191,9 +191,8 @@ void schrijfplaatje(char *name)
                else if(R.r.imtype==R_IRIZ) {
                        ibuf->ftype= IMAGIC;
                        if (ibuf->zbuf == 0) {
-                               if (R.rectz) {
+                               if (R.rectz)
                                        ibuf->zbuf = (int *)R.rectz;
-                               }
                                else printf("no zbuf\n");
                        }
                }
@@ -211,7 +210,15 @@ void schrijfplaatje(char *name)
                }
 #ifdef WITH_OPENEXR
                else if(R.r.imtype==R_OPENEXR) {
+                       /* ibuf stores bitmasks for types */
                        ibuf->ftype= OPENEXR;
+                       if(R.r.subimtype & R_OPENEXR_HALF)
+                               ibuf->ftype |= OPENEXR_HALF;
+                       
+                       ibuf->ftype |= (R.r.quality & OPENEXR_COMPRESS);
+                       
+                       if(R.rectz && (R.r.subimtype & R_OPENEXR_ZBUF))
+                               ibuf->zbuf = (int *)R.rectz;
                }
 #endif
                else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) {
@@ -533,6 +540,7 @@ void BIF_save_rendered_image(void)
                }
                
                R.r.imtype= G.scene->r.imtype;
+               R.r.subimtype= G.scene->r.subimtype;
                R.r.quality= G.scene->r.quality;
                R.r.planes= G.scene->r.planes;
        
index 4497ed51e8171a5c07239ea9395fc9292d7c3891..4f1224eabff9d2525e8e1cecfeb441bf3529332d 100644 (file)
@@ -66,6 +66,9 @@ int BIF_write_ibuf(ImBuf *ibuf, char *name)
 #ifdef WITH_OPENEXR
        else if (G.scene->r.imtype==R_OPENEXR) {
                ibuf->ftype= OPENEXR;
+               if(G.scene->r.subimtype & R_OPENEXR_HALF)
+                       ibuf->ftype |= OPENEXR_HALF;
+               ibuf->ftype |= (G.scene->r.quality & OPENEXR_COMPRESS);
        }
 #endif
        else if ((G.scene->r.imtype==R_TARGA) || (G.scene->r.imtype==R_PNG)) {