diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2007-08-03 13:01:55 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2007-08-03 13:01:55 +0000 |
commit | a811274d5812b2d15dad23ffcb8a2a5c1a86b3bb (patch) | |
tree | d7585ab30ecf2e085ed31684aacbbe9bbdeb71d6 | |
parent | 77d5f8f6cc9cfd43888366ff63c6ddcc43e5da0e (diff) |
INTEGRATION: CWS aquavcl02 (1.24.262); FILE MERGED
2007/07/11 10:50:02 pjanik 1.24.262.5: RESYNC: (1.24-1.27); FILE MERGED
2007/07/10 08:50:14 pl 1.24.262.4: #i79424# use an image mask instead of an image to support native menus, too
2007/07/10 08:14:42 pl 1.24.262.3: #i79424# reuse colorspace
2007/07/10 07:48:47 pl 1.24.262.2: #i79424# new implmentation for CreateWithMask
2007/07/02 11:53:46 pl 1.24.262.1: join from aquavcl01
-rw-r--r-- | vcl/aqua/source/gdi/salbmp.cxx | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/vcl/aqua/source/gdi/salbmp.cxx b/vcl/aqua/source/gdi/salbmp.cxx index f81690e1849c..99f42d5c7566 100644 --- a/vcl/aqua/source/gdi/salbmp.cxx +++ b/vcl/aqua/source/gdi/salbmp.cxx @@ -4,9 +4,9 @@ * * $RCSfile: salbmp.cxx,v $ * - * $Revision: 1.27 $ + * $Revision: 1.28 $ * - * last change: $Author: rt $ $Date: 2007-07-05 10:13:21 $ + * last change: $Author: hr $ $Date: 2007-08-03 14:01:55 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -56,6 +56,8 @@ #include <basebmp/color.hxx> #include <basegfx/vector/b2ivector.hxx> +#include <boost/bind.hpp> + #include "salinst.h" // ======================================================================= @@ -260,9 +262,7 @@ bool AquaSalBitmap::CreateContext() mnBits, mnBytesPerRow, maPalette, maUserBuffer.get() ); } - CGColorSpaceRef xColorSpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB) ); - mxGraphicContext = CGBitmapContextCreate( maContextBuffer.get(), mnWidth, mnHeight, bitsPerComponent, nContextBytesPerRow, xColorSpace, kCGImageAlphaNoneSkipFirst ); - CFRelease( xColorSpace ); + mxGraphicContext = CGBitmapContextCreate( maContextBuffer.get(), mnWidth, mnHeight, bitsPerComponent, nContextBytesPerRow, GetSalData()->mxRGBSpace, kCGImageAlphaNoneSkipFirst ); if( mxGraphicContext ) { @@ -659,7 +659,7 @@ CGImageRef AquaSalBitmap::CreateCroppedImage( int nX, int nY, int nWidth, int nH // ------------------------------------------------------------------ -/*static*/ CGImageRef AquaSalBitmap::CreateCroppedImage( CGContextRef xContext, int nX, int nY, int nWidth, int nHeight ) +CGImageRef AquaSalBitmap::CreateCroppedImage( CGContextRef xContext, int nX, int nY, int nWidth, int nHeight ) { CGImageRef xImage = 0; if( xContext ) @@ -677,6 +677,11 @@ CGImageRef AquaSalBitmap::CreateCroppedImage( int nX, int nY, int nWidth, int nH // ------------------------------------------------------------------ +static void CFRTLFree(void* /*info*/, const void* data, size_t /*size*/) +{ + rtl_freeMemory( const_cast<void*>(data) ); +} + /** TODO: Optimize me, merge the bitmap and alpha mask ourself */ CGImageRef AquaSalBitmap::CreateWithMask( const AquaSalBitmap& rMask, sal_uInt32 nX, sal_uInt32 nY, sal_uInt32 nDX, sal_uInt32 nDY ) @@ -702,46 +707,22 @@ CGImageRef AquaSalBitmap::CreateWithMask( const AquaSalBitmap& rMask, sal_uInt32 rMaskNew.Destroy();//destroy old context with a size which could be different from //the xMaskedImage, xImage, xMask size (the three have the same size=(nDX, nDY)) // and are part of the original image - rMaskNew.Create(xMask);//and create one which will fit to image - - //This code should be replaced by rMaskNew.invert() before the line containing - //rMaskNew.CreateCroppedImage when the AquaSalGraphic::invert function will be - //implemented (salgdi.cxx) - rMaskNew.CreateContext(); - CGContextTranslateCTM (rMaskNew.mxGraphicContext, 0, mnHeight); - CGContextScaleCTM (rMaskNew.mxGraphicContext, 1.0, -1.0); - CGContextSetGrayFillColor(rMaskNew.mxGraphicContext, 1.0, 1.0); - CGRect xImageRect=CGRectMake( 0, 0, nDX, nDY);//the rect has no offset - CGContextFillRect(rMaskNew.mxGraphicContext, xImageRect); - CGContextSetBlendMode(rMaskNew.mxGraphicContext, kCGBlendModeDifference); - CGContextDrawImage(rMaskNew.mxGraphicContext, xImageRect, xMask); - CFRelease( xMask ); - xMask=CGBitmapContextCreateImage(rMaskNew.mxGraphicContext); - - //we create the new image which has width and height equal to nDX and nDY - AquaSalBitmap xMaskedBmp; - xMaskedBmp.Create(xImage); - - CGContextSaveGState(mxGraphicContext); - //we create the transparent image - CGContextBeginTransparencyLayer(xMaskedBmp.mxGraphicContext, NULL); - CGContextClipToMask(xMaskedBmp.mxGraphicContext, xImageRect, xMask); - CGContextClearRect (xMaskedBmp.mxGraphicContext, xImageRect); - CGContextDrawImage(xMaskedBmp.mxGraphicContext, xImageRect, xImage ); - xMaskedImage=CGBitmapContextCreateImage(xMaskedBmp.mxGraphicContext); - CGContextEndTransparencyLayer(xMaskedBmp.mxGraphicContext); - - //we revert it as its top was on the bottom and vice versa - CGContextBeginTransparencyLayer(xMaskedBmp.mxGraphicContext, NULL); - CGContextClearRect (xMaskedBmp.mxGraphicContext, xImageRect); - CGContextDrawImage(xMaskedBmp.mxGraphicContext, xImageRect, xMaskedImage ); - CFRelease( xMaskedImage ); + CGRect xImageRect=CGRectMake( 0, 0, nDX, nDY);//the rect has no offset - xMaskedImage=CGBitmapContextCreateImage(xMaskedBmp.mxGraphicContext); - CGContextEndTransparencyLayer(xMaskedBmp.mxGraphicContext); + // create the alpha mask image fitting our image + int nMaskBytesPerRow = ((nDX + 3 ) & ~3); + void* pMaskMem = rtl_allocateMemory( nMaskBytesPerRow * nDY ); + CGContextRef xMaskContext = CGBitmapContextCreate( pMaskMem, nDX, nDY, 8, nMaskBytesPerRow, GetSalData()->mxGraySpace, kCGImageAlphaNone ); + CGContextDrawImage( xMaskContext, xImageRect, xMask ); + CFRelease( xMask ); + CGDataProviderRef xDataProvider( CGDataProviderCreateWithData(NULL, pMaskMem, nDY * nMaskBytesPerRow, &CFRTLFree) ); + xMask = CGImageMaskCreate( nDX, nDY, 8, 8, nMaskBytesPerRow, xDataProvider, NULL, false ); + CFRelease( xDataProvider ); + CFRelease( xMaskContext ); - CGContextRestoreGState(mxGraphicContext); + // combine image and alpha mask + xMaskedImage = CGImageCreateWithMask( xImage, xMask ); CFRelease( xMask ); } @@ -752,13 +733,6 @@ CGImageRef AquaSalBitmap::CreateWithMask( const AquaSalBitmap& rMask, sal_uInt32 // ------------------------------------------------------------------ -static void CFMallocDeleter(void* /*info*/, const void* data, size_t /*size*/) -{ - free( const_cast<void*>(data) ); -} - -// ------------------------------------------------------------------ - /** creates an image from the given rectangle, replacing all black pixels with nMaskColor and make all other full transparent */ CGImageRef AquaSalBitmap::CreateColorMask( int nX, int nY, int nWidth, int nHeight, SalColor nMaskColor ) const { @@ -766,7 +740,7 @@ CGImageRef AquaSalBitmap::CreateColorMask( int nX, int nY, int nWidth, int nHeig if( maUserBuffer.get() && (static_cast<unsigned int>(nX + nWidth) <= mnWidth) && (static_cast<unsigned int>(nY + nHeight) <= mnHeight) ) { const sal_uInt32 nDestBytesPerRow = nWidth << 2; - sal_uInt32* pMaskBuffer = static_cast<sal_uInt32*>( malloc( nHeight * nDestBytesPerRow ) ); + sal_uInt32* pMaskBuffer = static_cast<sal_uInt32*>( rtl_allocateMemory( nHeight * nDestBytesPerRow ) ); sal_uInt32* pDest = pMaskBuffer; ImplPixelFormat* pSourcePixels = ImplPixelFormat::GetFormat( mnBits, maPalette ); @@ -796,11 +770,9 @@ CGImageRef AquaSalBitmap::CreateColorMask( int nX, int nY, int nWidth, int nHeig pSource += mnBytesPerRow; } - CGColorSpaceRef xColorSpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB) ); - CGDataProviderRef xDataProvider( CGDataProviderCreateWithData(NULL, pMaskBuffer, nHeight * nDestBytesPerRow, &CFMallocDeleter) ); - xMask = CGImageCreate(nWidth, nHeight, 8, 32, nDestBytesPerRow, xColorSpace, kCGImageAlphaPremultipliedFirst, xDataProvider, NULL, true, kCGRenderingIntentDefault); + CGDataProviderRef xDataProvider( CGDataProviderCreateWithData(NULL, pMaskBuffer, nHeight * nDestBytesPerRow, &CFRTLFree) ); + xMask = CGImageCreate(nWidth, nHeight, 8, 32, nDestBytesPerRow, GetSalData()->mxRGBSpace, kCGImageAlphaPremultipliedFirst, xDataProvider, NULL, true, kCGRenderingIntentDefault); CFRelease(xDataProvider); - CFRelease(xColorSpace); } else { |