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
24 #include "util/bigendian_file_input_stream.h"
29 #include <boost/property_tree/ptree_fwd.hpp>
33 #include <common/memory.h>
35 namespace caspar { namespace psd {
38 typedef std::shared_ptr<layer> layer_ptr;
44 spl::shared_ptr<impl> impl_;
49 class vector_mask_info
53 std::vector<point<int>> knots_;
\r
55 friend class layer::mask_info;
56 bool populate(int length, bigendian_file_input_stream& stream, int doc_width, int doc_height);
67 vector_mask_info() : flags_(0)
70 bool enabled() const { return (flags_ & static_cast<std::uint8_t>(flags::disabled)) == 0; }
71 bool linked() const { return (flags_ & static_cast<std::uint8_t>(flags::unlinked)) == 0; }
72 bool inverted() const { return (flags_ & static_cast<std::uint8_t>(flags::inverted)) == static_cast<std::uint8_t>(flags::inverted); }
73 bool unsupported() const { return (flags_ & static_cast<std::uint8_t>(flags::unsupported)) == static_cast<std::uint8_t>(flags::unsupported); }
75 bool empty() { return rect_.empty() && knots_.empty(); }
77 const psd::rect<int>& rect() const { return rect_; }
78 const std::vector<point<int>>& knots() const { return knots_; }
83 friend struct layer::impl;
84 friend class layer::vector_mask_info;
86 void read_mask_data(bigendian_file_input_stream&);
87 void read_vector_mask_data(int length, bigendian_file_input_stream& stream, int doc_width, int doc_height)
89 vector_mask_.reset(new vector_mask_info);
90 vector_mask_->populate(length, stream, doc_width, doc_height);
93 image8bit_ptr bitmap_;
94 std::uint8_t default_value_;
98 std::unique_ptr<vector_mask_info> vector_mask_;
99 std::unique_ptr<mask_info> total_mask_;
101 void create_bitmap() {
102 bitmap_ = std::make_shared<image8bit>(rect_.size.width, rect_.size.height, 1);
106 mask_info() : default_value_(0), flags_(0)
109 bool enabled() const { return (flags_ & 2) == 0; }
110 bool linked() const { return (flags_ & 1) == 0; }
111 bool inverted() const { return (flags_ & 4) == 4; }
113 bool empty() const { return rect_.empty(); }
115 bool has_vector() const { return (vector_mask_ && !vector_mask_->empty() && vector_mask_->enabled()); }
116 bool has_bitmap() const { return (!vector_mask_ && !empty()) || (vector_mask_ && total_mask_); }
117 const std::unique_ptr<vector_mask_info>& vector() const { return vector_mask_; }
119 const psd::rect<int>& rect() const { return rect_; }
120 const image8bit_ptr& bitmap() const { return bitmap_; }
125 void populate(bigendian_file_input_stream&, const psd_document&);
126 void read_channel_data(bigendian_file_input_stream&);
128 const std::wstring& name() const;
130 caspar::core::blend_mode blend_mode() const;
131 int sheet_color() const;
133 bool is_position_protected();
135 const mask_info& mask() const;
137 const psd::point<double>& text_pos() const;
138 const psd::point<double>& scale() const;
139 const double angle() const;
140 const double shear() const;
142 bool is_text() const;
143 const boost::property_tree::wptree& text_data() const;
145 bool is_solid() const;
146 color<std::uint8_t> solid_color() const;
148 bool has_timeline() const;
149 const boost::property_tree::wptree& timeline_data() const;
151 const point<int>& location() const;
152 const psd::size<int>& size() const;
153 const image8bit_ptr& bitmap() const;
155 layer_type group_mode() const;
157 int link_group_id() const;
158 void set_link_group_id(int id);
160 bool is_explicit_dynamic() const;
161 bool is_static() const;
162 bool is_movable() const;
163 bool is_resizable() const;
164 bool is_placeholder() const;
165 bool is_cornerpin() const;
166 layer_tag tags() const;
169 ENUM_ENABLE_BITWISE(layer::vector_mask_info::flags);