OpenEXR 2.2 add support for Dreamworks DWAA / DWAB compression
authorMartijn Berger <martijn.berger@gmail.com>
Thu, 12 Mar 2015 13:02:33 +0000 (14:02 +0100)
committerMartijn Berger <martijn.berger@gmail.com>
Thu, 12 Mar 2015 13:02:33 +0000 (14:02 +0100)
This patch makes it possible for the user to select all supported compression types in OpenEXR 2.2

Discussion points:
 - B44 is only defined for half's it compresses to a fixed representation of 44% of the halfs. We do currently not reflect in the UI that in the case of float32's it will be equal to compression = NONE
 - ZIPS is single scanline zip and is supposed to be useful in cases where importing in Nuke happens.
 - The new Dreamworks formats, are the worth exposing etc etc

Reviewers: campbellbarton, sergey

Reviewed By: sergey

Projects: #bf_blender

Differential Revision: https://developer.blender.org/D1050

source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/intern/openexr/openexr_api.cpp
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c

index 867c4a826fe9fcc26758372536c49345cfe5119a..9e7201f53b43a6918eeaac7098d0f9098e82e20a 100644 (file)
@@ -202,7 +202,7 @@ typedef struct ImBuf {
 
 #define OPENEXR                        (1 << 22)
 #define OPENEXR_HALF   (1 << 8 )
-#define OPENEXR_COMPRESS (7)   
+#define OPENEXR_COMPRESS (15)
 
 #ifdef WITH_CINEON
 #define CINEON                 (1 << 21)
index 5de243845a465101931f68a43ae9403c0522d9df..45eae89ad9d7967c82d95c7a97e127c4b954f0ee 100644 (file)
@@ -38,6 +38,8 @@
 #include <errno.h>
 #include <algorithm>
 
+#include "DNA_scene_types.h" /* For OpenEXR compression constants */
+
 #include <openexr_api.h>
 
 #if defined (WIN32) && !defined(FREE_WINDOWS)
@@ -284,21 +286,38 @@ int imb_is_a_openexr(unsigned char *mem)
 static void openexr_header_compression(Header *header, int compression)
 {
        switch (compression) {
-               case 0:
+               case R_IMF_EXR_CODEC_NONE:
                        header->compression() = NO_COMPRESSION;
                        break;
-               case 1:
+               case R_IMF_EXR_CODEC_PXR24:
                        header->compression() = PXR24_COMPRESSION;
                        break;
-               case 2:
+               case R_IMF_EXR_CODEC_ZIP:
                        header->compression() = ZIP_COMPRESSION;
                        break;
-               case 3:
+               case R_IMF_EXR_CODEC_PIZ:
                        header->compression() = PIZ_COMPRESSION;
                        break;
-               case 4:
+               case R_IMF_EXR_CODEC_RLE:
                        header->compression() = RLE_COMPRESSION;
                        break;
+               case R_IMF_EXR_CODEC_ZIPS:
+                       header->compression() = ZIPS_COMPRESSION;
+                       break;
+               case R_IMF_EXR_CODEC_B44:
+                       header->compression() = B44_COMPRESSION;
+                       break;
+               case R_IMF_EXR_CODEC_B44A:
+                       header->compression() = B44A_COMPRESSION;
+                       break;
+#if OPENEXR_VERSION_MAJOR >= 2 && OPENEXR_VERSION_MINOR >= 2
+               case R_IMF_EXR_CODEC_DWAA:
+                       header->compression() = DWAA_COMPRESSION;
+                       break;
+               case R_IMF_EXR_CODEC_DWAB:
+                       header->compression() = DWAB_COMPRESSION;
+                       break;
+#endif
                default:
                        header->compression() = ZIP_COMPRESSION;
                        break;
index c20f5ff02f8f8012624b9adf72a5c5f5e05fe8c6..0eae50a2562a26297a1a620c98895485c87eafdc 100644 (file)
@@ -350,6 +350,12 @@ typedef struct ImageFormatData {
 #define R_IMF_EXR_CODEC_ZIP   2
 #define R_IMF_EXR_CODEC_PIZ   3
 #define R_IMF_EXR_CODEC_RLE   4
+#define R_IMF_EXR_CODEC_ZIPS  5
+#define R_IMF_EXR_CODEC_B44   6
+#define R_IMF_EXR_CODEC_B44A  7
+#define R_IMF_EXR_CODEC_DWAA  8
+#define R_IMF_EXR_CODEC_DWAB  9
+#define R_IMF_EXR_CODEC_MAX  10
 
 /* ImageFormatData.jp2_flag */
 #define R_IMF_JP2_FLAG_YCC          (1<<0)  /* when disabled use RGB */ /* was R_JPEG2K_YCC */
index 13350f653b80b0a5303cebf283f399aa6e143ad0..a41214a1dab8f14cfb97963e19fe9be8399a00b8 100644 (file)
@@ -82,6 +82,11 @@ EnumPropertyItem exr_codec_items[] = {
        {R_IMF_EXR_CODEC_ZIP, "ZIP", 0, "ZIP (lossless)", ""},
        {R_IMF_EXR_CODEC_PIZ, "PIZ", 0, "PIZ (lossless)", ""},
        {R_IMF_EXR_CODEC_RLE, "RLE", 0, "RLE (lossless)", ""},
+       {R_IMF_EXR_CODEC_ZIPS, "ZIPS", 0, "ZIPS (lossless)", ""},
+       {R_IMF_EXR_CODEC_B44, "B44", 0, "B44 (lossy)", ""},
+       {R_IMF_EXR_CODEC_B44A, "B44A", 0, "B44A (lossy)", ""},
+       {R_IMF_EXR_CODEC_DWAA, "DWAA", 0, "DWAA (lossy)", ""},
+       {R_IMF_EXR_CODEC_DWAB, "DWAB", 0, "DWAB (lossy)", ""},
        {0, NULL, 0, NULL, NULL}
 };
 #endif
@@ -938,6 +943,34 @@ static EnumPropertyItem *rna_ImageFormatSettings_color_depth_itemf(bContext *UNU
        }
 }
 
+#ifdef WITH_OPENEXR
+       /* OpenEXR */
+
+static EnumPropertyItem *rna_ImageFormatSettings_exr_codec_itemf(bContext *UNUSED(C), PointerRNA *ptr,
+PropertyRNA *UNUSED(prop), bool *r_free)
+{
+       ImageFormatData *imf = (ImageFormatData *)ptr->data;
+
+       EnumPropertyItem *item = NULL;
+       int i = 1, totitem = 0;
+
+       if(imf->depth == 16)
+               return exr_codec_items; /* All compression types are defined for halfs */
+
+       for (i = 0; i < R_IMF_EXR_CODEC_MAX; i++) {
+               if((i == R_IMF_EXR_CODEC_B44 || i == R_IMF_EXR_CODEC_B44A))
+                       continue; /* B44 and B44A are not defined for 32 bit floats */
+
+               RNA_enum_item_add(&item, &totitem, &exr_codec_items[i]);
+       }
+
+       RNA_enum_item_end(&item, &totitem);
+       *r_free = true;
+
+       return item;
+}
+
+#endif
 static int rna_SceneRender_file_ext_length(PointerRNA *ptr)
 {
        RenderData *rd = (RenderData *)ptr->data;
@@ -4101,6 +4134,7 @@ static void rna_def_scene_image_format_data(BlenderRNA *brna)
        prop = RNA_def_property(srna, "exr_codec", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "exr_codec");
        RNA_def_property_enum_items(prop, exr_codec_items);
+       RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_ImageFormatSettings_exr_codec_itemf");
        RNA_def_property_ui_text(prop, "Codec", "Codec settings for OpenEXR");
        RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);