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
61 friend class layer::mask_info;
62 bool populate(int length, bigendian_file_input_stream& stream, int doc_width, int doc_height);
65 vector_mask_info() : flags_(0)
68 bool enabled() const { return (flags_ & static_cast<std::uint8_t>(flags::disabled)) == 0; }
69 bool linked() const { return (flags_ & static_cast<std::uint8_t>(flags::unlinked)) == 0; }
70 bool inverted() const { return (flags_ & static_cast<std::uint8_t>(flags::inverted)) == static_cast<std::uint8_t>(flags::inverted); }
71 bool unsupported() const { return (flags_ & static_cast<std::uint8_t>(flags::unsupported)) == static_cast<std::uint8_t>(flags::unsupported); }
73 bool empty() { return rect_.empty(); }
75 const rect<int>& rect() const { return rect_; }
80 friend struct layer::impl;
81 friend class layer::vector_mask_info;
83 void read_mask_data(bigendian_file_input_stream&);
84 void read_vector_mask_data(int length, bigendian_file_input_stream& stream, int doc_width, int doc_height)
86 vector_mask_.reset(new vector_mask_info);
87 vector_mask_->populate(length, stream, doc_width, doc_height);
90 image8bit_ptr bitmap_;
91 std::uint8_t default_value_;
95 std::unique_ptr<vector_mask_info> vector_mask_;
96 std::unique_ptr<mask_info> total_mask_;
98 void create_bitmap() {
99 bitmap_ = std::make_shared<image8bit>(rect_.size.width, rect_.size.height, 1);
103 mask_info() : default_value_(0), flags_(0)
106 bool enabled() const { return (flags_ & 2) == 0; }
107 bool linked() const { return (flags_ & 1) == 0; }
108 bool inverted() const { return (flags_ & 4) == 4; }
110 bool empty() const { return rect_.empty(); }
112 bool has_vector() const { return (vector_mask_ && !vector_mask_->empty() && vector_mask_->enabled()); }
113 bool has_bitmap() const { return (!vector_mask_ && !empty()) || (vector_mask_ && total_mask_); }
114 const std::unique_ptr<vector_mask_info>& vector() { return vector_mask_; }
116 const rect<int>& rect() const { return rect_; }
117 const image8bit_ptr& bitmap() const { return bitmap_; }
122 void populate(bigendian_file_input_stream&, const psd_document&);
123 void read_channel_data(bigendian_file_input_stream&);
125 const std::wstring& name() const;
127 int sheet_color() const;
129 bool is_position_protected();
131 double text_scale() const;
132 bool is_text() const;
133 const boost::property_tree::wptree& text_data() const;
135 bool is_solid() const;
136 color<std::uint8_t> solid_color() const;
138 bool has_timeline() const;
139 const boost::property_tree::wptree& timeline_data() const;
141 const point<int>& location() const;
142 const size<int>& size() const;
143 const image8bit_ptr& bitmap() const;
145 layer_type group_mode() const;
147 int link_group_id() const;
148 void set_link_group_id(int id);