1 /*
2 Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
3 All Rights Reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 * Redistributions of source code must retain the above copyright
9   notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11   notice, this list of conditions and the following disclaimer in the
12   documentation and/or other materials provided with the distribution.
13 * Neither the name of Sony Pictures Imageworks nor the names of its
14   contributors may be used to endorse or promote products derived from
15   this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include <string>
30 
31 #include <OpenColorIO/OpenColorIO.h>
32 
33 #include "Display.h"
34 #include "ParseUtils.h"
35 
36 OCIO_NAMESPACE_ENTER
37 {
38 
39     DisplayMap::iterator find_display(DisplayMap & displays, const std::string & display)
40     {
41         for(DisplayMap::iterator iter = displays.begin();
42             iter != displays.end();
43             ++iter)
44         {
45             if(StrEqualsCaseIgnore(display, iter->first)) return iter;
46         }
47         return displays.end();
48     }
49 
50     DisplayMap::const_iterator find_display_const(const DisplayMap & displays, const std::string & display)
51     {
52         for(DisplayMap::const_iterator iter = displays.begin();
53             iter != displays.end();
54             ++iter)
55         {
56             if(StrEqualsCaseIgnore(display, iter->first)) return iter;
57         }
58         return displays.end();
59     }
60 
61     int find_view(const ViewVec & vec, const std::string & name)
62     {
63         for(unsigned int i=0; i<vec.size(); ++i)
64         {
65             if(StrEqualsCaseIgnore(name, vec[i].name)) return i;
66         }
67         return -1;
68     }
69 
70     void AddDisplay(DisplayMap & displays,
71                     const std::string & display,
72                     const std::string & view,
73                     const std::string & colorspace,
74                     const std::string & looks)
75     {
76         DisplayMap::iterator iter = find_display(displays, display);
77         if(iter == displays.end())
78         {
79             ViewVec views;
80             views.push_back( View(view, colorspace, looks) );
81             displays[display] = views;
82         }
83         else
84         {
85             ViewVec & views = iter->second;
86             int index = find_view(views, view);
87             if(index<0)
88             {
89                 views.push_back( View(view, colorspace, looks) );
90             }
91             else
92             {
93                 views[index].colorspace = colorspace;
94                 views[index].looks = looks;
95             }
96         }
97     }
98 
99     void ComputeDisplays(StringVec & displayCache,
100                          const DisplayMap & displays,
101                          const StringVec & activeDisplays,
102                          const StringVec & activeDisplaysEnvOverride)
103     {
104         displayCache.clear();
105 
106         StringVec displayMasterList;
107         for(DisplayMap::const_iterator iter = displays.begin();
108             iter != displays.end();
109             ++iter)
110         {
111             displayMasterList.push_back(iter->first);
112         }
113 
114         // Apply the env override if it's not empty.
115         if(!activeDisplaysEnvOverride.empty())
116         {
117             displayCache = IntersectStringVecsCaseIgnore(activeDisplaysEnvOverride, displayMasterList);
118             if(!displayCache.empty()) return;
119         }
120         // Otherwise, aApply the active displays if it's not empty.
121         else if(!activeDisplays.empty())
122         {
123             displayCache = IntersectStringVecsCaseIgnore(activeDisplays, displayMasterList);
124             if(!displayCache.empty()) return;
125         }
126 
127         displayCache = displayMasterList;
128     }
129 
130 }
131 OCIO_NAMESPACE_EXIT
132 
133 ///////////////////////////////////////////////////////////////////////////////
134 
135 #ifdef OCIO_UNIT_TEST
136 
137 namespace OCIO = OCIO_NAMESPACE;
138 #include "UnitTest.h"
139 
OIIO_ADD_TEST(Display,Basic)140 OIIO_ADD_TEST(Display, Basic)
141 {
142 
143 }
144 
145 #endif // OCIO_UNIT_TEST