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 #include "camtypes.h"
00104
00105 #include "bfxalu.h"
00106 #include "GDrawIntf.h"
00107 #include "gdrawcon.h"
00108
00109 #include "bitmpinf.h"
00110 #include "oilbitmap.h"
00111
00112
00113
00114
00115
00116
00117 #include "tracectl.h"
00118
00119
00120 #include "bfxpixop.h"
00121
00122 #include "progress.h"
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 #define ACCUSOFT_HAS_BROKEN_NON_FULL_PALETTES
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 #ifdef STANDALONE
00145 #undef FASTLINEARABK
00146 #undef FASTMARKBITBYWORD
00147 #undef FASTCLEARBITBYWORD
00148 #undef FASTMARKWORDBYBIT
00149 #undef FASTSCANBIT
00150 #undef FASTSCANTHRESHOLD
00151 #undef FASTSCANTHRESHOLD8
00152 #undef FASTMARKREGIONS
00153 #undef FASTMARKLARGESTAREA
00154 #undef FASTBUILDERRORREGIONLIST
00155 #undef FASTMARKTHRESHOLD
00156 #undef FASTMARKPOSITIVE
00157 #undef FASTMARKCOLOURTHRESHOLD
00158 #undef FASTREMOVEDITHER
00159 #endif
00160
00161
00162
00163 DECLARE_SOURCE("$Revision: 1282 $");
00164
00165
00166
00167 CC_IMPLEMENT_DYNCREATE(BfxALU, CCObject)
00168
00169 #ifndef EXCLUDE_FROM_RALPH
00170 CC_IMPLEMENT_DYNCREATE(BfxALULUT, CCObject)
00171 CC_IMPLEMENT_DYNCREATE(BfxErrorRegionList, CCObject);
00172
00173
00174
00175 #define new CAM_DEBUG_NEW
00176
00177 #define ALUC_PART 0
00178 #define ALUC_PARTMUL 1
00179 #define ALUC_PARTREVMUL 2
00180 #define ALUC_ADD 6
00181 #define ALUC_SUB 7
00182
00183
00184 #ifndef GAVIN_MONOCHROME_BITMAPS_BROKEN
00185 #define FixMono(i,s) { }
00186 #else
00187 #define FixMono(i,s) { BYTE __lut[256]; for(UINT32 __l=0;__l<256;__l++) __lut[__l]= (BYTE)(\
00188 ((__l & 0x80)>>7) + ((__l & 0x40)>>5) + ((__l & 0x20)>>3) + ((__l & 0x10)>>1) + \
00189 ((__l & 0x08)<<1) + ((__l & 0x04)<<3) + ((__l & 0x02)<<5) + ((__l & 0x01)<<7) ); \
00190 for (UINT32 __b=0; __b<((UINT32)s);__b++) ((BYTE *)(void *)i)[__b]=__lut[((BYTE *)(void *)i)[__b]];}
00191 #endif
00192
00193
00194
00195 #define BODGE_ACCUSOFT_RESIZE
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 #define LUTBYTE(x,y) Data[x+(y<<8)]
00217
00218 BOOL BfxALULUT::LinearABK(double PropA, double PropB, double Offset)
00219 {
00220 INT32 pa=(INT32)(PropA*(1<<15));
00221 INT32 pb=(INT32)(PropB*(1<<15));
00222 INT32 po=(INT32)(Offset*((1<<15)*255)+(1<<14));
00223
00224
00225
00226
00227 #ifndef FASTLINEARABK
00228 INT32 a;
00229 INT32 b;
00230 INT32 r;
00231 for (a=0; a<256; a++) for (b=0; b<256; b++)
00232 {
00233 r=(a*pa+b*pb+po)>>15;
00234 LUTBYTE(a,b)=(r<0)?0:((r>255)?255:(BYTE)(INT32)(r));
00235 }
00236 #else
00237 FastLinearABK(Data, pa, pb, po, 256);
00238 #if 0
00239 INT32 a;
00240 INT32 b;
00241 INT32 r;
00242 for (a=0; a<256; a++) for (b=0; b<256; b++)
00243 {
00244 r=(a*pa+b*pb+po)>>15;
00245 if (LUTBYTE(a,b)!=((r<0)?0:((r>255)?255:(BYTE)(INT32)(r))))
00246 {
00247 TRACEUSER( "Alex", _T("Byte %x,%x was %x should be %x\n"),a,b,
00248 LUTBYTE(a,b),( (r<0)?0:((r>255)?255:(BYTE)(INT32)(r)) ) );
00249 }
00250 }
00251 #endif
00252 #endif
00253
00254
00255 return(TRUE);
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 BYTE BfxALULUT::GetLUT(UINT32 A, UINT32 B)
00276 {
00277 return LUTBYTE(A,B);
00278 }
00279
00280 #endif // EXCLUDE_FROM_RALPH
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 BfxALU::BfxALU()
00300 {
00301 #ifndef EXCLUDE_FROM_RALPH
00302 GC = NULL;
00303 ResetAccusoftDibsToRuns = FALSE;
00304 #endif
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 BfxALU::~BfxALU()
00325 {
00326 #ifndef EXCLUDE_FROM_RALPH
00327
00328 ERROR3IF( (GC!=NULL), "Someone hasn't called the BfxALU deinit function!");
00329 #endif
00330 }
00331
00332 #ifndef EXCLUDE_FROM_RALPH
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 BOOL BfxALU::Init()
00353 {
00354 GC = new GDrawAsm;
00355 ERROR2IF((GC==NULL),FALSE,"Couldn't get a GDrawContext for the BfxALU");
00356 if (!GC->Init())
00357 {
00358 GC=NULL;
00359 ERROR2(FALSE,"Couldn't initialise GDrawContext for the BfxALU");
00360 }
00361
00362 identity.AX=identity.BY=1<<(FX+16);identity.CX=identity.CY=identity.AY=identity.BX=0;
00363 GC->SetupBitmap(256,256,32,NULL,TRUE);
00364 GC->SetMatrix(&identity);
00365 GC->SetAntialiasFlag(FALSE);
00366 GC->SelectPalette(0);
00367 GC->SetHalftoneOrigin(0,0);
00368
00369 return TRUE;
00370 }
00371
00372
00373 void BfxALU::TestGD()
00374 {
00375 identity.AX=identity.BY=1<<(FX+16);identity.CX=identity.CY=identity.AY=identity.BX=0;
00376 GC->SetupBitmap(256,256,32,NULL,TRUE);
00377 GC->SetMatrix(&identity);
00378 GC->SetAntialiasFlag(FALSE);
00379 GC->SelectPalette(0);
00380 GC->SetHalftoneOrigin(0,0);
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 BOOL BfxALU::DeInit()
00401 {
00402 if (GC)
00403 {
00404 delete GC;
00405 GC=NULL;
00406 }
00407 return TRUE;
00408 }
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 KernelBitmap * BfxALU::NewBitmap(KernelBitmap *pBitmap,INT32 XAdjust,INT32 YAdjust,INT32 NewDepth,
00444 String_256 * pName , UINT32 ResID )
00445 {
00446 INT32 Width;
00447 INT32 Height;
00448 INT32 Depth;
00449 INT32 DPI;
00450 BOOL IsTemp=TRUE;
00451
00452 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00453 if (!pBitmap)
00454 {
00455 Width=0;
00456 Height=0;
00457 Depth=32;
00458 DPI=96;
00459 IsTemp=FALSE;
00460 }
00461 else
00462 {
00463 ERROR2IF((pBitmap->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00464 ERROR3IF( (!(pBitmap->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00465
00466 BitmapInfo BMInfo;
00467 pBitmap->ActualBitmap->GetInfo(&BMInfo);
00468 Depth=BMInfo.PixelDepth;
00469 Width=BMInfo.PixelWidth;
00470 Height=BMInfo.PixelHeight;
00471 DPI=96;
00472 }
00473
00474 Width+=XAdjust;
00475 Height+=YAdjust;
00476 if (NewDepth) Depth=NewDepth;
00477
00478
00479
00480 KernelBitmap * pNewBitmap = new KernelBitmap(Width,Height,Depth,DPI,IsTemp);
00481 if (!pNewBitmap) return FALSE;
00482 if (!pNewBitmap->ActualBitmap)
00483 {
00484 delete pNewBitmap;
00485 return FALSE;
00486 }
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497 ERROR2IF((pNewBitmap->ActualBitmap==NULL) || (((CWxBitmap *)(pNewBitmap->ActualBitmap))->BMInfo==NULL) || (((CWxBitmap *)(pNewBitmap->ActualBitmap))->BMBytes==NULL),
00498 FALSE,"BfxALU can't find OIL bitmap of the new bitmap");
00499
00500 if (pBitmap)
00501 {
00502 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
00503 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(pNewBitmap->ActualBitmap))->BMInfo->bmiHeader);
00504
00505 pBBMI->biXPelsPerMeter = pABMI->biXPelsPerMeter;
00506 pBBMI->biYPelsPerMeter = pABMI->biYPelsPerMeter;
00507
00508 if (Depth<=8)
00509 {
00510 if (pBBMI->biClrUsed==pABMI->biClrUsed && pBBMI->biBitCount==pABMI->biBitCount)
00511 {
00512
00513 memcpy(pBBMI+1 , pABMI+1 , pBBMI->biClrUsed*sizeof(DWORD));
00514 }
00515 }
00516 }
00517
00518 String_256 BitmapName;
00519 if (pName)
00520 BitmapName=*pName;
00521 else
00522 {
00523 if (pBitmap)
00524 BitmapName=pBitmap->ActualBitmap->GetName();
00525 else
00526 BitmapName=pNewBitmap->ActualBitmap->GetName();
00527 }
00528
00529 if ((ResID) && (BitmapName.Length()<128))
00530 {
00531 String_256 Mask(_R(IDS_BFXALU_MASK_START));
00532 String_256 Mask2(_R(IDS_BFXALU_MASK_END));
00533 TCHAR Fuzz = '*';
00534 String_256 Processed(_R(IDS_BFX_PROCESSED));
00535 String_256 Res(ResID);
00536 INT32 pos = BitmapName.Sub(Mask, 0, Fuzz);
00537 if (pos>=0) if (BitmapName.Sub(Mask2, pos, Fuzz)<0) pos=-1;
00538 if (pos>=0) BitmapName.Left(&BitmapName, pos);
00539 BitmapName += String_8(_R(IDS_BFXALU_PROCESSED_START));
00540 if (pos>=0) BitmapName+=Processed;
00541 BitmapName+=Res;
00542 BitmapName += String_8(_R(IDS_BFXALU_PROCESSED_END));
00543 }
00544
00545 GetApplication()->GetGlobalBitmapList()->MakeNameUnique(&BitmapName);
00546
00547 pNewBitmap->ActualBitmap->SetName(BitmapName);
00548
00549 return pNewBitmap;
00550
00551 }
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 BOOL BfxALU::SetA(KernelBitmap * pBitmap)
00577 {
00578 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00579 if (!pBitmap)
00580 {
00581 GC->SetupBitmap(256,256,32,NULL,TRUE);
00582 GC->SetMatrix(&identity);
00583 A=NULL;
00584 return(TRUE);
00585 }
00586 else
00587 {
00588 ERROR2IF((pBitmap->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00589 ERROR3IF( (!(pBitmap->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00590
00591
00592 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
00593 ERROR2IF( (!GC->SetupBitmap(pBMI->biWidth,pBMI->biHeight,pBMI->biBitCount,
00594 ((CWxBitmap *)(pBitmap->ActualBitmap))->BMBytes)),
00595 FALSE,"GDraw didn't like BfxALU accumulator");
00596 GC->SetMatrix(&identity);
00597 A=pBitmap;
00598 return(TRUE);
00599 }
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 BOOL BfxALU::SetB(KernelBitmap * pBitmap,INT32 XOffset,INT32 YOffset,const BYTE * pTable,DWORD Style)
00628 {
00629 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00630 if (!pBitmap)
00631 {
00632 B=NULL;
00633 BColour=0;
00634 return(TRUE);
00635 }
00636 else
00637 {
00638 ERROR2IF((pBitmap->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00639 ERROR3IF( (!(pBitmap->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00640 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
00641
00642 BPoints[0].x = XOffset; BPoints[0].y = YOffset;
00643 BPoints[1].x = XOffset+(INT32)(pBMI->biWidth); BPoints[1].y = YOffset;
00644 BPoints[2].x = XOffset; BPoints[2].y = YOffset+(INT32)(pBMI->biHeight);
00645 B=pBitmap;
00646 BpTable=pTable;
00647 BStyle=Style;
00648 return(TRUE);
00649 }
00650 }
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 BOOL BfxALU::SetB(DWORD Colour)
00674 {
00675 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00676 B=NULL;
00677 BColour=Colour;
00678 return TRUE;
00679 }
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706 BOOL BfxALU::SetT(KernelBitmap * pBitmap,INT32 XOffset,INT32 YOffset,const BYTE * pTable,DWORD Style)
00707 {
00708 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00709 if (!pBitmap)
00710 {
00711 T=NULL;
00712 TValue=0;
00713 return(TRUE);
00714 }
00715 else
00716 {
00717 ERROR2IF((pBitmap->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00718 ERROR3IF( (!(pBitmap->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00719 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
00720
00721
00722 TPoints[0].x = XOffset; TPoints[0].y = YOffset;
00723 TPoints[1].x = XOffset+(INT32)(pBMI->biWidth); TPoints[1].y = YOffset;
00724 TPoints[2].x = XOffset; TPoints[2].y = YOffset+(INT32)(pBMI->biHeight);
00725 T=pBitmap;
00726 TpTable=pTable;
00727 TStyle=Style;
00728 return(TRUE);
00729 }
00730 }
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753 BOOL BfxALU::SetT(DWORD Value)
00754 {
00755 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00756 T = NULL;
00757 TValue = Value;
00758 return TRUE;
00759 }
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778 BOOL BfxALU::DoRect()
00779 {
00780 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00781 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)),FALSE,"BfxALU can't find OIL bitmap");
00782 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00783 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
00784 RECT Rect={0,pBMI->biHeight,pBMI->biWidth,0};
00785 ERROR2IF((!GC->FillRectangle(&Rect)),FALSE,"BfxALU GDraw_FillRectangle failed");
00786
00787 #if 0
00788 GC->SetColour((COLORREF) 0x0000FF00);
00789 GC->SetTransparency((COLORREF) 0x0000FF00,(enum TransparencyEnum) 0);
00790 RECT Rect2={0+40,pBMI->biHeight-40,pBMI->biWidth-40,0+40};
00791 ERROR2IF((!GC->FillRectangle(&Rect2)),FALSE,"BfxALU GDraw_FillRectangle failed");
00792 #endif
00793
00794
00795 return(TRUE);
00796 }
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 BOOL BfxALU::ZeroA(DWORD FillValue)
00816 {
00817 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00818 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
00819 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00820 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
00821
00822 memset(((CWxBitmap *)(A->ActualBitmap))->BMBytes, FillValue ,pBMI->biSizeImage);
00823 #if 0
00824 RECT Rect={0,pBMI->biHeight,pBMI->biWidth,0};
00825 GC->SetColour((COLORREF) 0x00000000);
00826 GC->SetTransparency((COLORREF) 0x00000000,(enum TransparencyEnum) 0);
00827 ERROR2IF((!GC->FillRectangle(&Rect)),FALSE,"BfxALU GDraw_FillRectangle failed");
00828 #endif
00829 return(TRUE);
00830 }
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849 BOOL BfxALU::UseBT(DWORD TransparencyStyle)
00850 {
00851 DWORD Style;
00852 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00853
00854 if (T)
00855 Style = TransparencyStyle+7;
00856 else
00857 Style = (TransparencyStyle+4)+(TValue<<8);
00858
00859 if ((!B) && (!T))
00860 {
00861 ERROR2IF((!GC->SetTransparency(BColour | TValue,(enum TransparencyEnum) Style)),FALSE,"Bad BfxALU BT reg");
00862 }
00863
00864 if ((B) && (!T))
00865 {
00866 ERROR2IF((B->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00867 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00868 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
00869
00870 ERROR2IF( (!GC->SetBitmapFill(pBMI,(((CWxBitmap *)(B->ActualBitmap))->BMBytes),
00871 BStyle | (Style<<8),
00872 BPoints,
00873 0,
00874 ((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiColors,
00875 (unsigned char *) BpTable,
00876 (unsigned char *) BpTable,
00877 (unsigned char *) BpTable,
00878 NULL
00879 )),
00880 FALSE,"GDraw didn't like BfxALU B reg");
00881
00882 }
00883 if ((!B) && (T))
00884 {
00885
00886 ERROR2IF((!GC->SetTransparency(BColour,(enum TransparencyEnum) Style)),FALSE,"Bad BfxALU BT reg");
00887
00888 ERROR2IF((T->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00889 ERROR3IF( (!(T->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00890 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(T->ActualBitmap))->BMInfo->bmiHeader);
00891 ERROR2IF((pBMI->biBitCount !=8), FALSE,"Bad BfxALU T reg");
00892 ERROR2IF( (!GC->SetTransparentBitmapFill(pBMI,(((CWxBitmap *)(T->ActualBitmap))->BMBytes),
00893 TStyle | (Style<<8),
00894 TPoints,
00895 0
00896 )),
00897 FALSE,"GDraw didn't like BfxALU T reg");
00898 }
00899
00900 if ((B) && (T))
00901 {
00902 ERROR2IF((B->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00903 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00904 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
00905
00906 ERROR2IF( (!GC->SetBitmapFill(pBMI,(((CWxBitmap *)(B->ActualBitmap))->BMBytes),
00907 BStyle | (Style<<8),
00908 BPoints,
00909 0,
00910 ((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiColors,
00911 (unsigned char *) BpTable,
00912 (unsigned char *) BpTable,
00913 (unsigned char *) BpTable,
00914 NULL
00915 )),
00916 FALSE,"GDraw didn't like BfxALU B reg");
00917
00918 ERROR2IF((T->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00919 ERROR3IF( (!(T->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00920 pBMI=&(((CWxBitmap *)(T->ActualBitmap))->BMInfo->bmiHeader);
00921 ERROR2IF((pBMI->biBitCount !=8), FALSE,"Bad BfxALU T reg");
00922 ERROR2IF( (!GC->SetTransparentBitmapFill(pBMI,(((CWxBitmap *)(T->ActualBitmap))->BMBytes),
00923 TStyle | (Style<<8),
00924 TPoints,
00925 0
00926 )),
00927 FALSE,"GDraw didn't like BfxALU T reg");
00928 }
00929
00930
00931 return DoRect();
00932 }
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952 BOOL BfxALU::UseBK(DWORD TransparencyStyle,DWORD Value)
00953 {
00954 DWORD Style;
00955 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
00956
00957 Style = (TransparencyStyle+4)+(Value<<8);
00958
00959 if (!B)
00960 {
00961 ERROR2IF((!GC->SetTransparency(BColour | TValue,(enum TransparencyEnum) Style)),FALSE,"Bad BfxALU BT reg");
00962 }
00963 else
00964 {
00965 ERROR2IF((B->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
00966 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
00967 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
00968
00969 ERROR2IF( (!GC->SetBitmapFill(pBMI,(((CWxBitmap *)(B->ActualBitmap))->BMBytes),
00970 BStyle | (Style<<8),
00971 BPoints,
00972 0,
00973 ((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiColors,
00974 (unsigned char *) BpTable,
00975 (unsigned char *) BpTable,
00976 (unsigned char *) BpTable,
00977 NULL
00978 )),
00979 FALSE,"GDraw didn't like BfxALU B reg");
00980
00981 }
00982
00983 return DoRect();
00984 }
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003 BOOL BfxALU::PlotB()
01004 {
01005 DWORD Style=0;
01006 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01007
01008 if (!B)
01009 {
01010 ERROR2IF((!GC->SetTransparency(BColour,(enum TransparencyEnum) Style)),FALSE,"Bad BfxALU B reg");
01011 }
01012 else
01013 {
01014 ERROR2IF((B->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
01015 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01016 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
01017
01018 ERROR2IF( (!GC->SetBitmapFill(pBMI,(((CWxBitmap *)(B->ActualBitmap))->BMBytes),
01019 BStyle | (Style<<8),
01020 BPoints,
01021 0,
01022 ((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiColors,
01023 (unsigned char *) BpTable,
01024 (unsigned char *) BpTable,
01025 (unsigned char *) BpTable,
01026 NULL
01027 )),
01028 FALSE,"GDraw didn't like BfxALU B reg");
01029
01030 }
01031
01032 return DoRect();
01033 }
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052 BOOL BfxALU::PlotBLUT(BfxALULUT * LUT)
01053 {
01054 DWORD Style=12;
01055 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01056 ERROR2IF((GC==NULL),FALSE,"BfxALU::PlotBLUT() where's my LUT then?");
01057
01058 if (!B)
01059 {
01060 ERROR2IF((!GC->SetTransparency(BColour,(enum TransparencyEnum) Style)),FALSE,"Bad BfxALU B reg");
01061 }
01062 else
01063 {
01064 ERROR2IF((B->ActualBitmap==NULL),FALSE,"BfxALU can't find OIL bitmap");
01065 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01066 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
01067
01068 ERROR2IF( (!GC->SetTransparencyLookupTable((CONST BYTE *) (LUT->Data))),FALSE,"Bad LUT");
01069 ERROR2IF( (!GC->SetBitmapFill(pBMI,(((CWxBitmap *)(B->ActualBitmap))->BMBytes),
01070 BStyle | (Style<<8),
01071 BPoints,
01072 0,
01073 ((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiColors,
01074 (unsigned char *) BpTable,
01075 (unsigned char *) BpTable,
01076 (unsigned char *) BpTable,
01077 NULL
01078 )),
01079 FALSE,"GDraw didn't like BfxALU B reg");
01080
01081 }
01082
01083 return DoRect();
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102 BOOL BfxALU::PartTAB()
01103 {
01104 return UseBT(ALUC_PART);
01105 }
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 BOOL BfxALU::PartMulTAB()
01124 {
01125 return UseBT(ALUC_PARTMUL);
01126 }
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144 BOOL BfxALU::PartRevMulTAB()
01145 {
01146 return UseBT(ALUC_PARTREVMUL);
01147 }
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165 BOOL BfxALU::AddTAB()
01166 {
01167 return UseBT(ALUC_ADD);
01168 }
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186 BOOL BfxALU::SubTAB()
01187 {
01188 return UseBT(ALUC_SUB);
01189 }
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207 BOOL BfxALU::PartKAB(DWORD Value)
01208 {
01209 return UseBK(ALUC_PART, Value);
01210 }
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228 BOOL BfxALU::PartMulKAB(DWORD Value)
01229 {
01230 return UseBK(ALUC_PARTMUL, Value);
01231 }
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249 BOOL BfxALU::PartRevMulKAB(DWORD Value)
01250 {
01251 return UseBK(ALUC_PARTREVMUL, Value);
01252 }
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270 BOOL BfxALU::AddKAB(DWORD Value)
01271 {
01272 return UseBK(ALUC_ADD, Value);
01273 }
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291 BOOL BfxALU::SubKAB(DWORD Value)
01292 {
01293 return UseBK(ALUC_SUB, Value);
01294 }
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317 BOOL BfxALU::MarkThresholdError(INT32 Value, DWORD MarkValue, DWORD ClearValue)
01318 {
01319 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01320 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01321 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01322 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01323 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01324 ERROR2IF( ((!T) || (T->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01325 ERROR3IF( (!(T->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01326
01327 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01328 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
01329 BITMAPINFOHEADER * pTBMI=&(((CWxBitmap *)(T->ActualBitmap))->BMInfo->bmiHeader);
01330
01331 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01332 ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01333 ERROR2IF((pTBMI->biBitCount !=32), FALSE,"Bad BfxALU T reg");
01334
01335 ERROR2IF( ((pABMI->biSizeImage != pBBMI->biSizeImage) || (pABMI->biSizeImage != pTBMI->biSizeImage)), FALSE,
01336 "Incompatible bitmaps for MarkThresholdError");
01337
01338
01339 AluPix32 * pB = (AluPix32 *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01340 AluPix32 * pT = (AluPix32 *)(void *)(((CWxBitmap *)(T->ActualBitmap))->BMBytes);
01341 DWORD * pO = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01342
01343 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01344
01345 INT32 Size = (pABMI->biSizeImage)>>2;
01346
01347 #ifdef FASTMARKTHRESHOLD
01348 XLONG BError = 0;
01349 INT32 MarkedPixels = 0;
01350
01351 FastMarkThreshold((DWORD *)(void *)pA, (DWORD *)(void *)pB, (DWORD *)(void *)pT, Size, Value, MarkValue, ClearValue,
01352 &BError, &MarkedPixels);
01353
01354
01355
01356 #else
01357 for (INT32 Pixel = 0; Pixel < Size; Pixel ++)
01358 pO[Pixel] = (( IntegerSquare( ((INT32)(pB[Pixel].R)) - ((INT32)(pT[Pixel].R)))
01359 + IntegerSquare( ((INT32)(pB[Pixel].G)) - ((INT32)(pT[Pixel].G)))
01360 + IntegerSquare( ((INT32)(pB[Pixel].B)) - ((INT32)(pT[Pixel].B)))) >= Value ) ? MarkValue : ClearValue;
01361 #endif
01362 return TRUE;
01363 }
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391 BOOL BfxALU::MarkColourThresholdError(INT32 Value, DWORD Colour, DWORD MarkValue, DWORD ClearValue,
01392 double * pAError, double * pBError, INT32 * pTotalPixels, INT32 * pMarkedPixels)
01393 {
01394 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01395 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01396 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01397 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01398 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01399 ERROR2IF( ((!T) || (T->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01400 ERROR3IF( (!(T->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01401
01402 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01403 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01404 BITMAPINFOHEADER * pTBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01405
01406 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01407 ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01408 ERROR2IF((pTBMI->biBitCount !=32), FALSE,"Bad BfxALU T reg");
01409
01410 ERROR2IF( ((pABMI->biSizeImage != pBBMI->biSizeImage) || (pABMI->biSizeImage != pTBMI->biSizeImage)), FALSE,
01411 "Incompatible bitmaps for MarkThresholdError");
01412
01413
01414 AluPix32 * pB = (AluPix32 *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01415 AluPix32 * pT = (AluPix32 *)(void *)(((CWxBitmap *)(T->ActualBitmap))->BMBytes);
01416 DWORD * pO = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01417
01418 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01419
01420 AluPix32 TheColour;
01421 *(DWORD *)(void *)(&TheColour)=Colour;
01422
01423 INT32 Size = (pABMI->biSizeImage)>>2;
01424 if (pTotalPixels) *pTotalPixels = Size;
01425
01426 #ifdef FASTMARKCOLOURTHRESHOLD
01427 XLONG AError = 0;
01428 XLONG BError = 0;
01429 INT32 MarkedPixels = 0;
01430
01431 FastMarkColourThreshold((DWORD *)(void *)pA, (DWORD *)(void *)pB, (DWORD *)(void *)pT, Size, Value, Colour,
01432 MarkValue, ClearValue, &AError, &BError, &MarkedPixels);
01433
01434 if (pAError) *pAError = AError.MakeDouble();
01435 if (pBError) *pBError = BError.MakeDouble();
01436 if (pMarkedPixels) *pMarkedPixels = MarkedPixels;
01437
01438 #else
01439 double AError = 0.0;
01440 double BError = 0.0;
01441 INT32 BE;
01442 INT32 AE;
01443 INT32 MarkedPixels=0;
01444
01445 for (INT32 Pixel = 0; Pixel < Size; Pixel ++)
01446 { AE = ( IntegerSquare( ((INT32)(TheColour.R)) - ((INT32)(pT[Pixel].R)))
01447 + IntegerSquare( ((INT32)(TheColour.G)) - ((INT32)(pT[Pixel].G)))
01448 + IntegerSquare( ((INT32)(TheColour.B)) - ((INT32)(pT[Pixel].B))) );
01449
01450 BE = ( IntegerSquare( ((INT32)(pB[Pixel].R)) - ((INT32)(pT[Pixel].R)))
01451 + IntegerSquare( ((INT32)(pB[Pixel].G)) - ((INT32)(pT[Pixel].G)))
01452 + IntegerSquare( ((INT32)(pB[Pixel].B)) - ((INT32)(pT[Pixel].B))) );
01453
01454 AError += AE;
01455 BError += BE;
01456
01457 pO[Pixel] = ((AE<Value) && (BE>=Value)) ? (MarkedPixels++,MarkValue) : ClearValue;
01458 }
01459
01460 if (pAError) *pAError = AError;
01461 if (pBError) *pBError = BError;
01462 if (pMarkedPixels) *pMarkedPixels = MarkedPixels;
01463 #endif
01464
01465 return TRUE;
01466 }
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493 BOOL BfxALU::MarkPositive(INT32 Value, DWORD MarkValue, DWORD ClearValue,
01494 double * pAError, double * pBError, INT32 * pTotalPixels, INT32 * pMarkedPixels)
01495 {
01496 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01497 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01498 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01499 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01500 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01501 ERROR2IF( ((!T) || (T->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01502 ERROR3IF( (!(T->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01503
01504 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01505 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01506 BITMAPINFOHEADER * pTBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01507
01508 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01509 ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01510 ERROR2IF((pTBMI->biBitCount !=32), FALSE,"Bad BfxALU T reg");
01511
01512 ERROR2IF( ((pABMI->biSizeImage != pBBMI->biSizeImage) || (pABMI->biSizeImage != pTBMI->biSizeImage)), FALSE,
01513 "Incompatible bitmaps for MarkThresholdError");
01514
01515 AluPix32 * pA = (AluPix32 *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01516 AluPix32 * pB = (AluPix32 *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01517 AluPix32 * pT = (AluPix32 *)(void *)(((CWxBitmap *)(T->ActualBitmap))->BMBytes);
01518 DWORD * pO = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01519
01520 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01521
01522 INT32 Size = (pABMI->biSizeImage)>>2;
01523 if (pTotalPixels) *pTotalPixels = Size;
01524
01525 #ifdef FASTMARKPOSITIVE
01526 XLONG AError = 0;
01527 XLONG BError = 0;
01528 INT32 MarkedPixels = 0;
01529
01530 FastMarkPositive((DWORD *)(void *)pA, (DWORD *)(void *)pB, (DWORD *)(void *)pT, Size, Value, MarkValue, ClearValue,
01531 &AError, &BError, &MarkedPixels);
01532
01533 if (pAError) *pAError = AError.MakeDouble();
01534 if (pBError) *pBError = BError.MakeDouble();
01535 if (pMarkedPixels) *pMarkedPixels = MarkedPixels;
01536
01537 #else
01538 double AError = 0.0;
01539 double BError = 0.0;
01540 INT32 BE;
01541 INT32 AE;
01542 INT32 MarkedPixels=0;
01543
01544 for (INT32 Pixel = 0; Pixel < Size; Pixel ++)
01545 { AE = ( IntegerSquare( ((INT32)(pA[Pixel].R)) - ((INT32)(pT[Pixel].R)))
01546 + IntegerSquare( ((INT32)(pA[Pixel].G)) - ((INT32)(pT[Pixel].G)))
01547 + IntegerSquare( ((INT32)(pA[Pixel].B)) - ((INT32)(pT[Pixel].B))) );
01548
01549 BE = ( IntegerSquare( ((INT32)(pB[Pixel].R)) - ((INT32)(pT[Pixel].R)))
01550 + IntegerSquare( ((INT32)(pB[Pixel].G)) - ((INT32)(pT[Pixel].G)))
01551 + IntegerSquare( ((INT32)(pB[Pixel].B)) - ((INT32)(pT[Pixel].B))) );
01552
01553 AError += AE;
01554 BError += BE;
01555
01556 pO[Pixel] = ((AE<Value) && (BE>=Value)) ? (MarkedPixels++,MarkValue) : ClearValue;
01557 }
01558
01559 if (pAError) *pAError = AError;
01560 if (pBError) *pBError = BError;
01561 if (pMarkedPixels) *pMarkedPixels = MarkedPixels;
01562 #endif
01563
01564 return TRUE;
01565 }
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585 BOOL BfxALU::MarkBitByWord(DWORD BitMask, DWORD TheWord)
01586 {
01587 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01588 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01589 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01590 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01591 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01592
01593 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01594 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01595
01596 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01597 ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01598
01599 ERROR2IF( (pABMI->biSizeImage != pBBMI->biSizeImage), FALSE, "Incompatible bitmaps for MarkBitByWord");
01600
01601 DWORD * pA = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01602 DWORD * pB = (DWORD *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01603
01604 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01605
01606 INT32 Size = (pABMI->biSizeImage)>>2;
01607
01608 #ifdef FASTMARKBITBYWORD
01609 FastMarkBitByWord(pB, pA, Size, BitMask, TheWord);
01610 #else
01611 for (INT32 Pixel = 0; Pixel < Size; Pixel ++) if (pB[Pixel]==TheWord) pA[Pixel]|=BitMask; else pA[Pixel]&=~BitMask;
01612 #endif
01613
01614 return TRUE;
01615 }
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633 BOOL BfxALU::ClearBitByWord(DWORD BitMask, DWORD TheWord)
01634 {
01635 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01636 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01637 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01638 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01639 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01640
01641 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01642 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01643
01644 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01645 ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01646
01647 ERROR2IF( (pABMI->biSizeImage != pBBMI->biSizeImage), FALSE, "Incompatible bitmaps for MarkBitByWord");
01648
01649 DWORD * pA = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01650 DWORD * pB = (DWORD *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01651
01652 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01653
01654 INT32 Size = (pABMI->biSizeImage)>>2;
01655
01656 #ifdef FASTCLEARBITBYWORD
01657 FastClearBitByWord(pB, pA, Size, BitMask, TheWord);
01658 #else
01659 for (INT32 Pixel = 0; Pixel < Size; Pixel ++) if (pB[Pixel]==TheWord) pA[Pixel]&=~BitMask;
01660 #endif
01661
01662 return TRUE;
01663 }
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681 BOOL BfxALU::MarkWordByBit(DWORD BitMask, DWORD MarkValue, DWORD ClearValue)
01682 {
01683 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01684 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01685 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01686 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01687 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01688
01689 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01690 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01691
01692 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01693 ERROR2IF((pBBMI->biBitCount !=32), FALSE,"Bad BfxALU B reg");
01694
01695 ERROR2IF( (pABMI->biSizeImage != pBBMI->biSizeImage), FALSE, "Incompatible bitmaps for MarkWordByBit");
01696
01697 DWORD * pB = (DWORD *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
01698 DWORD * pA = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01699
01700 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
01701
01702 INT32 Size = (pABMI->biSizeImage)>>2;
01703
01704 #ifdef FASTMARKWORDBYBIT
01705 FastMarkWordByBit(pB, pA, Size, BitMask, MarkValue, ClearValue);
01706 #else
01707 for (INT32 Pixel = 0; Pixel < Size; Pixel ++) pA[Pixel] = (pB[Pixel] & BitMask) ? MarkValue : ClearValue;
01708 #endif
01709
01710 return TRUE;
01711 }
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744 #define MLATestPixel(q) \
01745 { \
01746 OtherPixel = q; \
01747 while (pA[OtherPixel] < 0x80000000) OtherPixel = pA[OtherPixel]; \
01748 \
01749 \
01750 if ((pA[OtherPixel] != ClearValue) && (OtherPixel !=TopChain)) \
01751 { \
01752 \
01753 \
01754 if (TopChain<OtherPixel) {SwapTemp=TopChain;TopChain=OtherPixel;OtherPixel=SwapTemp;} \
01755 pA[OtherPixel]+=pA[TopChain]-0x80000000; \
01756 pA[TopChain]= OtherPixel; \
01757 TopChain=OtherPixel; \
01758 } \
01759 }
01760
01761 BOOL BfxALU::MarkRegions(DWORD MarkValue, DWORD ClearValue,
01762 BOOL * FoundRegion, INT32 * InitialX, INT32 * InitialY, INT32 * Area,
01763 INT32 * pSize, INT32 * pHighestChain, INT32 * pWidth, DWORD * * ppA)
01764
01765 {
01766 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
01767 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
01768 ERROR2IF(!FoundRegion,FALSE,"Found Region flag is compulsorary");
01769 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
01770
01771 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
01772
01773 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
01774
01775 DWORD * pA = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
01776
01777 INT32 Size = (pABMI->biSizeImage)>>2;
01778 INT32 Width = pABMI->biWidth;
01779 INT32 x=0;
01780 INT32 y=0;
01781 INT32 HighestChainVal = 0;
01782 INT32 HighestChain = -1;
01783
01784 #ifdef FASTMARKREGIONS
01785 FastMarkRegions(pA, Size, Width, MarkValue, ClearValue, &HighestChain, &HighestChainVal);
01786 #else
01787 INT32 Pixel;
01788 INT32 TopChain;
01789 INT32 OtherPixel;
01790 INT32 SwapTemp;
01791
01792 for (Pixel = 0; Pixel < Size; Pixel ++)
01793 {
01794
01795 if (pA[Pixel] != ClearValue)
01796 {
01797 pA[Pixel] = 0x80000001;
01798 TopChain = Pixel;
01799
01800 if (x!=0) MLATestPixel(Pixel-1);
01801 if (y!=0)
01802 {
01803 if (x!=Width-1) MLATestPixel(Pixel-Width+1);
01804 MLATestPixel(Pixel-Width);
01805 if (x!=0) MLATestPixel(Pixel-Width-1);
01806 }
01807 if (((INT32)(pA[TopChain]-0x80000000))>HighestChainVal)
01808 {
01809 HighestChainVal = (INT32)(pA[TopChain]-0x80000000);
01810 HighestChain = TopChain;
01811 }
01812 }
01813 if ((++x)==Width)
01814 {
01815 x=0;
01816 y++;
01817 }
01818 }
01819 #endif
01820
01821 if (InitialX) *InitialX = 0;
01822 if (InitialY) *InitialY = 0;
01823 if (Area) *Area = HighestChainVal;
01824 if ( (*FoundRegion = (HighestChain != -1) ) != FALSE )
01825 {
01826 if (InitialX) *InitialX = HighestChain % Width;
01827 if (InitialY) *InitialY = HighestChain / Width;
01828 }
01829 if (pSize) *pSize = Size;
01830 if (pHighestChain) *pHighestChain = HighestChain;
01831 if (ppA) *ppA=pA;
01832 if (pWidth) *pWidth=Width;
01833 return TRUE;
01834 }
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864 BOOL BfxALU::MarkLargestArea(DWORD MarkValue, DWORD ClearValue, DWORD RegionValue,
01865 BOOL * FoundRegion, INT32 * InitialX, INT32 * InitialY, INT32 * Area)
01866 {
01867 INT32 Size;
01868 INT32 HighestChain;
01869 DWORD * pA;
01870
01871 if (!MarkRegions(MarkValue, ClearValue, FoundRegion, InitialX, InitialY, Area,
01872 &Size, &HighestChain, NULL, &pA)) return FALSE;
01873
01874 if (!*FoundRegion) return TRUE;
01875
01876 #ifdef FASTMARKLARGESTAREA
01877 FastMarkLargestArea(pA, Size, MarkValue, ClearValue, RegionValue, HighestChain);
01878 #else
01879 INT32 OtherPixel;
01880 INT32 Pixel;
01881 for (Pixel = (Size-1); Pixel >= 0; Pixel--)
01882 {
01883 OtherPixel = Pixel;
01884 while (pA[OtherPixel] < 0x80000000) OtherPixel = pA[OtherPixel];
01885 if (OtherPixel==HighestChain)
01886 {
01887 pA[Pixel] = RegionValue;
01888 }
01889 else
01890 {
01891 if (pA[Pixel]!=ClearValue)
01892 #if 1
01893 pA[Pixel] = MarkValue;
01894 #else
01895 pA[Pixel] = 0x7F020202 | (_lrotl((OtherPixel ^ 0xabcdef13),(OtherPixel % 31)) % 0xFFFFFF);
01896 #endif
01897 }
01898 }
01899 #endif
01900 return TRUE;
01901 }
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932 BOOL BfxALU::MarkGivenArea(DWORD MarkValue, DWORD ClearValue, DWORD RegionValue,
01933 BOOL * FoundRegion, INT32 * InitialX, INT32 * InitialY, INT32 * Area)
01934 {
01935 INT32 Size;
01936 INT32 HighestChain;
01937 DWORD * pA;
01938 ERROR2IF((!InitialX)||(!InitialY),FALSE, "Why not pass in an InitialX & InitialY");
01939 INT32 ix = *InitialX;
01940 INT32 iy = *InitialY;
01941 INT32 Width;
01942
01943 if (!MarkRegions(MarkValue, ClearValue, FoundRegion, InitialX, InitialY, Area,
01944 &Size, &HighestChain, &Width, &pA)) return FALSE;
01945
01946 HighestChain=ix+Width*iy;
01947 while (pA[HighestChain] < 0x80000000) HighestChain = pA[HighestChain];
01948 if (pA[HighestChain] == ClearValue) HighestChain=-1;
01949
01950 if (InitialX) *InitialX = 0;
01951 if (InitialY) *InitialY = 0;
01952 if (Area) *Area = 0;
01953 if ( (*FoundRegion = (HighestChain != -1) ) != FALSE )
01954 {
01955 if (InitialX) *InitialX = HighestChain % Width;
01956 if (InitialY) *InitialY = HighestChain / Width;
01957 if (Area) *Area = pA[HighestChain] - 0x80000000;
01958 }
01959
01960 if (!*FoundRegion) return TRUE;
01961
01962 #ifdef FASTMARKLARGESTAREA
01963 FastMarkLargestArea(pA, Size, MarkValue, ClearValue, RegionValue, HighestChain);
01964 #else
01965 INT32 OtherPixel;
01966 INT32 Pixel;
01967 for (Pixel = (Size-1); Pixel >= 0; Pixel--)
01968 {
01969 OtherPixel = Pixel;
01970 while (pA[OtherPixel] < 0x80000000) OtherPixel = pA[OtherPixel];
01971 if (OtherPixel==HighestChain)
01972 {
01973 pA[Pixel] = RegionValue;
01974 }
01975 else
01976 {
01977 if (pA[Pixel]!=ClearValue)
01978 #if 1
01979 pA[Pixel] = MarkValue;
01980 #else
01981 pA[Pixel] = 0x7F020202 | (_lrotl((OtherPixel ^ 0xabcdef13),(OtherPixel % 31)) % 0xFFFFFF);
01982 #endif
01983 }
01984 }
01985 #endif
01986 return TRUE;
01987 }
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014 BOOL BfxALU::BuildErrorRegionList(DWORD MarkValue, DWORD ClearValue, DWORD RegionValue,
02015 BfxErrorRegionList * pERL, INT32 MinimumArea)
02016 {
02017 INT32 Pixel;
02018 INT32 Size;
02019 INT32 Width;
02020 DWORD * pA;
02021 BOOL FoundRegion=FALSE;
02022
02023 ERROR2IF(!pERL, FALSE, "OK, Where's the error region list then?");
02024
02025
02026 if (!pERL->Empty()) return FALSE;
02027
02028
02029
02030
02031 if (!MarkRegions(MarkValue, ClearValue, &FoundRegion, NULL, NULL, NULL,
02032 &Size, NULL, &Width, &pA)) return FALSE;
02033
02034 INT32 Area;
02035
02036 if (FoundRegion)
02037 {
02038 Pixel = 0;
02039 do
02040 {
02041
02042 #ifdef FASTBUILDERRORREGIONLIST
02043 FastBuildErrorRegionList(pA, Size, RegionValue, ClearValue, MinimumArea, &Pixel, &Area);
02044 #else
02045 do
02046 {
02047 if ((DWORD) (Area=(INT32)(pA[Pixel])) != ClearValue) pA[Pixel]=RegionValue;
02048
02049 } while ( (((DWORD)Area & 0xC0000000)!=0x80000000) && (Pixel++<Size));
02050 #endif
02051
02052 if (Pixel<Size)
02053 {
02054 if ((DWORD)(Area-0x80000000) >= (DWORD)MinimumArea)
02055 {
02056
02057 if (pERL->IsSpace()) pERL->Insert(Pixel % Width, Pixel / Width, Area-0x80000000);
02058 }
02059
02060 }
02061 } while (Pixel<Size);
02062
02063 }
02064 if (!pERL->IsSpace()) TRACEUSER( "Alex", _T("[[BuildErrorRegionList ran out of space]]\n"));
02065
02066 return (pERL->Sort() && pERL->ResetRead());
02067 }
02068
02070
02071 #if 0
02072 if (FoundRegion)
02073 {
02074 for (Pixel = (Size-1); Pixel >= 0; Pixel--)
02075 {
02076 if (((Area=pA[Pixel])<0xFF000000) && (Area>=0x80000000))
02077 {
02078 if ((INT32)(Area-0x80000000) > MinimumArea)
02079 {
02080
02081 if (pERL->IsSpace()) pERL->Insert(Pixel % Width, Pixel / Width, Area-0x80000000);
02082 }
02083 }
02084 if (((DWORD)Area) != ClearValue) pA[Pixel]=RegionValue;
02085 }
02086 }
02087 #endif
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112 BOOL BfxALU::ScanBit(DWORD BitMask, INT32 * X, INT32 * Y, INT32 *pPixel, BOOL * Found, BOOL CheckConnected)
02113 {
02114 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02115 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02116 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02117
02118 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02119
02120 ERROR2IF((pABMI->biBitCount !=32), FALSE,"Bad BfxALU A reg");
02121
02122 DWORD * pA = (DWORD *)(void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
02123
02124 INT32 Width = pABMI->biWidth;
02125 INT32 Size = (pABMI->biSizeImage)>>2;
02126
02127 INT32 Pixel = 0;
02128 BOOL Connected = TRUE;
02129 if (pPixel) Pixel=*pPixel; else if (X && Y) Pixel=(*X)+(*Y)*Width;
02130 INT32 tx;
02131 INT32 ty;
02132
02133 do
02134 {
02135 #ifdef FASTSCANBIT
02136 if (Pixel<Size) FastScanBit(pA, Size, BitMask, &Pixel);
02137 #else
02138 while (Pixel<Size && !(pA[Pixel] & BitMask)) Pixel++;
02139 #endif
02140 if (Pixel>=Size)
02141 {
02142 if (X) *X=0;
02143 if (Y) *Y=0;
02144 if (pPixel) *pPixel=0;
02145 if (Found) *Found=FALSE;
02146 return TRUE;
02147 }
02148 tx=Pixel % Width;
02149 ty=Pixel / Width;
02150 if (pPixel) *pPixel=Pixel;
02151 if (X) *X=tx;
02152 if (Y) *Y=ty;
02153 if (Found) *Found=TRUE;
02154
02155 Connected = !CheckConnected;
02156 if ((!Connected) && (tx!=Width-1)) Connected = ((pA[Pixel+1] & BitMask) !=0);
02157 if ((!Connected) && (Pixel+Width<Size)) Connected = ((pA[Pixel+Width] & BitMask) !=0);
02158 if ((!Connected) && (tx!=Width-1) && (Pixel+Width+1<Size)) Connected = ((pA[Pixel+Width+1] & BitMask) !=0);
02159 if ((!Connected) && (tx!=0) && (Pixel+Width-1<Size)) Connected = ((pA[Pixel+Width-1] & BitMask) !=0);
02160 if (!Connected) Pixel++;
02161
02162 } while (!Connected);
02163
02164
02165 return TRUE;
02166 }
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191 BOOL BfxALU::ScanThreshold(INT32 Value, INT32 * X, INT32 * Y, INT32 *pPixel, BOOL * Found, BOOL CheckConnected)
02192 {
02193 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02194 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02195 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02196 ERROR2IF( ((!T) || (T->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02197 ERROR3IF( (!(T->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02198
02199 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
02200 BITMAPINFOHEADER * pTBMI=&(((CWxBitmap *)(T->ActualBitmap))->BMInfo->bmiHeader);
02201
02202 ERROR2IF((pBBMI->biBitCount != pTBMI->biBitCount), FALSE,"Bad BfxALU B reg");
02203 ERROR2IF( (pTBMI->biSizeImage != pBBMI->biSizeImage), FALSE,
02204 "Incompatible bitmaps for ScanThreshold");
02205
02206 switch (pTBMI->biBitCount)
02207 {
02208 case 32:
02209 {
02210
02211 AluPix32 * pB = (AluPix32 *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
02212 AluPix32 * pT = (AluPix32 *)(void *)(((CWxBitmap *)(T->ActualBitmap))->BMBytes);
02213
02214 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
02215
02216 INT32 Width = pBBMI->biWidth;
02217 INT32 Size = (pBBMI->biSizeImage)>>2;
02218
02219 INT32 Pixel = 0;
02220 BOOL Connected = TRUE;
02221 if (pPixel) Pixel=*pPixel; else if (X && Y) Pixel=(*X)+(*Y)*Width;
02222 INT32 tx;
02223 INT32 ty;
02224 INT32 tp;
02225
02226 #define __scanthresh(p) (( IntegerSquare( ((INT32)(pB[p].R)) - ((INT32)(pT[p].R))) \
02227 + IntegerSquare( ((INT32)(pB[p].G)) - ((INT32)(pT[p].G))) \
02228 + IntegerSquare( ((INT32)(pB[p].B)) - ((INT32)(pT[p].B)))) >= Value )
02229
02230 do
02231 {
02232
02233 #ifdef FASTSCANTHRESHOLD
02234 if (Pixel<Size) FastScanThreshold((DWORD *)(void *)pB, (DWORD *)(void *)pT, Size, Value, &Pixel);
02235 #else
02236 while (Pixel<Size && !__scanthresh(Pixel)) Pixel++;
02237 #endif
02238
02239 if (Pixel>=Size)
02240 {
02241 if (X) *X=0;
02242 if (Y) *Y=0;
02243 if (pPixel) *pPixel=0;
02244 if (Found) *Found=FALSE;
02245 return TRUE;
02246 }
02247 tx=Pixel % Width;
02248 ty=Pixel / Width;
02249 if (pPixel) *pPixel=Pixel;
02250 if (X) *X=tx;
02251 if (Y) *Y=ty;
02252 if (Found) *Found=TRUE;
02253
02254 if ((Connected = !CheckConnected) != FALSE) return TRUE;
02255 if ((!Connected) && (tx!=Width-1)) {tp=Pixel+1;Connected = __scanthresh(tp);}
02256 if ((!Connected) && (Pixel+Width<Size)) {tp=Pixel+Width;Connected = __scanthresh(tp);}
02257 if ((!Connected) && (tx!=Width-1) && (Pixel+Width+1<Size)) {tp=Pixel+Width+1;Connected = __scanthresh(tp);}
02258 if ((!Connected) && (tx!=0) && (Pixel+Width-1<Size)) {tp=Pixel+Width-1;Connected = __scanthresh(tp);}
02259 if (!Connected) Pixel++;
02260
02261 } while (!Connected);
02262 return TRUE;
02263 }
02264
02265 case 8:
02266 {
02267
02268 BYTE * pB = (BYTE *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
02269 BYTE * pT = (BYTE *)(void *)(((CWxBitmap *)(T->ActualBitmap))->BMBytes);
02270
02271 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
02272
02273 INT32 Width = pBBMI->biWidth;
02274 INT32 Size = pBBMI->biSizeImage;
02275
02276 INT32 Pixel = 0;
02277 BOOL Connected = TRUE;
02278 INT32 WidthR = (Width+3) & ~3;
02279 if (pPixel) Pixel=*pPixel; else if (X && Y) Pixel=(*X)+(*Y)*WidthR;
02280 INT32 tx = Pixel % WidthR;
02281 INT32 ty = Pixel / WidthR;
02282 INT32 tp;
02283
02284 #define __scanthresh8(p) (pB[p]!=pT[p])
02285
02286 do
02287 {
02288
02289 #ifdef FASTSCANTHRESHOLD8
02290 if (Pixel<Size) FastScanThreshold8((DWORD *)(void *)pB, (DWORD *)(void *)pT, Size, Value, &Pixel,
02291 Width, WidthR, &tx, &ty);
02292 #else
02293 while (Pixel<Size && (tx>=Width || !__scanthresh8(Pixel)))
02294 {
02295 Pixel++;
02296 if ((++tx)>=WidthR)
02297 {
02298 ty++;
02299 tx=0;
02300 }
02301 }
02302 #endif
02303
02304 if (Pixel>=Size)
02305 {
02306 if (X) *X=0;
02307 if (Y) *Y=0;
02308 if (pPixel) *pPixel=0;
02309 if (Found) *Found=FALSE;
02310 return TRUE;
02311 }
02312 if (pPixel) *pPixel=Pixel;
02313 if (X) *X=tx;
02314 if (Y) *Y=ty;
02315 if (Found) *Found=TRUE;
02316
02317 if ((Connected = !CheckConnected) != FALSE) return TRUE;
02318 if ((!Connected) && (tx!=Width-1)) {tp=Pixel+1;Connected = __scanthresh8(tp);}
02319 if ((!Connected) && (Pixel+WidthR<Size)) {tp=Pixel+WidthR;Connected = __scanthresh8(tp);}
02320 if ((!Connected) && (tx!=Width-1) && (Pixel+WidthR+1<Size)) {tp=Pixel+WidthR+1;Connected = __scanthresh8(tp);}
02321 if ((!Connected) && (tx!=0) && (Pixel+WidthR-1<Size)) {tp=Pixel+WidthR-1;Connected = __scanthresh8(tp);}
02322 if (!Connected)
02323 {
02324 Pixel++;
02325 if ((++tx)>=WidthR)
02326 {
02327 ty++;
02328 tx=0;
02329 }
02330 }
02331 } while (!Connected);
02332 return TRUE;
02333 }
02334
02335 case 1:
02336 {
02337
02338 BYTE * pB = (BYTE *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
02339 BYTE * pT = (BYTE *)(void *)(((CWxBitmap *)(T->ActualBitmap))->BMBytes);
02340
02341 ERROR3IF((sizeof(DWORD) != sizeof(AluPix32)), "OK who's broken AluPix32 not to be 32 bits");
02342
02343 INT32 Width = pBBMI->biWidth;
02344 INT32 Size = pBBMI->biSizeImage<<3;
02345
02346 INT32 Pixel = 0;
02347 BOOL Connected = TRUE;
02348 INT32 WidthR = (Width+31) & ~31;
02349 if (pPixel) Pixel=*pPixel; else if (X && Y) Pixel=(*X)+(*Y)*WidthR;
02350 INT32 tx = Pixel % WidthR;
02351 INT32 ty = Pixel / WidthR;
02352 INT32 tp;
02353
02354 #define __scanthresh1(p) (((pB[p>>3]^pT[p>>3]) & (0x80>>(p&7))) !=0)
02355
02356 do
02357 {
02358
02359 #ifdef FASTSCANTHRESHOLD1
02360 if (Pixel<Size) FastScanThreshold1((DWORD *)(void *)pB, (DWORD *)(void *)pT, Size, Value, &Pixel);
02361 #else
02362 while (Pixel<Size && (tx>=Width || !__scanthresh1(Pixel)))
02363 {
02364 Pixel++;
02365 if ((++tx)>=WidthR)
02366 {
02367 ty++;
02368 tx=0;
02369 }
02370 }
02371 #endif
02372
02373 if (Pixel>=Size)
02374 {
02375 if (X) *X=0;
02376 if (Y) *Y=0;
02377 if (pPixel) *pPixel=0;
02378 if (Found) *Found=FALSE;
02379 return TRUE;
02380 }
02381 if (pPixel) *pPixel=Pixel;
02382 if (X) *X=tx;
02383 if (Y) *Y=ty;
02384 if (Found) *Found=TRUE;
02385
02386 if ((Connected = !CheckConnected) != FALSE) return TRUE;
02387 if ((!Connected) && (tx!=Width-1)) {tp=Pixel+1;Connected = __scanthresh1(tp);}
02388 if ((!Connected) && (Pixel+WidthR<Size)) {tp=Pixel+WidthR;Connected = __scanthresh1(tp);}
02389 if ((!Connected) && (tx!=Width-1) && (Pixel+WidthR+1<Size)) {tp=Pixel+WidthR+1;Connected = __scanthresh1(tp);}
02390 if ((!Connected) && (tx!=0) && (Pixel+WidthR-1<Size)) {tp=Pixel+WidthR-1;Connected = __scanthresh1(tp);}
02391 if (!Connected)
02392 {
02393 Pixel++;
02394 if ((++tx)>=WidthR)
02395 {
02396 ty++;
02397 tx=0;
02398 }
02399 }
02400 } while (!Connected);
02401 return TRUE;
02402 }
02403
02404 default: break;
02405 }
02406 ERROR2(FALSE, "BfxALU::ScanThreshold doesn't understand that BPP");
02407 return TRUE;
02408 }
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441 BOOL BfxALU::GradFillPath(Path * ThePath, DWORD StartColour, DWORD EndColour,
02442 INT32 StartX, INT32 StartY, INT32 EndX, INT32 EndY, BOOL AntiAlias, BOOL ColoursAreDWORDs)
02443 {
02444 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02445 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)),FALSE,"BfxALU can't find OIL bitmap");
02446 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02447 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02448
02449 DWORD Style=0;
02450 GraduationTable Table;
02451 Table.Length = 0x100;
02452
02453 if (StartColour != EndColour)
02454 {
02455 ERROR2IF(ColoursAreDWORDs, FALSE, "Grad fill DWORD colours not yet supported");
02456
02457 ERROR2IF((!GC->BuildGraduationTable( (COLORREF) StartColour, (COLORREF) EndColour, FALSE, &Table)), FALSE,
02458 "GDraw couldn't build grad fill table for BfxALU");
02459
02460
02461 POINT A,B,C;
02462
02463 A.x = StartX; A.y = StartY;
02464 C.x = EndX; C.y = EndY;
02465 B.x = A.x + (C.y-A.y);
02466 B.y = A.y - (C.x-A.x);
02467
02468 ERROR2IF((!GC->SetGraduation( Style, &Table, &A, &B, &C )), FALSE, "GDraw couldn't set BfxALU graduation");
02469 }
02470 else
02471 {
02472 if (ColoursAreDWORDs)
02473 {
02474 DWORD DupColour=StartColour;
02475 switch(pBMI->biBitCount)
02476 {
02477 case 32: DupColour=StartColour; break;
02478 case 16: DupColour=(StartColour & 0xFFFF); DupColour|=DupColour<<16; break;
02479 case 8: DupColour=(StartColour & 0xFF); DupColour|=DupColour<<8; DupColour|=DupColour<<16; break;
02480 case 4: DupColour=(StartColour & 0xF); DupColour|=DupColour<<4; DupColour|=DupColour<<8;
02481 DupColour|=DupColour<<16; break;
02482 case 2: DupColour=(StartColour & 0x3); DupColour|=DupColour<<2; DupColour|=DupColour<<4;
02483 DupColour|=DupColour<<8; DupColour|=DupColour<<16; break;
02484 case 1: DupColour=(StartColour & 0x1); DupColour|=DupColour<<1; DupColour|=DupColour<<2;
02485 DupColour|=DupColour<<4; DupColour|=DupColour<<8;
02486 DupColour|=DupColour<<16; break;
02487 default:
02488 {
02489 ERROR2(FALSE, "Corrupt biBitCount in BfxALU::GradFillPath");
02490 break;
02491 }
02492 }
02493
02494 ERROR2IF((!GC->SetWordColour(DupColour )), FALSE, "GDraw couldn't set BfxALU word colour");
02495 }
02496 else
02497 {
02498 ERROR2IF((!GC->SetColour( (COLORREF) StartColour )), FALSE, "GDraw couldn't set BfxALU colour");
02499 }
02500 }
02501
02502 GMATRIX pathmatrix;
02503 pathmatrix.AX=pathmatrix.BY=1<<(FX+8);pathmatrix.CX=pathmatrix.CY=pathmatrix.AY=pathmatrix.BX=0;
02504 ERROR2IF((!GC->SetMatrix(&pathmatrix)), FALSE, "GDraw couldn't set path matrix");
02505 GC->SetAntialiasFlag(AntiAlias);
02506 GC->SetFlatness(AntiAlias?32:128);
02507
02508 BOOL Success;
02509 if (ThePath)
02510 {
02511 Success = GC->FillPath( (POINT*)ThePath->GetCoordArray(), ThePath->GetVerbArray(), ThePath->GetNumCoords(), 0);
02512 }
02513 else
02514 {
02515 RECT Rect={0,(pBMI->biHeight)<<8,(pBMI->biWidth)<<8,0};
02516 Success = GC->FillRectangle(&Rect);
02517 }
02518
02519 GC->SetAntialiasFlag(FALSE);
02520 ERROR2IF(!(GC->SetMatrix(&identity)), FALSE, "GDraw couldn't restore BfxALU Matrix");
02521 ERROR2IF((!Success), FALSE, "GDraw couldn't fill BfxALU path");
02522
02523 return(TRUE);
02524 }
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546 BOOL BfxALU::GetStatistics(Path * ThePath, KernelStatistics * pStats)
02547 {
02548 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02549 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)),FALSE,"BfxALU can't find OIL bitmap");
02550 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02551 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02552
02553 GMATRIX pathmatrix;
02554 pathmatrix.AX=pathmatrix.BY=1<<(FX+8);pathmatrix.CX=pathmatrix.CY=pathmatrix.AY=pathmatrix.BX=0;
02555 ERROR2IF((!GC->SetMatrix(&pathmatrix)), FALSE, "GDraw couldn't set path matrix");
02556 GC->SetFlatness(128);
02557 STATISTICS Stats;
02558 BOOL Success = GC->GetStatistics( (POINT*)ThePath->GetCoordArray(), ThePath->GetVerbArray(), ThePath->GetNumCoords(),
02559 0, &Stats);
02560 ERROR2IF((!GC->SetMatrix(&identity)), FALSE, "GDraw couldn't restore BfxALU Matrix");
02561 ERROR2IF((!Success), FALSE, "GDraw couldn't fill BfxALU path");
02562
02563 pStats->N = Stats.N;
02564 double N = (double) Stats.N;
02565 if (N==0) N=1;
02566 #if 1
02567 pStats->R = ((Stats.R )*1.0)/(N*255.0);
02568 pStats->R2= ((Stats.R2)*1.0)/(N*255.0*255.0);
02569 pStats->RX= ((Stats.RX)*1.0)/(N*255.0);
02570 pStats->RY= ((Stats.RY)*1.0)/(N*255.0);
02571 pStats->G = ((Stats.G )*1.0)/(N*255.0);
02572 pStats->G2= ((Stats.G2)*1.0)/(N*255.0*255.0);
02573 pStats->GX= ((Stats.GX)*1.0)/(N*255.0);
02574 pStats->GY= ((Stats.GY)*1.0)/(N*255.0);
02575 pStats->B = ((Stats.B )*1.0)/(N*255.0);
02576 pStats->B2= ((Stats.B2)*1.0)/(N*255.0*255.0);
02577 pStats->BX= ((Stats.BX)*1.0)/(N*255.0);
02578 pStats->BY= ((Stats.BY)*1.0)/(N*255.0);
02579 pStats->X = ((Stats.X )*1.0)/(N*255.0);
02580 pStats->Y = ((Stats.Y )*1.0)/(N*255.0);
02581 pStats->X2= ((Stats.X2)*1.0)/(N*255.0);
02582 pStats->Y2= ((Stats.Y2)*1.0)/(N*255.0);
02583 pStats->XY= ((Stats.XY)*1.0)/(N*255.0);
02584
02585 #else
02586 pStats->R = ((Stats.R ).MakeDouble())/(N*255.0);
02587 pStats->R2= ((Stats.R2).MakeDouble())/(N*255.0*255.0);
02588 pStats->RX= ((Stats.RX).MakeDouble())/(N*255.0);
02589 pStats->RY= ((Stats.RY).MakeDouble())/(N*255.0);
02590 pStats->G = ((Stats.G ).MakeDouble())/(N*255.0);
02591 pStats->G2= ((Stats.G2).MakeDouble())/(N*255.0*255.0);
02592 pStats->GX= ((Stats.GX).MakeDouble())/(N*255.0);
02593 pStats->GY= ((Stats.GY).MakeDouble())/(N*255.0);
02594 pStats->B = ((Stats.B ).MakeDouble())/(N*255.0);
02595 pStats->B2= ((Stats.B2).MakeDouble())/(N*255.0*255.0);
02596 pStats->BX= ((Stats.BX).MakeDouble())/(N*255.0);
02597 pStats->BY= ((Stats.BY).MakeDouble())/(N*255.0);
02598 pStats->X = ((Stats.X ).MakeDouble())/(N*255.0);
02599 pStats->Y = ((Stats.Y ).MakeDouble())/(N*255.0);
02600 pStats->X2= ((Stats.X2).MakeDouble())/(N*255.0);
02601 pStats->Y2= ((Stats.Y2).MakeDouble())/(N*255.0);
02602 pStats->XY= ((Stats.XY).MakeDouble())/(N*255.0);
02603 #endif
02604
02605 INT32 Width = pBMI->biWidth;
02606
02607 pStats->LowX = -1;
02608 pStats->LowY = -1;
02609 pStats->Pixel = (DWORD)(-1);
02610
02611 if (Stats.C>0)
02612 {
02613 UINT32 Offset = ((UINT_PTR)(Stats.C))-((UINT_PTR)((((CWxBitmap *)(A->ActualBitmap))->BMBytes)));
02614 if (Offset<(UINT32)pBMI->biSizeImage)
02615 {
02616 pStats->LowX = (Offset>>2) % Width;
02617 pStats->LowY = (Offset>>2) / Width;
02618 DWORD pval = *((DWORD *)(Stats.C));
02619 pStats->Pixel = (pval & 0x00FF00) | ((pval >> 16) & 0xFF) | ((pval << 16) & 0xFF0000);
02620 }
02621 }
02622
02623 return(TRUE);
02624 }
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649 BOOL BfxALU::GetSize(KernelBitmap * pBitmap, INT32 * pXSize, INT32 * pYSize, INT32 * pDepth)
02650 {
02651 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02652 ERROR2IF( ((!pBitmap) || (pBitmap->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02653 ERROR3IF( (!(pBitmap->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02654
02655 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
02656
02657 if (pXSize) *pXSize=(INT32)(pABMI->biWidth);
02658 if (pYSize) *pYSize=(INT32)(pABMI->biHeight);
02659 if (pDepth) *pDepth=(INT32)(pABMI->biBitCount);
02660
02661 return TRUE;
02662 }
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683 BOOL BfxALU::ByteCopyBA()
02684 {
02685 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02686 ERROR2IF( ((!A) || (A->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02687 ERROR3IF( (!(A->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02688 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02689 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02690
02691 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02692 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(A->ActualBitmap))->BMInfo->bmiHeader);
02693
02694 ERROR2IF((pABMI->biBitCount != pBBMI->biBitCount), FALSE,"Bad BfxALU A/B reg");
02695 ERROR2IF( (pABMI->biSizeImage != pBBMI->biSizeImage), FALSE,
02696 "Incompatible bitmaps for ByteCopyBA()");
02697
02698 void * pA = (void *)(((CWxBitmap *)(A->ActualBitmap))->BMBytes);
02699 void * pB = (void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
02700
02701 memcpy(pA, pB, pABMI->biSizeImage);
02702
02703 return TRUE;
02704 }
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723 BfxErrorRegionList::BfxErrorRegionList()
02724 {
02725 pList = NULL;
02726 ListLength = 0;
02727 Used = 0;
02728 CurrentRead = 0;
02729 CurrentWrite = 0;
02730 Sorted = FALSE;
02731 }
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750 BfxErrorRegionList::~BfxErrorRegionList()
02751 {
02752 if (pList) CCFree(pList);
02753 }
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772 BOOL BfxErrorRegionList::Init(UINT32 Length)
02773 {
02774 if (pList) CCFree(pList);
02775 pList = NULL;
02776 ListLength = 0;
02777 Used = 0;
02778 CurrentRead = 0;
02779 CurrentWrite = 0;
02780 Sorted = FALSE;
02781
02782 if (!Length) return TRUE;
02783
02784 if ((pList = (BfxErrorRegionListItem *)CCMalloc(sizeof(BfxErrorRegionListItem) * (Length+1))) == NULL)
02785 return FALSE;
02786
02787 ListLength = Length;
02788
02789 return (Empty() && ResetRead());
02790 }
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809 BOOL BfxErrorRegionList::Empty()
02810 {
02811 ERROR2IF (!pList, FALSE, "No BfxErrorRegionList");
02812 CurrentRead = 0;
02813 CurrentWrite = 0;
02814 Sorted = FALSE;
02815
02816 pList[CurrentWrite].X=pList[CurrentWrite].Y=pList[CurrentWrite].Area = 0;
02817
02818 return TRUE;
02819 }
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836 BOOL BfxErrorRegionList::ResetRead()
02837 {
02838 CurrentRead = 0;
02839 return TRUE;
02840 }
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859 BOOL BfxErrorRegionList::Insert(INT32 XCoord, INT32 YCoord, INT32 Area)
02860 {
02861 ERROR2IF (!pList, FALSE, "No BfxErrorRegionList");
02862 ERROR2IF (!IsSpace(), FALSE, "It's full! Why not use IsSpace() first like a good programmer?");
02863 ERROR2IF (!Area, FALSE, "BfxErrorRegionLists cannot hold zero area regions coz they aren't really regions, are they?");
02864
02865 pList[CurrentWrite].X=XCoord;
02866 pList[CurrentWrite].Y=YCoord;
02867 pList[CurrentWrite++].Area=Area;
02868 pList[CurrentWrite].Area=0;
02869 pList[CurrentWrite].X=0;
02870 pList[CurrentWrite].Y=0;
02871
02872 return TRUE;
02873 }
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893 BOOL BfxErrorRegionList::Sort()
02894 {
02895 ERROR2IF (!pList, FALSE, "No BfxErrorRegionList");
02896 Sorted = FALSE;
02897
02898
02899 if ((pList[0].Area == 0) || (pList[1].Area ==0))
02900 {
02901 Sorted = TRUE;
02902 return TRUE;
02903 }
02904
02905 while (!Sorted)
02906 {
02907 INT32 Current = 0;
02908 Sorted = TRUE;
02909 while (pList[++Current].Area !=0) if (pList[Current].Area > pList[Current-1].Area)
02910 {
02911 Sorted=FALSE;
02912 Swap(&pList[Current], &pList[Current-1]);
02913 }
02914 }
02915 return TRUE;
02916 }
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937 PORTNOTE("other", "Disabled Accusoft filters")
02938 #ifndef EXCLUDE_FROM_XARALX
02939 #ifndef WEBSTER
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960 BOOL BfxALU::MakeAccusoftHandle(INT32 * pHandle, BOOL DoBodge)
02961 {
02962 ERROR1IF((!(AccusoftFilters::pfnIMG_create_handle_keep)), FALSE, _R(IDN_FILTERNOTPRESENT));
02963 ERROR2IF((!pHandle ),FALSE, "BfxALU handle parameter must be non-null");
02964
02965 ERROR2IF((GC==NULL),FALSE,"BfxALU::Init not called / failed");
02966 ERROR2IF( ((!B) || (B->ActualBitmap==NULL)) ,FALSE,"BfxALU can't find OIL bitmap");
02967 ERROR3IF( (!(B->ActualBitmap->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap)) )),"BfxALU Oil layer inconsistency");
02968
02969 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
02970
02971 DWORD PaletteUsed = pBBMI->biClrUsed;
02972
02973 ERROR2IF ((pBBMI->biSizeImage == 0) || (pBBMI->biCompression != BI_RGB) || (pBBMI->biHeight<0), FALSE,
02974 "A naughty DIB format has been used internally");
02975
02976
02977 if (pBBMI->biBitCount > 8)
02978 {
02979 PaletteUsed = 0;
02980 }
02981 else
02982 {
02983
02984
02985
02986 ERROR3IF(pBBMI->biBitCount==0,"There`s no depth to this picture! Cannot set Palette Used!");
02987 switch(pBBMI->biBitCount)
02988 {
02989 case 1:
02990 PaletteUsed = 2;
02991 break;
02992 case 2:
02993 PaletteUsed = 4;
02994 break;
02995 case 4:
02996 PaletteUsed = 16;
02997 break;
02998 case 8:
02999 PaletteUsed = 256;
03000 break;
03001 default:
03002 break;
03003 }
03004 }
03005
03006 INT32 SizeImage = pBBMI->biSizeImage;
03007 INT32 Depth = 0;
03008 if (pBBMI->biBitCount == 32)
03009 Depth = 24;
03010 else
03011 Depth = pBBMI->biBitCount;
03012 #ifdef BODGE_ACCUSOFT_RESIZE
03013 if (DoBodge)
03014 {
03015
03016 if (pBBMI->biBitCount == 32)
03017 SizeImage = DIBUtil::ScanlineSize(3 * pBBMI->biWidth, 24) * pBBMI->biHeight;
03018 else
03019 SizeImage = DIBUtil::ScanlineSize(3 * pBBMI->biWidth, Depth) * pBBMI->biHeight;
03020 }
03021 else if (pBBMI->biBitCount == 32)
03022 {
03023 UINT32 ScanLineSize = DIBUtil::ScanlineSize(pBBMI->biWidth, 24);
03024 SizeImage = ScanLineSize * pBBMI->biHeight;
03025 }
03026 #else
03027 if (pBBMI->biBitCount == 32)
03028 {
03029 UINT32 ScanLineSize = DIBUtil::ScanlineSize(pBBMI->biWidth, 24);
03030 SizeImage = ScanLineSize * pBBMI->biHeight;
03031 }
03032 #endif
03033
03034 HGLOBAL HMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(BITMAPINFOHEADER) + (sizeof(DWORD)*PaletteUsed) + SizeImage);
03035 ERROR1IF(!HMem, FALSE, _R(IDS_OUT_OF_MEMORY));
03036 LPBYTE Mem = (LPBYTE) (void *) GlobalLock(HMem);
03037 ERROR1IF(!Mem, FALSE, _R(IDS_OUT_OF_MEMORY));
03038
03039 BITMAPINFOHEADER * pCBMI = (BITMAPINFOHEADER *) Mem;
03040 LPBYTE pPal = Mem + sizeof(BITMAPINFOHEADER);
03041 LPBYTE pBits = pPal + (sizeof(DWORD)*PaletteUsed);
03042
03043 pCBMI->biSize = pBBMI->biSize;
03044 if (DoBodge)
03045 pCBMI->biWidth = pBBMI->biWidth * 3;
03046 else
03047 pCBMI->biWidth = pBBMI->biWidth;
03048 pCBMI->biHeight = pBBMI->biHeight;
03049 pCBMI->biPlanes = 1;
03050 pCBMI->biBitCount = (pBBMI->biBitCount != 32) ? (pBBMI->biBitCount) : 24;
03051 pCBMI->biCompression = BI_RGB;
03052 pCBMI->biSizeImage = SizeImage;
03053 pCBMI->biXPelsPerMeter = pBBMI->biXPelsPerMeter;
03054 pCBMI->biYPelsPerMeter = pBBMI->biYPelsPerMeter;
03055 if (PaletteUsed)
03056 {
03057 pCBMI->biClrUsed = PaletteUsed;
03058 pCBMI->biClrImportant = PaletteUsed;
03059 }
03060 else
03061 {
03062 pCBMI->biClrUsed = 0;
03063 pCBMI->biClrImportant = 0;
03064 }
03065
03066
03067 if (PaletteUsed) memcpy(pPal , ((LPBYTE)(pBBMI)) + sizeof(BITMAPINFOHEADER), sizeof(DWORD) * PaletteUsed);
03068
03069 #ifdef BODGE_ACCUSOFT_RESIZE
03070
03071 if (DoBodge)
03072 {
03073 LPBYTE pSourceBits = ((CWxBitmap *)(B->ActualBitmap))->BMBytes;
03074 if (!MAH_BodgeCopyBitmap(pBBMI->biWidth, pBBMI->biHeight, pBBMI->biBitCount, pSourceBits, pBits))
03075 {
03076 GlobalUnlock(HMem);
03077 GlobalFree(HMem);
03078 return FALSE;
03079 }
03080 }
03081 else
03082 #endif
03083 {
03084 if (pBBMI->biBitCount != 32)
03085 {
03086 memcpy(pBits , ((CWxBitmap *)(B->ActualBitmap))->BMBytes, pBBMI->biSizeImage);
03087 }
03088 else
03089 {
03090 GC->ConvertBitmap(pBBMI, ((CWxBitmap *)(B->ActualBitmap))->BMBytes, pCBMI, pBits, 8);
03091 }
03092 }
03093
03094 if (pBBMI->biBitCount==1) FixMono(pBits, pBBMI->biSizeImage);
03095
03096 INT32 result = AccusoftFilters::pfnIMG_create_handle_keep(pCBMI);
03097 if (result < 0)
03098 {
03099 GlobalUnlock(HMem);
03100 GlobalFree(HMem);
03101 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03102 }
03103 *pHandle = result;
03104
03105 return TRUE;
03106 }
03107
03108
03109
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131 BOOL BfxALU::MAH_BodgeCopyBitmap(INT32 Width, INT32 Height, INT32 Depth, LPBYTE pSourceBits, LPBYTE pDestBits)
03132 {
03133 #ifdef BODGE_ACCUSOFT_RESIZE
03134 UINT32 SourceScanline = DIBUtil::ScanlineSize(Width, Depth);
03135 UINT32 DestScanline = 1;
03136 if (Depth == 32)
03137 DestScanline = DIBUtil::ScanlineSize(Width * 3, 24);
03138 else
03139 DestScanline = DIBUtil::ScanlineSize(Width * 3, Depth);
03140
03141
03142
03143
03144
03145 INT32 Bytes = 1;
03146 switch (Depth)
03147 {
03148 case 4:
03149 {
03150
03151
03152
03153
03154
03155 Bytes = Width;
03156 for (INT32 i = 0; i < Height; i++ )
03157 {
03158
03159 BYTE * pDBits = pDestBits;
03160
03161 BYTE LeftHandByte = ((*pSourceBits) & 0xF0) >> 4;
03162 for (INT32 j = 0; j < Width; j++ )
03163 {
03164 LPBYTE pData = pDBits + j/2;
03165 if (j & 1)
03166 *(pData) = ((*(pData)) & 0xF0) | (LeftHandByte & 0x0F);
03167 else
03168 *(pData) = ((*(pData)) & 0x0F) | ((LeftHandByte << 4) & 0xF0);
03169 }
03170
03171 BYTE Byte = 0;
03172 INT32 k = 0;
03173 for (; j < (2 * Width); j++ )
03174 {
03175
03176 LPBYTE pSourceData = pSourceBits + k/2;
03177 if (k & 1)
03178 Byte = ((*(pSourceData)) & 0x0F);
03179 else
03180 Byte = ((*(pSourceData)) & 0xF0) >> 4;
03181
03182
03183 LPBYTE pData = pDBits + j/2;
03184 if (j & 1)
03185 *(pData) = ((*(pData)) & 0xF0) | (Byte & 0x0F);
03186 else
03187 *(pData) = ((*(pData)) & 0x0F) | ((Byte << 4) & 0xF0);
03188
03189 k ++;
03190 }
03191
03192
03193 LPBYTE pData = pDBits + Width/2;
03194 BYTE RightHandByte = 0;
03195 if (Width & 1)
03196 RightHandByte = ((*(pData)) & 0x0F);
03197 else
03198 RightHandByte = ((*(pData)) & 0xF0) >> 4;
03199
03200 for (; j < (3 * Width); j++ )
03201 {
03202
03203 LPBYTE pData = pDBits + j/2;
03204 if (j & 1)
03205 {
03206 *(pData) = ((*(pData)) & 0xF0) | (RightHandByte & 0x0F);
03207 }
03208 else
03209 *(pData) = ((*(pData)) & 0x0F) | ((RightHandByte << 4) & 0xF0);
03210 }
03211
03212 pDestBits += DestScanline;
03213 pSourceBits += SourceScanline;
03214 }
03215
03216 break;
03217 }
03218 case 8:
03219 {
03220
03221 Bytes = Width;
03222 for (INT32 i = 0; i < Height; i++ )
03223 {
03224 BYTE * pDBits = pDestBits;
03225
03226 BYTE LeftHandByte = *pSourceBits;
03227 memset(pDBits, LeftHandByte, Bytes );
03228 pDBits += Bytes;
03229
03230 memcpy(pDBits , pSourceBits, Bytes);
03231 pDBits += Bytes;
03232
03233 BYTE RightHandByte = *(pSourceBits + Bytes - 1);
03234 memset(pDBits, RightHandByte, Bytes );
03235
03236 pDestBits += DestScanline;
03237 pSourceBits += SourceScanline;
03238 }
03239
03240 break;
03241 }
03242 case 32:
03243 case 24:
03244 {
03245
03246 Bytes = 3 * Width;
03247 BYTE LeftHandByte_R = 0;
03248 BYTE RightHandByte_R = 0;
03249 BYTE LeftHandByte_G = 0;
03250 BYTE RightHandByte_G = 0;
03251 BYTE LeftHandByte_B = 0;
03252 BYTE RightHandByte_B = 0;
03253 for (INT32 i = 0; i < Height; i++ )
03254 {
03255 BYTE * pDBits = pDestBits;
03256
03257 LeftHandByte_R = *pSourceBits;
03258 LeftHandByte_G = *(pSourceBits + 1);
03259 LeftHandByte_B = *(pSourceBits + 2);
03260 for (INT32 j = 0; j < Width; j++ )
03261 {
03262 *pDBits = LeftHandByte_R;
03263 pDBits ++;
03264 *pDBits = LeftHandByte_G;
03265 pDBits ++;
03266 *pDBits = LeftHandByte_B;
03267 pDBits ++;
03268 }
03269
03270
03271 if (Depth != 32)
03272 {
03273 memcpy(pDBits , pSourceBits, Bytes);
03274 pDBits += Bytes;
03275 }
03276 else
03277 {
03278 LPBYTE pSBits = pSourceBits;
03279 for (INT32 j = 0; j < Width; j++ )
03280 {
03281 *(pDBits) = *(pSBits);
03282 *(pDBits + 1) = *(pSBits + 1);
03283 *(pDBits + 2) = *(pSBits + 2);
03284 pDBits += 3;
03285 pSBits += 4;
03286 }
03287 }
03288
03289
03290 if (Depth != 32)
03291 {
03292 RightHandByte_R = *(pSourceBits + Bytes - 3);
03293 RightHandByte_G = *(pSourceBits + Bytes - 2);
03294 RightHandByte_B = *(pSourceBits + Bytes - 1);
03295 }
03296 else
03297 {
03298 RightHandByte_R = *(pSourceBits + Bytes - 4);
03299 RightHandByte_G = *(pSourceBits + Bytes - 3);
03300 RightHandByte_B = *(pSourceBits + Bytes - 2);
03301 }
03302
03303 for (j = 0; j < Width; j++ )
03304 {
03305 *pDBits = RightHandByte_R;
03306 pDBits ++;
03307 *pDBits = RightHandByte_G;
03308 pDBits ++;
03309 *pDBits = RightHandByte_B;
03310 pDBits ++;
03311 }
03312
03313 pDestBits += DestScanline;
03314 pSourceBits += SourceScanline;
03315 }
03316
03317 break;
03318 }
03319 default:
03320 ERROR2(FALSE,"Bad colour depth when bodge copying");
03321 }
03322
03323 #endif
03324 return TRUE;
03325 }
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350 BOOL BfxALU::MKB_BodgeCopyBitmap(INT32 Width, INT32 Height, INT32 Depth, LPBYTE pSourceBits, LPBYTE pDestBits)
03351 {
03352 #ifdef BODGE_ACCUSOFT_RESIZE
03353
03354
03355 UINT32 SourceScanline = DIBUtil::ScanlineSize(Width * 3, Depth);
03356 UINT32 DestScanline = DIBUtil::ScanlineSize(Width, Depth);
03357
03358
03359 INT32 Bytes = 1;
03360 switch (Depth)
03361 {
03362
03363
03364
03365
03366
03367
03368
03369
03370
03371
03372
03373
03374
03375
03376 case 24:
03377 {
03378
03379 Bytes = 3 * Width;
03380
03381
03382 for (INT32 i = 0; i < Height; i++ )
03383 {
03384 memcpy(pDestBits , pSourceBits + Bytes, DestScanline);
03385 pDestBits += DestScanline;
03386 pSourceBits += SourceScanline;
03387 }
03388 break;
03389 }
03390 default:
03391 ERROR2(FALSE,"Bad colour depth when bodge copying");
03392 }
03393
03394 #endif
03395 return TRUE;
03396 }
03397
03398
03399
03400
03401
03402
03403
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419
03420 BOOL BfxALU::MakeKernelBitmap(INT32 Handle, KernelBitmap * * ppOutput, BOOL Make32Bits,
03421 String_256 * pName, UINT32 ResID, BOOL DoBodge)
03422 {
03423 ERROR3IF((!ppOutput ), "BfxALU output parameter must be non-null");
03424 INT32 width = 0;
03425 INT32 height = 0;
03426 INT32 bpp = 0;
03427
03428 HANDLE MHandle = AccusoftFilters::pfnIMG_bitmap_info(Handle, &width, &height, &bpp);
03429 if (Make32Bits && bpp != 24)
03430 {
03431 INT32 result = AccusoftFilters::pfnIMG_delete_bitmap(Handle);
03432 ERROR2(FALSE, "Can't make a non-24 bit image into a 32 bit one guv");
03433 }
03434
03435 ERROR2IF(width ==0 || height == 0 || (bpp != 1 && bpp != 4 && bpp != 8 && bpp !=24 && bpp != 32),
03436 FALSE,"Bad bitmap height, width or colour depth in MakeKernelBitmap");
03437
03438 #ifdef BODGE_ACCUSOFT_RESIZE
03439
03440
03441 if (DoBodge)
03442 {
03443 width /= 3;
03444 }
03445 #endif
03446
03447 BITMAPINFOHEADER * pBBMI = (LPBITMAPINFOHEADER) GlobalLock(MHandle);
03448 KernelBitmap * pKB = NewBitmap(NULL, width, height, Make32Bits ? 32 : bpp, pName, ResID);
03449 if (!pKB)
03450 {
03451 GlobalUnlock(MHandle);
03452 INT32 result = AccusoftFilters::pfnIMG_delete_bitmap(Handle);
03453 return FALSE;
03454 }
03455
03456 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiHeader);
03457
03458 if (
03459
03460 ((Make32Bits ? 24 : pABMI->biBitCount) != pBBMI->biBitCount) ||
03461 ((!Make32Bits && !DoBodge) && pABMI->biSizeImage != pBBMI->biSizeImage)
03462 )
03463 {
03464 GlobalUnlock(MHandle);
03465 delete pKB;
03466 INT32 result = AccusoftFilters::pfnIMG_delete_bitmap(Handle);
03467 ERROR2(FALSE,"Accusoft DLL lied about bpp / size");
03468 }
03469
03470
03471 if (bpp > 8)
03472 {
03473 pBBMI->biClrUsed = 0;
03474 pBBMI->biClrImportant = 0;
03475 }
03476 else
03477 {
03478 UINT32 UsedColours = 1 << bpp;
03479 #ifdef ACCUSOFT_HAS_BROKEN_NON_FULL_PALETTES
03480
03481 pBBMI->biClrUsed=pBBMI->biClrImportant=UsedColours;
03482 #endif
03483 if (pBBMI->biClrUsed == 0) pBBMI->biClrUsed = UsedColours;
03484 if (pBBMI->biClrImportant == 0) pBBMI->biClrImportant = UsedColours;
03485 if (UsedColours < pBBMI->biClrUsed)
03486 {
03487 TRACEUSER( "Alex", _T("These Accusoft boys really know what they're doing with Palettes - NOT\n"));
03488 pBBMI->biClrUsed = UsedColours;
03489 pBBMI->biClrImportant = UsedColours;
03490 }
03491 }
03492
03493
03494 void * pA = (void *)(((CWxBitmap *)(pKB->ActualBitmap))->BMBytes);
03495 void * pB = (void *)(((char *)(void *)(pBBMI)) + sizeof (BITMAPINFOHEADER) + (pBBMI->biClrUsed * sizeof (DWORD)) );
03496
03497
03498 if (pBBMI->biClrUsed > pABMI->biClrUsed)
03499 {
03500 pBBMI->biClrUsed = pABMI->biClrUsed;
03501 TRACEUSER( "Alex", _T("We've lost some palette information\n"));
03502 }
03503 if (pBBMI->biClrUsed < pBBMI->biClrImportant) pBBMI->biClrImportant = pBBMI->biClrUsed;
03504
03505 if (!Make32Bits)
03506 {
03507 #ifdef BODGE_ACCUSOFT_RESIZE
03508 if (DoBodge)
03509 {
03510
03511 if (pBBMI->biClrUsed > 0)
03512 {
03513 LPRGBQUAD pAPAL = &(((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiColors[0]);
03514 LPRGBQUAD pBPal = (LPRGBQUAD)(pBBMI + sizeof(BITMAPINFOHEADER));
03515 memcpy(pAPAL , pBPal, (pBBMI->biClrUsed * sizeof (RGBQUAD)) );
03516 }
03517
03518
03519
03520 pABMI->biClrUsed = pBBMI->biClrUsed;
03521 pABMI->biClrImportant = pBBMI->biClrImportant;
03522
03523 if (!MKB_BodgeCopyBitmap(width, height, bpp,(LPBYTE)pB, (LPBYTE)pA))
03524 {
03525 GlobalUnlock(MHandle);
03526 INT32 result = AccusoftFilters::pfnIMG_delete_bitmap(Handle);
03527 delete pKB;
03528 *ppOutput = NULL;
03529 return FALSE;
03530 }
03531 }
03532 else
03533 #endif
03534 {
03535
03536 memcpy(pABMI , pBBMI, sizeof(BITMAPINFOHEADER) + (pBBMI->biClrUsed * sizeof (DWORD)) );
03537
03538
03539 memcpy(pA , pB, pABMI->biSizeImage);
03540 }
03541 }
03542 else
03543 {
03544 POINT tempPoints[3];
03545 tempPoints[0].x = 0; tempPoints[0].y = 0;
03546 tempPoints[1].x = (INT32)(pBBMI->biWidth); tempPoints[1].y = 0;
03547 tempPoints[2].x = 0; tempPoints[2].y = (INT32)(pBBMI->biHeight);
03548 SetA(pKB);
03549 ZeroA();
03550 GC->SetBitmapFill(pBBMI,(LPBYTE)pB,
03551 0,
03552 tempPoints,
03553 0,
03554 NULL,
03555 NULL,
03556 NULL,
03557 NULL,
03558 NULL
03559 );
03560 DoRect();
03561 }
03562
03563 pABMI->biXPelsPerMeter = pBBMI->biXPelsPerMeter;
03564 pABMI->biYPelsPerMeter = pBBMI->biYPelsPerMeter;
03565
03566
03567
03568 GlobalUnlock(MHandle);
03569
03570 if (ResetAccusoftDibsToRuns)
03571 {
03572
03573 ResetAccusoftDibsToRuns = FALSE;
03574 }
03575
03576 INT32 result = AccusoftFilters::pfnIMG_delete_bitmap(Handle);
03577 if (result < 0)
03578 {
03579 delete pKB;
03580 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03581 }
03582
03583 *ppOutput = pKB;
03584
03585
03586 #ifdef _DEBUG
03587
03588
03589
03590
03591
03592
03593
03594
03595 #endif
03596
03597 return TRUE;
03598 }
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608
03609
03610
03611
03612
03613
03614
03615
03616
03617
03618 BOOL BfxALU::FlipX(KernelBitmap * * ppOutput)
03619 {
03620 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03621 INT32 AccusoftHandle = -1;
03622 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03623 INT32 result = AccusoftFilters::pfnIMG_flip_bitmapx(AccusoftHandle);
03624 if (result < 0)
03625 {
03626 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03627 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03628 }
03629 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_FLIPX));
03630 }
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650 BOOL BfxALU::FlipY(KernelBitmap * * ppOutput)
03651 {
03652 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03653 INT32 AccusoftHandle = -1;
03654 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03655 INT32 result = AccusoftFilters::pfnIMG_flip_bitmapy(AccusoftHandle);
03656 if (result < 0)
03657 {
03658 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03659 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03660 }
03661 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_FLIPY));
03662 }
03663
03664
03665
03666
03667
03668
03669
03670
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680
03681
03682 BOOL BfxALU::Rotate90(KernelBitmap * * ppOutput)
03683 {
03684 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03685 INT32 AccusoftHandle = -1;
03686 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03687 INT32 result = AccusoftFilters::pfnIMG_rotate_bitmap(AccusoftHandle, 9000);
03688 if (result < 0)
03689 {
03690 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03691 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03692 }
03693 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_ROTATE90));
03694 }
03695
03696
03697
03698
03699
03700
03701
03702
03703
03704
03705
03706
03707
03708
03709
03710
03711
03712
03713
03714 BOOL BfxALU::Rotate180(KernelBitmap * * ppOutput)
03715 {
03716 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03717 INT32 AccusoftHandle = -1;
03718 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03719 INT32 result = AccusoftFilters::pfnIMG_rotate_bitmap(AccusoftHandle, 18000);
03720 if (result < 0)
03721 {
03722 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03723 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03724 }
03725 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_ROTATE180));
03726 }
03727
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737
03738
03739
03740
03741
03742
03743
03744
03745
03746 BOOL BfxALU::Rotate270(KernelBitmap * * ppOutput)
03747 {
03748 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03749 INT32 AccusoftHandle = -1;
03750 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03751 INT32 result = AccusoftFilters::pfnIMG_rotate_bitmap(AccusoftHandle, 27000);
03752 if (result < 0)
03753 {
03754 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03755 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03756 }
03757
03758 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_ROTATE270));
03759 }
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775
03776
03777
03778 BOOL BfxALU::BrightnessContrast(KernelBitmap * * ppOutput, INT32 Brightness, INT32 Contrast, INT32 Colour)
03779 {
03780 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03781 #if 0
03782 INT32 AccusoftHandle = -1;
03783 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03784 INT32 result = AccusoftFilters::pfnIMG_set_lut(AccusoftHandle, (INT32) Brightness, (INT32) Contrast);
03785 if (result < 0)
03786 {
03787 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03788 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03789 }
03790 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_BRIGHTCONT));
03791 #endif
03792
03793 *ppOutput = NewBitmap(B,0,0,0,NULL, _R(IDS_BFX_BRIGHTCONT));
03794 if (!ppOutput) return FALSE;
03795
03796 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
03797 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)((*ppOutput)->ActualBitmap))->BMInfo->bmiHeader);
03798
03799 DWORD PaletteUsed = pBBMI->biClrUsed;
03800
03801 ERROR2IF ((pBBMI->biSizeImage == 0) || (pBBMI->biCompression != BI_RGB) || (pBBMI->biHeight<0), FALSE,
03802 "A naughty DIB format has been used internally");
03803 pABMI->biXPelsPerMeter = pBBMI->biXPelsPerMeter;
03804 pABMI->biYPelsPerMeter = pBBMI->biYPelsPerMeter;
03805 ERROR2IF ((pBBMI->biSizeImage != pABMI->biSizeImage), FALSE, "BfxALU brightness & constrast size upset");
03806
03807 DWORD Width;
03808 DWORD Height;
03809 DWORD Size;
03810 LPBYTE Source;
03811 LPBYTE Dest;
03812 LPBYTE pSBits = (((CWxBitmap *)(B->ActualBitmap))->BMBytes);
03813 LPBYTE pDBits = (((CWxBitmap *)((*ppOutput)->ActualBitmap))->BMBytes);
03814
03815
03816 BOOL SingleChannel=IsGreyscaleBitmap(B);
03817
03818
03819 if ((SingleChannel) || pBBMI->biBitCount>8)
03820 {
03821 if (SingleChannel && PaletteUsed)
03822 {
03823
03824 memcpy(((LPBYTE)(pABMI + 1)) , ((LPBYTE)(pBBMI + 1)) ,
03825 PaletteUsed * sizeof(DWORD));
03826 }
03827 else
03828 {
03829 PaletteUsed = 0;
03830 }
03831 Width = pBBMI->biWidth;
03832 Height = pBBMI->biHeight;
03833 Size = (pBBMI->biBitCount / 8);
03834 Source = pSBits;
03835 Dest = pDBits;
03836 }
03837 else
03838 {
03839
03840 if (PaletteUsed == 0) PaletteUsed = 1<<pBBMI->biBitCount;
03841 Width = PaletteUsed;
03842 Height = 1;
03843 Size = 4;
03844
03845 Source = ((LPBYTE)(pBBMI + 1));
03846 Dest = ((LPBYTE)(pABMI + 1));
03847
03848 memcpy(pDBits , pSBits , pBBMI->biSizeImage);
03849 }
03850
03851 if (!AdjustBrightnessContrastColour(Source, Dest, Size, Width, Height, Brightness, Contrast, Colour, SingleChannel))
03852 {
03853 delete *ppOutput;
03854 *ppOutput=NULL;
03855 return FALSE;
03856 }
03857 return TRUE;
03858 }
03859
03860
03861
03862
03863
03864
03865
03866
03867
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877 BOOL BfxALU::BayerMono(KernelBitmap * * ppOutput)
03878 {
03879 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03880 INT32 AccusoftHandle = -1;
03881 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03882 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
03883 {
03884 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
03885 if (result < 0)
03886 {
03887 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03888 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03889 }
03890 }
03891 INT32 result = AccusoftFilters::pfnIMG_bayer_mono(AccusoftHandle);
03892 if (result < 0)
03893 {
03894 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03895 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03896 }
03897
03898
03899 ResetAccusoftDibsToRuns = TRUE;
03900
03901 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_BAYERMONO));
03902 }
03903
03904
03905
03906
03907
03908
03909
03910
03911
03912
03913
03914
03915
03916
03917
03918
03919
03920
03921 BOOL BfxALU::HalftoneMono(KernelBitmap * * ppOutput)
03922 {
03923 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03924 INT32 AccusoftHandle = -1;
03925 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03926 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
03927 {
03928 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
03929 if (result < 0)
03930 {
03931 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03932 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03933 }
03934 }
03935 INT32 result = AccusoftFilters::pfnIMG_halftone_mono(AccusoftHandle);
03936
03937 if (result < 0)
03938 {
03939 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03940 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03941 }
03942
03943
03944
03945
03946 ResetAccusoftDibsToRuns = TRUE;
03947
03948
03949
03950
03951
03952
03953 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_HALFTONEMONO));
03954 }
03955
03956
03957
03958
03959
03960
03961
03962
03963
03964
03965
03966
03967
03968
03969
03970
03971
03972
03973 BOOL BfxALU::DiffusionMono(KernelBitmap * * ppOutput)
03974 {
03975 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
03976 INT32 AccusoftHandle = -1;
03977 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
03978 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
03979 {
03980 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
03981 if (result < 0)
03982 {
03983 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03984 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03985 }
03986 }
03987 INT32 result = AccusoftFilters::pfnIMG_diffusion_mono(AccusoftHandle);
03988 if (result < 0)
03989 {
03990 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
03991 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
03992 }
03993
03994
03995 ResetAccusoftDibsToRuns = TRUE;
03996
03997 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_DIFFUSIONMONO));
03998 }
03999
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009
04010
04011
04012
04013
04014
04015
04016
04017
04018
04019 BOOL BfxALU::BayerColour(KernelBitmap * * ppOutput)
04020 {
04021 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04022 INT32 AccusoftHandle = -1;
04023 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04024 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04025 {
04026 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04027 if (result < 0)
04028 {
04029 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04030 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04031 }
04032 }
04033 INT32 result = AccusoftFilters::pfnIMG_bayer_color(AccusoftHandle);
04034 if (result < 0)
04035 {
04036 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04037 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04038 }
04039 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_BAYERCOLOUR));
04040 }
04041
04042
04043
04044
04045
04046
04047
04048
04049
04050
04051
04052
04053
04054
04055
04056
04057
04058
04059 BOOL BfxALU::PopularityColour(KernelBitmap * * ppOutput)
04060 {
04061 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04062 INT32 AccusoftHandle = -1;
04063 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04064 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04065 {
04066 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04067 if (result < 0)
04068 {
04069 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04070 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04071 }
04072 }
04073 INT32 result = AccusoftFilters::pfnIMG_popularity_color(AccusoftHandle);
04074 if (result < 0)
04075 {
04076 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04077 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04078 }
04079 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_POPULARITYCOLOUR));
04080 }
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091
04092
04093
04094
04095
04096
04097
04098
04099 BOOL BfxALU::DiffusionColour(KernelBitmap * * ppOutput)
04100 {
04101
04102
04103
04104 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04105 INT32 AccusoftHandle = -1;
04106 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04107 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04108 {
04109 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04110 if (result < 0)
04111 {
04112 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04113 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04114 }
04115 }
04116 INT32 result = AccusoftFilters::pfnIMG_diffusion_color(AccusoftHandle);
04117 if (result < 0)
04118 {
04119 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04120 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04121 }
04122 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_DIFFUSIONCOLOUR));
04123 }
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135
04136
04137
04138
04139
04140
04141
04142 BOOL BfxALU::MakeGreyscale(KernelBitmap * * ppOutput)
04143 {
04144 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04145 INT32 AccusoftHandle = -1;
04146 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04147 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04148 {
04149 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04150 if (result < 0)
04151 {
04152 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04153 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04154 }
04155 }
04156 INT32 result = AccusoftFilters::pfnIMG_color_gray(AccusoftHandle);
04157 if (result < 0)
04158 {
04159 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04160 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04161 }
04162 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_GREYSCALE));
04163 }
04164 #endif //WEBSTER
04165 #endif //XARALX
04166
04167
04168
04169
04170
04171
04172
04173
04174
04175
04176
04177
04178
04179
04180
04181
04182
04183
04184
04185
04186 BOOL BfxALU::MakeGreyscale32to8(KernelBitmap * * ppOutput)
04187 {
04188 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04189
04190 *ppOutput = NewBitmap(B,0,0,8, NULL, _R(IDS_BFX_GREYSCALE));
04191 if (!ppOutput) return FALSE;
04192
04193 BITMAPINFOHEADER * pBBMI=&(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader);
04194 BITMAPINFOHEADER * pABMI=&(((CWxBitmap *)((*ppOutput)->ActualBitmap))->BMInfo->bmiHeader);
04195
04196 ERROR2IF ((pBBMI->biSizeImage == 0) || (pBBMI->biCompression != BI_RGB) || (pBBMI->biHeight<0)
04197 || (pBBMI->biBitCount !=32) , FALSE,
04198 "Can't convert this DIB (may be it's not 32 bits)");
04199 pABMI->biXPelsPerMeter = pBBMI->biXPelsPerMeter;
04200 pABMI->biYPelsPerMeter = pBBMI->biYPelsPerMeter;
04201 ERROR2IF ((pBBMI->biWidth != pABMI->biWidth)||(pBBMI->biHeight != pABMI->biHeight)||(pABMI->biClrUsed!=0x100),
04202 FALSE, "BfxALU MakeGreyscale32to8 size upset");
04203
04204 RGBQUAD * pSBits = (RGBQUAD *)(void *)(((CWxBitmap *)(B->ActualBitmap))->BMBytes);
04205 LPBYTE pDBits = (((CWxBitmap *)((*ppOutput)->ActualBitmap))->BMBytes);
04206
04207 RGBQUAD * Pal = ((RGBQUAD *)(void *)(pABMI + 1));
04208 for (INT32 x=0;x<0x100;x++)
04209 {
04210 Pal[x].rgbRed=Pal[x].rgbGreen=Pal[x].rgbBlue=(BYTE)x;
04211 Pal[x].rgbReserved=0;
04212 }
04213
04214 DWORD w=0;
04215 DWORD v=0;
04216 for (INT32 y=0;y<pBBMI->biHeight;y++)
04217 {
04218 for (INT32 x=0; x<pBBMI->biWidth; x++)
04219 {
04220 pDBits[v]=(2+pSBits[w].rgbRed+pSBits[w].rgbGreen+pSBits[w].rgbBlue)/3;
04221 w++;
04222 v++;
04223 }
04224 for (;v&3;v++) pDBits[v]=0;
04225 }
04226 ERROR3IF((w!=(pBBMI->biSizeImage>>2) || v!=pABMI->biSizeImage), "Alex messed up MakeGreyscale32to8 bitmap sizes");
04227 return TRUE;
04228 }
04229
04230 #endif //EXCLUDE_FROM_RALPH
04231
04232
04233
04234
04235
04236
04237
04238
04239
04240
04241
04242
04243
04244
04245
04246
04247
04248
04249
04250
04251 BOOL BfxALU::IsGreyscaleBitmap(KernelBitmap * pKB)
04252 {
04253 if ( (!pKB) || (!pKB->ActualBitmap) )
04254 return FALSE;
04255
04256 return IsGreyscaleBitmap(pKB->ActualBitmap);
04257 }
04258
04259
04260
04261
04262
04263
04264
04265
04266
04267
04268
04269
04270
04271
04272
04273
04274
04275
04276
04277
04278 BOOL BfxALU::IsGreyscaleBitmap(OILBitmap * pOilBmp)
04279 {
04280 if ( (!pOilBmp) || (!pOilBmp->IsKindOf(CC_RUNTIME_CLASS(CWxBitmap))) )
04281 return FALSE;
04282
04283 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)pOilBmp)->BMInfo->bmiHeader);
04284 if ((pBMI->biBitCount!=8) || (pBMI->biClrUsed!=0x100)) return FALSE;
04285 DWORD * pPal = (DWORD *)(void *)(pBMI +1 );
04286 for (DWORD x=0; x<0x100; x++) if ((pPal[x]&0x00ffffff) != (x|(x<<8)|(x<<16))) return FALSE;
04287 return TRUE;
04288 }
04289
04290 #ifndef WEBSTER
04291 #ifndef EXCLUDE_FROM_RALPH
04292 #ifndef EXCLUDE_FROM_XARALX
04293
04294
04295
04296
04297
04298
04299
04300
04301
04302
04303
04304
04305
04306
04307
04308
04309
04310
04311 BOOL BfxALU::Octree (KernelBitmap * * ppOutput)
04312 {
04313 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04314 INT32 AccusoftHandle = -1;
04315 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04316 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <8 )
04317 {
04318 INT32 result = AccusoftFilters::pfnIMG_promote_8(AccusoftHandle);
04319 if (result < 0)
04320 {
04321 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04322 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04323 }
04324 }
04325
04326 INT32 result = AccusoftFilters::pfnIMG_octree_color (AccusoftHandle, 8, NULL, 256);
04327
04328 if (result < 0)
04329 {
04330 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04331 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04332 }
04333 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_OCTREECOLOUR));
04334 }
04335
04336
04337
04338
04339
04340
04341
04342
04343
04344
04345
04346
04347
04348
04349
04350
04351
04352
04353
04354
04355 BOOL BfxALU::SharpenBlur(KernelBitmap * * ppOutput, INT32 Degree, INT32 Times)
04356 {
04357 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04358 INT32 AccusoftHandle = -1;
04359 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
04360 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <=8 )
04361 {
04362 INT32 result = AccusoftFilters::pfnIMG_promote_24(AccusoftHandle);
04363 if (result < 0)
04364 {
04365 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04366 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04367 }
04368 }
04369 if (Times>20) Times=20;
04370 for (INT32 i=1; i<=Times; i++)
04371 {
04372 INT32 result = AccusoftFilters::pfnIMG_sharpen_bitmap(AccusoftHandle, (INT32) Degree);
04373 if (result < 0)
04374 {
04375 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
04376 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
04377 }
04378 }
04379 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), (Degree>0)?_R(IDS_BFX_SHARPEN):_R(IDS_BFX_BLUR));
04380 }
04381
04382 #endif
04383
04384
04385
04386
04387
04388
04389
04390
04391
04392
04393
04394
04395
04396
04397
04398
04399
04400
04401
04402
04403
04404 INT32 BfxALUQuantisationRoutine( const void *arg1, const void *arg2 )
04405 {
04406 QuantisationCell * qc1 = *((QuantisationCell * *)(arg1));
04407 QuantisationCell * qc2 = *((QuantisationCell * *)(arg2));
04408 return ( ((qc1->pixels)>(qc2->pixels))?-1:( ((qc1->pixels)<(qc2->pixels))?1:0 ) );
04409 }
04410
04411
04412
04413 #define QUANT_SHIFT 4
04414 #define QUANT_SIZE ((1<<(8-QUANT_SHIFT))+1)
04415 #define QUANT_ROUND (1<<(QUANT_SHIFT-1))
04416
04417
04418 #define QMEMBER(x,y,z) [((x)+QUANT_SIZE*((y)+QUANT_SIZE*(z)))]
04419
04420
04421
04422
04423 #define QUANT_NUMBER (QUANT_SIZE*QUANT_SIZE*QUANT_SIZE)
04424
04425 BOOL BfxALU::RemoveDither(KernelBitmap * * ppOutput, INT32 Thresh, INT32 QuantCols, TraceMethod Method)
04426 {
04427 TRACEUSER( "Alex", _T("RemoveDither called Method %d, Degree %d\n"));
04428
04429 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
04430
04431 INT32 OutputBPP=1;
04432 INT32 NumPasses=1;
04433 INT32 Width=0;
04434 INT32 Depth=0;
04435 INT32 Height=0;
04436 INT32 l;
04437
04438 if (!GetSize(B, &Width, &Height, &Depth)) return FALSE;
04439
04440 DWORD * InputLine[5];
04441 BYTE * ByteLine[5];
04442 BYTE * OutputLine = NULL;
04443 for (l=0; l<5; l++) InputLine[l]=NULL;
04444
04445 Thresh=(Thresh*Thresh*3);
04446 if (Thresh>255*255*3) Thresh=255*255*3;
04447
04448 if (QuantCols<2) QuantCols=2;
04449 if ((Method==TRACEMETHOD_256COL) && (QuantCols<17)) QuantCols=17;
04450 if (QuantCols>255) QuantCols=255;
04451
04452 INT32 TotalCols=QuantCols;
04453
04454 *ppOutput=NULL;
04455
04456
04457
04458
04459 QuantisationCell * pQuantMap=NULL;
04460 if ((pQuantMap=(QuantisationCell *)CCMalloc(sizeof(QuantisationCell)*QUANT_NUMBER))==NULL)
04461 {
04462 return FALSE;
04463 }
04464
04465
04466
04467
04468
04469 QuantisationCell * * pQuantIndex = NULL;
04470 if ((pQuantIndex=(QuantisationCell * *)CCMalloc(sizeof(QuantisationCell *)*QUANT_NUMBER))==NULL)
04471 {
04472 CCFree(pQuantMap);
04473 return FALSE;
04474 }
04475
04476
04477 QuantisationCell * * QuantSort = pQuantIndex;
04478
04479
04480 ERROR3IF(QUANT_SIZE*QUANT_SIZE*QUANT_SIZE<256, "Too few quantisation steps");
04481
04482 switch(Method)
04483 {
04484 case TRACEMETHOD_MONO:
04485 OutputBPP=1;
04486 NumPasses=2;
04487 break;
04488 case TRACEMETHOD_GREYSCALE:
04489 OutputBPP=8;
04490 NumPasses=1;
04491 break;
04492 case TRACEMETHOD_256COL:
04493 {
04494 OutputBPP=8;
04495 NumPasses=2;
04496 for (INT32 i=0; i<QUANT_SIZE; i++) for (INT32 j=0; j<QUANT_SIZE; j++) for (INT32 k=0; k<QUANT_SIZE; k++)
04497 {
04498 (pQuantMap)QMEMBER(i,j,k).rsum=(pQuantMap)QMEMBER(i,j,k).gsum=(pQuantMap)QMEMBER(i,j,k).bsum=(pQuantMap)QMEMBER(i,j,k).pixels=0;
04499 (pQuantMap)QMEMBER(i,j,k).index=-1;
04500 (pQuantIndex)QMEMBER(i,j,k)=&(pQuantMap)QMEMBER(i,j,k);
04501 }
04502 }
04503 break;
04504 case TRACEMETHOD_TRUECOL:
04505 OutputBPP=32;
04506 NumPasses=1;
04507 break;
04508 default:
04509 ERROR2(FALSE,"BfxALU::RemoveDither doesn't understand trace method");
04510 break;
04511 }
04512
04513 KernelBitmap * pKB = NewBitmap(B, 0, 0, OutputBPP, NULL, _R(IDS_BFX_REMOVEDITHER));
04514
04515 if (!pKB)
04516 {
04517 CCFree(pQuantMap);
04518 CCFree(pQuantIndex);
04519 return FALSE;
04520 }
04521
04522 if (OutputBPP==1 && Depth==1)
04523 {
04524 DWORD * SPalette= (DWORD*)(void*)(((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiColors);
04525 if ((SPalette[0] & 0x00ffffff)==0 && (SPalette[1] & 0x00ffffff)==0x00ffffff)
04526 {
04527
04528
04529
04530
04531
04532
04533
04534
04535
04536 memcpy((((CWxBitmap *)(pKB->ActualBitmap))->BMBytes), (((CWxBitmap *)(B->ActualBitmap))->BMBytes),
04537 (((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiHeader.biSizeImage));
04538 RGBQUAD * Palette= (((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiColors);
04539 Palette[0].rgbRed=Palette[0].rgbBlue=Palette[0].rgbGreen=0;
04540 Palette[1].rgbRed=Palette[1].rgbBlue=Palette[1].rgbGreen=255;
04541 *ppOutput=pKB;
04542 CCFree(pQuantMap);
04543 CCFree(pQuantIndex);
04544 return TRUE;
04545 }
04546 }
04547
04548 INT32 x;
04549 INT32 y;
04550
04551
04552
04553
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565
04566
04567 INT32 NoiseMatrix[5][5]={
04568 { 1, 4, 6, 4, 1 },
04569 { 4, 8, 8, 8, 4 },
04570 { 6, 8, 8, 8, 6 },
04571 { 4, 8, 8, 8, 4 },
04572 { 1, 4, 6, 4, 1 }};
04573
04574 INT32 * NoiseMatrixP[5];
04575
04576 INT32 Distrib[256];
04577 INT32 Points=0;
04578 INT32 n;
04579 for (n=0; n<256; n++) Distrib[n]=0;
04580
04581 if (Method==TRACEMETHOD_GREYSCALE)
04582 {
04583 double QuantPoints[255];
04584 double QuantDist=256.0/(QuantCols-1);
04585 double q=-0.5*QuantDist;
04586 for (n=0; n<QuantCols; n++)
04587 {
04588 QuantPoints[n]=q;
04589 q+=QuantDist;
04590 }
04591 INT32 cp=0;
04592 for (n=0; n<256; n++)
04593 {
04594 while ((cp<QuantCols) && (n>QuantPoints[cp])) cp++;
04595 Distrib[n]=(INT32)(QuantDist*(cp-1));
04596 if (Distrib[n]<0) Distrib[n]=0;
04597 if (Distrib[n]>255) Distrib[n]=255;
04598 }
04599 }
04600
04601 OutputLine=(BYTE *) CCMalloc(Width<<2);
04602 if (!OutputLine)
04603 {
04604 CCFree(pQuantMap);
04605 CCFree(pQuantIndex);
04606 delete pKB;
04607 return FALSE;
04608 }
04609 for (x=0; x<(Width<<2); x++) OutputLine[x]=0;
04610
04611 for (l=0; l<5; l++)
04612 {
04613 if ((InputLine[l]=(DWORD *)CCMalloc((Width+4)<<2))==NULL)
04614 {
04615 for (l=0; l<5; l++) if (InputLine[l]) CCFree(InputLine[l]);
04616 CCFree(OutputLine);
04617 delete pKB;
04618 CCFree(pQuantMap);
04619 CCFree(pQuantIndex);
04620 return FALSE;
04621 };
04622 ByteLine[l]=(BYTE *)InputLine[l];
04623 NoiseMatrixP[l]=&(NoiseMatrix[l][0]);
04624 }
04625
04626
04627 for (INT32 Pass=0; Pass<NumPasses; Pass++)
04628 {
04629
04630
04631
04632 for (y=0; y<Height; y++)
04633 {
04634
04635
04636
04637
04638
04639
04640
04641 DWORD * L0=InputLine[0];
04642 for (l=0; l<5; l++)
04643 {
04644 InputLine[l]=(l==4)?L0:InputLine[l+1];
04645 }
04646
04647
04648 for (l=(y==0)?0:4; l<5; l++)
04649 {
04650 INT32 sy=y+l-2;
04651 if (sy<0) sy=0;
04652 if (sy>=Height) sy=Height-1;
04653 ConvertScanLineToDWORD(B,sy,&(InputLine[l][2]));
04654 InputLine[l][0]=InputLine[l][1]=InputLine[l][2];
04655 InputLine[l][Width+3]=InputLine[l][Width+2]=InputLine[l][Width+1];
04656 }
04657
04658 for (l=0; l<5; l++) ByteLine[l]=(BYTE *)InputLine[l];
04659
04660 INT32 r;
04661 INT32 g;
04662 INT32 b;
04663
04664
04665 BYTE * pOutput=OutputLine;
04666 if (Depth==1)
04667 {
04668
04669
04670
04671 memcpy(OutputLine, &(ByteLine[2][2<<2]), Width<<2);
04672 }
04673 else
04674 {
04675 #ifdef FASTREMOVEDITHER
04676
04677 FastRemoveDither(ByteLine, NoiseMatrixP, (DWORD *) OutputLine, Width, Thresh,
04678 (Method==TRACEMETHOD_GREYSCALE || Method==TRACEMETHOD_MONO)?1:0);
04679
04680 #else
04681 SlowRemoveDither(ByteLine, NoiseMatrix, OutputLine, Width, Thresh,
04682 (Method==TRACEMETHOD_GREYSCALE || Method==TRACEMETHOD_MONO));
04683 #endif
04684 }
04685
04686
04687 void * VImage = (((CWxBitmap *)(pKB->ActualBitmap))->BMBytes);
04688 switch (Method)
04689 {
04690 case TRACEMETHOD_GREYSCALE:
04691 {
04692 BYTE * Dest = &(((BYTE *) VImage)[((Width+3)&~3)*y]);
04693 for (x=0; x<Width; x++)
04694 {
04695 *(Dest++)=(BYTE)(DWORD)Distrib[*pOutput];
04696 pOutput+=4;
04697 }
04698 }
04699 break;
04700 case TRACEMETHOD_MONO:
04701 {
04702 if (!Pass)
04703 {
04704 for (x=0; x<Width; x++)
04705 {
04706 r=(INT32)(DWORD)(*pOutput);
04707 pOutput+=4;
04708 Distrib[r]++;
04709 Points++;
04710 }
04711 }
04712 else
04713 {
04714 BYTE * Dest = (&(((BYTE *) VImage)[(((Width+31)&~31)>>3)*y]))-1;
04715 for (x=0; x<Width; x++)
04716 {
04717 if (!(x&7)) *(++Dest)=0;
04718 *Dest |= Distrib[(INT32)(DWORD)(*pOutput)] >> (x&7);
04719 pOutput+=4;
04720 }
04721 }
04722 }
04723 break;
04724 case TRACEMETHOD_TRUECOL:
04725 {
04726 memcpy(&(((DWORD *) VImage)[Width*y]), pOutput, Width<<2);
04727 }
04728 break;
04729 case TRACEMETHOD_256COL:
04730 {
04731 if (!Pass)
04732 {
04733 for (x=0; x<Width; x++)
04734 {
04735 b=(INT32)(DWORD)*(pOutput++);
04736 g=(INT32)(DWORD)*(pOutput++);
04737 r=(INT32)(DWORD)*(pOutput++);
04738 pOutput++;
04739 INT32 qr=(r+QUANT_ROUND)>>QUANT_SHIFT;
04740 INT32 qg=(g+QUANT_ROUND)>>QUANT_SHIFT;
04741 INT32 qb=(b+QUANT_ROUND)>>QUANT_SHIFT;
04742 QuantisationCell * pQuantCell=&(pQuantMap)QMEMBER(qr,qg,qb);
04743 pQuantCell->pixels++;
04744 pQuantCell->rsum+=r;
04745 pQuantCell->gsum+=g;
04746 pQuantCell->bsum+=b;
04747 }
04748 }
04749 else
04750 {
04751 BYTE * Dest = &(((BYTE *) VImage)[((Width+3)&~3)*y]);
04752 for (x=0; x<Width; x++)
04753 {
04754 b=(INT32)(DWORD)*(pOutput++);
04755 g=(INT32)(DWORD)*(pOutput++);
04756 r=(INT32)(DWORD)*(pOutput++);
04757 pOutput++;
04758 INT32 qr=(r+QUANT_ROUND)>>QUANT_SHIFT;
04759 INT32 qg=(g+QUANT_ROUND)>>QUANT_SHIFT;
04760 INT32 qb=(b+QUANT_ROUND)>>QUANT_SHIFT;
04761 QuantisationCell * pQuantCell=&(pQuantMap)QMEMBER(qr,qg,qb);
04762 INT32 Index = pQuantCell->index;
04763 if (Index<0)
04764 {
04765
04766 INT32 rsum = pQuantCell->rsum;
04767 INT32 gsum = pQuantCell->gsum;
04768 INT32 bsum = pQuantCell->bsum;
04769
04770 INT32 MinD=0x7fffffff;
04771 Index=0;
04772 for (INT32 m=0; m<TotalCols; m++)
04773 {
04774
04775 INT32 d=IntegerSquare(QuantSort[m]->rsum - rsum)
04776 + IntegerSquare(QuantSort[m]->gsum - gsum)
04777 + IntegerSquare(QuantSort[m]->bsum - bsum);
04778 if (d<MinD)
04779 {
04780
04781 MinD=d;
04782 Index=m;
04783 }
04784 }
04785
04786 pQuantCell->index=Index;
04787 }
04788 ERROR3IF(((DWORD)Index)>255, "Wierd index value");
04789 *Dest++=(BYTE)(DWORD)Index;
04790 }
04791 }
04792 }
04793 break;
04794 default:
04795 {
04796 ERROR3("We shouldn't get here...");
04797 }
04798 break;
04799 }
04800
04801
04802 BOOL Continue=TRUE;
04803 if ((y & 15)==0) Continue=ContinueSlowJob((100*y/Height+100*Pass)/NumPasses);
04804 if (!Continue)
04805 {
04806 ERROR1RAW(_R(IDE_BFX_ABORT));
04807 for (l=0; l<5; l++) if (InputLine[l]) CCFree(InputLine[l]);
04808 CCFree(OutputLine);
04809 delete pKB;
04810 CCFree(pQuantMap);
04811 CCFree(pQuantIndex);
04812 return FALSE;
04813 }
04814 }
04815
04816 switch (Method)
04817 {
04818 case TRACEMETHOD_MONO:
04819 if (!Pass) {
04820 RGBQUAD * Palette= (((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiColors);
04821 INT32 Sum=0;
04822 for (INT32 n=0; n<256; n++)
04823 {
04824 BOOL Thresh=(Sum>Points/2)|(n==255);
04825 Sum+=Distrib[n];
04826 Distrib[n]=Thresh?0x80:0;
04827 }
04828 Palette[0].rgbRed=Palette[0].rgbBlue=Palette[0].rgbGreen=0;
04829 Palette[1].rgbRed=Palette[1].rgbBlue=Palette[1].rgbGreen=255;
04830 }
04831 break;
04832 case TRACEMETHOD_256COL:
04833 if (!Pass) {
04834
04835
04836
04837
04838 RGBQUAD * Palette= (((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiColors);
04839 INT32 totalpixels=Width * Height;
04840 INT32 pixmax=totalpixels * INT32(0xff);
04841 INT32 r;
04842 for (r=0; r<QUANT_SIZE; r+=QUANT_SIZE-1)
04843 for (INT32 g=0; g<QUANT_SIZE; g+=QUANT_SIZE-1)
04844 for (INT32 b=0; b<QUANT_SIZE; b+=QUANT_SIZE-1)
04845 {
04846 QuantisationCell * pQuantCell=&(pQuantMap)QMEMBER(r,g,b);
04847 pQuantCell->rsum=r?pixmax:0;
04848 pQuantCell->gsum=g?pixmax:0;
04849 pQuantCell->bsum=b?pixmax:0;
04850 pQuantCell->pixels=totalpixels;
04851 }
04852
04853
04854
04855 for (r=1; r<QUANT_SIZE-1; r+=2)
04856 {
04857 QuantisationCell * pQuantCell=&(pQuantMap)QMEMBER(r,r,r);
04858 pQuantCell->rsum=pQuantCell->gsum=pQuantCell->bsum=
04859 (r<<QUANT_SHIFT) * (pQuantCell->pixels=totalpixels);
04860 }
04861
04862
04863 qsort((void *)(QuantSort),QUANT_SIZE*QUANT_SIZE*QUANT_SIZE,sizeof(QuantisationCell *),
04864 &BfxALUQuantisationRoutine);
04865 TotalCols=0;
04866 INT32 n;
04867
04868
04869 for (n=0; n<256; n++) Palette[n].rgbRed=Palette[n].rgbBlue=Palette[n].rgbGreen=Palette[n].rgbReserved=0;
04870
04871
04872 for (n=0; (n<QUANT_SIZE*QUANT_SIZE*QUANT_SIZE) ; n++ ) if (QuantSort[n]->pixels>0)
04873 {
04874 INT32 r=(QuantSort[n]->rsum+(INT32)(QuantSort[n]->pixels>>1))/QuantSort[n]->pixels;
04875 INT32 g=(QuantSort[n]->gsum+(INT32)(QuantSort[n]->pixels>>1))/QuantSort[n]->pixels;
04876 INT32 b=(QuantSort[n]->bsum+(INT32)(QuantSort[n]->pixels>>1))/QuantSort[n]->pixels;
04877 if (r<0) r=0;
04878 if (r>255) r=255;
04879 if (g<0) g=0;
04880 if (g>255) g=255;
04881 if (b<0) b=0;
04882 if (b>255) b=255;
04883 QuantSort[n]->rsum = r;
04884 QuantSort[n]->gsum = g;
04885 QuantSort[n]->bsum = b;
04886 ERROR3IF((n>0) && (QuantSort[n-1]->pixels<QuantSort[n]->pixels), "urm, they aren't in order...");
04887 }
04888
04889
04890 for (n=0; (n<QuantCols) && (QuantSort[n]->pixels>0); n++)
04891 {
04892 QuantSort[n]->index=n;
04893 TotalCols=n+1;
04894 Palette[n].rgbRed=(BYTE)(DWORD)(QuantSort[n]->rsum);
04895 Palette[n].rgbBlue=(BYTE)(DWORD)(QuantSort[n]->bsum);
04896 Palette[n].rgbGreen=(BYTE)(DWORD)(QuantSort[n]->gsum);
04897 }
04898
04899
04900 ERROR3IF(!TotalCols, "OK, how come this image had no colours in it *at all*");
04901 }
04902 break;
04903 case TRACEMETHOD_GREYSCALE:
04904 {
04905 RGBQUAD * Palette= (((CWxBitmap *)(pKB->ActualBitmap))->BMInfo->bmiColors);
04906 for (INT32 c=0; c<256; c++)
04907 Palette[c].rgbRed=Palette[c].rgbBlue=Palette[c].rgbGreen=(BYTE)(DWORD)c;
04908 }
04909 break;
04910 default:
04911 break;
04912 }
04913 }
04914
04915 for (l=0; l<5; l++) if (InputLine[l]) CCFree(InputLine[l]);
04916 CCFree(OutputLine);
04917 *ppOutput=pKB;
04918 CCFree(pQuantMap);
04919 CCFree(pQuantIndex);
04920 return TRUE;
04921 }
04922
04923
04924
04925
04926
04927
04928
04929
04930
04931
04932
04933
04934
04935
04936
04937
04938
04939
04940
04941
04942
04943
04944 void BfxALU::SlowRemoveDither(BYTE * ByteLine[5], INT32 NoiseMatrix[5][5], BYTE * OutputLine, INT32 Width, INT32 Thresh, BOOL Mono)
04945 {
04946 for (INT32 x=0; x<Width; x++)
04947 {
04948 INT32 r=0;
04949 INT32 g=0;
04950 INT32 b=0;
04951
04952 INT32 s=0;
04953
04954 INT32 CB=(INT32)(ByteLine[2][2*4]);
04955 INT32 CG=(INT32)(ByteLine[2][2*4+1]);
04956 INT32 CR=(INT32)(ByteLine[2][2*4+2]);
04957
04958 for (INT32 dy=0; dy<=4; dy++)
04959 {
04960 for (INT32 dx=0; dx<=4; dx++)
04961 {
04962 INT32 v=NoiseMatrix[dx][dy];
04963
04964 INT32 LB=(INT32)(DWORD)(*(ByteLine[dy]++));
04965 INT32 LG=(INT32)(DWORD)(*(ByteLine[dy]++));
04966 INT32 LR=(INT32)(DWORD)(*(ByteLine[dy]++));
04967
04968 INT32 dr=LR-CR;
04969 INT32 dg=LG-CG;
04970 INT32 db=LB-CB;
04971 if (((dr*dr)+(dg*dg)+(db*db))<=Thresh)
04972 {
04973 s+=v;
04974 r+=v*LR;
04975 g+=v*LG;
04976 b+=v*LB;
04977 }
04978 ByteLine[dy]++;
04979 }
04980 ByteLine[dy]-=16;
04981 }
04982
04983 if (s)
04984 {
04985 if (Mono)
04986 {
04987 r=r+g+b;
04988 s*=3;
04989 r+=s>>1;
04990 r=r/s;
04991 if (r<0) r=0;
04992 if (r>255) r=255;
04993 }
04994 else
04995 {
04996 r+=s>>1;
04997 g+=s>>1;
04998 b+=s>>1;
04999 r=r/s;
05000 g=g/s;
05001 b=b/s;
05002 if (r<0) r=0;
05003 if (r>255) r=255;
05004 if (g<0) g=0;
05005 if (g>255) g=255;
05006 if (b<0) b=0;
05007 if (b>255) b=255;
05008 }
05009 }
05010 else
05011 {
05012 ERROR3("BfxALU::SlowRemoveDither should never get here!");
05013 }
05014
05015 *(OutputLine++)=(BYTE)(DWORD)b;
05016 *(OutputLine++)=(BYTE)(DWORD)g;
05017 *(OutputLine++)=(BYTE)(DWORD)r;
05018 OutputLine++;
05019 }
05020 return;
05021 }
05022
05023 #ifndef EXCLUDE_FROM_XARALX
05024
05025
05026
05027
05028
05029
05030
05031
05032
05033
05034
05035
05036
05037
05038
05039
05040
05041 BOOL BfxALU::SpecialEffect(KernelBitmap * * ppOutput, double * Matrix, BfxSpecialEffect Type)
05042 {
05043 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
05044 ERROR2IF((!Matrix) && (Type == BFX_SFX_USER), FALSE, "Must pass a matrix for BFX_SFX_USER");
05045 char matrix[9];
05046 if (Type==BFX_SFX_USER) for (INT32 i=0; i<=8; i++) matrix[i]=(char)(INT32)Matrix[i];
05047
05048 INT32 AccusoftHandle = -1;
05049 if (!MakeAccusoftHandle(&AccusoftHandle)) return FALSE;
05050
05051 if ( (((CWxBitmap *)(B->ActualBitmap))->BMInfo->bmiHeader).biBitCount <=8 )
05052 {
05053 INT32 result = AccusoftFilters::pfnIMG_promote_24(AccusoftHandle);
05054 if (result < 0)
05055 {
05056 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
05057 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
05058 }
05059 }
05060
05061 INT32 result = AccusoftFilters::pfnIMG_process_bitmap(AccusoftHandle, (INT32) Type, matrix);
05062 if (result < 0)
05063 {
05064 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
05065 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
05066 }
05067 UINT32 res = _R(IDS_BFX_EFFECTNAME0);
05068 switch (Type)
05069 {
05070 case BFX_SFX_USER:
05071 res=_R(IDS_BFX_EFFECTNAME0);
05072 break;
05073 case BFX_SFX_ISOLATEPOINTS:
05074 res=_R(IDS_BFX_EFFECTNAME1);
05075 break;
05076 case BFX_SFX_EDGE:
05077 res=_R(IDS_BFX_EFFECTNAME2);
05078 break;
05079 case BFX_SFX_HEDGE:
05080 res=_R(IDS_BFX_EFFECTNAME3);
05081 break;
05082 case BFX_SFX_VEDGE:
05083 res=_R(IDS_BFX_EFFECTNAME4);
05084 break;
05085 case BFX_SFX_P45EDGE:
05086 res=_R(IDS_BFX_EFFECTNAME5);
05087 break;
05088 case BFX_SFX_N45EDGE:
05089 res=_R(IDS_BFX_EFFECTNAME6);
05090 break;
05091 case BFX_SFX_LAPLACIAN:
05092 res=_R(IDS_BFX_EFFECTNAME7);
05093 break;
05094 case BFX_SFX_DIALATION:
05095 res=_R(IDS_BFX_EFFECTNAME8);
05096 break;
05097 case BFX_SFX_ROBERTS:
05098 res=_R(IDS_BFX_EFFECTNAME9);
05099 break;
05100 default:
05101 res=_R(IDS_BFX_EFFECTNAME0);
05102 break;
05103 }
05104
05105 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), res);
05106 }
05107
05108
05109
05110
05111
05112
05113
05114
05115
05116
05117
05118
05119
05120
05121
05122
05123
05124
05125 BOOL BfxALU::Resize(KernelBitmap * * ppOutput, INT32 Width, INT32 Height, BOOL LinearInterpolation)
05126 {
05127 ERROR2IF((!ppOutput),FALSE, "BfxALU output parameter must be non-null");
05128
05129
05130
05131 BOOL DoBodge = FALSE;
05132 INT32 bpp = B->GetBPP();
05133 #ifdef BODGE_ACCUSOFT_RESIZE
05134 if (LinearInterpolation && (bpp == 4 || bpp == 8 || bpp == 24 || bpp == 32))
05135 DoBodge = TRUE;
05136 #endif
05137
05138 INT32 AccusoftHandle = -1;
05139 if (!MakeAccusoftHandle(&AccusoftHandle, DoBodge))
05140 return FALSE;
05141
05142 INT32 result = 0;
05143 if (LinearInterpolation)
05144 {
05145
05146
05147
05148 INT32 NewWidth = Width;
05149 #ifdef BODGE_ACCUSOFT_RESIZE
05150
05151
05152
05153
05154 if (DoBodge)
05155 NewWidth *= 3;
05156 #endif
05157 if (bpp <= 8)
05158 {
05159 result = AccusoftFilters::pfnIMG_promote_24(AccusoftHandle);
05160 if (result < 0)
05161 {
05162 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
05163 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
05164 }
05165 }
05166 result = AccusoftFilters::pfnIMG_resize_bitmap_interp(AccusoftHandle, (INT32) NewWidth, (INT32) Height);
05167 }
05168 else
05169 {
05170
05171 result = AccusoftFilters::pfnIMG_resize_bitmap(AccusoftHandle, (INT32) Width, (INT32) Height);
05172 }
05173
05174 if (result < 0)
05175 {
05176 AccusoftFilters::pfnIMG_delete_bitmap(AccusoftHandle);
05177 ERROR1(FALSE, _R(IDE_ACCUSOFT_ERROR) - result);
05178 }
05179
05180 return MakeKernelBitmap(AccusoftHandle, ppOutput, FALSE, &(B->ActualBitmap->GetName()), _R(IDS_BFX_RESIZE), DoBodge);
05181 }
05182 #endif
05183
05184
05185
05186
05187
05188
05189
05190
05191
05192
05193
05194
05195
05196
05197
05198
05199
05200
05201
05202
05203
05204
05205 BOOL BfxALU::AdjustBrightnessContrastColour(LPBYTE Source, LPBYTE Dest, INT32 Size, INT32 Width, INT32 Height,
05206 INT32 Brightness, INT32 Contrast, INT32 Colour, BOOL SingleChannel)
05207 {
05208
05209
05210 double dBrightness = (Brightness*1.0)/127.0 *0.75;
05211 double dContrast = pow(2.0,3.0*(Contrast*1.0)/127.0);
05212 double dColour = pow(2.0,3.0*(Colour*1.0)/127.0);
05213
05214
05215
05216
05217 double PropA = dContrast * dColour;
05218 double PropB = dContrast / 3.0 * (1.0-dColour);
05219 double Offset = dBrightness + (1.0-dContrast)*0.5;
05220
05221 INT32 pa=(INT32)(PropA*(1<<15));
05222 INT32 pb=(INT32)(PropB*(1<<15));
05223 INT32 po=(INT32)(Offset*((1<<15)*255)+(1<<14));
05224
05225 BYTE * Data = (BYTE *) CCMalloc(3*256*256);
05226 if (!Data) return FALSE;
05227
05228
05229
05230
05231 #ifndef FASTLINEARABK
05232 INT32 a;
05233 INT32 b;
05234 INT32 r;
05235 for (a=0; a<256; a++) for (b=0; b<256*3; b++)
05236 {
05237 r=(a*pa+b*pb+po)>>15;
05238 LUTBYTE(a,b)=(r<0)?0:((r>255)?255:(BYTE)(INT32)(r));
05239 }
05240 #else
05241 FastLinearABK(Data, pa, pb, po, 256*3);
05242 #endif
05243
05244 DWORD Sum;
05245
05246 if (!SingleChannel)
05247 {
05248 for (INT32 y = 0 ;y<Height; y++)
05249 {
05250 for (INT32 x = 0; x<Width; x++)
05251 {
05252 Sum=((DWORD)Source[0])+((DWORD)Source[1])+((DWORD)Source[2]);
05253 Dest[0]=LUTBYTE(Source[0], Sum);
05254 Dest[1]=LUTBYTE(Source[1], Sum);
05255 Dest[2]=LUTBYTE(Source[2], Sum);
05256 Source+=Size;
05257 Dest+=Size;
05258 }
05259 Source = (LPBYTE)(void *)((((UINT_PTR)(void *)Source) +3)&(~3));
05260 Dest = (LPBYTE)(void *)((((UINT_PTR)(void *)Dest) +3)&(~3));
05261 }
05262 }
05263 else
05264 {
05265 for (INT32 y = 0 ;y<Height; y++)
05266 {
05267 for (INT32 x = 0; x<Width; x++)
05268 {
05269 *Dest=LUTBYTE((*Source), (*Source));
05270 Source+=Size;
05271 Dest+=Size;
05272 }
05273 Source = (LPBYTE)(void *)((((UINT_PTR)(void *)Source) +3)&(~3));
05274 Dest = (LPBYTE)(void *)((((UINT_PTR)(void *)Dest) +3)&(~3));
05275 }
05276 }
05277
05278 CCFree(Data);
05279 return TRUE;
05280 }
05281
05282
05283
05284
05285
05286
05287
05288
05289
05290
05291
05292
05293
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304 void BfxALU::ConvertScanLineToDWORD(KernelBitmap * pBitmap, INT32 Line, DWORD * pBuffer)
05305 {
05306 BITMAPINFOHEADER * pBMI=&(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiHeader);
05307 RGBQUAD * pPal=(((CWxBitmap *)(pBitmap->ActualBitmap))->BMInfo->bmiColors);
05308 void * VImage = (((CWxBitmap *)(pBitmap->ActualBitmap))->BMBytes);
05309 INT32 Width=pBMI->biWidth;
05310 switch (pBMI->biBitCount)
05311 {
05312 case 32:
05313 {
05314 DWORD * Source = &(((DWORD *) VImage)[Width*Line]);
05315 for (INT32 w=0; w<Width; w++) pBuffer[w]=Source[w] & 0x00ffffff;
05316 return;
05317 }
05318 break;
05319 case 24:
05320 {
05321 BYTE * Source = &(((BYTE *) VImage)[(((Width*3)+3)&~3)*Line]);
05322 INT32 b=0;
05323 for (INT32 w=0; w<Width; w++)
05324 {
05325 pBuffer[w]=(((INT32)(Source[b])))|(((INT32)(Source[b+1]))<<8)|(((INT32)(Source[b+2]))<<16);
05326 b+=3;
05327 }
05328 return;
05329 }
05330 break;
05331 case 8:
05332 {
05333 BYTE * Source = &(((BYTE *) VImage)[((Width+3)&~3)*Line]);
05334 for (INT32 w=0; w<Width; w++)
05335 {
05336 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[Source[w]]));
05337 }
05338 return;
05339 }
05340 break;
05341 case 4:
05342 {
05343 BYTE * Source = &(((BYTE *) VImage)[(((Width+7)&~7)>>1)*Line]);
05344 for (INT32 w=0; w<Width; w++)
05345 {
05346 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[ (Source[w>>1]>>( (1-(w&1)) <<2) )&0xf]));
05347 }
05348 return;
05349 }
05350 break;
05351 case 2:
05352 {
05353 BYTE * Source = &(((BYTE *) VImage)[(((Width+15)&~15)>>2)*Line]);
05354 for (INT32 w=0; w<Width; w++)
05355 {
05356 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[ (Source[w>>2]>>( (3-(w&3)) <<1) )&0x3]));
05357 }
05358 return;
05359 }
05360 break;
05361 case 1:
05362 {
05363 BYTE * Source = &(((BYTE *) VImage)[(((Width+31)&~31)>>3)*Line]);
05364 for (INT32 w=0; w<Width; w++)
05365 {
05366 pBuffer[w]=0x00ffffff & *((DWORD *)(&pPal[ (Source[w>>3]>>( (7-(w&7)) ) )&0x1]));
05367 }
05368 return;
05369 }
05370 break;
05371 default:
05372 {
05373 ERROR3("BPP not supported");
05374 }
05375 break;
05376 }
05377 return;
05378 }
05379
05380
05381
05382
05383
05384
05385
05386
05387
05388
05389
05390
05391
05392
05393
05394
05395
05396
05397
05398
05399
05400
05401
05402 void BfxALU::ConvertScanLineFromDWORD(KernelBitmap * pBitmap, INT32 Line, DWORD * pBuffer)
05403 {
05404 return;
05405 }
05406
05407 #endif // EXCLUDE_FROM_RALPH
05408 #endif //WEBSTER