[Bf-blender-cvs] [176bbdc] multiview: Compositor: remove (unify) duplicated code
Dalai Felinto
noreply at git.blender.org
Wed Sep 17 14:12:42 CEST 2014
Commit: 176bbdc3cf4d373e121c3110078345d6de1387e3
Author: Dalai Felinto
Date: Wed Sep 17 13:56:50 2014 +0200
Branches: multiview
https://developer.blender.org/rB176bbdc3cf4d373e121c3110078345d6de1387e3
Compositor: remove (unify) duplicated code
===================================================================
M source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
M source/blender/compositor/operations/COM_OutputFileOperation.cpp
M source/blender/compositor/operations/COM_OutputFileOperation.h
===================================================================
diff --git a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
index 78541d0..79a4439 100644
--- a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
+++ b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cpp
@@ -74,26 +74,7 @@ void *OutputOpenExrSingleLayerMultiViewOperation::get_handle(const char* filenam
continue;
IMB_exr_add_view(exrhandle, srv->name);
-
- /* create channels */
- switch (this->m_datatype) {
- case COM_DT_VALUE:
- IMB_exr_add_channel(exrhandle, NULL, "V", srv->name, 1, width, NULL);
- break;
- case COM_DT_VECTOR:
- IMB_exr_add_channel(exrhandle, NULL, "X", srv->name, 3, 3 * width, NULL);
- IMB_exr_add_channel(exrhandle, NULL, "Y", srv->name, 3, 3 * width, NULL);
- IMB_exr_add_channel(exrhandle, NULL, "Z", srv->name, 3, 3 * width, NULL);
- break;
- case COM_DT_COLOR:
- IMB_exr_add_channel(exrhandle, NULL, "R", srv->name, 4, 4 * width, NULL);
- IMB_exr_add_channel(exrhandle, NULL, "G", srv->name, 4, 4 * width, NULL);
- IMB_exr_add_channel(exrhandle, NULL, "B", srv->name, 4, 4 * width, NULL);
- IMB_exr_add_channel(exrhandle, NULL, "A", srv->name, 4, 4 * width, NULL);
- break;
- default:
- break;
- }
+ add_exr_channels(exrhandle, NULL, this->m_datatype, srv->name, width, NULL);
}
BLI_make_existing_file(filename);
@@ -120,7 +101,6 @@ void OutputOpenExrSingleLayerMultiViewOperation::deinitExecution()
if (width != 0 && height != 0) {
void *exrhandle;
- float *buf = this->m_outputBuffer;
Main *bmain = G.main; /* TODO, have this passed along */
char filename[FILE_MAX];
@@ -128,26 +108,7 @@ void OutputOpenExrSingleLayerMultiViewOperation::deinitExecution()
(this->m_rd->scemode & R_EXTENSION), true, "");
exrhandle = this->get_handle(filename);
-
- /* create channels */
- switch (this->m_datatype) {
- case COM_DT_VALUE:
- IMB_exr_add_channel(exrhandle, NULL, "V", this->m_viewName, 1, width, buf);
- break;
- case COM_DT_VECTOR:
- IMB_exr_add_channel(exrhandle, NULL, "X", this->m_viewName, 3, 3 * width, buf);
- IMB_exr_add_channel(exrhandle, NULL, "Y", this->m_viewName, 3, 3 * width, buf + 1);
- IMB_exr_add_channel(exrhandle, NULL, "Z", this->m_viewName, 3, 3 * width, buf + 2);
- break;
- case COM_DT_COLOR:
- IMB_exr_add_channel(exrhandle, NULL, "R", this->m_viewName, 4, 4 * width, buf);
- IMB_exr_add_channel(exrhandle, NULL, "G", this->m_viewName, 4, 4 * width, buf + 1);
- IMB_exr_add_channel(exrhandle, NULL, "B", this->m_viewName, 4, 4 * width, buf + 2);
- IMB_exr_add_channel(exrhandle, NULL, "A", this->m_viewName, 4, 4 * width, buf + 3);
- break;
- default:
- break;
- }
+ add_exr_channels(exrhandle, NULL, this->m_datatype, this->m_viewName, width, this->m_outputBuffer);
if (this->m_outputBuffer)
MEM_freeN(this->m_outputBuffer);
@@ -197,29 +158,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) {
- const char *layername = this->m_layers[i].name;
-
- /* create channels */
- switch (this->m_layers[i].datatype) {
- case COM_DT_VALUE:
- IMB_exr_add_channel(exrhandle, layername, "V", srv->name, 1, width, NULL);
- break;
- case COM_DT_VECTOR:
- IMB_exr_add_channel(exrhandle, layername, "X", srv->name, 3, 3 * width, NULL);
- IMB_exr_add_channel(exrhandle, layername, "Y", srv->name, 3, 3 * width, NULL);
- IMB_exr_add_channel(exrhandle, layername, "Z", srv->name, 3, 3 * width, NULL);
- break;
- case COM_DT_COLOR:
- IMB_exr_add_channel(exrhandle, layername, "R", srv->name, 4, 4 * width, NULL);
- IMB_exr_add_channel(exrhandle, layername, "G", srv->name, 4, 4 * width, NULL);
- IMB_exr_add_channel(exrhandle, layername, "B", srv->name, 4, 4 * width, NULL);
- IMB_exr_add_channel(exrhandle, layername, "A", srv->name, 4, 4 * width, NULL);
- break;
- default:
- break;
- }
- }
+ 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);
}
BLI_make_existing_file(filename);
@@ -252,30 +192,8 @@ void OutputOpenExrMultiLayerMultiViewOperation::deinitExecution()
exrhandle = this->get_handle(filename);
- for (unsigned int i = 0; i < this->m_layers.size(); ++i) {
- float *buf = this->m_layers[i].outputBuffer;
- const char *layername = this->m_layers[i].name;
-
- /* create channels */
- switch (this->m_layers[i].datatype) {
- case COM_DT_VALUE:
- IMB_exr_add_channel(exrhandle, layername, "V", this->m_viewName, 1, width, buf);
- break;
- case COM_DT_VECTOR:
- IMB_exr_add_channel(exrhandle, layername, "X", this->m_viewName, 3, 3 * width, buf);
- IMB_exr_add_channel(exrhandle, layername, "Y", this->m_viewName, 3, 3 * width, buf + 1);
- IMB_exr_add_channel(exrhandle, layername, "Z", this->m_viewName, 3, 3 * width, buf + 2);
- break;
- case COM_DT_COLOR:
- IMB_exr_add_channel(exrhandle, layername, "R", this->m_viewName, 4, 4 * width, buf);
- IMB_exr_add_channel(exrhandle, layername, "G", this->m_viewName, 4, 4 * width, buf + 1);
- IMB_exr_add_channel(exrhandle, layername, "B", this->m_viewName, 4, 4 * width, buf + 2);
- IMB_exr_add_channel(exrhandle, layername, "A", this->m_viewName, 4, 4 * width, buf + 3);
- break;
- default:
- break;
- }
- }
+ 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);
for (unsigned int i = 0; i < this->m_layers.size(); ++i) {
if (this->m_layers[i].outputBuffer) {
@@ -297,16 +215,6 @@ void OutputOpenExrMultiLayerMultiViewOperation::deinitExecution()
/******************************** Stereo3D ******************************/
-static int get_datatype_size(DataType datatype)
-{
- switch (datatype) {
- case COM_DT_VALUE: return 1;
- case COM_DT_VECTOR: return 3;
- case COM_DT_COLOR: return 4;
- default: return 0;
- }
-}
-
OutputStereoOperation::OutputStereoOperation(
const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path,
const char *name, const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings,
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cpp b/source/blender/compositor/operations/COM_OutputFileOperation.cpp
index d014389..408407b 100644
--- a/source/blender/compositor/operations/COM_OutputFileOperation.cpp
+++ b/source/blender/compositor/operations/COM_OutputFileOperation.cpp
@@ -39,7 +39,30 @@ extern "C" {
# include "IMB_imbuf_types.h"
}
-static int get_datatype_size(DataType datatype)
+void add_exr_channels(void *exrhandle, const char *layerName, const DataType datatype, const char *viewName, const size_t width, float *buf)
+{
+ /* create channels */
+ switch (datatype) {
+ case COM_DT_VALUE:
+ IMB_exr_add_channel(exrhandle, layerName, "V", viewName, 1, width, buf ? buf : NULL);
+ 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);
+ 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);
+ break;
+ default:
+ break;
+ }
+}
+
+int get_datatype_size(DataType datatype)
{
switch (datatype) {
case COM_DT_VALUE: return 1;
@@ -223,29 +246,7 @@ void OutputOpenExrMultiLayerOperation::deinitExecution()
if (!layer.imageInput)
continue; /* skip unconnected sockets */
- const char *layername = this->m_layers[i].name;
- float *buf = this->m_layers[i].outputBuffer;
-
- /* create channels */
- switch (this->m_layers[i].datatype) {
- case COM_DT_VALUE:
- IMB_exr_add_channel(exrhandle, layername, "V", "", 1, width, buf);
- break;
- case COM_DT_VECTOR:
- IMB_exr_add_channel(exrhandle, layername, "X", "", 3, 3 * width, buf);
- IMB_exr_add_channel(exrhandle, layername, "Y", "", 3, 3 * width, buf + 1);
- IMB_exr_add_channel(exrhandle, layername, "Z", "", 3, 3 * width, buf + 2);
- break;
- case COM_DT_COLOR:
- IMB_exr_add_channel(exrhandle, layername, "R", "", 4, 4 * width, buf);
- IMB_exr_add_channel(exrhandle, layername, "G", "", 4, 4 * width, buf + 1);
- IMB_exr_add_channel(exrhandle, layername, "B", "", 4, 4 * width, buf + 2);
- IMB_exr_add_channel(exrhandle, layername, "A", "", 4, 4 * width, buf + 3);
- break;
- default:
- break;
- }
-
+ add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i].datatype, "", width, this->m_layers[i].outputBuffer);
}
/* when the filename has no permissions, this can fail */
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h
index 0bac21b..d9626cd 100644
--- a/source/blender/compositor/operations/COM_OutputFileOperation.h
+++ b/source/blender/compositor/operations/COM_OutputFileOperation.h
@@ -102,4 +102,7 @@ public:
bool isFileOutputOperation() const { return true; }
};
+void add_exr_channels(void *exrhandle, const char *layerName, const DataType datatype, const char *viewName, const size_t width, float *buf);
+int get_datatype_size(DataType datatype);
+
#endif
More information about the Bf-blender-cvs
mailing list