[Bf-blender-cvs] [9d796df] master: Support half float file format storage for Multilayer EXR

Sergey Sharybin noreply at git.blender.org
Fri Jun 19 13:34:33 CEST 2015


Commit: 9d796df4f6376809f14ca0dd0484f63df9c72494
Author: Sergey Sharybin
Date:   Fri Jun 19 13:00:18 2015 +0200
Branches: master
https://developer.blender.org/rB9d796df4f6376809f14ca0dd0484f63df9c72494

Support half float file format storage for Multilayer EXR

Quite straightforward implementation -- all the conversion magic is
happening in IMB_exr_write_channels() and remained changes are only
needed to pass information whether channels is to be converted to
half float or not.

Regular file output will use full-float for Z pass, which matches
behavior of the single layer EXR files. But when saving happens
with File Output node then all the passes are respecting half float
settings because it's not possible to distinguish whether we're
saving Z pass or not.

Reviewers: juicyfruit, campbellbarton

Reviewed By: campbellbarton

Subscribers: maxon, effstops, fsiddi

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

===================================================================

M	source/blender/blenkernel/intern/image.c
M	source/blender/compositor/nodes/COM_OutputFileNode.cpp
M	source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
M	source/blender/compositor/operations/COM_OutputFileMultiViewOperation.h
M	source/blender/compositor/operations/COM_OutputFileOperation.cpp
M	source/blender/compositor/operations/COM_OutputFileOperation.h
M	source/blender/imbuf/intern/openexr/openexr_api.cpp
M	source/blender/imbuf/intern/openexr/openexr_multi.h
M	source/blender/imbuf/intern/openexr/openexr_stub.cpp
M	source/blender/render/intern/source/render_result.c

===================================================================

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 90aa094..451ab43 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1400,7 +1400,7 @@ char BKE_imtype_valid_depths(const char imtype)
 		case R_IMF_IMTYPE_OPENEXR:
 			return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32;
 		case R_IMF_IMTYPE_MULTILAYER:
-			return R_IMF_CHAN_DEPTH_32;
+			return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32;
 		/* eeh, cineon does some strange 10bits per channel */
 		case R_IMF_IMTYPE_DPX:
 			return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_10 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16;
diff --git a/source/blender/compositor/nodes/COM_OutputFileNode.cpp b/source/blender/compositor/nodes/COM_OutputFileNode.cpp
index acd2602..42805d1 100644
--- a/source/blender/compositor/nodes/COM_OutputFileNode.cpp
+++ b/source/blender/compositor/nodes/COM_OutputFileNode.cpp
@@ -47,18 +47,21 @@ void OutputFileNode::convertToOperations(NodeConverter &converter, const Composi
 		 */
 		return;
 	}
-	
+
 	if (storage->format.imtype == R_IMF_IMTYPE_MULTILAYER) {
+		const bool use_half_float = (storage->format.depth == R_IMF_CHAN_DEPTH_16);
 		/* single output operation for the multilayer file */
 		OutputOpenExrMultiLayerOperation *outputOperation;
 
 		if (is_multiview && storage->format.views_format == R_IMF_VIEWS_MULTIVIEW) {
 			outputOperation = new OutputOpenExrMultiLayerMultiViewOperation(
-			        context.getRenderData(), context.getbNodeTree(), storage->base_path, storage->format.exr_codec, context.getViewName());
+			        context.getRenderData(), context.getbNodeTree(), storage->base_path,
+			        storage->format.exr_codec, use_half_float, context.getViewName());
 		}
 		else {
 			outputOperation = new OutputOpenExrMultiLayerOperation(
-		          context.getRenderData(), context.getbNodeTree(), storage->base_path, storage->format.exr_codec, context.getViewName());
+		          context.getRenderData(), context.getbNodeTree(), storage->base_path,
+		          storage->format.exr_codec, use_half_float, context.getViewName());
 		}
 		converter.addOperation(outputOperation);
 
diff --git a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
index e89af9c..7786359 100644
--- a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
+++ b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
@@ -74,7 +74,7 @@ void *OutputOpenExrSingleLayerMultiViewOperation::get_handle(const char *filenam
 				continue;
 
 			IMB_exr_add_view(exrhandle, srv->name);
-			add_exr_channels(exrhandle, NULL, this->m_datatype, srv->name, width, NULL);
+			add_exr_channels(exrhandle, NULL, this->m_datatype, srv->name, width, false, NULL);
 		}
 
 		BLI_make_existing_file(filename);
