1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
36
//-----------------------------------------------------------------------------
40
//-----------------------------------------------------------------------------
42
#include <ImfTimeCode.h>
79
setDropFrame (dropFrame);
80
setColorFrame (colorFrame);
81
setFieldPhase (fieldPhase);
85
setBinaryGroup (1, binaryGroup1);
86
setBinaryGroup (2, binaryGroup2);
87
setBinaryGroup (3, binaryGroup3);
88
setBinaryGroup (4, binaryGroup4);
89
setBinaryGroup (5, binaryGroup5);
90
setBinaryGroup (6, binaryGroup6);
91
setBinaryGroup (7, binaryGroup7);
92
setBinaryGroup (8, binaryGroup8);
97
(unsigned int timeAndFlags,
98
unsigned int userData,
101
setTimeAndFlags (timeAndFlags, packing);
102
setUserData (userData);
106
TimeCode::TimeCode (const TimeCode &other)
114
TimeCode::operator = (const TimeCode &other)
125
bitField (unsigned int value, int minBit, int maxBit)
128
unsigned int mask = (~(~0U << (maxBit - minBit + 1)) << minBit);
129
return (value & mask) >> shift;
134
setBitField (unsigned int &value, int minBit, int maxBit, unsigned int field)
137
unsigned int mask = (~(~0U << (maxBit - minBit + 1)) << minBit);
138
value = ((value & ~mask) | ((field << shift) & mask));
143
bcdToBinary (unsigned int bcd)
145
return int ((bcd & 0x0f) + 10 * ((bcd >> 4) & 0x0f));
150
binaryToBcd (int binary)
152
int units = binary % 10;
153
int tens = (binary / 10) % 10;
154
return (unsigned int) (units | (tens << 4));
162
TimeCode::hours () const
164
return bcdToBinary (bitField (_time, 24, 29));
169
TimeCode::setHours (int value)
171
if (value < 0 || value > 23)
172
throw Iex::ArgExc ("Cannot set hours field in time code. "
173
"New value is out of range.");
175
setBitField (_time, 24, 29, binaryToBcd (value));
180
TimeCode::minutes () const
182
return bcdToBinary (bitField (_time, 16, 22));
187
TimeCode::setMinutes (int value)
189
if (value < 0 || value > 59)
190
throw Iex::ArgExc ("Cannot set minutes field in time code. "
191
"New value is out of range.");
193
setBitField (_time, 16, 22, binaryToBcd (value));
198
TimeCode::seconds () const
200
return bcdToBinary (bitField (_time, 8, 14));
205
TimeCode::setSeconds (int value)
207
if (value < 0 || value > 59)
208
throw Iex::ArgExc ("Cannot set seconds field in time code. "
209
"New value is out of range.");
211
setBitField (_time, 8, 14, binaryToBcd (value));
216
TimeCode::frame () const
218
return bcdToBinary (bitField (_time, 0, 5));
223
TimeCode::setFrame (int value)
225
if (value < 0 || value > 59)
226
throw Iex::ArgExc ("Cannot set frame field in time code. "
227
"New value is out of range.");
229
setBitField (_time, 0, 5, binaryToBcd (value));
234
TimeCode::dropFrame () const
236
return bool (bitField (_time, 6, 6));
241
TimeCode::setDropFrame (bool value)
243
setBitField (_time, 6, 6, (unsigned int) !!value);
248
TimeCode::colorFrame () const
250
return bool (bitField (_time, 7, 7));
255
TimeCode::setColorFrame (bool value)
257
setBitField (_time, 7, 7, (unsigned int) !!value);
262
TimeCode::fieldPhase () const
264
return bool (bitField (_time, 15, 15));
269
TimeCode::setFieldPhase (bool value)
271
setBitField (_time, 15, 15, (unsigned int) !!value);
276
TimeCode::bgf0 () const
278
return bool (bitField (_time, 23, 23));
283
TimeCode::setBgf0 (bool value)
285
setBitField (_time, 23, 23, (unsigned int) !!value);
290
TimeCode::bgf1 () const
292
return bool (bitField (_time, 30, 30));
297
TimeCode::setBgf1 (bool value)
299
setBitField (_time, 30, 30, (unsigned int) !!value);
304
TimeCode::bgf2 () const
306
return bool (bitField (_time, 31, 31));
311
TimeCode::setBgf2 (bool value)
313
setBitField (_time, 31, 31, (unsigned int) !!value);
318
TimeCode::binaryGroup (int group) const
320
if (group < 1 || group > 8)
321
throw Iex::ArgExc ("Cannot extract binary group from time code "
322
"user data. Group number is out of range.");
324
int minBit = 4 * (group - 1);
325
int maxBit = minBit + 3;
326
return int (bitField (_user, minBit, maxBit));
331
TimeCode::setBinaryGroup (int group, int value)
333
if (group < 1 || group > 8)
334
throw Iex::ArgExc ("Cannot extract binary group from time code "
335
"user data. Group number is out of range.");
337
int minBit = 4 * (group - 1);
338
int maxBit = minBit + 3;
339
setBitField (_user, minBit, maxBit, (unsigned int) value);
344
TimeCode::timeAndFlags (Packing packing) const
346
if (packing == TV50_PACKING)
348
unsigned int t = _time;
350
t &= ~((1 << 6) | (1 << 15) | (1 << 23) | (1 << 30) | (1 << 31));
352
t |= ((unsigned int) bgf0() << 15);
353
t |= ((unsigned int) bgf2() << 23);
354
t |= ((unsigned int) bgf1() << 30);
355
t |= ((unsigned int) fieldPhase() << 31);
359
if (packing == FILM24_PACKING)
361
return _time & ~((1 << 6) | (1 << 7));
363
else // packing == TV60_PACKING
371
TimeCode::setTimeAndFlags (unsigned int value, Packing packing)
373
if (packing == TV50_PACKING)
376
~((1 << 6) | (1 << 15) | (1 << 23) | (1 << 30) | (1 << 31));
378
if (value & (1 << 15))
381
if (value & (1 << 23))
384
if (value & (1 << 30))
387
if (value & (1 << 31))
388
setFieldPhase (true);
390
else if (packing == FILM24_PACKING)
392
_time = value & ~((1 << 6) | (1 << 7));
394
else // packing == TV60_PACKING
402
TimeCode::userData () const
409
TimeCode::setUserData (unsigned int value)
1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
36
//-----------------------------------------------------------------------------
40
//-----------------------------------------------------------------------------
42
#include <ImfTimeCode.h>
79
setDropFrame (dropFrame);
80
setColorFrame (colorFrame);
81
setFieldPhase (fieldPhase);
85
setBinaryGroup (1, binaryGroup1);
86
setBinaryGroup (2, binaryGroup2);
87
setBinaryGroup (3, binaryGroup3);
88
setBinaryGroup (4, binaryGroup4);
89
setBinaryGroup (5, binaryGroup5);
90
setBinaryGroup (6, binaryGroup6);
91
setBinaryGroup (7, binaryGroup7);
92
setBinaryGroup (8, binaryGroup8);
97
(unsigned int timeAndFlags,
98
unsigned int userData,
101
setTimeAndFlags (timeAndFlags, packing);
102
setUserData (userData);
106
TimeCode::TimeCode (const TimeCode &other)
114
TimeCode::operator = (const TimeCode &other)
125
bitField (unsigned int value, int minBit, int maxBit)
128
unsigned int mask = (~(~0U << (maxBit - minBit + 1)) << minBit);
129
return (value & mask) >> shift;
134
setBitField (unsigned int &value, int minBit, int maxBit, unsigned int field)
137
unsigned int mask = (~(~0U << (maxBit - minBit + 1)) << minBit);
138
value = ((value & ~mask) | ((field << shift) & mask));
143
bcdToBinary (unsigned int bcd)
145
return int ((bcd & 0x0f) + 10 * ((bcd >> 4) & 0x0f));
150
binaryToBcd (int binary)
152
int units = binary % 10;
153
int tens = (binary / 10) % 10;
154
return (unsigned int) (units | (tens << 4));
162
TimeCode::hours () const
164
return bcdToBinary (bitField (_time, 24, 29));
169
TimeCode::setHours (int value)
171
if (value < 0 || value > 23)
172
throw Iex::ArgExc ("Cannot set hours field in time code. "
173
"New value is out of range.");
175
setBitField (_time, 24, 29, binaryToBcd (value));
180
TimeCode::minutes () const
182
return bcdToBinary (bitField (_time, 16, 22));
187
TimeCode::setMinutes (int value)
189
if (value < 0 || value > 59)
190
throw Iex::ArgExc ("Cannot set minutes field in time code. "
191
"New value is out of range.");
193
setBitField (_time, 16, 22, binaryToBcd (value));
198
TimeCode::seconds () const
200
return bcdToBinary (bitField (_time, 8, 14));
205
TimeCode::setSeconds (int value)
207
if (value < 0 || value > 59)
208
throw Iex::ArgExc ("Cannot set seconds field in time code. "
209
"New value is out of range.");
211
setBitField (_time, 8, 14, binaryToBcd (value));
216
TimeCode::frame () const
218
return bcdToBinary (bitField (_time, 0, 5));
223
TimeCode::setFrame (int value)
225
if (value < 0 || value > 59)
226
throw Iex::ArgExc ("Cannot set frame field in time code. "
227
"New value is out of range.");
229
setBitField (_time, 0, 5, binaryToBcd (value));
234
TimeCode::dropFrame () const
236
return bool (bitField (_time, 6, 6));
241
TimeCode::setDropFrame (bool value)
243
setBitField (_time, 6, 6, (unsigned int) !!value);
248
TimeCode::colorFrame () const
250
return bool (bitField (_time, 7, 7));
255
TimeCode::setColorFrame (bool value)
257
setBitField (_time, 7, 7, (unsigned int) !!value);
262
TimeCode::fieldPhase () const
264
return bool (bitField (_time, 15, 15));
269
TimeCode::setFieldPhase (bool value)
271
setBitField (_time, 15, 15, (unsigned int) !!value);
276
TimeCode::bgf0 () const
278
return bool (bitField (_time, 23, 23));
283
TimeCode::setBgf0 (bool value)
285
setBitField (_time, 23, 23, (unsigned int) !!value);
290
TimeCode::bgf1 () const
292
return bool (bitField (_time, 30, 30));
297
TimeCode::setBgf1 (bool value)
299
setBitField (_time, 30, 30, (unsigned int) !!value);
304
TimeCode::bgf2 () const
306
return bool (bitField (_time, 31, 31));
311
TimeCode::setBgf2 (bool value)
313
setBitField (_time, 31, 31, (unsigned int) !!value);
318
TimeCode::binaryGroup (int group) const
320
if (group < 1 || group > 8)
321
throw Iex::ArgExc ("Cannot extract binary group from time code "
322
"user data. Group number is out of range.");
324
int minBit = 4 * (group - 1);
325
int maxBit = minBit + 3;
326
return int (bitField (_user, minBit, maxBit));
331
TimeCode::setBinaryGroup (int group, int value)
333
if (group < 1 || group > 8)
334
throw Iex::ArgExc ("Cannot extract binary group from time code "
335
"user data. Group number is out of range.");
337
int minBit = 4 * (group - 1);
338
int maxBit = minBit + 3;
339
setBitField (_user, minBit, maxBit, (unsigned int) value);
344
TimeCode::timeAndFlags (Packing packing) const
346
if (packing == TV50_PACKING)
348
unsigned int t = _time;
350
t &= ~((1 << 6) | (1 << 15) | (1 << 23) | (1 << 30) | (1 << 31));
352
t |= ((unsigned int) bgf0() << 15);
353
t |= ((unsigned int) bgf2() << 23);
354
t |= ((unsigned int) bgf1() << 30);
355
t |= ((unsigned int) fieldPhase() << 31);
359
if (packing == FILM24_PACKING)
361
return _time & ~((1 << 6) | (1 << 7));
363
else // packing == TV60_PACKING
371
TimeCode::setTimeAndFlags (unsigned int value, Packing packing)
373
if (packing == TV50_PACKING)
376
~((1 << 6) | (1 << 15) | (1 << 23) | (1 << 30) | (1 << 31));
378
if (value & (1 << 15))
381
if (value & (1 << 23))
384
if (value & (1 << 30))
387
if (value & (1 << 31))
388
setFieldPhase (true);
390
else if (packing == FILM24_PACKING)
392
_time = value & ~((1 << 6) | (1 << 7));
394
else // packing == TV60_PACKING
402
TimeCode::userData () const
409
TimeCode::setUserData (unsigned int value)