]> git.sesse.net Git - casparcg/blob - modules/psd/misc.cpp
Merge branch '2.1.0' of https://github.com/CasparCG/Server into 2.1.0
[casparcg] / modules / psd / misc.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
20 */
21
22 #include <boost/algorithm/string.hpp>
23 #include <vector>
24
25 #include "misc.h"
26
27 namespace caspar { namespace psd {
28
29 layer_type int_to_layer_type(std::uint32_t x, std::uint32_t y)
30 {
31         if (x == 1 || x == 2)
32                 return (y == 1) ? layer_type::timeline_group : layer_type::group;
33         else if (x == 3)
34                 return layer_type::group_delimiter;
35
36         return layer_type::content;
37 }
38
39 std::wstring layer_type_to_string(layer_type b)
40 {
41         switch (b)
42         {
43         case layer_type::content: return L"Content";
44         case layer_type::group: return L"Group";
45         case layer_type::timeline_group: return L"TimelineGroup";
46         case layer_type::group_delimiter: return L"GroupDelimiter";
47         default: return L"Invalid";
48         }
49 }
50
51
52 caspar::core::blend_mode int_to_blend_mode(std::uint32_t x)
53 {
54         switch (x)
55         {
56         case 'norm':
57                 return core::blend_mode::normal;
58         case 'dark':
59                 return core::blend_mode::darken;
60         case 'lite':
61                 return core::blend_mode::lighten;
62         case'hue ':
63                 return core::blend_mode::contrast;
64         case 'sat ':
65                 return core::blend_mode::saturation;
66         case 'colr':
67                 return core::blend_mode::color;
68         case 'lum ':
69                 return core::blend_mode::luminosity;
70         case 'mul ':
71                 return core::blend_mode::multiply;
72         case 'scrn':
73                 return core::blend_mode::screen;
74         case 'diss':    //no support for the 'dissove' blend mode atm
75                 return core::blend_mode::normal;
76         case 'over':
77                 return core::blend_mode::overlay;
78         case 'hLit':
79                 return core::blend_mode::hard_light;
80         case 'sLit':
81                 return core::blend_mode::soft_light;
82         case 'diff':
83                 return core::blend_mode::difference;
84         case 'smud':
85                 return core::blend_mode::exclusion;
86         case 'div ':
87                 return core::blend_mode::color_dodge;
88         case 'idiv':
89                 return core::blend_mode::color_burn;
90         }
91
92         return core::blend_mode::normal;
93 }
94
95 color_mode int_to_color_mode(std::uint16_t x)
96 {
97         color_mode mode = static_cast<color_mode>(x);
98
99         switch(mode)
100         {
101                 case color_mode::Bitmap:
102                 case color_mode::Grayscale:
103                 case color_mode::Indexed:
104                 case color_mode::RGB:
105                 case color_mode::CMYK:
106                 case color_mode::Multichannel:
107                 case color_mode::Duotone:
108                 case color_mode::Lab:
109                         return mode;
110                 default:
111                         return color_mode::InvalidColorMode;
112         };
113 }
114
115 std::wstring color_mode_to_string(color_mode c)
116 {
117         switch(c)
118         {
119                 case color_mode::Bitmap: return L"Bitmap";
120                 case color_mode::Grayscale:     return L"Grayscale";
121                 case color_mode::Indexed: return L"Indexed";
122                 case color_mode::RGB: return L"RGB";
123                 case color_mode::CMYK: return L"CMYK";
124                 case color_mode::Multichannel: return L"Multichannel";
125                 case color_mode::Duotone: return L"Duotone";
126                 case color_mode::Lab: return L"Lab";
127                 default: return L"Invalid";
128         };
129 }
130
131 layer_tag string_to_layer_tags(const std::wstring& str) {\r
132         std::vector<std::wstring> flags;\r
133         boost::split(flags, str, boost::is_any_of(L", "), boost::token_compress_on);\r
134 \r
135         layer_tag result = layer_tag::none;\r
136         for (auto& flag : flags) {\r
137                 if (boost::algorithm::iequals(flag, "producer"))\r
138                         result = result | layer_tag::placeholder;\r
139                 else if (boost::algorithm::iequals(flag, "dynamic")) {\r
140                         result = result | layer_tag::explicit_dynamic;\r
141                         result = result & (~layer_tag::rasterized);\r
142                 }\r
143                 else if (boost::algorithm::iequals(flag, "static")) {\r
144                         result = result | layer_tag::rasterized;\r
145                         result = result & (~layer_tag::explicit_dynamic);\r
146                 }\r
147                 else if (boost::algorithm::iequals(flag, "movable")) {\r
148                         result = result | layer_tag::moveable;\r
149                         result = result & (~layer_tag::resizable);\r
150                         result = result & (~layer_tag::explicit_dynamic);\r
151                 }\r
152                 else if (boost::algorithm::iequals(flag, "resizable")) {\r
153                         result = result | layer_tag::resizable;\r
154                         result = result & (~layer_tag::moveable);\r
155                         result = result & (~layer_tag::explicit_dynamic);\r
156                 }\r
157                 else if (boost::algorithm::iequals(flag, "cornerpin")) {\r
158                         result = result | layer_tag::cornerpin;\r
159                         result = result & (~layer_tag::resizable);\r
160                         result = result & (~layer_tag::explicit_dynamic);\r
161                 }\r
162         }\r
163 \r
164         return result;\r
165 }
166
167
168 }       //namespace psd
169 }       //namespace caspar