28#include <com/sun/star/geometry/RealRectangle2D.hpp>
44 sal_uInt32& rnDiscreteWidth, sal_uInt32& rnDiscreteHeight,
45 const sal_uInt32 nMaxSquarePixels)
47 if (rSequence.empty())
50 if (rnDiscreteWidth <= 0 || rnDiscreteHeight <= 0)
53 const sal_uInt32 nViewVisibleArea(rnDiscreteWidth * rnDiscreteHeight);
55 if (nViewVisibleArea > nMaxSquarePixels)
59 = sqrt(
static_cast<double>(nMaxSquarePixels) /
static_cast<double>(nViewVisibleArea));
60 rnDiscreteWidth =
basegfx::fround(
static_cast<double>(rnDiscreteWidth) * fReduceFactor);
61 rnDiscreteHeight =
basegfx::fround(
static_cast<double>(rnDiscreteHeight) * fReduceFactor);
66 std::move(rSequence)));
76 const Size& rSizePixel,
bool bUseLuminance)
81 if (!pContent->SetOutputSizePixel(rSizePixel,
false))
83 SAL_WARN(
"vcl",
"Cannot set VirtualDevice to size : " << rSizePixel.
Width() <<
"x"
91 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pContentProcessor
96 pContent->SetMapMode(
MapMode(MapUnit::MapPixel));
106 aBColorModifier = std::make_shared<basegfx::BColorModifier_luminance_to_alpha>();
112 = std::make_shared<basegfx::BColorModifier_replace>(
basegfx::BColor(0.0, 0.0, 0.0));
120 pContentProcessor->process(xSeq);
121 pContentProcessor.reset();
124 pContent->EnableMapMode(
false);
125 const Point aEmptyPoint;
130 Bitmap aContentBitmap = pContent->GetBitmap(aEmptyPoint, rSizePixel);
141 sal_uInt32 nDiscreteWidth, sal_uInt32 nDiscreteHeight,
142 sal_uInt32 nMaxSquarePixels,
bool bUseLuminance)
146 if (!implPrepareConversion(aSequence, nDiscreteWidth, nDiscreteHeight, nMaxSquarePixels))
151 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
153 return implcreateAlphaMask(aSequence, rViewInformation2D, aSizePixel, bUseLuminance);
158 sal_uInt32 nDiscreteWidth, sal_uInt32 nDiscreteHeight,
159 sal_uInt32 nMaxSquarePixels)
163 if (!implPrepareConversion(aSequence, nDiscreteWidth, nDiscreteHeight, nMaxSquarePixels))
168 const Point aEmptyPoint;
169 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
206 if (!pContent->SetOutputSizePixel(aSizePixel,
false))
208 SAL_WARN(
"vcl",
"Cannot set VirtualDevice to size : " << aSizePixel.
Width() <<
"x"
214 pContent->SetMapMode(
MapMode(MapUnit::MapPixel));
220 std::unique_ptr<processor2d::BaseProcessor2D> pContentProcessor
224 pContentProcessor->process(aSequence);
227 Bitmap aRetval(pContent->GetBitmap(aEmptyPoint, aSizePixel));
230 static bool bDoSaveForVisualControl(
false);
231 if (bDoSaveForVisualControl)
234 static const OUString sDumpPath(
235 OUString::createFromAscii(std::getenv(
"VCL_DUMP_BMP_PATH")));
236 if (!sDumpPath.isEmpty())
239 StreamMode::WRITE | StreamMode::TRUNC);
240 WriteDIB(aRetval, aNew,
false,
true);
248 AlphaMask aAlpha(implcreateAlphaMask(aSequence, rViewInformation2D, aSizePixel,
false));
251 if (bDoSaveForVisualControl)
254 static const OUString sDumpPath(
255 OUString::createFromAscii(std::getenv(
"VCL_DUMP_BMP_PATH")));
256 if (!sDumpPath.isEmpty())
258 SvFileStream aNew(sDumpPath +
"test_alpha.bmp", StreamMode::WRITE | StreamMode::TRUNC);
270 if (pContent->GetBitCount() < 32)
281 sal_uInt32 nMaximumQuadraticPixels,
283 const std::optional<Size>& rTargetDPI)
285 if (rSequence.empty())
290 css::geometry::RealRectangle2D aRealRect;
291 aRealRect.X1 = rTargetRange.
getMinX();
292 aRealRect.Y1 = rTargetRange.
getMinY();
293 aRealRect.X2 = rTargetRange.
getMaxX();
294 aRealRect.Y2 = rTargetRange.
getMaxY();
299 if (rTargetDPI.has_value())
304 ::sal_uInt32 DPI_X = aDPI.
getWidth();
306 const basegfx::B2DRange aRange(aRealRect.X1, aRealRect.Y1, aRealRect.X2, aRealRect.Y2);
307 const double fWidth(aRange.
getWidth());
308 const double fHeight(aRange.
getHeight());
323 if (0 == nMaximumQuadraticPixels)
325 nMaximumQuadraticPixels = 500000;
329 const sal_uInt32 nDiscreteWidth(
331 const sal_uInt32 nDiscreteHeight(
337 aEmbedding.
scale(nDiscreteWidth / fWidth, nDiscreteHeight / fHeight);
344 nDiscreteWidth, nDiscreteHeight,
345 nMaximumQuadraticPixels));
354 catch (
const css::uno::Exception&)
358 catch (
const std::exception& e)
360 SAL_WARN(
"vcl",
"Got no graphic::XPrimitive2DRenderer! : " << e.what());
Bitmap const & GetBitmap() const
static OutputDevice * GetDefaultDevice()
void SetPrefMapMode(const MapMode &rPrefMapMode)
void SetPrefSize(const Size &rPrefSize)
void RemoveBlendedStartColor(const Color &rColor, const AlphaMask &rAlphaMask)
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long getWidth() const
constexpr tools::Long Width() const
void scale(double fX, double fY)
ModifiedColorPrimitive2D class.
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
std::shared_ptr< BColorModifier > BColorModifierSharedPtr
B2IRange fround(const B2DRange &rRange)
ViewInformation2D createViewInformation2D(const css::uno::Sequence< css::beans::PropertyValue > &rViewParameters)
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
create the best available pixel based BaseProcessor2D (which may be system-dependent)
BitmapEx convertPrimitive2DContainerToBitmapEx(primitive2d::Primitive2DContainer &&rSequence, const basegfx::B2DRange &rTargetRange, sal_uInt32 nMaximumQuadraticPixels, const o3tl::Length eTargetUnit, const std::optional< Size > &rTargetDPI)
AlphaMask createAlphaMask(drawinglayer::primitive2d::Primitive2DContainer &&rSeq, const geometry::ViewInformation2D &rViewInformation2D, sal_uInt32 nDiscreteWidth, sal_uInt32 nDiscreteHeight, sal_uInt32 nMaxSquarePixels, bool bUseLuminance)
BitmapEx convertToBitmapEx(drawinglayer::primitive2d::Primitive2DContainer &&rSeq, const geometry::ViewInformation2D &rViewInformation2D, sal_uInt32 nDiscreteWidth, sal_uInt32 nDiscreteHeight, sal_uInt32 nMaxSquarePixels)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)