ImfTimeCode.h 5.9 KB

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