[Libreoffice-commits] .: vcl/aqua vcl/inc vcl/ios vcl/Library_vcl.mk vcl/quartz
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Jan 19 13:58:50 PST 2013
vcl/Library_vcl.mk | 4
vcl/aqua/source/app/salinst.cxx | 10
vcl/aqua/source/gdi/salbmp.cxx | 903 ------------------------------
vcl/aqua/source/gdi/salgdicommon.cxx | 16
vcl/aqua/source/gdi/salnativewidgets.cxx | 1
vcl/aqua/source/window/salmenu.cxx | 1
vcl/inc/aqua/atsui/salgdi.h | 1
vcl/inc/aqua/salbmp.h | 108 ---
vcl/inc/aqua/salcolorutils.hxx | 1
vcl/inc/aqua/salconst.h | 37 -
vcl/inc/aqua/salvd.h | 1
vcl/inc/ios/salbmp.h | 108 ---
vcl/inc/ios/salconst.h | 37 -
vcl/inc/quartz/salbmp.h | 105 +++
vcl/ios/source/app/salinst.cxx | 10
vcl/ios/source/gdi/salbmp.cxx | 903 ------------------------------
vcl/ios/source/gdi/salgdicommon.cxx | 16
vcl/ios/source/gdi/salnativewidgets.cxx | 1
vcl/ios/source/window/salmenu.cxx | 1
vcl/quartz/salbmp.cxx | 911 +++++++++++++++++++++++++++++++
20 files changed, 1044 insertions(+), 2131 deletions(-)
New commits:
commit 28f794086f4ed0f456ad67a293e81b019a971197
Author: Tor Lillqvist <tml at iki.fi>
Date: Sat Jan 19 23:31:57 2013 +0200
AquaSalBitmap and IosSalBitmap were identical so unify
Call it QuartzSalBitmap. The more we get rid of that "Aqua" term the
better. Aqua is the name of a visual theme, not of an API. The Quartz
2D API is shared between OS X and iOS.
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 29f764f..2454fc3 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -439,7 +439,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/aqua/source/dtrans/PictToBmpFlt \
vcl/aqua/source/dtrans/aqua_clipboard \
vcl/aqua/source/dtrans/service_entry \
- vcl/aqua/source/gdi/salbmp \
+ vcl/quartz/salbmp \
vcl/aqua/source/gdi/salcolorutils \
vcl/aqua/source/gdi/salgdicommon \
vcl/aqua/source/gdi/salgdiutils \
@@ -605,7 +605,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/coretext/salcoretextfontutils \
vcl/coretext//salcoretextlayout \
vcl/coretext//salcoretextstyle \
- vcl/ios/source/gdi/salbmp \
+ vcl/quartz/salbmp \
vcl/coretext/salgdi \
vcl/ios/source/gdi/salgdicommon \
vcl/ios/source/gdi/salnativewidgets \
diff --git a/vcl/aqua/source/app/salinst.cxx b/vcl/aqua/source/app/salinst.cxx
index 715005d..6ff8aea 100644
--- a/vcl/aqua/source/app/salinst.cxx
+++ b/vcl/aqua/source/app/salinst.cxx
@@ -39,7 +39,7 @@
#include "aqua/salobj.h"
#include "aqua/salsys.h"
#include "aqua/salvd.h"
-#include "aqua/salbmp.h"
+#include "quartz/salbmp.h"
#include "aqua/salprn.h"
#include "aqua/saltimer.h"
#include "aqua/vclnsapp.h"
@@ -1149,7 +1149,7 @@ SalSystem* AquaSalInstance::CreateSalSystem()
SalBitmap* AquaSalInstance::CreateSalBitmap()
{
- return new AquaSalBitmap();
+ return new QuartzSalBitmap();
}
// -----------------------------------------------------------------------
@@ -1249,7 +1249,7 @@ CGImageRef CreateCGImage( const Image& rImage )
return NULL;
// simple case, no transparency
- AquaSalBitmap* pSalBmp = static_cast<AquaSalBitmap*>(aBmp.ImplGetImpBitmap()->ImplGetSalBitmap());
+ QuartzSalBitmap* pSalBmp = static_cast<QuartzSalBitmap*>(aBmp.ImplGetImpBitmap()->ImplGetSalBitmap());
if( ! pSalBmp )
return NULL;
@@ -1261,7 +1261,7 @@ CGImageRef CreateCGImage( const Image& rImage )
{
AlphaMask aAlphaMask( aBmpEx.GetAlpha() );
Bitmap aMask( aAlphaMask.GetBitmap() );
- AquaSalBitmap* pMaskBmp = static_cast<AquaSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
+ QuartzSalBitmap* pMaskBmp = static_cast<QuartzSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
if( pMaskBmp )
xImage = pSalBmp->CreateWithMask( *pMaskBmp, 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else
@@ -1270,7 +1270,7 @@ CGImageRef CreateCGImage( const Image& rImage )
else if( aBmpEx.GetTransparentType() == TRANSPARENT_BITMAP )
{
Bitmap aMask( aBmpEx.GetMask() );
- AquaSalBitmap* pMaskBmp = static_cast<AquaSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
+ QuartzSalBitmap* pMaskBmp = static_cast<QuartzSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
if( pMaskBmp )
xImage = pSalBmp->CreateWithMask( *pMaskBmp, 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else
diff --git a/vcl/aqua/source/gdi/salbmp.cxx b/vcl/aqua/source/gdi/salbmp.cxx
deleted file mode 100644
index 8d8afa2..0000000
--- a/vcl/aqua/source/gdi/salbmp.cxx
+++ /dev/null
@@ -1,903 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-
-#include "basebmp/scanlineformats.hxx"
-#include "basebmp/color.hxx"
-
-#include "basegfx/vector/b2ivector.hxx"
-
-#include "tools/color.hxx"
-
-#include "vcl/bitmap.hxx" // for BitmapSystemData
-#include "vcl/salbtype.hxx"
-
-#include "aqua/salbmp.h"
-#include "aqua/salinst.h"
-
-#include "bmpfast.hxx"
-
-// =======================================================================
-
-static bool isValidBitCount( sal_uInt16 nBitCount )
-{
- return (nBitCount == 1) || (nBitCount == 4) || (nBitCount == 8) || (nBitCount == 16) || (nBitCount == 24) || (nBitCount == 32);
-}
-
-// =======================================================================
-
-AquaSalBitmap::AquaSalBitmap()
-: mxGraphicContext( NULL )
-, mxCachedImage( NULL )
-, mnBits(0)
-, mnWidth(0)
-, mnHeight(0)
-, mnBytesPerRow(0)
-{
-}
-
-// ------------------------------------------------------------------
-
-AquaSalBitmap::~AquaSalBitmap()
-{
- Destroy();
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::Create( CGLayerRef xLayer, int nBitmapBits,
- int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/ )
-{
- DBG_ASSERT( xLayer, "AquaSalBitmap::Create() from non-layered context" );
-
- // sanitize input parameters
- if( nX < 0 )
- nWidth += nX, nX = 0;
- if( nY < 0 )
- nHeight += nY, nY = 0;
- const CGSize aLayerSize = CGLayerGetSize( xLayer );
- if( nWidth >= (int)aLayerSize.width - nX )
- nWidth = (int)aLayerSize.width - nX;
- if( nHeight >= (int)aLayerSize.height - nY )
- nHeight = (int)aLayerSize.height - nY;
- if( (nWidth < 0) || (nHeight < 0) )
- nWidth = nHeight = 0;
-
- // initialize properties
- mnWidth = nWidth;
- mnHeight = nHeight;
- mnBits = nBitmapBits ? nBitmapBits : 32;
-
- // initialize drawing context
- CreateContext();
-
- // copy layer content into the bitmap buffer
- const CGPoint aSrcPoint = { static_cast<CGFloat>(-nX), static_cast<CGFloat>(-nY) };
- ::CGContextDrawLayerAtPoint( mxGraphicContext, aSrcPoint, xLayer );
- return true;
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::Create( const Size& rSize, sal_uInt16 nBits, const BitmapPalette& rBitmapPalette )
-{
- if( !isValidBitCount( nBits ) )
- return false;
- maPalette = rBitmapPalette;
- mnBits = nBits;
- mnWidth = rSize.Width();
- mnHeight = rSize.Height();
- return AllocateUserData();
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::Create( const SalBitmap& rSalBmp )
-{
- return Create( rSalBmp, rSalBmp.GetBitCount() );
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics )
-{
- return Create( rSalBmp, pGraphics ? pGraphics->GetBitCount() : rSalBmp.GetBitCount() );
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount )
-{
- const AquaSalBitmap& rSourceBitmap = static_cast<const AquaSalBitmap&>(rSalBmp);
-
- if( isValidBitCount( nNewBitCount ) && rSourceBitmap.maUserBuffer.get() )
- {
- mnBits = nNewBitCount;
- mnWidth = rSourceBitmap.mnWidth;
- mnHeight = rSourceBitmap.mnHeight;
- maPalette = rSourceBitmap.maPalette;
-
- if( AllocateUserData() )
- {
- ConvertBitmapData( mnWidth, mnHeight, mnBits, mnBytesPerRow, maPalette, maUserBuffer.get(), rSourceBitmap.mnBits, rSourceBitmap.mnBytesPerRow, rSourceBitmap.maPalette, rSourceBitmap.maUserBuffer.get() );
- return true;
- }
- }
- return false;
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
-{
- return false;
-}
-
-// ------------------------------------------------------------------
-
-void AquaSalBitmap::Destroy()
-{
- DestroyContext();
- maUserBuffer.reset();
-}
-
-// ------------------------------------------------------------------
-
-void AquaSalBitmap::DestroyContext()
-{
- CGImageRelease( mxCachedImage );
- mxCachedImage = NULL;
-
- if( mxGraphicContext )
- {
- CGContextRelease( mxGraphicContext );
- mxGraphicContext = NULL;
- maContextBuffer.reset();
- }
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::CreateContext()
-{
- DestroyContext();
-
- // prepare graphics context
- // convert image from user input if available
- const bool bSkipConversion = !maUserBuffer;
- if( bSkipConversion )
- AllocateUserData();
-
- // default to RGBA color space
- CGColorSpaceRef aCGColorSpace = GetSalData()->mxRGBSpace;
- CGBitmapInfo aCGBmpInfo = kCGImageAlphaNoneSkipFirst;
-
- // convert data into something accepted by CGBitmapContextCreate()
- size_t bitsPerComponent = (mnBits == 16) ? 5 : 8;
- sal_uInt32 nContextBytesPerRow = mnBytesPerRow;
- if( (mnBits == 16) || (mnBits == 32) )
- {
- // no conversion needed for truecolor
- maContextBuffer = maUserBuffer;
- }
- else if( (mnBits == 8) && maPalette.IsGreyPalette() )
- {
- // no conversion needed for grayscale
- maContextBuffer = maUserBuffer;
- aCGColorSpace = GetSalData()->mxGraySpace;
- aCGBmpInfo = kCGImageAlphaNone;
- bitsPerComponent = mnBits;
- }
- // TODO: is special handling for 1bit input buffers worth it?
- else
- {
- // convert user data to 32 bit
- nContextBytesPerRow = mnWidth << 2;
- try
- {
- maContextBuffer.reset( new sal_uInt8[ mnHeight * nContextBytesPerRow ] );
-
- if( !bSkipConversion )
- ConvertBitmapData( mnWidth, mnHeight,
- 32, nContextBytesPerRow, maPalette, maContextBuffer.get(),
- mnBits, mnBytesPerRow, maPalette, maUserBuffer.get() );
- }
- catch( const std::bad_alloc& )
- {
- mxGraphicContext = 0;
- }
- }
-
- if( maContextBuffer.get() )
- {
- mxGraphicContext = ::CGBitmapContextCreate( maContextBuffer.get(), mnWidth, mnHeight,
- bitsPerComponent, nContextBytesPerRow, aCGColorSpace, aCGBmpInfo );
- }
-
- if( !mxGraphicContext )
- maContextBuffer.reset();
-
- return mxGraphicContext != NULL;
-}
-
-// ------------------------------------------------------------------
-
-bool AquaSalBitmap::AllocateUserData()
-{
- Destroy();
-
- if( mnWidth && mnHeight )
- {
- mnBytesPerRow = 0;
-
- switch( mnBits )
- {
- case 1: mnBytesPerRow = (mnWidth + 7) >> 3; break;
- case 4: mnBytesPerRow = (mnWidth + 1) >> 1; break;
- case 8: mnBytesPerRow = mnWidth; break;
- case 16: mnBytesPerRow = mnWidth << 1; break;
- case 24: mnBytesPerRow = (mnWidth << 1) + mnWidth; break;
- case 32: mnBytesPerRow = mnWidth << 2; break;
- default:
- OSL_FAIL("vcl::AquaSalBitmap::AllocateUserData(), illegal bitcount!");
- }
- }
-
- try
- {
- if( mnBytesPerRow )
- maUserBuffer.reset( new sal_uInt8[mnBytesPerRow * mnHeight] );
- }
- catch( const std::bad_alloc& )
- {
- OSL_FAIL( "vcl::AquaSalBitmap::AllocateUserData: bad alloc" );
- maUserBuffer.reset( NULL );
- mnBytesPerRow = 0;
- }
-
- return maUserBuffer.get() != 0;
-}
-
-// ------------------------------------------------------------------
-
-class ImplPixelFormat
-{
-protected:
- sal_uInt8* pData;
-public:
- static ImplPixelFormat* GetFormat( sal_uInt16 nBits, const BitmapPalette& rPalette );
-
- virtual void StartLine( sal_uInt8* pLine ) { pData = pLine; }
- virtual void SkipPixel( sal_uInt32 nPixel ) = 0;
- virtual ColorData ReadPixel() = 0;
- virtual void WritePixel( ColorData nColor ) = 0;
- virtual ~ImplPixelFormat() { }
-};
-
-class ImplPixelFormat32 : public ImplPixelFormat
-// currently ARGB-format for 32bit depth
-{
-public:
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += nPixel << 2;
- }
- virtual ColorData ReadPixel()
- {
- const ColorData c = RGB_COLORDATA( pData[1], pData[2], pData[3] );
- pData += 4;
- return c;
- }
- virtual void WritePixel( ColorData nColor )
- {
- *pData++ = 0;
- *pData++ = COLORDATA_RED( nColor );
- *pData++ = COLORDATA_GREEN( nColor );
- *pData++ = COLORDATA_BLUE( nColor );
- }
-};
-
-class ImplPixelFormat24 : public ImplPixelFormat
-// currently BGR-format for 24bit depth
-{
-public:
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += (nPixel << 1) + nPixel;
- }
- virtual ColorData ReadPixel()
- {
- const ColorData c = RGB_COLORDATA( pData[2], pData[1], pData[0] );
- pData += 3;
- return c;
- }
- virtual void WritePixel( ColorData nColor )
- {
- *pData++ = COLORDATA_BLUE( nColor );
- *pData++ = COLORDATA_GREEN( nColor );
- *pData++ = COLORDATA_RED( nColor );
- }
-};
-
-class ImplPixelFormat16 : public ImplPixelFormat
-// currently R5G6B5-format for 16bit depth
-{
-protected:
- sal_uInt16* pData16;
-public:
-
- virtual void StartLine( sal_uInt8* pLine )
- {
- pData16 = (sal_uInt16*)pLine;
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += nPixel;
- }
- virtual ColorData ReadPixel()
- {
- const ColorData c = RGB_COLORDATA( (*pData & 0x7c00) >> 7, (*pData & 0x03e0) >> 2 , (*pData & 0x001f) << 3 );
- pData++;
- return c;
- }
- virtual void WritePixel( ColorData nColor )
- {
- *pData++ = ((COLORDATA_RED( nColor ) & 0xf8 ) << 7 ) ||
- ((COLORDATA_GREEN( nColor ) & 0xf8 ) << 2 ) ||
- ((COLORDATA_BLUE( nColor ) & 0xf8 ) >> 3 );
- }
-};
-
-class ImplPixelFormat8 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
-
-public:
- ImplPixelFormat8( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += nPixel;
- }
- virtual ColorData ReadPixel()
- {
- return mrPalette[ *pData++ ].operator Color().GetColor();
- }
- virtual void WritePixel( ColorData nColor )
- {
- const BitmapColor aColor( COLORDATA_RED( nColor ), COLORDATA_GREEN( nColor ), COLORDATA_BLUE( nColor ) );
- *pData++ = static_cast< sal_uInt8 >( mrPalette.GetBestIndex( aColor ) );
- }
-};
-
-class ImplPixelFormat4 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
- sal_uInt32 mnX;
- sal_uInt32 mnShift;
-
-public:
- ImplPixelFormat4( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- mnX += nPixel;
- if( (nPixel & 1) )
- mnShift ^= 4;
- }
- virtual void StartLine( sal_uInt8* pLine )
- {
- pData = pLine;
- mnX = 0;
- mnShift = 4;
- }
- virtual ColorData ReadPixel()
- {
- const BitmapColor& rColor = mrPalette[( pData[mnX >> 1] >> mnShift) & 0x0f];
- mnX++;
- mnShift ^= 4;
- return rColor.operator Color().GetColor();
- }
- virtual void WritePixel( ColorData nColor )
- {
- const BitmapColor aColor( COLORDATA_RED( nColor ), COLORDATA_GREEN( nColor ), COLORDATA_BLUE( nColor ) );
- pData[mnX>>1] &= (0xf0 >> mnShift);
- pData[mnX>>1] |= (static_cast< sal_uInt8 >( mrPalette.GetBestIndex( aColor ) ) & 0x0f);
- mnX++;
- mnShift ^= 4;
- }
-};
-
-class ImplPixelFormat1 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
- sal_uInt32 mnX;
-
-public:
- ImplPixelFormat1( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- mnX += nPixel;
- }
- virtual void StartLine( sal_uInt8* pLine )
- {
- pData = pLine;
- mnX = 0;
- }
- virtual ColorData ReadPixel()
- {
- const BitmapColor& rColor = mrPalette[ (pData[mnX >> 3 ] >> ( 7 - ( mnX & 7 ) )) & 1];
- mnX++;
- return rColor.operator Color().GetColor();
- }
- virtual void WritePixel( ColorData nColor )
- {
- const BitmapColor aColor( COLORDATA_RED( nColor ), COLORDATA_GREEN( nColor ), COLORDATA_BLUE( nColor ) );
- if( mrPalette.GetBestIndex( aColor ) & 1 )
- pData[ mnX >> 3 ] |= 1 << ( 7 - ( mnX & 7 ) );
- else
- pData[ mnX >> 3 ] &= ~( 1 << ( 7 - ( mnX & 7 ) ) );
- mnX++;
- }
-};
-
-ImplPixelFormat* ImplPixelFormat::GetFormat( sal_uInt16 nBits, const BitmapPalette& rPalette )
-{
- switch( nBits )
- {
- case 1: return new ImplPixelFormat1( rPalette );
- case 4: return new ImplPixelFormat4( rPalette );
- case 8: return new ImplPixelFormat8( rPalette );
- case 16: return new ImplPixelFormat16;
- case 24: return new ImplPixelFormat24;
- case 32: return new ImplPixelFormat32;
- }
-
- return 0;
-}
-
-void AquaSalBitmap::ConvertBitmapData( sal_uInt32 nWidth, sal_uInt32 nHeight,
- sal_uInt16 nDestBits, sal_uInt32 nDestBytesPerRow, const BitmapPalette& rDestPalette, sal_uInt8* pDestData,
- sal_uInt16 nSrcBits, sal_uInt32 nSrcBytesPerRow, const BitmapPalette& rSrcPalette, sal_uInt8* pSrcData )
-
-{
- if( (nDestBytesPerRow == nSrcBytesPerRow) && (nDestBits == nSrcBits) && ((nSrcBits != 8) || (rDestPalette.operator==( rSrcPalette ))) )
- {
- // simple case, same format, so just copy
- memcpy( pDestData, pSrcData, nHeight * nDestBytesPerRow );
- return;
- }
-
- // try accelerated conversion if possible
- // TODO: are other truecolor conversions except BGR->ARGB worth it?
- bool bConverted = false;
- if( (nSrcBits == 24) && (nDestBits == 32) )
- {
- // TODO: extend bmpfast.cxx with a method that can be directly used here
- BitmapBuffer aSrcBuf;
- aSrcBuf.mnFormat = BMP_FORMAT_24BIT_TC_BGR;
- aSrcBuf.mpBits = pSrcData;
- aSrcBuf.mnBitCount = nSrcBits;
- aSrcBuf.mnScanlineSize = nSrcBytesPerRow;
- BitmapBuffer aDstBuf;
- aDstBuf.mnFormat = BMP_FORMAT_32BIT_TC_ARGB;
- aDstBuf.mpBits = pDestData;
- aSrcBuf.mnBitCount = nDestBits;
- aDstBuf.mnScanlineSize = nDestBytesPerRow;
-
- aSrcBuf.mnWidth = aDstBuf.mnWidth = nWidth;
- aSrcBuf.mnHeight = aDstBuf.mnHeight = nHeight;
-
- SalTwoRect aTwoRects;
- aTwoRects.mnSrcX = aTwoRects.mnDestX = 0;
- aTwoRects.mnSrcY = aTwoRects.mnDestY = 0;
- aTwoRects.mnSrcWidth = aTwoRects.mnDestWidth = mnWidth;
- aTwoRects.mnSrcHeight = aTwoRects.mnDestHeight = mnHeight;
- bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );
- }
-
- if( !bConverted )
- {
- // TODO: this implementation is for clarety, not for speed
-
- ImplPixelFormat* pD = ImplPixelFormat::GetFormat( nDestBits, rDestPalette );
- ImplPixelFormat* pS = ImplPixelFormat::GetFormat( nSrcBits, rSrcPalette );
-
- if( pD && pS )
- {
- sal_uInt32 nY = nHeight;
- while( nY-- )
- {
- pD->StartLine( pDestData );
- pS->StartLine( pSrcData );
-
- sal_uInt32 nX = nWidth;
- while( nX-- )
- pD->WritePixel( pS->ReadPixel() );
-
- pSrcData += nSrcBytesPerRow;
- pDestData += nDestBytesPerRow;
- }
- }
- delete pS;
- delete pD;
- }
-}
-
-// ------------------------------------------------------------------
-
-Size AquaSalBitmap::GetSize() const
-{
- return Size( mnWidth, mnHeight );
-}
-
-// ------------------------------------------------------------------
-
-sal_uInt16 AquaSalBitmap::GetBitCount() const
-{
- return mnBits;
-}
-
-// ------------------------------------------------------------------
-
-static struct pal_entry
-{
- sal_uInt8 mnRed;
- sal_uInt8 mnGreen;
- sal_uInt8 mnBlue;
-}
-const aImplSalSysPalEntryAry[ 16 ] =
-{
-{ 0, 0, 0 },
-{ 0, 0, 0x80 },
-{ 0, 0x80, 0 },
-{ 0, 0x80, 0x80 },
-{ 0x80, 0, 0 },
-{ 0x80, 0, 0x80 },
-{ 0x80, 0x80, 0 },
-{ 0x80, 0x80, 0x80 },
-{ 0xC0, 0xC0, 0xC0 },
-{ 0, 0, 0xFF },
-{ 0, 0xFF, 0 },
-{ 0, 0xFF, 0xFF },
-{ 0xFF, 0, 0 },
-{ 0xFF, 0, 0xFF },
-{ 0xFF, 0xFF, 0 },
-{ 0xFF, 0xFF, 0xFF }
-};
-
-const BitmapPalette& GetDefaultPalette( int mnBits, bool bMonochrome )
-{
- if( bMonochrome )
- return Bitmap::GetGreyPalette( 1U << mnBits );
-
- // at this point we should provide some kind of default palette
- // since all other platforms do so, too.
- static bool bDefPalInit = false;
- static BitmapPalette aDefPalette256;
- static BitmapPalette aDefPalette16;
- static BitmapPalette aDefPalette2;
- if( ! bDefPalInit )
- {
- bDefPalInit = true;
- aDefPalette256.SetEntryCount( 256 );
- aDefPalette16.SetEntryCount( 16 );
- aDefPalette2.SetEntryCount( 2 );
-
- // Standard colors
- unsigned int i;
- for( i = 0; i < 16; i++ )
- {
- aDefPalette16[i] =
- aDefPalette256[i] = BitmapColor( aImplSalSysPalEntryAry[i].mnRed,
- aImplSalSysPalEntryAry[i].mnGreen,
- aImplSalSysPalEntryAry[i].mnBlue );
- }
-
- aDefPalette2[0] = BitmapColor( 0, 0, 0 );
- aDefPalette2[1] = BitmapColor( 0xff, 0xff, 0xff );
-
- // own palette (6/6/6)
- const int DITHER_PAL_STEPS = 6;
- const sal_uInt8 DITHER_PAL_DELTA = 51;
- int nB, nG, nR;
- sal_uInt8 nRed, nGreen, nBlue;
- for( nB=0, nBlue=0; nB < DITHER_PAL_STEPS; nB++, nBlue += DITHER_PAL_DELTA )
- {
- for( nG=0, nGreen=0; nG < DITHER_PAL_STEPS; nG++, nGreen += DITHER_PAL_DELTA )
- {
- for( nR=0, nRed=0; nR < DITHER_PAL_STEPS; nR++, nRed += DITHER_PAL_DELTA )
- {
- aDefPalette256[ i ] = BitmapColor( nRed, nGreen, nBlue );
- i++;
- }
- }
- }
- }
-
- // now fill in appropriate palette
- switch( mnBits )
- {
- case 1: return aDefPalette2;
- case 4: return aDefPalette16;
- case 8: return aDefPalette256;
- default: break;
- }
-
- const static BitmapPalette aEmptyPalette;
- return aEmptyPalette;
-}
-
-BitmapBuffer* AquaSalBitmap::AcquireBuffer( bool /*bReadOnly*/ )
-{
- if( !maUserBuffer.get() )
-// || maContextBuffer.get() && (maUserBuffer.get() != maContextBuffer.get()) )
- {
- fprintf(stderr,"ASB::Acq(%dx%d,d=%d)\n",mnWidth,mnHeight,mnBits);
- // TODO: AllocateUserData();
- return NULL;
- }
-
- BitmapBuffer* pBuffer = new BitmapBuffer;
- pBuffer->mnWidth = mnWidth;
- pBuffer->mnHeight = mnHeight;
- pBuffer->maPalette = maPalette;
- pBuffer->mnScanlineSize = mnBytesPerRow;
- pBuffer->mpBits = maUserBuffer.get();
- pBuffer->mnBitCount = mnBits;
- switch( mnBits )
- {
- case 1: pBuffer->mnFormat = BMP_FORMAT_1BIT_MSB_PAL; break;
- case 4: pBuffer->mnFormat = BMP_FORMAT_4BIT_MSN_PAL; break;
- case 8: pBuffer->mnFormat = BMP_FORMAT_8BIT_PAL; break;
- case 16: pBuffer->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
- pBuffer->maColorMask = ColorMask( k16BitRedColorMask, k16BitGreenColorMask, k16BitBlueColorMask );
- break;
- case 24: pBuffer->mnFormat = BMP_FORMAT_24BIT_TC_BGR; break;
- case 32: pBuffer->mnFormat = BMP_FORMAT_32BIT_TC_ARGB;
- pBuffer->maColorMask = ColorMask( k32BitRedColorMask, k32BitGreenColorMask, k32BitBlueColorMask );
- break;
- }
- pBuffer->mnFormat |= BMP_FORMAT_BOTTOM_UP;
-
- // some BitmapBuffer users depend on a complete palette
- if( (mnBits <= 8) && !maPalette )
- pBuffer->maPalette = GetDefaultPalette( mnBits, true );
-
- return pBuffer;
-}
-
-// ------------------------------------------------------------------
-
-void AquaSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
-{
- // invalidate graphic context if we have different data
- if( !bReadOnly )
- {
- maPalette = pBuffer->maPalette;
- if( mxGraphicContext )
- DestroyContext();
- }
-
- delete pBuffer;
-}
-
-// ------------------------------------------------------------------
-
-CGImageRef AquaSalBitmap::CreateCroppedImage( int nX, int nY, int nNewWidth, int nNewHeight ) const
-{
- if( !mxCachedImage )
- {
- if( !mxGraphicContext )
- if( !const_cast<AquaSalBitmap*>(this)->CreateContext() )
- return NULL;
-
- mxCachedImage = CGBitmapContextCreateImage( mxGraphicContext );
- }
-
- CGImageRef xCroppedImage = NULL;
- // short circuit if there is nothing to crop
- if( !nX && !nY && (mnWidth == nNewWidth) && (mnHeight == nNewHeight) )
- {
- xCroppedImage = mxCachedImage;
- CFRetain( xCroppedImage );
- }
- else
- {
- nY = mnHeight - (nY + nNewHeight); // adjust for y-mirrored context
- const CGRect aCropRect = { { static_cast<CGFloat>(nX), static_cast<CGFloat>(nY) }, { static_cast<CGFloat>(nNewWidth), static_cast<CGFloat>(nNewHeight) } };
- xCroppedImage = CGImageCreateWithImageInRect( mxCachedImage, aCropRect );
- }
-
- return xCroppedImage;
-}
-
-// ------------------------------------------------------------------
-
-static void CFRTLFree(void* /*info*/, const void* data, size_t /*size*/)
-{
- rtl_freeMemory( const_cast<void*>(data) );
-}
-
-CGImageRef AquaSalBitmap::CreateWithMask( const AquaSalBitmap& rMask,
- int nX, int nY, int nWidth, int nHeight ) const
-{
- CGImageRef xImage( CreateCroppedImage( nX, nY, nWidth, nHeight ) );
- if( !xImage )
- return NULL;
-
- CGImageRef xMask = rMask.CreateCroppedImage( nX, nY, nWidth, nHeight );
- if( !xMask )
- return xImage;
-
- // CGImageCreateWithMask() only likes masks or greyscale images => convert if needed
- // TODO: isolate in an extra method?
- if( !CGImageIsMask(xMask) || (CGImageGetColorSpace(xMask) != GetSalData()->mxGraySpace) )
- {
- const CGRect xImageRect=CGRectMake( 0, 0, nWidth, nHeight );//the rect has no offset
-
- // create the alpha mask image fitting our image
- // TODO: is caching the full mask or the subimage mask worth it?
- int nMaskBytesPerRow = ((nWidth + 3) & ~3);
- void* pMaskMem = rtl_allocateMemory( nMaskBytesPerRow * nHeight );
- CGContextRef xMaskContext = CGBitmapContextCreate( pMaskMem,
- nWidth, nHeight, 8, nMaskBytesPerRow, GetSalData()->mxGraySpace, kCGImageAlphaNone );
- CGContextDrawImage( xMaskContext, xImageRect, xMask );
- CFRelease( xMask );
- CGDataProviderRef xDataProvider( CGDataProviderCreateWithData( NULL,
- pMaskMem, nHeight * nMaskBytesPerRow, &CFRTLFree ) );
- static const CGFloat* pDecode = NULL;
- xMask = CGImageMaskCreate( nWidth, nHeight, 8, 8, nMaskBytesPerRow, xDataProvider, pDecode, false );
- CFRelease( xDataProvider );
- CFRelease( xMaskContext );
- }
-
- if( !xMask )
- return xImage;
-
- // combine image and alpha mask
- CGImageRef xMaskedImage = CGImageCreateWithMask( xImage, xMask );
- CFRelease( xMask );
- CFRelease( xImage );
- return xMaskedImage;
-}
-
-// ------------------------------------------------------------------
-
-/** 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
-{
- CGImageRef xMask = 0;
- if( maUserBuffer.get() && (nX + nWidth <= mnWidth) && (nY + nHeight <= mnHeight) )
- {
- const sal_uInt32 nDestBytesPerRow = nWidth << 2;
- sal_uInt32* pMaskBuffer = static_cast<sal_uInt32*>( rtl_allocateMemory( nHeight * nDestBytesPerRow ) );
- sal_uInt32* pDest = pMaskBuffer;
-
- ImplPixelFormat* pSourcePixels = ImplPixelFormat::GetFormat( mnBits, maPalette );
-
- if( pMaskBuffer && pSourcePixels )
- {
- sal_uInt32 nColor;
- reinterpret_cast<sal_uInt8*>(&nColor)[0] = 0xff;
- reinterpret_cast<sal_uInt8*>(&nColor)[1] = SALCOLOR_RED( nMaskColor );
- reinterpret_cast<sal_uInt8*>(&nColor)[2] = SALCOLOR_GREEN( nMaskColor );
- reinterpret_cast<sal_uInt8*>(&nColor)[3] = SALCOLOR_BLUE( nMaskColor );
-
- sal_uInt8* pSource = maUserBuffer.get();
- if( nY )
- pSource += nY * mnBytesPerRow;
-
- int y = nHeight;
- while( y-- )
- {
- pSourcePixels->StartLine( pSource );
- pSourcePixels->SkipPixel(nX);
- sal_uInt32 x = nWidth;
- while( x-- )
- {
- *pDest++ = ( pSourcePixels->ReadPixel() == 0 ) ? nColor : 0;
- }
- pSource += mnBytesPerRow;
- }
-
- CGDataProviderRef xDataProvider( CGDataProviderCreateWithData(NULL, pMaskBuffer, nHeight * nDestBytesPerRow, &CFRTLFree) );
- xMask = CGImageCreate(nWidth, nHeight, 8, 32, nDestBytesPerRow, GetSalData()->mxRGBSpace, kCGImageAlphaPremultipliedFirst, xDataProvider, NULL, true, kCGRenderingIntentDefault);
- CFRelease(xDataProvider);
- }
- else
- {
- free(pMaskBuffer);
- }
-
- delete pSourcePixels;
- }
- return xMask;
-}
-
-// =======================================================================
-
-/** AquaSalBitmap::GetSystemData Get platform native image data from existing image
- *
- * @param rData struct BitmapSystemData, defined in vcl/inc/bitmap.hxx
- * @return true if successful
-**/
-bool AquaSalBitmap::GetSystemData( BitmapSystemData& rData )
-{
- bool bRet = false;
-
- if( !mxGraphicContext )
- CreateContext();
-
- if ( mxGraphicContext )
- {
- bRet = true;
-
- if ((CGBitmapContextGetBitsPerPixel(mxGraphicContext) == 32) &&
- (CGBitmapContextGetBitmapInfo(mxGraphicContext) & kCGBitmapByteOrderMask) != kCGBitmapByteOrder32Host) {
- /**
- * We need to hack things because VCL does not use kCGBitmapByteOrder32Host, while Cairo requires it.
- */
- OSL_TRACE("AquaSalBitmap::%s(): kCGBitmapByteOrder32Host not found => inserting it.",__func__);
-
- CGImageRef xImage = CGBitmapContextCreateImage (mxGraphicContext);
-
- // re-create the context with single change: include kCGBitmapByteOrder32Host flag.
- CGContextRef mxGraphicContextNew = CGBitmapContextCreate( CGBitmapContextGetData(mxGraphicContext),
- CGBitmapContextGetWidth(mxGraphicContext),
- CGBitmapContextGetHeight(mxGraphicContext),
- CGBitmapContextGetBitsPerComponent(mxGraphicContext),
- CGBitmapContextGetBytesPerRow(mxGraphicContext),
- CGBitmapContextGetColorSpace(mxGraphicContext),
- CGBitmapContextGetBitmapInfo(mxGraphicContext) | kCGBitmapByteOrder32Host);
- CFRelease(mxGraphicContext);
-
- // Needs to be flipped
- CGContextSaveGState( mxGraphicContextNew );
- CGContextTranslateCTM (mxGraphicContextNew, 0, CGBitmapContextGetHeight(mxGraphicContextNew));
- CGContextScaleCTM (mxGraphicContextNew, 1.0, -1.0);
-
- CGContextDrawImage(mxGraphicContextNew, CGRectMake( 0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)), xImage);
-
- // Flip back
- CGContextRestoreGState( mxGraphicContextNew );
-
- CGImageRelease( xImage );
- mxGraphicContext = mxGraphicContextNew;
- }
-
- rData.rImageContext = (void *) mxGraphicContext;
- rData.mnWidth = mnWidth;
- rData.mnHeight = mnHeight;
- }
-
- return bRet;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/aqua/source/gdi/salgdicommon.cxx b/vcl/aqua/source/gdi/salgdicommon.cxx
index 4fbca5aa..214a6ab 100644
--- a/vcl/aqua/source/gdi/salgdicommon.cxx
+++ b/vcl/aqua/source/gdi/salgdicommon.cxx
@@ -22,7 +22,7 @@
#include "basegfx/polygon/b2dpolygon.hxx"
-#include "aqua/salbmp.h"
+#include "quartz/salbmp.h"
#include "aqua/salgdi.h"
#include "fontsubset.hxx"
@@ -510,8 +510,8 @@ bool AquaSalGraphics::drawAlphaBitmap( const SalTwoRect& rTR,
return false;
}
- const AquaSalBitmap& rSrcSalBmp = static_cast<const AquaSalBitmap&>(rSrcBitmap);
- const AquaSalBitmap& rMaskSalBmp = static_cast<const AquaSalBitmap&>(rAlphaBmp);
+ const QuartzSalBitmap& rSrcSalBmp = static_cast<const QuartzSalBitmap&>(rSrcBitmap);
+ const QuartzSalBitmap& rMaskSalBmp = static_cast<const QuartzSalBitmap&>(rAlphaBmp);
CGImageRef xMaskedImage = rSrcSalBmp.CreateWithMask( rMaskSalBmp, rTR.mnSrcX,
rTR.mnSrcY, rTR.mnSrcWidth,
rTR.mnSrcHeight );
@@ -564,7 +564,7 @@ void AquaSalGraphics::drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rS
{
return;
}
- const AquaSalBitmap& rBitmap = static_cast<const AquaSalBitmap&>(rSalBitmap);
+ const QuartzSalBitmap& rBitmap = static_cast<const QuartzSalBitmap&>(rSalBitmap);
CGImageRef xImage = rBitmap.CreateCroppedImage( (int)pPosAry->mnSrcX, (int)pPosAry->mnSrcY,
(int)pPosAry->mnSrcWidth, (int)pPosAry->mnSrcHeight );
if( !xImage )
@@ -591,8 +591,8 @@ void AquaSalGraphics::drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rS
{
return;
}
- const AquaSalBitmap& rBitmap = static_cast<const AquaSalBitmap&>(rSalBitmap);
- const AquaSalBitmap& rMask = static_cast<const AquaSalBitmap&>(rTransparentBitmap);
+ const QuartzSalBitmap& rBitmap = static_cast<const QuartzSalBitmap&>(rSalBitmap);
+ const QuartzSalBitmap& rMask = static_cast<const QuartzSalBitmap&>(rTransparentBitmap);
CGImageRef xMaskedImage( rBitmap.CreateWithMask( rMask, pPosAry->mnSrcX, pPosAry->mnSrcY,
pPosAry->mnSrcWidth, pPosAry->mnSrcHeight ) );
if( !xMaskedImage )
@@ -680,7 +680,7 @@ void AquaSalGraphics::drawMask( const SalTwoRect* pPosAry,
{
return;
}
- const AquaSalBitmap& rBitmap = static_cast<const AquaSalBitmap&>(rSalBitmap);
+ const QuartzSalBitmap& rBitmap = static_cast<const QuartzSalBitmap&>(rSalBitmap);
CGImageRef xImage = rBitmap.CreateColorMask( pPosAry->mnSrcX, pPosAry->mnSrcY,
pPosAry->mnSrcWidth, pPosAry->mnSrcHeight,
nMaskColor );
@@ -1083,7 +1083,7 @@ SalBitmap* AquaSalGraphics::getBitmap( long nX, long nY, long nDX, long nDY
ApplyXorContext();
- AquaSalBitmap* pBitmap = new AquaSalBitmap;
+ QuartzSalBitmap* pBitmap = new QuartzSalBitmap;
if( !pBitmap->Create( mxLayer, mnBitmapDepth, nX, nY, nDX, nDY, !mbWindow ) )
{
delete pBitmap;
diff --git a/vcl/aqua/source/gdi/salnativewidgets.cxx b/vcl/aqua/source/gdi/salnativewidgets.cxx
index ad9800f..a2586ac 100644
--- a/vcl/aqua/source/gdi/salnativewidgets.cxx
+++ b/vcl/aqua/source/gdi/salnativewidgets.cxx
@@ -22,7 +22,6 @@
#include "vcl/svapp.hxx"
#include "vcl/timer.hxx"
-#include "aqua/salconst.h"
#include "aqua/salgdi.h"
#include "aqua/salnativewidgets.h"
#include "aqua/saldata.hxx"
diff --git a/vcl/aqua/source/window/salmenu.cxx b/vcl/aqua/source/window/salmenu.cxx
index dda138c..953c386 100644
--- a/vcl/aqua/source/window/salmenu.cxx
+++ b/vcl/aqua/source/window/salmenu.cxx
@@ -31,7 +31,6 @@
#include "aqua/salmenu.h"
#include "aqua/salnsmenu.h"
#include "aqua/salframe.h"
-#include "aqua/salbmp.h"
#include "aqua/aqua11ywrapper.h"
#include "svids.hrc"
diff --git a/vcl/inc/aqua/atsui/salgdi.h b/vcl/inc/aqua/atsui/salgdi.h
index 098eadb..44d433c 100644
--- a/vcl/inc/aqua/atsui/salgdi.h
+++ b/vcl/inc/aqua/atsui/salgdi.h
@@ -38,7 +38,6 @@
#include "aqua/salgdicommon.hxx"
class AquaSalFrame;
-class AquaSalBitmap;
class ImplDevFontAttributes;
struct CGRect;
diff --git a/vcl/inc/aqua/salbmp.h b/vcl/inc/aqua/salbmp.h
deleted file mode 100644
index 0f18c91..0000000
--- a/vcl/inc/aqua/salbmp.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _SV_SALBMP_H
-#define _SV_SALBMP_H
-
-#include "tools/gen.hxx"
-
-#include "basebmp/bitmapdevice.hxx"
-
-#include "vcl/salbtype.hxx"
-
-#include "aqua/salconst.h"
-#include "aqua/salgdi.h"
-
-#include "saldata.hxx"
-#include "salinst.hxx"
-#include "salvd.hxx"
-#include "salbmp.hxx"
-
-#include "salcolorutils.hxx"
-
-
-// --------------
-// - SalBitmap -
-// --------------
-
-struct BitmapBuffer;
-class BitmapColor;
-class BitmapPalette;
-class AquaSalVirtualDevice;
-
-class AquaSalBitmap : public SalBitmap
-{
-public:
- CGContextRef mxGraphicContext;
- mutable CGImageRef mxCachedImage;
- BitmapPalette maPalette;
- basebmp::RawMemorySharedArray maUserBuffer;
- basebmp::RawMemorySharedArray maContextBuffer;
- sal_uInt16 mnBits;
- int mnWidth;
- int mnHeight;
- sal_uInt32 mnBytesPerRow;
-
-public:
- AquaSalBitmap();
- virtual ~AquaSalBitmap();
-
-public:
-
- // SalBitmap methods
- bool Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal );
- bool Create( const SalBitmap& rSalBmp );
- bool Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics );
- bool Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount );
- virtual bool Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > xBitmapCanvas,
- Size& rSize,
- bool bMask = false );
-
- void Destroy();
-
- Size GetSize() const;
- sal_uInt16 GetBitCount() const;
-
- BitmapBuffer *AcquireBuffer( bool bReadOnly );
- void ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly );
-
- bool GetSystemData( BitmapSystemData& rData );
-
-private:
- // quartz helper
- bool CreateContext();
- void DestroyContext();
- bool AllocateUserData();
-
- void ConvertBitmapData( sal_uInt32 nWidth, sal_uInt32 nHeight,
- sal_uInt16 nDestBits, sal_uInt32 nDestBytesPerRow, const BitmapPalette& rDestPalette, sal_uInt8* pDestData,
- sal_uInt16 nSrcBits, sal_uInt32 nSrcBytesPerRow, const BitmapPalette& rSrcPalette, sal_uInt8* pSrcData );
-
-public:
- bool Create( CGLayerRef xLayer, int nBitCount, int nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true );
-
-public:
- CGImageRef CreateWithMask( const AquaSalBitmap& rMask, int nX, int nY, int nWidth, int nHeight ) const;
- CGImageRef CreateColorMask( int nX, int nY, int nWidth, int nHeight, SalColor nMaskColor ) const;
- CGImageRef CreateCroppedImage( int nX, int nY, int nWidth, int nHeight ) const;
-};
-
-#endif // _SV_SALBMP_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/aqua/salcolorutils.hxx b/vcl/inc/aqua/salcolorutils.hxx
index e42340b..bba70e2 100644
--- a/vcl/inc/aqua/salcolorutils.hxx
+++ b/vcl/inc/aqua/salcolorutils.hxx
@@ -30,7 +30,6 @@
#include "vcl/salbtype.hxx"
#include "vcl/salgtype.hxx"
-#include "salconst.h"
#include "salmathutils.hxx"
// ------------------------------------------------------------------
diff --git a/vcl/inc/aqua/salconst.h b/vcl/inc/aqua/salconst.h
deleted file mode 100644
index e46a51a..0000000
--- a/vcl/inc/aqua/salconst.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _SV_SALCONST_H
-#define _SV_SALCONST_H
-
-// -------------------
-// - Constants -
-// -------------------
-
-static const unsigned long k16BitRedColorMask = 0x00007c00;
-static const unsigned long k16BitGreenColorMask = 0x000003e0;
-static const unsigned long k16BitBlueColorMask = 0x0000001f;
-
-static const unsigned long k32BitRedColorMask = 0x00ff0000;
-static const unsigned long k32BitGreenColorMask = 0x0000ff00;
-static const unsigned long k32BitBlueColorMask = 0x000000ff;
-
-#endif // _SV_SALCONST_H
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/aqua/salvd.h b/vcl/inc/aqua/salvd.h
index 3134a79..987636f 100644
--- a/vcl/inc/aqua/salvd.h
+++ b/vcl/inc/aqua/salvd.h
@@ -24,7 +24,6 @@
#include <ApplicationServices/ApplicationServices.h>
#include "postmac.h"
-#include "aqua/salconst.h"
#include "aqua/salcolorutils.hxx"
#include "aqua/salgdi.h"
diff --git a/vcl/inc/ios/salbmp.h b/vcl/inc/ios/salbmp.h
deleted file mode 100644
index 816e523..0000000
--- a/vcl/inc/ios/salbmp.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _SV_SALBMP_H
-#define _SV_SALBMP_H
-
-#include "tools/gen.hxx"
-
-#include "basebmp/bitmapdevice.hxx"
-
-#include "vcl/salbtype.hxx"
-
-#include "ios/salconst.h"
-#include "coretext/salgdi.h"
-
-#include "saldata.hxx"
-#include "salinst.hxx"
-#include "salvd.hxx"
-#include "salbmp.hxx"
-
-#include "salcolorutils.hxx"
-
-
-// --------------
-// - SalBitmap -
-// --------------
-
-struct BitmapBuffer;
-class BitmapColor;
-class BitmapPalette;
-class IosSalVirtualDevice;
-
-class IosSalBitmap : public SalBitmap
-{
-public:
- CGContextRef mxGraphicContext;
- mutable CGImageRef mxCachedImage;
- BitmapPalette maPalette;
- basebmp::RawMemorySharedArray maUserBuffer;
- basebmp::RawMemorySharedArray maContextBuffer;
- sal_uInt16 mnBits;
- int mnWidth;
- int mnHeight;
- sal_uInt32 mnBytesPerRow;
-
-public:
- IosSalBitmap();
- virtual ~IosSalBitmap();
-
-public:
-
- // SalBitmap methods
- bool Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal );
- bool Create( const SalBitmap& rSalBmp );
- bool Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics );
- bool Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount );
- virtual bool Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > xBitmapCanvas,
- Size& rSize,
- bool bMask = false );
-
- void Destroy();
-
- Size GetSize() const;
- sal_uInt16 GetBitCount() const;
-
- BitmapBuffer *AcquireBuffer( bool bReadOnly );
- void ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly );
-
- bool GetSystemData( BitmapSystemData& rData );
-
-private:
- // quartz helper
- bool CreateContext();
- void DestroyContext();
- bool AllocateUserData();
-
- void ConvertBitmapData( sal_uInt32 nWidth, sal_uInt32 nHeight,
- sal_uInt16 nDestBits, sal_uInt32 nDestBytesPerRow, const BitmapPalette& rDestPalette, sal_uInt8* pDestData,
- sal_uInt16 nSrcBits, sal_uInt32 nSrcBytesPerRow, const BitmapPalette& rSrcPalette, sal_uInt8* pSrcData );
-
-public:
- bool Create( CGLayerRef xLayer, int nBitCount, int nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true );
-
-public:
- CGImageRef CreateWithMask( const IosSalBitmap& rMask, int nX, int nY, int nWidth, int nHeight ) const;
- CGImageRef CreateColorMask( int nX, int nY, int nWidth, int nHeight, SalColor nMaskColor ) const;
- CGImageRef CreateCroppedImage( int nX, int nY, int nWidth, int nHeight ) const;
-};
-
-#endif // _SV_SALBMP_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/ios/salconst.h b/vcl/inc/ios/salconst.h
deleted file mode 100644
index e46a51a..0000000
--- a/vcl/inc/ios/salconst.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _SV_SALCONST_H
-#define _SV_SALCONST_H
-
-// -------------------
-// - Constants -
-// -------------------
-
-static const unsigned long k16BitRedColorMask = 0x00007c00;
-static const unsigned long k16BitGreenColorMask = 0x000003e0;
-static const unsigned long k16BitBlueColorMask = 0x0000001f;
-
-static const unsigned long k32BitRedColorMask = 0x00ff0000;
-static const unsigned long k32BitGreenColorMask = 0x0000ff00;
-static const unsigned long k32BitBlueColorMask = 0x000000ff;
-
-#endif // _SV_SALCONST_H
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/quartz/salbmp.h b/vcl/inc/quartz/salbmp.h
new file mode 100644
index 0000000..16460ab
--- /dev/null
+++ b/vcl/inc/quartz/salbmp.h
@@ -0,0 +1,105 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef _VCL_QUARTZ_SALBMP_H
+#define _VCL_QUARTZ_SALBMP_H
+
+#include "tools/gen.hxx"
+
+#include "basebmp/bitmapdevice.hxx"
+
+#include "vcl/salbtype.hxx"
+
+#ifdef MACOSX
+#include "aqua/salgdi.h"
+#else
+#include "coretext/salgdi.h"
+#endif
+
+#include "salinst.hxx"
+#include "salvd.hxx"
+#include "salbmp.hxx"
+
+// --------------
+// - SalBitmap -
+// --------------
+
+struct BitmapBuffer;
+class BitmapPalette;
+
+class QuartzSalBitmap : public SalBitmap
+{
+public:
+ CGContextRef mxGraphicContext;
+ mutable CGImageRef mxCachedImage;
+ BitmapPalette maPalette;
+ basebmp::RawMemorySharedArray maUserBuffer;
+ basebmp::RawMemorySharedArray maContextBuffer;
+ sal_uInt16 mnBits;
+ int mnWidth;
+ int mnHeight;
+ sal_uInt32 mnBytesPerRow;
+
+public:
+ QuartzSalBitmap();
+ virtual ~QuartzSalBitmap();
+
+public:
+
+ // SalBitmap methods
+ bool Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal );
+ bool Create( const SalBitmap& rSalBmp );
+ bool Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics );
+ bool Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount );
+ virtual bool Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > xBitmapCanvas,
+ Size& rSize,
+ bool bMask = false );
+
+ void Destroy();
+
+ Size GetSize() const;
+ sal_uInt16 GetBitCount() const;
+
+ BitmapBuffer *AcquireBuffer( bool bReadOnly );
+ void ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly );
+
+ bool GetSystemData( BitmapSystemData& rData );
+
+private:
+ // quartz helper
+ bool CreateContext();
+ void DestroyContext();
+ bool AllocateUserData();
+
+ void ConvertBitmapData( sal_uInt32 nWidth, sal_uInt32 nHeight,
+ sal_uInt16 nDestBits, sal_uInt32 nDestBytesPerRow, const BitmapPalette& rDestPalette, sal_uInt8* pDestData,
+ sal_uInt16 nSrcBits, sal_uInt32 nSrcBytesPerRow, const BitmapPalette& rSrcPalette, sal_uInt8* pSrcData );
+
+public:
+ bool Create( CGLayerRef xLayer, int nBitCount, int nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true );
+
+public:
+ CGImageRef CreateWithMask( const QuartzSalBitmap& rMask, int nX, int nY, int nWidth, int nHeight ) const;
+ CGImageRef CreateColorMask( int nX, int nY, int nWidth, int nHeight, SalColor nMaskColor ) const;
+ CGImageRef CreateCroppedImage( int nX, int nY, int nWidth, int nHeight ) const;
+};
+
+#endif // _VCL_QUARTZ_SALBMP_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/ios/source/app/salinst.cxx b/vcl/ios/source/app/salinst.cxx
index 0e5c69b..6ff0e84 100644
--- a/vcl/ios/source/app/salinst.cxx
+++ b/vcl/ios/source/app/salinst.cxx
@@ -39,7 +39,7 @@
#include "ios/salobj.h"
#include "ios/salsys.h"
#include "ios/salvd.h"
-#include "ios/salbmp.h"
+#include "quartz/salbmp.h"
#include "ios/salprn.h"
#include "ios/saltimer.h"
#include "ios/vcluiapp.h"
@@ -670,7 +670,7 @@ SalSystem* IosSalInstance::CreateSalSystem()
SalBitmap* IosSalInstance::CreateSalBitmap()
{
- return new IosSalBitmap();
+ return new QuartzSalBitmap();
}
// -----------------------------------------------------------------------
@@ -772,7 +772,7 @@ CGImageRef CreateCGImage( const Image& rImage )
return NULL;
// simple case, no transparency
- IosSalBitmap* pSalBmp = static_cast<IosSalBitmap*>(aBmp.ImplGetImpBitmap()->ImplGetSalBitmap());
+ QuartzSalBitmap* pSalBmp = static_cast<QuartzSalBitmap*>(aBmp.ImplGetImpBitmap()->ImplGetSalBitmap());
if( ! pSalBmp )
return NULL;
@@ -784,7 +784,7 @@ CGImageRef CreateCGImage( const Image& rImage )
{
AlphaMask aAlphaMask( aBmpEx.GetAlpha() );
Bitmap aMask( aAlphaMask.GetBitmap() );
- IosSalBitmap* pMaskBmp = static_cast<IosSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
+ QuartzSalBitmap* pMaskBmp = static_cast<QuartzSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
if( pMaskBmp )
xImage = pSalBmp->CreateWithMask( *pMaskBmp, 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else
@@ -793,7 +793,7 @@ CGImageRef CreateCGImage( const Image& rImage )
else if( aBmpEx.GetTransparentType() == TRANSPARENT_BITMAP )
{
Bitmap aMask( aBmpEx.GetMask() );
- IosSalBitmap* pMaskBmp = static_cast<IosSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
+ QuartzSalBitmap* pMaskBmp = static_cast<QuartzSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
if( pMaskBmp )
xImage = pSalBmp->CreateWithMask( *pMaskBmp, 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else
diff --git a/vcl/ios/source/gdi/salbmp.cxx b/vcl/ios/source/gdi/salbmp.cxx
deleted file mode 100644
index 4bd1d45..0000000
--- a/vcl/ios/source/gdi/salbmp.cxx
+++ /dev/null
@@ -1,903 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-
-#include "basebmp/scanlineformats.hxx"
-#include "basebmp/color.hxx"
-
-#include "basegfx/vector/b2ivector.hxx"
-
-#include "tools/color.hxx"
-
-#include "vcl/bitmap.hxx" // for BitmapSystemData
-#include "vcl/salbtype.hxx"
-
-#include "ios/salbmp.h"
-#include "ios/salinst.h"
-
-#include "bmpfast.hxx"
-
-// =======================================================================
-
-static bool isValidBitCount( sal_uInt16 nBitCount )
-{
- return (nBitCount == 1) || (nBitCount == 4) || (nBitCount == 8) || (nBitCount == 16) || (nBitCount == 24) || (nBitCount == 32);
-}
-
-// =======================================================================
-
-IosSalBitmap::IosSalBitmap()
-: mxGraphicContext( NULL )
-, mxCachedImage( NULL )
-, mnBits(0)
-, mnWidth(0)
-, mnHeight(0)
-, mnBytesPerRow(0)
-{
-}
-
-// ------------------------------------------------------------------
-
-IosSalBitmap::~IosSalBitmap()
-{
- Destroy();
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::Create( CGLayerRef xLayer, int nBitmapBits,
- int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/ )
-{
- DBG_ASSERT( xLayer, "IosSalBitmap::Create() from non-layered context" );
-
- // sanitize input parameters
- if( nX < 0 )
- nWidth += nX, nX = 0;
- if( nY < 0 )
- nHeight += nY, nY = 0;
- const CGSize aLayerSize = CGLayerGetSize( xLayer );
- if( nWidth >= (int)aLayerSize.width - nX )
- nWidth = (int)aLayerSize.width - nX;
- if( nHeight >= (int)aLayerSize.height - nY )
- nHeight = (int)aLayerSize.height - nY;
- if( (nWidth < 0) || (nHeight < 0) )
- nWidth = nHeight = 0;
-
- // initialize properties
- mnWidth = nWidth;
- mnHeight = nHeight;
- mnBits = nBitmapBits ? nBitmapBits : 32;
-
- // initialize drawing context
- CreateContext();
-
- // copy layer content into the bitmap buffer
- const CGPoint aSrcPoint = { static_cast<CGFloat>(-nX), static_cast<CGFloat>(-nY) };
- ::CGContextDrawLayerAtPoint( mxGraphicContext, aSrcPoint, xLayer );
- return true;
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::Create( const Size& rSize, sal_uInt16 nBits, const BitmapPalette& rBitmapPalette )
-{
- if( !isValidBitCount( nBits ) )
- return false;
- maPalette = rBitmapPalette;
- mnBits = nBits;
- mnWidth = rSize.Width();
- mnHeight = rSize.Height();
- return AllocateUserData();
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::Create( const SalBitmap& rSalBmp )
-{
- return Create( rSalBmp, rSalBmp.GetBitCount() );
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics )
-{
- return Create( rSalBmp, pGraphics ? pGraphics->GetBitCount() : rSalBmp.GetBitCount() );
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount )
-{
- const IosSalBitmap& rSourceBitmap = static_cast<const IosSalBitmap&>(rSalBmp);
-
- if( isValidBitCount( nNewBitCount ) && rSourceBitmap.maUserBuffer.get() )
- {
- mnBits = nNewBitCount;
- mnWidth = rSourceBitmap.mnWidth;
- mnHeight = rSourceBitmap.mnHeight;
- maPalette = rSourceBitmap.maPalette;
-
- if( AllocateUserData() )
- {
- ConvertBitmapData( mnWidth, mnHeight, mnBits, mnBytesPerRow, maPalette, maUserBuffer.get(), rSourceBitmap.mnBits, rSourceBitmap.mnBytesPerRow, rSourceBitmap.maPalette, rSourceBitmap.maUserBuffer.get() );
- return true;
- }
- }
- return false;
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
-{
- return false;
-}
-
-// ------------------------------------------------------------------
-
-void IosSalBitmap::Destroy()
-{
- DestroyContext();
- maUserBuffer.reset();
-}
-
-// ------------------------------------------------------------------
-
-void IosSalBitmap::DestroyContext()
-{
- CGImageRelease( mxCachedImage );
- mxCachedImage = NULL;
-
- if( mxGraphicContext )
- {
- CGContextRelease( mxGraphicContext );
- mxGraphicContext = NULL;
- maContextBuffer.reset();
- }
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::CreateContext()
-{
- DestroyContext();
-
- // prepare graphics context
- // convert image from user input if available
- const bool bSkipConversion = !maUserBuffer;
- if( bSkipConversion )
- AllocateUserData();
-
- // default to RGBA color space
- CGColorSpaceRef aCGColorSpace = GetSalData()->mxRGBSpace;
- CGBitmapInfo aCGBmpInfo = kCGImageAlphaNoneSkipFirst;
-
- // convert data into something accepted by CGBitmapContextCreate()
- size_t bitsPerComponent = (mnBits == 16) ? 5 : 8;
- sal_uInt32 nContextBytesPerRow = mnBytesPerRow;
- if( (mnBits == 16) || (mnBits == 32) )
- {
- // no conversion needed for truecolor
- maContextBuffer = maUserBuffer;
- }
- else if( (mnBits == 8) && maPalette.IsGreyPalette() )
- {
- // no conversion needed for grayscale
- maContextBuffer = maUserBuffer;
- aCGColorSpace = GetSalData()->mxGraySpace;
- aCGBmpInfo = kCGImageAlphaNone;
- bitsPerComponent = mnBits;
- }
- // TODO: is special handling for 1bit input buffers worth it?
- else
- {
- // convert user data to 32 bit
- nContextBytesPerRow = mnWidth << 2;
- try
- {
- maContextBuffer.reset( new sal_uInt8[ mnHeight * nContextBytesPerRow ] );
-
- if( !bSkipConversion )
- ConvertBitmapData( mnWidth, mnHeight,
- 32, nContextBytesPerRow, maPalette, maContextBuffer.get(),
- mnBits, mnBytesPerRow, maPalette, maUserBuffer.get() );
- }
- catch( const std::bad_alloc& )
- {
- mxGraphicContext = 0;
- }
- }
-
- if( maContextBuffer.get() )
- {
- mxGraphicContext = ::CGBitmapContextCreate( maContextBuffer.get(), mnWidth, mnHeight,
- bitsPerComponent, nContextBytesPerRow, aCGColorSpace, aCGBmpInfo );
- }
-
- if( !mxGraphicContext )
- maContextBuffer.reset();
-
- return mxGraphicContext != NULL;
-}
-
-// ------------------------------------------------------------------
-
-bool IosSalBitmap::AllocateUserData()
-{
- Destroy();
-
- if( mnWidth && mnHeight )
- {
- mnBytesPerRow = 0;
-
- switch( mnBits )
- {
- case 1: mnBytesPerRow = (mnWidth + 7) >> 3; break;
- case 4: mnBytesPerRow = (mnWidth + 1) >> 1; break;
- case 8: mnBytesPerRow = mnWidth; break;
- case 16: mnBytesPerRow = mnWidth << 1; break;
- case 24: mnBytesPerRow = (mnWidth << 1) + mnWidth; break;
- case 32: mnBytesPerRow = mnWidth << 2; break;
- default:
- OSL_FAIL("vcl::IosSalBitmap::AllocateUserData(), illegal bitcount!");
- }
- }
-
- try
- {
- if( mnBytesPerRow )
- maUserBuffer.reset( new sal_uInt8[mnBytesPerRow * mnHeight] );
- }
- catch( const std::bad_alloc& )
- {
- OSL_FAIL( "vcl::IosSalBitmap::AllocateUserData: bad alloc" );
- maUserBuffer.reset( NULL );
- mnBytesPerRow = 0;
- }
-
- return maUserBuffer.get() != 0;
-}
-
-// ------------------------------------------------------------------
-
-class ImplPixelFormat
-{
-protected:
- sal_uInt8* pData;
-public:
- virtual ~ImplPixelFormat() { }
- static ImplPixelFormat* GetFormat( sal_uInt16 nBits, const BitmapPalette& rPalette );
-
- virtual void StartLine( sal_uInt8* pLine ) { pData = pLine; }
- virtual void SkipPixel( sal_uInt32 nPixel ) = 0;
- virtual ColorData ReadPixel() = 0;
- virtual void WritePixel( ColorData nColor ) = 0;
-};
-
-class ImplPixelFormat32 : public ImplPixelFormat
-// currently ARGB-format for 32bit depth
-{
-public:
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += nPixel << 2;
- }
- virtual ColorData ReadPixel()
- {
- const ColorData c = RGB_COLORDATA( pData[1], pData[2], pData[3] );
- pData += 4;
- return c;
- }
- virtual void WritePixel( ColorData nColor )
- {
- *pData++ = 0;
- *pData++ = COLORDATA_RED( nColor );
- *pData++ = COLORDATA_GREEN( nColor );
- *pData++ = COLORDATA_BLUE( nColor );
- }
-};
-
-class ImplPixelFormat24 : public ImplPixelFormat
-// currently BGR-format for 24bit depth
-{
-public:
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += (nPixel << 1) + nPixel;
- }
- virtual ColorData ReadPixel()
- {
- const ColorData c = RGB_COLORDATA( pData[2], pData[1], pData[0] );
- pData += 3;
- return c;
- }
- virtual void WritePixel( ColorData nColor )
- {
- *pData++ = COLORDATA_BLUE( nColor );
- *pData++ = COLORDATA_GREEN( nColor );
- *pData++ = COLORDATA_RED( nColor );
- }
-};
-
-class ImplPixelFormat16 : public ImplPixelFormat
-// currently R5G6B5-format for 16bit depth
-{
-protected:
- sal_uInt16* pData16;
-public:
-
- virtual void StartLine( sal_uInt8* pLine )
- {
- pData16 = (sal_uInt16*)pLine;
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += nPixel;
- }
- virtual ColorData ReadPixel()
- {
- const ColorData c = RGB_COLORDATA( (*pData & 0x7c00) >> 7, (*pData & 0x03e0) >> 2 , (*pData & 0x001f) << 3 );
- pData++;
- return c;
- }
- virtual void WritePixel( ColorData nColor )
- {
- *pData++ = ((COLORDATA_RED( nColor ) & 0xf8 ) << 7 ) ||
- ((COLORDATA_GREEN( nColor ) & 0xf8 ) << 2 ) ||
- ((COLORDATA_BLUE( nColor ) & 0xf8 ) >> 3 );
- }
-};
-
-class ImplPixelFormat8 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
-
-public:
- ImplPixelFormat8( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- pData += nPixel;
- }
- virtual ColorData ReadPixel()
- {
- return mrPalette[ *pData++ ].operator Color().GetColor();
- }
- virtual void WritePixel( ColorData nColor )
- {
- const BitmapColor aColor( COLORDATA_RED( nColor ), COLORDATA_GREEN( nColor ), COLORDATA_BLUE( nColor ) );
- *pData++ = static_cast< sal_uInt8 >( mrPalette.GetBestIndex( aColor ) );
- }
-};
-
-class ImplPixelFormat4 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
- sal_uInt32 mnX;
- sal_uInt32 mnShift;
-
-public:
- ImplPixelFormat4( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- mnX += nPixel;
- if( (nPixel & 1) )
- mnShift ^= 4;
- }
- virtual void StartLine( sal_uInt8* pLine )
- {
- pData = pLine;
- mnX = 0;
- mnShift = 4;
- }
- virtual ColorData ReadPixel()
- {
- const BitmapColor& rColor = mrPalette[( pData[mnX >> 1] >> mnShift) & 0x0f];
- mnX++;
- mnShift ^= 4;
- return rColor.operator Color().GetColor();
- }
- virtual void WritePixel( ColorData nColor )
- {
- const BitmapColor aColor( COLORDATA_RED( nColor ), COLORDATA_GREEN( nColor ), COLORDATA_BLUE( nColor ) );
- pData[mnX>>1] &= (0xf0 >> mnShift);
- pData[mnX>>1] |= (static_cast< sal_uInt8 >( mrPalette.GetBestIndex( aColor ) ) & 0x0f);
- mnX++;
- mnShift ^= 4;
- }
-};
-
-class ImplPixelFormat1 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
- sal_uInt32 mnX;
-
-public:
- ImplPixelFormat1( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual void SkipPixel( sal_uInt32 nPixel )
- {
- mnX += nPixel;
- }
- virtual void StartLine( sal_uInt8* pLine )
- {
- pData = pLine;
- mnX = 0;
- }
- virtual ColorData ReadPixel()
- {
- const BitmapColor& rColor = mrPalette[ (pData[mnX >> 3 ] >> ( 7 - ( mnX & 7 ) )) & 1];
- mnX++;
- return rColor.operator Color().GetColor();
- }
- virtual void WritePixel( ColorData nColor )
- {
- const BitmapColor aColor( COLORDATA_RED( nColor ), COLORDATA_GREEN( nColor ), COLORDATA_BLUE( nColor ) );
- if( mrPalette.GetBestIndex( aColor ) & 1 )
- pData[ mnX >> 3 ] |= 1 << ( 7 - ( mnX & 7 ) );
- else
- pData[ mnX >> 3 ] &= ~( 1 << ( 7 - ( mnX & 7 ) ) );
- mnX++;
- }
-};
-
-ImplPixelFormat* ImplPixelFormat::GetFormat( sal_uInt16 nBits, const BitmapPalette& rPalette )
-{
- switch( nBits )
- {
- case 1: return new ImplPixelFormat1( rPalette );
- case 4: return new ImplPixelFormat4( rPalette );
- case 8: return new ImplPixelFormat8( rPalette );
- case 16: return new ImplPixelFormat16;
- case 24: return new ImplPixelFormat24;
- case 32: return new ImplPixelFormat32;
- }
-
- return 0;
-}
-
-void IosSalBitmap::ConvertBitmapData( sal_uInt32 nWidth, sal_uInt32 nHeight,
- sal_uInt16 nDestBits, sal_uInt32 nDestBytesPerRow, const BitmapPalette& rDestPalette, sal_uInt8* pDestData,
- sal_uInt16 nSrcBits, sal_uInt32 nSrcBytesPerRow, const BitmapPalette& rSrcPalette, sal_uInt8* pSrcData )
-
-{
- if( (nDestBytesPerRow == nSrcBytesPerRow) && (nDestBits == nSrcBits) && ((nSrcBits != 8) || (rDestPalette.operator==( rSrcPalette ))) )
- {
- // simple case, same format, so just copy
- memcpy( pDestData, pSrcData, nHeight * nDestBytesPerRow );
- return;
- }
-
- // try accelerated conversion if possible
- // TODO: are other truecolor conversions except BGR->ARGB worth it?
- bool bConverted = false;
- if( (nSrcBits == 24) && (nDestBits == 32) )
- {
- // TODO: extend bmpfast.cxx with a method that can be directly used here
- BitmapBuffer aSrcBuf;
- aSrcBuf.mnFormat = BMP_FORMAT_24BIT_TC_BGR;
- aSrcBuf.mpBits = pSrcData;
- aSrcBuf.mnBitCount = nSrcBits;
- aSrcBuf.mnScanlineSize = nSrcBytesPerRow;
- BitmapBuffer aDstBuf;
- aDstBuf.mnFormat = BMP_FORMAT_32BIT_TC_ARGB;
- aDstBuf.mpBits = pDestData;
- aSrcBuf.mnBitCount = nDestBits;
- aDstBuf.mnScanlineSize = nDestBytesPerRow;
-
- aSrcBuf.mnWidth = aDstBuf.mnWidth = nWidth;
- aSrcBuf.mnHeight = aDstBuf.mnHeight = nHeight;
-
- SalTwoRect aTwoRects;
- aTwoRects.mnSrcX = aTwoRects.mnDestX = 0;
- aTwoRects.mnSrcY = aTwoRects.mnDestY = 0;
- aTwoRects.mnSrcWidth = aTwoRects.mnDestWidth = mnWidth;
- aTwoRects.mnSrcHeight = aTwoRects.mnDestHeight = mnHeight;
- bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );
- }
-
- if( !bConverted )
- {
- // TODO: this implementation is for clarety, not for speed
-
- ImplPixelFormat* pD = ImplPixelFormat::GetFormat( nDestBits, rDestPalette );
- ImplPixelFormat* pS = ImplPixelFormat::GetFormat( nSrcBits, rSrcPalette );
-
- if( pD && pS )
- {
- sal_uInt32 nY = nHeight;
- while( nY-- )
- {
- pD->StartLine( pDestData );
- pS->StartLine( pSrcData );
-
- sal_uInt32 nX = nWidth;
- while( nX-- )
- pD->WritePixel( pS->ReadPixel() );
-
- pSrcData += nSrcBytesPerRow;
- pDestData += nDestBytesPerRow;
- }
- }
- delete pS;
- delete pD;
- }
-}
-
-// ------------------------------------------------------------------
-
-Size IosSalBitmap::GetSize() const
-{
- return Size( mnWidth, mnHeight );
-}
-
-// ------------------------------------------------------------------
-
-sal_uInt16 IosSalBitmap::GetBitCount() const
-{
- return mnBits;
-}
-
-// ------------------------------------------------------------------
-
-static struct pal_entry
-{
- sal_uInt8 mnRed;
- sal_uInt8 mnGreen;
- sal_uInt8 mnBlue;
-}
-const aImplSalSysPalEntryAry[ 16 ] =
-{
-{ 0, 0, 0 },
-{ 0, 0, 0x80 },
-{ 0, 0x80, 0 },
-{ 0, 0x80, 0x80 },
-{ 0x80, 0, 0 },
-{ 0x80, 0, 0x80 },
-{ 0x80, 0x80, 0 },
-{ 0x80, 0x80, 0x80 },
-{ 0xC0, 0xC0, 0xC0 },
-{ 0, 0, 0xFF },
-{ 0, 0xFF, 0 },
-{ 0, 0xFF, 0xFF },
-{ 0xFF, 0, 0 },
-{ 0xFF, 0, 0xFF },
-{ 0xFF, 0xFF, 0 },
-{ 0xFF, 0xFF, 0xFF }
-};
-
-const BitmapPalette& GetDefaultPalette( int mnBits, bool bMonochrome )
-{
- if( bMonochrome )
- return Bitmap::GetGreyPalette( 1U << mnBits );
-
- // at this point we should provide some kind of default palette
- // since all other platforms do so, too.
- static bool bDefPalInit = false;
- static BitmapPalette aDefPalette256;
- static BitmapPalette aDefPalette16;
- static BitmapPalette aDefPalette2;
- if( ! bDefPalInit )
- {
- bDefPalInit = true;
- aDefPalette256.SetEntryCount( 256 );
- aDefPalette16.SetEntryCount( 16 );
- aDefPalette2.SetEntryCount( 2 );
-
- // Standard colors
- unsigned int i;
- for( i = 0; i < 16; i++ )
- {
- aDefPalette16[i] =
- aDefPalette256[i] = BitmapColor( aImplSalSysPalEntryAry[i].mnRed,
- aImplSalSysPalEntryAry[i].mnGreen,
- aImplSalSysPalEntryAry[i].mnBlue );
- }
-
- aDefPalette2[0] = BitmapColor( 0, 0, 0 );
- aDefPalette2[1] = BitmapColor( 0xff, 0xff, 0xff );
-
- // own palette (6/6/6)
- const int DITHER_PAL_STEPS = 6;
- const sal_uInt8 DITHER_PAL_DELTA = 51;
- int nB, nG, nR;
- sal_uInt8 nRed, nGreen, nBlue;
- for( nB=0, nBlue=0; nB < DITHER_PAL_STEPS; nB++, nBlue += DITHER_PAL_DELTA )
- {
- for( nG=0, nGreen=0; nG < DITHER_PAL_STEPS; nG++, nGreen += DITHER_PAL_DELTA )
- {
- for( nR=0, nRed=0; nR < DITHER_PAL_STEPS; nR++, nRed += DITHER_PAL_DELTA )
- {
- aDefPalette256[ i ] = BitmapColor( nRed, nGreen, nBlue );
- i++;
- }
- }
- }
- }
-
- // now fill in appropriate palette
- switch( mnBits )
- {
- case 1: return aDefPalette2;
- case 4: return aDefPalette16;
- case 8: return aDefPalette256;
- default: break;
- }
-
- const static BitmapPalette aEmptyPalette;
- return aEmptyPalette;
-}
-
-BitmapBuffer* IosSalBitmap::AcquireBuffer( bool /*bReadOnly*/ )
-{
- if( !maUserBuffer.get() )
-// || maContextBuffer.get() && (maUserBuffer.get() != maContextBuffer.get()) )
- {
- fprintf(stderr,"ASB::Acq(%dx%d,d=%d)\n",mnWidth,mnHeight,mnBits);
- // TODO: AllocateUserData();
- return NULL;
- }
-
- BitmapBuffer* pBuffer = new BitmapBuffer;
- pBuffer->mnWidth = mnWidth;
- pBuffer->mnHeight = mnHeight;
- pBuffer->maPalette = maPalette;
- pBuffer->mnScanlineSize = mnBytesPerRow;
- pBuffer->mpBits = maUserBuffer.get();
- pBuffer->mnBitCount = mnBits;
- switch( mnBits )
- {
- case 1: pBuffer->mnFormat = BMP_FORMAT_1BIT_MSB_PAL; break;
- case 4: pBuffer->mnFormat = BMP_FORMAT_4BIT_MSN_PAL; break;
- case 8: pBuffer->mnFormat = BMP_FORMAT_8BIT_PAL; break;
- case 16: pBuffer->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK;
- pBuffer->maColorMask = ColorMask( k16BitRedColorMask, k16BitGreenColorMask, k16BitBlueColorMask );
- break;
- case 24: pBuffer->mnFormat = BMP_FORMAT_24BIT_TC_BGR; break;
- case 32: pBuffer->mnFormat = BMP_FORMAT_32BIT_TC_ARGB;
- pBuffer->maColorMask = ColorMask( k32BitRedColorMask, k32BitGreenColorMask, k32BitBlueColorMask );
- break;
- }
- pBuffer->mnFormat |= BMP_FORMAT_BOTTOM_UP;
-
- // some BitmapBuffer users depend on a complete palette
- if( (mnBits <= 8) && !maPalette )
- pBuffer->maPalette = GetDefaultPalette( mnBits, true );
-
- return pBuffer;
-}
-
-// ------------------------------------------------------------------
-
-void IosSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, bool bReadOnly )
-{
- // invalidate graphic context if we have different data
- if( !bReadOnly )
- {
- maPalette = pBuffer->maPalette;
- if( mxGraphicContext )
- DestroyContext();
- }
-
- delete pBuffer;
-}
-
-// ------------------------------------------------------------------
-
-CGImageRef IosSalBitmap::CreateCroppedImage( int nX, int nY, int nNewWidth, int nNewHeight ) const
-{
- if( !mxCachedImage )
- {
- if( !mxGraphicContext )
- if( !const_cast<IosSalBitmap*>(this)->CreateContext() )
- return NULL;
-
- mxCachedImage = CGBitmapContextCreateImage( mxGraphicContext );
- }
-
- CGImageRef xCroppedImage = NULL;
- // short circuit if there is nothing to crop
- if( !nX && !nY && (mnWidth == nNewWidth) && (mnHeight == nNewHeight) )
- {
- xCroppedImage = mxCachedImage;
- CFRetain( xCroppedImage );
- }
- else
- {
- nY = mnHeight - (nY + nNewHeight); // adjust for y-mirrored context
- const CGRect aCropRect = { { static_cast<CGFloat>(nX), static_cast<CGFloat>(nY)}, { static_cast<CGFloat>(nNewWidth), static_cast<CGFloat>(nNewHeight) } };
- xCroppedImage = CGImageCreateWithImageInRect( mxCachedImage, aCropRect );
- }
-
- return xCroppedImage;
-}
-
-// ------------------------------------------------------------------
-
-static void CFRTLFree(void* /*info*/, const void* data, size_t /*size*/)
-{
- rtl_freeMemory( const_cast<void*>(data) );
-}
-
-CGImageRef IosSalBitmap::CreateWithMask( const IosSalBitmap& rMask,
- int nX, int nY, int nWidth, int nHeight ) const
-{
- CGImageRef xImage( CreateCroppedImage( nX, nY, nWidth, nHeight ) );
- if( !xImage )
- return NULL;
-
- CGImageRef xMask = rMask.CreateCroppedImage( nX, nY, nWidth, nHeight );
- if( !xMask )
- return xImage;
-
- // CGImageCreateWithMask() only likes masks or greyscale images => convert if needed
- // TODO: isolate in an extra method?
- if( !CGImageIsMask(xMask) || (CGImageGetColorSpace(xMask) != GetSalData()->mxGraySpace) )
- {
- const CGRect xImageRect=CGRectMake( 0, 0, nWidth, nHeight );//the rect has no offset
-
- // create the alpha mask image fitting our image
- // TODO: is caching the full mask or the subimage mask worth it?
- int nMaskBytesPerRow = ((nWidth + 3) & ~3);
- void* pMaskMem = rtl_allocateMemory( nMaskBytesPerRow * nHeight );
- CGContextRef xMaskContext = CGBitmapContextCreate( pMaskMem,
- nWidth, nHeight, 8, nMaskBytesPerRow, GetSalData()->mxGraySpace, kCGImageAlphaNone );
- CGContextDrawImage( xMaskContext, xImageRect, xMask );
- CFRelease( xMask );
- CGDataProviderRef xDataProvider( CGDataProviderCreateWithData( NULL,
- pMaskMem, nHeight * nMaskBytesPerRow, &CFRTLFree ) );
- static const float* pDecode = NULL;
- xMask = CGImageMaskCreate( nWidth, nHeight, 8, 8, nMaskBytesPerRow, xDataProvider, pDecode, false );
- CFRelease( xDataProvider );
- CFRelease( xMaskContext );
- }
-
- if( !xMask )
- return xImage;
-
- // combine image and alpha mask
- CGImageRef xMaskedImage = CGImageCreateWithMask( xImage, xMask );
- CFRelease( xMask );
- CFRelease( xImage );
- return xMaskedImage;
-}
-
-// ------------------------------------------------------------------
-
-/** creates an image from the given rectangle, replacing all black pixels with nMaskColor and make all other full transparent */
-CGImageRef IosSalBitmap::CreateColorMask( int nX, int nY, int nWidth, int nHeight, SalColor nMaskColor ) const
-{
- CGImageRef xMask = 0;
- if( maUserBuffer.get() && (nX + nWidth <= mnWidth) && (nY + nHeight <= mnHeight) )
- {
- const sal_uInt32 nDestBytesPerRow = nWidth << 2;
- sal_uInt32* pMaskBuffer = static_cast<sal_uInt32*>( rtl_allocateMemory( nHeight * nDestBytesPerRow ) );
- sal_uInt32* pDest = pMaskBuffer;
-
- ImplPixelFormat* pSourcePixels = ImplPixelFormat::GetFormat( mnBits, maPalette );
-
- if( pMaskBuffer && pSourcePixels )
- {
- sal_uInt32 nColor;
- reinterpret_cast<sal_uInt8*>(&nColor)[0] = 0xff;
- reinterpret_cast<sal_uInt8*>(&nColor)[1] = SALCOLOR_RED( nMaskColor );
- reinterpret_cast<sal_uInt8*>(&nColor)[2] = SALCOLOR_GREEN( nMaskColor );
- reinterpret_cast<sal_uInt8*>(&nColor)[3] = SALCOLOR_BLUE( nMaskColor );
-
- sal_uInt8* pSource = maUserBuffer.get();
- if( nY )
- pSource += nY * mnBytesPerRow;
-
- int y = nHeight;
- while( y-- )
- {
- pSourcePixels->StartLine( pSource );
- pSourcePixels->SkipPixel(nX);
- sal_uInt32 x = nWidth;
- while( x-- )
- {
- *pDest++ = ( pSourcePixels->ReadPixel() == 0 ) ? nColor : 0;
- }
- pSource += mnBytesPerRow;
- }
-
- CGDataProviderRef xDataProvider( CGDataProviderCreateWithData(NULL, pMaskBuffer, nHeight * nDestBytesPerRow, &CFRTLFree) );
- xMask = CGImageCreate(nWidth, nHeight, 8, 32, nDestBytesPerRow, GetSalData()->mxRGBSpace, kCGImageAlphaPremultipliedFirst, xDataProvider, NULL, true, kCGRenderingIntentDefault);
- CFRelease(xDataProvider);
- }
- else
- {
- free(pMaskBuffer);
- }
-
- delete pSourcePixels;
- }
- return xMask;
-}
-
-// =======================================================================
-
-/** IosSalBitmap::GetSystemData Get platform native image data from existing image
- *
- * @param rData struct BitmapSystemData, defined in vcl/inc/bitmap.hxx
- * @return true if successful
-**/
-bool IosSalBitmap::GetSystemData( BitmapSystemData& rData )
-{
- bool bRet = false;
-
- if( !mxGraphicContext )
- CreateContext();
-
- if ( mxGraphicContext )
- {
- bRet = true;
-
- if ((CGBitmapContextGetBitsPerPixel(mxGraphicContext) == 32) &&
- (CGBitmapContextGetBitmapInfo(mxGraphicContext) & kCGBitmapByteOrderMask) != kCGBitmapByteOrder32Host) {
- /**
- * We need to hack things because VCL does not use kCGBitmapByteOrder32Host, while Cairo requires it.
- */
- OSL_TRACE("IosSalBitmap::%s(): kCGBitmapByteOrder32Host not found => inserting it.",__func__);
-
- CGImageRef xImage = CGBitmapContextCreateImage (mxGraphicContext);
-
- // re-create the context with single change: include kCGBitmapByteOrder32Host flag.
- CGContextRef mxGraphicContextNew = CGBitmapContextCreate( CGBitmapContextGetData(mxGraphicContext),
- CGBitmapContextGetWidth(mxGraphicContext),
- CGBitmapContextGetHeight(mxGraphicContext),
- CGBitmapContextGetBitsPerComponent(mxGraphicContext),
- CGBitmapContextGetBytesPerRow(mxGraphicContext),
- CGBitmapContextGetColorSpace(mxGraphicContext),
- CGBitmapContextGetBitmapInfo(mxGraphicContext) | kCGBitmapByteOrder32Host);
- CFRelease(mxGraphicContext);
-
- // Needs to be flipped
- CGContextSaveGState( mxGraphicContextNew );
- CGContextTranslateCTM (mxGraphicContextNew, 0, CGBitmapContextGetHeight(mxGraphicContextNew));
- CGContextScaleCTM (mxGraphicContextNew, 1.0, -1.0);
-
- CGContextDrawImage(mxGraphicContextNew, CGRectMake( 0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)), xImage);
-
- // Flip back
- CGContextRestoreGState( mxGraphicContextNew );
-
- CGImageRelease( xImage );
- mxGraphicContext = mxGraphicContextNew;
- }
-
- rData.rImageContext = (void *) mxGraphicContext;
- rData.mnWidth = mnWidth;
- rData.mnHeight = mnHeight;
- }
-
- return bRet;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/ios/source/gdi/salgdicommon.cxx b/vcl/ios/source/gdi/salgdicommon.cxx
index bb6ec70..c15346a 100644
--- a/vcl/ios/source/gdi/salgdicommon.cxx
+++ b/vcl/ios/source/gdi/salgdicommon.cxx
@@ -22,7 +22,7 @@
#include "basegfx/polygon/b2dpolygon.hxx"
-#include "ios/salbmp.h"
+#include "quartz/salbmp.h"
#include "coretext/salgdi.h"
#include "fontsubset.hxx"
@@ -501,8 +501,8 @@ bool QuartzSalGraphics::drawAlphaBitmap( const SalTwoRect& rTR,
return false;
}
- const IosSalBitmap& rSrcSalBmp = static_cast<const IosSalBitmap&>(rSrcBitmap);
- const IosSalBitmap& rMaskSalBmp = static_cast<const IosSalBitmap&>(rAlphaBmp);
+ const QuartzSalBitmap& rSrcSalBmp = static_cast<const QuartzSalBitmap&>(rSrcBitmap);
+ const QuartzSalBitmap& rMaskSalBmp = static_cast<const QuartzSalBitmap&>(rAlphaBmp);
CGImageRef xMaskedImage = rSrcSalBmp.CreateWithMask( rMaskSalBmp, rTR.mnSrcX,
rTR.mnSrcY, rTR.mnSrcWidth,
rTR.mnSrcHeight );
@@ -555,7 +555,7 @@ void QuartzSalGraphics::drawBitmap( const SalTwoRect* pPosAry, const SalBitmap&
{
return;
}
- const IosSalBitmap& rBitmap = static_cast<const IosSalBitmap&>(rSalBitmap);
+ const QuartzSalBitmap& rBitmap = static_cast<const QuartzSalBitmap&>(rSalBitmap);
CGImageRef xImage = rBitmap.CreateCroppedImage( (int)pPosAry->mnSrcX, (int)pPosAry->mnSrcY,
(int)pPosAry->mnSrcWidth, (int)pPosAry->mnSrcHeight );
if( !xImage )
@@ -582,8 +582,8 @@ void QuartzSalGraphics::drawBitmap( const SalTwoRect* pPosAry, const SalBitmap&
{
return;
}
- const IosSalBitmap& rBitmap = static_cast<const IosSalBitmap&>(rSalBitmap);
- const IosSalBitmap& rMask = static_cast<const IosSalBitmap&>(rTransparentBitmap);
+ const QuartzSalBitmap& rBitmap = static_cast<const QuartzSalBitmap&>(rSalBitmap);
+ const QuartzSalBitmap& rMask = static_cast<const QuartzSalBitmap&>(rTransparentBitmap);
CGImageRef xMaskedImage( rBitmap.CreateWithMask( rMask, pPosAry->mnSrcX, pPosAry->mnSrcY,
pPosAry->mnSrcWidth, pPosAry->mnSrcHeight ) );
if( !xMaskedImage )
@@ -632,7 +632,7 @@ void QuartzSalGraphics::drawMask( const SalTwoRect* pPosAry,
{
return;
}
- const IosSalBitmap& rBitmap = static_cast<const IosSalBitmap&>(rSalBitmap);
+ const QuartzSalBitmap& rBitmap = static_cast<const QuartzSalBitmap&>(rSalBitmap);
CGImageRef xImage = rBitmap.CreateColorMask( pPosAry->mnSrcX, pPosAry->mnSrcY,
pPosAry->mnSrcWidth, pPosAry->mnSrcHeight,
nMaskColor );
@@ -1036,7 +1036,7 @@ SalBitmap* QuartzSalGraphics::getBitmap( long nX, long nY, long nDX, long nD
ApplyXorContext();
- IosSalBitmap* pBitmap = new IosSalBitmap;
+ QuartzSalBitmap* pBitmap = new QuartzSalBitmap;
if( !pBitmap->Create( mxLayer, mnBitmapDepth, nX, nY, nDX, nDY, !mbWindow ) )
{
delete pBitmap;
diff --git a/vcl/ios/source/gdi/salnativewidgets.cxx b/vcl/ios/source/gdi/salnativewidgets.cxx
index 7b4beb5..c3023e1 100644
--- a/vcl/ios/source/gdi/salnativewidgets.cxx
+++ b/vcl/ios/source/gdi/salnativewidgets.cxx
@@ -22,7 +22,6 @@
#include "vcl/svapp.hxx"
#include "vcl/timer.hxx"
-#include "ios/salconst.h"
#include "coretext/salgdi.h"
#include "ios/saldata.hxx"
#include "ios/salframe.h"
diff --git a/vcl/ios/source/window/salmenu.cxx b/vcl/ios/source/window/salmenu.cxx
index 27c6e10..50c262e 100644
--- a/vcl/ios/source/window/salmenu.cxx
+++ b/vcl/ios/source/window/salmenu.cxx
@@ -28,7 +28,6 @@
#include "ios/salinst.h"
#include "ios/salmenu.h"
#include "ios/salframe.h"
-#include "ios/salbmp.h"
#include "svids.hrc"
#include "window.h"
diff --git a/vcl/quartz/salbmp.cxx b/vcl/quartz/salbmp.cxx
new file mode 100644
index 0000000..9211c52
--- /dev/null
+++ b/vcl/quartz/salbmp.cxx
@@ -0,0 +1,911 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "basebmp/scanlineformats.hxx"
+#include "basebmp/color.hxx"
+
+#include "basegfx/vector/b2ivector.hxx"
+
+#include "tools/color.hxx"
+
+#include "vcl/bitmap.hxx" // for BitmapSystemData
+#include "vcl/salbtype.hxx"
+
+#include "quartz/salbmp.h"
+//#include "aqua/salinst.h"
+
+#include "bmpfast.hxx"
+
+static const unsigned long k16BitRedColorMask = 0x00007c00;
+static const unsigned long k16BitGreenColorMask = 0x000003e0;
+static const unsigned long k16BitBlueColorMask = 0x0000001f;
+
+static const unsigned long k32BitRedColorMask = 0x00ff0000;
+static const unsigned long k32BitGreenColorMask = 0x0000ff00;
+static const unsigned long k32BitBlueColorMask = 0x000000ff;
+
+// =======================================================================
+
+static bool isValidBitCount( sal_uInt16 nBitCount )
+{
+ return (nBitCount == 1) || (nBitCount == 4) || (nBitCount == 8) || (nBitCount == 16) || (nBitCount == 24) || (nBitCount == 32);
+}
+
+// =======================================================================
+
+QuartzSalBitmap::QuartzSalBitmap()
+: mxGraphicContext( NULL )
+, mxCachedImage( NULL )
+, mnBits(0)
+, mnWidth(0)
+, mnHeight(0)
+, mnBytesPerRow(0)
+{
+}
+
+// ------------------------------------------------------------------
+
+QuartzSalBitmap::~QuartzSalBitmap()
+{
+ Destroy();
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::Create( CGLayerRef xLayer, int nBitmapBits,
+ int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/ )
+{
+ DBG_ASSERT( xLayer, "QuartzSalBitmap::Create() from non-layered context" );
+
+ // sanitize input parameters
+ if( nX < 0 )
+ nWidth += nX, nX = 0;
+ if( nY < 0 )
+ nHeight += nY, nY = 0;
+ const CGSize aLayerSize = CGLayerGetSize( xLayer );
+ if( nWidth >= (int)aLayerSize.width - nX )
+ nWidth = (int)aLayerSize.width - nX;
+ if( nHeight >= (int)aLayerSize.height - nY )
+ nHeight = (int)aLayerSize.height - nY;
+ if( (nWidth < 0) || (nHeight < 0) )
+ nWidth = nHeight = 0;
+
+ // initialize properties
+ mnWidth = nWidth;
+ mnHeight = nHeight;
+ mnBits = nBitmapBits ? nBitmapBits : 32;
+
+ // initialize drawing context
+ CreateContext();
+
+ // copy layer content into the bitmap buffer
+ const CGPoint aSrcPoint = { static_cast<CGFloat>(-nX), static_cast<CGFloat>(-nY) };
+ ::CGContextDrawLayerAtPoint( mxGraphicContext, aSrcPoint, xLayer );
+ return true;
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::Create( const Size& rSize, sal_uInt16 nBits, const BitmapPalette& rBitmapPalette )
+{
+ if( !isValidBitCount( nBits ) )
+ return false;
+ maPalette = rBitmapPalette;
+ mnBits = nBits;
+ mnWidth = rSize.Width();
+ mnHeight = rSize.Height();
+ return AllocateUserData();
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp )
+{
+ return Create( rSalBmp, rSalBmp.GetBitCount() );
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics )
+{
+ return Create( rSalBmp, pGraphics ? pGraphics->GetBitCount() : rSalBmp.GetBitCount() );
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount )
+{
+ const QuartzSalBitmap& rSourceBitmap = static_cast<const QuartzSalBitmap&>(rSalBmp);
+
+ if( isValidBitCount( nNewBitCount ) && rSourceBitmap.maUserBuffer.get() )
+ {
+ mnBits = nNewBitCount;
+ mnWidth = rSourceBitmap.mnWidth;
+ mnHeight = rSourceBitmap.mnHeight;
+ maPalette = rSourceBitmap.maPalette;
+
+ if( AllocateUserData() )
+ {
+ ConvertBitmapData( mnWidth, mnHeight, mnBits, mnBytesPerRow, maPalette, maUserBuffer.get(), rSourceBitmap.mnBits, rSourceBitmap.mnBytesPerRow, rSourceBitmap.maPalette, rSourceBitmap.maUserBuffer.get() );
+ return true;
+ }
+ }
+ return false;
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > /*xBitmapCanvas*/, Size& /*rSize*/, bool /*bMask*/ )
+{
+ return false;
+}
+
+// ------------------------------------------------------------------
+
+void QuartzSalBitmap::Destroy()
+{
+ DestroyContext();
+ maUserBuffer.reset();
+}
+
+// ------------------------------------------------------------------
+
+void QuartzSalBitmap::DestroyContext()
+{
+ CGImageRelease( mxCachedImage );
+ mxCachedImage = NULL;
+
+ if( mxGraphicContext )
+ {
+ CGContextRelease( mxGraphicContext );
+ mxGraphicContext = NULL;
+ maContextBuffer.reset();
+ }
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::CreateContext()
+{
+ DestroyContext();
+
+ // prepare graphics context
+ // convert image from user input if available
+ const bool bSkipConversion = !maUserBuffer;
+ if( bSkipConversion )
+ AllocateUserData();
+
+ // default to RGBA color space
+ CGColorSpaceRef aCGColorSpace = GetSalData()->mxRGBSpace;
+ CGBitmapInfo aCGBmpInfo = kCGImageAlphaNoneSkipFirst;
+
+ // convert data into something accepted by CGBitmapContextCreate()
+ size_t bitsPerComponent = (mnBits == 16) ? 5 : 8;
+ sal_uInt32 nContextBytesPerRow = mnBytesPerRow;
+ if( (mnBits == 16) || (mnBits == 32) )
+ {
+ // no conversion needed for truecolor
+ maContextBuffer = maUserBuffer;
+ }
+ else if( (mnBits == 8) && maPalette.IsGreyPalette() )
+ {
+ // no conversion needed for grayscale
+ maContextBuffer = maUserBuffer;
+ aCGColorSpace = GetSalData()->mxGraySpace;
+ aCGBmpInfo = kCGImageAlphaNone;
+ bitsPerComponent = mnBits;
+ }
+ // TODO: is special handling for 1bit input buffers worth it?
+ else
+ {
+ // convert user data to 32 bit
+ nContextBytesPerRow = mnWidth << 2;
+ try
+ {
+ maContextBuffer.reset( new sal_uInt8[ mnHeight * nContextBytesPerRow ] );
+
+ if( !bSkipConversion )
+ ConvertBitmapData( mnWidth, mnHeight,
+ 32, nContextBytesPerRow, maPalette, maContextBuffer.get(),
+ mnBits, mnBytesPerRow, maPalette, maUserBuffer.get() );
+ }
+ catch( const std::bad_alloc& )
+ {
+ mxGraphicContext = 0;
+ }
+ }
+
+ if( maContextBuffer.get() )
+ {
+ mxGraphicContext = ::CGBitmapContextCreate( maContextBuffer.get(), mnWidth, mnHeight,
+ bitsPerComponent, nContextBytesPerRow, aCGColorSpace, aCGBmpInfo );
+ }
+
+ if( !mxGraphicContext )
+ maContextBuffer.reset();
+
+ return mxGraphicContext != NULL;
+}
+
+// ------------------------------------------------------------------
+
+bool QuartzSalBitmap::AllocateUserData()
+{
+ Destroy();
+
+ if( mnWidth && mnHeight )
+ {
+ mnBytesPerRow = 0;
+
+ switch( mnBits )
+ {
+ case 1: mnBytesPerRow = (mnWidth + 7) >> 3; break;
+ case 4: mnBytesPerRow = (mnWidth + 1) >> 1; break;
+ case 8: mnBytesPerRow = mnWidth; break;
+ case 16: mnBytesPerRow = mnWidth << 1; break;
+ case 24: mnBytesPerRow = (mnWidth << 1) + mnWidth; break;
+ case 32: mnBytesPerRow = mnWidth << 2; break;
+ default:
+ OSL_FAIL("vcl::QuartzSalBitmap::AllocateUserData(), illegal bitcount!");
+ }
+ }
+
+ try
+ {
+ if( mnBytesPerRow )
+ maUserBuffer.reset( new sal_uInt8[mnBytesPerRow * mnHeight] );
+ }
+ catch( const std::bad_alloc& )
+ {
+ OSL_FAIL( "vcl::QuartzSalBitmap::AllocateUserData: bad alloc" );
+ maUserBuffer.reset( NULL );
+ mnBytesPerRow = 0;
+ }
+
+ return maUserBuffer.get() != 0;
+}
+
+// ------------------------------------------------------------------
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list