]> git.sesse.net Git - casparcg/blob - modules/psd/misc.cpp
support for rectangular vectors masks in PSD-files with binding to crop transform
[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 blend_mode int_to_blend_mode(std::uint32_t x)
53 {
54         blend_mode mode = static_cast<blend_mode>(x);
55
56         switch (mode)
57         {
58                 case blend_mode::Normal:
59                 case blend_mode::Darken:
60                 case blend_mode::Lighten:
61                 case blend_mode::Hue:
62                 case blend_mode::Saturation:
63                 case blend_mode::Color:
64                 case blend_mode::Luminosity:
65                 case blend_mode::Multiply:
66                 case blend_mode::Screen:
67                 case blend_mode::Dissolve:
68                 case blend_mode::Overlay:
69                 case blend_mode::HardLight:
70                 case blend_mode::SoftLight:
71                 case blend_mode::Difference:
72                 case blend_mode::Exclusion:
73                 case blend_mode::ColorDodge:
74                 case blend_mode::ColorBurn:
75                         return mode;
76                 default:
77                         return blend_mode::InvalidBlendMode;
78         }
79 }
80
81 std::wstring blend_mode_to_string(blend_mode b)
82 {
83         switch(b)
84         {
85                 case blend_mode::Normal: return L"Normal";
86                 case blend_mode::Darken: return L"Darken";
87                 case blend_mode::Lighten: return L"Lighten";
88                 case blend_mode::Hue: return L"Hue";
89                 case blend_mode::Saturation: return L"Saturation";
90                 case blend_mode::Color: return L"Color";
91                 case blend_mode::Luminosity: return L"Luminosity";
92                 case blend_mode::Multiply: return L"Multiply";
93                 case blend_mode::Screen: return L"Screen";
94                 case blend_mode::Dissolve: return L"Dissolve";
95                 case blend_mode::Overlay: return L"Overlay";
96                 case blend_mode::HardLight: return L"HardLight";
97                 case blend_mode::SoftLight: return L"SoftLight";
98                 case blend_mode::Difference: return L"Difference";
99                 case blend_mode::Exclusion: return L"Exclusion";
100                 case blend_mode::ColorDodge: return L"ColorDodge";
101                 case blend_mode::ColorBurn: return L"ColorBurn";
102                 default: return L"Invalid";
103         }
104 }
105
106 color_mode int_to_color_mode(std::uint16_t x)
107 {
108         color_mode mode = static_cast<color_mode>(x);
109
110         switch(mode)
111         {
112                 case color_mode::Bitmap:
113                 case color_mode::Grayscale:
114                 case color_mode::Indexed:
115                 case color_mode::RGB:
116                 case color_mode::CMYK:
117                 case color_mode::Multichannel:
118                 case color_mode::Duotone:
119                 case color_mode::Lab:
120                         return mode;
121                 default:
122                         return color_mode::InvalidColorMode;
123         };
124 }
125
126 std::wstring color_mode_to_string(color_mode c)
127 {
128         switch(c)
129         {
130                 case color_mode::Bitmap: return L"Bitmap";
131                 case color_mode::Grayscale:     return L"Grayscale";
132                 case color_mode::Indexed: return L"Indexed";
133                 case color_mode::RGB: return L"RGB";
134                 case color_mode::CMYK: return L"CMYK";
135                 case color_mode::Multichannel: return L"Multichannel";
136                 case color_mode::Duotone: return L"Duotone";
137                 case color_mode::Lab: return L"Lab";
138                 default: return L"Invalid";
139         };
140 }
141
142 layer_tag string_to_layer_tags(const std::wstring& str) {\r
143         std::vector<std::wstring> flags;\r
144         boost::split(flags, str, boost::is_any_of(L", "), boost::token_compress_on);\r
145 \r
146         layer_tag result = layer_tag::none;\r
147         for (auto& flag : flags) {\r
148                 if (boost::algorithm::iequals(flag, "producer"))\r
149                         result = result | layer_tag::placeholder;\r
150                 else if (boost::algorithm::iequals(flag, "dynamic")) {\r
151                         result = result | layer_tag::explicit_dynamic;\r
152                         result = result & (~layer_tag::rasterized);\r
153                 }\r
154                 else if (boost::algorithm::iequals(flag, "static")) {\r
155                         result = result | layer_tag::rasterized;\r
156                         result = result & (~layer_tag::explicit_dynamic);\r
157                 }\r
158                 else if (boost::algorithm::iequals(flag, "movable")) {\r
159                         result = result | layer_tag::moveable;\r
160                         result = result & (~layer_tag::resizable);\r
161                         result = result & (~layer_tag::explicit_dynamic);\r
162                 }\r
163                 else if (boost::algorithm::iequals(flag, "resizable")) {\r
164                         result = result | layer_tag::resizable;\r
165                         result = result & (~layer_tag::moveable);\r
166                         result = result & (~layer_tag::explicit_dynamic);\r
167                 }\r
168                 else if (boost::algorithm::iequals(flag, "cornerpin")) {\r
169                         result = result | layer_tag::cornerpin;\r
170                         result = result & (~layer_tag::resizable);\r
171                         result = result & (~layer_tag::explicit_dynamic);\r
172                 }\r
173         }\r
174 \r
175         return result;\r
176 }
177
178
179 }       //namespace psd
180 }       //namespace caspar