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 "exrutils.h" |
32 | |
33 | // appleseed.foundation headers. |
34 | #include "foundation/image/imageattributes.h" |
35 | #include "foundation/platform/system.h" |
36 | #include "foundation/utility/foreach.h" |
37 | #include "foundation/utility/string.h" |
38 | |
39 | // OpenEXR headers. |
40 | #include "foundation/platform/exrheaderguards.h" |
41 | BEGIN_EXR_INCLUDES |
42 | #include "OpenEXR/ImfStandardAttributes.h" |
43 | #include "OpenEXR/ImfStringAttribute.h" |
44 | #include "OpenEXR/ImfThreading.h" |
45 | END_EXR_INCLUDES |
46 | |
47 | // Standard headers. |
48 | #include <string> |
49 | |
50 | using namespace Imf; |
51 | using namespace std; |
52 | |
53 | namespace foundation |
54 | { |
55 | |
56 | namespace |
57 | { |
58 | struct OpenEXRInitializer |
59 | { |
60 | OpenEXRInitializer() |
61 | { |
62 | setGlobalThreadCount( |
63 | static_cast<int>(System::get_logical_cpu_core_count())); |
64 | } |
65 | }; |
66 | } |
67 | |
68 | void initialize_openexr() |
69 | { |
70 | static OpenEXRInitializer initializer; |
71 | } |
72 | |
73 | void ( |
74 | const ImageAttributes& image_attributes, |
75 | Header& ) |
76 | { |
77 | for (const_each<ImageAttributes> i = image_attributes; i; ++i) |
78 | { |
79 | // Fetch the name and the value of the attribute. |
80 | const string attr_name = i->key(); |
81 | const string attr_value = i->value<string>(); |
82 | |
83 | if (attr_name == "dpi" ) |
84 | addXDensity(header, from_string<float>(attr_value)); |
85 | |
86 | else if (attr_name == "author" ) |
87 | addOwner(header, attr_value); |
88 | |
89 | else if (attr_name == "comment" ) |
90 | addComments(header, attr_value); |
91 | |
92 | else if (attr_name == "creation_time" ) |
93 | addCapDate(header, attr_value); |
94 | |
95 | else |
96 | header.insert(attr_name.c_str(), StringAttribute(attr_value)); |
97 | } |
98 | } |
99 | |
100 | } // namespace foundation |
101 | |