1 | |
2 | // |
3 | // This source file is part of appleseed. |
4 | // Visit http://appleseedhq.net/ for additional information and resources. |
5 | // |
6 | // This software is released under the MIT license. |
7 | // |
8 | // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited |
9 | // Copyright (c) 2014-2017 Francois Beaune, The appleseedhq Organization |
10 | // |
11 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | // of this software and associated documentation files (the "Software"), to deal |
13 | // in the Software without restriction, including without limitation the rights |
14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15 | // copies of the Software, and to permit persons to whom the Software is |
16 | // furnished to do so, subject to the following conditions: |
17 | // |
18 | // The above copyright notice and this permission notice shall be included in |
19 | // all copies or substantial portions of the Software. |
20 | // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 | // THE SOFTWARE. |
28 | // |
29 | |
30 | // Interface header. |
31 | #include "progresstilecallback.h" |
32 | |
33 | // appleseed.renderer headers. |
34 | #include "renderer/api/frame.h" |
35 | #include "renderer/api/log.h" |
36 | |
37 | // appleseed.foundation headers. |
38 | #include "foundation/image/canvasproperties.h" |
39 | #include "foundation/image/image.h" |
40 | #include "foundation/image/tile.h" |
41 | #include "foundation/utility/string.h" |
42 | |
43 | // Standard headers. |
44 | #include <string> |
45 | |
46 | using namespace foundation; |
47 | using namespace renderer; |
48 | using namespace std; |
49 | |
50 | namespace appleseed { |
51 | namespace cli { |
52 | |
53 | // |
54 | // ProgressTileCallback class implementation. |
55 | // |
56 | |
57 | ProgressTileCallback::ProgressTileCallback(Logger& logger) |
58 | : m_logger(logger) |
59 | , m_rendered_pixels(0) |
60 | { |
61 | } |
62 | |
63 | void ProgressTileCallback::release() |
64 | { |
65 | // Do nothing. |
66 | } |
67 | |
68 | void ProgressTileCallback::post_render_tile( |
69 | const Frame* frame, |
70 | const size_t tile_x, |
71 | const size_t tile_y) |
72 | { |
73 | boost::mutex::scoped_lock lock(m_mutex); |
74 | do_post_render_tile(frame, tile_x, tile_y); |
75 | } |
76 | |
77 | void ProgressTileCallback::do_post_render_tile( |
78 | const Frame* frame, |
79 | const size_t tile_x, |
80 | const size_t tile_y) |
81 | { |
82 | // Keep track of the total number of rendered pixels. |
83 | const Tile& tile = frame->image().tile(tile_x, tile_y); |
84 | m_rendered_pixels += tile.get_pixel_count(); |
85 | |
86 | // Retrieve the total number of pixels in the frame. |
87 | const size_t total_pixels = frame->image().properties().m_pixel_count; |
88 | |
89 | // Print a progress message. |
90 | LOG_INFO(m_logger, "rendering, %s done" , pretty_percent(m_rendered_pixels, total_pixels).c_str()); |
91 | } |
92 | |
93 | |
94 | // |
95 | // ProgressTileCallbackFactory class implementation. |
96 | // |
97 | |
98 | ProgressTileCallbackFactory::ProgressTileCallbackFactory(Logger& logger) |
99 | : m_callback(new ProgressTileCallback(logger)) |
100 | { |
101 | } |
102 | |
103 | void ProgressTileCallbackFactory::release() |
104 | { |
105 | delete this; |
106 | } |
107 | |
108 | ITileCallback* ProgressTileCallbackFactory::create() |
109 | { |
110 | return m_callback.get(); |
111 | } |
112 | |
113 | } // namespace cli |
114 | } // namespace appleseed |
115 | |