AJA NTV2 SDK  17.0.1.1246
NTV2 SDK 17.0.1.1246
ntv2fixed.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef NTV2FIXED_H
9 #define NTV2FIXED_H
10 
11 #include "ajatypes.h"
12 
13 #define FIXED_ONE (1<<16)
14 
15 #ifdef MSWindows
16  //Visual Studio 2008 or lower
17  #if (_MSC_VER <= 1500)
18  #define inline __inline
19  #endif
20 #endif
21 
22 #if defined (AJAMac) | defined (AJAVirtual)
23  // MacOS still defines the functions below in CarbonCore/FixMath.h
24  #ifdef FixedRound
25  #undef FixedRound
26  #endif
27  #ifdef FloatToFixed
28  #undef FloatToFixed
29  #endif
30  #ifdef FixedToFloat
31  #undef FixedToFloat
32  #endif
33  #if !defined (FixedTrunc)
34  // Conflicts with FixedTrunc function in AJABase's videoutilities.h
35  #define FixedTrunc(__x__) ((__x__)>>16)
36  #endif
37  #define FixedRound(__x__) (((__x__) < 0) ? (-((-(__x__)+0x8000)>>16)) : (((__x__) + 0x8000)>>16))
38  #define FixedMix(__min__,__max__,__mixer__) (FixedRound(((__max__)-(__min__))*(__mixer__)+(__min__)))
39  #define FloatToFixed(__x__) ((Fixed_)((__x__) * (float)FIXED_ONE))
40  #define FixedToFloat(__x__) (((float)(__x__) / (float) 65536.0))
41  #define FixedFrac(__x__) (((__x__) < 0) ? (-(__x__) & 0xFFFF)) : ((__x__) & 0xFFFF)
42 
43 #else // not AJAMac
44 
45  // Prevent unsupported-floating link errors in Linux device driver.
46  // The following are not used in the Linux driver but cause the 2.6 kernel
47  // linker to fail anyway.
48  #ifndef __KERNEL__
49  inline Fixed_ FloatToFixed(float inFlt)
50  {
51  return (Fixed_)(inFlt * (float)FIXED_ONE);
52  }
53 
54  inline float FixedToFloat(Fixed_ inFix)
55  {
56  return((float)inFix/(float)65536.0);
57  }
58  #endif // if __KERNEL__ undefined
59 
60  inline Word FixedRound(Fixed_ inFix)
61  {
62  Word retValue;
63 
64  if ( inFix < 0 )
65  {
66  retValue = (Word)(-((-inFix+0x8000)>>16));
67  }
68  else
69  {
70  retValue = (Word)((inFix + 0x8000)>>16);
71  }
72  return retValue;
73  }
74 
75  inline Fixed_ FixedFrac(Fixed_ inFix)
76  {
77  Fixed_ retValue;
78 
79  if ( inFix < 0 )
80  {
81  retValue = -inFix&0xFFFF;
82  }
83  else
84  {
85  retValue = inFix&0xFFFF;
86  }
87 
88  return retValue;
89  }
90 
91  inline Fixed_ FixedTrunc(Fixed_ inFix)
92  {
93  return (inFix>>16);
94  }
95 
96  inline Word FixedMix(Word min, Word max, Fixed_ mixer)
97  {
98  Fixed_ result = (max-min)*mixer+min;
99 
100  return FixedRound(result);
101  }
102 #endif // else not AJAMac
103 
104 #endif // NTV2FIXED_H
FixedRound
#define FixedRound(__x__)
Definition: ntv2fixed.h:37
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
FixedTrunc
#define FixedTrunc(__x__)
Definition: ntv2fixed.h:35
Word
int16_t Word
Definition: ajatypes.h:243
FixedMix
#define FixedMix(__min__, __max__, __mixer__)
Definition: ntv2fixed.h:38
FloatToFixed
#define FloatToFixed(__x__)
Definition: ntv2fixed.h:39
FixedToFloat
#define FixedToFloat(__x__)
Definition: ntv2fixed.h:40
FIXED_ONE
#define FIXED_ONE
Definition: ntv2fixed.h:13
FixedFrac
#define FixedFrac(__x__)
Definition: ntv2fixed.h:41
Fixed_
int Fixed_
Definition: ajatypes.h:308