]> git.sesse.net Git - casparcg/blob - modules/psd/layer.h
* added parsing of text-layer data
[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), opacity_(255), baseClipping_(false), flags_(0), masks_(0)
64         {}
65
66         static std::shared_ptr<layer> create(BEFileInputStream&);
67         void read_channel_data(BEFileInputStream&);
68
69         const std::wstring& name() const
70         {
71                 return name_;
72         }
73         const psd::rect<long>& rect() const
74         {
75                 return rect_;
76         }
77
78         unsigned char opacity() const
79         {
80                 return opacity_;
81         }
82
83         unsigned short flags() const
84         {
85                 return flags_;
86         }
87
88         bool visible() { return (flags_ & 2) == 0; }    //the (PSD file-format) documentation is is saying the opposite but what the heck
89         bool is_text() const;
90
91         const boost::property_tree::wptree& text_data() const { return text_layer_info_; }
92
93         const image8bit_ptr& image() const { return image_; }
94
95         const layer_mask& mask_info() const { return mask_; }
96         const image8bit_ptr& mask() const { return mask_.mask_; }
97
98 private:
99         channel_ptr get_channel(channel_type);
100         void read_blending_ranges(BEFileInputStream&);
101
102         caspar::psd::rect<long>                 rect_;
103         std::vector<channel_ptr>                channels_;
104         blend_mode                                              blend_mode_;
105         unsigned char                                   opacity_;
106         bool                                                    baseClipping_;
107         unsigned char                                   flags_;
108         std::wstring                                    name_;
109         char                                                    masks_;
110
111         layer_mask                                              mask_;
112
113         image8bit_ptr                                   image_;
114
115         boost::property_tree::wptree    text_layer_info_;
116 };
117
118 }       //namespace psd
119 }       //namespace caspar
120
121 #endif  //_PSDLAYER_H__