]> git.sesse.net Git - casparcg/blob - modules/psd/layer.h
binding between linked layers in psd-import/scene-producer
[casparcg] / modules / psd / layer.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
20 */
21
22 #ifndef _PSDLAYER_H__
23 #define _PSDLAYER_H__
24
25 #pragma once
26
27 #include <vector>
28 #include <string>
29 #include <memory>
30 #include "util\bigendian_file_input_stream.h"
31
32 #include "image.h"
33 #include "misc.h"
34 #include "channel.h"
35 #include <boost/property_tree/ptree.hpp>
36
37 namespace caspar { namespace psd {
38
39 class layer;
40 typedef std::shared_ptr<layer> layer_ptr;
41
42 class layer
43 {
44 public:
45         class layer_mask
46         {
47                 friend class layer;
48         public:
49
50                 bool enabled() { return (flags_ & 2) == 0; }
51                 bool linked() { return (flags_ & 1) == 0;  }
52                 bool inverted() { return (flags_ & 4) == 4; }
53
54                 void read_mask_data(BEFileInputStream&);
55
56                 char                    mask_id_;
57                 image8bit_ptr   mask_;
58                 psd::rect<long> rect_;
59                 unsigned char   default_value_;
60                 unsigned char   flags_;
61         };
62
63         layer() : blend_mode_(InvalidBlendMode), link_group_id_(0), opacity_(255), baseClipping_(false), flags_(0), protection_flags_(0), masks_(0)
64         {}
65
66         static std::shared_ptr<layer> create(BEFileInputStream&);
67         void populate(BEFileInputStream&);
68         void read_channel_data(BEFileInputStream&);
69
70         const std::wstring& name() const
71         {
72                 return name_;
73         }
74         const psd::rect<long>& rect() const
75         {
76                 return rect_;
77         }
78
79         unsigned char opacity() const
80         {
81                 return opacity_;
82         }
83
84         unsigned short flags() const
85         {
86                 return flags_;
87         }
88
89         bool visible() { return (flags_ & 2) == 0; }    //the (PSD file-format) documentation is is saying the opposite but what the heck
90         bool is_position_protected() { return (protection_flags_& 4) == 4; }
91         bool is_text() const;
92
93         const boost::property_tree::wptree& text_data() const { return text_layer_info_; }
94
95         const image8bit_ptr& image() const { return image_; }
96
97         const layer_mask& mask_info() const { return mask_; }
98         const image8bit_ptr& mask() const { return mask_.mask_; }
99
100         int link_group_id() { return link_group_id_; }
101         void set_link_group_id(int id) { link_group_id_ = id; }
102
103 private:
104         channel_ptr get_channel(channel_type);
105         void read_blending_ranges(BEFileInputStream&);
106
107         caspar::psd::rect<long>                 rect_;
108         std::vector<channel_ptr>                channels_;
109         blend_mode                                              blend_mode_;
110         int                                                             link_group_id_;
111         unsigned char                                   opacity_;
112         bool                                                    baseClipping_;
113         unsigned char                                   flags_;
114         int                                                             protection_flags_;
115         std::wstring                                    name_;
116         char                                                    masks_;
117
118         layer_mask                                              mask_;
119
120         image8bit_ptr                                   image_;
121
122         boost::property_tree::wptree    text_layer_info_;
123 };
124
125 }       //namespace psd
126 }       //namespace caspar
127
128 #endif  //_PSDLAYER_H__