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 #include "camtypes.h"
00101
00102 #include "grnddib.h"
00103
00104 #include "tunemem.h"
00105
00106 #include "osrndrgn.h"
00107 #include "colormgr.h"
00108 #include "colplate.h"
00109
00110 CC_IMPLEMENT_DYNAMIC( GRenderDIB, GRenderRegion )
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 GRenderDIB::GRenderDIB(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00130 : GRenderRegion( ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00131 {
00132 m_test = 1;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 LPBITMAPINFO GRenderDIB::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE*lplpBits)
00152 {
00153
00154 LPBITMAPINFO bmInfo = NULL;
00155
00156
00157
00158 if(IsWrapped)
00159 bmInfo = AllocDIB( Width, Height, Depth, lplpBits, NULL, FALSE);
00160 else
00161 bmInfo = AllocDIB( Width, Height, Depth, lplpBits, NULL, TRUE);
00162
00163
00164 return bmInfo;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 void GRenderDIB::FreeLPBits( LPBITMAPINFO lpBMI, LPBYTE lpB )
00183 {
00184
00185 FreeDIB(lpBMI, lpB, NULL, TRUE);
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 LPBYTE GRenderDIB::ResizeBits( LPBYTE lpBits, INT32 NewSize)
00203 {
00204
00205 TunedMemory* pTuned = GetTunedMemManager();
00206 if (pTuned == NULL)
00207 return NULL;
00208
00209 return (LPBYTE)pTuned->LimitedCCRealloc(lpBits, NewSize);
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 GRenderDIB::~GRenderDIB()
00227 {
00228 if (LocalBitmap)
00229 {
00230 FreeOffscreenState();
00231 pBitmapInfo = NULL;
00232 pBits = NULL;
00233 }
00234
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 BOOL GRenderDIB::DisplayBits(LPBITMAPINFO lpDisplayBitmapInfo, LPBYTE lpDisplayBits)
00252 {
00253 LPBITMAPINFO lpLocalInfo = pBitmapInfo;
00254 LPBYTE lpLocalBits = pBits;
00255
00256 if (lpDisplayBitmapInfo && lpDisplayBits)
00257 {
00258 lpLocalInfo = lpDisplayBitmapInfo;
00259 lpLocalBits = lpDisplayBits;
00260 }
00261
00262 if (lpLocalInfo && lpLocalBits && RenderDC)
00263 {
00264
00265
00266
00267
00268
00269 PORTNOTE("other","GRenderDIB::DisplayBits - removed separation code")
00270 #ifndef EXCLUDE_FROM_XARALX
00271 ColourPlate* pPlate = CurrentColContext->GetColourPlate();
00272 if (pPlate && !pPlate->IsDisabled())
00273 {
00274 ColourPlateType Type = pPlate->GetType();
00275 if (Type != COLOURPLATE_COMPOSITE &&
00276 Type != COLOURPLATE_SPOT &&
00277 Type != COLOURPLATE_KEY &&
00278 Type != COLOURPLATE_NONE &&
00279 !(pPlate->IsMonochrome()))
00280 {
00281 if (BitmapDepth == 32)
00282 {
00283
00284
00285 RGBQUAD Lookup[256];
00286 DocColour temp;
00287 PColourRGBT Converted;
00288 DWORD* pLookup = (DWORD*)Lookup;
00289
00290 XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
00291 if (lpCMSMan != NULL)
00292 {
00293 ColourRGBT Def;
00294
00295 for (DWORD i = 0; i < 256; i++)
00296 {
00297 switch (Type)
00298 {
00299 case COLOURPLATE_CYAN:
00300 Def.Blue = 1;
00301 Def.Green = 1;
00302 Def.Red = (i / 255.0);
00303 Def.Transparent = 0;
00304 break;
00305 case COLOURPLATE_MAGENTA:
00306 Def.Blue = 1;
00307 Def.Green = (i / 255.0);
00308 Def.Red = 1;
00309 Def.Transparent = 0;
00310 break;
00311 case COLOURPLATE_YELLOW:
00312 Def.Blue = (i / 255.0);
00313 Def.Green = 1;
00314 Def.Red = 1;
00315 Def.Transparent = 0;
00316 break;
00317 }
00318 lpCMSMan->ConvertColourForPaperView(&Def);
00319 Lookup[i].rgbRed = Def.Red.MakeDouble() * 0xFF;
00320 Lookup[i].rgbGreen = Def.Green.MakeDouble() * 0xFF;
00321 Lookup[i].rgbBlue = Def.Blue.MakeDouble() * 0xFF;
00322 Lookup[i].rgbReserved = 0;
00323 }
00324 }
00325
00326 DWORD PixMask = 0;
00327 INT32 ByteOffset = 0;
00328 switch (Type)
00329 {
00330 case COLOURPLATE_CYAN:
00331 PixMask = 0x00FFFF;
00332 ByteOffset = 2;
00333 break;
00334 case COLOURPLATE_MAGENTA:
00335 PixMask = 0xFF00FF;
00336 ByteOffset = 1;
00337 break;
00338 case COLOURPLATE_YELLOW:
00339 PixMask = 0xFFFF00;
00340 ByteOffset = 0;
00341 break;
00342 }
00343 INT32 Width = lpLocalInfo->bmiHeader.biWidth;
00344 INT32 Height = lpLocalInfo->bmiHeader.biHeight;
00345 INT32 NumPixels = Width * Height;
00346 DWORD* pPixel = (DWORD*)lpLocalBits;
00347 INT32 Pix;
00348 for (Pix = 0; Pix < NumPixels; Pix++)
00349 {
00350 if ((*pPixel & PixMask) == PixMask)
00351 {
00352 BYTE Val = *(((BYTE*)pPixel) + ByteOffset);
00353 *pPixel = pLookup[Val];
00354 }
00355 pPixel++;
00356 }
00357 }
00358 }
00359 }
00360 #endif
00361
00362 LPBITMAPINFO lpStoredInfo = pBitmapInfo;
00363 LPBYTE lpStoredBits = pBits;
00364 pBitmapInfo = lpLocalInfo;
00365 pBits = lpLocalBits;
00366
00367 if ( uBitmapDepth == (UINT32)ScreenDepth )
00368 Display1to1Bitmap();
00369
00370 PORTNOTE("other","GRenderDIB::DisplayBits - removed BitmapDepth tests")
00371 #ifdef EXCLUDE_FROM_XARALX
00372 else
00373 DisplayLtoHBitmap();
00374
00375 #else
00376 else if ( BitmapDepth < ScreenDepth )
00377 DisplayLtoHBitmap();
00378
00379 else if ( (ScreenDepth==8 ) || (ScreenDepth==4) )
00380 DisplayHto8Bitmap();
00381
00382 else
00383 DisplayLtoHBitmap();
00384
00385 #endif
00386 pBitmapInfo = lpStoredInfo;
00387 pBits = lpStoredBits;
00388 }
00389 return TRUE;
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 BOOL GRenderDIB::SetFirstBand()
00410 {
00411
00412 if (IsBanded() || pBitmapInfo!=NULL)
00413 return TRUE;
00414
00415
00416 ENSURE(GetCaptureDepth()==0 || MasterCaptureIsCurrent(), "Can't set a band while there are any non-master captures running\n");
00417
00418
00419 CanRegionBeMerged = TRUE;
00420
00421
00422 if (!RenderFlags.ValidDevice)
00423 {
00424
00425 if (!InitDevice())
00426 {
00427
00428 TRACE( _T("InitDevice failed in Render Region"));
00429 return FALSE;
00430 }
00431
00432
00433 RenderFlags.ValidDevice = TRUE;
00434 }
00435
00436
00437 TunedMemory* pTunedMem = GetTunedMemManager();
00438 if (pTunedMem==NULL)
00439 return FALSE;
00440
00441
00442 if (pTunedMem->IsMemSizeInfinite())
00443 {
00444
00445 IsRegionBanded = FALSE;
00446 IsWaitingForRAM = FALSE;
00447 IsLastBand = TRUE;
00448 return TRUE;
00449 }
00450
00451
00452 size_t AvailableRAM = pTunedMem->GetAvailableTunedMem();
00453
00454
00455 INT32 ScanLineSize = DIBUtil::ScanlineSize(WRect.width, uBitmapDepth);
00456 if (ScanLineSize==0)
00457 return FALSE;
00458
00459
00460 INT32 MaxScanLines = INT32(AvailableRAM / ScanLineSize);
00461 INT32 Height = WRect.height;
00462
00463
00464 if (MaxScanLines<16)
00465 {
00466
00467 IsWaitingForRAM = TRUE;
00468 return TRUE;
00469 }
00470
00471
00472 if (MaxScanLines>=Height)
00473 {
00474
00475 IsRegionBanded = FALSE;
00476 IsWaitingForRAM = FALSE;
00477 IsLastBand = TRUE;
00478 return TRUE;
00479 }
00480 else
00481 {
00482
00483 IsRegionBanded = TRUE;
00484 IsWaitingForRAM = FALSE;
00485 IsLastBand = FALSE;
00486 CanRegionBeMerged = FALSE;
00487
00488
00489 double TruePixelHeight = 72000.0 / PixelsPerInch;
00490 TruePixelHeight = TruePixelHeight / ScaleFactor.MakeDouble();
00491 MILLIPOINT MaxHeight = (MILLIPOINT)(TruePixelHeight * (double)MaxScanLines);
00492
00493
00494 DocRect NewClipRect = CurrentClipRect;
00495 NewClipRect.hi.y = NewClipRect.lo.y + MaxHeight;
00496
00497
00498 if (NewClipRect.hi.y>CurrentClipRect.hi.y)
00499 NewClipRect.hi.y = CurrentClipRect.hi.y;
00500
00501
00502 SetClipRect(NewClipRect);
00503 return TRUE;
00504 }
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 BOOL GRenderDIB::GetNextBand()
00523 {
00524
00525 if (!IsBanded())
00526 return FALSE;
00527
00528
00529 ENSURE(GetCaptureDepth()==0 || MasterCaptureIsCurrent(), "Can't set a band while there are any non-master captures running\n");
00530
00531
00532
00533
00534 ERROR3IF(!MasterCaptureIsCurrent(),"GetNextBand called before previous band finished!");
00535
00536
00537 FreeOffscreenState();
00538 pBitmapInfo = NULL;
00539 pBits = NULL;
00540
00541
00542 if ((CurrentClipRect.hi.y>=RegionRect.hi.y) || (IsLastBand))
00543 return FALSE;
00544
00545
00546
00547 TunedMemory* pTunedMem = GetTunedMemManager();
00548
00549
00550 IsPaperRendered = FALSE;
00551 IsInkRenderStarted = FALSE;
00552
00553
00554 size_t AvailableRAM = pTunedMem->GetAvailableTunedMem();
00555
00556
00557 INT32 ScanLineSize = DIBUtil::ScanlineSize(WRect.width, uBitmapDepth);
00558 if (ScanLineSize==0)
00559 return FALSE;
00560
00561
00562 INT32 MaxScanLines = INT32(AvailableRAM / ScanLineSize);
00563
00564
00565 double TruePixelHeight = 72000.0 / PixelsPerInch;
00566 TruePixelHeight = TruePixelHeight / ScaleFactor.MakeDouble();
00567 INT32 Height = (INT32) ((double)(RegionRect.hi.y - CurrentClipRect.hi.y) / TruePixelHeight);
00568
00569
00570 IsWaitingForRAM = FALSE;
00571 if ((Height>=16) && (MaxScanLines<16))
00572 {
00573
00574 IsWaitingForRAM = TRUE;
00575 return TRUE;
00576 }
00577
00578
00579 INT32 ScanLinesToDo = (MaxScanLines<Height) ? MaxScanLines : Height;
00580 if (ScanLinesToDo==Height)
00581 IsLastBand = TRUE;
00582 else
00583 IsLastBand = FALSE;
00584
00585
00586 MILLIPOINT MaxHeight = (MILLIPOINT) (TruePixelHeight * (double)ScanLinesToDo);
00587
00588
00589 DocRect NewClipRect = CurrentClipRect;
00590 NewClipRect.lo.y = CurrentClipRect.hi.y;
00591 NewClipRect.hi.y = NewClipRect.lo.y + MaxHeight;
00592
00593
00594 if ((NewClipRect.hi.y>RegionRect.hi.y) || (IsLastBand))
00595 NewClipRect.hi.y = RegionRect.hi.y;
00596
00597
00598 if (NewClipRect.Height()==0)
00599 return FALSE;
00600
00601
00602 SetClipRect(NewClipRect);
00603
00604
00605 IsPaperRendered = FALSE;
00606 IsInkRenderStarted = FALSE;
00607 TRACEUSER("Gavin",_T("GRenderDIB::GetNextBand - RenderFlags.Rendering = FALSE;\n"));
00608 RenderFlags.Rendering = FALSE;
00609
00610
00611 return TRUE;
00612 }
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 void GRenderDIB::ResizeRegion(DocRect &NewClipRect)
00628 {
00629 DocRect NewRegionRect = NewClipRect;
00630
00631 BOOL HaveABitmap = TRUE;
00632
00633 if (IsRegionBanded)
00634 {
00635
00636
00637 if (CurrentClipRect.IsIntersectedWith(NewRegionRect))
00638 {
00639
00640 NewClipRect = CurrentClipRect.Intersection(NewRegionRect);
00641 }
00642 else
00643 {
00644
00645 if (NewRegionRect.lo.y >= CurrentClipRect.hi.y)
00646 {
00647
00648
00649 ResetRegion(NewRegionRect);
00650 return;
00651 }
00652 else
00653 {
00654
00655
00656
00657
00658
00659
00660 NewClipRect = NewRegionRect;
00661 NewClipRect.lo.y = NewClipRect.hi.y;
00662
00663 ResetRegion(NewClipRect);
00664 return;
00665 }
00666 }
00667
00668 if (IsWaitingForRAM)
00669 {
00670
00671
00672 HaveABitmap = FALSE;
00673 }
00674 }
00675
00676 if (!MasterCaptureIsCurrent())
00677 {
00678
00679 ResetRegion(NewRegionRect);
00680 return;
00681 }
00682
00683
00684 Matrix ViewMatrix = RenderView->ConstructRenderingMatrix(RenderSpread);
00685
00686
00687 wxRect NRect = OSRenderRegion::DocRectToWin( ViewMatrix, NewClipRect, PixelsPerInch );
00688 const INT32 NewWidth = NRect.width;
00689 const INT32 NewHeight = NRect.height;
00690
00691 if (HaveABitmap)
00692 {
00693 if (uBitmapDepth < 8)
00694 {
00695
00696
00697
00698 ResetRegion(NewClipRect);
00699 return;
00700 }
00701
00702
00703 wxRect ORect = OSRenderRegion::DocRectToWin( ViewMatrix, CurrentClipRect, PixelsPerInch );
00704
00705 const INT32 OldWidth = ORect.width;
00706 const INT32 OldHeight = ORect.height;
00707
00708
00709
00710 if (pBits!=NULL && pBitmapInfo!=NULL &&
00711 (NewWidth!=OldWidth || NewHeight!=OldHeight))
00712 {
00713
00714
00715
00716 UINT32 BaseX = NRect.x> ORect.x ? OldWidth - NewWidth : 0;
00717 UINT32 BaseY = NRect.y> ORect.y ? OldHeight - NewHeight : 0;
00718
00719
00720 BaseY=OldHeight-NewHeight-BaseY;
00721
00722
00723
00724 if (DIBUtil::MakeBitmapSmaller(OldWidth, OldHeight, BaseX, BaseY,
00725 NewWidth, NewHeight, uBitmapDepth, pBits))
00726 {
00727
00728 INT32 NewBitmapSize =
00729 DIBUtil::ScanlineSize(NewWidth, uBitmapDepth) * NewHeight;
00730
00731 pBitmapInfo->bmiHeader.biWidth = NewWidth;
00732 pBitmapInfo->bmiHeader.biHeight = NewHeight;
00733 pBitmapInfo->bmiHeader.biSizeImage = NewBitmapSize;
00734
00735
00736
00737 INT32 size = NewBitmapSize;
00738
00739 #define DIB_DEBUG 0
00740
00741 #if DIB_DEBUG
00742 const INT32 dbsize = DIBUtil::ScanlineSize( NewWidth, uBitmapDepth ) * DIB_DEBUG*2;
00743 if (dbsize<16)
00744 dbsize = 16;
00745 #else
00746 const INT32 dbsize = 0;
00747 #endif
00748
00749 if (size==0)
00750 size = 4;
00751
00752
00753 INT32 NewSize = size + dbsize + EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize(NewWidth, uBitmapDepth);
00754
00755
00756 pBits = ResizeBits(pBits, NewSize);
00757
00758
00759 if (pBits == NULL)
00760 {
00761 ResetRegion(NewRegionRect);
00762 return;
00763 }
00764
00765
00766 GetDrawContext()->ClipRectangle( (LPRECT)&NewClipRect );
00767 }
00768 else
00769 {
00770
00771 ResetRegion(NewRegionRect);
00772 }
00773 }
00774 }
00775
00776
00777 WRect = NRect;
00778
00779
00780 CurrentClipRect = NewClipRect;
00781 RegionRect = NewRegionRect;
00782
00783
00784 Capture* pMasterCapture = GetMasterCapture();
00785 pMasterCapture->CaptureRect = NewClipRect;
00786 pMasterCapture->CaptureMatrix = ViewMatrix;
00787 pMasterCapture->lpBitmapInfo = pBitmapInfo;
00788 pMasterCapture->lpBits = pBits;
00789
00790 GMATRIX gmat = MakeGavinMatrix(RenderMatrix, CurrentClipRect, pMasterCapture->dPixelsPerInch, TRUE);
00791 SetGavinMatrix(&gmat);
00792
00793
00794
00795 RECT bbox;
00796 bbox.left = 0;
00797 bbox.right = NewWidth;
00798 bbox.top = 0;
00799 bbox.bottom = NewHeight;
00800 BOOL ok = GetDrawContext()->SetChangedBBox(&bbox);
00801 ERROR2IF(!ok, (void)0, "GDraw_SetChangedBBox failed");
00802
00803 }