1 #pragma once
2 
3 #ifndef LEVELPROPERTIES_H
4 #define LEVELPROPERTIES_H
5 
6 // TnzCore includes
7 #include "tgeometry.h"
8 
9 #undef DVAPI
10 #undef DVVAR
11 #ifdef TOONZLIB_EXPORTS
12 #define DVAPI DV_EXPORT_API
13 #define DVVAR DV_EXPORT_VAR
14 #else
15 #define DVAPI DV_IMPORT_API
16 #define DVVAR DV_IMPORT_VAR
17 #endif
18 
19 //**********************************************************************************
20 //    LevelOptions  definition
21 //**********************************************************************************
22 
23 /*!
24   \brief    User-editable level properties.
25 
26   \details  Historically, LevelProperties stores properties both accessible
27             to Toonz end-users, and internal to the Toonz application.
28 
29             The user-accessible options have been moved to this nested class
30             to clearly separate them from internal properties of a level.
31 */
32 
33 class DVAPI LevelOptions {
34 public:
35   enum DpiPolicy       //!  Describes the dpi policy used for a level.
36   { DP_ImageDpi  = 0,  //!< Level uses the natural dpi embedded in its images.
37     DP_CustomDpi = 2   //!< Level uses a custom dpi set by the user.
38   };
39 
40 public:
41   double m_dpi;       //!< <TT>[default: Stage::inch]</TT> Dpi used with the
42                       //!  LevelProperties::DP_CustomDpi policy.
43   int m_subsampling,  //!< <TT>[default: 1]</TT> Image subsampling value (see
44                       //!  LevelProperties::setSubsampling()).
45       m_antialias;    //!< <TT>[default: 0]</TT> Antialias amount (\p 0 meaning
46                       //!  no antialias).
47   DpiPolicy m_dpiPolicy;  //!< <TT>[default: DP_ImageDpi]</TT> Dpi policy to be
48                           //! adpoted.
49 
50   bool m_whiteTransp,  //!< <TT>[default: false]</TT> Whether white should be
51                        //!  visualized as transparent.
52       m_premultiply,  //!< <TT>[default: false]</TT> Whether level images should
53                       //! be
54       //!  premultiplied by Toonz for alpha compositing (because they
55       //!  are not).
56       m_isStopMotionLevel;
57 
58 public:
59   LevelOptions();  //!< Constructs with default values.
60 
61   bool operator==(const LevelOptions &opts) const;
62   bool operator!=(const LevelOptions &other) const {
63     return !operator==(other);
64   }
65 };
66 
67 //**********************************************************************************
68 //    LevelProperties  definition
69 //**********************************************************************************
70 
71 /*!
72   \brief    Stores the possible properties of a Toonz level.
73 */
74 
75 class DVAPI LevelProperties {
76 public:
77   /*!
78 \brief        Alias for LevelOptions::DpiPolicy provided for backward
79             compatibility.
80 
81 \deprecated   Use LevelOptions::DpiPolicy instead.
82 */
83 
84   enum DpiPolicy {
85     DP_ImageDpi  = LevelOptions::DP_ImageDpi,
86     DP_CustomDpi = LevelOptions::DP_CustomDpi
87   };
88 
89 public:
90   LevelProperties();
91 
options()92   const LevelOptions &options() const  //!  Returns user-accessible options.
93   {
94     return m_options;
95   }
options()96   LevelOptions &options()  //!  Returns user-accessible options.
97   {
98     return m_options;
99   }
100 
101   /*! \details  The level subsampling is the integer value (strictly
102           greater than 1) denoting the fraction of pixels to be
103           displayed for its images <I>while in camera stand mode</I>.
104           For example, a value of 2 will \a halve the original image
105           resolution.
106 
107           Note that only the crudest algorithm will be applied for
108           resampling, as this feature is explicitly intended to
109           improve visualization speed as much as possible.                    */
110 
111   void setSubsampling(int s);  //!< Sets the level subsampling.
112   int getSubsampling() const;  //!< Returns the level subsampling.
113 
114   /*! \details  The dirty flag is the boolean value specifying whether
115           a level has been altered in any way. Saving operations on
116           levels whose dirty flag is \p false are no-op.                      */
117 
118   void setDirtyFlag(bool on);  //!< Sets the level's <I>dirty flag</I>.
119   bool getDirtyFlag() const;   //!< Returns the level's <I>dirty flag</I>
120 
121   void setDpiPolicy(DpiPolicy dpiPolicy);  //!< Sets the level's DpiPolicy.
122   DpiPolicy getDpiPolicy() const;          //!< Returns the level's DpiPolicy.
123 
124   void setImageDpi(const TPointD &dpi);  //!< Sets the level's \a image dpi.
125   TPointD getImageDpi() const;           //!< Returns the level's \a image dpi.
126 
127   void setDpi(const TPointD &dpi);  //!< Sets the level's \a custom dpi.
128   void setDpi(double dpi);          //!< Sets a uniform \a custom level dpi.
129   TPointD getDpi() const;           //!< Returns the level's \a custom dpi.
130 
131   void setImageRes(
132       const TDimension &d);  //!< Sets the level's known image resolution.
133   TDimension getImageRes()
134       const;  //!< Returns the level's known image resolution.
135 
136   void setBpp(int bpp);  //!< Sets the level's known bits-per-pixel.
137   int getBpp() const;    //!< Returns the level's known bits-per-pixel.
138 
setHasAlpha(bool hasAlpha)139   void setHasAlpha(
140       bool hasAlpha)  //!  Sets whether the level has an alpha channel.
141   {
142     m_hasAlpha = hasAlpha;
143   }
hasAlpha()144   bool hasAlpha() const  //!  Returns whether the level has an alpha channel.
145   {
146     return m_hasAlpha;
147   }
148 
setCreator(const std::string & creator)149   void setCreator(
150       const std::string &creator)  //!  Sets the level's creator string.
151   {
152     m_creator = creator;
153   }
getCreator()154   std::string getCreator() const  //!  Returns the level's creator string.
155   {
156     return m_creator;
157   }
158 
159   /*! \details  A level is forbidden if it has been created with a
160           uncompatible application version (e.g. it was created with
161           Student and loaded with Toonz).                                     */
162 
setIsForbidden(bool forbidden)163   void setIsForbidden(
164       bool forbidden)  //!  Sets whether it is forbidden to edit a level.
165   {
166     m_forbidden = forbidden;
167   }
isForbidden()168   bool isForbidden() const {
169     return m_forbidden;
170   }  //!< Returns whether the level is forbidden for editing.
171 
172   /*! \param    doPremultiply  Whether Toonz must perform premultiplication - ie
173           image pixels are \a not already premultiplied.
174 
175 \details  Images with an alpha channel may or may not store pixels in
176           \a premultiplied form. See the Wikipedia entry on alhpa
177           compositing for further information:
178           http://en.wikipedia.org/wiki/Alpha_compositing
179 
180           Already premultiplied images do not require Toonz to perform
181           additional premultiplication on its own to perform alpha
182           compositing.                                                        */
183 
setDoPremultiply(bool doPremultiply)184   void setDoPremultiply(
185       bool doPremultiply)  //!  Sets whether premultiplication must be applied.
186   {
187     m_options.m_premultiply = doPremultiply;
188   }
doPremultiply()189   bool doPremultiply()
190       const  //!  Returns whether premultiplication must be applied.
191   {
192     return m_options.m_premultiply;
193   }
194 
195   /*! \details  See
196      http://visual-computing.intel-research.net/publications/papers/2009/mlaa/mlaa.pdf
197           for an in-depth explanation of the morphological antialiasing
198      technique.                */
199 
setDoAntialias(int softness)200   void setDoAntialias(int softness)  //!  Sets the amount of morphological
201                                      //!  antialiasing to be applied.
202   {
203     m_options.m_antialias = softness;
204   }
antialiasSoftness()205   int antialiasSoftness() const  //!  Returns the amount of morphological
206                                  //!  antialiasing to be applied.
207   {
208     return m_options.m_antialias;
209   }
210 
211   /*! \details  White substitution is currently an \a exact feature in Toonz -
212 ie
213           only \a fully white pixels will be replaced with transparent.
214           This implicityl restrains its applicability to images <I>without
215           antialias</I>. This is therefore coupled with antialiasing settins.
216 \sa       The setDoAntialias() method.                                        */
217 
setWhiteTransp(bool whiteTransp)218   void setWhiteTransp(bool whiteTransp)  //!  Whether full white pixels should
219                                          //!  be intended as transparent.
220   {
221     m_options.m_whiteTransp = whiteTransp;
222   }
whiteTransp()223   bool whiteTransp() const { return m_options.m_whiteTransp; }
224 
setIsStopMotion(bool isStopMotion)225   void setIsStopMotion(bool isStopMotion)  // Is this level used for Stop Motion
226 
227   {
228     m_options.m_isStopMotionLevel = isStopMotion;
229   }
isStopMotionLevel()230   bool isStopMotionLevel() const { return m_options.m_isStopMotionLevel; }
231 
232 private:
233   TPointD m_imageDpi;
234 
235   std::string m_creator;
236 
237   TDimension m_imageRes;
238 
239   int m_bpp;
240 
241   bool m_loadAtOnce, m_dirtyFlag, m_forbidden, m_hasAlpha;
242 
243   LevelOptions m_options;
244 };
245 
246 #endif  // LEVELPROPERTIES_H
247