ImfTimeCode.h 7.5 KB

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