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 caspar::core::blend_mode int_to_blend_mode(std::uint32_t x)
57 return core::blend_mode::normal;
59 return core::blend_mode::darken;
61 return core::blend_mode::lighten;
63 return core::blend_mode::contrast;
65 return core::blend_mode::saturation;
67 return core::blend_mode::color;
69 return core::blend_mode::luminosity;
71 return core::blend_mode::multiply;
73 return core::blend_mode::screen;
74 case 'diss': //no support for the 'dissove' blend mode atm
75 return core::blend_mode::normal;
77 return core::blend_mode::overlay;
79 return core::blend_mode::hard_light;
81 return core::blend_mode::soft_light;
83 return core::blend_mode::difference;
85 return core::blend_mode::exclusion;
87 return core::blend_mode::color_dodge;
89 return core::blend_mode::color_burn;
92 return core::blend_mode::normal;
95 color_mode int_to_color_mode(std::uint16_t x)
97 color_mode mode = static_cast<color_mode>(x);
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:
111 return color_mode::InvalidColorMode;
115 std::wstring color_mode_to_string(color_mode c)
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";
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
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
143 else if (boost::algorithm::iequals(flag, "static")) {
\r
144 result = result | layer_tag::rasterized;
\r
145 result = result & (~layer_tag::explicit_dynamic);
\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
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
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