Home | History | Annotate | Download | only in IlmImf
      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 //-----------------------------------------------------------------------------
     40 //
     41 //	class TimeCode
     42 //
     43 // 	A TimeCode object stores time and control codes as described
     44 // 	in SMPTE standard 12M-1999.  A TimeCode object contains the
     45 // 	following fields:
     46 //
     47 // 	    Time Address:
     48 //
     49 //		hours			integer, range 0 - 23
     50 //		minutes			integer, range 0 - 59
     51 //		seconds			integer, range 0 - 59
     52 //		frame 			integer, range 0 - 29
     53 //
     54 // 	    Flags:
     55 //
     56 // 		drop frame flag		boolean
     57 //		color frame flag	boolean
     58 //		field/phase flag	boolean
     59 //		bgf0			boolean
     60 //		bgf1			boolean
     61 //		bgf2			boolean
     62 //
     63 // 	    Binary groups for user-defined data and control codes:
     64 //
     65 //		binary group 1		integer, range 0 - 15
     66 //		binary group 2		integer, range 0 - 15
     67 //		...
     68 //		binary group 8		integer, range 0 - 15
     69 //
     70 //	Class TimeCode contains methods to convert between the fields
     71 //	listed above and a more compact representation where the fields
     72 //	are packed into two unsigned 32-bit integers.  In the packed
     73 //	integer representations, bit 0 is the least significant bit,
     74 //	and bit 31 is the most significant bit of the integer value.
     75 //
     76 //	The time address and flags fields can be packed in three
     77 //	different ways:
     78 //
     79 //	      bits	packing for	  packing for	    packing for
     80 //	    		24-frame 	  60-field 	    50-field
     81 //	    		film		  television	    television
     82 //
     83 //	     0 -  3	frame units	  frame units	    frame units
     84 //	     4 -  5	frame tens	  frame tens	    frame tens
     85 //	     6		unused, set to 0  drop frame flag   unused, set to 0
     86 //	     7		unused, set to 0  color frame flag  color frame flag
     87 //	     8 - 11	seconds units	  seconds units	    seconds units
     88 //	    12 - 14	seconds tens	  seconds tens	    seconds tens
     89 //	    15		phase flag	  field/phase flag  bgf0
     90 //	    16 - 19	minutes units	  minutes units	    minutes units
     91 //	    20 - 22	minutes tens	  minutes tens	    minutes tens
     92 //	    23		bgf0		  bgf0		    bgf2
     93 //	    24 - 27	hours units	  hours units	    hours units
     94 //	    28 - 29	hours tens	  hours tens	    hours tens
     95 //	    30		bgf1		  bgf1		    bgf1
     96 //	    31		bgf2		  bgf2		    field/phase flag
     97 //
     98 //	User-defined data and control codes are packed as follows:
     99 //
    100 //	      bits	field
    101 //
    102 //	     0 -  3	binary group 1
    103 //	     4 -  7	binary group 2
    104 //	     8 - 11	binary group 3
    105 //	    12 - 15	binary group 4
    106 //	    16 - 19	binary group 5
    107 //	    20 - 23	binary group 6
    108 //	    24 - 27	binary group 7
    109 //	    28 - 31	binary group 8
    110 //
    111 //-----------------------------------------------------------------------------
    112 
    113 namespace Imf {
    114 
    115 
    116 class TimeCode
    117 {
    118   public:
    119 
    120     //---------------------
    121     // Bit packing variants
    122     //---------------------
    123 
    124     enum Packing
    125     {
    126     TV60_PACKING,		// packing for 60-field television
    127     TV50_PACKING,		// packing for 50-field television
    128     FILM24_PACKING		// packing for 24-frame film
    129     };
    130 
    131 
    132     //-------------------------------------
    133     // Constructors and assignment operator
    134     //-------------------------------------
    135 
    136     TimeCode ();  // all fields set to 0 or false
    137 
    138     TimeCode (int hours,
    139           int minutes,
    140           int seconds,
    141           int frame,
    142           bool dropFrame = false,
    143           bool colorFrame = false,
    144           bool fieldPhase = false,
    145           bool bgf0 = false,
    146           bool bgf1 = false,
    147           bool bgf2 = false,
    148           int binaryGroup1 = 0,
    149           int binaryGroup2 = 0,
    150           int binaryGroup3 = 0,
    151           int binaryGroup4 = 0,
    152           int binaryGroup5 = 0,
    153           int binaryGroup6 = 0,
    154           int binaryGroup7 = 0,
    155           int binaryGroup8 = 0);
    156 
    157     TimeCode (unsigned int timeAndFlags,
    158           unsigned int userData = 0,
    159           Packing packing = TV60_PACKING);
    160 
    161     TimeCode (const TimeCode &other);
    162 
    163     TimeCode & operator = (const TimeCode &other);
    164 
    165 
    166     //----------------------------
    167     // Access to individual fields
    168     //----------------------------
    169 
    170     int		hours () const;
    171     void	setHours (int value);
    172 
    173     int		minutes () const;
    174     void	setMinutes (int value);
    175 
    176     int		seconds () const;
    177     void	setSeconds (int value);
    178 
    179     int		frame () const;
    180     void	setFrame (int value);
    181 
    182     bool	dropFrame () const;
    183     void	setDropFrame (bool value);
    184 
    185     bool	colorFrame () const;
    186     void	setColorFrame (bool value);
    187 
    188     bool	fieldPhase () const;
    189     void	setFieldPhase (bool value);
    190 
    191     bool	bgf0 () const;
    192     void	setBgf0 (bool value);
    193 
    194     bool	bgf1 () const;
    195     void	setBgf1 (bool value);
    196 
    197     bool	bgf2 () const;
    198     void	setBgf2 (bool value);
    199 
    200     int		binaryGroup (int group) const; // group must be between 1 and 8
    201     void	setBinaryGroup (int group, int value);
    202 
    203 
    204     //---------------------------------
    205     // Access to packed representations
    206     //---------------------------------
    207 
    208     unsigned int	timeAndFlags (Packing packing = TV60_PACKING) const;
    209 
    210     void		setTimeAndFlags (unsigned int value,
    211                      Packing packing = TV60_PACKING);
    212 
    213     unsigned int	userData () const;
    214 
    215     void		setUserData (unsigned int value);
    216 
    217   private:
    218 
    219     unsigned int	_time;
    220     unsigned int	_user;
    221 };
    222 
    223 
    224 } // namespace Imf
    225 
    226 #endif
    227