diff options
author | Guillaume Chereau <guillaumec> | 2018-03-16 00:07:37 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-03-16 01:05:16 +0300 |
commit | e56fd59f22cb45ed4780b443b7245483dd5509ad (patch) | |
tree | adf8e71bfc3364a59e36d8ef690275cf96178ad1 /intern/cycles | |
parent | 41149ca134ff1ffe1029e3eebf1c6b3e95ef4422 (diff) |
Code refactor: move OIIO image buffer writing outside session, into callback.
Original patch by Guillaume, modifications by Brecht.
Differential Revision: https://developer.blender.org/D3102
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/app/cycles_standalone.cpp | 32 | ||||
-rw-r--r-- | intern/cycles/render/buffers.cpp | 33 | ||||
-rw-r--r-- | intern/cycles/render/buffers.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/session.cpp | 10 | ||||
-rw-r--r-- | intern/cycles/render/session.h | 8 |
5 files changed, 42 insertions, 42 deletions
diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp index 2d4b0d35e54..c682744f5fa 100644 --- a/intern/cycles/app/cycles_standalone.cpp +++ b/intern/cycles/app/cycles_standalone.cpp @@ -51,6 +51,7 @@ struct Options { SessionParams session_params; bool quiet; bool show_help, interactive, pause; + string output_path; } options; static void session_print(const string& str) @@ -86,6 +87,34 @@ static void session_print_status() session_print(status); } +static bool write_render(const uchar *pixels, int w, int h, int channels) +{ + string msg = string_printf("Writing image %s", options.output_path.c_str()); + session_print(msg); + + ImageOutput *out = ImageOutput::create(options.output_path); + if(!out) { + return false; + } + + ImageSpec spec(w, h, channels, TypeDesc::UINT8); + if(!out->open(options.output_path, spec)) { + return false; + } + + /* conversion for different top/bottom convention */ + out->write_image(TypeDesc::UINT8, + pixels + (h - 1) * w * channels, + AutoStride, + -w * channels, + AutoStride); + + out->close(); + delete out; + + return true; +} + static BufferParams& session_buffer_params() { static BufferParams buffer_params; @@ -120,6 +149,7 @@ static void scene_init() static void session_init() { + options.session_params.write_render_cb = write_render; options.session = new Session(options.session_params); if(options.session_params.background && !options.quiet) @@ -364,7 +394,7 @@ static void options_parse(int argc, const char **argv) "--background", &options.session_params.background, "Render in background, without user interface", "--quiet", &options.quiet, "In background mode, don't print progress messages", "--samples %d", &options.session_params.samples, "Number of samples to render", - "--output %s", &options.session_params.output_path, "File path to write output image", + "--output %s", &options.output_path, "File path to write output image", "--threads %d", &options.session_params.threads, "CPU Rendering Threads", "--width %d", &options.width, "Window width in pixel", "--height %d", &options.height, "Window height in pixel", diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp index 84d10cc477e..6f560380b40 100644 --- a/intern/cycles/render/buffers.cpp +++ b/intern/cycles/render/buffers.cpp @@ -21,7 +21,6 @@ #include "util/util_foreach.h" #include "util/util_hash.h" -#include "util/util_image.h" #include "util/util_math.h" #include "util/util_opengl.h" #include "util/util_time.h" @@ -448,37 +447,5 @@ bool DisplayBuffer::draw_ready() return (draw_width != 0 && draw_height != 0); } -void DisplayBuffer::write(const string& filename) -{ - int w = draw_width; - int h = draw_height; - - if(w == 0 || h == 0) - return; - - if(half_float) - return; - - /* read buffer from device */ - uchar4 *pixels = rgba_byte.copy_from_device(0, w, h); - - /* write image */ - ImageOutput *out = ImageOutput::create(filename); - ImageSpec spec(w, h, 4, TypeDesc::UINT8); - - out->open(filename, spec); - - /* conversion for different top/bottom convention */ - out->write_image(TypeDesc::UINT8, - (uchar*)(pixels + (h-1)*w), - AutoStride, - -w*sizeof(uchar4), - AutoStride); - - out->close(); - - delete out; -} - CCL_NAMESPACE_END diff --git a/intern/cycles/render/buffers.h b/intern/cycles/render/buffers.h index 028bfb83735..dfc98fe2061 100644 --- a/intern/cycles/render/buffers.h +++ b/intern/cycles/render/buffers.h @@ -113,7 +113,6 @@ public: ~DisplayBuffer(); void reset(BufferParams& params); - void write(const string& filename); void draw_set(int width, int height); void draw(Device *device, const DeviceDrawParams& draw_params); diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 41156038558..bb636dd962a 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -55,7 +55,7 @@ Session::Session(const SessionParams& params_) device = Device::create(params.device, stats, params.background); - if(params.background && params.output_path.empty()) { + if(params.background && !params.write_render_cb) { buffers = NULL; display = NULL; } @@ -101,7 +101,7 @@ Session::~Session() wait(); } - if(!params.output_path.empty()) { + if(params.write_render_cb) { /* tonemap and write out image if requested */ delete display; @@ -109,8 +109,10 @@ Session::~Session() display->reset(buffers->params); tonemap(params.samples); - progress.set_status("Writing Image", params.output_path); - display->write(params.output_path); + int w = display->draw_width; + int h = display->draw_height; + uchar4 *pixels = display->rgba_byte.copy_from_device(0, w, h); + params.write_render_cb((uchar*)pixels, w, h, 4); } /* clean up */ diff --git a/intern/cycles/render/session.h b/intern/cycles/render/session.h index 8495d95666b..e63cad0d977 100644 --- a/intern/cycles/render/session.h +++ b/intern/cycles/render/session.h @@ -45,7 +45,6 @@ public: DeviceInfo device; bool background; bool progressive_refine; - string output_path; bool progressive; bool experimental; @@ -71,11 +70,15 @@ public: ShadingSystem shadingsystem; + function<bool(const uchar *pixels, + int width, + int height, + int channels)> write_render_cb; + SessionParams() { background = false; progressive_refine = false; - output_path = ""; progressive = false; experimental = false; @@ -106,7 +109,6 @@ public: { return !(device == params.device && background == params.background && progressive_refine == params.progressive_refine - && output_path == params.output_path /* && samples == params.samples */ && progressive == params.progressive && experimental == params.experimental |