1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <canvas/canvastools.hxx>
24 #include <comphelper/diagnose_ex.hxx>
25 #include <vcl/bitmapex.hxx>
26 #include <vcl/BitmapTools.hxx>
27 #include <vcl/canvastools.hxx>
29 #include "canvasbitmap.hxx"
30 #include "canvasbitmaphelper.hxx"
33 using namespace ::com::sun::star
;
37 CanvasBitmapHelper::CanvasBitmapHelper()
41 void CanvasBitmapHelper::init( const BitmapEx
& rBitmap
,
42 rendering::XGraphicDevice
& rDevice
,
43 const OutDevProviderSharedPtr
& rOutDevReference
)
45 mpOutDevReference
= rOutDevReference
;
46 mpBackBuffer
= std::make_shared
<BitmapBackBuffer
>( rBitmap
, rOutDevReference
->getOutDev() );
48 // forward new settings to base class (ref device, output
49 // surface, no protection (own backbuffer), alpha depends on
50 // whether BmpEx is transparent or not)
51 CanvasHelper::init( rDevice
,
57 void CanvasBitmapHelper::disposing()
60 mpOutDevReference
.reset();
62 // forward to base class
63 CanvasHelper::disposing();
66 geometry::IntegerSize2D
CanvasBitmapHelper::getSize() const
69 return geometry::IntegerSize2D();
71 return vcl::unotools::integerSize2DFromSize( mpBackBuffer
->getBitmapSizePixel() );
74 void CanvasBitmapHelper::clear()
78 mpBackBuffer
->clear(); // alpha vdev needs special treatment
81 uno::Reference
< rendering::XBitmap
> CanvasBitmapHelper::getScaledBitmap( const geometry::RealSize2D
& newSize
,
84 ENSURE_OR_THROW( mpDevice
,
85 "disposed CanvasHelper" );
87 SAL_INFO( "canvas.vcl", "::vclcanvas::CanvasBitmapHelper::getScaledBitmap()" );
89 if( !mpBackBuffer
|| mpDevice
)
90 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
92 BitmapEx
aRes( mpBackBuffer
->getBitmapReference() );
94 aRes
.Scale( vcl::unotools::sizeFromRealSize2D(newSize
),
95 beFast
? BmpScaleFlag::Default
: BmpScaleFlag::BestQuality
);
97 return uno::Reference
< rendering::XBitmap
>(
98 new CanvasBitmap( aRes
, *mpDevice
, mpOutDevReference
) );
101 uno::Sequence
< sal_Int8
> CanvasBitmapHelper::getData( rendering::IntegerBitmapLayout
& rLayout
,
102 const geometry::IntegerRectangle2D
& rect
)
104 SAL_INFO( "canvas.vcl", "::vclcanvas::CanvasBitmapHelper::getData()" );
107 return uno::Sequence
< sal_Int8
>(); // we're disposed
109 rLayout
= getMemoryLayout();
111 // TODO(F1): Support more formats.
112 const Size
aBmpSize( mpBackBuffer
->getBitmapReference().GetSizePixel() );
114 rLayout
.ScanLines
= aBmpSize
.Height();
115 rLayout
.ScanLineBytes
= aBmpSize
.Width()*4;
116 rLayout
.ScanLineStride
= rLayout
.ScanLineBytes
;
118 uno::Sequence
< sal_Int8
> aRes
= vcl::bitmap::CanvasExtractBitmapData(mpBackBuffer
->getBitmapReference(), rect
);
122 uno::Sequence
< sal_Int8
> CanvasBitmapHelper::getPixel( rendering::IntegerBitmapLayout
& rLayout
,
123 const geometry::IntegerPoint2D
& pos
)
125 SAL_INFO( "canvas.vcl", "::vclcanvas::CanvasBitmapHelper::getPixel()" );
128 return uno::Sequence
< sal_Int8
>(); // we're disposed
130 rLayout
= getMemoryLayout();
131 rLayout
.ScanLines
= 1;
132 rLayout
.ScanLineBytes
= 4;
133 rLayout
.ScanLineStride
= rLayout
.ScanLineBytes
;
135 const Size
aBmpSize( mpBackBuffer
->getBitmapReference().GetSizePixel() );
137 ENSURE_ARG_OR_THROW( pos
.X
>= 0 && pos
.X
< aBmpSize
.Width(),
138 "X coordinate out of bounds" );
139 ENSURE_ARG_OR_THROW( pos
.Y
>= 0 && pos
.Y
< aBmpSize
.Height(),
140 "Y coordinate out of bounds" );
142 ::Color aColor
= mpBackBuffer
->getBitmapReference().GetPixelColor(pos
.X
, pos
.Y
);
144 uno::Sequence
< sal_Int8
> aRes( 4 );
145 sal_Int8
* pRes
= aRes
.getArray();
146 pRes
[ 0 ] = aColor
.GetRed();
147 pRes
[ 1 ] = aColor
.GetGreen();
148 pRes
[ 2 ] = aColor
.GetBlue();
149 pRes
[ 3 ] = 255 - aColor
.GetAlpha();
154 rendering::IntegerBitmapLayout
CanvasBitmapHelper::getMemoryLayout() const
156 if( !mpOutDevProvider
)
157 return rendering::IntegerBitmapLayout(); // we're disposed
159 rendering::IntegerBitmapLayout
aBitmapLayout( ::canvas::tools::getStdMemoryLayout(getSize()) );
161 aBitmapLayout
.ColorSpace
= canvas::tools::getStdColorSpaceWithoutAlpha();
163 return aBitmapLayout
;
166 BitmapEx
CanvasBitmapHelper::getBitmap() const
169 return BitmapEx(); // we're disposed
171 return mpBackBuffer
->getBitmapReference();
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */