2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
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.
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.
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/>.
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
22 #include <boost/algorithm/string.hpp>
27 namespace caspar { namespace psd {
29 layer_type int_to_layer_type(std::uint32_t x, std::uint32_t y)
32 return (y == 1) ? layer_type::timeline_group : layer_type::group;
34 return layer_type::group_delimiter;
36 return layer_type::content;
39 std::wstring layer_type_to_string(layer_type b)
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";
52 blend_mode int_to_blend_mode(std::uint32_t x)
54 blend_mode mode = static_cast<blend_mode>(x);
58 case blend_mode::Normal:
59 case blend_mode::Darken:
60 case blend_mode::Lighten:
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:
77 return blend_mode::InvalidBlendMode;
81 std::wstring blend_mode_to_string(blend_mode b)
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";
106 color_mode int_to_color_mode(std::uint16_t x)
108 color_mode mode = static_cast<color_mode>(x);
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:
122 return color_mode::InvalidColorMode;
126 std::wstring color_mode_to_string(color_mode c)
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";
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
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
154 else if (boost::algorithm::iequals(flag, "static")) {
\r
155 result = result | layer_tag::rasterized;
\r
156 result = result & (~layer_tag::explicit_dynamic);
\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
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
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