eLynx SDK
v3.3.0 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: 00032 virtual ~IMapTransform(); 00033 00038 virtual bool IsSupported( 00039 EResolution iDestination, 00040 EResolution iSource) const = 0; 00041 00049 virtual bool Transform( 00050 void * iprDst, EResolution iDestination, 00051 const void * iprSrc, EResolution iSource, 00052 size_t iSize) const = 0; 00053 }; 00054 00055 //---------------------------------------------------------------------------- 00056 class ExportedByMath CopyTransform : public IMapTransform 00057 { 00058 public: 00059 CopyTransform(); 00060 virtual ~CopyTransform(); 00061 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const; 00062 virtual bool Transform( 00063 void * iprDst, EResolution iDst, 00064 const void * iprSrc, EResolution iSrc, 00065 size_t iSize ) const; 00066 CopyTransform(const CopyTransform&); 00067 const CopyTransform& operator=(const CopyTransform&); 00068 }; 00069 /* 00070 //---------------------------------------------------------------------------- 00071 class ExportedByMath GammaTransform : public IMapTransform 00072 { 00073 public: 00074 GammaTransform(double iLow, double iHigh, double iGamma); 00075 00076 virtual ~GammaTransform(); 00077 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const; 00078 virtual bool Transform( 00079 void * iprDst, EResolution iDst, 00080 const void * iprSrc, EResolution iSrc, 00081 size_t iSize ) const; 00082 00083 void SetLow(double iLow); 00084 void SetHigh(double iHigh); 00085 void SetParam(double iGamma); 00086 double GetParam() const { return _gamma; } 00087 00088 private: 00089 bool Do(uint8 * iprDest, const uint8 * iprSrc, size_t iSize) const; 00090 bool Do(uint8 * iprDest, const uint16 * iprSrc, size_t iSize) const; 00091 bool Do(uint8 * iprDest, const int32 * iprSrc, size_t iSize) const; 00092 bool Do(uint8 * iprDest, const float * iprSrc, size_t iSize) const; 00093 bool Do(uint8 * iprDest, const double * iprSrc, size_t iSize) const; 00094 00095 bool Do(uint16 * iprDest, const uint8 * iprSrc, size_t iSize) const; 00096 bool Do(uint16 * iprDest, const uint16 * iprSrc, size_t iSize) const; 00097 bool Do(uint16 * iprDest, const int32 * iprSrc, size_t iSize) const; 00098 bool Do(uint16 * iprDest, const float * iprSrc, size_t iSize) const; 00099 bool Do(uint16 * iprDest, const double * iprSrc, size_t iSize) const; 00100 00101 bool Do(float * iprDest, const uint8 * iprSrc, size_t iSize) const; 00102 bool Do(float * iprDest, const uint16 * iprSrc, size_t iSize) const; 00103 bool Do(float * iprDest, const int32 * iprSrc, size_t iSize) const; 00104 bool Do(float * iprDest, const float * iprSrc, size_t iSize) const; 00105 bool Do(float * iprDest, const double * iprSrc, size_t iSize) const; 00106 00107 bool Do(double * iprDest, const uint8 * iprSrc, size_t iSize) const; 00108 bool Do(double * iprDest, const uint16 * iprSrc, size_t iSize) const; 00109 bool Do(double * iprDest, const int32 * iprSrc, size_t iSize) const; 00110 bool Do(double * iprDest, const float * iprSrc, size_t iSize) const; 00111 bool Do(double * iprDest, const double * iprSrc, size_t iSize) const; 00112 00113 double _low, _high; 00114 double _gamma; 00115 00116 GammaTransform(const GammaTransform&); 00117 const GammaTransform& operator=(const GammaTransform&); 00118 }; 00119 */ 00120 //---------------------------------------------------------------------------- 00121 class ExportedByMath MidtoneTransform : public IMapTransform 00122 { 00123 public: 00124 MidtoneTransform(double iLow, double iHigh, double iGamma); 00125 virtual ~MidtoneTransform(); 00126 void SetLow(double iLow); 00127 void SetHigh(double iHigh); 00128 void SetParam(double iMidtone); 00129 double GetParam() const { return _midtone; } 00130 virtual bool IsSupported(EResolution iDestination, EResolution iSource) const; 00131 virtual bool Transform( 00132 void * iprDst, EResolution iDst, 00133 const void * iprSrc, EResolution iSrc, 00134 size_t iSize ) const; 00135 00136 private: 00137 bool Do(uint8 * iprDest, const uint8 * iprSrc, size_t iSize) const; 00138 bool Do(uint8 * iprDest, const uint16 * iprSrc, size_t iSize) const; 00139 bool Do(uint8 * iprDest, const int32 * iprSrc, size_t iSize) const; 00140 bool Do(uint8 * iprDest, const float * iprSrc, size_t iSize) const; 00141 bool Do(uint8 * iprDest, const double * iprSrc, size_t iSize) const; 00142 00143 bool Do(uint16 * iprDest, const uint8 * iprSrc, size_t iSize) const; 00144 bool Do(uint16 * iprDest, const uint16 * iprSrc, size_t iSize) const; 00145 bool Do(uint16 * iprDest, const int32 * iprSrc, size_t iSize) const; 00146 bool Do(uint16 * iprDest, const float * iprSrc, size_t iSize) const; 00147 bool Do(uint16 * iprDest, const double * iprSrc, size_t iSize) const; 00148 00149 bool Do(float * iprDest, const uint8 * iprSrc, size_t iSize) const; 00150 bool Do(float * iprDest, const uint16 * iprSrc, size_t iSize) const; 00151 bool Do(float * iprDest, const int32 * iprSrc, size_t iSize) const; 00152 bool Do(float * iprDest, const float * iprSrc, size_t iSize) const; 00153 bool Do(float * iprDest, const double * iprSrc, size_t iSize) const; 00154 00155 bool Do(double * iprDest, const uint8 * iprSrc, size_t iSize) const; 00156 bool Do(double * iprDest, const uint16 * iprSrc, size_t iSize) const; 00157 bool Do(double * iprDest, const int32 * iprSrc, size_t iSize) const; 00158 bool Do(double * iprDest, const float * iprSrc, size_t iSize) const; 00159 bool Do(double * iprDest, const double * iprSrc, size_t iSize) const; 00160 00161 double _low, _high; 00162 double _midtone; 00163 00164 MidtoneTransform(const MidtoneTransform&); 00165 const MidtoneTransform& operator=(const MidtoneTransform&); 00166 }; 00167 00168 00169 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00170 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00171 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00172 00173 00174 // Interface defining a transfert function for image viewer. 00175 class ExportedByMath ITransfertFunction 00176 { 00177 public: 00178 virtual ~ITransfertFunction(); 00179 00180 virtual void SetRange(double iLow, double iHigh) = 0; 00181 virtual void SetLow(double iLow) = 0; 00182 virtual void SetHigh(double iHigh) = 0;; 00183 virtual void SetParam(double iParam) = 0; 00184 virtual double GetLow() const = 0; 00185 virtual double GetHigh() const = 0; 00186 virtual double GetParam() const = 0; 00187 00188 virtual bool IsSupported(EResolution iResolution) const = 0; 00189 virtual bool Transform( 00190 uint8 * iprDest, 00191 const void * iprSrc, 00192 size_t iSize, 00193 EResolution iResolution) const = 0; 00194 }; 00195 00196 //---------------------------------------------------------------------------- 00197 class ExportedByMath AbstractTransfertFunction : 00198 public ITransfertFunction 00199 { 00200 public: 00201 virtual ~AbstractTransfertFunction(); 00202 virtual void Release(); 00203 00205 virtual void SetRange(double iLow, double iHigh); 00206 virtual double GetLow() const; 00207 virtual double GetHigh() const; 00208 virtual void SetLow(double iLow); 00209 virtual void SetHigh(double iHigh); 00210 00211 virtual void SetParam(double){} 00212 virtual double GetParam() const { return 0.0;} 00213 00214 virtual bool IsInvariant() const { return false; } 00215 00216 protected: 00217 AbstractTransfertFunction(double iLow=0.0, double iHigh=1.0); 00218 double _low, _high; 00219 00220 private: 00221 AbstractTransfertFunction(const AbstractTransfertFunction&); 00222 }; 00223 00224 //---------------------------------------------------------------------------- 00225 class ExportedByMath TransfertFunctionCopy : public AbstractTransfertFunction 00226 { 00227 public: 00228 TransfertFunctionCopy(); 00229 virtual ~TransfertFunctionCopy(); 00230 virtual void SetRange(double, double); 00231 virtual bool IsSupported(EResolution iResolution) const; 00232 virtual bool Transform( 00233 uint8 * iprDest, 00234 const void * iprSrc, 00235 size_t iSize, 00236 EResolution iResolution) const; 00237 00238 virtual bool IsInvariant() const { return true; } 00239 00240 private: 00241 CopyTransform _transformation; 00242 00243 TransfertFunctionCopy(const TransfertFunctionCopy&); 00244 const TransfertFunctionCopy& operator=(const TransfertFunctionCopy&); 00245 }; 00246 00247 00248 //---------------------------------------------------------------------------- 00249 class ExportedByMath TransfertFunctionMidtone : public AbstractTransfertFunction 00250 { 00251 public: 00252 TransfertFunctionMidtone(double iLow = 0.0, double iHigh = 1.0, double iMidtone = 0.5); 00253 virtual ~TransfertFunctionMidtone(); 00254 00255 virtual void SetRange(double iLow, double iHigh); 00256 virtual bool IsSupported(EResolution iResolution) const; 00257 virtual bool Transform( 00258 uint8 * iprDest, 00259 const void * iprSrc, 00260 size_t iSize, 00261 EResolution iResolution) const; 00262 00263 void SetParam(double iMidtone); 00264 double GetParam() const; 00265 00266 void SetParameters(double iLow, double iHigh, double iMidtone) 00267 { 00268 SetRange(iLow,iHigh); 00269 SetParam(iMidtone); 00270 } 00271 void GetParameters(double& oLow, double& oHigh, double& oMidtone) const 00272 { 00273 oLow = _low; 00274 oHigh = _high; 00275 oMidtone = _transformation.GetParam(); 00276 } 00277 00278 virtual void SetLow(double iLow) 00279 { 00280 _low = iLow; 00281 _transformation.SetLow(iLow); 00282 } 00283 00284 virtual void SetHigh(double iHigh) 00285 { 00286 _high = iHigh; 00287 _transformation.SetHigh(iHigh); 00288 } 00289 00290 virtual bool IsInvariant() const 00291 { 00292 return ((_low == 0.0) && (_high == 1.0) && (_transformation.GetParam() == 0.5)); 00293 } 00294 00295 private: 00296 MidtoneTransform _transformation; 00297 00298 TransfertFunctionMidtone(const TransfertFunctionMidtone&); 00299 const TransfertFunctionMidtone& operator=(const TransfertFunctionMidtone&); 00300 }; 00301 00302 } // namespace Math 00303 } // namespace eLynx 00304 00305 #endif // __TransfertFunction_h__