grnddib.cpp

Go to the documentation of this file.
00001 // $Id: grnddib.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 
00100 #include "camtypes.h"
00101 //#include "dibutil.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00102 #include "grnddib.h"
00103 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 #include "tunemem.h"
00105 //#include "view.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 #include "osrndrgn.h"
00107 #include "colormgr.h"
00108 #include "colplate.h"
00109 
00110 CC_IMPLEMENT_DYNAMIC( GRenderDIB, GRenderRegion )
00111 
00112 /********************************************************************************************
00113 
00114 >   GRenderDIB::GRenderDIB(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00115 
00116     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00117     Created:    2/6/94
00118     Inputs:     -
00119     Outputs:    -
00120     Returns:    -
00121     Purpose:    GRenderDIB constructor. Doesn't do anything actually, just calls base class.
00122                 INT32 dpi changed to double dpi (12/12/95) to improve the range of values allowed
00123                 at the < 1000dpi settings that we will be using.
00124     Errors:     -
00125     SeeAlso:    GRenderRegion::GRenderRegion
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 >   LPBITMAPINFO GRenderDIB::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE*lplpBits)
00139 
00140     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00141     Created:    2/6/94
00142     Inputs:     Bitmap characteristics.
00143     Outputs:    *lplpBits is made to point to the bytes of the bitmap.
00144     Returns:    The bitmap header, or NULL if not enough memory.
00145     Purpose:    Allocates a bitmap header and the bitmap bytes.
00146     Errors:     -
00147     SeeAlso:    GRenderDIB::FreeLPBits
00148 
00149 ********************************************************************************************/
00150 
00151 LPBITMAPINFO GRenderDIB::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE*lplpBits)
00152 {
00153     // Get a DIB out of the limited heap
00154     LPBITMAPINFO bmInfo = NULL;
00155 
00156     // Wrapped render regions are not used in the normal process of rendering to screen
00157     // So don't use limited mem
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     // return it.
00164     return bmInfo;
00165 }
00166 
00167 /********************************************************************************************
00168 
00169 >   void GRenderDIB::FreeLPBits( LPBITMAPINFO lpBMI, LPBYTE lpB )
00170 
00171     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00172     Created:    2/6/94
00173     Inputs:     Bitmap characteristics.
00174     Outputs:    -
00175     Returns:    -
00176     Purpose:    Frees up a bitmap allocated with GetLPBits.
00177     Errors:     -
00178     SeeAlso:    GRenderDIB::FreeLPBits
00179 
00180 ********************************************************************************************/
00181 
00182 void GRenderDIB::FreeLPBits( LPBITMAPINFO lpBMI, LPBYTE lpB )
00183 {
00184     // If we are banded, then free the memory from the limited heap
00185     FreeDIB(lpBMI, lpB, NULL, TRUE);
00186 }
00187 
00188 /********************************************************************************************
00189 
00190 >   LPBYTE GRenderDIB::ResizeBits( LPBYTE lpBits, INT32 NewSize)
00191 
00192     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00193     Created:    5/7/95
00194     Inputs:     Bitmap pointer, and the new size.
00195     Returns:    The newly resized bitmap data pointer.
00196     Purpose:    Reallocates the bitmap to be a new size.
00197     Errors:     -
00198     SeeAlso:    GRenderDIB::FreeLPBits
00199 
00200 ********************************************************************************************/
00201 
00202 LPBYTE GRenderDIB::ResizeBits( LPBYTE lpBits, INT32 NewSize)
00203 {
00204     // Get the memory manager
00205     TunedMemory* pTuned = GetTunedMemManager();
00206     if (pTuned == NULL)
00207         return NULL;
00208 
00209     return (LPBYTE)pTuned->LimitedCCRealloc(lpBits, NewSize);
00210 }
00211 
00212 /********************************************************************************************
00213 
00214 >   GRenderDIB::~GRenderDIB()
00215 
00216     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00217     Created:    2/6/94
00218     Inputs:     -
00219     Outputs:    -
00220     Returns:    -
00221     Purpose:    GRenderDIB destructor. Frees up the bitmap.
00222     Errors:     -
00223 
00224 ********************************************************************************************/
00225 
00226 GRenderDIB::~GRenderDIB()
00227 {
00228     if (LocalBitmap)
00229     {
00230         FreeOffscreenState();
00231         pBitmapInfo = NULL;
00232         pBits = NULL;
00233     }
00234     // will call GRenderRegions destructor here
00235 }
00236 
00237 /********************************************************************************************
00238 
00239 >   BOOL GRenderDIB::DisplayBits(LPBITMAPINFO lpDisplayBitmapInfo = NULL, LPBYTE lpDisplayBits = NULL)
00240 
00241     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00242     Created:    2/6/94
00243     Inputs:     -
00244     Outputs:    -
00245     Returns:    TRUE if worked, FALSE if failed.
00246     Purpose:    Plots the DIB onto the owner device.
00247     Errors:     -
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         // If we are doing a colour separation and are not in Mono mode
00265         // then we need to convert the bitmap from 32 bpp platescale to 
00266         // simulated printer colours
00267         // We do this conversion in place as separations are not background rendered
00268         // so we wont be rendering anything else into the bitmap
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                     // First we set up a colour conversion table from platescale value
00284                     // to real RGB value
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 // TEMP BODGE to avoid rewriting all these function to take LP bitmap info/bits parameters!
00362 LPBITMAPINFO lpStoredInfo = pBitmapInfo;
00363 LPBYTE lpStoredBits = pBits;
00364 pBitmapInfo = lpLocalInfo;
00365 pBits = lpLocalBits;
00366 
00367         if ( uBitmapDepth == (UINT32)ScreenDepth )
00368             Display1to1Bitmap();
00369 //          Display1to1Bitmap(lpLocalInfo, lpLocalBits);
00370 PORTNOTE("other","GRenderDIB::DisplayBits - removed BitmapDepth tests")
00371 #ifdef EXCLUDE_FROM_XARALX
00372         else
00373             DisplayLtoHBitmap();
00374 //          DisplayLtoHBitmap(lpLocalInfo, lpLocalBits);
00375 #else
00376         else if ( BitmapDepth < ScreenDepth )
00377             DisplayLtoHBitmap();
00378 //          DisplayLtoHBitmap(lpLocalInfo, lpLocalBits);
00379         else if ( (ScreenDepth==8 ) || (ScreenDepth==4) )
00380             DisplayHto8Bitmap();            // high-colour to 256/16 is special
00381 //          DisplayHto8Bitmap(lpLocalInfo, lpLocalBits);            // high-colour to 256/16 is special
00382         else
00383             DisplayLtoHBitmap();            // fallback code to general blit
00384 //          DisplayLtoHBitmap(lpLocalInfo, lpLocalBits);            // fallback code to general blit
00385 #endif
00386 pBitmapInfo = lpStoredInfo;
00387 pBits = lpStoredBits;
00388     }
00389     return TRUE;
00390 }
00391 
00392 
00393 
00394 
00395 
00396 /********************************************************************************************
00397 
00398 >   virtual BOOL GRenderDIB::SetFirstBand()
00399 
00400     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00401     Created:    2/5/95
00402     Returns:    TRUE if all went well. FALSE if it did not
00403     Purpose:    This determines if banding is needed for this render region and sets up
00404                 ready for it. If this region is already banded, then this function does
00405                 nothing - it is safe to call this even if it has been called before.
00406 
00407 ********************************************************************************************/
00408 
00409 BOOL GRenderDIB::SetFirstBand()
00410 {
00411     // if we are already banded, or we already have a bitmap, then stop looking
00412     if (IsBanded() || pBitmapInfo!=NULL)
00413         return TRUE;
00414 
00415 //  ENSURE(GetCaptureDepth()==0, "Can't set a band while there are any captures running");
00416     ENSURE(GetCaptureDepth()==0 || MasterCaptureIsCurrent(), "Can't set a band while there are any non-master captures running\n");
00417 
00418     // They can be merged for the time being
00419     CanRegionBeMerged = TRUE;
00420 
00421     // Make sure the InitDevice has been called.
00422     if (!RenderFlags.ValidDevice)
00423     {
00424         // Device needs to be initialised
00425         if (!InitDevice())
00426         {
00427             // Something's gone wrong - inform the user.
00428             TRACE( _T("InitDevice failed in Render Region"));
00429             return FALSE;
00430         }
00431 
00432         // Make sure we don't do this again for this render region
00433         RenderFlags.ValidDevice = TRUE;
00434     }
00435 
00436     // ok, how much ram do we need and how much ram is there to use
00437     TunedMemory* pTunedMem = GetTunedMemManager();
00438     if (pTunedMem==NULL)
00439         return FALSE;
00440 
00441     // If we are not limited, then do not bother with the bands
00442     if (pTunedMem->IsMemSizeInfinite())
00443     {
00444         // No Banding needed
00445         IsRegionBanded = FALSE;
00446         IsWaitingForRAM = FALSE;
00447         IsLastBand = TRUE;
00448         return TRUE;
00449     }
00450 
00451     // We are limited, so find out how much we are allowed
00452     size_t AvailableRAM = pTunedMem->GetAvailableTunedMem();
00453     
00454     // Work out a rough idea of the amount of ram needed
00455     INT32 ScanLineSize = DIBUtil::ScanlineSize(WRect.width, uBitmapDepth);
00456     if (ScanLineSize==0)
00457         return FALSE;
00458 
00459     // Work out how many scan lines we could fit into the available ram
00460     INT32 MaxScanLines = INT32(AvailableRAM / ScanLineSize);
00461     INT32 Height = WRect.height;
00462 
00463     // see if there are enought to bother with
00464     if (MaxScanLines<16)
00465     {
00466         // Not really enough memory to bother
00467         IsWaitingForRAM = TRUE;
00468         return TRUE;
00469     }
00470 
00471     // See if we can do it
00472     if (MaxScanLines>=Height)
00473     {
00474         // No Banding needed
00475         IsRegionBanded = FALSE;
00476         IsWaitingForRAM = FALSE;
00477         IsLastBand = TRUE;
00478         return TRUE;
00479     }
00480     else
00481     {
00482         // Lets band this region then
00483         IsRegionBanded = TRUE;
00484         IsWaitingForRAM = FALSE;
00485         IsLastBand = FALSE;
00486         CanRegionBeMerged = FALSE;
00487 
00488         // Find out how big in millipoints we can do
00489         double TruePixelHeight = 72000.0 / PixelsPerInch; //.MakeDouble();
00490         TruePixelHeight = TruePixelHeight / ScaleFactor.MakeDouble();
00491         MILLIPOINT MaxHeight = (MILLIPOINT)(TruePixelHeight * (double)MaxScanLines);
00492 
00493         // Set up the new clip rect ready
00494         DocRect NewClipRect = CurrentClipRect;
00495         NewClipRect.hi.y = NewClipRect.lo.y + MaxHeight;
00496 
00497         // Sanity check
00498         if (NewClipRect.hi.y>CurrentClipRect.hi.y)
00499             NewClipRect.hi.y = CurrentClipRect.hi.y;
00500 
00501         // Set the new clip rect up ready for rendering
00502         SetClipRect(NewClipRect);       
00503         return TRUE;
00504     }
00505 }
00506 
00507 
00508 
00509 
00510 /********************************************************************************************
00511 
00512 >   virtual BOOL GRenderDIB::GetNextBand()
00513 
00514     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00515     Created:    2/5/95
00516     Returns:    TRUE if there is another band to do, FALSE if there are no more bands
00517     Purpose:    This function decides if there are more bands to do. If there are it sets
00518                 them up and returns TRUE.
00519 
00520 ********************************************************************************************/
00521 
00522 BOOL GRenderDIB::GetNextBand()
00523 {
00524     // if this is not a banded render region, then there are no more bands
00525     if (!IsBanded())
00526         return FALSE;
00527 
00528 //  ENSURE(GetCaptureDepth()==0, "Can't set a band while there are any captures running");
00529     ENSURE(GetCaptureDepth()==0 || MasterCaptureIsCurrent(), "Can't set a band while there are any non-master captures running\n");
00530 
00531     // ensure all offscreen rendering in previous band finished rendering
00532     // NB if it didn't then GetNextBand shouldn't have been called.
00533 //  if(IsUserName("Ilan"))
00534     ERROR3IF(!MasterCaptureIsCurrent(),"GetNextBand called before previous band finished!");
00535 
00536     // Free previous band's bmp memory
00537     FreeOffscreenState();
00538     pBitmapInfo = NULL;
00539     pBits = NULL;
00540 
00541     // See if we are out of bands
00542     if ((CurrentClipRect.hi.y>=RegionRect.hi.y) || (IsLastBand))
00543         return FALSE;
00544 
00545     // Go find the next band, if there is one.
00546     // ok, how much ram do we need and how much ram is there to use
00547     TunedMemory* pTunedMem = GetTunedMemManager();
00548 
00549     // we're going to need to be re-rendered
00550     IsPaperRendered = FALSE;
00551     IsInkRenderStarted = FALSE;
00552 
00553     // Find out how much free memory there is now
00554     size_t AvailableRAM = pTunedMem->GetAvailableTunedMem();
00555     
00556     // Work out a rough idea of the amount of ram needed
00557     INT32 ScanLineSize = DIBUtil::ScanlineSize(WRect.width, uBitmapDepth);
00558     if (ScanLineSize==0)
00559         return FALSE;
00560 
00561     // Work out how many scan lines we could fit into the available ram
00562     INT32 MaxScanLines = INT32(AvailableRAM / ScanLineSize);
00563 
00564     // Work out how many scan lines there are left to do
00565     double TruePixelHeight = 72000.0 / PixelsPerInch; //.MakeDouble();
00566     TruePixelHeight = TruePixelHeight / ScaleFactor.MakeDouble();
00567     INT32 Height = (INT32) ((double)(RegionRect.hi.y - CurrentClipRect.hi.y) / TruePixelHeight);
00568 
00569     // see if there are enought to bother with
00570     IsWaitingForRAM = FALSE;
00571     if ((Height>=16) && (MaxScanLines<16))
00572     {
00573         // Not really enough memory to bother
00574         IsWaitingForRAM = TRUE;
00575         return TRUE;
00576     }
00577 
00578     // Do what we can
00579     INT32 ScanLinesToDo = (MaxScanLines<Height) ? MaxScanLines : Height;
00580     if (ScanLinesToDo==Height)
00581         IsLastBand = TRUE;
00582     else
00583         IsLastBand = FALSE;
00584 
00585     // Find out how big in millipoints we can do
00586     MILLIPOINT MaxHeight = (MILLIPOINT) (TruePixelHeight * (double)ScanLinesToDo);
00587 
00588     // Set up the new clip rect ready
00589     DocRect NewClipRect = CurrentClipRect;
00590     NewClipRect.lo.y = CurrentClipRect.hi.y;
00591     NewClipRect.hi.y = NewClipRect.lo.y + MaxHeight;
00592 
00593     // Sanity check
00594     if ((NewClipRect.hi.y>RegionRect.hi.y) || (IsLastBand))
00595         NewClipRect.hi.y = RegionRect.hi.y;
00596         
00597     // Make sure that we are not dealing with an empty rect
00598     if (NewClipRect.Height()==0)
00599         return FALSE;
00600 
00601     // Set the new clip rect up ready for rendering
00602     SetClipRect(NewClipRect);
00603 
00604     // we're going to need to be re-rendered
00605     IsPaperRendered = FALSE;
00606     IsInkRenderStarted = FALSE;
00607     TRACEUSER("Gavin",_T("GRenderDIB::GetNextBand - RenderFlags.Rendering = FALSE;\n"));
00608     RenderFlags.Rendering = FALSE;
00609 
00610     // Say it all worked
00611     return TRUE;
00612 }
00613 
00614 
00615 
00616 
00617 /********************************************************************************************
00618 
00619 >   virtual void GRenderDIB::ResizeRegion(DocRect &NewClipRect)
00620 
00621     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00622     Created:    4/7/95
00623     Purpose:    Called when a Region is changed in size (eg. clipped to the client area)
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         // The Region is banded.  That's gunna complicate things.
00636 
00637         if (CurrentClipRect.IsIntersectedWith(NewRegionRect))
00638         {
00639             // 'Clip' the current clip rect to the new Region Rect
00640             NewClipRect = CurrentClipRect.Intersection(NewRegionRect);
00641         }
00642         else
00643         {
00644             // The current band has disappeared outside the Region
00645             if (NewRegionRect.lo.y >= CurrentClipRect.hi.y)
00646             {
00647                 // The area visible, is completely un-rendered,
00648                 // so we may as well start again.
00649                 ResetRegion(NewRegionRect);
00650                 return;
00651             }
00652             else
00653             {
00654                 // We've already render everything beneath the band
00655                 // that has just gone outside the region, so this 
00656                 // region is finished with
00657 
00658                 // Fake it so it doesn't render anything, by setting
00659                 // the clip rect to zero height
00660                 NewClipRect = NewRegionRect;
00661                 NewClipRect.lo.y = NewClipRect.hi.y;                
00662 
00663                 ResetRegion(NewClipRect);
00664                 return;
00665             }
00666         }
00667 
00668         if (IsWaitingForRAM)
00669         {
00670             // This region is waiting for memory to be freed, 
00671             // so there is no bitmap to resize !!
00672             HaveABitmap = FALSE;
00673         }
00674     }
00675 
00676     if (!MasterCaptureIsCurrent())
00677     {
00678         // midway through offscreen rendering. Free memory and start again.
00679         ResetRegion(NewRegionRect);
00680         return;
00681     }
00682 
00683     // Make a new Render Matrix, in case the View has changed position
00684     Matrix ViewMatrix = RenderView->ConstructRenderingMatrix(RenderSpread);
00685 
00686     // Get windows rects, using the new RenderMatrix.
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             // We are about to re-size the bitmap, but we can't
00696             // do this for anything less than 8bpp, so we'll just
00697             // reset instead.
00698             ResetRegion(NewClipRect);
00699             return;
00700         }
00701 
00702         // Get the current clip rect in windows coords
00703         wxRect ORect = OSRenderRegion::DocRectToWin( ViewMatrix, CurrentClipRect, PixelsPerInch );
00704 
00705         const INT32 OldWidth    = ORect.width;
00706         const INT32 OldHeight = ORect.height;
00707 
00708         // Its changed size, so we'll try and re-size the bitmap
00709         // If this fails, then we'll just re-set
00710         if (pBits!=NULL && pBitmapInfo!=NULL &&
00711             (NewWidth!=OldWidth || NewHeight!=OldHeight))
00712         {
00713 //          TRACEUSER("Gerry", _T("OldRect is (%d, %d) [%d, %d]\n"),ORect.x,ORect.y,ORect.width,ORect.height);
00714 //          TRACEUSER("Gerry", _T("NewRect is (%d, %d) [%d, %d]\n"),NRect.x,NRect.y,NRect.width,NRect.height);
00715 
00716             UINT32 BaseX = NRect.x> ORect.x ? OldWidth  - NewWidth  : 0;
00717             UINT32 BaseY = NRect.y> ORect.y ? OldHeight - NewHeight : 0;
00718 
00719             // DIB are upside down to windows rects, ie 0,0 is in the bottom left
00720             BaseY=OldHeight-NewHeight-BaseY; // Use Windows type origin from top left.
00721 
00722 //          TRACEUSER("Gerry", _T("Base X,Y is %d,%d\n"), BaseX, BaseY);
00723 
00724             if (DIBUtil::MakeBitmapSmaller(OldWidth, OldHeight, BaseX, BaseY, 
00725                                            NewWidth, NewHeight, uBitmapDepth, pBits))
00726             {
00727                 // Bitmap resized ok, so we can re-allocate the block to the new size
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                 // Gavin needs an extra bit of memory, on top of the actual
00736                 // bitmap size, so lets work out how much we need ...
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;                                       // in case of zero w or h
00751 
00752                 // Added extra bit on
00753                 INT32 NewSize = size + dbsize + EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize(NewWidth, uBitmapDepth);
00754 
00755                 // Resize the DIB to the new size (always smaller)
00756                 pBits = ResizeBits(pBits, NewSize);
00757 //              TRACEUSER("Gerry", _T("ReAlloc called. Bits now at %x, size=%d\n"), pBits, NewSize);
00758 
00759                 if (pBits == NULL)
00760                 {
00761                     ResetRegion(NewRegionRect);
00762                     return;
00763                 }
00764 
00765                 // Set the new Gavin clip rect
00766                 GetDrawContext()->ClipRectangle( (LPRECT)&NewClipRect );
00767             }
00768             else
00769             {
00770                 // Make smaller failed, so we'll do it the old lazy way.
00771                 ResetRegion(NewRegionRect);
00772             }
00773         }
00774     }
00775 
00776     // set new rectangle size
00777     WRect = NRect;
00778 
00779     // Update the clip rect if one was given
00780     CurrentClipRect = NewClipRect;
00781     RegionRect      = NewRegionRect;
00782 
00783     // Update the master capture
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     // Since we have changed the clipping rect the GDraw changed bounding box may no longer be
00794     // correct so we must enlarge it to be full size...
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 }

Generated on Sat Nov 10 03:48:33 2007 for Camelot by  doxygen 1.4.4