summaryrefslogtreecommitdiff
path: root/vcl/unx
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-10-30 18:23:11 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-11-06 12:05:31 +0100
commitea6d73b55bac6eea8a1b11c1dd3e0c86ce2752b9 (patch)
treea17e56ba1bccddda464428abfc480791a8ab7f1d /vcl/unx
parent19ff1dd4a93409517186065ab5b0e200a05d5fa3 (diff)
KF5 add initial SalBitmap implementation
Change-Id: I1f7b1894272096a0f0b23b63c3eeae310fb28c6f
Diffstat (limited to 'vcl/unx')
-rw-r--r--vcl/unx/kf5/Kf5Bitmap.cxx265
-rw-r--r--vcl/unx/kf5/Kf5Bitmap.hxx69
-rw-r--r--vcl/unx/kf5/Kf5Graphics.hxx2
-rw-r--r--vcl/unx/kf5/Kf5Instance.cxx3
-rw-r--r--vcl/unx/kf5/Kf5Tools.hxx51
5 files changed, 389 insertions, 1 deletions
diff --git a/vcl/unx/kf5/Kf5Bitmap.cxx b/vcl/unx/kf5/Kf5Bitmap.cxx
new file mode 100644
index 000000000000..d1e40ee39887
--- /dev/null
+++ b/vcl/unx/kf5/Kf5Bitmap.cxx
@@ -0,0 +1,265 @@
+/* -*- 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 "Kf5Bitmap.hxx"
+#include "Kf5Tools.hxx"
+#include "Kf5Graphics.hxx"
+
+#include <QtGui/QImage>
+#include <QtCore/QVector>
+#include <QtGui/QColor>
+
+Kf5Bitmap::Kf5Bitmap()
+{
+}
+
+Kf5Bitmap::Kf5Bitmap( const QImage &rImage )
+{
+ m_pImage.reset( new QImage( rImage ) );
+}
+
+Kf5Bitmap::~Kf5Bitmap()
+{
+}
+
+bool Kf5Bitmap::Create( const Size& rSize, sal_uInt16 nBitCount,
+ const BitmapPalette& rPal )
+{
+ assert(
+ (nBitCount == 1
+ || nBitCount == 4
+ || nBitCount == 8
+ || nBitCount == 16
+ || nBitCount == 24
+ || nBitCount == 32)
+ && "Unsupported BitCount!");
+
+ if ( nBitCount == 1 )
+ assert( 2 == rPal.GetEntryCount() );
+ if ( nBitCount == 4 )
+ assert( 16 == rPal.GetEntryCount() );
+ if ( nBitCount == 8 )
+ assert( 256 == rPal.GetEntryCount() );
+
+ if ( nBitCount == 4 )
+ {
+ m_pImage.reset();
+ m_aSize = rSize;
+ m_nScanline = rSize.Width() / 2 + (rSize.Width() % 2) ? 0 : 1;
+ m_pBuffer.reset( new sal_uInt8[ m_nScanline * rSize.Height() ] );
+ }
+ else
+ {
+ m_pImage.reset( new QImage( toQSize( rSize ), getBitFormat( nBitCount ) ) );
+ m_pBuffer.reset();
+ }
+ m_aPalette = rPal;
+
+ auto count = rPal.GetEntryCount();
+ if( nBitCount != 4 && count )
+ {
+ QVector<QRgb> aColorTable( count );
+ for ( unsigned i = 0; i < count; ++i )
+ aColorTable[ i ] = qRgb( rPal[ i ].GetRed(),
+ rPal[ i ].GetGreen(), rPal[ i ].GetBlue() );
+ m_pImage->setColorTable( aColorTable );
+ }
+ return true;
+}
+
+bool Kf5Bitmap::Create( const SalBitmap& rSalBmp )
+{
+ const Kf5Bitmap *pBitmap = static_cast< const Kf5Bitmap*>( &rSalBmp );
+ if ( pBitmap->m_pImage.get() )
+ {
+ m_pImage.reset( new QImage( *pBitmap->m_pImage.get() ) );
+ m_pBuffer.reset();
+ }
+ else
+ {
+ m_aSize = pBitmap->m_aSize;
+ m_nScanline = pBitmap->m_nScanline;
+ m_pBuffer.reset( new sal_uInt8[ m_nScanline * m_aSize.Height() ] );
+ memcpy( m_pBuffer.get(), pBitmap->m_pBuffer.get(), m_nScanline );
+ m_pImage.reset();
+ }
+ m_aPalette = pBitmap->m_aPalette;
+ return true;
+}
+
+bool Kf5Bitmap::Create( const SalBitmap& rSalBmp,
+ SalGraphics* pSalGraphics )
+{
+ const Kf5Bitmap *pBitmap = static_cast< const Kf5Bitmap *>( &rSalBmp );
+ Kf5Graphics *pGraphics = static_cast< Kf5Graphics* >( pSalGraphics );
+ QImage *pImage = pGraphics->m_pQImage;
+ m_pImage.reset( new QImage( pBitmap->m_pImage->convertToFormat( pImage->format() ) ) );
+ m_pBuffer.reset();
+ return true;
+}
+
+bool Kf5Bitmap::Create( const SalBitmap& rSalBmp,
+ sal_uInt16 nNewBitCount )
+{
+ assert(
+ (nNewBitCount == 1
+ || nNewBitCount == 4
+ || nNewBitCount == 8
+ || nNewBitCount == 16
+ || nNewBitCount == 24
+ || nNewBitCount == 32)
+ && "Unsupported BitCount!");
+
+ const Kf5Bitmap *pBitmap = static_cast< const Kf5Bitmap *>( &rSalBmp );
+ if ( pBitmap->m_pBuffer.get() )
+ return false;
+
+ m_pImage.reset( new QImage( pBitmap->m_pImage->convertToFormat( getBitFormat( nNewBitCount ) ) ) );
+ return true;
+}
+
+bool Kf5Bitmap::Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
+ Size& rSize, bool bMask )
+{
+ return false;
+}
+
+void Kf5Bitmap::Destroy()
+{
+ m_pImage.reset();
+ m_pBuffer.reset();
+}
+
+Size Kf5Bitmap::GetSize() const
+{
+ if ( m_pBuffer.get() )
+ return m_aSize;
+ else if ( m_pImage.get() )
+ return toSize( m_pImage->size() );
+ return Size();
+}
+
+sal_uInt16 Kf5Bitmap::GetBitCount() const
+{
+ if ( m_pBuffer.get() )
+ return 4;
+ else if ( m_pImage.get() )
+ return getFormatBits( m_pImage->format() );
+ return 0;
+}
+
+BitmapBuffer* Kf5Bitmap::AcquireBuffer( BitmapAccessMode nMode )
+{
+ static const BitmapPalette aEmptyPalette;
+
+ if ( !(m_pImage.get() || m_pBuffer.get()) )
+ return nullptr;
+
+ BitmapBuffer* pBuffer = new BitmapBuffer;
+
+ if ( m_pBuffer.get() )
+ {
+ pBuffer->mnWidth = m_aSize.Width();
+ pBuffer->mnHeight = m_aSize.Height();
+ pBuffer->mnBitCount = 4;
+ pBuffer->mpBits = m_pBuffer.get();
+ pBuffer->mnScanlineSize = m_nScanline;
+ }
+ else
+ {
+ pBuffer->mnWidth = m_pImage->width();
+ pBuffer->mnHeight = m_pImage->height();
+ pBuffer->mnBitCount = getFormatBits( m_pImage->format() );
+ pBuffer->mpBits = m_pImage->bits();
+ pBuffer->mnScanlineSize = m_pImage->bytesPerLine();
+ }
+
+ switch( pBuffer->mnBitCount )
+ {
+ case 1:
+ pBuffer->mnFormat = ScanlineFormat::N1BitLsbPal;
+ pBuffer->maPalette = m_aPalette;
+ break;
+ case 4:
+ pBuffer->mnFormat = ScanlineFormat::N4BitMsnPal;
+ pBuffer->maPalette = m_aPalette;
+ break;
+ case 8:
+ pBuffer->mnFormat = ScanlineFormat::N8BitPal;
+ pBuffer->maPalette = m_aPalette;
+ break;
+ case 16:
+ {
+#ifdef OSL_BIGENDIAN
+ pBuffer->mnFormat= ScanlineFormat::N16BitTcMsbMask;
+#else
+ pBuffer->mnFormat= ScanlineFormat::N16BitTcLsbMask;
+#endif
+ ColorMaskElement aRedMask(0xf800); // 5
+ aRedMask.CalcMaskShift();
+ ColorMaskElement aGreenMask(0x07e0); // 6
+ aGreenMask.CalcMaskShift();
+ ColorMaskElement aBlueMask(0x001f); // 5
+ aBlueMask.CalcMaskShift();
+ pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
+ pBuffer->maPalette = aEmptyPalette;
+ break;
+ }
+ case 24:
+ pBuffer->mnFormat = ScanlineFormat::N24BitTcRgb;
+ pBuffer->maPalette = aEmptyPalette;
+ break;
+ case 32:
+ {
+ pBuffer->mnFormat = ScanlineFormat::N32BitTcArgb;
+ pBuffer->maPalette = aEmptyPalette;
+ break;
+ }
+ }
+
+ return pBuffer;
+}
+
+void Kf5Bitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode )
+{
+ m_aPalette = pBuffer->maPalette;
+ delete pBuffer;
+}
+
+bool Kf5Bitmap::GetSystemData( BitmapSystemData& rData )
+{
+ return false;
+}
+
+bool Kf5Bitmap::ScalingSupported() const
+{
+ return false;
+}
+
+bool Kf5Bitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag )
+{
+ return false;
+}
+
+bool Kf5Bitmap::Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol )
+{
+ return false;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kf5/Kf5Bitmap.hxx b/vcl/unx/kf5/Kf5Bitmap.hxx
new file mode 100644
index 000000000000..2ea4accc8e9c
--- /dev/null
+++ b/vcl/unx/kf5/Kf5Bitmap.hxx
@@ -0,0 +1,69 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <salbmp.hxx>
+
+#include <memory>
+
+class QImage;
+
+class VCL_DLLPUBLIC Kf5Bitmap : public SalBitmap
+{
+ std::unique_ptr< QImage > m_pImage;
+ BitmapPalette m_aPalette;
+
+ // for 4bit support
+ std::unique_ptr< sal_uInt8 > m_pBuffer;
+ Size m_aSize;
+ sal_uInt32 m_nScanline;
+
+public:
+ Kf5Bitmap();
+ Kf5Bitmap( const QImage& rQImage );
+ virtual ~Kf5Bitmap() override;
+
+ const QImage* GetQImage() const { return m_pImage.get(); }
+
+ virtual bool Create( const Size& rSize,
+ sal_uInt16 nBitCount,
+ const BitmapPalette& rPal ) override;
+ virtual bool Create( const SalBitmap& rSalBmp ) override;
+ virtual bool Create( const SalBitmap& rSalBmp,
+ SalGraphics* pGraphics ) override;
+ virtual bool Create( const SalBitmap& rSalBmp,
+ sal_uInt16 nNewBitCount ) override;
+ virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
+ Size& rSize,
+ bool bMask = false ) override;
+ virtual void Destroy() final override;
+ virtual Size GetSize() const override;
+ virtual sal_uInt16 GetBitCount() const override;
+
+ virtual BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) override;
+ virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) override;
+ virtual bool GetSystemData( BitmapSystemData& rData ) override;
+
+ virtual bool ScalingSupported() const override;
+ virtual bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) override;
+ virtual bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol ) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kf5/Kf5Graphics.hxx b/vcl/unx/kf5/Kf5Graphics.hxx
index 141f8bdc61e1..f9a169c1141f 100644
--- a/vcl/unx/kf5/Kf5Graphics.hxx
+++ b/vcl/unx/kf5/Kf5Graphics.hxx
@@ -30,6 +30,8 @@ class QImage;
class Kf5Graphics : public SalGraphics
{
+ friend class Kf5Bitmap;
+
Kf5Frame *m_pFrame;
QImage *m_pQImage;
PhysicalFontCollection *m_pFontCollection;
diff --git a/vcl/unx/kf5/Kf5Instance.cxx b/vcl/unx/kf5/Kf5Instance.cxx
index 126b11b635de..3eb7e20cfa4e 100644
--- a/vcl/unx/kf5/Kf5Instance.cxx
+++ b/vcl/unx/kf5/Kf5Instance.cxx
@@ -25,6 +25,7 @@
#include "Kf5Timer.hxx"
#include "Kf5VirtualDevice.hxx"
#include "Kf5Object.hxx"
+#include "Kf5Bitmap.hxx"
#include <QtCore/QThread>
#include <QtWidgets/QApplication>
@@ -111,7 +112,7 @@ SalSystem* Kf5Instance::CreateSalSystem()
SalBitmap* Kf5Instance::CreateSalBitmap()
{
- return new SvpSalBitmap();
+ return new Kf5Bitmap();
}
bool Kf5Instance::ImplYield( bool bWait, bool bHandleAllCurrentEvents )
diff --git a/vcl/unx/kf5/Kf5Tools.hxx b/vcl/unx/kf5/Kf5Tools.hxx
index d5ba80bc0898..40c34d9d4303 100644
--- a/vcl/unx/kf5/Kf5Tools.hxx
+++ b/vcl/unx/kf5/Kf5Tools.hxx
@@ -20,8 +20,12 @@
#pragma once
#include <QtCore/QString>
+#include <QtCore/QRect>
+#include <QtCore/QSize>
+#include <QtGui/QImage>
#include <rtl/string.hxx>
+#include <tools/gen.hxx>
inline OUString toOUString(const QString& s)
{
@@ -35,4 +39,51 @@ inline QString toQString(const OUString& s)
reinterpret_cast<ushort const *>(s.getStr()), s.getLength());
}
+inline QRect toQRect( const tools::Rectangle& rRect )
+{
+ return QRect( rRect.Left(), rRect.Top(),
+ rRect.GetWidth(), rRect.GetHeight() );
+}
+
+inline QSize toQSize( const Size& rSize )
+{
+ return QSize( rSize.Width(), rSize.Height() );
+}
+
+inline Size toSize( const QSize& rSize )
+{
+ return Size( rSize.width(), rSize.height() );
+}
+
+inline QImage::Format getBitFormat( sal_uInt16 nBitCount )
+{
+ switch ( nBitCount )
+ {
+ case 1 : return QImage::Format_Mono;
+ case 8 : return QImage::Format_Indexed8;
+ case 16 : return QImage::Format_RGB16;
+ case 24 : return QImage::Format_RGB888;
+ case 32 : return QImage::Format_ARGB32;
+ default :
+ std::abort();
+ break;
+ }
+ return QImage::Format_Invalid;
+}
+
+inline sal_uInt16 getFormatBits( QImage::Format eFormat )
+{
+ switch ( eFormat )
+ {
+ case QImage::Format_Mono : return 1;
+ case QImage::Format_Indexed8 : return 8;
+ case QImage::Format_RGB16 : return 16;
+ case QImage::Format_RGB888 : return 24;
+ case QImage::Format_ARGB32 : return 32;
+ default :
+ std::abort();
+ return 0;
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */