]> git.sesse.net Git - casparcg/blob - modules/psd/misc.h
support for rectangular vectors masks in PSD-files with binding to crop transform
[casparcg] / modules / psd / misc.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 #include <common/except.h>\r
25 #include <common/enum_class.h>\r
26 \r
27 #include <string>\r
28 #include <cstdint>\r
29 \r
30 namespace caspar { namespace psd {\r
31         \r
32 template<typename T>\r
33 struct point\r
34 {\r
35         point() : x(0), y(0) {}\r
36         point(T x1, T y1) : x(x1), y(y1) {}\r
37         T x;\r
38         T y;\r
39 \r
40         void clear() { x = 0; y = 0; }\r
41 };\r
42 \r
43 template<typename T>\r
44 struct color\r
45 {\r
46         T red           = 0;\r
47         T green         = 0;\r
48         T blue          = 0;\r
49         T alpha         = 0;\r
50 \r
51         std::uint32_t to_uint32()\r
52         {\r
53                 return (alpha << 24) + (red << 16) + (green << 8) + blue;\r
54         }\r
55 };\r
56 \r
57 template<typename T>\r
58 struct size\r
59 {\r
60         size() : width(0), height(0) {}\r
61         size(T w, T h) : width(w), height(h) {}\r
62         T width;\r
63         T height;\r
64 \r
65         void clear() { width = 0; height = 0; }\r
66 };\r
67 \r
68 template<typename T>\r
69 struct rect\r
70 {\r
71         point<T>                location;\r
72         psd::size<T>    size;\r
73 \r
74         bool empty() const { return size.width == 0 || size.height == 0; }\r
75         void clear() { location.clear(); size.clear(); }\r
76 };\r
77 \r
78 struct psd_file_format_exception : virtual caspar_exception {};\r
79 \r
80 enum class channel_type\r
81 {\r
82         total_user_mask = -3,\r
83         user_mask = -2,\r
84         transparency = -1,\r
85         color_red = 0,\r
86         color_green = 1,\r
87         color_blue = 2\r
88 };\r
89 \r
90 enum class layer_type\r
91 {\r
92         content = 0,\r
93         group,\r
94         timeline_group,\r
95         group_delimiter\r
96 };\r
97 layer_type int_to_layer_type(std::uint32_t x, std::uint32_t y);\r
98 std::wstring layer_type_to_string(layer_type b);\r
99 \r
100 enum class blend_mode\r
101 {\r
102         InvalidBlendMode = -1,\r
103         Normal = 'norm',\r
104         Darken = 'dark',\r
105         Lighten = 'lite',\r
106         Hue = 'hue ',\r
107         Saturation = 'sat ',\r
108         Color = 'colr',\r
109         Luminosity = 'lum ',\r
110         Multiply = 'mul ',\r
111         Screen = 'scrn',\r
112         Dissolve = 'diss',\r
113         Overlay = 'over',\r
114         HardLight = 'hLit',\r
115         SoftLight = 'sLit',\r
116         Difference = 'diff',\r
117         Exclusion = 'smud',\r
118         ColorDodge = 'div ',\r
119         ColorBurn = 'idiv'\r
120 };\r
121 \r
122 blend_mode int_to_blend_mode(std::uint32_t x);\r
123 std::wstring blend_mode_to_string(blend_mode b);\r
124 \r
125 enum class color_mode\r
126 {\r
127         InvalidColorMode = -1,\r
128         Bitmap = 0,\r
129         Grayscale = 1,\r
130         Indexed = 2,\r
131         RGB = 3,\r
132         CMYK = 4,\r
133         Multichannel = 7,\r
134         Duotone = 8,\r
135         Lab = 9\r
136 };\r
137 \r
138 color_mode int_to_color_mode(std::uint16_t x);\r
139 std::wstring color_mode_to_string(color_mode c);\r
140 \r
141 \r
142 enum class layer_tag : int {\r
143         none = 0,\r
144         placeholder = 1,\r
145         explicit_dynamic = 2,\r
146         moveable = 4,\r
147         resizable = 8,\r
148         rasterized = 16,\r
149         cornerpin = 32,\r
150         all = 63\r
151 };\r
152 ENUM_ENABLE_BITWISE(layer_tag);\r
153 \r
154 inline layer_tag operator ~ (layer_tag rhs)\r
155 {\r
156         return (layer_tag)(static_cast<int>(layer_tag::all) ^ static_cast<int>(rhs));\r
157 }\r
158 \r
159 layer_tag string_to_layer_tags(const std::wstring& str);\r
160 \r
161 }       //namespace psd\r
162 }       //namespace caspar\r
163 \r