bevfill.cpp

Go to the documentation of this file.
00001 // $Id: bevfill.cpp 1282 2006-06-09 09:46:49Z alex $
00003 // bevel filling class implementation
00004 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00005 ================================XARAHEADERSTART===========================
00006  
00007                Xara LX, a vector drawing and manipulation program.
00008                     Copyright (C) 1993-2006 Xara Group Ltd.
00009        Copyright on certain contributions may be held in joint with their
00010               respective authors. See AUTHORS file for details.
00011 
00012 LICENSE TO USE AND MODIFY SOFTWARE
00013 ----------------------------------
00014 
00015 This file is part of Xara LX.
00016 
00017 Xara LX is free software; you can redistribute it and/or modify it
00018 under the terms of the GNU General Public License version 2 as published
00019 by the Free Software Foundation.
00020 
00021 Xara LX and its component source files are distributed in the hope
00022 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00023 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00024 See the GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License along
00027 with Xara LX (see the file GPL in the root directory of the
00028 distribution); if not, write to the Free Software Foundation, Inc., 51
00029 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00030 
00031 
00032 ADDITIONAL RIGHTS
00033 -----------------
00034 
00035 Conditional upon your continuing compliance with the GNU General Public
00036 License described above, Xara Group Ltd grants to you certain additional
00037 rights. 
00038 
00039 The additional rights are to use, modify, and distribute the software
00040 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00041 library and any other such library that any version of Xara LX relased
00042 by Xara Group Ltd requires in order to compile and execute, including
00043 the static linking of that library to XaraLX. In the case of the
00044 "CDraw" library, you may satisfy obligation under the GNU General Public
00045 License to provide source code by providing a binary copy of the library
00046 concerned and a copy of the license accompanying it.
00047 
00048 Nothing in this section restricts any of the rights you have under
00049 the GNU General Public License.
00050 
00051 
00052 SCOPE OF LICENSE
00053 ----------------
00054 
00055 This license applies to this program (XaraLX) and its constituent source
00056 files only, and does not necessarily apply to other Xara products which may
00057 in part share the same code base, and are subject to their own licensing
00058 terms.
00059 
00060 This license does not apply to files in the wxXtra directory, which
00061 are built into a separate library, and are subject to the wxWindows
00062 license contained within that directory in the file "WXXTRA-LICENSE".
00063 
00064 This license does not apply to the binary libraries (if any) within
00065 the "libs" directory, which are subject to a separate license contained
00066 within that directory in the file "LIBS-LICENSE".
00067 
00068 
00069 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00070 ----------------------------------------------
00071 
00072 Subject to the terms of the GNU Public License (see above), you are
00073 free to do whatever you like with your modifications. However, you may
00074 (at your option) wish contribute them to Xara's source tree. You can
00075 find details of how to do this at:
00076   http://www.xaraxtreme.org/developers/
00077 
00078 Prior to contributing your modifications, you will need to complete our
00079 contributor agreement. This can be found at:
00080   http://www.xaraxtreme.org/developers/contribute/
00081 
00082 Please note that Xara will not accept modifications which modify any of
00083 the text between the start and end of this header (marked
00084 XARAHEADERSTART and XARAHEADEREND).
00085 
00086 
00087 MARKS
00088 -----
00089 
00090 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00091 designs are registered or unregistered trademarks, design-marks, and/or
00092 service marks of Xara Group Ltd. All rights in these marks are reserved.
00093 
00094 
00095       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00096                         http://www.xara.com/
00097 
00098 =================================XARAHEADEREND============================
00099  */
00100 
00101 #include "camtypes.h"
00102 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00103 #include "bevfill.h"
00104 
00105 CC_IMPLEMENT_DYNAMIC(CBevelFills, CCObject)
00106 CC_IMPLEMENT_DYNAMIC(CBevelFill, CCObject)
00107 CC_IMPLEMENT_DYNAMIC(CBevelFillFlat, CBevelFill)
00108 CC_IMPLEMENT_DYNAMIC(CBevelFillRound, CBevelFill)
00109 CC_IMPLEMENT_DYNAMIC(CBevelFillSquare, CBevelFill)
00110 CC_IMPLEMENT_DYNAMIC(CBevelFillFrame, CBevelFill)
00111 CC_IMPLEMENT_DYNAMIC(CBevelFillSmooth, CBevelFill)
00112 CC_IMPLEMENT_DYNAMIC(CBevelFillRuffle, CBevelFill)
00113 CC_IMPLEMENT_DYNAMIC(CBevelFillPoint, CBevelFill)
00114 
00115 #define new CAM_DEBUG_NEW
00116 
00117 // the value to set to be transparent in some fills
00118 const double SplitValue = 213;
00119 
00120 void CBevelFill::EnsureValueRange(double *value)
00121 {
00122     if (*value > 254)
00123     {
00124         *value = 254;
00125     }
00126     else if (*value < 1)
00127     {
00128         *value = 1;
00129     }
00130 }
00131 
00133 // the CBevFills class
00134 
00135 CBevelFills::CBevelFills()
00136 {
00137     SetUpFills();
00138 }
00139 
00140 CBevelFills::~CBevelFills()
00141 {
00142     for (INT32 i = 0 ; i < m_NumFills; i++)
00143     {
00144         TRACE( _T("deleting bevel fill %d\n"), i);
00145         delete m_pBevFills[i];
00146     }
00147 
00148     delete m_pBevFills;
00149     m_pBevFills = NULL;
00150 }
00151 
00152 /********************************************************************************************
00153 
00154 >   BOOL CBevelFills::SetUpFills()
00155 
00156     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00157     Created:    23/10/98
00158     Purpose:    Set up the bevel filling array
00159     Inputs:     
00160     Returns:    TRUE for success
00161     SeeAlso:    -
00162 
00163 ********************************************************************************************/
00164 
00165 BOOL CBevelFills::SetUpFills()
00166 {
00167     // set up the list first
00168     m_NumFills = 7;
00169 
00170     m_pBevFills = new CBevelFill *[m_NumFills];
00171     m_pBevFills[0] = new CBevelFillFlat;
00172 
00173     m_pBevFills[1] = new CBevelFillRound;
00174 
00175     m_pBevFills[2] = new CBevelFillSquare;
00176 
00177     m_pBevFills[3] = new CBevelFillFrame;
00178 
00179     m_pBevFills[4] = new CBevelFillSmooth;
00180 
00181     m_pBevFills[5] = new CBevelFillPoint;
00182 
00183     m_pBevFills[6] = new CBevelFillRuffle;
00184 
00185     return TRUE;
00186 }
00187 
00188 COLORREF CBevelFills::CalcPixelValue(BYTE value, INT32 bevType, double Pos, INT32 Contrast)
00189 {
00190     if (Pos < 0.00)
00191     {
00192         Pos = 0.00;
00193     }
00194 
00195     if (Pos >= 1.00)
00196     {
00197         Pos = 1.00;
00198     }
00199 
00200     if (bevType < 0 || bevType >= m_NumFills)
00201     {
00202         return m_pBevFills[0]->CalcPixelValue(value, Pos, Contrast);
00203     }
00204     
00205     return m_pBevFills[bevType]->CalcPixelValue(value, Pos, Contrast);
00206 }
00207 
00209 // all the fill class definitions
00210 
00211 /********************************************************************************************
00212 
00213 >   COLORREF CBevelFlatFill::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00214 
00215     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00216     Created:    11/11/98
00217     Purpose:    Do a flat fill
00218     Inputs:     
00219     Returns:    TRUE for success
00220     SeeAlso:    -
00221 
00222 ********************************************************************************************/
00223 
00224 COLORREF CBevelFillFlat::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00225 {
00226     double RValue = value;
00227     double GValue = value;
00228     double BValue = value;
00229     double AValue = value;
00230 
00231     if (AValue < SplitValue)
00232     {
00233         AValue *= 255.0 / SplitValue;
00234     }
00235     else 
00236     {
00237         AValue = 255.0 - AValue;
00238         AValue *= 255.0 / (255.0 - SplitValue);
00239 
00240         AValue = 1.0 - (AValue / 255.0);
00241         AValue *= AValue;
00242         AValue = (1.0 - AValue) * 255.0;
00243     }
00244     
00245     AValue *= 200.0 / 255.0;
00246 
00247     RValue += 0.5;
00248     GValue += 0.5;
00249     BValue += 0.5;
00250 
00251     EnsureValueRange(&AValue);
00252     
00253     BYTE RByte = (BYTE)RValue;
00254     BYTE GByte = (BYTE)GValue;
00255     BYTE BByte = (BYTE)BValue;
00256     BYTE AByte = (BYTE)AValue;
00257 
00258     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00259 }
00260 
00261 /********************************************************************************************
00262 
00263 >   COLORREF CBevelFillRound::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00264 
00265     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00266     Created:    11/11/98
00267     Purpose:    Do a flat fill
00268     Inputs:     
00269     Returns:    TRUE for success
00270     SeeAlso:    -
00271 
00272 ********************************************************************************************/
00273 
00274 COLORREF CBevelFillRound::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00275 {
00276     double RValue = value;
00277     double GValue = value;
00278     double BValue = value;
00279     double AValue = value;
00280 
00281     double Gradient = 0;
00282 
00283 
00284     if (Pos <= 0.5)
00285     {
00286         Pos = Pos / 0.5;
00287 
00288         Gradient = 128 - RValue;
00289         RValue = RValue + (Gradient * Pos);
00290     }   
00291     else
00292     {
00293         Pos = 1.0 - Pos;
00294         RValue = 255.0 - RValue;
00295         
00296         Pos = Pos / 0.5;
00297 
00298         Gradient = 128 - RValue;
00299         RValue = RValue + (Gradient * Pos);
00300     }       
00301 
00302     BYTE RByte = (BYTE)RValue;
00303     BYTE GByte = (BYTE)RValue;
00304     BYTE BByte = (BYTE)RValue;
00305     BYTE AByte = (BYTE)AValue;
00306 
00307     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00308 }
00309     
00310 /********************************************************************************************
00311 
00312 >   COLORREF CBevelFillSqaure::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00313 
00314     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00315     Created:    11/11/98
00316     Purpose:    Do a flat fill
00317     Inputs:     
00318     Returns:    TRUE for success
00319     SeeAlso:    -
00320 
00321 ********************************************************************************************/
00322 
00323 COLORREF CBevelFillSquare::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00324 {
00325 double RValue = value;
00326     double GValue = value;
00327     double BValue = value;
00328     double AValue = value;
00329 
00330     double Gradient = 0;
00331 
00332 
00333     if (Pos <= 0.3)
00334     {
00335         // do nothing
00336     }
00337     else if (Pos >= 0.7)
00338     {
00339         RValue = 255.0 - RValue;
00340     }
00341     else
00342     {
00343         RValue = 128.0;
00344     }       
00345 
00346     BYTE RByte = (BYTE)RValue;
00347     BYTE GByte = (BYTE)RValue;
00348     BYTE BByte = (BYTE)RValue;
00349     BYTE AByte = (BYTE)AValue;
00350 
00351     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00352 }
00353     
00354 /********************************************************************************************
00355 
00356 >   COLORREF CBevelFillFrame::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00357 
00358     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00359     Created:    11/11/98
00360     Purpose:    Do a Mesa fill
00361     Inputs:     
00362     Returns:    TRUE for success
00363     SeeAlso:    -
00364 
00365 ********************************************************************************************/
00366 
00367 COLORREF CBevelFillFrame::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00368 {
00369     Pos = 1.0 - Pos;
00370     
00371     double RValue = value;
00372     double GValue = value;
00373     double BValue = value;
00374     double AValue = value;
00375 
00376     double kValue = value;
00377 
00378     // deal with the outside inwards
00379     if (value <= 128)
00380     {
00381         kValue = 128.0 - kValue;
00382         kValue *= (1.0 - Pos);
00383         kValue = 128.0 - kValue;
00384     }
00385     else
00386     {
00387         kValue -= 127.0;
00388         kValue *= (1.0 - Pos);
00389         kValue += 127.0;
00390     }
00391 
00392     RValue = kValue;
00393     GValue = kValue;
00394     BValue = kValue;
00395     AValue = kValue;
00396     
00397     BYTE RByte = (BYTE)RValue;
00398     BYTE GByte = (BYTE)GValue;
00399     BYTE BByte = (BYTE)BValue;
00400     BYTE AByte = (BYTE)AValue;
00401 
00402     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00403 }
00404 
00405 /********************************************************************************************
00406 
00407 >   COLORREF CBevelFillSmooth::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00408 
00409     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00410     Created:    11/11/98
00411     Purpose:    Do a flat fill
00412     Inputs:     
00413     Returns:    TRUE for success
00414     SeeAlso:    -
00415 
00416 ********************************************************************************************/
00417 
00418 COLORREF CBevelFillSmooth::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00419 {
00420     double RValue = value;
00421     double GValue = value;
00422     double BValue = value;
00423     double AValue = value;
00424 
00425     double kValue = value;
00426 
00427     // deal with the outside inwards
00428     if (value <= 128)
00429     {
00430         kValue = 128.0 - kValue;
00431         kValue *= (1.0 - Pos);
00432         kValue = 128.0 - kValue;
00433     }
00434     else
00435     {
00436         kValue -= 127.0;
00437         kValue *= (1.0 - Pos);
00438         kValue += 127.0;
00439     }
00440 
00441     RValue = kValue;
00442     GValue = kValue;
00443     BValue = kValue;
00444     AValue = kValue;
00445     
00446     BYTE RByte = (BYTE)RValue;
00447     BYTE GByte = (BYTE)GValue;
00448     BYTE BByte = (BYTE)BValue;
00449     BYTE AByte = (BYTE)AValue;
00450 
00451     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00452 }
00453 
00454 /********************************************************************************************
00455 
00456 >   COLORREF CBevelFillPoint::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00457 
00458     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00459     Created:    11/11/98
00460     Purpose:    Do a flat fill
00461     Inputs:     
00462     Returns:    TRUE for success
00463     SeeAlso:    -
00464 
00465 ********************************************************************************************/
00466 
00467 COLORREF CBevelFillPoint::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00468 {
00469     double RValue = value;
00470     double GValue = value;
00471     double BValue = value;
00472     double AValue = value;
00473 
00474     double kValue = value;
00475 
00476     if (Pos < 0.5)
00477     {
00478         // do nothing
00479     }
00480     else
00481     {
00482         kValue = 255.0 - kValue;
00483     }
00484     
00485     RValue = kValue;
00486     GValue = kValue;
00487     BValue = kValue;
00488     AValue = kValue;
00489 
00490     BYTE RByte = (BYTE)RValue;
00491     BYTE GByte = (BYTE)GValue;
00492     BYTE BByte = (BYTE)BValue;
00493     BYTE AByte = (BYTE)AValue;
00494 
00495     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00496 }
00497 
00498 /********************************************************************************************
00499 
00500 >   COLORREF CBevelFillRuffle::CalcPixelValue(BYTE value, double Pos, INT32 Contrast);
00501 
00502     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00503     Created:    11/11/98
00504     Purpose:    Do a ruffled fill
00505                 This is the same as 3 rounded fills
00506     Inputs:     
00507     Returns:    TRUE for success
00508     SeeAlso:    -
00509 
00510 ********************************************************************************************/
00511 
00512 COLORREF CBevelFillRuffle::CalcPixelValue(BYTE value, double Pos, INT32 Contrast)
00513 {
00514     // change the position
00515     if (Pos >= 0 && Pos < 0.3)
00516     {
00517         Pos = Pos * (1.0/0.3);
00518     }
00519     else if (Pos >= 0.3 && Pos < 0.6)
00520     {
00521         Pos = (Pos - 0.3) * (1.0 / 0.3);
00522     }
00523     else 
00524     {
00525         Pos = (Pos - 0.6) * (1.0 / 0.4);
00526     }
00527     
00528     double RValue = value;
00529     double GValue = value;
00530     double BValue = value;
00531     double AValue = value;
00532 
00533     double kValue = value;
00534 
00535     if (Pos < 0.5)
00536     {
00537         // do nothing
00538     }
00539     else
00540     {
00541         kValue = 255.0 - kValue;
00542     }
00543     
00544     RValue = kValue;
00545     GValue = kValue;
00546     BValue = kValue;
00547     AValue = kValue;
00548 
00549     BYTE RByte = (BYTE)RValue;
00550     BYTE GByte = (BYTE)GValue;
00551     BYTE BByte = (BYTE)BValue;
00552     BYTE AByte = (BYTE)AValue;
00553 
00554     return RByte | (GByte << 8) | (BByte << 16) | (AByte << 24);
00555 }

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