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
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 #include "camtypes.h"
00116 #include "grndbmp.h"
00117 #include "colcontx.h"
00118
00119 #include "oilbitmap.h"
00120
00121
00122 #include "osrndrgn.h"
00123
00124 #include "palman.h"
00125 #include "progress.h"
00126 #include "GDrawIntf.h"
00127
00128
00129
00130
00131 #include "bmapprev.h"
00132
00133 #define FIXEDBANDSIZE 512
00134
00135 CC_IMPLEMENT_DYNAMIC( GRenderBitmap, GRenderDIB )
00136 #if !defined(EXCLUDE_FROM_RALPH)
00137 CC_IMPLEMENT_DYNAMIC( GRenderOptPalette, GRenderBitmap )
00138 #endif
00139
00140 #define new CAM_DEBUG_NEW
00141
00142 #if !defined(EXCLUDE_FROM_RALPH)
00143
00144 BOOL GRenderOptPalette::DoTwoColourRoundingToPrimary = TRUE;
00145 #endif
00146
00147
00148
00149
00150
00151
00152 GDrawContext *GRenderBitmap::pGreyscaleContext = NULL;
00153
00154 BOOL GRenderOptPalette::DoGDrawConversion = TRUE;
00155 BOOL GRenderOptPalette::UseOldPalette = TRUE;
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 GRenderBitmap::GRenderBitmap(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale,
00177 UINT32 Depth, double dpi, BOOL Printing, UINT32 Dither, LPLOGPALETTE pPalette,
00178 BOOL AutoConvert)
00179 : GRenderDIB( ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00180 {
00181
00182
00183
00184
00185
00186 if (RenderView==NULL)
00187 CurrentColContext = ColourContext::GetGlobalDefault(COLOURMODEL_RGBT);
00188
00189
00190 OverlapBands = FALSE;
00191
00192
00193 RenderBottomToTop = TRUE;
00194
00195
00196 RenderFlags.Printing = Printing;
00197
00198
00199
00200 DitherType = Dither;
00201 uOutputDepth = Depth;
00202
00203 lpOutputInfo = NULL;
00204 lpOutputBits = NULL;
00205
00206 m_dXCentralAdjust = 0;
00207 m_dYCentralAdjust = 0;
00208
00209 pConvPalette = pPalette;
00210
00211 if (AutoConvert && uOutputDepth<32)
00212 {
00213
00214
00215
00216
00217 uBitmapDepth = 32;
00218 }
00219
00220 pPreviousGDrawContext = NULL;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 BOOL GRenderBitmap::DitheringNeeds32bpp(UINT32 Dither)
00238 {
00239 return (Dither != XARADITHER_ORDERED_GREY);
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 BOOL GRenderBitmap::StartRender()
00259 {
00260
00261 const BOOL ok = GRenderDIB::StartRender();
00262 if (!ok)
00263 return FALSE;
00264
00265
00266
00267
00268
00269
00270
00271
00272 pBitmapInfo->bmiHeader.biXPelsPerMeter = (INT32)((PixelsPerInch * 10000 ) / 254);
00273
00274 pBitmapInfo->bmiHeader.biYPelsPerMeter = pBitmapInfo->bmiHeader.biXPelsPerMeter;
00275
00276
00277 return TRUE;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 WinRect GRenderBitmap::CalculateWinRect( Matrix& RenderMatrix, const DocRect& docrect,
00299 const double dpi)
00300 {
00301
00302
00303
00304 return OSRenderRegion::BitmapDocRectToWin( RenderMatrix, docrect, dpi );
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 GMATRIX GRenderBitmap::MakeGavinMatrix(Matrix NewRenderMatrix, DocRect ClipRect, double dPixelsPerInch, BOOL bMasterCapture)
00322 {
00323 GMATRIX gmat;
00324
00325 FIXED16 abcd[4];
00326 NewRenderMatrix.GetComponents( abcd, NULL );
00327
00328
00329
00330 Matrix UnscrolledRender(abcd[0], abcd[1], abcd[2], abcd[3], 0, 0);
00331
00332
00333
00334
00335
00336
00337
00338
00339 const XLONG Mult = (INT32)(dPixelsPerInch*(double)(1 << FX) + 0.5);
00340
00341 gmat.AX = ( (XLONG)abcd[0].GetRawLong() * Mult ) / XLONG(72000);
00342 gmat.AY = ( (XLONG)abcd[1].GetRawLong() * Mult ) / XLONG(72000);
00343 gmat.BX = ( (XLONG)abcd[2].GetRawLong() * Mult ) / XLONG(72000);
00344 gmat.BY = ( (XLONG)abcd[3].GetRawLong() * Mult ) / XLONG(72000);
00345
00346
00347
00348
00349
00350
00351 OSRenderRegion::CalculateGavinOffsetsWinRect(UnscrolledRender, ClipRect, dPixelsPerInch, &gmat, bMasterCapture, &m_dXCentralAdjust, &m_dYCentralAdjust);
00352
00353 return gmat;
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 GRenderBitmap::~GRenderBitmap()
00371 {
00372
00373
00374
00375 if (lpOutputInfo!=NULL || lpOutputBits!=NULL)
00376 {
00377
00378 FreeDIB(lpOutputInfo, lpOutputBits);
00379 lpOutputInfo = NULL;
00380 lpOutputBits = NULL;
00381 }
00382
00383
00384
00385
00386 if (pBitmapInfo!=NULL)
00387 {
00388
00389
00390 FreeOffscreenState();
00391 pBitmapInfo = NULL;
00392 pBits = NULL;
00393 }
00394
00395
00396
00397 if (pPreviousGDrawContext != NULL)
00398 {
00399 if (SetTempDrawContext(pPreviousGDrawContext) != pGreyscaleContext)
00400 {
00401 ERROR3("Not pGreyscaleContext when restoring");
00402 }
00403 pPreviousGDrawContext = NULL;
00404 }
00405 }
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 INT32 GRenderBitmap::GetNumBands()
00425 {
00426
00427 double TruePixelHeight = 72000.0 / PixelsPerInch;
00428
00429
00430
00431
00432
00433 INT32 Height = (INT32)((double)RegionRect.Height() / TruePixelHeight);
00434
00435
00436 INT32 Bands = 0;
00437 while (Height>0)
00438 {
00439 Bands++;
00440 Height -= FIXEDBANDSIZE;
00441 }
00442
00443
00444 return Bands;
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 INT32 GRenderBitmap::GetFullRegionHeight()
00461 {
00462
00463
00464
00465 Matrix Identity;
00466 WinRect Rect = OSRenderRegion::BitmapDocRectToWin( Identity, RegionRect, PixelsPerInch );
00467 return Rect.height;
00468 }
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 void GRenderBitmap::SetOverlapBands(BOOL NewVal)
00485 {
00486 OverlapBands = NewVal;
00487 }
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 BOOL GRenderBitmap::SetRenderBottomToTop(BOOL NewVal)
00504 {
00505 BOOL OldVal = RenderBottomToTop;
00506 RenderBottomToTop = NewVal;
00507 return OldVal;
00508 }
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 BOOL GRenderBitmap::SetFirstBand()
00524 {
00525
00526
00527
00528
00529
00530
00531 ENSURE(GetCaptureDepth()==0 || MasterCaptureIsCurrent(), "Can't set a band while there are any non-master captures running\n");
00532
00533
00534 CanRegionBeMerged = TRUE;
00535
00536
00537 if (!RenderFlags.ValidDevice)
00538 {
00539
00540 if (!InitDevice())
00541 {
00542
00543 TRACE( _T("InitDevice failed in Render Region"));
00544 return FALSE;
00545 }
00546
00547
00548 RenderFlags.ValidDevice = TRUE;
00549 }
00550
00551
00552 double TruePixelHeight = 72000.0 / PixelsPerInch;
00553
00554
00555 INT32 Height = (INT32) ((double)(RegionRect.hi.y - RegionRect.lo.y) / TruePixelHeight);
00556
00557
00558 INT32 MaxScanLines = FIXEDBANDSIZE;
00559
00560
00561 if (MaxScanLines>=Height)
00562 {
00563
00564 IsRegionBanded = FALSE;
00565 IsWaitingForRAM = FALSE;
00566 IsLastBand = TRUE;
00567 return TRUE;
00568 }
00569 else
00570 {
00571
00572 IsRegionBanded = TRUE;
00573 IsWaitingForRAM = FALSE;
00574 IsLastBand = FALSE;
00575 CanRegionBeMerged = FALSE;
00576
00577
00578 MILLIPOINT MaxHeight = (MILLIPOINT)(TruePixelHeight * (double)MaxScanLines);
00579
00580
00581 DocRect NewClipRect = CurrentClipRect;
00582 if (RenderBottomToTop)
00583 {
00584
00585 NewClipRect.hi.y = NewClipRect.lo.y + MaxHeight;
00586
00587
00588 if (NewClipRect.hi.y > CurrentClipRect.hi.y)
00589 NewClipRect.hi.y = CurrentClipRect.hi.y;
00590 }
00591 else
00592 {
00593
00594 NewClipRect.lo.y = NewClipRect.hi.y - MaxHeight;
00595
00596
00597 if (NewClipRect.lo.y < CurrentClipRect.lo.y)
00598 NewClipRect.lo.y = CurrentClipRect.lo.y;
00599 }
00600
00601
00602 SetClipRect(NewClipRect);
00603 return TRUE;
00604 }
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 BOOL GRenderBitmap::GetNextBand()
00621 {
00622
00623
00624 if (pBitmapInfo!=NULL)
00625 {
00626 FreeOffscreenState();
00627 pBitmapInfo = NULL;
00628 pBits = NULL;
00629 }
00630
00631
00632 ENSURE(GetCaptureDepth()==0 || MasterCaptureIsCurrent(), "Can't set a band while there are any non-master captures running\n");
00633
00634
00635 if (!IsBanded())
00636 return FALSE;
00637
00638 if (RenderBottomToTop)
00639 {
00640
00641
00642 if ((CurrentClipRect.hi.y >= RegionRect.hi.y) || (IsLastBand))
00643 return FALSE;
00644 }
00645 else
00646 {
00647
00648
00649 if ((CurrentClipRect.lo.y <= RegionRect.lo.y) || (IsLastBand))
00650 return FALSE;
00651 }
00652
00653
00654 IsPaperRendered = FALSE;
00655 IsInkRenderStarted = FALSE;
00656
00657
00658 INT32 MaxScanLines = FIXEDBANDSIZE;
00659
00660
00661 double TruePixelHeight = 72000.0 / PixelsPerInch;
00662
00663
00664
00665 INT32 Height = 0;
00666 if (RenderBottomToTop)
00667 {
00668
00669 Height = (INT32) ((double)(RegionRect.hi.y - CurrentClipRect.hi.y) / TruePixelHeight);
00670 }
00671 else
00672 {
00673
00674 Height = (INT32) ((double)(CurrentClipRect.lo.y - RegionRect.lo.y ) / TruePixelHeight);
00675 }
00676
00677
00678 IsWaitingForRAM = FALSE;
00679
00680
00681 INT32 ScanLinesToDo = (MaxScanLines < Height) ? MaxScanLines : Height;
00682 if (ScanLinesToDo==Height)
00683 IsLastBand = TRUE;
00684 else
00685 IsLastBand = FALSE;
00686
00687
00688 MILLIPOINT MaxHeight = (MILLIPOINT) (TruePixelHeight * (double)ScanLinesToDo);
00689
00690 DocRect NewClipRect = CurrentClipRect;
00691 if (RenderBottomToTop)
00692 {
00693
00694
00695 NewClipRect.lo.y = CurrentClipRect.hi.y;
00696 NewClipRect.hi.y = NewClipRect.lo.y + MaxHeight;
00697
00698
00699 if (OverlapBands)
00700 NewClipRect.lo.y -= (INT32)(2 * TruePixelHeight);
00701
00702
00703 if ((NewClipRect.hi.y > RegionRect.hi.y) || (IsLastBand))
00704 NewClipRect.hi.y = RegionRect.hi.y;
00705 }
00706 else
00707 {
00708
00709
00710 NewClipRect.hi.y = CurrentClipRect.lo.y;
00711 NewClipRect.lo.y = NewClipRect.hi.y - MaxHeight;
00712
00713
00714 if (OverlapBands)
00715 NewClipRect.hi.y -= (INT32)(2 * TruePixelHeight);
00716
00717
00718 if ((NewClipRect.lo.y < RegionRect.lo.y) || (IsLastBand))
00719 NewClipRect.lo.y = RegionRect.lo.y;
00720 }
00721
00722
00723 if (NewClipRect.Height()==0)
00724 return FALSE;
00725
00726
00727 SetClipRect(NewClipRect);
00728
00729
00730 IsPaperRendered = FALSE;
00731 IsInkRenderStarted = FALSE;
00732 TRACEUSER("Gavin",_T("GRenderBitmap::GetNextBand - RenderFlags.Rendering = FALSE;\n"));
00733 RenderFlags.Rendering = FALSE;
00734
00735
00736 return TRUE;
00737 }
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754 LPBITMAPINFO GRenderBitmap::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE* lplpBits)
00755 {
00756
00757 LPBITMAPINFO bmInfo = NULL;
00758 bmInfo = AllocDIB( abs(Width), abs(Height), Depth, lplpBits, NULL, FALSE);
00759
00760
00761 return bmInfo;
00762 }
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777 void GRenderBitmap::FreeLPBits(LPBITMAPINFO lpBMI, LPBYTE lpB)
00778 {
00779
00780 FreeDIB(lpBMI, lpB, NULL, FALSE);
00781 }
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 BOOL GRenderBitmap::DisplayBits(LPBITMAPINFO lpDisplayBitmapInfo, LPBYTE lpDisplayBits)
00801 {
00802 return TRUE;
00803 }
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 OILBitmap *GRenderBitmap::ExtractBitmap(LPLOGPALETTE pPalette)
00820 {
00821 if (pBitmapInfo && pBits)
00822 {
00823 LPBITMAPINFO lpConvInfo;
00824 LPBYTE lpConvBits;
00825
00826 BOOL DeletePalette = FALSE;
00827
00828 if(!pPalette)
00829 {
00830 pPalette = GetConversionPalette();
00831 if (pPalette && pPalette != pConvPalette)
00832 DeletePalette = TRUE;
00833 }
00834
00835 BOOL ok = DoOutputBitmapConversion(&lpConvInfo, &lpConvBits, pPalette);
00836 ERROR3IF(!ok, "Output conversion failed in GRenderBitmap::ExtractBitmap");
00837 if (!ok)
00838 {
00839 if(DeletePalette)
00840 CCFree(pPalette);
00841 return NULL;
00842 }
00843
00844 CWxBitmap *OILBM = new CWxBitmap( lpConvInfo, lpConvBits );
00845 if (OILBM)
00846 {
00847
00848 RGBQUAD* pOilPalette = OILBM->BMInfo->bmiColors;
00849 PALETTEENTRY* pPaletteEntry = pPalette->palPalEntry;
00850
00851
00852
00853 for (DWORD i=0; i< OILBM->BMInfo->bmiHeader.biClrUsed; i++)
00854 {
00855 pOilPalette[i].rgbBlue = pPaletteEntry[i].peBlue;
00856 pOilPalette[i].rgbGreen = pPaletteEntry[i].peGreen;
00857 pOilPalette[i].rgbRed = pPaletteEntry[i].peRed;
00858 pOilPalette[i].rgbReserved = pPaletteEntry[i].peFlags;
00859 }
00860
00861 if (lpConvBits == pBits)
00862 {
00863
00864
00865
00866
00867 ENSURE(MasterCaptureIsCurrent(), "Extract bitmap whilst rendering offscreen not finished!");
00868
00869
00870 SetBitmapPointers(NULL, NULL);
00871 }
00872
00873 if (lpConvBits == lpOutputBits)
00874 {
00875
00876 lpOutputInfo = NULL;
00877 lpOutputBits = NULL;
00878 }
00879
00880 if(DeletePalette)
00881 CCFree(pPalette);
00882
00883 return OILBM;
00884 }
00885
00886 if(DeletePalette)
00887 CCFree(pPalette);
00888 }
00889
00890 return NULL;
00891 }
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 OILBitmap *GRenderBitmap::ExtractBitmapCopy(LPLOGPALETTE pPalette,
00921 LPBITMAPINFO pMaskInfo, LPBYTE pMaskData,
00922 INT32 MaskColour, BOOL LookForDuplicates)
00923 {
00924 ERROR3IF(MaskColour==-2,"Someone`s using a MaskColour of -2!!! Please Correct!");
00925 BOOL bBrowserPalette = FALSE;
00926
00927 if(!pPalette)
00928 bBrowserPalette = TRUE;
00929
00930 if (pBitmapInfo && pBits)
00931 {
00932 LPBITMAPINFO lpCopyInfo = NULL;
00933 LPBYTE lpCopyBits = NULL;
00934 LPBITMAPINFO lpConvInfo = NULL;
00935 LPBYTE lpConvBits = NULL;
00936
00937 BOOL DeletePalette = FALSE;
00938
00939 if (!pPalette)
00940 {
00941 pPalette = GetConversionPalette();
00942 DeletePalette = (pPalette && pPalette != pConvPalette);
00943 }
00944
00945 if (pPalette && MaskColour >= 0 && MaskColour < pPalette->palNumEntries)
00946 {
00947 pPalette->palPalEntry[MaskColour].peRed = 255;
00948 pPalette->palPalEntry[MaskColour].peGreen = 255;
00949 pPalette->palPalEntry[MaskColour].peBlue = 255;
00950 pPalette->palPalEntry[MaskColour].peFlags = 255;
00951 }
00952
00953 BOOL ok = DoOutputBitmapConversion(&lpConvInfo, &lpConvBits, pPalette);
00954 ERROR3IF(!ok, "Output conversion failed in GRenderBitmap::ExtractBitmap");
00955 if (!ok)
00956 {
00957 if (DeletePalette)
00958 CCFree(pPalette);
00959 return NULL;
00960 }
00961
00962 if (lpConvBits == pBits)
00963 {
00964 BOOL CopyOK = DIBUtil::CopyBitmap(pBitmapInfo, pBits, &lpCopyInfo, &lpCopyBits);
00965
00966 if (!CopyOK)
00967 {
00968 ERROR3("Failed to copy bitmap in ExtractBitmapCopy");
00969 if (DeletePalette)
00970 CCFree(pPalette);
00971 return NULL;
00972 }
00973 }
00974 else
00975 {
00976 lpCopyInfo = lpConvInfo;
00977 lpCopyBits = lpConvBits;
00978 }
00979
00980 if (pMaskInfo && pMaskData && MaskColour>=0)
00981 {
00982
00983 if (!DIBUtil::MakeTransparentBitmap(lpCopyInfo, lpCopyBits, pMaskInfo, pMaskData, MaskColour))
00984 {
00985 ERROR3("Failed to apply mask in GRenderBitmap::ExtractBitmapCopy");
00986 if (DeletePalette)
00987 CCFree(pPalette);
00988 FreeDIB(lpCopyInfo, lpCopyBits);
00989 return NULL;
00990 }
00991 }
00992
00993 CWxBitmap *OILBM = new CWxBitmap( lpCopyInfo, lpCopyBits );
00994 if (OILBM)
00995 {
00996
00997
00998 INT32 width = (INT32)(( OILBM->BMInfo->bmiHeader.biWidth ) * 72000 / 96.0);
00999 INT32 height = (INT32)(( OILBM->BMInfo->bmiHeader.biHeight ) * 72000 / 96.0);
01000 OILBM->SetRecommendedWidth( width );
01001 OILBM->SetRecommendedHeight( height );
01002
01003
01004 RGBQUAD* pOilPalette = OILBM->BMInfo->bmiColors;
01005
01006
01007 if (pPalette != NULL)
01008 {
01009
01010 INT32 ColoursInPal = pPalette->palNumEntries;
01011
01012
01013 if (MaskColour >= 0)
01014 {
01015
01016
01017 if (MaskColour > ColoursInPal)
01018 {
01019
01020
01021 ColoursInPal = MaskColour + 1;
01022 }
01023 else
01024 ColoursInPal++;
01025 }
01026
01027
01028 INT32 MaxColours = OILBM->BMInfo->bmiHeader.biClrUsed;
01029
01030 if (ColoursInPal > MaxColours)
01031 ColoursInPal = MaxColours;
01032
01033
01034
01035 PALETTEENTRY* pPaletteEntry = pPalette->palPalEntry;
01036 for (INT32 i = 0; i < MaxColours; i++)
01037 {
01038 if (i == MaskColour)
01039 {
01040
01041
01042 pOilPalette[i].rgbBlue = 255;
01043 pOilPalette[i].rgbGreen = 255;
01044 pOilPalette[i].rgbRed = 255;
01045 pOilPalette[i].rgbReserved = 255;
01046 }
01047 else if (i > ColoursInPal)
01048 {
01049
01050 pOilPalette[i].rgbBlue = 0;
01051 pOilPalette[i].rgbGreen = 0;
01052 pOilPalette[i].rgbRed = 0;
01053 pOilPalette[i].rgbReserved = 0;
01054 }
01055 else
01056 {
01057 pOilPalette[i].rgbBlue = pPaletteEntry[i].peBlue;
01058 pOilPalette[i].rgbGreen = pPaletteEntry[i].peGreen;
01059 pOilPalette[i].rgbRed = pPaletteEntry[i].peRed;
01060 pOilPalette[i].rgbReserved = 0;
01061 }
01062 }
01063
01064
01065 OILBM->BMInfo->bmiHeader.biClrUsed = ColoursInPal;
01066 }
01067
01068 if (lpCopyBits == pBits)
01069 {
01070
01071 SetBitmapPointers(NULL, NULL);
01072
01073
01074 ENSURE(MasterCaptureIsCurrent(), "Extract bitmap whilst rendering offscreen not finished!");
01075 }
01076
01077 if (lpCopyBits == lpOutputBits)
01078 {
01079
01080 lpOutputInfo = NULL;
01081 lpOutputBits = NULL;
01082 }
01083
01084 if (LookForDuplicates)
01085 {
01086
01087
01088
01089
01090 GlobalBitmapList * pBmpList = GetApplication()->GetGlobalBitmapList();
01091 OILBitmap* pExistingBmp = NULL;
01092 if (pBmpList)
01093 pExistingBmp = pBmpList->FindDuplicateBitmap(OILBM);
01094 if (pExistingBmp)
01095 {
01096 TRACEUSER( "Neville", _T("This bitmap already exists. Re-using existing OILBitmap.\n"));
01097
01098
01099 if (DeletePalette)
01100 CCFree(pPalette);
01101 delete OILBM;
01102 return pExistingBmp;
01103 }
01104 }
01105 if (DeletePalette)
01106 CCFree(pPalette);
01107
01108 return OILBitmap::Attach(OILBM, FALSE);
01109 }
01110
01111 if(DeletePalette)
01112 CCFree(pPalette);
01113 }
01114
01115 return NULL;
01116 }
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129 BOOL GRenderBitmap::GetBitmapData(LPBITMAPINFO* pBmpInfo, LPBYTE* pBmpData, BOOL Convert)
01130 {
01131 ERROR3IF(pBmpInfo == NULL, "NULL info pointer passed to GetBitmapData");
01132 if (pBmpInfo == NULL)
01133 return FALSE;
01134
01135 ERROR3IF(pBmpData == NULL, "NULL data pointer passed to GetBitmapData");
01136 if (pBmpData == NULL)
01137 return FALSE;
01138
01139 if (!Convert)
01140 {
01141 *pBmpInfo = pBitmapInfo;
01142 *pBmpData = pBits;
01143
01144 if(m_bEnableConversion && m_DoCompression)
01145 {
01146 UINT32 Width = pBitmapInfo->bmiHeader.biWidth;
01147 UINT32 Height = pBitmapInfo->bmiHeader.biHeight;
01148 BYTE* lpOutput = *pBmpData;
01149
01150 DIBConvert* Converter = DIBConvert::Create( 32, 32, Width, NULL, 0 );
01151
01152 if(Converter != NULL)
01153 {
01154 Converter->Convert(pBits, lpOutput, Height);
01155 delete Converter;
01156 Converter = NULL;
01157
01158
01159 ForceInitBmpBits = TRUE;
01160
01161 ENSURE(GetMasterCapture()==NULL || MasterCaptureIsCurrent(), "Bitmap converted in-place while captures are running\n");
01162 }
01163 }
01164
01165 return TRUE;
01166 }
01167
01168 LPBITMAPINFO lpConvInfo=NULL;
01169 LPBYTE lpConvBits=NULL;
01170
01171 LPLOGPALETTE pPalette = GetConversionPalette();
01172
01173 BOOL ok = DoOutputBitmapConversion(&lpConvInfo, &lpConvBits, pPalette);
01174 ERROR3IF(!ok, "Output conversion failed in GRenderBitmap::GetBitmapData");
01175
01176 *pBmpInfo = lpConvInfo;
01177 *pBmpData = lpConvBits;
01178
01179 if (pPalette != pConvPalette)
01180 CCFree(pPalette);
01181
01182 return ok;
01183 }
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196 BOOL GRenderBitmap::DoOutputBitmapConversion(LPBITMAPINFO* lpConvInfo, LPBYTE* lpConvBits, LPLOGPALETTE pPalette)
01197 {
01198 #if !defined(EXCLUDE_FROM_RALPH)
01199 ERROR3IF(lpConvInfo == NULL, "NULL info pointer passed to GRenderBitmap::DoOutputBitmapConversion");
01200 if (lpConvInfo == NULL)
01201 return FALSE;
01202
01203 ERROR3IF(lpConvBits == NULL, "NULL data pointer passed to GRenderBitmap::DoOutputBitmapConversion");
01204 if (lpConvBits == NULL)
01205 return FALSE;
01206
01207 if (uOutputDepth == uBitmapDepth)
01208 {
01209
01210 *lpConvInfo = pBitmapInfo;
01211 *lpConvBits = pBits;
01212
01213 if(m_bEnableConversion && m_DoCompression)
01214 {
01215 UINT32 Width = pBitmapInfo->bmiHeader.biWidth;
01216 UINT32 Height = pBitmapInfo->bmiHeader.biHeight;
01217 BYTE* lpOutput = pBits;
01218
01219 DIBConvert* Converter = DIBConvert::Create( 32, 32, Width, NULL, 0 );
01220
01221 if(Converter != NULL)
01222 {
01223 Converter->Convert(pBits, lpOutput, Height);
01224 delete Converter;
01225 Converter = NULL;
01226
01227
01228 ForceInitBmpBits = TRUE;
01229
01230 ENSURE(GetMasterCapture()==NULL || MasterCaptureIsCurrent(), "Bitmap converted in-place while captures are running\n");
01231 }
01232 }
01233
01234 return TRUE;
01235 }
01236
01237
01238 *lpConvInfo = NULL;
01239 *lpConvBits = NULL;
01240
01241
01242 UINT32 Width = pBitmapInfo->bmiHeader.biWidth;
01243 UINT32 Height = pBitmapInfo->bmiHeader.biHeight;
01244
01245
01246 DIBConvert* Converter = DIBConvert::Create( uBitmapDepth, uOutputDepth, Width, pPalette, DitherType );
01247 ERROR3IF(Converter == NULL, "Failed to create DIBConvert object in GRenderBitmap::DoOutputBitmapConversion");
01248 if (Converter == NULL)
01249 return FALSE;
01250
01251 if (lpOutputInfo != NULL || lpOutputBits != NULL)
01252 {
01253
01254 FreeDIB(lpOutputInfo, lpOutputBits);
01255
01256 lpOutputInfo = NULL;
01257 lpOutputBits = NULL;
01258 }
01259
01260
01261 lpOutputInfo = AllocDIB(Width, Height, uOutputDepth, &lpOutputBits);
01262 ERROR3IF(lpOutputInfo == NULL, "Failed to allocate conversion info in GRenderBitmap::DoOutputBitmapConversion");
01263 ERROR3IF(lpOutputBits == NULL, "Failed to allocate conversion data in GRenderBitmap::DoOutputBitmapConversion");
01264 if (lpOutputInfo == NULL || lpOutputBits == NULL)
01265 return FALSE;
01266
01267
01268 BOOL ok = Converter->Convert(pBits, lpOutputBits, Height);
01269 delete Converter;
01270
01271 if (ok)
01272 {
01273 *lpConvInfo = lpOutputInfo;
01274 *lpConvBits = lpOutputBits;
01275 }
01276
01277 return ok;
01278 #else
01279 return FALSE;
01280 #endif
01281 }
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294 LPLOGPALETTE GRenderBitmap::GetConversionPalette()
01295 {
01296 #if !defined(EXCLUDE_FROM_RALPH)
01297 if (uOutputDepth>8)
01298 return NULL;
01299
01300 if (pConvPalette)
01301 return pConvPalette;
01302
01303
01304
01305
01306 LPLOGPALETTE pPalette;
01307 size_t TotalPal;
01308
01309 switch (uOutputDepth)
01310 {
01311 case 8:
01312
01313 TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 );
01314 pPalette = (LPLOGPALETTE)CCMalloc( TotalPal );
01315 if (pPalette != NULL)
01316 {
01317 LPLOGPALETTE pRecPalette = GetErrorDiffPalette();
01318 if (pRecPalette)
01319 {
01320 memcpy(pPalette, pRecPalette, TotalPal);
01321 }
01322 else
01323 {
01324 CCFree(pPalette);
01325 return NULL;
01326 }
01327 }
01328 break;
01329
01330 case 4:
01331 TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 16 );
01332 pPalette = (LPLOGPALETTE)CCMalloc( TotalPal );
01333 if (pPalette != NULL)
01334 {
01335
01336 OutputDIB::Fix16ColourPalette(pPalette);
01337 }
01338 break;
01339
01340 case 1:
01341 TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 2 );
01342 pPalette = (LPLOGPALETTE)CCMalloc( TotalPal );
01343 if (pPalette != NULL)
01344 {
01345
01346 OutputDIB::FixBlackAndWhitePalette(pPalette);
01347 }
01348 break;
01349
01350 default:
01351 ERROR3("Bad colour depth in GRenderBitmap::GetConversionPalette");
01352 pPalette = NULL;
01353 break;
01354 }
01355
01356 return pPalette;
01357 #else
01358 return NULL;
01359 #endif
01360 }
01361
01362
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
01392
01393
01394
01395 void GRenderBitmap::UseGreyscaleContextDangerous(void)
01396 {
01397 TRACEUSER( "Gerry", _T("GRenderBitmap::UseGreyscaleContextDangerous\n"));
01398 ERROR3IF(pPreviousGDrawContext != NULL, "UseGreyscaleContextDangerous called while context in use");
01399 if (pPreviousGDrawContext == NULL)
01400 {
01401 if (pGreyscaleContext == NULL)
01402 {
01403 PORTNOTE("other","GRenderBitmap::UseGreyscaleContextDangerous - removed progress reporting")
01404 #if !defined(EXCLUDE_FROM_XARALX)
01405 Progress::Start();
01406 #endif
01407
01408
01409 pGreyscaleContext = new GDrawAsm;
01410
01411 if (pGreyscaleContext != NULL)
01412 {
01413
01414
01415
01416 DWORD PaletteFlag = 0;
01417 if (WhichDither == 0 || WhichDither == 3)
01418 PaletteFlag = 1;
01419
01420 if (pGreyscaleContext->SelectPalette(PaletteFlag) != NULL)
01421 pGreyscaleContext->InitialiseWithPalette(pConvPalette);
01422 }
01423
01424 #if !defined(EXCLUDE_FROM_XARALX)
01425 Progress::Stop();
01426 #endif
01427 }
01428
01429 if (pGreyscaleContext != NULL)
01430 {
01431 pPreviousGDrawContext = SetTempDrawContext(pGreyscaleContext);
01432 }
01433 }
01434 }
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451 void GRenderBitmap::StopUsingGreyscaleContextDangerous(void)
01452 {
01453 TRACEUSER( "Gerry", _T("GRenderBitmap::StopUsingGreyscaleContextDangerous\n"));
01454 ERROR3IF(pPreviousGDrawContext == NULL, "UseGreyscaleContextDangerous called while context not in use");
01455 if (pPreviousGDrawContext != NULL)
01456 {
01457 if (SetTempDrawContext(pPreviousGDrawContext) != pGreyscaleContext)
01458 {
01459 ERROR3("Not pGreyscaleContext when restoring");
01460 }
01461 pPreviousGDrawContext = NULL;
01462 }
01463 }
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480 void GRenderBitmap::Deinit(void)
01481 {
01482 ERROR3IF(GD != NULL && GD == pGreyscaleContext, "GRenderBitmap greyscale context still in use");
01483
01484 if (pGreyscaleContext != NULL)
01485 {
01486 delete pGreyscaleContext;
01487 pGreyscaleContext = NULL;
01488 }
01489 }
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499 #if !defined(EXCLUDE_FROM_RALPH)
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523 GRenderOptPalette::GRenderOptPalette(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi, BOOL Use8bpp)
01524 : GRenderBitmap( ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
01525 {
01526 ERROR3IF(Depth != 32, "Bad Depth for GRenderOptPalette, must be 32bpp");
01527
01528 UseSpecial8bpp = Use8bpp;
01529
01530 m_pExactPalette = NULL;
01531
01532 if (Depth == 32)
01533 {
01534 if (UseSpecial8bpp)
01535 {
01536 Stats = CCMalloc(DIBUtil::GetOptimal8bppPaletteWorkspaceSize() * 4);
01537 if (Stats)
01538 DIBUtil::Optimal8bppPaletteInitialise((INT32*)Stats);
01539 }
01540 else
01541 {
01542 Stats = CCMalloc(DIBUtil::GetOptimalPaletteWorkspaceSize());
01543 if (Stats)
01544 DIBUtil::OptimalPaletteInitialise(Stats);
01545
01546 }
01547 if( !UseOldPalette )
01548 {
01549 const size_t TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 );
01550 m_pExactPalette = (LPLOGPALETTE)CCMalloc( TotalPal );
01551 if( m_pExactPalette )
01552 DIBUtil::ExactPaletteInitialise( m_pExactPalette );
01553 }
01554 }
01555
01556 m_bTooManyColours = FALSE;
01557
01558
01559 DoGDrawConversion = TRUE;
01560 }
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576 GRenderOptPalette::~GRenderOptPalette()
01577 {
01578 if (Stats)
01579 CCFree(Stats);
01580
01581 if (m_pExactPalette)
01582 CCFree(m_pExactPalette) ;
01583 }
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600 BOOL GRenderOptPalette::GetNextBand()
01601 {
01602
01603
01604 if (Stats)
01605 {
01606 INT32 Width = pBitmapInfo->bmiHeader.biWidth;
01607 INT32 Height = pBitmapInfo->bmiHeader.biHeight;
01608
01609 INT32 BmpSize = Width * Height;
01610
01611
01612
01613
01614 if( !m_bTooManyColours && !UseOldPalette )
01615 {
01616 BOOL bResult = DIBUtil::CalculateNumberOfColoursInBitmap( m_pExactPalette, ( RGBQUAD* )pBits, BmpSize );
01617 if( !bResult )
01618 {
01619 m_bTooManyColours = TRUE;
01620 DoGDrawConversion = FALSE;
01621 }
01622 }
01623
01624 BOOL ok;
01625 if (UseSpecial8bpp)
01626 ok = DIBUtil::GenOptimal8bppPaletteStats( (INT32*)Stats, (RGBQUAD*)pBits, BmpSize );
01627 else
01628 ok = DIBUtil::GenOptimalPaletteStats( Stats, (RGBQUAD*)pBits, BmpSize );
01629
01630 ERROR3IF(!ok, "GenOptimalPaletteStats failed");
01631 }
01632
01633 return GRenderBitmap::GetNextBand();
01634 }
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666 LPLOGPALETTE GRenderOptPalette::GetOptimisedPalette(UINT32 PaletteSize, UINT32 NumColours, UINT32 ReservedColours, BOOL SnapToBrowserPalette)
01667 {
01668 ERROR3IF(!(PaletteSize==2 || PaletteSize==16 || PaletteSize==256), "Bad palette size passed to GRenderOptPalette::GetOptimisedPalette");
01669 ERROR3IF(ReservedColours > PaletteSize, "Too many colours reserved in GRenderOptPalette::GetOptimisedPalette");
01670
01671 LPLOGPALETTE pPalette = NULL;
01672
01673 if (Stats)
01674 {
01675 const size_t TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * PaletteSize );
01676 pPalette = (LPLOGPALETTE)CCMalloc( TotalPal );
01677 if (pPalette)
01678 {
01679
01680 memset(pPalette, 0, TotalPal);
01681
01682 pPalette->palVersion = 0x300;
01683 pPalette->palNumEntries = PaletteSize;
01684
01685 if (NumColours > PaletteSize)
01686 NumColours = PaletteSize;
01687
01688 if (ReservedColours < NumColours)
01689 {
01690 BOOL ok = TRUE;
01691
01692
01693
01694 PORTNOTE("BmpPrevDlg", "Rampant use of BmapPrevDlg removed (please don't re-instate directly - the value should be a param or member of this class)")
01695 #ifndef EXCLUDE_FROM_XARALX
01696 if( !m_bTooManyColours && m_pExactPalette && !UseOldPalette
01697 && m_pExactPalette->palNumEntries < BmapPrevDlg::m_NumOfColoursUserAskedFor )
01698 #else
01699 if( !m_bTooManyColours && m_pExactPalette && !UseOldPalette )
01700 #endif
01701 {
01702
01703 INT32 blackEntry = 10;
01704 pPalette->palNumEntries = m_pExactPalette->palNumEntries;
01705 INT32 i = 0;
01706 for( i = 0; i < m_pExactPalette->palNumEntries; i++ )
01707 {
01708 pPalette->palPalEntry[i].peRed = m_pExactPalette->palPalEntry[i].peRed;
01709 pPalette->palPalEntry[i].peGreen = m_pExactPalette->palPalEntry[i].peGreen;
01710 pPalette->palPalEntry[i].peBlue = m_pExactPalette->palPalEntry[i].peBlue;
01711
01712 if (pPalette->palPalEntry[i].peRed == 255 &&
01713 pPalette->palPalEntry[i].peGreen == 255 &&
01714 pPalette->palPalEntry[i].peBlue == 255 )
01715 blackEntry = i;
01716 }
01717 if (blackEntry != 10 && ReservedColours == 1)
01718 {
01719
01720 pPalette->palPalEntry[blackEntry].peRed = pPalette->palPalEntry[10].peRed;
01721 pPalette->palPalEntry[blackEntry].peGreen = pPalette->palPalEntry[10].peGreen;
01722 pPalette->palPalEntry[blackEntry].peBlue = pPalette->palPalEntry[10].peBlue;
01723
01724 pPalette->palPalEntry[10].peRed = 255;
01725 pPalette->palPalEntry[10].peGreen = 255;
01726 pPalette->palPalEntry[10].peBlue = 255;
01727 }
01728 for( ; i<0x100 ; i++ )
01729 {
01730 pPalette->palPalEntry[i].peRed =
01731 pPalette->palPalEntry[i].peGreen =
01732 pPalette->palPalEntry[i].peBlue = 0 ;
01733 }
01734
01735
01736 PORTNOTE("BmpPrevDlg", "Use of BmapPrevDlg removed")
01737 #ifndef EXCLUDE_FROM_XARALX
01738 BmapPrevDlg::m_bUseExistingPalette = FALSE;
01739 #endif
01740 }
01741 else if (UseSpecial8bpp)
01742 {
01743 if (PaletteSize != 256)
01744 {
01745 ERROR3("Palette size is wrong for an 8bpp bitmap");
01746 CCFree( pPalette );
01747 return NULL;
01748 }
01749
01750
01751 if (NumColours < 20)
01752 NumColours = 20;
01753
01754
01755
01756
01757 NumColours -= 4;
01758
01759
01760 if (NumColours > 252)
01761 NumColours = 252;
01762
01763
01764 NumColours -= ReservedColours;
01765
01766 ok = DIBUtil::GenOptimal8bppPalette((INT32*) Stats, pPalette, NumColours);
01767 }
01768 else
01769 {
01770
01771 NumColours -= ReservedColours;
01772
01773 ok = DIBUtil::GenOptimalPalette( Stats, pPalette, (NumColours==1) ? 2 : NumColours );
01774 }
01775
01776 if( m_pExactPalette )
01777 {
01778
01779 CCFree( m_pExactPalette );
01780 m_pExactPalette = NULL;
01781 }
01782
01783
01784 if (ok && SnapToBrowserPalette)
01785 {
01786 PaletteManager::SnapToBrowserPalette(pPalette);
01787 }
01788
01789 if (ok)
01790 {
01791
01792 switch (PaletteSize)
01793 {
01794 INT32 index;
01795
01796 case 2:
01797 if (NumColours == 1)
01798 {
01799
01800 if (pPalette->palPalEntry[1].peRed == 0xFF &&
01801 pPalette->palPalEntry[1].peGreen == 0xFF &&
01802 pPalette->palPalEntry[1].peBlue == 0xFF)
01803 {
01804
01805 pPalette->palPalEntry[1] = pPalette->palPalEntry[0];
01806 pPalette->palPalEntry[1].peFlags = 0;
01807
01808
01809 pPalette->palPalEntry[0].peRed = 255;
01810 pPalette->palPalEntry[0].peGreen = 255;
01811 pPalette->palPalEntry[0].peBlue = 255;
01812 pPalette->palPalEntry[0].peFlags = 255;
01813
01814 }
01815 else if (pPalette->palPalEntry[0].peRed == 0xFF &&
01816 pPalette->palPalEntry[0].peGreen == 0xFF &&
01817 pPalette->palPalEntry[0].peBlue == 0xFF)
01818 {
01819
01820 pPalette->palPalEntry[0].peFlags = 255;
01821
01822 }
01823 else
01824 {
01825
01826 pPalette->palPalEntry[0].peRed = 255;
01827 pPalette->palPalEntry[0].peGreen = 255;
01828 pPalette->palPalEntry[0].peBlue = 255;
01829 pPalette->palPalEntry[0].peFlags = 255;
01830
01831 }
01832
01833 pPalette->palNumEntries = 2;
01834 }
01835 else
01836 pPalette->palNumEntries += ReservedColours;
01837 break;
01838
01839 case 16:
01840
01841 for (index = NumColours - 1; index >= 0; index--)
01842 {
01843 pPalette->palPalEntry[index + ReservedColours] = pPalette->palPalEntry[index];
01844 }
01845
01846
01847 for (index = 0; index < INT32(ReservedColours); index++)
01848 {
01849 pPalette->palPalEntry[index].peRed = 255;
01850 pPalette->palPalEntry[index].peGreen = 255;
01851 pPalette->palPalEntry[index].peBlue = 255;
01852 pPalette->palPalEntry[index].peFlags = 255;
01853
01854 }
01855
01856 pPalette->palNumEntries += ReservedColours;
01857 break;
01858
01859 case 256:
01860 #ifdef _BATCHING
01861 {
01862 for (UINT32 index = 0;index < NumColours;index++)
01863 {
01864 BYTE R = pPalette->palPalEntry[index].peRed;
01865 BYTE G = pPalette->palPalEntry[index].peGreen;
01866 BYTE B = pPalette->palPalEntry[index].peBlue;
01867 if (R == 254 && G == 254 && B == 254)
01868 {
01869 pPalette->palPalEntry[index].peRed = 255;
01870 pPalette->palPalEntry[index].peGreen = 255;
01871 pPalette->palPalEntry[index].peBlue = 255;
01872 }
01873 }
01874 }
01875 #endif
01876
01877 if (UseSpecial8bpp && !( !m_bTooManyColours && !UseOldPalette ) )
01878 {
01879 LPLOGPALETTE pWinPalette;
01880
01881
01882 UINT32 CurStart = 16;
01883 UINT32 NewStart = 10 + ReservedColours;
01884
01885 if (CurStart < NumColours)
01886 {
01887 BOOL ColoursMoved = FALSE;
01888
01889 UINT32 NumColsToMove = NumColours - CurStart;
01890 ERROR3IF((NumColsToMove+CurStart) > 256,"No room for system colours");
01891 ERROR3IF((NumColsToMove+NewStart) > 256,"No room for system colours");
01892
01893 if (NewStart < CurStart)
01894 {
01895
01896 for (index = 0; index < INT32(NumColsToMove); index++)
01897 pPalette->palPalEntry[index + NewStart] = pPalette->palPalEntry[index + CurStart];
01898
01899
01900 for (index = NumColsToMove+NewStart;index < 246;index++)
01901 {
01902 pPalette->palPalEntry[index].peRed = 0;
01903 pPalette->palPalEntry[index].peGreen = 0;
01904 pPalette->palPalEntry[index].peBlue = 0;
01905 }
01906
01907 ColoursMoved = TRUE;
01908 }
01909
01910 ERROR3IF(!ColoursMoved,"Rewrite code to accomodate system colours");
01911 }
01912
01913 ERROR3IF(CurStart > NumColours,"Not enough room for system colours");
01914
01915
01916
01917 pWinPalette = GetErrorDiffPalette();
01918
01919 for (index = 0; index < 10; index++)
01920 {
01921 pPalette->palPalEntry[index] = pWinPalette->palPalEntry[index];
01922 }
01923
01924 for (index = 246; index < 256; index++)
01925 {
01926 pPalette->palPalEntry[index] = pWinPalette->palPalEntry[index];
01927 }
01928
01929
01930 for (index = 10; index < INT32(10 + ReservedColours); index++)
01931 {
01932 pPalette->palPalEntry[index].peRed = 255;
01933 pPalette->palPalEntry[index].peGreen = 255;
01934 pPalette->palPalEntry[index].peBlue = 255;
01935 pPalette->palPalEntry[index].peFlags = 255;
01936
01937 }
01938 }
01939 else
01940 {
01941
01942
01943
01944
01945
01946 if (ReservedColours == 1)
01947 {
01948 for (index = 255;index > 10;index--)
01949 pPalette->palPalEntry[index] = pPalette->palPalEntry[index-1];
01950
01951 pPalette->palPalEntry[10].peRed = 255;
01952 pPalette->palPalEntry[10].peGreen = 255;
01953 pPalette->palPalEntry[10].peBlue = 255;
01954 pPalette->palPalEntry[10].peFlags = 255;
01955 }
01956
01957 ERROR3IF(ReservedColours > 1,"This code won't work with more than one reserved colour");
01958
01959
01960
01961
01962
01963
01964
01965
01966 }
01967 break;
01968 default:
01969 ERROR3("Bad palette size in GRenderOptPalette::GetOptimisedPalette");
01970 }
01971 }
01972 else
01973 {
01974 ERROR3("Failed to generate optimised palette");
01975 CCFree( pPalette );
01976 pPalette = NULL;
01977 }
01978 }
01979 }
01980
01981
01982 if (UseSpecial8bpp)
01983 DIBUtil::Optimal8bppPaletteInitialise((INT32*)Stats);
01984 else
01985 DIBUtil::OptimalPaletteInitialise(Stats);
01986 }
01987
01988 return pPalette;
01989 }
01990 #endif