mrhbits.cpp

Go to the documentation of this file.
00001 // $Id: mrhbits.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 "mrhbits.h"        // TODO
00102 //#include "view.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00103 //#include "bitmap.h"
00104 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 #include "grndrgn.h"
00106 #include "grndbmp.h"
00107 #include "fillattr2.h"
00108 //#include "docview.h"
00109 //#include "grptrans.h"
00110 //#include "ndcchbmp.h"
00111 
00112 // Place any IMPLEMENT type statements here
00113 CC_IMPLEMENT_MEMDUMP(CBMPBits, CC_CLASS_MEMDUMP)
00114 
00115 // We want better memory tracking
00116 #define new CAM_DEBUG_NEW
00117 
00118 /********************************************************************************************
00119 
00120 >   BOOL CBMPBits::RenderOILBMPToTransparentWhiteRect(BitmapFillAttribute* pRef, BOOL Transparent)
00121                     
00122     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
00123     Created:    28/7/99
00124     Inputs:     Pointer to an OILBitmap, Flag to say wether or not the Rectangle is to be transparent!
00125     Outputs:    None
00126     Returns:    TRUE if Everything ok!
00127     Purpose:    Front end function for RenderBMPFillAttrToTransparentWhiteRect(BitmapFillAttribute* pRef)
00128                 used if the calling function does not contain a bitmapfillattribute!
00129 
00130 ********************************************************************************************/
00131 OILBitmap* CBMPBits::RenderOILBMPToTransparentWhiteRect(OILBitmap* pConvBMP, BOOL Transparent, INT32 OutputBPP)
00132 {
00133     // Check to see if we`ve been given a null bitmap pointer!
00134     ERROR2IF(pConvBMP == NULL,FALSE,"We`ve got a NULL Bitmap Pointer!! CBMPBits!");
00135 
00136     // Setup All the pointers that are going to be used
00137     KernelBitmap* pKernel = NULL;
00138     OILBitmap* pNewBMP = NULL;
00139 
00140     // Create a new KernelBitmap from the OILBitmap so we can create a new BitmapFillAttribute!
00141     pKernel = new KernelBitmap(pConvBMP);
00142     
00143     if(pKernel != NULL)
00144     {
00145         pNewBMP = RenderKernelBMPToTransparentWhiteRect(pKernel, Transparent, OutputBPP);
00146 
00147         delete pKernel;
00148         pKernel = NULL;
00149     }
00150 
00151     // Return the new Bitmap
00152     return pNewBMP;
00153 }
00154 
00155 /********************************************************************************************
00156 
00157 >   BOOL CBMPBits::RenderKernelBMPToTransparentWhiteRect(BitmapFillAttribute* pRef)
00158                     
00159     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
00160     Created:    28/7/99
00161     Inputs:     Pointer to an KernelBitmap, Flag to say wether or not the Rectangle is to be transparent!
00162     Outputs:    None
00163     Returns:    TRUE if Everything ok!
00164     Purpose:    Front end function for RenderBMPFillAttrToTransparentWhiteRect(BitmapFillAttribute* pRef)
00165                 used if the calling function does not contain a bitmapfillattribute!
00166 
00167 ********************************************************************************************/
00168 OILBitmap* CBMPBits::RenderKernelBMPToTransparentWhiteRect(KernelBitmap* pConvBMP, BOOL Transparent, INT32 OutputBPP)
00169 {
00170     // Check to see if we`ve been given a null bitmap pointer!
00171     ERROR2IF(pConvBMP == NULL,FALSE,"We`ve got a NULL Bitmap Pointer!! CBMPBits!");
00172 
00173     // Setup All the pointers that are going to be used
00174     OILBitmap* pNewBMP = NULL;
00175     BitmapFillAttribute* pRef = NULL;
00176 
00177     // Create the new BitmapFill Attribute
00178     pRef = new BitmapFillAttribute;
00179 
00180     if(pRef != NULL)
00181     {
00182         // make it reference the Passed in OILBitmap!
00183         pRef->AttachBitmap(pConvBMP);
00184 
00185         // Get the Width and Height of the Bitmap
00186         UINT32 Width = pConvBMP->GetWidth();
00187         UINT32 Height = pConvBMP->GetHeight();
00188 
00189         // Set the Fill Coordinates from the width and height variables
00190         DocCoord Start(0, 0);
00191         DocCoord End(Width * 750, 0);
00192         DocCoord End2(0, Height * 750);
00193 
00194         pRef->SetStartPoint(&Start);
00195         pRef->SetEndPoint(&End);
00196         pRef->SetEndPoint2(&End2);
00197 
00198         // Set the tessalation to repeating
00199         pRef->SetTesselation(2);
00200 
00201         // Now call the RenderBMPFillAttrToTransparentWhiteRect function with our new
00202         // BitmapFillAttribute!
00203         pNewBMP = RenderBMPFillAttrToTransparentWhiteRect(pRef,Transparent,OutputBPP);
00204     }
00205 
00206     // Delete everything that we created!
00207     if(pRef != NULL)
00208     {
00209         pRef->DetachBitmap();
00210         delete pRef;
00211         pRef = NULL;
00212     }
00213 
00214     // Return the new Bitmap
00215     return pNewBMP;
00216 }
00217 
00218 /********************************************************************************************
00219 
00220 >   BOOL CBMPBits::RenderBMPFillAttrToTransparentWhiteRect(BitmapFillAttribute* pRef)
00221                     
00222     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
00223     Created:    28/7/99
00224     Inputs:     A Pointer to a Bitmap Reference, Flag to say wether or not the Rectangle is to be transparent!
00225     Outputs:    None
00226     Returns:    TRUE if Everything ok!
00227     Purpose:    Renders a Any Bitmap onto a 32bit Transparent White Rectangle of size
00228                 equal to bitmap referenced. This is mainly used just before a 32bit alpha channeled
00229                 bitmap is rendered into a lower dpi region. It stops the effect of rendering 
00230                 solid shapes on a black background.
00231 
00232 ********************************************************************************************/
00233 OILBitmap* CBMPBits::RenderBMPFillAttrToTransparentWhiteRect(BitmapFillAttribute* pRef, BOOL Transparent, INT32 OutputBPP)
00234 {
00235     ERROR2IF(pRef == NULL, FALSE, "Where`s the Bitmap Reference Pointer? {DIBUtil}");
00236 
00237     // Ok, we`ve got a 32Bit BMP so lets setup a render region!
00238     View*   pView = View::GetCurrent();
00239     Matrix  Mat(1,0,0,1,0,0);
00240     FIXED16 Scale = 1;
00241     double  DPI = 96;
00242     DocRect RenderRect;
00243     OILBitmap* pNewBMP = NULL;
00244 
00245     // Get the info from the bitmap we`re trying to display in the gallery!
00246 //  LPBITMAPINFOHEADER pInfo = (pRef->GetBitmap()->ActualBitmap)->GetBitmapInfoHeader();
00247 
00248     // Setup the DocRect with the Start and End points of the bitmap fill
00249     RenderRect.lo.x = pRef->GetStartPoint()->x;
00250     RenderRect.lo.y = pRef->GetStartPoint()->y;
00251     RenderRect.hi.x = pRef->GetEndPoint()->x;
00252     RenderRect.hi.y = pRef->GetEndPoint2()->y;
00253 
00254     // Create a new GRenderBitmap region
00255     GRenderBitmap* pGBMP = new GRenderBitmap(RenderRect, Mat, Scale, OutputBPP, DPI, FALSE, 0, NULL, TRUE);
00256 
00257     if(pGBMP != NULL && pView != NULL)
00258     {
00259         // Set the flag to say that we want to use the BiCompression Field for transparencies!
00260         pGBMP->m_DoCompression = TRUE;
00261         
00262         // Create a new path which is the same size as the bitmap which will fill it!
00263         Path BMPPath;
00264         BMPPath.Initialise();
00265         BMPPath.CreatePathFromDocRect(&RenderRect);
00266 
00267         // Create a new FlatFillAttr and set it to white
00268         FlatFillAttribute* pWhiteFill = new FlatFillAttribute;
00269         DocColour White(COLOUR_WHITE);
00270         pWhiteFill->SetStartColour(&White);
00271 
00272         // Create a new StrokeColourAttr and set that also to white
00273         StrokeColourAttribute* pStrokeColour = new StrokeColourAttribute;
00274         pStrokeColour->SetStartColour(&White);
00275 
00276         // Create a new stroketransattr and set it to fully transparent
00277         StrokeTranspAttribute* pStrokeTrans = NULL;
00278         FlatTranspFillAttribute* pTransFill = NULL;
00279 
00280         if(Transparent)
00281         {
00282             pStrokeTrans = new StrokeTranspAttribute(0xFF);
00283             pTransFill = new FlatTranspFillAttribute(0xFF);
00284         }
00285         else
00286         {
00287             pStrokeTrans = new StrokeTranspAttribute(0x00);
00288             pTransFill = new FlatTranspFillAttribute(0x00);
00289         }
00290 
00291         // Make sure everything got setup alright and then proceed!
00292         if( pWhiteFill != NULL && pStrokeColour != NULL &&
00293             pStrokeTrans != NULL && pTransFill != NULL)
00294         {
00295             if (!pGBMP->AttachDevice(pView, NULL, NULL))
00296             {
00297                 ERROR3("Cannot attatch devices");
00298             }
00299 
00300             // Initialize the Render region
00301             pGBMP->InitDevice();
00302 
00303             // Save the current context
00304             pGBMP->SaveContext();
00305 
00306             // Start the render process
00307             pGBMP->StartRender();
00308 
00309             pGBMP->SetLineColour(COLOUR_NONE);
00310             pGBMP->SetLineWidth(0);
00311 
00312             // Set all the attributes we`ve just created
00313             pTransFill->Render(pGBMP);
00314             pStrokeTrans->Render(pGBMP);
00315             pWhiteFill->Render(pGBMP);
00316             pStrokeColour->Render(pGBMP);
00317 
00318             // Render a rectangle with the current attributes
00319             pGBMP->DrawRect(&RenderRect);
00320 
00321             // Now Render the Bitmap using no Flat Transparency, else it all comes out blank!           
00322             UINT32 NoTrans = 0x00;
00323             pTransFill->SetStartTransp(&NoTrans);
00324             pTransFill->Render(pGBMP);
00325 
00326             // Render the bitmap onto the white rectangle
00327             pGBMP->RenderBitmapFill(&BMPPath,pRef);
00328 
00329             // Finished so stop rendering
00330             pGBMP->StopRender();
00331 
00332             // Restore the old context
00333             pGBMP->RestoreContext();
00334 
00335             // WinBM Now needs to be setup with the newly created bitmap
00336             pNewBMP = OILBitmap::Attach(pGBMP->ExtractBitmapCopy(),TRUE);
00337         }
00338         else
00339         {
00340             ERROR3("Can not display 32bit Alpha channel bitmap!!!");
00341         }
00342 
00343         // Now delete everything!
00344         if(pGBMP != NULL)
00345         {
00346             delete pGBMP;
00347             pGBMP = NULL;
00348         }
00349 
00350         if(pStrokeColour != NULL)
00351         {
00352             delete pStrokeColour;
00353             pStrokeColour = NULL;
00354         }
00355 
00356         if(pStrokeTrans != NULL)
00357         {
00358             delete pStrokeTrans;
00359             pStrokeTrans = NULL;
00360         }
00361 
00362         if(pWhiteFill != NULL)
00363         {
00364             delete pWhiteFill;
00365             pWhiteFill = NULL;
00366         }
00367 
00368         if(pTransFill != NULL)
00369         {
00370             delete pTransFill;
00371             pTransFill = NULL;
00372         }
00373     }
00374 
00375     // Return the new Bitmap!
00376     return pNewBMP;
00377 }
00378 
00379 /********************************************************************************************
00380 
00381 >   BOOL CBMPBits::RenderSelectionToBMP(SelRange* pSel, INT32 OutputBPP, BOOL Transparent)
00382                     
00383     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
00384     Created:    12/8/99
00385     Inputs:     Flag to say wether or not the Rectangle is to be transparent and the required
00386                 output depth. Pointer to the current selection of nodes.
00387     Returns:    The newly rendered BMP or NULL if something went bang!
00388     Purpose:    Renders any selection of nodes into a BMP copy.
00389 
00390 ********************************************************************************************/
00391 OILBitmap* CBMPBits::RenderSelectionToBMP(SelRange* pSel, INT32 OutputBPP, BOOL Transparent, DocRect *pClip, double DPI)
00392 {
00393     // Check to see if we have a valid selection pointer!
00394     ERROR2IF(pSel == NULL,NULL,"Recieved a NULL Selection Range Pointer in CBMPBits!");
00395 
00396     // Ok, Lets setup a few variables need to create the new BMP
00397     View*   pView = View::GetCurrent();
00398     Matrix  Mat(1,0,0,1,0,0);
00399     FIXED16 Scale = 1;
00400 //  double  DPI = 96;
00401     OILBitmap* pNewBMP = NULL;
00402 
00403     // Get the current DocRect of the selection!
00404     // but use the passed in clip region if it is already calculated
00405     DocRect RenderRect = pClip ? *pClip : pSel->GetBoundingRect();
00406 
00407     // Check to see if we`ve got an empty rect if so then return NULL!
00408     ERROR2IF(RenderRect.IsEmpty(),NULL,"We`ve got an empty DocRect in the selection! (CBMPBits)");
00409 
00410     // Create a new GRenderBitmap region
00411     GRenderBitmap* pGBMP = new GRenderBitmap(RenderRect, Mat, Scale, OutputBPP, DPI, FALSE, 0, NULL, TRUE);
00412 
00413     // Check to see if the Render Region is valid!
00414     ERROR2IF(pGBMP == NULL,NULL,"Failed to create a GRenderBitmap in CBMPBits!");
00415 
00416     if (Transparent)
00417     {
00418         // Set the flag to say that we want to use the BiCompression Field for transparencies!
00419         pGBMP->m_DoCompression = TRUE;
00420     }
00421 
00422     // Start to render into region!
00423     if(!pGBMP->AttachDevice(pView, NULL, NULL))
00424     {
00425         ERROR3("Cannot attatch devices");
00426         
00427         delete pGBMP;
00428         pGBMP = NULL;
00429         
00430         return NULL;
00431     }
00432 
00433     pGBMP->InitDevice();
00434     pGBMP->InitAttributes();
00435     pGBMP->RRQuality.SetQuality(QUALITY_MAX);
00436     pGBMP->SetQualityLevel();
00437     pGBMP->SetLineAttributes();
00438     pGBMP->SetFillAttributes();
00439 
00440     pGBMP->StartRender();
00441 
00442     Node* pCurrent = pSel->FindFirst(FALSE);
00443 
00444     while(pCurrent != NULL)
00445     {
00446         // Render all it's child nodes using the following function
00447         pGBMP->RenderTreeNoCache(pCurrent);
00448 
00449         pCurrent = pSel->FindNext(pCurrent);
00450     }
00451 
00452     // Rendered everything so stop the render process.
00453     pGBMP->StopRender();
00454 
00455     // Now Extract the bitmap!
00456     pNewBMP = OILBitmap::Attach(pGBMP->ExtractBitmapCopy(),TRUE);
00457 
00458     // Delete all the new`s that have happened!
00459     if(pGBMP != NULL)
00460     {
00461         delete pGBMP;
00462         pGBMP = NULL;
00463     }
00464     
00465     // If everything went ok then return the pointer to the BMP!
00466     return pNewBMP;
00467 }
00468 
00469 
00470 
00471 

Generated on Sat Nov 10 03:45:44 2007 for Camelot by  doxygen 1.4.4