@@ -108,7 +108,8 @@ void OutputOpenExrSingleLayerMultiViewOperation::deinitExecution()
 		        (this->m_rd->scemode & R_EXTENSION) != 0, true, NULL);
 
 		exrhandle = this->get_handle(filename);
-		add_exr_channels(exrhandle, NULL, this->m_datatype, this->m_viewName, width, this->m_outputBuffer);
+		add_exr_channels(exrhandle, NULL, this->m_datatype, this->m_viewName, width,
+		                 this->m_format->depth == R_IMF_CHAN_DEPTH_16, this->m_outputBuffer);
 
 		/* memory can only be freed after we write all views to the file */
 		this->m_outputBuffer = NULL;
@@ -130,8 +131,9 @@ void OutputOpenExrSingleLayerMultiViewOperation::deinitExecution()
 /************************************  OpenEXR Multilayer Multiview *****************************************/
 
 OutputOpenExrMultiLayerMultiViewOperation::OutputOpenExrMultiLayerMultiViewOperation(
-        const RenderData *rd, const bNodeTree *tree, const char *path, char exr_codec, const char *viewName)
-    : OutputOpenExrMultiLayerOperation(rd, tree, path, exr_codec, viewName)
+        const RenderData *rd, const bNodeTree *tree, const char *path,
+        char exr_codec, bool exr_half_float, const char *viewName)
+    : OutputOpenExrMultiLayerOperation(rd, tree, path, exr_codec, exr_half_float, viewName)
 {
 }
 
@@ -162,7 +164,8 @@ void *OutputOpenExrMultiLayerMultiViewOperation::get_handle(const char *filename
 			IMB_exr_add_view(exrhandle, srv->name);
 
 			for (unsigned int i = 0; i < this->m_layers.size(); ++i)
-				add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i].datatype, srv->name, width, NULL);
+				add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i].datatype,
+				                 srv->name, width, this->m_exr_half_float, NULL);
 		}
 
 		BLI_make_existing_file(filename);
@@ -197,7 +200,8 @@ void OutputOpenExrMultiLayerMultiViewOperation::deinitExecution()
 		exrhandle = this->get_handle(filename);
 
 		for (unsigned int i = 0; i < this->m_layers.size(); ++i)
