bfxpixop.h

Go to the documentation of this file.
00001 // $Id: bfxpixop.h 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 is the header file for the bitmap effect pixop class
00099 
00100 /*
00101 */
00102 
00103 #ifndef INC_BFXPIXOP
00104 #define INC_BFXPIXOP
00105 
00106 //#include "ccobject.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 
00108 class KernelBitmap;
00109 
00110 typedef struct
00111 {
00112     INT32 rsum;
00113     INT32 gsum;
00114     INT32 bsum;
00115     INT32 pixels;
00116     INT32 index;
00117 } QuantisationCell;
00118 
00119 
00120 /********************************************************************************************
00121 
00122 >   class BfxPixelOp : public CCObject
00123 
00124     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00125     Created:    12/10/1994
00126     Purpose:    Pixel operator
00127 
00128 The tracing stuff uses this class to determine whether or not a pixel should be traced or
00129 not.
00130 
00131 ********************************************************************************************/
00132 
00133 #define __bfxpixop_xy(x,y) Base[(x)+(y)*Width]
00134 
00135 class BfxPixelOp : public CCObject
00136 {
00137     CC_DECLARE_DYNCREATE(BfxPixelOp);
00138 
00139     public:
00140 
00141     BfxPixelOp();            /* Constructor */
00142     virtual ~BfxPixelOp();       /* Destructor */
00143 
00144     virtual BOOL Reset();
00145 
00146     virtual BOOL SetBitmap(KernelBitmap * pKB, DWORD theCacheStateMask, DWORD theCacheValueMask, BOOL theDefaultValue);
00147     
00148     virtual inline BOOL IsInRegion(INT32 x, INT32 y) {return DefaultValue;}
00149 
00150     virtual inline BOOL ClearCachedArea() {return TRUE;};
00151     virtual inline BOOL ClearEntireCache() {return TRUE;};
00152     virtual BOOL SetAuxilliaryBitmaps(KernelBitmap * pProposed /*A*/, KernelBitmap * pCurrent /*B*/,
00153                               KernelBitmap * pOriginal /*T*/, INT32 Threshold, DWORD theColour);
00154 
00155     virtual inline BOOL CheckMinimumArea(INT32 MinimumArea, INT32 InitialX, INT32 InitialY, BOOL * FoundRegion)
00156                             {*FoundRegion = FALSE; return TRUE;};
00157 
00158     virtual inline DWORD ReadPixel(void * Image, INT32 p) { return 0; }
00159     virtual inline void TranslateToRGB(DWORD Colour, KernelBitmap * pKB, INT32 * R, INT32 * G, INT32 * B)
00160         { *R = (INT32)(Colour >>16) & 0x0FF; *G = (INT32)(Colour>>8) & 0x0FF; *B = (INT32)(Colour/*>>0*/) & 0x0FF;return;};
00161 
00162     inline DWORD ReadOriginalPixel(INT32 x, INT32 y)
00163         { return ReadPixel((void *)pT, x+y*WidthRounded); };
00164 
00165     virtual inline DWORD ReadBPixel(INT32 x, INT32 y)
00166         { return ReadPixel((void *)pB, x+y*WidthRounded); };
00167 
00168     inline DWORD ReadPixel(void * Image, INT32 x, INT32 y) { return ReadPixel(Image, x+y*WidthRounded); };
00169 
00170     virtual inline void WritePixel(void * Image, INT32 p, DWORD Value) { return; }
00171     virtual inline DWORD TranslateToDWORD(KernelBitmap * pKB, INT32 R, INT32 G, INT32 B)
00172         { return ((R & 0xFF)<<16) | ((G & 0xFF)<<8) | (B & 0xFF); };
00173 
00174     inline void WriteOriginalPixel(INT32 x, INT32 y, DWORD Value)
00175         { WritePixel((void *)pT, x+y*WidthRounded, Value); return; };
00176 
00177     inline void WritePixel(void * Image, INT32 x, INT32 y, DWORD Value) { WritePixel(Image, x+y*WidthRounded, Value); return;};
00178 
00179     protected:
00180 
00181     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00182 
00183     DWORD * Base;
00184     INT32 Height;
00185     INT32 Width;
00186     INT32 WidthRounded;
00187     DWORD Size;
00188     BOOL DefaultValue;
00189 
00190     INT32 BPP;
00191 
00192     DWORD * pA;
00193     DWORD * pB;
00194     DWORD * pT;
00195     DWORD Colour;
00196     INT32 Value;
00197 
00198 };
00199 
00200 /********************************************************************************************
00201 
00202 >   class BfxPixelOp32 : public BfxPixelOp
00203 
00204     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00205     Created:    12/10/1994
00206     Purpose:    32 bit Pixel operator
00207 
00208 This class caches the state of a pixel in 2 bits of an otherwised top byte of a 32 bit bitmap.
00209 
00210 ********************************************************************************************/
00211 
00212 #define __bfxpixop_xy(x,y) Base[(x)+(y)*Width]
00213 
00214 class BfxPixelOp32 : public BfxPixelOp
00215 {
00216     CC_DECLARE_DYNCREATE(BfxPixelOp32);
00217 
00218     public:
00219 
00220     BfxPixelOp32();          /* Constructor */
00221     virtual ~BfxPixelOp32();         /* Destructor */
00222 
00223     virtual BOOL Reset();
00224 
00225     virtual BOOL SetBitmap(KernelBitmap * pKB, DWORD theCacheStateMask, DWORD theCacheValueMask, BOOL theDefaultValue);
00226     
00227     inline BOOL IsCached(INT32 x, INT32 y) { return (( (DWORD)x>=(DWORD)Width ) || ( (DWORD)y>=(DWORD)Height ) || (!Base))?
00228                                                 DefaultValue:((__bfxpixop_xy(x,y) & CacheStateMask)!=0); };
00229     virtual inline BOOL IsInRegion(INT32 x, INT32 y) {
00230         if (( (DWORD)x>=(DWORD)Width ) || ( (DWORD)y>=(DWORD)Height ) || (!Base)) return DefaultValue;
00231         DWORD *pix = &__bfxpixop_xy(x,y);
00232         BOOL val;
00233         return (((*pix) & CacheStateMask)!=0)?(((*pix) & CacheValueMask)!=0):
00234         (val=GetValueAdjustCache(x,y),(*pix)=((*pix)&~CacheValueMask) | CacheStateMask | (val?CacheValueMask:0),val);
00235         };
00236     virtual BOOL ClearCachedArea();
00237     virtual BOOL ClearEntireCache();
00238 
00239     virtual inline DWORD ReadPixel(void * Image, INT32 p)
00240     {
00241         if ((((DWORD)p)>=Size)||!Image)
00242         {
00243             ERROR3("Out of range BfxPixOp::ReadPixel()");
00244             return 0;
00245         }
00246         return ((DWORD *) Image)[p];
00247     };
00248 
00249     virtual inline void WritePixel(void * Image, INT32 p, DWORD Value)
00250     {
00251         if ((((DWORD)p)>=Size)||!Image)
00252         {
00253             ERROR3("Out of range BfxPixOp::WritePixel()");
00254             return;
00255         }
00256         ((DWORD *) Image)[p]=Value;
00257         return;
00258     };
00259 
00260     inline INT32 GetCacheMarks() { return CacheMarks; };
00261 
00262     virtual BOOL CheckMinimumArea(INT32 MinimumArea, INT32 InitialX, INT32 InitialY, BOOL * FoundRegion);
00263 
00264     protected:
00265 
00266     virtual BOOL GetValueAdjustCache(INT32 x, INT32 y);
00267     virtual BOOL FloodSearch(INT32 x, INT32 y, INT32 MinimumArea);
00268 
00269     DWORD CacheStateMask;
00270     DWORD CacheValueMask;
00271     INT32 CacheMarks;
00272 
00273     INT32 MinX;
00274     INT32 MinY;
00275     INT32 MaxX;
00276     INT32 MaxY;
00277 };
00278 
00279 /********************************************************************************************
00280 
00281 >   class BfxPixelOpPseudo : public BfxPixelOp
00282 
00283     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00284     Created:    12/10/1994
00285     Purpose:    32 bit Pixel operator
00286 
00287 This pixcel op handles pseudocolour bitmaps on an equality basis
00288 
00289 ********************************************************************************************/
00290 
00291 #define __bfxpixopl2_xy(x,y) (((Base[(x>>Log2BPP)+(y)*WidthRounded]) >> (x & XMask)) & BPPMask)
00292 
00293 // this is the maximum minimum area that can be used
00294 #define BFX_PSEUDOFLOODSIZE 256
00295 
00296 class BfxPixelOpPseudo : public BfxPixelOp
00297 {
00298     CC_DECLARE_DYNCREATE(BfxPixelOpPseudo);
00299 
00300     public:
00301 
00302     BfxPixelOpPseudo();          /* Constructor */
00303     virtual ~BfxPixelOpPseudo();         /* Destructor */
00304 
00305     virtual BOOL Reset();
00306 
00307     virtual BOOL SetBitmap(KernelBitmap * pKB, DWORD theCacheStateMask, DWORD theCacheValueMask, BOOL theDefaultValue);
00308     
00309     virtual inline BOOL IsInRegion(INT32 x, INT32 y) {
00310         if (( (DWORD)x>=(DWORD)Width ) || ( (DWORD)y>=(DWORD)Height ) ) return DefaultValue;
00311         else return IsPixelReallyInRegion(x, y);};
00312 
00313     virtual void TranslateToRGB(DWORD Colour, KernelBitmap * pKB, INT32 * R, INT32 * G, INT32 * B);
00314 
00315     virtual inline DWORD ReadPixel(void * Image, INT32 p)
00316     {
00317         if ( (((DWORD)p)>=Size)||!Image)
00318         {
00319             ERROR3("Out of range BfxPixOp::ReadPixel()");
00320             return 0;
00321         }
00322         return (DWORD)(((((BYTE *) Image)[p>>XShift])>>((XMask-(p & XMask))<<Log2BPP))&BPPMask);
00323     };
00324 
00325     virtual inline void WritePixel(void * Image, INT32 p, DWORD Value)
00326     {
00327         if ( (((DWORD)p)>=Size)||!Image)
00328         {
00329             ERROR3("Out of range BfxPixOp::ReadPixel()");
00330             return;
00331         }
00332         BYTE * thebyte = &(((BYTE *) Image)[p>>XShift]);
00333         INT32 shift = ((XMask-(p & XMask))<<Log2BPP);
00334         *thebyte = (BYTE)(((*thebyte) & ~(BPPMask<<shift)) | ((Value & BPPMask)<<shift));
00335         return;
00336     };
00337 
00338     virtual BOOL CheckMinimumArea(INT32 MinimumArea, INT32 InitialX, INT32 InitialY, BOOL * FoundRegion);
00339 
00340     protected:
00341 
00342     BOOL FloodSearch(INT32 x, INT32 y, INT32 MinimumArea,
00343                   INT32 FloodArray[BFX_PSEUDOFLOODSIZE][2], INT32 * FloodTop);
00344 
00345 
00346     INT32 Log2BPP;
00347     INT32 XShift;
00348     INT32 XMask;
00349     INT32 BPPMask;
00350 };
00351 
00352 /********************************************************************************************
00353 
00354 >   class BfxPixelOp24 : public BfxPixelOp
00355 
00356     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00357     Created:    12/10/1994
00358     Purpose:    32 bit Pixel operator
00359 
00360 This pixcel op handles pseudocolour bitmaps on an equality basis
00361 
00362 THIS PIXEL OP IS ONLY VERY PARTIALLY IMPLEMENTED - IT ONLY READS B PIXELS
00363 
00364 ********************************************************************************************/
00365 
00366 #define __bfxpixopl2_xy(x,y) (((Base[(x>>Log2BPP)+(y)*WidthRounded]) >> (x & XMask)) & BPPMask)
00367 
00368 class BfxPixelOp24 : public BfxPixelOp
00369 {
00370     CC_DECLARE_DYNCREATE(BfxPixelOp24);
00371 
00372     BfxPixelOp24() : BfxPixelOp() { BPP=24; };
00373 
00374     public:
00375 
00376     virtual inline DWORD ReadBPixel(INT32 x, INT32 y)
00377         { return *((DWORD *)&( ((BYTE *)(pB))[y*(((Width*3)+3)&~3)+(x*3)] ) ) &0x00FFFFFF; };
00378     
00379 };
00380 
00381 /********************************************************************************************
00382 
00383 >   class BfxPositivePixelOp : public BfxPixelOp32
00384 
00385     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00386     Created:    12/10/1994
00387     Purpose:    Pixel operator
00388 
00389 PixelOp that determines whether a pixel is better by more than a given amount in one bitmap
00390 than in another
00391 
00392 ********************************************************************************************/
00393 
00394 class BfxPositivePixelOp : public BfxPixelOp32
00395 {
00396     CC_DECLARE_DYNCREATE(BfxPositivePixelOp);
00397 
00398     protected:
00399     
00400     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00401     
00402 };
00403 
00404 /********************************************************************************************
00405 
00406 >   class BfxThresholdPixelOp : public BfxPixelOp32
00407 
00408     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00409     Created:    12/10/1994
00410     Purpose:    Pixel operator
00411 
00412 PixelOp that determines whether a pixel is better by more than a given amount in one bitmap
00413 than in another
00414 
00415 ********************************************************************************************/
00416 
00417 class BfxThresholdPixelOp : public BfxPixelOp32
00418 {
00419     CC_DECLARE_DYNCREATE(BfxThresholdPixelOp);
00420 
00421     protected:
00422 
00423     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00424 
00425 };
00426 
00427 /********************************************************************************************
00428 
00429 >   class BfxColourThresholdPixelOp : public BfxPixelOp32
00430 
00431     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00432     Created:    12/10/1994
00433     Purpose:    Pixel operator
00434 
00435 PixelOp that determines whether a pixel is better by more than a given amount in one bitmap
00436 than in another
00437 
00438 ********************************************************************************************/
00439 
00440 class BfxColourThresholdPixelOp : public BfxPixelOp32
00441 {
00442     CC_DECLARE_DYNCREATE(BfxColourThresholdPixelOp);
00443 
00444     protected:
00445 
00446     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00447 
00448 };
00449 
00450 /********************************************************************************************
00451 
00452 >   class BfxPositivePixelOpPseudo : public BfxPixelOpPseudo
00453 
00454     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00455     Created:    12/10/1994
00456     Purpose:    Pixel operator
00457 
00458 PixelOp that determines whether a pixel is better by more than a given amount in one bitmap
00459 than in another
00460 
00461 ********************************************************************************************/
00462 
00463 class BfxPositivePixelOpPseudo : public BfxPixelOpPseudo
00464 {
00465     CC_DECLARE_DYNCREATE(BfxPositivePixelOpPseudo);
00466 
00467     protected:
00468     
00469     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00470     
00471 };
00472 
00473 /********************************************************************************************
00474 
00475 >   class BfxThresholdPixelOpPseudo : public BfxPixelOpPseudo
00476 
00477     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00478     Created:    12/10/1994
00479     Purpose:    Pixel operator
00480 
00481 PixelOp that determines whether a pixel is better by more than a given amount in one bitmap
00482 than in another
00483 
00484 ********************************************************************************************/
00485 
00486 class BfxThresholdPixelOpPseudo : public BfxPixelOpPseudo
00487 {
00488     CC_DECLARE_DYNCREATE(BfxThresholdPixelOpPseudo);
00489 
00490     protected:
00491 
00492     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00493 
00494 };
00495 
00496 /********************************************************************************************
00497 
00498 >   class BfxColourThresholdPixelOpPseudo : public BfxPixelOpPseudo
00499 
00500     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00501     Created:    12/10/1994
00502     Purpose:    Pixel operator
00503 
00504 PixelOp that determines whether a pixel is better by more than a given amount in one bitmap
00505 than in another
00506 
00507 ********************************************************************************************/
00508 
00509 class BfxColourThresholdPixelOpPseudo : public BfxPixelOpPseudo
00510 {
00511     CC_DECLARE_DYNCREATE(BfxColourThresholdPixelOpPseudo);
00512 
00513     protected:
00514 
00515     virtual BOOL IsPixelReallyInRegion(INT32 x, INT32 y);
00516 
00517 };
00518 
00519 /********************************************************************************************
00520 
00521 >   class Octree : public CCObject
00522 
00523     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00524     Created:    12/10/1994
00525     Purpose:    Colour octree
00526 
00527 ********************************************************************************************/
00528 
00529 class OctreeElement : public SimpleCCObject
00530 {
00531     public:
00532 
00533     OctreeElement() { pParent=pListNext=pListPrev=NULL; for (INT32 c=0; c<8; c++) pChildren[c]=NULL;
00534                       Pixels=Depth=R=G=B=NumChildren=0;Index=-1;};
00535     ~OctreeElement() {
00536             for (INT32 c=0; c<8; c++) if (pChildren[c])
00537             {
00538                 delete (pChildren[c]);
00539                 pChildren[c]=NULL;
00540             }
00541             pParent=pListNext=pListPrev=NULL;Pixels=Depth=R=G=B=NumChildren=0;Index=-1;
00542         };
00543 
00544     INT32 Depth;
00545     INT32 R;
00546     INT32 G;
00547     INT32 B;
00548     INT32 Index;
00549     INT32 Pixels;
00550     INT32 NumChildren;
00551     OctreeElement * pChildren[8];
00552     OctreeElement * pParent;
00553     OctreeElement * pListNext;
00554     OctreeElement * pListPrev;
00555 };
00556 
00557 class Octree : public CCObject
00558 {
00559     CC_DECLARE_DYNCREATE(Octree);
00560 
00561     public:
00562 
00563     Octree();            /* Constructor */
00564     ~Octree();       /* Destructor */
00565 
00566     BOOL Init(INT32 NumColours);
00567     BOOL Insert(INT32 r, INT32 g, INT32 b);
00568     BOOL Index(RGBQUAD * Palette, OctreeElement * pEl=NULL);
00569     INT32 GetIndex(INT32 r, INT32 g, INT32 b);
00570 
00571     private:
00572 
00573     OctreeElement * GetElement(INT32 r, INT32 g, INT32 b);
00574     void CheckIntegrity();
00575     void Unlink(OctreeElement * pEl);
00576     void Link(OctreeElement * pEl);
00577 
00578     INT32 MaxLeaves;
00579     INT32 CurrentLeaves;
00580     OctreeElement * pTopElement;
00581     INT32 CurrentIndex;
00582 
00583     OctreeElement * ListHead[9 /*depth 0-8*/ ][9 /*children 0-8*/ ];
00584 
00585 };
00586 
00587 
00588 
00589 
00590 #endif
00591 

Generated on Sat Nov 10 03:48:06 2007 for Camelot by  doxygen 1.4.4