1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
4 // Digital Ltd. LLC
5 //
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 // *       Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // *       Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // *       Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 ///////////////////////////////////////////////////////////////////////////
34 
35 
36 #ifndef INCLUDED_IMF_TIME_CODE_H
37 #define INCLUDED_IMF_TIME_CODE_H
38 
39 #include "ImfExport.h"
40 #include "ImfNamespace.h"
41 
42 //-----------------------------------------------------------------------------
43 //
44 //	class TimeCode
45 //
46 // 	A TimeCode object stores time and control codes as described
47 // 	in SMPTE standard 12M-1999.  A TimeCode object contains the
48 // 	following fields:
49 //
50 // 	    Time Address:
51 //
52 //		hours			integer, range 0 - 23
53 //		minutes			integer, range 0 - 59
54 //		seconds			integer, range 0 - 59
55 //		frame 			integer, range 0 - 29
56 //
57 // 	    Flags:
58 //
59 // 		drop frame flag		boolean
60 //		color frame flag	boolean
61 //		field/phase flag	boolean
62 //		bgf0			boolean
63 //		bgf1			boolean
64 //		bgf2			boolean
65 //
66 // 	    Binary groups for user-defined data and control codes:
67 //
68 //		binary group 1		integer, range 0 - 15
69 //		binary group 2		integer, range 0 - 15
70 //		...
71 //		binary group 8		integer, range 0 - 15
72 //
73 //	Class TimeCode contains methods to convert between the fields
74 //	listed above and a more compact representation where the fields
75 //	are packed into two unsigned 32-bit integers.  In the packed
76 //	integer representations, bit 0 is the least significant bit,
77 //	and bit 31 is the most significant bit of the integer value.
78 //
79 //	The time address and flags fields can be packed in three
80 //	different ways:
81 //
82 //	      bits	packing for	  packing for	    packing for
83 //	    		24-frame 	  60-field 	    50-field
84 //	    		film		  television	    television
85 //
86 //	     0 -  3	frame units	  frame units	    frame units
87 //	     4 -  5	frame tens	  frame tens	    frame tens
88 //	     6		unused, set to 0  drop frame flag   unused, set to 0
89 //	     7		unused, set to 0  color frame flag  color frame flag
90 //	     8 - 11	seconds units	  seconds units	    seconds units
91 //	    12 - 14	seconds tens	  seconds tens	    seconds tens
92 //	    15		phase flag	  field/phase flag  bgf0
93 //	    16 - 19	minutes units	  minutes units	    minutes units
94 //	    20 - 22	minutes tens	  minutes tens	    minutes tens
95 //	    23		bgf0		  bgf0		    bgf2
96 //	    24 - 27	hours units	  hours units	    hours units
97 //	    28 - 29	hours tens	  hours tens	    hours tens
98 //	    30		bgf1		  bgf1		    bgf1
99 //	    31		bgf2		  bgf2		    field/phase flag
100 //
101 //	User-defined data and control codes are packed as follows:
102 //
103 //	      bits	field
104 //
105 //	     0 -  3	binary group 1
106 //	     4 -  7	binary group 2
107 //	     8 - 11	binary group 3
108 //	    12 - 15	binary group 4
109 //	    16 - 19	binary group 5
110 //	    20 - 23	binary group 6
111 //	    24 - 27	binary group 7
112 //	    28 - 31	binary group 8
113 //
114 //-----------------------------------------------------------------------------
115 
116 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
117 
118 
119 class IMF_EXPORT TimeCode
120 {
121   public:
122 
123     //---------------------
124     // Bit packing variants
125     //---------------------
126 
127     enum Packing
128     {
129 	TV60_PACKING,		// packing for 60-field television
130 	TV50_PACKING,		// packing for 50-field television
131 	FILM24_PACKING		// packing for 24-frame film
132     };
133 
134 
135     //-------------------------------------
136     // Constructors and assignment operator
137     //-------------------------------------
138 
139     TimeCode ();  // all fields set to 0 or false
140 
141     TimeCode (int hours,
142 	      int minutes,
143 	      int seconds,
144 	      int frame,
145 	      bool dropFrame = false,
146 	      bool colorFrame = false,
147 	      bool fieldPhase = false,
148 	      bool bgf0 = false,
149 	      bool bgf1 = false,
150 	      bool bgf2 = false,
151 	      int binaryGroup1 = 0,
152 	      int binaryGroup2 = 0,
153 	      int binaryGroup3 = 0,
154 	      int binaryGroup4 = 0,
155 	      int binaryGroup5 = 0,
156 	      int binaryGroup6 = 0,
157 	      int binaryGroup7 = 0,
158 	      int binaryGroup8 = 0);
159 
160     TimeCode (unsigned int timeAndFlags,
161 	      unsigned int userData = 0,
162 	      Packing packing = TV60_PACKING);
163 
164     TimeCode (const TimeCode &other);
165 
166     TimeCode & operator = (const TimeCode &other);
167 
168 
169     //----------------------------
170     // Access to individual fields
171     //----------------------------
172 
173     int		hours () const;
174     void	setHours (int value);
175 
176     int		minutes () const;
177     void	setMinutes (int value);
178 
179     int		seconds () const;
180     void	setSeconds (int value);
181 
182     int		frame () const;
183     void	setFrame (int value);
184 
185     bool	dropFrame () const;
186     void	setDropFrame (bool value);
187 
188     bool	colorFrame () const;
189     void	setColorFrame (bool value);
190 
191     bool	fieldPhase () const;
192     void	setFieldPhase (bool value);
193 
194     bool	bgf0 () const;
195     void	setBgf0 (bool value);
196 
197     bool	bgf1 () const;
198     void	setBgf1 (bool value);
199 
200     bool	bgf2 () const;
201     void	setBgf2 (bool value);
202 
203     int		binaryGroup (int group) const; // group must be between 1 and 8
204     void	setBinaryGroup (int group, int value);
205 
206 
207     //---------------------------------
208     // Access to packed representations
209     //---------------------------------
210 
211     unsigned int	timeAndFlags (Packing packing = TV60_PACKING) const;
212 
213     void		setTimeAndFlags (unsigned int value,
214 					 Packing packing = TV60_PACKING);
215 
216     unsigned int	userData () const;
217 
218     void		setUserData (unsigned int value);
219 
220 
221     //---------
222     // Equality
223     //---------
224 
225     bool		operator == (const TimeCode &v) const;
226     bool		operator != (const TimeCode &v) const;
227 
228   private:
229 
230     unsigned int	_time;
231     unsigned int	_user;
232 };
233 
234 
235 
236 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
237 
238 
239 
240 
241 
242 #endif
243