-			add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i].datatype, this->m_viewName, width, this->m_layers[i].outputBuffer);
+			add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i].datatype, this->m_viewName,
+			                 width, this->m_exr_half_float, this->m_layers[i].outputBuffer);
 
 		for (unsigned int i = 0; i < this->m_layers.size(); ++i) {
 			/* memory can only be freed after we write all views to the file */
@@ -269,7 +273,8 @@ void OutputStereoOperation::deinitExecution()
 		float *buf = this->m_outputBuffer;
 
 		/* populate single EXR channel with view data */
-		IMB_exr_add_channel(exrhandle, NULL, this->m_name, this->m_viewName, 1, this->m_channels * width * height, buf);
+		IMB_exr_add_channel(exrhandle, NULL, this->m_name, this->m_viewName, 1, this->m_channels * width * height, buf,
+		                    this->m_format->depth == R_IMF_CHAN_DEPTH_16);
 
 		this->m_imageInput = NULL;
 		this->m_outputBuffer = NULL;
diff --git a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.h b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.h
index 25716fd..0e3cde6 100644
--- a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.h
+++ b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.h
@@ -51,7 +51,8 @@ public:
 class OutputOpenExrMultiLayerMultiViewOperation : public OutputOpenExrMultiLayerOperation {
 private:
 public:
-	OutputOpenExrMultiLayerMultiViewOperation(const RenderData *rd, const bNodeTree *tree, const char *path, char exr_codec, const char *viewName);
+	OutputOpenExrMultiLayerMultiViewOperation(const RenderData *rd, const bNodeTree *tree, const char *path,
+	                                          char exr_codec, bool exr_half_float, const char *viewName);
 
 	void *get_handle(const char *filename);
 	void deinitExecution();
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cpp b/source/blender/compositor/operations/COM_OutputFileOperation.cpp
index b99b0d5..fdf5a0b 100644
--- a/source/blender/compositor/operations/COM_OutputFileOperation.cpp
+++ b/source/blender/compositor/operations/COM_OutputFileOperation.cpp
@@ -40,23 +40,24 @@ extern "C" {
 #  include "IMB_imbuf_types.h"
 }
 
-void add_exr_channels(void *exrhandle, const char *layerName, const DataType datatype, const char *viewName, const size_t width, float *buf)
+void add_exr_channels(void *exrhandle, const char *layerName, const DataType datatype,
+                      const char *viewName, const size_t width, bool use_half_float, float *buf)
 {
 	/* create channels */
 	switch (datatype) {
 		case COM_DT_VALUE:
-			IMB_exr_add_channel(exrhandle, layerName, "V", viewName, 1, width, buf ? buf : NULL);
+			IMB_exr_add_channel(exrhandle, layerName, "V", viewName, 1, width, buf ? buf : NULL, use_half_float);
 			break;
 		case COM_DT_VECTOR:
-			IMB_exr_add_channel(exrhandle, layerName, "X", viewName, 3, 3 * width, buf ? buf : NULL);
-			IMB_exr_add_channel(exrhandle, layerName, "Y", viewName, 3, 3 * width, buf ? buf + 1 : NULL);
-			IMB_exr_add_channel(exrhandle, layerName, "Z", viewName, 3, 3 * width, buf ? buf + 2 : NULL);
+			IMB_exr_add_channel(exrhandle, layerName, "X", viewName, 3, 3 * width, buf ? buf : NULL, use_half_float);
+			IMB_exr_add_channel(exrhandle, layerName, "Y", viewName, 3, 3 * width, buf ? buf + 1 : NULL, use_half_float);
+			IMB_exr_add_channel(exrhandle, layerName, "Z", viewName, 3, 3 * width, buf ? buf + 2 : NULL, use_half_float);
 			break;
 		case COM_DT_COLOR:
-			IMB_exr_add_channel(exrhandle, layerName, "R", viewName, 4, 4 * width, buf ? buf : NULL);
-			IMB_exr_add_channel(exrhandle, layerName, "G", viewName, 4, 4 * width, buf ? buf + 1 : NULL);
-			IMB_exr_add_channel(exrhandle, layerName, "B", viewName, 4, 4 * width, buf ? buf + 2 : NULL);
-			IMB_exr_add_channel(exrhandle, layerName, "A", viewName, 4, 4 * width, buf ? buf + 3 : NULL);
+			IMB_exr_add_channel(exrhandle, layerName, "R", viewName, 4, 4 * width, buf ? buf : NULL, use_half_float);
+			IMB_exr_add_channel(exrhandle, layerName, "G", viewName, 4, 4 * width, buf ? buf + 1 : NULL, use_half_float);
+			IMB_exr_add_channel(exrhandle, layerName, "B", viewName, 4, 4 * width, buf ? buf + 2 : NULL, use_half_float);
+			IMB_exr_add_channel(exrhandle, layerName, "A", viewName, 4, 4 * width, buf ? buf + 3 : NULL, use_half_float);
 			break;
 		default:
 			break;
@@ -227,13 +228,15 @@ OutputOpenExrLayer::OutputOpenExrLayer(const char *name_, DataType datatype_, bo
 }
 
 OutputOpenExrMultiLayerOperation::OutputOpenExrMultiLayerOperation(
-        const RenderData *rd, const bNodeTree *tree, const char *path, char exr_codec, const char *viewName)
+        const RenderData *rd, const bNodeTree *tree, const char *path,
+        char exr_codec, bool exr_half_float, const char *viewName)
 {
 	this->m_rd = rd;
 	this->m_tree = tree;
 	
 	BLI_strncpy(this->m_path, path, sizeof(this->m_path));
 	this->m_exr_codec = exr_codec;
+	this->m_exr_half_float = exr_half_float;
 	this->m_viewName = viewName;
 }
 
@@ -284,7 +287,8 @@ void OutputOpenExrMultiLayerOperation::deinitExecution()
 			if (!layer.imageInput)
 				continue; /* skip unconnected sockets */
 			
-			add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i]

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list