eLynx SDK
v3.0.1 C++ image processing API reference |
00001 //============================================================================ 00002 // TransfertFunction.h Math.Component package 00003 //============================================================================ 00004 // Usage : 00005 //---------------------------------------------------------------------------- 00006 // Copyright (C) 2006 by eLynx project 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 // See the GNU Library General Public License for more details. 00017 //---------------------------------------------------------------------------- 00018 #ifndef __TransfertFunction_h__ 00019 #define __TransfertFunction_h__ 00020 00021 #include <elx/core/CoreTypes.h> 00022 #include "MathLib.h" 00023 00024 namespace eLynx { 00025 namespace Math { 00026 00027 //---------------------------------------------------------------------------- 00028 class ExportedByMath IMapTransform 00029 { 00030 public: 00031 virtual ~IMapTransform(); 00032 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const = 0; 00033 virtual bool Transform( 00034 void * iprDst, EResolution iDst, 00035 const void * iprSrc, EResolution iSrc, 00036 uint32 iSize) const = 0; 00037 }; 00038 00039 00040 //---------------------------------------------------------------------------- 00041 class ExportedByMath CopyTransform : public IMapTransform 00042 { 00043 public: 00044 CopyTransform(); 00045 virtual ~CopyTransform(); 00046 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const; 00047 virtual bool Transform( 00048 void * iprDst, EResolution iDst, 00049 const void * iprSrc, EResolution iSrc, 00050 uint32 iSize ) const; 00051 CopyTransform(const CopyTransform&); 00052 const CopyTransform& operator=(const CopyTransform&); 00053 }; 00054 00055 //---------------------------------------------------------------------------- 00056 class ExportedByMath GammaTransform : public IMapTransform 00057 { 00058 public: 00059 GammaTransform(double iLow, double iHigh, double iGamma); 00060 virtual ~GammaTransform(); 00061 void SetLow(double iLow); 00062 void SetHigh(double iHigh); 00063 void SetParam(double iGamma); 00064 double GetParam() const { return _Gamma; } 00065 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const; 00066 virtual bool Transform( 00067 void * iprDst, EResolution iDst, 00068 const void * iprSrc, EResolution iSrc, 00069 uint32 iSize ) const; 00070 00071 private: 00072 bool Do(uint8 * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00073 bool Do(uint8 * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00074 bool Do(uint8 * iprDest, const int32 * iprSrc, uint32 iSize) const; 00075 bool Do(uint8 * iprDest, const float * iprSrc, uint32 iSize) const; 00076 bool Do(uint8 * iprDest, const double * iprSrc, uint32 iSize) const; 00077 00078 bool Do(uint16 * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00079 bool Do(uint16 * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00080 bool Do(uint16 * iprDest, const int32 * iprSrc, uint32 iSize) const; 00081 bool Do(uint16 * iprDest, const float * iprSrc, uint32 iSize) const; 00082 bool Do(uint16 * iprDest, const double * iprSrc, uint32 iSize) const; 00083 00084 bool Do(float * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00085 bool Do(float * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00086 bool Do(float * iprDest, const int32 * iprSrc, uint32 iSize) const; 00087 bool Do(float * iprDest, const float * iprSrc, uint32 iSize) const; 00088 bool Do(float * iprDest, const double * iprSrc, uint32 iSize) const; 00089 00090 bool Do(double * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00091 bool Do(double * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00092 bool Do(double * iprDest, const int32 * iprSrc, uint32 iSize) const; 00093 bool Do(double * iprDest, const float * iprSrc, uint32 iSize) const; 00094 bool Do(double * iprDest, const double * iprSrc, uint32 iSize) const; 00095 00096 double _Low; 00097 double _High; 00098 double _Gamma; 00099 00100 GammaTransform(const GammaTransform&); 00101 const GammaTransform& operator=(const GammaTransform&); 00102 }; 00103 00104 //---------------------------------------------------------------------------- 00105 class ExportedByMath MidtoneTransform : public IMapTransform 00106 { 00107 public: 00108 MidtoneTransform(double iLow, double iHigh, double iGamma); 00109 virtual ~MidtoneTransform(); 00110 void SetLow(double iLow); 00111 void SetHigh(double iHigh); 00112 void SetParam(double iMidtone); 00113 double GetParam() const { return _Midtone; } 00114 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const; 00115 virtual bool Transform( 00116 void * iprDst, EResolution iDst, 00117 const void * iprSrc, EResolution iSrc, 00118 uint32 iSize ) const; 00119 00120 private: 00121 bool Do(uint8 * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00122 bool Do(uint8 * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00123 bool Do(uint8 * iprDest, const int32 * iprSrc, uint32 iSize) const; 00124 bool Do(uint8 * iprDest, const float * iprSrc, uint32 iSize) const; 00125 bool Do(uint8 * iprDest, const double * iprSrc, uint32 iSize) const; 00126 00127 bool Do(uint16 * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00128 bool Do(uint16 * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00129 bool Do(uint16 * iprDest, const int32 * iprSrc, uint32 iSize) const; 00130 bool Do(uint16 * iprDest, const float * iprSrc, uint32 iSize) const; 00131 bool Do(uint16 * iprDest, const double * iprSrc, uint32 iSize) const; 00132 00133 bool Do(float * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00134 bool Do(float * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00135 bool Do(float * iprDest, const int32 * iprSrc, uint32 iSize) const; 00136 bool Do(float * iprDest, const float * iprSrc, uint32 iSize) const; 00137 bool Do(float * iprDest, const double * iprSrc, uint32 iSize) const; 00138 00139 bool Do(double * iprDest, const uint8 * iprSrc, uint32 iSize) const; 00140 bool Do(double * iprDest, const uint16 * iprSrc, uint32 iSize) const; 00141 bool Do(double * iprDest, const int32 * iprSrc, uint32 iSize) const; 00142 bool Do(double * iprDest, const float * iprSrc, uint32 iSize) const; 00143 bool Do(double * iprDest, const double * iprSrc, uint32 iSize) const; 00144 00145 double _Low; 00146 double _High; 00147 double _Midtone; 00148 00149 MidtoneTransform(const MidtoneTransform&); 00150 const MidtoneTransform& operator=(const MidtoneTransform&); 00151 }; 00152 00153 00154 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00155 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00156 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00157 00158 00159 // Interface defining a transfert function for image viewer. 00160 class ExportedByMath ITransfertFunction 00161 { 00162 public: 00163 virtual ~ITransfertFunction(); 00164 00165 virtual void SetRange(double iLow, double iHigh) = 0; 00166 virtual void SetLow(double iLow) = 0; 00167 virtual void SetHigh(double iHigh) = 0;; 00168 virtual void SetParam(double iParam) = 0; 00169 virtual double GetLow() const = 0; 00170 virtual double GetHigh() const = 0; 00171 virtual double GetParam() const = 0; 00172 00173 virtual bool IsSupported(EResolution iResolution) const = 0; 00174 virtual bool Transform( 00175 uint8 * iprDest, 00176 const void * iprSrc, 00177 uint32 iSize, 00178 EResolution iResolution) const = 0; 00179 }; 00180 00181 //---------------------------------------------------------------------------- 00182 class ExportedByMath AbstractTransfertFunction : 00183 public ITransfertFunction 00184 { 00185 public: 00186 virtual ~AbstractTransfertFunction(); 00187 virtual void Release(); 00188 00190 virtual void SetRange(double iLow, double iHigh); 00191 virtual double GetLow() const; 00192 virtual double GetHigh() const; 00193 virtual void SetLow(double iLow); 00194 virtual void SetHigh(double iHigh); 00195 00196 virtual void SetParam(double){} 00197 virtual double GetParam() const { return 0.0;} 00198 00199 virtual bool IsInvariant() const { return false; } 00200 00201 protected: 00202 AbstractTransfertFunction(double iLow=0.0, double iHigh=1.0); 00203 double _Low; 00204 double _High; 00205 00206 private: 00207 AbstractTransfertFunction(const AbstractTransfertFunction&); 00208 }; 00209 00210 //---------------------------------------------------------------------------- 00211 class ExportedByMath TransfertFunctionCopy : public AbstractTransfertFunction 00212 { 00213 public: 00214 TransfertFunctionCopy(); 00215 virtual ~TransfertFunctionCopy(); 00216 virtual void SetRange(double, double); 00217 virtual bool IsSupported(EResolution iResolution) const; 00218 virtual bool Transform( 00219 uint8 * iprDest, 00220 const void * iprSrc, 00221 uint32 iSize, 00222 EResolution iResolution) const; 00223 00224 virtual bool IsInvariant() const { return true; } 00225 00226 private: 00227 CopyTransform _Transformation; 00228 00229 TransfertFunctionCopy(const TransfertFunctionCopy&); 00230 const TransfertFunctionCopy& operator=(const TransfertFunctionCopy&); 00231 }; 00232 00233 //---------------------------------------------------------------------------- 00234 class ExportedByMath TransfertFunctionGamma : public AbstractTransfertFunction 00235 { 00236 public: 00237 TransfertFunctionGamma(double iLow = 0.0, double iHigh = 1.0, double iGamma = 1.0); 00238 virtual ~TransfertFunctionGamma(); 00239 00240 virtual void SetRange(double iLow, double iHigh); 00241 virtual bool IsSupported(EResolution iResolution) const; 00242 virtual bool Transform( 00243 uint8 * iprDest, 00244 const void * iprSrc, 00245 uint32 iSize, 00246 EResolution iResolution) const; 00247 00248 void SetParam(double iGamma); 00249 double GetParam() const; 00250 00251 void SetParameters(double iLow, double iHigh, double iGamma) 00252 { 00253 SetRange(iLow,iHigh); 00254 SetParam(iGamma); 00255 } 00256 void GetParameters(double& oLow, double& oHigh, double& oGamma) const 00257 { 00258 oLow = _Low; 00259 oHigh = _High; 00260 oGamma = _Transformation.GetParam(); 00261 } 00262 00263 virtual void SetLow(double iLow) 00264 { 00265 _Low = iLow; 00266 _Transformation.SetLow(iLow); 00267 } 00268 00269 virtual void SetHigh(double iHigh) 00270 { 00271 _High = iHigh; 00272 _Transformation.SetHigh(iHigh); 00273 } 00274 00275 virtual bool IsInvariant() const 00276 { 00277 return ((_Low == 0.0) && (_High == 1.0) && (_Transformation.GetParam() == 1.0)); 00278 } 00279 00280 private: 00281 GammaTransform _Transformation; 00282 00283 TransfertFunctionGamma(const TransfertFunctionGamma&); 00284 const TransfertFunctionGamma& operator=(const TransfertFunctionGamma&); 00285 }; 00286 00287 00288 //---------------------------------------------------------------------------- 00289 class ExportedByMath TransfertFunctionMidtone : public AbstractTransfertFunction 00290 { 00291 public: 00292 TransfertFunctionMidtone(double iLow = 0.0, double iHigh = 1.0, double iMidtone = 0.5); 00293 virtual ~TransfertFunctionMidtone(); 00294 00295 virtual void SetRange(double iLow, double iHigh); 00296 virtual bool IsSupported(EResolution iResolution) const; 00297 virtual bool Transform( 00298 uint8 * iprDest, 00299 const void * iprSrc, 00300 uint32 iSize, 00301 EResolution iResolution) const; 00302 00303 void SetParam(double iMidtone); 00304 double GetParam() const; 00305 00306 void SetParameters(double iLow, double iHigh, double iMidtone) 00307 { 00308 SetRange(iLow,iHigh); 00309 SetParam(iMidtone); 00310 } 00311 void GetParameters(double& oLow, double& oHigh, double& oMidtone) const 00312 { 00313 oLow = _Low; 00314 oHigh = _High; 00315 oMidtone = _Transformation.GetParam(); 00316 } 00317 00318 virtual void SetLow(double iLow) 00319 { 00320 _Low = iLow; 00321 _Transformation.SetLow(iLow); 00322 } 00323 00324 virtual void SetHigh(double iHigh) 00325 { 00326 _High = iHigh; 00327 _Transformation.SetHigh(iHigh); 00328 } 00329 00330 virtual bool IsInvariant() const 00331 { 00332 return ((_Low == 0.0) && (_High == 1.0) && (_Transformation.GetParam() == 0.5)); 00333 } 00334 00335 private: 00336 MidtoneTransform _Transformation; 00337 00338 TransfertFunctionMidtone(const TransfertFunctionMidtone&); 00339 const TransfertFunctionMidtone& operator=(const TransfertFunctionMidtone&); 00340 }; 00341 00342 } // namespace Math 00343 } // namespace eLynx 00344 00345 #endif // __TransfertFunction_h__