bfxbase.cpp

Go to the documentation of this file.
00001 // $Id: bfxbase.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // This file implents the BitmapEffect class
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 #include "bfxbase.h"
00106 #include "bfxalu.h"
00107 
00108 // This is not compulsory, but you may as well put it in so that the correct version
00109 // of your file can be registered in the .exe
00110 DECLARE_SOURCE("$Revision: 1282 $");
00111 
00112 // An implement to match the Declare in the .h file.
00113 // If you have many classes, it is recommended to place them all together, here at the start of the file
00114 CC_IMPLEMENT_DYNCREATE(BitmapEffectBase, ListItem)
00115 
00116 // This will get Camelot to display the filename and linenumber of any memory allocations
00117 // that are not released at program exit
00118 #define new CAM_DEBUG_NEW
00119 
00120 // statics
00121 BfxALU * BitmapEffectBase::ALU = NULL;
00122 
00123 /********************************************************************************************
00124 
00125 >   BitmapEffectBase::BitmapEffectBase()
00126                     
00127     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00128     Created:    12/10/94
00129     Inputs:     None
00130     Outputs:    Constructs object
00131     Returns:    Nothing
00132     Purpose:    Default constructor for bitmap effect object
00133     Errors:     Causes a level 3 if the setting the parameters to the default fails
00134     SeeAlso:    -
00135 
00136 This constructs an object and sets the parameters to the default set. As contructors can't fail
00137 we explode if we can't set the parameters to the default set on the basis that this is an
00138 operation defined algorithmically to work 100% of the time!
00139 
00140 ********************************************************************************************/
00141 
00142 BitmapEffectBase::BitmapEffectBase()
00143 {
00144     Source = NULL;
00145     Destination = NULL;
00146 //  Monitor = NULL;
00147 
00148     if (!(SetParameters())) /* virtual */
00149     {
00150         ERROR3("Bitmap effect default parameter set failed in constructor");
00151     }
00152 }
00153 
00154 /********************************************************************************************
00155 
00156 >   BitmapEffectBase::~BitmapEffectBase()
00157                     
00158     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00159     Created:    12/10/94
00160     Inputs:     None
00161     Outputs:    Constructs object
00162     Returns:    Nothing
00163     Purpose:    Default constructor for bitmap effect object
00164     Errors:     Causes a level 3 if the setting the parameters to the default fails
00165     SeeAlso:    -
00166 
00167 This constructs an object and sets the parameters to the default set. As contructors can't fail
00168 we explode if we can't set the parameters to the default set on the basis that this is an
00169 operation defined algorithmically to work 100% of the time!
00170 
00171 ********************************************************************************************/
00172 
00173 BitmapEffectBase::~BitmapEffectBase()
00174 {
00175     ERROR3IF((Destination!=NULL),"Bitmap effect destructor called when destination exists");
00176     // Unforunately we habe to use ERROR3 not ERROR2 as we can't return a flag  
00177 }
00178 
00179 /********************************************************************************************
00180 
00181 >   static BOOL BitmapEffectBase::Init()
00182                     
00183     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00184     Created:    27/10/94
00185     Inputs:     None
00186     Outputs:    Initialises subsystem
00187     Returns:    TRUE if succeeded, FALSE & error set if not
00188     Purpose:    Initialises the bitmap effect subsystem
00189     Errors:     None from this one as yet
00190     SeeAlso:    -
00191 
00192 This call's primary purposes is to initialise the BfxALU, getting its static pointer.
00193 
00194 ********************************************************************************************/
00195 
00196 BOOL BitmapEffectBase::Init()
00197 {
00198     ALU=new BfxALU;
00199     return (ALU) ? (ALU->Init()) : FALSE;
00200 }
00201 
00202 void BitmapEffectBase::TestGD()
00203 {
00204     ALU->TestGD();
00205 }
00206 
00207 /********************************************************************************************
00208 
00209 >   static BOOL BitmapEffectBase::DeInit()
00210                     
00211     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00212     Created:    27/10/94
00213     Inputs:     None
00214     Outputs:    DeInitialises subsystem
00215     Returns:    TRUE if succeeded, FALSE & error set if not
00216     Purpose:    Initialises the bitmap effect subsystem
00217     Errors:     None from this one as yet
00218     SeeAlso:    -
00219 
00220 This call's primary purposes is to deinitialise the BfxALU.
00221 
00222 ********************************************************************************************/
00223 
00224 BOOL BitmapEffectBase::DeInit()
00225 {
00226     if ( (ALU) && (ALU->DeInit()) )
00227     {
00228         delete(ALU);
00229         ALU=NULL;
00230         return TRUE;
00231     }
00232     else return FALSE;
00233 }
00234 
00235 /********************************************************************************************
00236 
00237 >   BOOL BitmapEffectBase::SetParameters()
00238                     
00239     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    12/10/94
00241     Inputs:     None
00242     Outputs:    Sets up the parameters to the default
00243     Returns:    TRUE if succeeded, FALSE & error set if not
00244     Purpose:    Sets the bitmap effect params up to the default
00245     Errors:     None from this one as yet
00246     SeeAlso:    -
00247 
00248 Normally this would be overridden to det a default set of parameters, but the base class
00249 version might be used if the effect has no parameters
00250 
00251 ********************************************************************************************/
00252 
00253 BOOL BitmapEffectBase::SetParameters()
00254 {
00255     return TRUE;
00256 }
00257 
00258 /********************************************************************************************
00259 
00260 >   BOOL BitmapEffectBase::SetSourceImage(KernelBitmap * theSource)
00261                     
00262     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00263     Created:    12/10/94
00264     Inputs:     theSource is pointer to the bitmap to use, or NULL to unset it
00265     Outputs:    Records a pointer to the bitmap
00266     Returns:    TRUE if succeeded, FALSE & error set if not
00267     Purpose:    Sets up the effect to use a chosen bitmap
00268     Errors:     None from this one as yet
00269     SeeAlso:    -
00270 
00271 Normally this would be overridden to check the bitmap was suitable.
00272 
00273 ********************************************************************************************/
00274 
00275 BOOL BitmapEffectBase::SetSourceImage(KernelBitmap * theSource)
00276 {
00277     Source = theSource;
00278     return TRUE;
00279 }
00280 
00281 /********************************************************************************************
00282 
00283 >   BOOL BitmapEffectBase::GetEffectInfo(UINT32 * pOrderBitmap, UINT32 * pOrderEffect,
00284                    UINT32 * pPlotEstimate)
00285                     
00286     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00287     Created:    12/10/94
00288     Inputs:     None
00289     Outputs:    pOrderBitmap filled in with the order of the operation wrt size of bitmap
00290                 pOrderEffect filled in with the order of the operation wrt size of effect
00291                 pPlotEstimate filled in with the number of sprite plots this is roughly
00292                     equivalent to in time terms.
00293     Returns:    TRUE if succeeded, FALSE & error set if not
00294     Purpose:    Gets information about the given effect
00295     Errors:     None from this one as yet
00296     SeeAlso:    -
00297 
00298 This should be overridden to give the user some idea of how long a bitmap operation is going
00299 to take, so they can be marked as fast, slow or whatever. If the source image is not set up,
00300 pPlotEstimate should be returned as zero.
00301 
00302 Any parameters passed as NULL will not be filled
00303 
00304 ********************************************************************************************/
00305 
00306 BOOL BitmapEffectBase::GetEffectInfo(UINT32 * pOrderBitmap, UINT32 * pOrderEffect,
00307                    UINT32 * pPlotEstimate)
00308 {
00309     
00310     if (pOrderBitmap) *pOrderBitmap=0;
00311     if (pOrderEffect) *pOrderEffect=0;
00312     if (pPlotEstimate) *pPlotEstimate=0;
00313     return(TRUE);
00314 }
00315 
00316 /********************************************************************************************
00317 
00318 >   BOOL BitmapEffectBase::GetDestinationInfo(UINT32 * pDestinationSize,
00319                                     INT32 * pDestinationDepth,
00320                                     UINT32 * pDestinationWidth,
00321                                     UINT32 * pDestinationHeight)
00322                     
00323     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00324     Created:    12/10/94
00325     Inputs:     None
00326     Outputs:    pDestinationSize filled with size in bytes of dest bitmap
00327                 pDestinationDepth filled with bpp of dest bitmap
00328                 pDestinationWidth|Height filled with width height of dest in pixels
00329     Returns:    TRUE if succeeded, FALSE & error set if not
00330     Purpose:    Gets information about the given effect
00331     Errors:     Error2 if source hasn't been set up
00332     SeeAlso:    -
00333 
00334 This should be overridden to give an accurate representation of what the dest bitmap will
00335 look like. It is an error to call this without setting the source up.
00336 
00337 ********************************************************************************************/
00338 
00339 
00340 BOOL BitmapEffectBase::GetDestinationInfo(UINT32 * pDestinationSize,
00341                                     INT32 * pDestinationDepth,
00342                                     UINT32 * pDestinationWidth,
00343                                     UINT32 * pDestinationHeight)
00344 {
00345     
00346     ERROR2IF(!Source,FALSE,"No source for bitmap effect");
00347 
00348     if (pDestinationSize) *pDestinationSize=0;
00349     if (pDestinationDepth) *pDestinationDepth=0;
00350     if (pDestinationWidth) *pDestinationWidth=0;
00351     if (pDestinationHeight) *pDestinationHeight=0;
00352     
00353     return(TRUE);
00354 }
00355 
00356 
00357 /********************************************************************************************
00358 
00359 >   BOOL BitmapEffectBase::UseDestinationBitmap(KernelBitmap * theDestination)
00360                     
00361     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00362     Created:    12/10/94
00363     Inputs:     theDestination is pointer to the bitmap to use, or NULL to unset it
00364     Outputs:    Records a pointer to the dest bitmap
00365     Returns:    TRUE if succeeded, FALSE & error set if not
00366     Purpose:    Indicates the Run method should use this bitmap for output
00367     Errors:     None from this one as yet
00368     SeeAlso:    -
00369 
00370 Normally this would be overridden to check the bitmap was suitable. The bitmap specified will
00371 be used if specified, else a new KernelBitmap will be used. If the KernelBitmap does not have
00372 an OilBitmap attached and created of the correct size, it will be created and attached. If a
00373 NULL is passed (this is the default situation) then a new KernelBitmap will be created.
00374 
00375 This routine can also be called with NULL to indicate that responsibility for an output image
00376 after a run has been assumed by the caller. The object won't destruct when it has a destination
00377 bitmap.
00378 
00379 ********************************************************************************************/
00380 
00381 BOOL BitmapEffectBase::UseDestinationBitmap(KernelBitmap * theDestination)
00382 {
00383     Destination = theDestination;
00384     return TRUE;
00385 }
00386 
00387 /********************************************************************************************
00388 
00389 >   KernelBitmap * BitmapEffectBase::GetDestination();
00390                     
00391     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00392     Created:    12/10/94
00393     Inputs:     None
00394     Outputs:    None
00395     Returns:    Pointer to destination imagwe
00396     Purpose:    Returns a pointer to the destination image
00397     Errors:     None from this one as yet
00398     SeeAlso:    -
00399 
00400 The dest image will be present if it has been set using UseDestinationBitmap, or if the
00401 effect has been run and UseDestinationBitmap has not been set to NULL subsequently.
00402 
00403 ********************************************************************************************/
00404 
00405 KernelBitmap * BitmapEffectBase::GetDestination()
00406 {
00407     return (Destination);
00408 }
00409 
00410 /********************************************************************************************
00411 
00412 >   BOOL BitmapEffectBase::IsSourceSpecified();
00413                     
00414     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00415     Created:    12/10/94
00416     Inputs:     None
00417     Outputs:    None
00418     Returns:    TRUE if source image is specified else false
00419     Purpose:    Indicates whether or a source image has been specified yet
00420     Errors:     None from this one as yet
00421     SeeAlso:    -
00422 
00423 The source image will be specified if the last call to SetSourceImage was non null. Overridden
00424 if multiple source images need to be specified.
00425 
00426 ********************************************************************************************/
00427 
00428 BOOL BitmapEffectBase::IsSourceSpecified()
00429 {
00430     return (Source != NULL);
00431 }
00432                                 
00433 
00434 /********************************************************************************************
00435 
00436 >   BOOL BitmapEffectBase::IsAbleToRun();
00437                     
00438     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00439     Created:    12/10/94
00440     Inputs:     None
00441     Outputs:    None
00442     Returns:    TRUE if you've done enough setting up to do a Run
00443     Purpose:    Indicates whether you've done enough setting up to do a Run
00444     Errors:     None from this one as yet
00445     SeeAlso:    -
00446  
00447 For now just requires IsSourceSpecified
00448 
00449 ********************************************************************************************/
00450 
00451 BOOL BitmapEffectBase::IsAbleToRun()
00452 {
00453     return IsSourceSpecified();
00454 }
00455                     
00456 /********************************************************************************************
00457 
00458 >   BOOL BitmapEffectBase::Run();
00459                     
00460     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00461     Created:    12/10/94
00462     Inputs:     None
00463     Outputs:    None
00464     Returns:    TRUE if succeeded, FALSE if failed
00465     Purpose:    Runs a transform!
00466     Errors:     ERROR2 if called when parameters aren't set up properly
00467     SeeAlso:    -
00468 
00469 It's obviously important to override this!
00470 
00471 ********************************************************************************************/
00472 
00473 BOOL BitmapEffectBase::Run()
00474 {
00475     ERROR2IF(!IsAbleToRun(),FALSE,"BitmapEffectRun called at inappropriate time");
00476     return TRUE;
00477 }

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