File indexing completed on 2025-01-19 03:55:12
0001 /*****************************************************************************/ 0002 // Copyright 2006-2019 Adobe Systems Incorporated 0003 // All Rights Reserved. 0004 // 0005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 0006 // accordance with the terms of the Adobe license agreement accompanying it. 0007 /*****************************************************************************/ 0008 0009 /** \file 0010 * Signed and unsigned rational data types. 0011 */ 0012 0013 /*****************************************************************************/ 0014 0015 #ifndef __dng_rational__ 0016 #define __dng_rational__ 0017 0018 /*****************************************************************************/ 0019 0020 #include "dng_types.h" 0021 0022 /*****************************************************************************/ 0023 0024 class dng_srational 0025 { 0026 0027 public: 0028 0029 int32 n; // Numerator 0030 int32 d; // Denominator 0031 0032 public: 0033 0034 dng_srational () 0035 : n (0) 0036 , d (0) 0037 { 0038 } 0039 0040 dng_srational (int32 nn, int32 dd) 0041 : n (nn) 0042 , d (dd) 0043 { 0044 } 0045 0046 void Clear () 0047 { 0048 n = 0; 0049 d = 0; 0050 } 0051 0052 bool IsValid () const 0053 { 0054 return d != 0; 0055 } 0056 0057 bool NotValid () const 0058 { 0059 return !IsValid (); 0060 } 0061 0062 bool operator== (const dng_srational &r) const 0063 { 0064 return (n == r.n) && 0065 (d == r.d); 0066 } 0067 0068 bool operator!= (const dng_srational &r) const 0069 { 0070 return !(*this == r); 0071 } 0072 0073 real64 As_real64 () const; 0074 0075 void Set_real64 (real64 x, int32 dd = 0); 0076 0077 void ReduceByFactor (int32 factor); 0078 0079 }; 0080 0081 /*****************************************************************************/ 0082 0083 class dng_urational 0084 { 0085 0086 public: 0087 0088 uint32 n; // Numerator 0089 uint32 d; // Denominator 0090 0091 public: 0092 0093 dng_urational () 0094 : n (0) 0095 , d (0) 0096 { 0097 } 0098 0099 dng_urational (uint32 nn, uint32 dd) 0100 : n (nn) 0101 , d (dd) 0102 { 0103 } 0104 0105 void Clear () 0106 { 0107 n = 0; 0108 d = 0; 0109 } 0110 0111 bool IsValid () const 0112 { 0113 return d != 0; 0114 } 0115 0116 bool NotValid () const 0117 { 0118 return !IsValid (); 0119 } 0120 0121 bool operator== (const dng_urational &r) const 0122 { 0123 return (n == r.n) && 0124 (d == r.d); 0125 } 0126 0127 bool operator!= (const dng_urational &r) const 0128 { 0129 return !(*this == r); 0130 } 0131 0132 real64 As_real64 () const; 0133 0134 void Set_real64 (real64 x, uint32 dd = 0); 0135 0136 void ReduceByFactor (uint32 factor); 0137 0138 }; 0139 0140 /*****************************************************************************/ 0141 0142 #endif 0143 0144 /*****************************************************************************/