diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/compositor/operations/COM_OutputFileOperation.cpp | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/compositor/operations/COM_OutputFileOperation.cpp')
-rw-r--r-- | source/blender/compositor/operations/COM_OutputFileOperation.cpp | 485 |
1 files changed, 273 insertions, 212 deletions
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cpp b/source/blender/compositor/operations/COM_OutputFileOperation.cpp index 9da3d15883c..f83ce478bd5 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cpp +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cpp @@ -32,279 +32,340 @@ #include "DNA_color_types.h" extern "C" { -# include "MEM_guardedalloc.h" -# include "IMB_imbuf.h" -# include "IMB_colormanagement.h" -# include "IMB_imbuf_types.h" +#include "MEM_guardedalloc.h" +#include "IMB_imbuf.h" +#include "IMB_colormanagement.h" +#include "IMB_imbuf_types.h" } -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) +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, use_half_float); - break; - case COM_DT_VECTOR: - 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, 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; - } + /* create channels */ + switch (datatype) { + case COM_DT_VALUE: + 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, 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, 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; + } } -void free_exr_channels(void *exrhandle, const RenderData *rd, const char *layerName, const DataType datatype) +void free_exr_channels(void *exrhandle, + const RenderData *rd, + const char *layerName, + const DataType datatype) { - SceneRenderView *srv; - - /* check renderdata for amount of views */ - for (srv = (SceneRenderView *) rd->views.first; srv; srv = srv->next) { - float *rect = NULL; - - if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) - continue; - - /* the pointer is stored in the first channel of each datatype */ - switch (datatype) { - case COM_DT_VALUE: - rect = IMB_exr_channel_rect(exrhandle, layerName, "V", srv->name); - break; - case COM_DT_VECTOR: - rect = IMB_exr_channel_rect(exrhandle, layerName, "X", srv->name); - break; - case COM_DT_COLOR: - rect = IMB_exr_channel_rect(exrhandle, layerName, "R", srv->name); - break; - default: - break; - } - if (rect) - MEM_freeN(rect); - } + SceneRenderView *srv; + + /* check renderdata for amount of views */ + for (srv = (SceneRenderView *)rd->views.first; srv; srv = srv->next) { + float *rect = NULL; + + if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) + continue; + + /* the pointer is stored in the first channel of each datatype */ + switch (datatype) { + case COM_DT_VALUE: + rect = IMB_exr_channel_rect(exrhandle, layerName, "V", srv->name); + break; + case COM_DT_VECTOR: + rect = IMB_exr_channel_rect(exrhandle, layerName, "X", srv->name); + break; + case COM_DT_COLOR: + rect = IMB_exr_channel_rect(exrhandle, layerName, "R", srv->name); + break; + default: + break; + } + if (rect) + MEM_freeN(rect); + } } 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; - } + switch (datatype) { + case COM_DT_VALUE: + return 1; + case COM_DT_VECTOR: + return 3; + case COM_DT_COLOR: + return 4; + default: + return 0; + } } static float *init_buffer(unsigned int width, unsigned int height, DataType datatype) { - // When initializing the tree during initial load the width and height can be zero. - if (width != 0 && height != 0) { - int size = get_datatype_size(datatype); - return (float *)MEM_callocN(width * height * size * sizeof(float), "OutputFile buffer"); - } - else - return NULL; + // When initializing the tree during initial load the width and height can be zero. + if (width != 0 && height != 0) { + int size = get_datatype_size(datatype); + return (float *)MEM_callocN(width * height * size * sizeof(float), "OutputFile buffer"); + } + else + return NULL; } -static void write_buffer_rect(rcti *rect, const bNodeTree *tree, - SocketReader *reader, float *buffer, unsigned int width, DataType datatype) +static void write_buffer_rect(rcti *rect, + const bNodeTree *tree, + SocketReader *reader, + float *buffer, + unsigned int width, + DataType datatype) { - float color[4]; - int i, size = get_datatype_size(datatype); - - if (!buffer) return; - int x1 = rect->xmin; - int y1 = rect->ymin; - int x2 = rect->xmax; - int y2 = rect->ymax; - int offset = (y1 * width + x1) * size; - int x; - int y; - bool breaked = false; - - for (y = y1; y < y2 && (!breaked); y++) { - for (x = x1; x < x2 && (!breaked); x++) { - reader->readSampled(color, x, y, COM_PS_NEAREST); - - for (i = 0; i < size; ++i) - buffer[offset + i] = color[i]; - offset += size; - - if (tree->test_break && tree->test_break(tree->tbh)) - breaked = true; - } - offset += (width - (x2 - x1)) * size; - } + float color[4]; + int i, size = get_datatype_size(datatype); + + if (!buffer) + return; + int x1 = rect->xmin; + int y1 = rect->ymin; + int x2 = rect->xmax; + int y2 = rect->ymax; + int offset = (y1 * width + x1) * size; + int x; + int y; + bool breaked = false; + + for (y = y1; y < y2 && (!breaked); y++) { + for (x = x1; x < x2 && (!breaked); x++) { + reader->readSampled(color, x, y, COM_PS_NEAREST); + + for (i = 0; i < size; ++i) + buffer[offset + i] = color[i]; + offset += size; + + if (tree->test_break && tree->test_break(tree->tbh)) + breaked = true; + } + offset += (width - (x2 - x1)) * size; + } } - OutputSingleLayerOperation::OutputSingleLayerOperation( - const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path, - const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings, const char *viewName) + const RenderData *rd, + const bNodeTree *tree, + DataType datatype, + ImageFormatData *format, + const char *path, + const ColorManagedViewSettings *viewSettings, + const ColorManagedDisplaySettings *displaySettings, + const char *viewName) { - this->m_rd = rd; - this->m_tree = tree; + this->m_rd = rd; + this->m_tree = tree; - this->addInputSocket(datatype); + this->addInputSocket(datatype); - this->m_outputBuffer = NULL; - this->m_datatype = datatype; - this->m_imageInput = NULL; + this->m_outputBuffer = NULL; + this->m_datatype = datatype; + this->m_imageInput = NULL; - this->m_format = format; - BLI_strncpy(this->m_path, path, sizeof(this->m_path)); + this->m_format = format; + BLI_strncpy(this->m_path, path, sizeof(this->m_path)); - this->m_viewSettings = viewSettings; - this->m_displaySettings = displaySettings; - this->m_viewName = viewName; + this->m_viewSettings = viewSettings; + this->m_displaySettings = displaySettings; + this->m_viewName = viewName; } void OutputSingleLayerOperation::initExecution() { - this->m_imageInput = getInputSocketReader(0); - this->m_outputBuffer = init_buffer(this->getWidth(), this->getHeight(), this->m_datatype); + this->m_imageInput = getInputSocketReader(0); + this->m_outputBuffer = init_buffer(this->getWidth(), this->getHeight(), this->m_datatype); } void OutputSingleLayerOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/) { - write_buffer_rect(rect, this->m_tree, this->m_imageInput, this->m_outputBuffer, this->getWidth(), this->m_datatype); + write_buffer_rect(rect, + this->m_tree, + this->m_imageInput, + this->m_outputBuffer, + this->getWidth(), + this->m_datatype); } void OutputSingleLayerOperation::deinitExecution() { - if (this->getWidth() * this->getHeight() != 0) { - - int size = get_datatype_size(this->m_datatype); - ImBuf *ibuf = IMB_allocImBuf(this->getWidth(), this->getHeight(), this->m_format->planes, 0); - char filename[FILE_MAX]; - const char *suffix; - - ibuf->channels = size; - ibuf->rect_float = this->m_outputBuffer; - ibuf->mall |= IB_rectfloat; - ibuf->dither = this->m_rd->dither_intensity; - - IMB_colormanagement_imbuf_for_write(ibuf, true, false, m_viewSettings, m_displaySettings, - this->m_format); - - suffix = BKE_scene_multiview_view_suffix_get(this->m_rd, this->m_viewName); - - BKE_image_path_from_imformat( - filename, this->m_path, BKE_main_blendfile_path_from_global(), this->m_rd->cfra, this->m_format, - (this->m_rd->scemode & R_EXTENSION) != 0, true, suffix); - - if (0 == BKE_imbuf_write(ibuf, filename, this->m_format)) - printf("Cannot save Node File Output to %s\n", filename); - else - printf("Saved: %s\n", filename); - - IMB_freeImBuf(ibuf); - } - this->m_outputBuffer = NULL; - this->m_imageInput = NULL; + if (this->getWidth() * this->getHeight() != 0) { + + int size = get_datatype_size(this->m_datatype); + ImBuf *ibuf = IMB_allocImBuf(this->getWidth(), this->getHeight(), this->m_format->planes, 0); + char filename[FILE_MAX]; + const char *suffix; + + ibuf->channels = size; + ibuf->rect_float = this->m_outputBuffer; + ibuf->mall |= IB_rectfloat; + ibuf->dither = this->m_rd->dither_intensity; + + IMB_colormanagement_imbuf_for_write( + ibuf, true, false, m_viewSettings, m_displaySettings, this->m_format); + + suffix = BKE_scene_multiview_view_suffix_get(this->m_rd, this->m_viewName); + + BKE_image_path_from_imformat(filename, + this->m_path, + BKE_main_blendfile_path_from_global(), + this->m_rd->cfra, + this->m_format, + (this->m_rd->scemode & R_EXTENSION) != 0, + true, + suffix); + + if (0 == BKE_imbuf_write(ibuf, filename, this->m_format)) + printf("Cannot save Node File Output to %s\n", filename); + else + printf("Saved: %s\n", filename); + + IMB_freeImBuf(ibuf); + } + this->m_outputBuffer = NULL; + this->m_imageInput = NULL; } /******************************* MultiLayer *******************************/ OutputOpenExrLayer::OutputOpenExrLayer(const char *name_, DataType datatype_, bool use_layer_) { - BLI_strncpy(this->name, name_, sizeof(this->name)); - this->datatype = datatype_; - this->use_layer = use_layer_; + BLI_strncpy(this->name, name_, sizeof(this->name)); + this->datatype = datatype_; + this->use_layer = use_layer_; - /* these are created in initExecution */ - this->outputBuffer = 0; - this->imageInput = 0; + /* these are created in initExecution */ + this->outputBuffer = 0; + this->imageInput = 0; } -OutputOpenExrMultiLayerOperation::OutputOpenExrMultiLayerOperation( - const RenderData *rd, const bNodeTree *tree, const char *path, - char exr_codec, bool exr_half_float, const char *viewName) +OutputOpenExrMultiLayerOperation::OutputOpenExrMultiLayerOperation(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; + 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; + 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; } -void OutputOpenExrMultiLayerOperation::add_layer(const char *name, DataType datatype, bool use_layer) +void OutputOpenExrMultiLayerOperation::add_layer(const char *name, + DataType datatype, + bool use_layer) { - this->addInputSocket(datatype); - this->m_layers.push_back(OutputOpenExrLayer(name, datatype, use_layer)); + this->addInputSocket(datatype); + this->m_layers.push_back(OutputOpenExrLayer(name, datatype, use_layer)); } void OutputOpenExrMultiLayerOperation::initExecution() { - for (unsigned int i = 0; i < this->m_layers.size(); ++i) { - if (this->m_layers[i].use_layer) { - SocketReader *reader = getInputSocketReader(i); - this->m_layers[i].imageInput = reader; - this->m_layers[i].outputBuffer = init_buffer(this->getWidth(), this->getHeight(), this->m_layers[i].datatype); - } - } + for (unsigned int i = 0; i < this->m_layers.size(); ++i) { + if (this->m_layers[i].use_layer) { + SocketReader *reader = getInputSocketReader(i); + this->m_layers[i].imageInput = reader; + this->m_layers[i].outputBuffer = init_buffer( + this->getWidth(), this->getHeight(), this->m_layers[i].datatype); + } + } } void OutputOpenExrMultiLayerOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/) { - for (unsigned int i = 0; i < this->m_layers.size(); ++i) { - OutputOpenExrLayer &layer = this->m_layers[i]; - if (layer.imageInput) - write_buffer_rect(rect, this->m_tree, layer.imageInput, layer.outputBuffer, this->getWidth(), layer.datatype); - } + for (unsigned int i = 0; i < this->m_layers.size(); ++i) { + OutputOpenExrLayer &layer = this->m_layers[i]; + if (layer.imageInput) + write_buffer_rect(rect, + this->m_tree, + layer.imageInput, + layer.outputBuffer, + this->getWidth(), + layer.datatype); + } } void OutputOpenExrMultiLayerOperation::deinitExecution() { - unsigned int width = this->getWidth(); - unsigned int height = this->getHeight(); - if (width != 0 && height != 0) { - char filename[FILE_MAX]; - const char *suffix; - void *exrhandle = IMB_exr_get_handle(); - - suffix = BKE_scene_multiview_view_suffix_get(this->m_rd, this->m_viewName); - BKE_image_path_from_imtype( - filename, this->m_path, BKE_main_blendfile_path_from_global(), this->m_rd->cfra, R_IMF_IMTYPE_MULTILAYER, - (this->m_rd->scemode & R_EXTENSION) != 0, true, suffix); - BLI_make_existing_file(filename); - - for (unsigned int i = 0; i < this->m_layers.size(); ++i) { - OutputOpenExrLayer &layer = this->m_layers[i]; - if (!layer.imageInput) - continue; /* skip unconnected sockets */ - - add_exr_channels(exrhandle, this->m_layers[i].name, this->m_layers[i].datatype, "", width, - this->m_exr_half_float, this->m_layers[i].outputBuffer); - } - - /* when the filename has no permissions, this can fail */ - if (IMB_exr_begin_write(exrhandle, filename, width, height, this->m_exr_codec, NULL)) { - IMB_exr_write_channels(exrhandle); - } - else { - /* TODO, get the error from openexr's exception */ - /* XXX nice way to do report? */ - printf("Error Writing Render Result, see console\n"); - } - - IMB_exr_close(exrhandle); - for (unsigned int i = 0; i < this->m_layers.size(); ++i) { - if (this->m_layers[i].outputBuffer) { - MEM_freeN(this->m_layers[i].outputBuffer); - this->m_layers[i].outputBuffer = NULL; - } - - this->m_layers[i].imageInput = NULL; - } - } + unsigned int width = this->getWidth(); + unsigned int height = this->getHeight(); + if (width != 0 && height != 0) { + char filename[FILE_MAX]; + const char *suffix; + void *exrhandle = IMB_exr_get_handle(); + + suffix = BKE_scene_multiview_view_suffix_get(this->m_rd, this->m_viewName); + BKE_image_path_from_imtype(filename, + this->m_path, + BKE_main_blendfile_path_from_global(), + this->m_rd->cfra, + R_IMF_IMTYPE_MULTILAYER, + (this->m_rd->scemode & R_EXTENSION) != 0, + true, + suffix); + BLI_make_existing_file(filename); + + for (unsigned int i = 0; i < this->m_layers.size(); ++i) { + OutputOpenExrLayer &layer = this->m_layers[i]; + if (!layer.imageInput) + continue; /* skip unconnected sockets */ + + add_exr_channels(exrhandle, + this->m_layers[i].name, + this->m_layers[i].datatype, + "", + width, + this->m_exr_half_float, + this->m_layers[i].outputBuffer); + } + + /* when the filename has no permissions, this can fail */ + if (IMB_exr_begin_write(exrhandle, filename, width, height, this->m_exr_codec, NULL)) { + IMB_exr_write_channels(exrhandle); + } + else { + /* TODO, get the error from openexr's exception */ + /* XXX nice way to do report? */ + printf("Error Writing Render Result, see console\n"); + } + + IMB_exr_close(exrhandle); + for (unsigned int i = 0; i < this->m_layers.size(); ++i) { + if (this->m_layers[i].outputBuffer) { + MEM_freeN(this->m_layers[i].outputBuffer); + this->m_layers[i].outputBuffer = NULL; + } + + this->m_layers[i].imageInput = NULL; + } + } } |