00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #ifndef INC_BFXPIXOP
00104 #define INC_BFXPIXOP
00105
00106
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
00123
00124
00125
00126
00127
00128
00129
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();
00142 virtual ~BfxPixelOp();
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 , KernelBitmap * pCurrent ,
00153 KernelBitmap * pOriginal , 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) & 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
00203
00204
00205
00206
00207
00208
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();
00221 virtual ~BfxPixelOp32();
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
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 #define __bfxpixopl2_xy(x,y) (((Base[(x>>Log2BPP)+(y)*WidthRounded]) >> (x & XMask)) & BPPMask)
00292
00293
00294 #define BFX_PSEUDOFLOODSIZE 256
00295
00296 class BfxPixelOpPseudo : public BfxPixelOp
00297 {
00298 CC_DECLARE_DYNCREATE(BfxPixelOpPseudo);
00299
00300 public:
00301
00302 BfxPixelOpPseudo();
00303 virtual ~BfxPixelOpPseudo();
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
00355
00356
00357
00358
00359
00360
00361
00362
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
00384
00385
00386
00387
00388
00389
00390
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
00407
00408
00409
00410
00411
00412
00413
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
00430
00431
00432
00433
00434
00435
00436
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
00453
00454
00455
00456
00457
00458
00459
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
00476
00477
00478
00479
00480
00481
00482
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
00499
00500
00501
00502
00503
00504
00505
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
00522
00523
00524
00525
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();
00564 ~Octree();
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 ][9 ];
00584
00585 };
00586
00587
00588
00589
00590 #endif
00591