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 "bfxatom.h"
00106
00107
00108
00109
00110
00111
00112
00113 #include "nodebmp.h"
00114 #include "bitmpinf.h"
00115 #include "chapter.h"
00116
00117 #include "page.h"
00118 #include "bfxtest.h"
00119 #include "bfxalu.h"
00120
00121
00122
00123 DECLARE_SOURCE("$Revision: 1282 $");
00124
00125
00126
00127 CC_IMPLEMENT_DYNCREATE(BitmapEffectAtom, BitmapEffectBase)
00128 CC_IMPLEMENT_DYNCREATE(BitmapEffectSILT, BitmapEffectAtom)
00129
00130
00131
00132 #define new CAM_DEBUG_NEW
00133
00134
00135 INT32 BitmapEffectAtom::TestValue=0;
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 #define DEBUGSILT 0
00157
00158 BOOL BitmapEffectSILT::Run()
00159 {
00160 KernelBitmap * Temp;
00161 INT32 Stage;
00162 double mDest,cDest,mAdd,cAdd,mCurrent,cCurrent;
00163 BfxALULUT * LUT;
00164 BfxALULUT * LUT2;
00165 BYTE CurrentZero, CurrentOne, AddZero, AddOne;
00166
00167 #define Stages 8
00168 #define TestSize 5
00169 double Coefficient[Stages+1]=
00170
00171
00172 {-0.153426, -0.538158, 0.291086, 0.539231, -3.12917, -0.989594, 6.792, 4.80329, 0};
00173
00174 double t;
00175
00176 #if DEBUGSILT
00177 double TestVars[TestSize];
00178 double RealVars[TestSize];
00179 double ScaleVars[TestSize];
00180 BYTE TestByte[256];
00181 BYTE DestByte[256];
00182 INT32 v;
00183 #endif
00184
00185 #if DEBUGSILT
00186 for (v=0; v<TestSize; v++) TestVars[v]=RealVars[v]=ScaleVars[v]=(((double)v) / (double)(TestSize-1));
00187
00188 for (v=0; v<=255; v++) TestByte[v]=DestByte[v]=v;
00189 #endif
00190
00191 t=0;
00192
00193 for (Stage=0; Stage<=Stages; Stage++)
00194 t+=(Coefficient[Stage]);
00195
00196 for (Stage=0; Stage<=Stages; Stage++) Coefficient[Stage]=Coefficient[Stage]*1.0/t;
00197
00198 #if DEBUGSILT
00199 TRACEUSER( "Alex", _T("Coefficients "));
00200 for (Stage=0; Stage<=Stages; Stage++)
00201 TRACEUSER( "Alex", _T("%d=%5f "),Stage,Coefficient[Stage]);
00202 TRACEUSER( "Alex", _T("\n"));
00203 #endif
00204
00205 if (!(LUT = new BfxALULUT)) return FALSE;
00206 if (!(LUT2 = new BfxALULUT))
00207 {
00208 delete LUT;
00209 return FALSE;
00210 }
00211
00212 if (!(Temp = ALU->NewBitmap(Destination)))
00213 {
00214 delete LUT;
00215 delete LUT2;
00216 return FALSE;
00217 }
00218
00219 if (!(ALU->SetA(Temp) &&
00220 ALU->ZeroA() &&
00221 ALU->SetA(Destination) &&
00222 ALU->ZeroA()))
00223 {
00224 delete LUT;
00225 delete LUT2;
00226 delete Temp;
00227 return FALSE;
00228 }
00229
00230
00231
00232
00233
00234 Stage=Stages;
00235
00236 if (Coefficient[Stage]>=0)
00237 {
00238 mAdd = Coefficient[Stage];
00239 cAdd = 0;
00240 if (!(ALU->SetB(Source) &&
00241 ALU->PlotB()
00242 ))
00243 {
00244 delete LUT;
00245 delete LUT2;
00246 delete Temp;
00247 return FALSE;
00248 }
00249 CurrentZero=0;
00250 CurrentOne=255;
00251
00252 #if DEBUGSILT
00253 for (v=0; v<TestSize; v++)
00254 {
00255 RealVars[v]=RealVars[v]*Coefficient[Stage];
00256 ScaleVars[v]=ScaleVars[v];
00257 }
00258 for (v=0; v<=255; v++)
00259 {
00260 DestByte[v]=TestByte[v];
00261 }
00262 #endif
00263
00264 }
00265 else
00266 {
00267 mAdd = -Coefficient[Stage];
00268 cAdd = -mAdd;
00269 if (!(ALU->SetB(Source) &&
00270 LUT->LinearABK(0,-1,1) &&
00271 ALU->PlotBLUT(LUT)
00272 ))
00273 {
00274 delete LUT;
00275 delete LUT2;
00276 delete Temp;
00277 return FALSE;
00278 }
00279 CurrentZero=255;
00280 CurrentOne=1;
00281
00282 #if DEBUGSILT
00283 for (v=0; v<TestSize; v++)
00284 {
00285 RealVars[v]=RealVars[v]*Coefficient[Stage];
00286 ScaleVars[v]=1.0-ScaleVars[v];
00287 }
00288 for (v=0; v<=255; v++)
00289 {
00290 DestByte[v]=LUT->GetLUT(0,TestByte[v]);
00291 }
00292 #endif
00293
00294 }
00295
00296 mDest=mAdd;
00297 cDest=cAdd;
00298
00299 #if DEBUGSILT
00300 TRACEUSER( "Alex", _T("Stage %d "),Stage);
00301 for (v=0; v<TestSize; v++)
00302 {
00303 TRACEUSER( "Alex", _T("%5f|%5f|%5f "),RealVars[v],ScaleVars[v]*mDest+cDest,ScaleVars[v]);
00304 }
00305 TRACEUSER( "Alex", _T(" .. %5f,%5f,%5f | %5f,%5f\n"),0.0,0.0,0.0,mDest,cDest);
00306
00307 TRACEUSER( "Alex", _T(" "));
00308 for (v=0; v<=10; v++) TRACEUSER( "Alex", _T("%2x~%2x "),v,DestByte[v]);
00309 for (v=245; v<=255; v++) TRACEUSER( "Alex", _T("%2x~%2x "),v,DestByte[v]);
00310 TRACEUSER( "Alex", _T("\n"));
00311 #endif
00312
00313 if (!(LUT2->LinearABK(2.0,-0.5,0)))
00314 {
00315 delete LUT;
00316 delete LUT2;
00317 delete Temp;
00318 return FALSE;
00319 }
00320
00321 for (Stage = Stages-1; Stage>=0; Stage--)
00322 {
00323 #if 1
00324 if (!(
00325 ALU->SetA(Temp) &&
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 ALU->ZeroA() &&
00336
00337
00338
00339
00340 ALU->SetB(Destination,0,1) &&
00341 ALU->AddKAB(0x20) &&
00342
00343 ALU->SetB(Destination,0,-1) &&
00344 ALU->AddKAB(0x20) &&
00345
00346 ALU->SetB(Destination,1,0) &&
00347 ALU->AddKAB(0x20) &&
00348
00349 ALU->SetB(Destination,-1,0) &&
00350 ALU->AddKAB(0x20) &&
00351
00352 ALU->SetB(Destination,1,1) &&
00353 ALU->AddKAB(0x10) &&
00354
00355 ALU->SetB(Destination,-1,1) &&
00356 ALU->AddKAB(0x10) &&
00357
00358 ALU->SetB(Destination,1,-1) &&
00359 ALU->AddKAB(0x10) &&
00360
00361 ALU->SetB(Destination,-1,-1) &&
00362 ALU->AddKAB(0x10) &&
00363
00364 ALU->SetB(Destination) &&
00365 ALU->PlotBLUT(LUT2) &&
00366
00367
00368 ALU->SetA(Destination) &&
00369 ALU->SetB(Temp) &&
00370 ALU->PlotB() &&
00371
00372 TRUE))
00373 {
00374 delete LUT;
00375 delete LUT2;
00376 delete Temp;
00377 return FALSE;
00378 }
00379 #endif
00380 mAdd = 1;
00381 cAdd = 0;
00382
00383 mCurrent = mDest;
00384 cCurrent = cDest;
00385 AddZero=0;
00386 AddOne=255;
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
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
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 if (Coefficient[Stage]>=0)
00483 {
00484 cDest = cCurrent + cAdd * Coefficient[Stage];
00485 mDest = mCurrent + mAdd * Coefficient[Stage];
00486 }
00487 else
00488 {
00489 cDest = cCurrent + (cAdd+mAdd) * Coefficient[Stage];
00490 mDest = mCurrent - mAdd * Coefficient[Stage];
00491 }
00492
00493 double mDestIso;
00494 double cDestIso;
00495 double LimitZero;
00496 double LimitOne;
00497
00498
00499
00500
00501
00502
00503
00504
00505 LimitZero=((((double)CurrentZero)/255.0*mCurrent)+cCurrent)+cAdd*Coefficient[Stage];
00506 LimitOne=((((double)CurrentOne)/255.0*mCurrent)+cCurrent)+((1.0*mAdd)+cAdd)*Coefficient[Stage];
00507 if (LimitOne>LimitZero)
00508 {
00509 cDestIso=LimitZero;
00510 mDestIso=LimitOne-LimitZero;
00511 }
00512 else
00513 {
00514 cDestIso=LimitOne;
00515 mDestIso=LimitZero-LimitOne;
00516 }
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 #if 0
00539 const double HighestIsoRange =9999.0;
00540 const double HighestRange = 4.0;
00541 double interp;
00542
00543 interp = 0.75 + 0.25 * (mDestIso/mDest);
00544
00545
00546 if (mDest<0.5/255.0) mDest = 0.5/255.0;
00547 if (mDestIso<0.5/255.0) mDestIso = 0.5/255.0;
00548
00549 if (mDestIso>HighestIsoRange)
00550 {
00551 cDestIso+=(mDestIso-HighestIsoRange)/2.0;
00552 mDestIso=HighestIsoRange;
00553 }
00554
00555 if (mDest>HighestRange)
00556 {
00557 cDest+=(mDest-HighestRange)/2.0;
00558 mDest=HighestRange;
00559 }
00560
00561 mDest = (1-interp) * mDest + interp * mDestIso;
00562 cDest = (1-interp) * cDest + interp * cDestIso;
00563 #endif
00564
00565 mDest=mDestIso;
00566 cDest=cDestIso;
00567
00568
00569
00570
00571 double oldcDest = cDest;
00572 cDest=(floor(cDest * 255.0))/255.0;
00573 mDest = (ceil((oldcDest + mDest)*255.0))/255.0 - cDest;
00574
00575 double PropA;
00576 double PropB;
00577 double Offset;
00578
00579
00580 PropA = mCurrent / mDest;
00581 PropB = Coefficient[Stage] * mAdd / mDest;
00582 Offset = (cCurrent+cAdd * Coefficient[Stage]-cDest)/ mDest;
00583
00584 #if DEBUGSILT
00585 for (v=0; v<TestSize; v++)
00586 {
00587 RealVars[v]+=Coefficient[Stage]*TestVars[v];
00588 ScaleVars[v]=PropA*ScaleVars[v]+PropB*TestVars[v]+Offset;
00589 }
00590 #endif
00591
00592 if (!(LUT->LinearABK(PropA, PropB, Offset) &&
00593 ALU->SetA(Destination) &&
00594 ALU->SetB(Source) &&
00595 ALU->PlotBLUT(LUT) &&
00596 TRUE))
00597 {
00598 delete LUT;
00599 delete LUT2;
00600 delete Temp;
00601 return FALSE;
00602 }
00603
00604 CurrentZero=LUT->GetLUT(CurrentZero,0);
00605 CurrentOne=LUT->GetLUT(CurrentOne,255);
00606
00607 #if DEBUGSILT
00608 for (v=0; v<=255; v++)
00609 {
00610 DestByte[v]=LUT->GetLUT(DestByte[v],TestByte[v]);
00611 }
00612
00613
00614 TRACEUSER( "Alex", _T("Stage %d "),Stage);
00615 for (v=0; v<TestSize; v++)
00616 {
00617 TRACEUSER( "Alex", _T("%5f|%5f|%5f "),RealVars[v],ScaleVars[v]*mDest+cDest,ScaleVars[v]);
00618 }
00619 TRACEUSER( "Alex", _T(" .. %5f,%5f,%5f | %5f,%5f\n"),PropA,PropB,Offset,mDest,cDest);
00620
00621 TRACEUSER( "Alex", _T(" "));
00622 for (v=0; v<=10; v++) TRACEUSER( "Alex", _T("%2x~%2x "),v,DestByte[v]);
00623 for (v=245; v<=255; v++) TRACEUSER( "Alex", _T("%2x~%2x "),v,DestByte[v]);
00624 TRACEUSER( "Alex", _T("\n"));
00625 #endif
00626
00627
00628 }
00629
00630 if (!(LUT->LinearABK(mDest, 0, cDest)
00631 && ALU->PlotBLUT(LUT)))
00632 {
00633 delete LUT;
00634 delete LUT2;
00635 delete Temp;
00636 return FALSE;
00637 }
00638
00639 #if DEBUGSILT
00640 for (v=0; v<=255; v++)
00641 {
00642 DestByte[v]=LUT->GetLUT(DestByte[v],TestByte[v]);
00643 }
00644
00645 TRACEUSER( "Alex", _T("End "));
00646 for (v=0; v<=10; v++) TRACEUSER( "Alex", _T("%2x~%2x "),v,DestByte[v]);
00647 for (v=245; v<=255; v++) TRACEUSER( "Alex", _T("%2x~%2x "),v,DestByte[v]);
00648 TRACEUSER( "Alex", _T("\n"));
00649 #endif
00650
00651 delete LUT;
00652 delete LUT2;
00653 delete Temp;
00654 return(TRUE);
00655
00656 }
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 void BitmapEffectAtom::Test(INT32 Value)
00678 {
00679 TRACEUSER( "Alex", _T("Value is %d\n"),Value);
00680
00681 TestValue=Value;
00682 }
00683
00684 void BitmapEffectAtom::Test2(UndoableOperation * Op)
00685 {
00686
00687 BOOL CarryOn=TRUE;
00688 Range Sel(*(GetApplication()->FindSelection()));
00689
00690 Node* FirstSelectedNode = Sel.FindFirst();
00691 if (FirstSelectedNode != NULL)
00692 {
00693 Node* CurrentNode = FirstSelectedNode;
00694 Node* NextCurrent;
00695
00696
00697 while ((CurrentNode != NULL) && CarryOn)
00698 {
00699 NextCurrent = Sel.FindNext(CurrentNode);
00700 if ( (CurrentNode->IsSelected()) && (CurrentNode->GetRuntimeClass() == CC_RUNTIME_CLASS(NodeBitmap)) )
00701 {
00702 KernelBitmap * pBitmap = ((NodeBitmap *)(CurrentNode))->GetBitmap();
00703 BitmapInfo BMInfo;
00704 UINT32 bpp;
00705 pBitmap->ActualBitmap->GetInfo(&BMInfo);
00706 bpp=BMInfo.PixelDepth;
00707
00708 TRACEUSER( "Alex", _T("Bitmap found %d bpp\n"),bpp);
00709
00710 if ((bpp==32) || TRUE)
00711 {
00712 CarryOn = FALSE;
00713 NodeBitmap *pNodeBitmap = new NodeBitmap;
00714 if ((pNodeBitmap == NULL) || (!pNodeBitmap->SetUpPath(12,12)))
00715 return;
00716
00717 Spread *pSpread;
00718 DocCoord Origin;
00719
00720
00721 Node *pNode = (Document::GetSelected())->GetFirstNode()->FindNext()->FindFirstChild();
00722 while ((pNode != NULL) && (!pNode->IsKindOf(CC_RUNTIME_CLASS(Chapter))))
00723 pNode = pNode->FindNext();
00724
00725 ENSURE(pNode->IsKindOf(CC_RUNTIME_CLASS(Chapter)),
00726 "Filter::GetFirstSpread(): Could not find Chapter");
00727 Chapter *pChapter = (Chapter *) pNode;
00728
00729
00730 pSpread = (Spread *) pChapter->FindFirstChild();
00731 ENSURE(pSpread->IsKindOf(CC_RUNTIME_CLASS(Spread)),
00732 "Filter::GetFirstSpread(): Could not find Spread");
00733
00734 Page *pPage = (Page *) pSpread->FindFirstPageInSpread();
00735 ENSURE(pPage->IsKindOf(CC_RUNTIME_CLASS(Page)),
00736 "BaseBitmapFilter::DoImport(): Could not find first Page");
00737
00738
00739 DocRect PageRect = pPage->GetPageRect();
00740 Origin = PageRect.lo;
00741
00742 KernelBitmap* kb = new KernelBitmap(BMInfo.PixelWidth,BMInfo.PixelHeight,32,100);
00743
00744 pNodeBitmap->GetBitmapRef()->Attach(kb);
00745 if (pNodeBitmap->GetBitmap() != kb)
00746 {
00747
00748 delete kb;
00749 }
00750
00751 ENSURE(pNodeBitmap->GetBitmap()->ActualBitmap != NULL, "No bitmap object found!");
00752
00753
00754
00755 BitmapInfo Info;
00756 pNodeBitmap->GetBitmap()->ActualBitmap->GetInfo(&Info);
00757
00758 DocRect BoundsRect;
00759 BoundsRect.lo = Origin;
00760 BoundsRect.hi.x = BoundsRect.lo.x + Info.RecommendedWidth;
00761 BoundsRect.hi.y = BoundsRect.lo.y + Info.RecommendedHeight;
00762
00763
00764 pNodeBitmap->CreateShape(BoundsRect);
00765
00766
00767
00768 if (!pNodeBitmap->ApplyDefaultBitmapAttrs(Op))
00769 {
00770 return;
00771 }
00772
00773
00774 if (!Op->DoInsertNewNode(pNodeBitmap, pSpread, FALSE))
00775 {
00776
00777 delete pNodeBitmap;
00778 return;
00779 }
00780
00781
00782 Op->DoInvalidateNodeRegion(pNodeBitmap, TRUE, FALSE);
00783
00784
00785 BitmapEffectBase * pEffect;
00786
00787 pEffect=new BitmapEffectSILT;
00788
00789 pEffect->SetParameters();
00790 pEffect->SetSourceImage(pBitmap);
00791 pEffect->UseDestinationBitmap(pNodeBitmap->GetBitmap());
00792
00793 pEffect->Run();
00794
00795 pEffect->UseDestinationBitmap(NULL);
00796
00797 delete(pEffect);
00798 }
00799 }
00800 CurrentNode = NextCurrent;
00801 }
00802
00803 }
00804
00805
00806
00807 return;
00808 }