00001 // $Id: capturemanager.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 */ 00101 00102 // CaptureManager.CPP 00103 // 00104 // Created: 29/06/2004 by Phil 00105 // 00106 00107 #include "camtypes.h" 00108 //#include "capturemanager.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 #include "grndrgn.h" 00110 #include "clipattr.h" // so we know what a ClipRegionAttribute is. 00111 00112 //CC_IMPLEMENT_DYNAMIC(CaptureManager, CCObject) 00113 CC_IMPLEMENT_DYNAMIC(Capture, CCObject) 00114 00115 // Declare smart memory handling in Debug builds 00116 #define new CAM_DEBUG_NEW 00117 00118 00119 /******************************************************************************************** 00120 00121 > Capture::Capture() 00122 00123 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00124 Created: 19/07/2004 00125 Inputs: - 00126 Outputs: - 00127 Returns: - 00128 Purpose: Default Constructor for Capture Class 00129 Errors: - 00130 SeeAlso: - 00131 00132 ********************************************************************************************/ 00133 00134 Capture::Capture() 00135 { 00136 m_pOwner = NULL; 00137 m_pDirectBitmapSupplier = NULL; 00138 m_pClipRegionAttrValue = NULL; 00139 00140 CaptureRect = DocRect(0,0,0,0); 00141 lpBitmapInfo = NULL; 00142 lpBits = NULL; 00143 CaptureMatrix = Matrix(); 00144 pColContext = NULL; 00145 info = CAPTUREINFO(ctDISABLED, cfNONE); 00146 dPixelsPerInch = 96; 00147 00148 // m_ClipRegionMap.InitHashTable(17, FALSE); 00149 } 00150 00151 00152 00153 00154 /******************************************************************************************** 00155 00156 > Capture::Capture(CCObject* pOwner, // New Capture constructor 00157 CAPTUREINFO cinfo, 00158 Matrix CaptureMatrix, 00159 DocRect CaptureRect, 00160 ColourContext* pCaptureColourContext 00161 ) 00162 00163 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00164 Created: 19/07/2004 00165 Inputs: - 00166 Outputs: - 00167 Returns: - 00168 Purpose: New Capture Constructor for Capture Class 00169 Errors: - 00170 SeeAlso: - 00171 00172 ********************************************************************************************/ 00173 00174 Capture::Capture(CCObject* pOwner, // New Capture constructor 00175 CAPTUREINFO cinfo, 00176 Matrix cMatrix, 00177 DocRect cRect, 00178 double PixelsPerInch, 00179 ColourContext* pcColourContext 00180 ) 00181 { 00182 m_pOwner = pOwner; 00183 m_pDirectBitmapSupplier = NULL; 00184 m_pClipRegionAttrValue = NULL; 00185 00186 CaptureRect = cRect; 00187 lpBitmapInfo = NULL; 00188 lpBits = NULL; 00189 PORTNOTE("other","Removed GRenderRegion::MakeGavinMatrix usage") 00190 #ifndef EXCLUDE_FROM_XARALX 00191 CaptureGMatrix = GRenderRegion::MakeGavinMatrix(cMatrix, cRect, PixelsPerInch); 00192 #endif 00193 CaptureMatrix = cMatrix; 00194 pColContext = pcColourContext; 00195 info = cinfo; 00196 dPixelsPerInch = PixelsPerInch; 00197 } 00198 00199 00200 00201 00202 /******************************************************************************************** 00203 00204 > Capture::Capture(Capture* pSourceCapture, // Copy constructor 00205 BOOL bCopyBitmap) 00206 00207 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00208 Created: 19/07/2004 00209 Inputs: - 00210 Outputs: - 00211 Returns: - 00212 Purpose: Copy Constructor for Capture Class 00213 Errors: - 00214 SeeAlso: - 00215 00216 ********************************************************************************************/ 00217 00218 Capture::Capture(Capture* pSourceCapture, // Copy constructor 00219 BOOL bCopyBitmap) 00220 { 00221 m_pOwner = pSourceCapture->m_pOwner; 00222 m_pDirectBitmapSupplier = pSourceCapture->m_pDirectBitmapSupplier; 00223 m_pClipRegionAttrValue = pSourceCapture->m_pClipRegionAttrValue; 00224 00225 CaptureRect = pSourceCapture->CaptureRect; 00226 lpBitmapInfo = pSourceCapture->lpBitmapInfo; 00227 lpBits = pSourceCapture->lpBits; 00228 CaptureMatrix = pSourceCapture->CaptureMatrix; 00229 pColContext = pSourceCapture->pColContext; 00230 info = pSourceCapture->info; // Note that copying a master will create a master! 00231 dPixelsPerInch = pSourceCapture->dPixelsPerInch; 00232 00233 if (bCopyBitmap && pSourceCapture->lpBitmapInfo && pSourceCapture->lpBits) 00234 { 00235 DIBUtil::CopyBitmap(pSourceCapture->lpBitmapInfo, pSourceCapture->lpBits, 00236 &lpBitmapInfo, &lpBits); 00237 } 00238 00239 // CopyBitmap doesn't copy compression flag correctly... 00240 lpBitmapInfo->bmiHeader.biCompression = pSourceCapture->lpBitmapInfo->bmiHeader.biCompression; 00241 } 00242 00243 00244 00245 00246 /******************************************************************************************** 00247 00248 > BOOL Capture::AllocateDIB(BOOL bTransparent = FALSE) 00249 00250 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00251 Created: 19/07/2004 00252 Inputs: - 00253 Outputs: - 00254 Returns: - 00255 Purpose: Default Destructor for CaptureManager Class 00256 Errors: - 00257 SeeAlso: - 00258 00259 ********************************************************************************************/ 00260 00261 /*BOOL Capture::AllocateDIB(BOOL bTransparent) 00262 { 00263 ERROR2(FALSE, "Unimplemented!"); 00264 00265 // NB Millipoint endpoints don't necessarily fall on exact pixel boundaries. 00266 // Hence use following function to find out which pixels the millipoints fall on 00267 RECT Rect = CalculateWinRect(CaptureMatrix, CaptureRect, PixelsPerInch); 00268 UINT32 PixelWidth = Rect.right-Rect.left; 00269 UINT32 PixelHeight = Rect.bottom-Rect.top; 00270 UINT32 bpp = 32; 00271 00272 // TRACEUSER( "Gerry", _T("Creating offscreen bitmap (%d, %d)\n"), PixelWidth, PixelHeight); 00273 if (PixelWidth==0 || PixelHeight==0) 00274 return FALSE; 00275 00276 lpBitmapInfo = ::AllocDIB( PixelWidth, PixelHeight, bpp, &lpBits, NULL, FALSE); // don't use limited mem manager 00277 00278 if (lpBitmapInfo==NULL || lpBits==NULL) 00279 { 00280 ENSURE(FALSE,"Couldn't create bitmap for offscreen rendering."); 00281 return FALSE; 00282 } 00283 00284 LPBITMAPINFOHEADER bh = &lpBitmapInfo->bmiHeader; 00285 bh->biCompression = bTransparent ? 0x80000001: BI_RGB; // see GDraw docs on GDraw_SetDIBitmap 00286 bh->biXPelsPerMeter = PixelsPerMeterAtCurrentViewScale(ScaleFactor); // Not used by GDraw - just for completeness sake 00287 bh->biYPelsPerMeter = PixelsPerMeterAtCurrentViewScale(ScaleFactor); // Not used by GDraw 00288 00289 // Success 00290 return TRUE; 00291 } 00292 */ 00293 00294 00295 00296 /******************************************************************************************** 00297 00298 > BOOL Capture::FreeDIB() 00299 00300 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00301 Created: 19/07/2004 00302 Inputs: - 00303 Outputs: - 00304 Returns: - 00305 Purpose: Default Destructor for CaptureManager Class 00306 Errors: - 00307 SeeAlso: - 00308 00309 ********************************************************************************************/ 00310 00311 BOOL Capture::FreeDIB() 00312 { 00313 ::FreeDIB(lpBitmapInfo, lpBits, NULL, FALSE); 00314 lpBitmapInfo = NULL; // Owns bitmap will now return FALSE 00315 lpBits = NULL; 00316 00317 return FALSE; 00318 } 00319 00320 00321 00322 00323 /******************************************************************************************** 00324 00325 > Capture::~Capture() 00326 00327 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00328 Created: 19/07/2004 00329 Inputs: - 00330 Outputs: - 00331 Returns: - 00332 Purpose: Default Destructor for CaptureManager Class 00333 Errors: - 00334 SeeAlso: - 00335 00336 ********************************************************************************************/ 00337 00338 Capture::~Capture() 00339 { 00340 RemoveAllCachedClipRegions(); 00341 00342 if (m_pClipRegionAttrValue) 00343 { 00344 delete m_pClipRegionAttrValue; 00345 m_pClipRegionAttrValue = NULL; 00346 } 00347 } 00348 00349 00350 00351 00352 /******************************************************************************************** 00353 00354 > void Capture::SetTransparent(BOOL bNewState) 00355 00356 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00357 Created: 19/07/2004 00358 Inputs: bNewState - TRUE if captured bitmap should be made transparent 00359 FALSE if captured bitmap should be made opaque 00360 Outputs: - 00361 Returns: - 00362 Purpose: Change the transparency of a captured bitmap 00363 Errors: - 00364 SeeAlso: - 00365 00366 ********************************************************************************************/ 00367 00368 void Capture::SetTransparent(BOOL bNewState) 00369 { 00370 if (lpBitmapInfo && lpBits && lpBitmapInfo->bmiHeader.biBitCount==32) 00371 { 00372 lpBitmapInfo->bmiHeader.biCompression = bNewState ? 0x80000001 : BI_RGB; 00373 UINT32 BmpSize = GetDIBBitsSize(&lpBitmapInfo->bmiHeader); 00374 UINT32 Index = 0; 00375 LPBYTE pSetBits = lpBits; 00376 00377 if (bNewState) 00378 { 00379 // ReInit bitmap to be fully transparent 00380 while(Index < BmpSize) 00381 { 00382 // initial values for using internal alpha channelled format 00383 // fully transparent black bacground 00384 00385 pSetBits[Index++] = 0x00; 00386 pSetBits[Index++] = 0x00; 00387 pSetBits[Index++] = 0x00; 00388 pSetBits[Index++] = 0xFF; 00389 } 00390 } 00391 else 00392 { 00393 // ReInit bitmap to be fully opaque 00394 while(Index < BmpSize) 00395 { 00396 // fully opaque white background 00397 pSetBits[Index++] = 0xFF; 00398 pSetBits[Index++] = 0xFF; 00399 pSetBits[Index++] = 0xFF; 00400 pSetBits[Index++] = 0x00; 00401 } 00402 } 00403 } 00404 else 00405 { 00406 ERROR3("SetTransparency called on empty/non-32BPP bitmap"); 00407 } 00408 } 00409 00410 00411 00412 00413 /******************************************************************************************** 00414 00415 > BOOL Capture::ConsumeDirectBitmap(NodeRenderableInk* pSupplier) 00416 00417 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00418 Created: 02/08/2005 00419 Inputs: - 00420 Outputs: - 00421 Returns: - 00422 Purpose: Consume the supplied bitmap if the supplier is right 00423 Errors: - 00424 SeeAlso: - 00425 00426 ********************************************************************************************/ 00427 00428 BOOL Capture::ConsumeDirectBitmap(NodeRenderableInk* pSupplier) 00429 { 00430 if (m_pDirectBitmapSupplier!=pSupplier || info.caFlags.Direct==FALSE) 00431 return FALSE; 00432 00433 // TODO: Could grab some info about the direct bitmap here? 00434 00435 return TRUE; 00436 } 00437 00438 00439 00440 00441 /******************************************************************************************** 00442 00443 > const REGION* Capture::GetClipRegion(ClipRegionAttribute* pClipAttr) 00444 00445 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00446 Created: 03/10/2005 00447 Inputs: - 00448 Outputs: - 00449 Returns: - 00450 Purpose: - 00451 Errors: - 00452 SeeAlso: - 00453 00454 ********************************************************************************************/ 00455 00456 const REGION* Capture::GetCachedClipRegion(ClipRegionAttribute* pClipAttr) 00457 { 00458 ClipRegionMap::const_iterator iter = m_ClipRegionMap.find( pClipAttr ); 00459 if( m_ClipRegionMap.end() == iter ) 00460 return NULL; 00461 00462 return (REGION *)iter->second; 00463 } 00464 00465 00466 00467 00468 /******************************************************************************************** 00469 00470 > void Capture::SetCachedClipRegion(ClipRegionAttribute* pClipAttr, const REGION* pClipRegion) 00471 00472 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00473 Created: 03/10/2005 00474 Inputs: - 00475 Outputs: - 00476 Returns: - 00477 Purpose: - 00478 Errors: - 00479 SeeAlso: - 00480 00481 ********************************************************************************************/ 00482 00483 void Capture::SetCachedClipRegion(ClipRegionAttribute* pClipAttr, const REGION* pClipRegion) 00484 { 00485 m_ClipRegionMap[pClipAttr] = (void *)pClipRegion; 00486 } 00487 00488 00489 00490 00491 /******************************************************************************************** 00492 00493 > void Capture::RemoveCachedClipRegion(ClipRegionAttribute* pClipAttr) 00494 00495 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00496 Created: 03/10/2005 00497 Inputs: - 00498 Outputs: - 00499 Returns: - 00500 Purpose: - 00501 Errors: - 00502 SeeAlso: - 00503 00504 ********************************************************************************************/ 00505 00506 void Capture::RemoveCachedClipRegion(ClipRegionAttribute* pClipAttr) 00507 { 00508 ClipRegionMap::iterator iter = m_ClipRegionMap.find( pClipAttr ); 00509 if( m_ClipRegionMap.end() != iter ) 00510 { 00511 if (iter->second != NULL) 00512 delete []( (BYTE *)iter->second ); 00513 00514 m_ClipRegionMap.erase( iter ); 00515 } 00516 } 00517 00518 00519 00520 00521 /******************************************************************************************** 00522 00523 > void Capture::RemoveAllCachedClipRegions() 00524 00525 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00526 Created: 03/10/2005 00527 Inputs: - 00528 Outputs: - 00529 Returns: - 00530 Purpose: - 00531 Errors: - 00532 SeeAlso: - 00533 00534 ********************************************************************************************/ 00535 00536 void Capture::RemoveAllCachedClipRegions() 00537 { 00538 ClipRegionMap::const_iterator iter = m_ClipRegionMap.begin(); 00539 for( ; iter != m_ClipRegionMap.end(); ++iter ) 00540 { 00541 if( iter->second != NULL ) 00542 delete []( (BYTE *)iter->second ); 00543 } 00544 m_ClipRegionMap.clear(); 00545 } 00546 00547 00548 00549