bmpsrc.cpp

Go to the documentation of this file.
00001 // $Id: bmpsrc.cpp 751 2006-03-31 15:43: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 // 
00099 
00100 
00101 #include "camtypes.h"
00102 #include "bmpsrc.h"
00103 #include "ccbuffil.h"
00104 
00105 
00106 // Place any IMPLEMENT type statements here
00107 CC_IMPLEMENT_MEMDUMP(BitmapSource, CC_CLASS_MEMDUMP)
00108 
00109 
00110 // Declare smart memory handling in Debug builds
00111 // We want better memory tracking
00112 #define new CAM_DEBUG_NEW
00113 
00114 
00115 // Functions follow
00116 
00117 /********************************************************************************************
00118 
00119 >   BitmapSource::BitmapSource(OFFSET Size)
00120                     
00121     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00122     Created:    8/8/96
00123  
00124     Inputs:     Size :  The size of the bitmap source (usually the file size). Must be
00125                         greater than one.
00126  
00127     Purpose:    Constructor providing BitmapSource objects of the given size.
00128                 We construct objects of the required size, and associate bitmaps with
00129                 them via SetOriginalSource
00130  
00131     SeeAlso:    KernelBitmap::SetOriginalSource
00132  
00133 ********************************************************************************************/
00134 BitmapSource::BitmapSource(OFFSET Size)
00135 {
00136     m_pBuffer           = NULL;
00137     m_nSize             = 0;
00138     m_ReadWritePosition = 0;    
00139 
00140     if (Size > 0)
00141     {
00142         m_pBuffer   = new BYTE[Size];
00143         m_nSize     = Size;
00144     }
00145 }
00146 
00147 
00148 /********************************************************************************************
00149 
00150 >   BitmapSource::~BitmapSource()
00151                     
00152     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00153     Created:    18/08/96
00154  
00155     Purpose:    Destructor for BitmapSource objects
00156  
00157 ********************************************************************************************/
00158 BitmapSource::~BitmapSource()
00159 {
00160     if (m_pBuffer != NULL)
00161     {
00162         delete m_pBuffer;
00163         m_pBuffer = NULL;
00164     }       
00165     m_nSize = 0;
00166 }
00167 
00168 
00169 /********************************************************************************************
00170 
00171 >   BOOL BitmapSource::IsOK() const
00172                     
00173     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00174     Created:    8/8/96
00175 
00176     Returns:    TRUE if constructor succeeded
00177                 FALSE otherwise
00178  
00179     Purpose:    Since the constructor can fail, this member function determines whether or
00180                 not it was wholly successful.
00181                 Users should always call this function after constructing BitmapSource
00182                 objects
00183  
00184     SeeAlso:    BitmapSource::BitmapSource(...)
00185  
00186 ********************************************************************************************/
00187 BOOL BitmapSource::IsOK() const
00188 {
00189     return (m_pBuffer != NULL);
00190 }
00191 
00192 
00193 /********************************************************************************************
00194  
00195 >   virtual BOOL BitmapSource::GetByte(BYTE& byte)
00196                     
00197     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00198     Created:    20/08/96
00199  
00200     Outputs:    byte :  Returns the byte from the current position in the BitmapSource
00201  
00202     Purpose:    Allows this BitmapSource to be copied elsewhere (to disk) a byte at a time.
00203     Notes:      SeekPos() should be called to reset the current position
00204     Errors:     ERROR2 if trying to read beyond the end of this BitmapSource
00205 
00206  
00207 ********************************************************************************************/
00208 BOOL BitmapSource::GetByte(BYTE& byte)
00209 {
00210     ERROR2IF(m_ReadWritePosition > GetSize(), FALSE, "m_ReadWritePosition > GetSize()");
00211 
00212     byte = m_pBuffer[m_ReadWritePosition];
00213     ++m_ReadWritePosition;
00214 
00215     return TRUE;
00216 }
00217 
00218 
00219 /********************************************************************************************
00220 
00221 >   virtual BOOL BitmapSource::PutByte(const BYTE byte)
00222 
00223     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00224     Created:    20/08/96
00225 
00226     Inputs:     byte:   a BYTE to place at the current position in this BitmapSource
00227 
00228     Returns:    TRUE if put succeeded
00229                 FALSE otherwise
00230     Errors:     ERROR2 if trying to put after end of BitmapSource
00231     Purpose:    Adds a byte to this BitmapSorce object.
00232 
00233 ********************************************************************************************/
00234 BOOL BitmapSource::PutByte(const BYTE byte)
00235 {
00236     ERROR2IF(m_ReadWritePosition > GetSize(), FALSE, "m_ReadWritePosition > GetSize()");
00237 
00238     m_pBuffer[m_ReadWritePosition] = byte;
00239     ++m_ReadWritePosition;
00240 
00241     return TRUE;
00242 }
00243 
00244 
00245 /********************************************************************************************
00246 
00247 >   virtual FilePos BitmapSource::SeekPos(FilePos nPos)
00248 
00249 
00250     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00251     Created:    20/08/96
00252 
00253     Inputs:     nPos:   The position to be set
00254 
00255     Returns:    TRUE : if successful
00256                 FALSE:  otherwise
00257 
00258     Purpose:    Sets the position in the BitmapSource at which the next GetByte/PutByte will
00259                 occur. Usually this function will just be used to start from the beginning
00260                 of the BitmapSource, by passing zero for nPos.
00261 
00262     Errors:     ERROR2 if trying to seek after the end of this BitmapSource
00263 
00264 ********************************************************************************************/
00265 BOOL BitmapSource::SeekPos(OFFSET nPos)
00266 {
00267     ERROR2IF(nPos > GetSize(), FALSE, "nPos > GetSize()");
00268 
00269     m_ReadWritePosition = nPos;
00270     return TRUE;
00271 }
00272 
00273 
00274 /********************************************************************************************
00275 
00276 >   BOOL BitmapSource::AttachToBufferFile(CCBufferFile* pFile) const
00277 
00278     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00279     Created:    20/08/96
00280 
00281     Returns:    A pointer to a CCBufferFile object which will provide a reference to this
00282                 BitmapSource.
00283                 NULL is returned if an error occurred
00284 
00285     Purpose:    The entry points to filters need a CCFile object. This function
00286                 provides a CCFile object which uses this BitmapSource when calling the
00287                 CCFile member functions.
00288     Notes:      The returned CCFile should be destroyed using delete when no longer
00289                 needed
00290 
00291 ********************************************************************************************/
00292 BOOL BitmapSource::AttachToBufferFile(CCBufferFile* pFile) const
00293 {
00294     ERROR3IF(!pFile->IS_KIND_OF(CCBufferFile), "pFile is not");
00295 
00296     pFile->init(m_pBuffer, m_nSize);
00297 
00298     return TRUE;
00299 }

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