biasgain.cpp

Go to the documentation of this file.
00001 // $Id: biasgain.cpp 1282 2006-06-09 09:46:49Z alex $
00002 //------------------------------------------------
00003 //  CProfileBiasGain.cpp
00004 //------------------------------------------------
00005 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00006 ================================XARAHEADERSTART===========================
00007  
00008                Xara LX, a vector drawing and manipulation program.
00009                     Copyright (C) 1993-2006 Xara Group Ltd.
00010        Copyright on certain contributions may be held in joint with their
00011               respective authors. See AUTHORS file for details.
00012 
00013 LICENSE TO USE AND MODIFY SOFTWARE
00014 ----------------------------------
00015 
00016 This file is part of Xara LX.
00017 
00018 Xara LX is free software; you can redistribute it and/or modify it
00019 under the terms of the GNU General Public License version 2 as published
00020 by the Free Software Foundation.
00021 
00022 Xara LX and its component source files are distributed in the hope
00023 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00024 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00025 See the GNU General Public License for more details.
00026 
00027 You should have received a copy of the GNU General Public License along
00028 with Xara LX (see the file GPL in the root directory of the
00029 distribution); if not, write to the Free Software Foundation, Inc., 51
00030 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00031 
00032 
00033 ADDITIONAL RIGHTS
00034 -----------------
00035 
00036 Conditional upon your continuing compliance with the GNU General Public
00037 License described above, Xara Group Ltd grants to you certain additional
00038 rights. 
00039 
00040 The additional rights are to use, modify, and distribute the software
00041 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00042 library and any other such library that any version of Xara LX relased
00043 by Xara Group Ltd requires in order to compile and execute, including
00044 the static linking of that library to XaraLX. In the case of the
00045 "CDraw" library, you may satisfy obligation under the GNU General Public
00046 License to provide source code by providing a binary copy of the library
00047 concerned and a copy of the license accompanying it.
00048 
00049 Nothing in this section restricts any of the rights you have under
00050 the GNU General Public License.
00051 
00052 
00053 SCOPE OF LICENSE
00054 ----------------
00055 
00056 This license applies to this program (XaraLX) and its constituent source
00057 files only, and does not necessarily apply to other Xara products which may
00058 in part share the same code base, and are subject to their own licensing
00059 terms.
00060 
00061 This license does not apply to files in the wxXtra directory, which
00062 are built into a separate library, and are subject to the wxWindows
00063 license contained within that directory in the file "WXXTRA-LICENSE".
00064 
00065 This license does not apply to the binary libraries (if any) within
00066 the "libs" directory, which are subject to a separate license contained
00067 within that directory in the file "LIBS-LICENSE".
00068 
00069 
00070 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00071 ----------------------------------------------
00072 
00073 Subject to the terms of the GNU Public License (see above), you are
00074 free to do whatever you like with your modifications. However, you may
00075 (at your option) wish contribute them to Xara's source tree. You can
00076 find details of how to do this at:
00077   http://www.xaraxtreme.org/developers/
00078 
00079 Prior to contributing your modifications, you will need to complete our
00080 contributor agreement. This can be found at:
00081   http://www.xaraxtreme.org/developers/contribute/
00082 
00083 Please note that Xara will not accept modifications which modify any of
00084 the text between the start and end of this header (marked
00085 XARAHEADERSTART and XARAHEADEREND).
00086 
00087 
00088 MARKS
00089 -----
00090 
00091 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00092 designs are registered or unregistered trademarks, design-marks, and/or
00093 service marks of Xara Group Ltd. All rights in these marks are reserved.
00094 
00095 
00096       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00097                         http://www.xara.com/
00098 
00099 =================================XARAHEADEREND============================
00100  */
00101 
00102 
00103 
00104 
00105 #include "camtypes.h"
00106 
00107 //#include "biasgain.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #include "clamp.h"
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00118 
00119 const AFp  CProfileBiasGain::kSmallAmount_s( 0.00001 );
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00129 
00135 
00136 CProfileBiasGain::CProfileBiasGain ()
00137     : IProfile()/*,
00138       BiasMinus1ToPlus1_m( AFp(0.0) ),
00139       GainMinus1ToPlus1_m( AFp(0.0) ),
00140       Bias_m( AFp(0.0) ),
00141       Gain_m( AFp(0.0) ),
00142       DomainLow_m   ( AFp(0.0) ),
00143       DomainLength_m( AFp(1.0) ),
00144       RangeLow_m    ( AFp(0.0) ),
00145       RangeLength_m ( AFp(1.0) )*/
00146 {
00147 
00148     CProfileBiasGain::SetBiasGain( AFp(0.0),  AFp(0.0) );
00149     CProfileBiasGain::SetDefaultIntervals();
00150     generatesInfiniteUndo = FALSE;
00151 }
00152 
00153 
00160 
00161 CProfileBiasGain::CProfileBiasGain ( AFp BiasMinus1ToPlus1,  AFp GainMinus1ToPlus1 )
00162     : IProfile()/*,
00163       BiasMinus1ToPlus1_m( AFp(0.0) ),
00164       GainMinus1ToPlus1_m( AFp(0.0) ),
00165       Bias_m( AFp(0.0) ),
00166       Gain_m( AFp(0.0) ),
00167       DomainLow_m   ( AFp(0.0) ),
00168       DomainLength_m( AFp(1.0) ),
00169       RangeLow_m    ( AFp(0.0) ),
00170       RangeLength_m ( AFp(1.0) )*/
00171 {
00172 
00173     CProfileBiasGain::SetBiasGain( BiasMinus1ToPlus1,  GainMinus1ToPlus1 );
00174     CProfileBiasGain::SetDefaultIntervals();
00175     generatesInfiniteUndo = FALSE;
00176 }
00177 
00178 
00179 
00180 
00181 CProfileBiasGain::~CProfileBiasGain ()
00182 {
00183 }
00184 
00185 
00186 
00187 
00188 CProfileBiasGain::CProfileBiasGain ( const CProfileBiasGain& Other )
00189     /*: IProfile( Other ),
00190       BiasMinus1ToPlus1_m( Other.BiasMinus1ToPlus1_m ),
00191       GainMinus1ToPlus1_m( Other.GainMinus1ToPlus1_m ),
00192       Bias_m( Other.Bias_m ),
00193       Gain_m( Other.Gain_m ),
00194       DomainLow_m   ( Other.DomainLow_m ),
00195       DomainLength_m( Other.DomainLength_m ),
00196       RangeLow_m    ( Other.RangeLow_m ),
00197       RangeLength_m ( Other.RangeLength_m )*/
00198 {
00199 
00200     CProfileBiasGain::operator=( Other );
00201 
00202 }
00203 
00204 
00205 
00206 
00207 CProfileBiasGain&  CProfileBiasGain::operator= ( const CProfileBiasGain& Other )
00208 {
00209 
00210     IProfile::operator=( Other );
00211 
00212     BiasMinus1ToPlus1_m  =  Other.BiasMinus1ToPlus1_m;
00213     GainMinus1ToPlus1_m  =  Other.GainMinus1ToPlus1_m;
00214     Bias_m               =  Other.Bias_m;
00215     Gain_m               =  Other.Gain_m;
00216 
00217     DomainLow_m     =  Other.DomainLow_m;
00218     DomainLength_m  =  Other.DomainLength_m;
00219     RangeLow_m      =  Other.RangeLow_m;
00220     RangeLength_m   =  Other.RangeLength_m;
00221 
00222     return  *this;
00223 
00224 }
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00234 
00236 
00243 
00244 void  CProfileBiasGain::SetBiasGain ( AFp BiasMinus1ToPlus1,  AFp GainMinus1ToPlus1 )
00245 {
00246 
00247     SetBias( BiasMinus1ToPlus1 );
00248     SetGain( GainMinus1ToPlus1 );
00249 
00250 }
00251 
00252 
00259 
00260 void  CProfileBiasGain::SetBias ( AFp BiasMinus1ToPlus1 )
00261 {
00262 
00264     BiasMinus1ToPlus1  =  ClampBetween( BiasMinus1ToPlus1,  AFp(-1.0),  AFp(+1.0) );
00265 
00266 
00268     const AFp  BiasZeroToOne( ConvertIntervalMinus1Plus1ToZeroOne( BiasMinus1ToPlus1 ) );
00269 
00270 
00272     BiasMinus1ToPlus1_m  =  BiasMinus1ToPlus1;
00273     Bias_m               =  BiasZeroToOne;
00274 
00275 }
00276 
00277 
00284 
00285 void  CProfileBiasGain::SetGain ( AFp GainMinus1ToPlus1 )
00286 {
00287 
00289     GainMinus1ToPlus1  =  ClampBetween( GainMinus1ToPlus1,  AFp(-1.0),  AFp(+1.0) );
00290 
00291 
00293     const AFp  GainZeroToOne( ConvertIntervalMinus1Plus1ToZeroOne( GainMinus1ToPlus1 ) );
00294 
00295 
00297     GainMinus1ToPlus1_m  =  GainMinus1ToPlus1;
00298     Gain_m               =  GainZeroToOne;
00299 
00300 }
00301 
00302 
00303 AFp  CProfileBiasGain::GetBias ()   const
00304 {
00305 
00306     return  BiasMinus1ToPlus1_m;
00307 
00308 }
00309 
00310 
00311 AFp  CProfileBiasGain::GetGain ()   const
00312 {
00313 
00314     return  GainMinus1ToPlus1_m;
00315 
00316 }
00317 
00318 
00319 
00320 
00322 
00330 
00331 AFp  CProfileBiasGain::MapZeroToOne ( AFp InputZeroToOne )   const
00332 {
00333 
00335     InputZeroToOne  =  ClampBetween( InputZeroToOne,  AFp(0.0),  AFp(1.0) );
00336 
00337 
00339     AFp  BiasedGained( 0.0 );
00340     {
00343         if(     ( BiasMinus1ToPlus1_m  !=  AFp(0.0) )
00344             ||  ( GainMinus1ToPlus1_m  !=  AFp(0.0) ) )
00345         {
00347             BiasedGained  =  BiasGain( Bias_m,  Gain_m,  InputZeroToOne );
00348         }
00349         else
00350         {
00351             BiasedGained  =  InputZeroToOne; 
00352         }
00353     }
00354 
00355 
00356     return  BiasedGained;
00357 
00358 }
00359 
00360 
00361 
00362 
00364 
00371 
00372 void  CProfileBiasGain::SetIntervals ( AFp Low,   AFp High )
00373 {
00374 
00375     SetIntervals( Low, High,  Low, High );
00376 
00377 }
00378 
00379 
00386 
00387 void  CProfileBiasGain::SetIntervals ( AFp DomainLow,  AFp DomainHigh,  AFp RangeLow,  AFp RangeHigh )
00388 {
00389 
00390     AFp  DomainLength( DomainHigh - DomainLow );
00391     AFp  RangeLength(  RangeHigh  - RangeLow  );
00392 
00393 
00395     if( DomainLength == AFp(0.0) )
00396     {
00397         DomainLength  =  kSmallAmount_s;
00398     }
00399     if( RangeLength  == AFp(0.0) )
00400     {
00401         RangeLength   =  kSmallAmount_s;
00402     }
00403 
00404 
00406     DomainLow_m     =  DomainLow;
00407     DomainLength_m  =  DomainLength;
00408 
00409     RangeLow_m      =  RangeLow;
00410     RangeLength_m   =  RangeLength;
00411 
00412 }
00413 
00414 
00422 
00423 AFp  CProfileBiasGain::MapInterval ( AFp InputDomain )   const
00424 {
00425 
00427     InputDomain  =  ClampBetween( InputDomain,  DomainLow_m,  DomainLow_m + DomainLength_m );
00428 
00429 
00431     const AFp  InputZeroToOne( ScaleDomainToZeroOne( InputDomain ) );
00432 
00434     const AFp  BiasedGained( MapZeroToOne( InputZeroToOne ) );
00435 
00437     const AFp  OutputRange( ScaleZeroOneToRange( BiasedGained ) );
00438 
00439 
00440     return  OutputRange;
00441 
00442 }
00443 
00444 
00452 
00453 void  CProfileBiasGain::MapInterval ( AFp Table[],  INT32 TableLength )   const
00454 {
00455 
00457     if( Table != 0 )
00458     {
00459 
00461         const AFp  Increment( AFp(1.0) / AFp(TableLength) );
00462               AFp  InputZeroOne( 0.0 );
00463 
00464 
00466         for( INT32 Index = 0  ;  Index < TableLength  ;  ++Index  )
00467         {
00468             const AFp  BiasedGained( MapZeroToOne( InputZeroOne ) );
00469             const AFp  OutputRange( ScaleZeroOneToRange( BiasedGained ) );
00470 
00471             Table[ Index ]  =  OutputRange;
00472             
00473             InputZeroOne   +=  Increment;
00474         }
00475 
00476     }
00477 
00478 }
00479 
00480 
00481 
00482 
00484 
00485 bool  CProfileBiasGain::operator== ( const CProfileBiasGain& Other )   const
00486 {
00487 
00489     const bool  IsSame  =      ( Bias_m  ==  Other.Bias_m )
00490                            &&  ( Gain_m  ==  Other.Gain_m );
00491 
00492     return  IsSame;
00493 
00494 }
00495 
00496 
00497 
00498 
00499 
00500 
00501 
00502 
00504 
00506 
00515 
00516 AFp  CProfileBiasGain::ConvertIntervalMinus1Plus1ToZeroOne ( AFp Minus1ToPlus1 )   
00517 {
00518 
00519     //static const AFp  kShrink( ( AFp(1.0) - kSmallAmount_s ) / AFp(2.0) );   /// (0,1]
00520     static const AFp  kShrink( ( AFp(1.0) / AFp(2.0) ) - kSmallAmount_s );     
00521 
00522     const AFp  ZeroToOne( ( Minus1ToPlus1 + AFp(1.0) ) * kShrink + kSmallAmount_s );
00523 
00524 
00525     return  ZeroToOne;
00526 
00527 }
00528 
00529 
00530 AFp  CProfileBiasGain::ScaleDomainToZeroOne ( AFp InDomain )   const
00531 {
00532 
00534     if( DomainLength_m  !=  AFp(0.0) )
00535     {
00536         return  ( InDomain - DomainLow_m ) / DomainLength_m;
00537     }
00538     else
00539     {
00540         return  AFp( 0.0 );
00541     }
00542 
00543 }
00544 
00545     
00546 AFp  CProfileBiasGain::ScaleZeroOneToRange ( AFp InZeroOne )   const
00547 {
00548 
00549     return   ( InZeroOne * RangeLength_m ) + RangeLow_m;
00550 
00551 }
00552 
00553     
00554     
00555     
00556 
00557 
00558 
00559 
00561 
00571 
00572 AFp  CProfileBiasGain::BiasGain ( AFp bias,  AFp gain,  AFp Input )   
00573 {
00574 
00575     const AFp  Biased( Bias( bias,  Input  ) );
00576     const AFp  Output( Gain( gain,  Biased ) );
00577 
00578     return  Output;
00579 
00580 }
00581 
00582 
00591 
00592 AFp  CProfileBiasGain::Bias ( AFp Bias,  AFp Input )   
00593 {
00594 
00595     static const AFp  kOne( 1.0 );
00596     static const AFp  kTwo( 2.0 );
00597 
00598 //  const AFp  Output( Input  /  ( ( kOne / Bias - kTwo ) * ( kOne - Input ) + kOne ) );
00599     const AFp  Output( Input*Bias  /  ( ( kOne - kTwo*Bias ) * ( kOne - Input ) + Bias ) );
00600 
00601 
00602     return  Output;
00603 
00604 }
00605 
00606 
00615 
00616 AFp  CProfileBiasGain::Gain ( AFp Gain,   AFp Input )   
00617 {
00618 
00619     static const AFp  kOne( 1.0 );
00620     static const AFp  kTwo( 2.0 );
00621     static const AFp  kHalf( 0.5 );
00622 
00623 //  const AFp  CommonPart( ( kOne / Gain - kTwo ) * ( kOne - kTwo * Input ) );
00624     const AFp  CommonPart( ( kOne - kTwo*Gain ) * ( kOne - kTwo * Input ) );
00625 
00626     if( Input  <  kHalf )
00627     {
00628 //      return  Input / ( CommonPart + kOne );
00629         return  Input*Gain / ( CommonPart + Gain );
00630     }
00631     else
00632     {
00633 //      return  ( CommonPart - Input ) / ( CommonPart - kOne );
00634         return  ( CommonPart - Input*Gain ) / ( CommonPart - Gain );
00635     }
00636 
00637 }
00638 
00639 
00640 
00641 
00643 
00644 void  CProfileBiasGain::SetDefaultIntervals ()
00645 {
00646 
00647     DomainLow_m     =  AFp( 0.0 );
00648     DomainLength_m  =  AFp( 1.0 );
00649     RangeLow_m      =  AFp( 0.0 );
00650     RangeLength_m   =  AFp( 1.0 );
00651 
00652 }

Generated on Sat Nov 10 03:44:21 2007 for Camelot by  doxygen 1.4.4